提交 2cd3ad9b 编写于 作者: R Richard Levitte

Modify "openssl engine" to handle and display internal control

commands appropriately.
上级 323f289c
...@@ -72,9 +72,10 @@ ...@@ -72,9 +72,10 @@
static char *engine_usage[]={ static char *engine_usage[]={
"usage: engine opts [engine ...]\n", "usage: engine opts [engine ...]\n",
" -v[v[v]] - verbose mode, for each engine, list its 'control commands'\n", " -v[v[v[v]]] - verbose mode, for each engine, list its 'control commands'\n",
" -vv will additionally display each command's description\n", " -vv will additionally display each command's description\n",
" -vvv will also add the input flags for each command\n", " -vvv will also add the input flags for each command\n",
" -vvvv will also show internal input flags\n",
" -c - for each engine, also list the capabilities\n", " -c - for each engine, also list the capabilities\n",
" -t - for each engine, check that they are really available\n", " -t - for each engine, check that they are really available\n",
" -pre <cmd> - runs command 'cmd' against the ENGINE before any attempts\n", " -pre <cmd> - runs command 'cmd' against the ENGINE before any attempts\n",
...@@ -135,8 +136,20 @@ static int util_flags(BIO *bio_out, unsigned int flags, const char *indent) ...@@ -135,8 +136,20 @@ static int util_flags(BIO *bio_out, unsigned int flags, const char *indent)
BIO_printf(bio_out, "<no flags>\n"); BIO_printf(bio_out, "<no flags>\n");
return 1; return 1;
} }
/* If the object is internal, mark it in a way that shows instead of
* having it part of all the other flags, even if it really is. */
if(flags & ENGINE_CMD_FLAG_INTERNAL)
{
BIO_printf(bio_out, "[Internal] ");
}
if(flags & ENGINE_CMD_FLAG_NUMERIC) if(flags & ENGINE_CMD_FLAG_NUMERIC)
{ {
if(started)
{
BIO_printf(bio_out, "|");
err = 1;
}
BIO_printf(bio_out, "NUMERIC"); BIO_printf(bio_out, "NUMERIC");
started = 1; started = 1;
} }
...@@ -167,7 +180,8 @@ static int util_flags(BIO *bio_out, unsigned int flags, const char *indent) ...@@ -167,7 +180,8 @@ static int util_flags(BIO *bio_out, unsigned int flags, const char *indent)
/* Check for unknown flags */ /* Check for unknown flags */
flags = flags & ~ENGINE_CMD_FLAG_NUMERIC & flags = flags & ~ENGINE_CMD_FLAG_NUMERIC &
~ENGINE_CMD_FLAG_STRING & ~ENGINE_CMD_FLAG_STRING &
~ENGINE_CMD_FLAG_NO_INPUT; ~ENGINE_CMD_FLAG_NO_INPUT &
~ENGINE_CMD_FLAG_INTERNAL;
if(flags) if(flags)
{ {
if(started) BIO_printf(bio_out, "|"); if(started) BIO_printf(bio_out, "|");
...@@ -205,60 +219,63 @@ static int util_verbose(ENGINE *e, int verbose, BIO *bio_out, const char *indent ...@@ -205,60 +219,63 @@ static int util_verbose(ENGINE *e, int verbose, BIO *bio_out, const char *indent
goto err; goto err;
do { do {
int len; int len;
/* Get the command name */
if((len = ENGINE_ctrl(e, ENGINE_CTRL_GET_NAME_LEN_FROM_CMD, num,
NULL, NULL)) <= 0)
goto err;
if((name = OPENSSL_malloc(len + 1)) == NULL)
goto err;
if(ENGINE_ctrl(e, ENGINE_CTRL_GET_NAME_FROM_CMD, num, name,
NULL) <= 0)
goto err;
/* Get the command description */
if((len = ENGINE_ctrl(e, ENGINE_CTRL_GET_DESC_LEN_FROM_CMD, num,
NULL, NULL)) < 0)
goto err;
if(len > 0)
{
if((desc = OPENSSL_malloc(len + 1)) == NULL)
goto err;
if(ENGINE_ctrl(e, ENGINE_CTRL_GET_DESC_FROM_CMD, num, desc,
NULL) <= 0)
goto err;
}
/* Get the command input flags */ /* Get the command input flags */
if((flags = ENGINE_ctrl(e, ENGINE_CTRL_GET_CMD_FLAGS, num, if((flags = ENGINE_ctrl(e, ENGINE_CTRL_GET_CMD_FLAGS, num,
NULL, NULL)) < 0) NULL, NULL)) < 0)
goto err; goto err;
/* Now decide on the output */ if (!(flags & ENGINE_CMD_FLAG_INTERNAL) || verbose >= 4)
if(xpos == 0) {
/* Do an indent */ /* Get the command name */
xpos = BIO_printf(bio_out, indent); if((len = ENGINE_ctrl(e, ENGINE_CTRL_GET_NAME_LEN_FROM_CMD, num,
else NULL, NULL)) <= 0)
/* Otherwise prepend a ", " */ goto err;
xpos += BIO_printf(bio_out, ", "); if((name = OPENSSL_malloc(len + 1)) == NULL)
if(verbose == 1) goto err;
{ if(ENGINE_ctrl(e, ENGINE_CTRL_GET_NAME_FROM_CMD, num, name,
/* We're just listing names, comma-delimited */ NULL) <= 0)
if((xpos > (int)strlen(indent)) && goto err;
/* Get the command description */
if((len = ENGINE_ctrl(e, ENGINE_CTRL_GET_DESC_LEN_FROM_CMD, num,
NULL, NULL)) < 0)
goto err;
if(len > 0)
{
if((desc = OPENSSL_malloc(len + 1)) == NULL)
goto err;
if(ENGINE_ctrl(e, ENGINE_CTRL_GET_DESC_FROM_CMD, num, desc,
NULL) <= 0)
goto err;
}
/* Now decide on the output */
if(xpos == 0)
/* Do an indent */
xpos = BIO_printf(bio_out, indent);
else
/* Otherwise prepend a ", " */
xpos += BIO_printf(bio_out, ", ");
if(verbose == 1)
{
/* We're just listing names, comma-delimited */
if((xpos > (int)strlen(indent)) &&
(xpos + (int)strlen(name) > line_wrap)) (xpos + (int)strlen(name) > line_wrap))
{ {
BIO_printf(bio_out, "\n"); BIO_printf(bio_out, "\n");
xpos = BIO_printf(bio_out, indent); xpos = BIO_printf(bio_out, indent);
} }
xpos += BIO_printf(bio_out, "%s", name); xpos += BIO_printf(bio_out, "%s", name);
} }
else else
{ {
/* We're listing names plus descriptions */ /* We're listing names plus descriptions */
BIO_printf(bio_out, "%s: %s\n", name, BIO_printf(bio_out, "%s: %s\n", name,
(desc == NULL) ? "<no description>" : desc); (desc == NULL) ? "<no description>" : desc);
/* ... and sometimes input flags */ /* ... and sometimes input flags */
if((verbose == 3) && !util_flags(bio_out, flags, if((verbose >= 3) && !util_flags(bio_out, flags,
indent)) indent))
goto err; goto err;
xpos = 0; xpos = 0;
} }
}
OPENSSL_free(name); name = NULL; OPENSSL_free(name); name = NULL;
if(desc) { OPENSSL_free(desc); desc = NULL; } if(desc) { OPENSSL_free(desc); desc = NULL; }
/* Move to the next command */ /* Move to the next command */
...@@ -355,7 +372,7 @@ int MAIN(int argc, char **argv) ...@@ -355,7 +372,7 @@ int MAIN(int argc, char **argv)
{ {
if(strspn(*argv + 1, "v") < strlen(*argv + 1)) if(strspn(*argv + 1, "v") < strlen(*argv + 1))
goto skip_arg_loop; goto skip_arg_loop;
if((verbose=strlen(*argv + 1)) > 3) if((verbose=strlen(*argv + 1)) > 4)
goto skip_arg_loop; goto skip_arg_loop;
} }
else if (strcmp(*argv,"-c") == 0) else if (strcmp(*argv,"-c") == 0)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册