summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/engine/eng_ctrl.c
diff options
context:
space:
mode:
authorjsing <>2014-06-10 15:20:40 +0000
committerjsing <>2014-06-10 15:20:40 +0000
commit1f0ada29dbbd22c18c51187561c2eb01d2a776b2 (patch)
tree26b9352fb9a5ac6c506e8003ffd77006cf098bbb /src/lib/libcrypto/engine/eng_ctrl.c
parent3d34b57814cfdc90c98c015ae0dbd3c1862c83cd (diff)
downloadopenbsd-1f0ada29dbbd22c18c51187561c2eb01d2a776b2.tar.gz
openbsd-1f0ada29dbbd22c18c51187561c2eb01d2a776b2.tar.bz2
openbsd-1f0ada29dbbd22c18c51187561c2eb01d2a776b2.zip
KNF.
Diffstat (limited to 'src/lib/libcrypto/engine/eng_ctrl.c')
-rw-r--r--src/lib/libcrypto/engine/eng_ctrl.c313
1 files changed, 151 insertions, 162 deletions
diff --git a/src/lib/libcrypto/engine/eng_ctrl.c b/src/lib/libcrypto/engine/eng_ctrl.c
index d5017e2329..67a724202b 100644
--- a/src/lib/libcrypto/engine/eng_ctrl.c
+++ b/src/lib/libcrypto/engine/eng_ctrl.c
@@ -7,7 +7,7 @@
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 11 *
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in 13 * notice, this list of conditions and the following disclaimer in
@@ -63,95 +63,92 @@ static const char *int_no_description = "";
63 * ENGINE in question has asked us to take care of it (ie. the ENGINE did not 63 * ENGINE in question has asked us to take care of it (ie. the ENGINE did not
64 * set the ENGINE_FLAGS_MANUAL_CMD_CTRL flag. */ 64 * set the ENGINE_FLAGS_MANUAL_CMD_CTRL flag. */
65 65
66static int int_ctrl_cmd_is_null(const ENGINE_CMD_DEFN *defn) 66static int
67 { 67int_ctrl_cmd_is_null(const ENGINE_CMD_DEFN *defn)
68 if((defn->cmd_num == 0) || (defn->cmd_name == NULL)) 68{
69 if ((defn->cmd_num == 0) || (defn->cmd_name == NULL))
69 return 1; 70 return 1;
70 return 0; 71 return 0;
71 } 72}
72 73
73static int int_ctrl_cmd_by_name(const ENGINE_CMD_DEFN *defn, const char *s) 74static int
74 { 75int_ctrl_cmd_by_name(const ENGINE_CMD_DEFN *defn, const char *s)
76{
75 int idx = 0; 77 int idx = 0;
76 while(!int_ctrl_cmd_is_null(defn) && (strcmp(defn->cmd_name, s) != 0)) 78 while (!int_ctrl_cmd_is_null(defn) &&
77 { 79 (strcmp(defn->cmd_name, s) != 0)) {
78 idx++; 80 idx++;
79 defn++; 81 defn++;
80 } 82 }
81 if(int_ctrl_cmd_is_null(defn)) 83 if (int_ctrl_cmd_is_null(defn))
82 /* The given name wasn't found */ 84 /* The given name wasn't found */
83 return -1; 85 return -1;
84 return idx; 86 return idx;
85 } 87}
86 88
87static int int_ctrl_cmd_by_num(const ENGINE_CMD_DEFN *defn, unsigned int num) 89static int
88 { 90int_ctrl_cmd_by_num(const ENGINE_CMD_DEFN *defn, unsigned int num)
91{
89 int idx = 0; 92 int idx = 0;
90 /* NB: It is stipulated that 'cmd_defn' lists are ordered by cmd_num. So 93 /* NB: It is stipulated that 'cmd_defn' lists are ordered by cmd_num. So
91 * our searches don't need to take any longer than necessary. */ 94 * our searches don't need to take any longer than necessary. */
92 while(!int_ctrl_cmd_is_null(defn) && (defn->cmd_num < num)) 95 while (!int_ctrl_cmd_is_null(defn) && (defn->cmd_num < num)) {
93 {
94 idx++; 96 idx++;
95 defn++; 97 defn++;
96 } 98 }
97 if(defn->cmd_num == num) 99 if (defn->cmd_num == num)
98 return idx; 100 return idx;
99 /* The given cmd_num wasn't found */ 101 /* The given cmd_num wasn't found */
100 return -1; 102 return -1;
101 } 103}
102 104
103static int int_ctrl_helper(ENGINE *e, int cmd, long i, void *p, 105static int
104 void (*f)(void)) 106int_ctrl_helper(ENGINE *e, int cmd, long i, void *p, void (*f)(void))
105 { 107{
106 int idx; 108 int idx;
107 int ret; 109 int ret;
108 char *s = (char *)p; 110 char *s = (char *)p;
111
109 /* Take care of the easy one first (eg. it requires no searches) */ 112 /* Take care of the easy one first (eg. it requires no searches) */
110 if(cmd == ENGINE_CTRL_GET_FIRST_CMD_TYPE) 113 if (cmd == ENGINE_CTRL_GET_FIRST_CMD_TYPE) {
111 { 114 if ((e->cmd_defns == NULL) ||
112 if((e->cmd_defns == NULL) || int_ctrl_cmd_is_null(e->cmd_defns)) 115 int_ctrl_cmd_is_null(e->cmd_defns))
113 return 0; 116 return 0;
114 return e->cmd_defns->cmd_num; 117 return e->cmd_defns->cmd_num;
115 } 118 }
116 /* One or two commands require that "p" be a valid string buffer */ 119 /* One or two commands require that "p" be a valid string buffer */
117 if((cmd == ENGINE_CTRL_GET_CMD_FROM_NAME) || 120 if ((cmd == ENGINE_CTRL_GET_CMD_FROM_NAME) ||
118 (cmd == ENGINE_CTRL_GET_NAME_FROM_CMD) || 121 (cmd == ENGINE_CTRL_GET_NAME_FROM_CMD) ||
119 (cmd == ENGINE_CTRL_GET_DESC_FROM_CMD)) 122 (cmd == ENGINE_CTRL_GET_DESC_FROM_CMD)) {
120 { 123 if (s == NULL) {
121 if(s == NULL)
122 {
123 ENGINEerr(ENGINE_F_INT_CTRL_HELPER, 124 ENGINEerr(ENGINE_F_INT_CTRL_HELPER,
124 ERR_R_PASSED_NULL_PARAMETER); 125 ERR_R_PASSED_NULL_PARAMETER);
125 return -1; 126 return -1;
126 }
127 } 127 }
128 }
128 /* Now handle cmd_name -> cmd_num conversion */ 129 /* Now handle cmd_name -> cmd_num conversion */
129 if(cmd == ENGINE_CTRL_GET_CMD_FROM_NAME) 130 if (cmd == ENGINE_CTRL_GET_CMD_FROM_NAME) {
130 { 131 if ((e->cmd_defns == NULL) ||
131 if((e->cmd_defns == NULL) || ((idx = int_ctrl_cmd_by_name( 132 ((idx = int_ctrl_cmd_by_name(e->cmd_defns, s)) < 0)) {
132 e->cmd_defns, s)) < 0))
133 {
134 ENGINEerr(ENGINE_F_INT_CTRL_HELPER, 133 ENGINEerr(ENGINE_F_INT_CTRL_HELPER,
135 ENGINE_R_INVALID_CMD_NAME); 134 ENGINE_R_INVALID_CMD_NAME);
136 return -1; 135 return -1;
137 }
138 return e->cmd_defns[idx].cmd_num;
139 } 136 }
137 return e->cmd_defns[idx].cmd_num;
138 }
140 /* For the rest of the commands, the 'long' argument must specify a 139 /* For the rest of the commands, the 'long' argument must specify a
141 * valie command number - so we need to conduct a search. */ 140 * valie command number - so we need to conduct a search. */
142 if((e->cmd_defns == NULL) || ((idx = int_ctrl_cmd_by_num(e->cmd_defns, 141 if ((e->cmd_defns == NULL) ||
143 (unsigned int)i)) < 0)) 142 ((idx = int_ctrl_cmd_by_num(e->cmd_defns, (unsigned int)i)) < 0)) {
144 {
145 ENGINEerr(ENGINE_F_INT_CTRL_HELPER, 143 ENGINEerr(ENGINE_F_INT_CTRL_HELPER,
146 ENGINE_R_INVALID_CMD_NUMBER); 144 ENGINE_R_INVALID_CMD_NUMBER);
147 return -1; 145 return -1;
148 } 146 }
149 /* Now the logic splits depending on command type */ 147 /* Now the logic splits depending on command type */
150 switch(cmd) 148 switch (cmd) {
151 {
152 case ENGINE_CTRL_GET_NEXT_CMD_TYPE: 149 case ENGINE_CTRL_GET_NEXT_CMD_TYPE:
153 idx++; 150 idx++;
154 if(int_ctrl_cmd_is_null(e->cmd_defns + idx)) 151 if (int_ctrl_cmd_is_null(e->cmd_defns + idx))
155 /* end-of-list */ 152 /* end-of-list */
156 return 0; 153 return 0;
157 else 154 else
@@ -159,17 +156,17 @@ static int int_ctrl_helper(ENGINE *e, int cmd, long i, void *p,
159 case ENGINE_CTRL_GET_NAME_LEN_FROM_CMD: 156 case ENGINE_CTRL_GET_NAME_LEN_FROM_CMD:
160 return strlen(e->cmd_defns[idx].cmd_name); 157 return strlen(e->cmd_defns[idx].cmd_name);
161 case ENGINE_CTRL_GET_NAME_FROM_CMD: 158 case ENGINE_CTRL_GET_NAME_FROM_CMD:
162 ret = snprintf(s,strlen(e->cmd_defns[idx].cmd_name) + 1, 159 ret = snprintf(s, strlen(e->cmd_defns[idx].cmd_name) + 1,
163 "%s", e->cmd_defns[idx].cmd_name); 160 "%s", e->cmd_defns[idx].cmd_name);
164 if (ret >= (strlen(e->cmd_defns[idx].cmd_name) + 1)) 161 if (ret >= (strlen(e->cmd_defns[idx].cmd_name) + 1))
165 ret = -1; 162 ret = -1;
166 return ret; 163 return ret;
167 case ENGINE_CTRL_GET_DESC_LEN_FROM_CMD: 164 case ENGINE_CTRL_GET_DESC_LEN_FROM_CMD:
168 if(e->cmd_defns[idx].cmd_desc) 165 if (e->cmd_defns[idx].cmd_desc)
169 return strlen(e->cmd_defns[idx].cmd_desc); 166 return strlen(e->cmd_defns[idx].cmd_desc);
170 return strlen(int_no_description); 167 return strlen(int_no_description);
171 case ENGINE_CTRL_GET_DESC_FROM_CMD: 168 case ENGINE_CTRL_GET_DESC_FROM_CMD:
172 if(e->cmd_defns[idx].cmd_desc) { 169 if (e->cmd_defns[idx].cmd_desc) {
173 ret = snprintf(s, 170 ret = snprintf(s,
174 strlen(e->cmd_defns[idx].cmd_desc) + 1, 171 strlen(e->cmd_defns[idx].cmd_desc) + 1,
175 "%s", e->cmd_defns[idx].cmd_desc); 172 "%s", e->cmd_defns[idx].cmd_desc);
@@ -177,40 +174,40 @@ static int int_ctrl_helper(ENGINE *e, int cmd, long i, void *p,
177 ret = -1; 174 ret = -1;
178 return ret; 175 return ret;
179 } 176 }
180 ret = snprintf(s, strlen(int_no_description) + 1,"%s", 177 ret = snprintf(s, strlen(int_no_description) + 1, "%s",
181 int_no_description); 178 int_no_description);
182 if (ret >= strlen(int_no_description) + 1) 179 if (ret >= strlen(int_no_description) + 1)
183 ret = -1; 180 ret = -1;
184 return ret; 181 return ret;
185 case ENGINE_CTRL_GET_CMD_FLAGS: 182 case ENGINE_CTRL_GET_CMD_FLAGS:
186 return e->cmd_defns[idx].cmd_flags; 183 return e->cmd_defns[idx].cmd_flags;
187 } 184 }
185
188 /* Shouldn't really be here ... */ 186 /* Shouldn't really be here ... */
189 ENGINEerr(ENGINE_F_INT_CTRL_HELPER,ENGINE_R_INTERNAL_LIST_ERROR); 187 ENGINEerr(ENGINE_F_INT_CTRL_HELPER, ENGINE_R_INTERNAL_LIST_ERROR);
190 return -1; 188 return -1;
191 } 189}
192 190
193int ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void)) 191int
194 { 192ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void))
193{
195 int ctrl_exists, ref_exists; 194 int ctrl_exists, ref_exists;
196 if(e == NULL) 195
197 { 196 if (e == NULL) {
198 ENGINEerr(ENGINE_F_ENGINE_CTRL,ERR_R_PASSED_NULL_PARAMETER); 197 ENGINEerr(ENGINE_F_ENGINE_CTRL, ERR_R_PASSED_NULL_PARAMETER);
199 return 0; 198 return 0;
200 } 199 }
201 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); 200 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
202 ref_exists = ((e->struct_ref > 0) ? 1 : 0); 201 ref_exists = ((e->struct_ref > 0) ? 1 : 0);
203 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); 202 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
204 ctrl_exists = ((e->ctrl == NULL) ? 0 : 1); 203 ctrl_exists = ((e->ctrl == NULL) ? 0 : 1);
205 if(!ref_exists) 204 if (!ref_exists) {
206 { 205 ENGINEerr(ENGINE_F_ENGINE_CTRL, ENGINE_R_NO_REFERENCE);
207 ENGINEerr(ENGINE_F_ENGINE_CTRL,ENGINE_R_NO_REFERENCE);
208 return 0; 206 return 0;
209 } 207 }
210 /* Intercept any "root-level" commands before trying to hand them on to 208 /* Intercept any "root-level" commands before trying to hand them on to
211 * ctrl() handlers. */ 209 * ctrl() handlers. */
212 switch(cmd) 210 switch (cmd) {
213 {
214 case ENGINE_CTRL_HAS_CTRL_FUNCTION: 211 case ENGINE_CTRL_HAS_CTRL_FUNCTION:
215 return ctrl_exists; 212 return ctrl_exists;
216 case ENGINE_CTRL_GET_FIRST_CMD_TYPE: 213 case ENGINE_CTRL_GET_FIRST_CMD_TYPE:
@@ -221,180 +218,172 @@ int ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void))
221 case ENGINE_CTRL_GET_DESC_LEN_FROM_CMD: 218 case ENGINE_CTRL_GET_DESC_LEN_FROM_CMD:
222 case ENGINE_CTRL_GET_DESC_FROM_CMD: 219 case ENGINE_CTRL_GET_DESC_FROM_CMD:
223 case ENGINE_CTRL_GET_CMD_FLAGS: 220 case ENGINE_CTRL_GET_CMD_FLAGS:
224 if(ctrl_exists && !(e->flags & ENGINE_FLAGS_MANUAL_CMD_CTRL)) 221 if (ctrl_exists && !(e->flags & ENGINE_FLAGS_MANUAL_CMD_CTRL))
225 return int_ctrl_helper(e,cmd,i,p,f); 222 return int_ctrl_helper(e, cmd, i, p, f);
226 if(!ctrl_exists) 223 if (!ctrl_exists) {
227 { 224 ENGINEerr(ENGINE_F_ENGINE_CTRL,
228 ENGINEerr(ENGINE_F_ENGINE_CTRL,ENGINE_R_NO_CONTROL_FUNCTION); 225 ENGINE_R_NO_CONTROL_FUNCTION);
229 /* For these cmd-related functions, failure is indicated 226 /* For these cmd-related functions, failure is indicated
230 * by a -1 return value (because 0 is used as a valid 227 * by a -1 return value (because 0 is used as a valid
231 * return in some places). */ 228 * return in some places). */
232 return -1; 229 return -1;
233 } 230 }
234 default: 231 default:
235 break; 232 break;
236 } 233 }
237 /* Anything else requires a ctrl() handler to exist. */ 234 /* Anything else requires a ctrl() handler to exist. */
238 if(!ctrl_exists) 235 if (!ctrl_exists) {
239 { 236 ENGINEerr(ENGINE_F_ENGINE_CTRL, ENGINE_R_NO_CONTROL_FUNCTION);
240 ENGINEerr(ENGINE_F_ENGINE_CTRL,ENGINE_R_NO_CONTROL_FUNCTION);
241 return 0; 237 return 0;
242 }
243 return e->ctrl(e, cmd, i, p, f);
244 } 238 }
239 return e->ctrl(e, cmd, i, p, f);
240}
245 241
246int ENGINE_cmd_is_executable(ENGINE *e, int cmd) 242int
247 { 243ENGINE_cmd_is_executable(ENGINE *e, int cmd)
244{
248 int flags; 245 int flags;
249 if((flags = ENGINE_ctrl(e, ENGINE_CTRL_GET_CMD_FLAGS, cmd, NULL, NULL)) < 0) 246
250 { 247 if ((flags = ENGINE_ctrl(e, ENGINE_CTRL_GET_CMD_FLAGS, cmd,
248 NULL, NULL)) < 0) {
251 ENGINEerr(ENGINE_F_ENGINE_CMD_IS_EXECUTABLE, 249 ENGINEerr(ENGINE_F_ENGINE_CMD_IS_EXECUTABLE,
252 ENGINE_R_INVALID_CMD_NUMBER); 250 ENGINE_R_INVALID_CMD_NUMBER);
253 return 0; 251 return 0;
254 } 252 }
255 if(!(flags & ENGINE_CMD_FLAG_NO_INPUT) && 253 if (!(flags & ENGINE_CMD_FLAG_NO_INPUT) &&
256 !(flags & ENGINE_CMD_FLAG_NUMERIC) && 254 !(flags & ENGINE_CMD_FLAG_NUMERIC) &&
257 !(flags & ENGINE_CMD_FLAG_STRING)) 255 !(flags & ENGINE_CMD_FLAG_STRING))
258 return 0; 256 return 0;
259 return 1; 257 return 1;
260 } 258}
261 259
262int ENGINE_ctrl_cmd(ENGINE *e, const char *cmd_name, 260int
263 long i, void *p, void (*f)(void), int cmd_optional) 261ENGINE_ctrl_cmd(ENGINE *e, const char *cmd_name, long i, void *p,
264 { 262 void (*f)(void), int cmd_optional)
263{
265 int num; 264 int num;
266 265
267 if((e == NULL) || (cmd_name == NULL)) 266 if ((e == NULL) || (cmd_name == NULL)) {
268 {
269 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD, 267 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD,
270 ERR_R_PASSED_NULL_PARAMETER); 268 ERR_R_PASSED_NULL_PARAMETER);
271 return 0; 269 return 0;
272 } 270 }
273 if((e->ctrl == NULL) || ((num = ENGINE_ctrl(e, 271 if ((e->ctrl == NULL) ||
274 ENGINE_CTRL_GET_CMD_FROM_NAME, 272 ((num = ENGINE_ctrl(e, ENGINE_CTRL_GET_CMD_FROM_NAME,
275 0, (void *)cmd_name, NULL)) <= 0)) 273 0, (void *)cmd_name, NULL)) <= 0)) {
276 {
277 /* If the command didn't *have* to be supported, we fake 274 /* If the command didn't *have* to be supported, we fake
278 * success. This allows certain settings to be specified for 275 * success. This allows certain settings to be specified for
279 * multiple ENGINEs and only require a change of ENGINE id 276 * multiple ENGINEs and only require a change of ENGINE id
280 * (without having to selectively apply settings). Eg. changing 277 * (without having to selectively apply settings). Eg. changing
281 * from a hardware device back to the regular software ENGINE 278 * from a hardware device back to the regular software ENGINE
282 * without editing the config file, etc. */ 279 * without editing the config file, etc. */
283 if(cmd_optional) 280 if (cmd_optional) {
284 {
285 ERR_clear_error(); 281 ERR_clear_error();
286 return 1; 282 return 1;
287 }
288 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD,
289 ENGINE_R_INVALID_CMD_NAME);
290 return 0;
291 } 283 }
284 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD, ENGINE_R_INVALID_CMD_NAME);
285 return 0;
286 }
287
292 /* Force the result of the control command to 0 or 1, for the reasons 288 /* Force the result of the control command to 0 or 1, for the reasons
293 * mentioned before. */ 289 * mentioned before. */
294 if (ENGINE_ctrl(e, num, i, p, f) > 0) 290 if (ENGINE_ctrl(e, num, i, p, f) > 0)
295 return 1; 291 return 1;
296 return 0;
297 }
298 292
299int ENGINE_ctrl_cmd_string(ENGINE *e, const char *cmd_name, const char *arg, 293 return 0;
300 int cmd_optional) 294}
301 { 295
296int
297ENGINE_ctrl_cmd_string(ENGINE *e, const char *cmd_name, const char *arg,
298 int cmd_optional)
299{
302 int num, flags; 300 int num, flags;
303 long l; 301 long l;
304 char *ptr; 302 char *ptr;
305 if((e == NULL) || (cmd_name == NULL)) 303
306 { 304 if ((e == NULL) || (cmd_name == NULL)) {
307 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING, 305 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING,
308 ERR_R_PASSED_NULL_PARAMETER); 306 ERR_R_PASSED_NULL_PARAMETER);
309 return 0; 307 return 0;
310 } 308 }
311 if((e->ctrl == NULL) || ((num = ENGINE_ctrl(e, 309 if ((e->ctrl == NULL) ||
312 ENGINE_CTRL_GET_CMD_FROM_NAME, 310 ((num = ENGINE_ctrl(e, ENGINE_CTRL_GET_CMD_FROM_NAME, 0,
313 0, (void *)cmd_name, NULL)) <= 0)) 311 (void *)cmd_name, NULL)) <= 0)) {
314 {
315 /* If the command didn't *have* to be supported, we fake 312 /* If the command didn't *have* to be supported, we fake
316 * success. This allows certain settings to be specified for 313 * success. This allows certain settings to be specified for
317 * multiple ENGINEs and only require a change of ENGINE id 314 * multiple ENGINEs and only require a change of ENGINE id
318 * (without having to selectively apply settings). Eg. changing 315 * (without having to selectively apply settings). Eg. changing
319 * from a hardware device back to the regular software ENGINE 316 * from a hardware device back to the regular software ENGINE
320 * without editing the config file, etc. */ 317 * without editing the config file, etc. */
321 if(cmd_optional) 318 if (cmd_optional) {
322 {
323 ERR_clear_error(); 319 ERR_clear_error();
324 return 1; 320 return 1;
325 } 321 }
326 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING, 322 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING,
327 ENGINE_R_INVALID_CMD_NAME); 323 ENGINE_R_INVALID_CMD_NAME);
328 return 0; 324 return 0;
329 } 325 }
330 if(!ENGINE_cmd_is_executable(e, num)) 326 if (!ENGINE_cmd_is_executable(e, num)) {
331 {
332 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING, 327 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING,
333 ENGINE_R_CMD_NOT_EXECUTABLE); 328 ENGINE_R_CMD_NOT_EXECUTABLE);
334 return 0; 329 return 0;
335 } 330 }
336 if((flags = ENGINE_ctrl(e, ENGINE_CTRL_GET_CMD_FLAGS, num, NULL, NULL)) < 0) 331 if ((flags = ENGINE_ctrl(e, ENGINE_CTRL_GET_CMD_FLAGS, num,
337 { 332 NULL, NULL)) < 0) {
338 /* Shouldn't happen, given that ENGINE_cmd_is_executable() 333 /* Shouldn't happen, given that ENGINE_cmd_is_executable()
339 * returned success. */ 334 * returned success. */
340 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING, 335 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING,
341 ENGINE_R_INTERNAL_LIST_ERROR); 336 ENGINE_R_INTERNAL_LIST_ERROR);
342 return 0; 337 return 0;
343 } 338 }
344 /* If the command takes no input, there must be no input. And vice 339 /* If the command takes no input, there must be no input. And vice
345 * versa. */ 340 * versa. */
346 if(flags & ENGINE_CMD_FLAG_NO_INPUT) 341 if (flags & ENGINE_CMD_FLAG_NO_INPUT) {
347 { 342 if (arg != NULL) {
348 if(arg != NULL)
349 {
350 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING, 343 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING,
351 ENGINE_R_COMMAND_TAKES_NO_INPUT); 344 ENGINE_R_COMMAND_TAKES_NO_INPUT);
352 return 0; 345 return 0;
353 } 346 }
354 /* We deliberately force the result of ENGINE_ctrl() to 0 or 1 347 /* We deliberately force the result of ENGINE_ctrl() to 0 or 1
355 * rather than returning it as "return data". This is to ensure 348 * rather than returning it as "return data". This is to ensure
356 * usage of these commands is consistent across applications and 349 * usage of these commands is consistent across applications and
357 * that certain applications don't understand it one way, and 350 * that certain applications don't understand it one way, and
358 * others another. */ 351 * others another. */
359 if(ENGINE_ctrl(e, num, 0, (void *)arg, NULL) > 0) 352 if (ENGINE_ctrl(e, num, 0, (void *)arg, NULL) > 0)
360 return 1; 353 return 1;
361 return 0; 354 return 0;
362 } 355 }
363 /* So, we require input */ 356 /* So, we require input */
364 if(arg == NULL) 357 if (arg == NULL) {
365 {
366 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING, 358 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING,
367 ENGINE_R_COMMAND_TAKES_INPUT); 359 ENGINE_R_COMMAND_TAKES_INPUT);
368 return 0; 360 return 0;
369 } 361 }
370 /* If it takes string input, that's easy */ 362 /* If it takes string input, that's easy */
371 if(flags & ENGINE_CMD_FLAG_STRING) 363 if (flags & ENGINE_CMD_FLAG_STRING) {
372 {
373 /* Same explanation as above */ 364 /* Same explanation as above */
374 if(ENGINE_ctrl(e, num, 0, (void *)arg, NULL) > 0) 365 if (ENGINE_ctrl(e, num, 0, (void *)arg, NULL) > 0)
375 return 1; 366 return 1;
376 return 0; 367 return 0;
377 } 368 }
378 /* If it doesn't take numeric either, then it is unsupported for use in 369 /* If it doesn't take numeric either, then it is unsupported for use in
379 * a config-setting situation, which is what this function is for. This 370 * a config-setting situation, which is what this function is for. This
380 * should never happen though, because ENGINE_cmd_is_executable() was 371 * should never happen though, because ENGINE_cmd_is_executable() was
381 * used. */ 372 * used. */
382 if(!(flags & ENGINE_CMD_FLAG_NUMERIC)) 373 if (!(flags & ENGINE_CMD_FLAG_NUMERIC)) {
383 {
384 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING, 374 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING,
385 ENGINE_R_INTERNAL_LIST_ERROR); 375 ENGINE_R_INTERNAL_LIST_ERROR);
386 return 0; 376 return 0;
387 } 377 }
388 l = strtol(arg, &ptr, 10); 378 l = strtol(arg, &ptr, 10);
389 if((arg == ptr) || (*ptr != '\0')) 379 if ((arg == ptr) || (*ptr != '\0')) {
390 {
391 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING, 380 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING,
392 ENGINE_R_ARGUMENT_IS_NOT_A_NUMBER); 381 ENGINE_R_ARGUMENT_IS_NOT_A_NUMBER);
393 return 0; 382 return 0;
394 } 383 }
395 /* Force the result of the control command to 0 or 1, for the reasons 384 /* Force the result of the control command to 0 or 1, for the reasons
396 * mentioned before. */ 385 * mentioned before. */
397 if(ENGINE_ctrl(e, num, l, NULL, NULL) > 0) 386 if (ENGINE_ctrl(e, num, l, NULL, NULL) > 0)
398 return 1; 387 return 1;
399 return 0; 388 return 0;
400 } 389}