10Sstevel@tonic-gate /* crypto/engine/eng_ctrl.c */
20Sstevel@tonic-gate /* ====================================================================
30Sstevel@tonic-gate * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved.
40Sstevel@tonic-gate *
50Sstevel@tonic-gate * Redistribution and use in source and binary forms, with or without
60Sstevel@tonic-gate * modification, are permitted provided that the following conditions
70Sstevel@tonic-gate * are met:
80Sstevel@tonic-gate *
90Sstevel@tonic-gate * 1. Redistributions of source code must retain the above copyright
100Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer.
110Sstevel@tonic-gate *
120Sstevel@tonic-gate * 2. Redistributions in binary form must reproduce the above copyright
130Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer in
140Sstevel@tonic-gate * the documentation and/or other materials provided with the
150Sstevel@tonic-gate * distribution.
160Sstevel@tonic-gate *
170Sstevel@tonic-gate * 3. All advertising materials mentioning features or use of this
180Sstevel@tonic-gate * software must display the following acknowledgment:
190Sstevel@tonic-gate * "This product includes software developed by the OpenSSL Project
200Sstevel@tonic-gate * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
210Sstevel@tonic-gate *
220Sstevel@tonic-gate * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
230Sstevel@tonic-gate * endorse or promote products derived from this software without
240Sstevel@tonic-gate * prior written permission. For written permission, please contact
250Sstevel@tonic-gate * licensing@OpenSSL.org.
260Sstevel@tonic-gate *
270Sstevel@tonic-gate * 5. Products derived from this software may not be called "OpenSSL"
280Sstevel@tonic-gate * nor may "OpenSSL" appear in their names without prior written
290Sstevel@tonic-gate * permission of the OpenSSL Project.
300Sstevel@tonic-gate *
310Sstevel@tonic-gate * 6. Redistributions of any form whatsoever must retain the following
320Sstevel@tonic-gate * acknowledgment:
330Sstevel@tonic-gate * "This product includes software developed by the OpenSSL Project
340Sstevel@tonic-gate * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
350Sstevel@tonic-gate *
360Sstevel@tonic-gate * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
370Sstevel@tonic-gate * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
380Sstevel@tonic-gate * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
390Sstevel@tonic-gate * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
400Sstevel@tonic-gate * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
410Sstevel@tonic-gate * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
420Sstevel@tonic-gate * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
430Sstevel@tonic-gate * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
440Sstevel@tonic-gate * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
450Sstevel@tonic-gate * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
460Sstevel@tonic-gate * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
470Sstevel@tonic-gate * OF THE POSSIBILITY OF SUCH DAMAGE.
480Sstevel@tonic-gate * ====================================================================
490Sstevel@tonic-gate *
500Sstevel@tonic-gate * This product includes cryptographic software written by Eric Young
510Sstevel@tonic-gate * (eay@cryptsoft.com). This product includes software written by Tim
520Sstevel@tonic-gate * Hudson (tjh@cryptsoft.com).
530Sstevel@tonic-gate *
540Sstevel@tonic-gate */
550Sstevel@tonic-gate
560Sstevel@tonic-gate #include "eng_int.h"
570Sstevel@tonic-gate
580Sstevel@tonic-gate /* When querying a ENGINE-specific control command's 'description', this string
590Sstevel@tonic-gate * is used if the ENGINE_CMD_DEFN has cmd_desc set to NULL. */
600Sstevel@tonic-gate static const char *int_no_description = "";
610Sstevel@tonic-gate
620Sstevel@tonic-gate /* These internal functions handle 'CMD'-related control commands when the
630Sstevel@tonic-gate * ENGINE in question has asked us to take care of it (ie. the ENGINE did not
640Sstevel@tonic-gate * set the ENGINE_FLAGS_MANUAL_CMD_CTRL flag. */
650Sstevel@tonic-gate
int_ctrl_cmd_is_null(const ENGINE_CMD_DEFN * defn)660Sstevel@tonic-gate static int int_ctrl_cmd_is_null(const ENGINE_CMD_DEFN *defn)
670Sstevel@tonic-gate {
680Sstevel@tonic-gate if((defn->cmd_num == 0) || (defn->cmd_name == NULL))
690Sstevel@tonic-gate return 1;
700Sstevel@tonic-gate return 0;
710Sstevel@tonic-gate }
720Sstevel@tonic-gate
int_ctrl_cmd_by_name(const ENGINE_CMD_DEFN * defn,const char * s)730Sstevel@tonic-gate static int int_ctrl_cmd_by_name(const ENGINE_CMD_DEFN *defn, const char *s)
740Sstevel@tonic-gate {
750Sstevel@tonic-gate int idx = 0;
760Sstevel@tonic-gate while(!int_ctrl_cmd_is_null(defn) && (strcmp(defn->cmd_name, s) != 0))
770Sstevel@tonic-gate {
780Sstevel@tonic-gate idx++;
790Sstevel@tonic-gate defn++;
800Sstevel@tonic-gate }
810Sstevel@tonic-gate if(int_ctrl_cmd_is_null(defn))
820Sstevel@tonic-gate /* The given name wasn't found */
830Sstevel@tonic-gate return -1;
840Sstevel@tonic-gate return idx;
850Sstevel@tonic-gate }
860Sstevel@tonic-gate
int_ctrl_cmd_by_num(const ENGINE_CMD_DEFN * defn,unsigned int num)870Sstevel@tonic-gate static int int_ctrl_cmd_by_num(const ENGINE_CMD_DEFN *defn, unsigned int num)
880Sstevel@tonic-gate {
890Sstevel@tonic-gate int idx = 0;
900Sstevel@tonic-gate /* NB: It is stipulated that 'cmd_defn' lists are ordered by cmd_num. So
910Sstevel@tonic-gate * our searches don't need to take any longer than necessary. */
920Sstevel@tonic-gate while(!int_ctrl_cmd_is_null(defn) && (defn->cmd_num < num))
930Sstevel@tonic-gate {
940Sstevel@tonic-gate idx++;
950Sstevel@tonic-gate defn++;
960Sstevel@tonic-gate }
970Sstevel@tonic-gate if(defn->cmd_num == num)
980Sstevel@tonic-gate return idx;
990Sstevel@tonic-gate /* The given cmd_num wasn't found */
1000Sstevel@tonic-gate return -1;
1010Sstevel@tonic-gate }
1020Sstevel@tonic-gate
int_ctrl_helper(ENGINE * e,int cmd,long i,void * p,void (* f)(void))103*2139Sjp161948 static int int_ctrl_helper(ENGINE *e, int cmd, long i, void *p,
104*2139Sjp161948 void (*f)(void))
1050Sstevel@tonic-gate {
1060Sstevel@tonic-gate int idx;
1070Sstevel@tonic-gate char *s = (char *)p;
1080Sstevel@tonic-gate /* Take care of the easy one first (eg. it requires no searches) */
1090Sstevel@tonic-gate if(cmd == ENGINE_CTRL_GET_FIRST_CMD_TYPE)
1100Sstevel@tonic-gate {
1110Sstevel@tonic-gate if((e->cmd_defns == NULL) || int_ctrl_cmd_is_null(e->cmd_defns))
1120Sstevel@tonic-gate return 0;
1130Sstevel@tonic-gate return e->cmd_defns->cmd_num;
1140Sstevel@tonic-gate }
1150Sstevel@tonic-gate /* One or two commands require that "p" be a valid string buffer */
1160Sstevel@tonic-gate if((cmd == ENGINE_CTRL_GET_CMD_FROM_NAME) ||
1170Sstevel@tonic-gate (cmd == ENGINE_CTRL_GET_NAME_FROM_CMD) ||
1180Sstevel@tonic-gate (cmd == ENGINE_CTRL_GET_DESC_FROM_CMD))
1190Sstevel@tonic-gate {
1200Sstevel@tonic-gate if(s == NULL)
1210Sstevel@tonic-gate {
1220Sstevel@tonic-gate ENGINEerr(ENGINE_F_INT_CTRL_HELPER,
1230Sstevel@tonic-gate ERR_R_PASSED_NULL_PARAMETER);
1240Sstevel@tonic-gate return -1;
1250Sstevel@tonic-gate }
1260Sstevel@tonic-gate }
1270Sstevel@tonic-gate /* Now handle cmd_name -> cmd_num conversion */
1280Sstevel@tonic-gate if(cmd == ENGINE_CTRL_GET_CMD_FROM_NAME)
1290Sstevel@tonic-gate {
1300Sstevel@tonic-gate if((e->cmd_defns == NULL) || ((idx = int_ctrl_cmd_by_name(
1310Sstevel@tonic-gate e->cmd_defns, s)) < 0))
1320Sstevel@tonic-gate {
1330Sstevel@tonic-gate ENGINEerr(ENGINE_F_INT_CTRL_HELPER,
1340Sstevel@tonic-gate ENGINE_R_INVALID_CMD_NAME);
1350Sstevel@tonic-gate return -1;
1360Sstevel@tonic-gate }
1370Sstevel@tonic-gate return e->cmd_defns[idx].cmd_num;
1380Sstevel@tonic-gate }
1390Sstevel@tonic-gate /* For the rest of the commands, the 'long' argument must specify a
1400Sstevel@tonic-gate * valie command number - so we need to conduct a search. */
1410Sstevel@tonic-gate if((e->cmd_defns == NULL) || ((idx = int_ctrl_cmd_by_num(e->cmd_defns,
1420Sstevel@tonic-gate (unsigned int)i)) < 0))
1430Sstevel@tonic-gate {
1440Sstevel@tonic-gate ENGINEerr(ENGINE_F_INT_CTRL_HELPER,
1450Sstevel@tonic-gate ENGINE_R_INVALID_CMD_NUMBER);
1460Sstevel@tonic-gate return -1;
1470Sstevel@tonic-gate }
1480Sstevel@tonic-gate /* Now the logic splits depending on command type */
1490Sstevel@tonic-gate switch(cmd)
1500Sstevel@tonic-gate {
1510Sstevel@tonic-gate case ENGINE_CTRL_GET_NEXT_CMD_TYPE:
1520Sstevel@tonic-gate idx++;
1530Sstevel@tonic-gate if(int_ctrl_cmd_is_null(e->cmd_defns + idx))
1540Sstevel@tonic-gate /* end-of-list */
1550Sstevel@tonic-gate return 0;
1560Sstevel@tonic-gate else
1570Sstevel@tonic-gate return e->cmd_defns[idx].cmd_num;
1580Sstevel@tonic-gate case ENGINE_CTRL_GET_NAME_LEN_FROM_CMD:
1590Sstevel@tonic-gate return strlen(e->cmd_defns[idx].cmd_name);
1600Sstevel@tonic-gate case ENGINE_CTRL_GET_NAME_FROM_CMD:
1610Sstevel@tonic-gate return BIO_snprintf(s,strlen(e->cmd_defns[idx].cmd_name) + 1,
1620Sstevel@tonic-gate "%s", e->cmd_defns[idx].cmd_name);
1630Sstevel@tonic-gate case ENGINE_CTRL_GET_DESC_LEN_FROM_CMD:
1640Sstevel@tonic-gate if(e->cmd_defns[idx].cmd_desc)
1650Sstevel@tonic-gate return strlen(e->cmd_defns[idx].cmd_desc);
1660Sstevel@tonic-gate return strlen(int_no_description);
1670Sstevel@tonic-gate case ENGINE_CTRL_GET_DESC_FROM_CMD:
1680Sstevel@tonic-gate if(e->cmd_defns[idx].cmd_desc)
1690Sstevel@tonic-gate return BIO_snprintf(s,
1700Sstevel@tonic-gate strlen(e->cmd_defns[idx].cmd_desc) + 1,
1710Sstevel@tonic-gate "%s", e->cmd_defns[idx].cmd_desc);
1720Sstevel@tonic-gate return BIO_snprintf(s, strlen(int_no_description) + 1,"%s",
1730Sstevel@tonic-gate int_no_description);
1740Sstevel@tonic-gate case ENGINE_CTRL_GET_CMD_FLAGS:
1750Sstevel@tonic-gate return e->cmd_defns[idx].cmd_flags;
1760Sstevel@tonic-gate }
1770Sstevel@tonic-gate /* Shouldn't really be here ... */
1780Sstevel@tonic-gate ENGINEerr(ENGINE_F_INT_CTRL_HELPER,ENGINE_R_INTERNAL_LIST_ERROR);
1790Sstevel@tonic-gate return -1;
1800Sstevel@tonic-gate }
1810Sstevel@tonic-gate
ENGINE_ctrl(ENGINE * e,int cmd,long i,void * p,void (* f)(void))182*2139Sjp161948 int ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void))
1830Sstevel@tonic-gate {
1840Sstevel@tonic-gate int ctrl_exists, ref_exists;
1850Sstevel@tonic-gate if(e == NULL)
1860Sstevel@tonic-gate {
1870Sstevel@tonic-gate ENGINEerr(ENGINE_F_ENGINE_CTRL,ERR_R_PASSED_NULL_PARAMETER);
1880Sstevel@tonic-gate return 0;
1890Sstevel@tonic-gate }
1900Sstevel@tonic-gate CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
1910Sstevel@tonic-gate ref_exists = ((e->struct_ref > 0) ? 1 : 0);
1920Sstevel@tonic-gate CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
1930Sstevel@tonic-gate ctrl_exists = ((e->ctrl == NULL) ? 0 : 1);
1940Sstevel@tonic-gate if(!ref_exists)
1950Sstevel@tonic-gate {
1960Sstevel@tonic-gate ENGINEerr(ENGINE_F_ENGINE_CTRL,ENGINE_R_NO_REFERENCE);
1970Sstevel@tonic-gate return 0;
1980Sstevel@tonic-gate }
1990Sstevel@tonic-gate /* Intercept any "root-level" commands before trying to hand them on to
2000Sstevel@tonic-gate * ctrl() handlers. */
2010Sstevel@tonic-gate switch(cmd)
2020Sstevel@tonic-gate {
2030Sstevel@tonic-gate case ENGINE_CTRL_HAS_CTRL_FUNCTION:
2040Sstevel@tonic-gate return ctrl_exists;
2050Sstevel@tonic-gate case ENGINE_CTRL_GET_FIRST_CMD_TYPE:
2060Sstevel@tonic-gate case ENGINE_CTRL_GET_NEXT_CMD_TYPE:
2070Sstevel@tonic-gate case ENGINE_CTRL_GET_CMD_FROM_NAME:
2080Sstevel@tonic-gate case ENGINE_CTRL_GET_NAME_LEN_FROM_CMD:
2090Sstevel@tonic-gate case ENGINE_CTRL_GET_NAME_FROM_CMD:
2100Sstevel@tonic-gate case ENGINE_CTRL_GET_DESC_LEN_FROM_CMD:
2110Sstevel@tonic-gate case ENGINE_CTRL_GET_DESC_FROM_CMD:
2120Sstevel@tonic-gate case ENGINE_CTRL_GET_CMD_FLAGS:
2130Sstevel@tonic-gate if(ctrl_exists && !(e->flags & ENGINE_FLAGS_MANUAL_CMD_CTRL))
2140Sstevel@tonic-gate return int_ctrl_helper(e,cmd,i,p,f);
2150Sstevel@tonic-gate if(!ctrl_exists)
2160Sstevel@tonic-gate {
2170Sstevel@tonic-gate ENGINEerr(ENGINE_F_ENGINE_CTRL,ENGINE_R_NO_CONTROL_FUNCTION);
2180Sstevel@tonic-gate /* For these cmd-related functions, failure is indicated
2190Sstevel@tonic-gate * by a -1 return value (because 0 is used as a valid
2200Sstevel@tonic-gate * return in some places). */
2210Sstevel@tonic-gate return -1;
2220Sstevel@tonic-gate }
2230Sstevel@tonic-gate default:
2240Sstevel@tonic-gate break;
2250Sstevel@tonic-gate }
2260Sstevel@tonic-gate /* Anything else requires a ctrl() handler to exist. */
2270Sstevel@tonic-gate if(!ctrl_exists)
2280Sstevel@tonic-gate {
2290Sstevel@tonic-gate ENGINEerr(ENGINE_F_ENGINE_CTRL,ENGINE_R_NO_CONTROL_FUNCTION);
2300Sstevel@tonic-gate return 0;
2310Sstevel@tonic-gate }
2320Sstevel@tonic-gate return e->ctrl(e, cmd, i, p, f);
2330Sstevel@tonic-gate }
2340Sstevel@tonic-gate
ENGINE_cmd_is_executable(ENGINE * e,int cmd)2350Sstevel@tonic-gate int ENGINE_cmd_is_executable(ENGINE *e, int cmd)
2360Sstevel@tonic-gate {
2370Sstevel@tonic-gate int flags;
2380Sstevel@tonic-gate if((flags = ENGINE_ctrl(e, ENGINE_CTRL_GET_CMD_FLAGS, cmd, NULL, NULL)) < 0)
2390Sstevel@tonic-gate {
2400Sstevel@tonic-gate ENGINEerr(ENGINE_F_ENGINE_CMD_IS_EXECUTABLE,
2410Sstevel@tonic-gate ENGINE_R_INVALID_CMD_NUMBER);
2420Sstevel@tonic-gate return 0;
2430Sstevel@tonic-gate }
2440Sstevel@tonic-gate if(!(flags & ENGINE_CMD_FLAG_NO_INPUT) &&
2450Sstevel@tonic-gate !(flags & ENGINE_CMD_FLAG_NUMERIC) &&
2460Sstevel@tonic-gate !(flags & ENGINE_CMD_FLAG_STRING))
2470Sstevel@tonic-gate return 0;
2480Sstevel@tonic-gate return 1;
2490Sstevel@tonic-gate }
2500Sstevel@tonic-gate
ENGINE_ctrl_cmd(ENGINE * e,const char * cmd_name,long i,void * p,void (* f)(void),int cmd_optional)2510Sstevel@tonic-gate int ENGINE_ctrl_cmd(ENGINE *e, const char *cmd_name,
252*2139Sjp161948 long i, void *p, void (*f)(void), int cmd_optional)
2530Sstevel@tonic-gate {
2540Sstevel@tonic-gate int num;
2550Sstevel@tonic-gate
2560Sstevel@tonic-gate if((e == NULL) || (cmd_name == NULL))
2570Sstevel@tonic-gate {
258*2139Sjp161948 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD,
2590Sstevel@tonic-gate ERR_R_PASSED_NULL_PARAMETER);
2600Sstevel@tonic-gate return 0;
2610Sstevel@tonic-gate }
2620Sstevel@tonic-gate if((e->ctrl == NULL) || ((num = ENGINE_ctrl(e,
2630Sstevel@tonic-gate ENGINE_CTRL_GET_CMD_FROM_NAME,
2640Sstevel@tonic-gate 0, (void *)cmd_name, NULL)) <= 0))
2650Sstevel@tonic-gate {
2660Sstevel@tonic-gate /* If the command didn't *have* to be supported, we fake
2670Sstevel@tonic-gate * success. This allows certain settings to be specified for
2680Sstevel@tonic-gate * multiple ENGINEs and only require a change of ENGINE id
2690Sstevel@tonic-gate * (without having to selectively apply settings). Eg. changing
2700Sstevel@tonic-gate * from a hardware device back to the regular software ENGINE
2710Sstevel@tonic-gate * without editing the config file, etc. */
2720Sstevel@tonic-gate if(cmd_optional)
2730Sstevel@tonic-gate {
2740Sstevel@tonic-gate ERR_clear_error();
2750Sstevel@tonic-gate return 1;
2760Sstevel@tonic-gate }
2770Sstevel@tonic-gate ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD,
2780Sstevel@tonic-gate ENGINE_R_INVALID_CMD_NAME);
2790Sstevel@tonic-gate return 0;
2800Sstevel@tonic-gate }
2810Sstevel@tonic-gate /* Force the result of the control command to 0 or 1, for the reasons
2820Sstevel@tonic-gate * mentioned before. */
2830Sstevel@tonic-gate if (ENGINE_ctrl(e, num, i, p, f))
2840Sstevel@tonic-gate return 1;
2850Sstevel@tonic-gate return 0;
2860Sstevel@tonic-gate }
2870Sstevel@tonic-gate
ENGINE_ctrl_cmd_string(ENGINE * e,const char * cmd_name,const char * arg,int cmd_optional)2880Sstevel@tonic-gate int ENGINE_ctrl_cmd_string(ENGINE *e, const char *cmd_name, const char *arg,
2890Sstevel@tonic-gate int cmd_optional)
2900Sstevel@tonic-gate {
2910Sstevel@tonic-gate int num, flags;
2920Sstevel@tonic-gate long l;
2930Sstevel@tonic-gate char *ptr;
2940Sstevel@tonic-gate if((e == NULL) || (cmd_name == NULL))
2950Sstevel@tonic-gate {
2960Sstevel@tonic-gate ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING,
2970Sstevel@tonic-gate ERR_R_PASSED_NULL_PARAMETER);
2980Sstevel@tonic-gate return 0;
2990Sstevel@tonic-gate }
3000Sstevel@tonic-gate if((e->ctrl == NULL) || ((num = ENGINE_ctrl(e,
3010Sstevel@tonic-gate ENGINE_CTRL_GET_CMD_FROM_NAME,
3020Sstevel@tonic-gate 0, (void *)cmd_name, NULL)) <= 0))
3030Sstevel@tonic-gate {
3040Sstevel@tonic-gate /* If the command didn't *have* to be supported, we fake
3050Sstevel@tonic-gate * success. This allows certain settings to be specified for
3060Sstevel@tonic-gate * multiple ENGINEs and only require a change of ENGINE id
3070Sstevel@tonic-gate * (without having to selectively apply settings). Eg. changing
3080Sstevel@tonic-gate * from a hardware device back to the regular software ENGINE
3090Sstevel@tonic-gate * without editing the config file, etc. */
3100Sstevel@tonic-gate if(cmd_optional)
3110Sstevel@tonic-gate {
3120Sstevel@tonic-gate ERR_clear_error();
3130Sstevel@tonic-gate return 1;
3140Sstevel@tonic-gate }
3150Sstevel@tonic-gate ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING,
3160Sstevel@tonic-gate ENGINE_R_INVALID_CMD_NAME);
3170Sstevel@tonic-gate return 0;
3180Sstevel@tonic-gate }
3190Sstevel@tonic-gate if(!ENGINE_cmd_is_executable(e, num))
3200Sstevel@tonic-gate {
3210Sstevel@tonic-gate ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING,
3220Sstevel@tonic-gate ENGINE_R_CMD_NOT_EXECUTABLE);
3230Sstevel@tonic-gate return 0;
3240Sstevel@tonic-gate }
3250Sstevel@tonic-gate if((flags = ENGINE_ctrl(e, ENGINE_CTRL_GET_CMD_FLAGS, num, NULL, NULL)) < 0)
3260Sstevel@tonic-gate {
3270Sstevel@tonic-gate /* Shouldn't happen, given that ENGINE_cmd_is_executable()
3280Sstevel@tonic-gate * returned success. */
3290Sstevel@tonic-gate ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING,
3300Sstevel@tonic-gate ENGINE_R_INTERNAL_LIST_ERROR);
3310Sstevel@tonic-gate return 0;
3320Sstevel@tonic-gate }
3330Sstevel@tonic-gate /* If the command takes no input, there must be no input. And vice
3340Sstevel@tonic-gate * versa. */
3350Sstevel@tonic-gate if(flags & ENGINE_CMD_FLAG_NO_INPUT)
3360Sstevel@tonic-gate {
3370Sstevel@tonic-gate if(arg != NULL)
3380Sstevel@tonic-gate {
3390Sstevel@tonic-gate ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING,
3400Sstevel@tonic-gate ENGINE_R_COMMAND_TAKES_NO_INPUT);
3410Sstevel@tonic-gate return 0;
3420Sstevel@tonic-gate }
3430Sstevel@tonic-gate /* We deliberately force the result of ENGINE_ctrl() to 0 or 1
3440Sstevel@tonic-gate * rather than returning it as "return data". This is to ensure
3450Sstevel@tonic-gate * usage of these commands is consistent across applications and
3460Sstevel@tonic-gate * that certain applications don't understand it one way, and
3470Sstevel@tonic-gate * others another. */
3480Sstevel@tonic-gate if(ENGINE_ctrl(e, num, 0, (void *)arg, NULL))
3490Sstevel@tonic-gate return 1;
3500Sstevel@tonic-gate return 0;
3510Sstevel@tonic-gate }
3520Sstevel@tonic-gate /* So, we require input */
3530Sstevel@tonic-gate if(arg == NULL)
3540Sstevel@tonic-gate {
3550Sstevel@tonic-gate ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING,
3560Sstevel@tonic-gate ENGINE_R_COMMAND_TAKES_INPUT);
3570Sstevel@tonic-gate return 0;
3580Sstevel@tonic-gate }
3590Sstevel@tonic-gate /* If it takes string input, that's easy */
3600Sstevel@tonic-gate if(flags & ENGINE_CMD_FLAG_STRING)
3610Sstevel@tonic-gate {
3620Sstevel@tonic-gate /* Same explanation as above */
3630Sstevel@tonic-gate if(ENGINE_ctrl(e, num, 0, (void *)arg, NULL))
3640Sstevel@tonic-gate return 1;
3650Sstevel@tonic-gate return 0;
3660Sstevel@tonic-gate }
3670Sstevel@tonic-gate /* If it doesn't take numeric either, then it is unsupported for use in
3680Sstevel@tonic-gate * a config-setting situation, which is what this function is for. This
3690Sstevel@tonic-gate * should never happen though, because ENGINE_cmd_is_executable() was
3700Sstevel@tonic-gate * used. */
3710Sstevel@tonic-gate if(!(flags & ENGINE_CMD_FLAG_NUMERIC))
3720Sstevel@tonic-gate {
3730Sstevel@tonic-gate ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING,
3740Sstevel@tonic-gate ENGINE_R_INTERNAL_LIST_ERROR);
3750Sstevel@tonic-gate return 0;
3760Sstevel@tonic-gate }
3770Sstevel@tonic-gate l = strtol(arg, &ptr, 10);
3780Sstevel@tonic-gate if((arg == ptr) || (*ptr != '\0'))
3790Sstevel@tonic-gate {
3800Sstevel@tonic-gate ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING,
3810Sstevel@tonic-gate ENGINE_R_ARGUMENT_IS_NOT_A_NUMBER);
3820Sstevel@tonic-gate return 0;
3830Sstevel@tonic-gate }
3840Sstevel@tonic-gate /* Force the result of the control command to 0 or 1, for the reasons
3850Sstevel@tonic-gate * mentioned before. */
3860Sstevel@tonic-gate if(ENGINE_ctrl(e, num, l, NULL, NULL))
3870Sstevel@tonic-gate return 1;
3880Sstevel@tonic-gate return 0;
3890Sstevel@tonic-gate }
390