eng_ctrl.c revision 9dc0df1bac950d6e491f9a7c7e4888f2b301cb15
/* crypto/engine/eng_ctrl.c */
/* ====================================================================
* Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
*
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* licensing@OpenSSL.org.
*
* 5. Products derived from this software may not be called "OpenSSL"
* nor may "OpenSSL" appear in their names without prior written
* permission of the OpenSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
* This product includes cryptographic software written by Eric Young
* (eay@cryptsoft.com). This product includes software written by Tim
* Hudson (tjh@cryptsoft.com).
*
*/
#include "eng_int.h"
/* When querying a ENGINE-specific control command's 'description', this string
* is used if the ENGINE_CMD_DEFN has cmd_desc set to NULL. */
static const char *int_no_description = "";
/* These internal functions handle 'CMD'-related control commands when the
* ENGINE in question has asked us to take care of it (ie. the ENGINE did not
* set the ENGINE_FLAGS_MANUAL_CMD_CTRL flag. */
{
return 1;
return 0;
}
{
int idx = 0;
{
idx++;
defn++;
}
if(int_ctrl_cmd_is_null(defn))
/* The given name wasn't found */
return -1;
return idx;
}
{
int idx = 0;
/* NB: It is stipulated that 'cmd_defn' lists are ordered by cmd_num. So
* our searches don't need to take any longer than necessary. */
{
idx++;
defn++;
}
return idx;
/* The given cmd_num wasn't found */
return -1;
}
void (*f)(void))
{
int idx;
char *s = (char *)p;
/* Take care of the easy one first (eg. it requires no searches) */
{
return 0;
}
/* One or two commands require that "p" be a valid string buffer */
if((cmd == ENGINE_CTRL_GET_CMD_FROM_NAME) ||
(cmd == ENGINE_CTRL_GET_NAME_FROM_CMD) ||
{
if(s == NULL)
{
return -1;
}
}
/* Now handle cmd_name -> cmd_num conversion */
if(cmd == ENGINE_CTRL_GET_CMD_FROM_NAME)
{
e->cmd_defns, s)) < 0))
{
return -1;
}
}
/* For the rest of the commands, the 'long' argument must specify a
* valie command number - so we need to conduct a search. */
(unsigned int)i)) < 0))
{
return -1;
}
/* Now the logic splits depending on command type */
switch(cmd)
{
idx++;
/* end-of-list */
return 0;
else
return strlen(int_no_description);
return BIO_snprintf(s,
}
/* Shouldn't really be here ... */
return -1;
}
{
int ctrl_exists, ref_exists;
if(e == NULL)
{
return 0;
}
if(!ref_exists)
{
return 0;
}
/* Intercept any "root-level" commands before trying to hand them on to
* ctrl() handlers. */
switch(cmd)
{
return ctrl_exists;
return int_ctrl_helper(e,cmd,i,p,f);
if(!ctrl_exists)
{
/* For these cmd-related functions, failure is indicated
* by a -1 return value (because 0 is used as a valid
* return in some places). */
return -1;
}
default:
break;
}
/* Anything else requires a ctrl() handler to exist. */
if(!ctrl_exists)
{
return 0;
}
}
{
int flags;
{
return 0;
}
if(!(flags & ENGINE_CMD_FLAG_NO_INPUT) &&
!(flags & ENGINE_CMD_FLAG_NUMERIC) &&
!(flags & ENGINE_CMD_FLAG_STRING))
return 0;
return 1;
}
long i, void *p, void (*f)(void), int cmd_optional)
{
int num;
{
return 0;
}
{
/* If the command didn't *have* to be supported, we fake
* success. This allows certain settings to be specified for
* multiple ENGINEs and only require a change of ENGINE id
* (without having to selectively apply settings). Eg. changing
* from a hardware device back to the regular software ENGINE
* without editing the config file, etc. */
if(cmd_optional)
{
return 1;
}
return 0;
}
/* Force the result of the control command to 0 or 1, for the reasons
* mentioned before. */
if (ENGINE_ctrl(e, num, i, p, f))
return 1;
return 0;
}
int cmd_optional)
{
long l;
char *ptr;
{
return 0;
}
{
/* If the command didn't *have* to be supported, we fake
* success. This allows certain settings to be specified for
* multiple ENGINEs and only require a change of ENGINE id
* (without having to selectively apply settings). Eg. changing
* from a hardware device back to the regular software ENGINE
* without editing the config file, etc. */
if(cmd_optional)
{
return 1;
}
return 0;
}
if(!ENGINE_cmd_is_executable(e, num))
{
return 0;
}
{
/* Shouldn't happen, given that ENGINE_cmd_is_executable()
* returned success. */
return 0;
}
/* If the command takes no input, there must be no input. And vice
* versa. */
{
{
return 0;
}
/* We deliberately force the result of ENGINE_ctrl() to 0 or 1
* rather than returning it as "return data". This is to ensure
* usage of these commands is consistent across applications and
* that certain applications don't understand it one way, and
* others another. */
return 1;
return 0;
}
/* So, we require input */
{
return 0;
}
/* If it takes string input, that's easy */
if(flags & ENGINE_CMD_FLAG_STRING)
{
/* Same explanation as above */
return 1;
return 0;
}
/* If it doesn't take numeric either, then it is unsupported for use in
* a config-setting situation, which is what this function is for. This
* should never happen though, because ENGINE_cmd_is_executable() was
* used. */
if(!(flags & ENGINE_CMD_FLAG_NUMERIC))
{
return 0;
}
{
return 0;
}
/* Force the result of the control command to 0 or 1, for the reasons
* mentioned before. */
return 1;
return 0;
}