Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 183 lines (150 sloc) 4.59 kb
05bf0a1 @bwalex Start C API work
authored
1 /*
2 * Copyright (c) 2011 Alex Hornung <alex@alexhornung.com>.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
19 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
20 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
22 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
a6e7a9d @bwalex make compilable when in lib/api mode
authored
30 #include <stdlib.h>
31 #include <unistd.h>
05bf0a1 @bwalex Start C API work
authored
32 #include <errno.h>
33
1af29c1 @bwalex rename tc-play => tcplay
authored
34 #include "tcplay.h"
35 #include "tcplay_api.h"
05bf0a1 @bwalex Start C API work
authored
36
37 int
38 tc_api_init(int verbose)
39 {
2e3a80c @bwalex several minor fixes/cleanups
authored
40 int error;
41
05bf0a1 @bwalex Start C API work
authored
42 tc_internal_verbose = verbose;
43
2e3a80c @bwalex several minor fixes/cleanups
authored
44 if ((error = tc_play_init()) != 0)
45 return TC_ERR;
46 else
47 return TC_OK;
05bf0a1 @bwalex Start C API work
authored
48 }
49
50 int
51 tc_api_uninit(void)
52 {
53 check_and_purge_safe_mem();
54 return TC_OK;
55 }
56
38499ea @bwalex minor API fix; these char* are actually const
authored
57 const char *
05bf0a1 @bwalex Start C API work
authored
58 tc_api_get_error_msg(void)
59 {
18ab2a2 @bwalex fix several API-detected bugs
authored
60 return tc_internal_log_buffer;
05bf0a1 @bwalex Start C API work
authored
61 }
62
38499ea @bwalex minor API fix; these char* are actually const
authored
63 const char *
69686eb @bwalex improve secure_erase speed; add SIGINFO support
authored
64 tc_api_get_summary(void)
65 {
18fec4d @bwalex minor fix
authored
66 if (summary_fn != NULL) {
69686eb @bwalex improve secure_erase speed; add SIGINFO support
authored
67 summary_fn();
18fec4d @bwalex minor fix
authored
68 return tc_internal_log_buffer;
69 }
69686eb @bwalex improve secure_erase speed; add SIGINFO support
authored
70
18fec4d @bwalex minor fix
authored
71 return NULL;
69686eb @bwalex improve secure_erase speed; add SIGINFO support
authored
72 }
73
05bf0a1 @bwalex Start C API work
authored
74 int
2e3a80c @bwalex several minor fixes/cleanups
authored
75 tc_api_create_volume(tc_api_opts *api_opts)
05bf0a1 @bwalex Start C API work
authored
76 {
77 int nkeyfiles, n_hkeyfiles;
78 int create_hidden;
431d5f9 @bwalex silence compiler warnings in api
authored
79 int err;
05bf0a1 @bwalex Start C API work
authored
80
81 if ((api_opts == NULL) ||
82 (api_opts->tc_device == NULL)) {
83 errno = EFAULT;
84 return TC_ERR;
85 }
86
87 if ((err = tc_api_check_cipher(api_opts)) != TC_OK)
88 return TC_ERR;
89
90 if ((err = tc_api_check_prf_hash(api_opts)) != TC_OK)
91 return TC_ERR;
92
93 for (nkeyfiles = 0; (nkeyfiles < MAX_KEYFILES) &&
18ab2a2 @bwalex fix several API-detected bugs
authored
94 (api_opts->tc_keyfiles != NULL) &&
05bf0a1 @bwalex Start C API work
authored
95 (api_opts->tc_keyfiles[nkeyfiles] != NULL); nkeyfiles++)
96 ;
97
98 create_hidden = 0;
99
a6e7a9d @bwalex make compilable when in lib/api mode
authored
100 if (api_opts->tc_size_hidden_in_blocks > 0) {
05bf0a1 @bwalex Start C API work
authored
101 create_hidden = 1;
102 for (n_hkeyfiles = 0; (n_hkeyfiles < MAX_KEYFILES) &&
18ab2a2 @bwalex fix several API-detected bugs
authored
103 (api_opts->tc_keyfiles_hidden != NULL) &&
05bf0a1 @bwalex Start C API work
authored
104 (api_opts->tc_keyfiles_hidden[n_hkeyfiles] != NULL);
105 n_hkeyfiles++)
106 ;
107 }
108
109 err = create_volume(api_opts->tc_device, create_hidden,
110 api_opts->tc_keyfiles, nkeyfiles,
111 api_opts->tc_keyfiles_hidden, n_hkeyfiles,
112 check_prf_algo(api_opts->tc_prf_hash, 1),
113 check_cipher_chain(api_opts->tc_cipher, 1),
c4608da @bwalex bugfix, support for different cipher for hidden vol
authored
114 check_prf_algo(api_opts->tc_prf_hash_hidden, 1),
115 check_cipher_chain(api_opts->tc_cipher_hidden, 1),
05bf0a1 @bwalex Start C API work
authored
116 api_opts->tc_passphrase, api_opts->tc_passphrase_hidden,
a6e7a9d @bwalex make compilable when in lib/api mode
authored
117 api_opts->tc_size_hidden_in_blocks, 0 /* non-interactive */);
05bf0a1 @bwalex Start C API work
authored
118
119 return (err) ? TC_ERR : TC_OK;
120 }
121
122 int
2e3a80c @bwalex several minor fixes/cleanups
authored
123 tc_api_map_volume(tc_api_opts *api_opts)
05bf0a1 @bwalex Start C API work
authored
124 {
bc488b4 @bwalex expand api with map command; clean up a bit
authored
125 int nkeyfiles;
126 int err;
127
128 if ((api_opts == NULL) ||
129 (api_opts->tc_device == NULL)) {
130 errno = EFAULT;
131 return TC_ERR;
132 }
133
134 for (nkeyfiles = 0; (nkeyfiles < MAX_KEYFILES) &&
1ae48b1 @bwalex fix another API bug
authored
135 (api_opts->tc_keyfiles != NULL) &&
bc488b4 @bwalex expand api with map command; clean up a bit
authored
136 (api_opts->tc_keyfiles[nkeyfiles] != NULL); nkeyfiles++)
137 ;
138
a6e7a9d @bwalex make compilable when in lib/api mode
authored
139 err = map_volume(api_opts->tc_map_name, api_opts->tc_device,
bc488b4 @bwalex expand api with map command; clean up a bit
authored
140 /* sflag */ 0, /* sys_dev */ NULL,
141 /* protect_hidden */ 0, api_opts->tc_keyfiles, nkeyfiles,
142 /* h_keyfiles[] */ NULL, /* n_hkeyfiles */ 0,
a6e7a9d @bwalex make compilable when in lib/api mode
authored
143 api_opts->tc_passphrase, /* passphrase_hidden */ NULL,
bc488b4 @bwalex expand api with map command; clean up a bit
authored
144 api_opts->tc_interactive_prompt, api_opts->tc_password_retries);
145
146 return (err) ? TC_ERR : TC_OK;
05bf0a1 @bwalex Start C API work
authored
147 }
148
149 int
2e3a80c @bwalex several minor fixes/cleanups
authored
150 tc_api_check_cipher(tc_api_opts *api_opts)
05bf0a1 @bwalex Start C API work
authored
151 {
152 struct tc_cipher_chain *chain;
153
a6e7a9d @bwalex make compilable when in lib/api mode
authored
154 if (api_opts == NULL || api_opts->tc_cipher == NULL) {
05bf0a1 @bwalex Start C API work
authored
155 errno = EFAULT;
156 return TC_ERR;
157 }
158
159 if ((chain = check_cipher_chain(api_opts->tc_cipher, 1)) != NULL)
160 return TC_OK;
161
162 errno = ENOENT;
163 return TC_ERR;
164 }
165
166 int
2e3a80c @bwalex several minor fixes/cleanups
authored
167 tc_api_check_prf_hash(tc_api_opts *api_opts)
05bf0a1 @bwalex Start C API work
authored
168 {
169 struct pbkdf_prf_algo *prf_hash;
170
a6e7a9d @bwalex make compilable when in lib/api mode
authored
171 if (api_opts == NULL || api_opts->tc_prf_hash == NULL) {
05bf0a1 @bwalex Start C API work
authored
172 errno = EFAULT;
173 return TC_ERR;
174 }
175
176 if ((prf_hash = check_prf_algo(api_opts->tc_prf_hash, 1)) != NULL)
177 return TC_OK;
178
179 errno = ENOENT;
180 return TC_ERR;
181 }
182
Something went wrong with that request. Please try again.