Main Page | Class List | Directories | File List | Class Members | File Members

engine.c File Reference

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "apps.h"
#include <openssl/err.h>
#include <openssl/engine.h>
#include <openssl/ssl.h>

Go to the source code of this file.

Defines

#define PROG   engine_main

Functions

static void identity (void *ptr)
static int append_buf (char **buf, const char *s, int *size, int step)
static int util_flags (BIO *bio_out, unsigned int flags, const char *indent)
static int util_verbose (ENGINE *e, int verbose, BIO *bio_out, const char *indent)
static void util_do_cmds (ENGINE *e, STACK *cmds, BIO *bio_out, const char *indent)
int MAIN (int, char **)

Variables

static const char * engine_usage []


Define Documentation

#define PROG   engine_main
 

Definition at line 73 of file engine.c.


Function Documentation

static int append_buf char **  buf,
const char *  s,
int *  size,
int  step
[static]
 

Definition at line 100 of file engine.c.

References BUF_strlcat(), OPENSSL_malloc, and OPENSSL_realloc.

00101         {
00102         int l = strlen(s);
00103 
00104         if (*buf == NULL)
00105                 {
00106                 *size = step;
00107                 *buf = OPENSSL_malloc(*size);
00108                 if (*buf == NULL)
00109                         return 0;
00110                 **buf = '\0';
00111                 }
00112 
00113         if (**buf != '\0')
00114                 l += 2;         /* ", " */
00115 
00116         if (strlen(*buf) + strlen(s) >= (unsigned int)*size)
00117                 {
00118                 *size += step;
00119                 *buf = OPENSSL_realloc(*buf, *size);
00120                 }
00121 
00122         if (*buf == NULL)
00123                 return 0;
00124 
00125         if (**buf != '\0')
00126                 BUF_strlcat(*buf, ", ", *size);
00127         BUF_strlcat(*buf, s, *size);
00128 
00129         return 1;
00130         }

static void identity void *  ptr  )  [static]
 

Definition at line 95 of file engine.c.

Referenced by util_verbose().

00096         {
00097         return;
00098         }

int MAIN int  ,
char ** 
 

static void util_do_cmds ENGINE e,
STACK cmds,
BIO bio_out,
const char *  indent
[static]
 

Definition at line 298 of file engine.c.

References BIO_printf(), ENGINE_ctrl_cmd_string(), ERR_print_errors(), int(), num, sk_num(), and sk_value().

00299         {
00300         int loop, res, num = sk_num(cmds);
00301         if(num < 0)
00302                 {
00303                 BIO_printf(bio_out, "[Error]: internal stack error\n");
00304                 return;
00305                 }
00306         for(loop = 0; loop < num; loop++)
00307                 {
00308                 char buf[256];
00309                 const char *cmd, *arg;
00310                 cmd = sk_value(cmds, loop);
00311                 res = 1; /* assume success */
00312                 /* Check if this command has no ":arg" */
00313                 if((arg = strstr(cmd, ":")) == NULL)
00314                         {
00315                         if(!ENGINE_ctrl_cmd_string(e, cmd, NULL, 0))
00316                                 res = 0;
00317                         }
00318                 else
00319                         {
00320                         if((int)(arg - cmd) > 254)
00321                                 {
00322                                 BIO_printf(bio_out,"[Error]: command name too long\n");
00323                                 return;
00324                                 }
00325                         memcpy(buf, cmd, (int)(arg - cmd));
00326                         buf[arg-cmd] = '\0';
00327                         arg++; /* Move past the ":" */
00328                         /* Call the command with the argument */
00329                         if(!ENGINE_ctrl_cmd_string(e, buf, arg, 0))
00330                                 res = 0;
00331                         }
00332                 if(res)
00333                         BIO_printf(bio_out, "[Success]: %s\n", cmd);
00334                 else
00335                         {
00336                         BIO_printf(bio_out, "[Failure]: %s\n", cmd);
00337                         ERR_print_errors(bio_out);
00338                         }
00339                 }
00340         }

static int util_flags BIO bio_out,
unsigned int  flags,
const char *  indent
[static]
 

Definition at line 132 of file engine.c.

References BIO_printf(), ENGINE_CMD_FLAG_INTERNAL, ENGINE_CMD_FLAG_NO_INPUT, ENGINE_CMD_FLAG_NUMERIC, and ENGINE_CMD_FLAG_STRING.

Referenced by util_verbose().

00133         {
00134         int started = 0, err = 0;
00135         /* Indent before displaying input flags */
00136         BIO_printf(bio_out, "%s%s(input flags): ", indent, indent);
00137         if(flags == 0)
00138                 {
00139                 BIO_printf(bio_out, "<no flags>\n");
00140                 return 1;
00141                 }
00142         /* If the object is internal, mark it in a way that shows instead of
00143          * having it part of all the other flags, even if it really is. */
00144         if(flags & ENGINE_CMD_FLAG_INTERNAL)
00145                 {
00146                 BIO_printf(bio_out, "[Internal] ");
00147                 }
00148 
00149         if(flags & ENGINE_CMD_FLAG_NUMERIC)
00150                 {
00151                 if(started)
00152                         {
00153                         BIO_printf(bio_out, "|");
00154                         err = 1;
00155                         }
00156                 BIO_printf(bio_out, "NUMERIC");
00157                 started = 1;
00158                 }
00159         /* Now we check that no combinations of the mutually exclusive NUMERIC,
00160          * STRING, and NO_INPUT flags have been used. Future flags that can be
00161          * OR'd together with these would need to added after these to preserve
00162          * the testing logic. */
00163         if(flags & ENGINE_CMD_FLAG_STRING)
00164                 {
00165                 if(started)
00166                         {
00167                         BIO_printf(bio_out, "|");
00168                         err = 1;
00169                         }
00170                 BIO_printf(bio_out, "STRING");
00171                 started = 1;
00172                 }
00173         if(flags & ENGINE_CMD_FLAG_NO_INPUT)
00174                 {
00175                 if(started)
00176                         {
00177                         BIO_printf(bio_out, "|");
00178                         err = 1;
00179                         }
00180                 BIO_printf(bio_out, "NO_INPUT");
00181                 started = 1;
00182                 }
00183         /* Check for unknown flags */
00184         flags = flags & ~ENGINE_CMD_FLAG_NUMERIC &
00185                         ~ENGINE_CMD_FLAG_STRING &
00186                         ~ENGINE_CMD_FLAG_NO_INPUT &
00187                         ~ENGINE_CMD_FLAG_INTERNAL;
00188         if(flags)
00189                 {
00190                 if(started) BIO_printf(bio_out, "|");
00191                 BIO_printf(bio_out, "<0x%04X>", flags);
00192                 }
00193         if(err)
00194                 BIO_printf(bio_out, "  <illegal flags!>");
00195         BIO_printf(bio_out, "\n");
00196         return 1;
00197         }

static int util_verbose ENGINE e,
int  verbose,
BIO bio_out,
const char *  indent
[static]
 

Definition at line 199 of file engine.c.

References BIO_printf(), ENGINE_CMD_FLAG_INTERNAL, ENGINE_ctrl(), ENGINE_CTRL_GET_CMD_FLAGS, ENGINE_CTRL_GET_DESC_FROM_CMD, ENGINE_CTRL_GET_DESC_LEN_FROM_CMD, ENGINE_CTRL_GET_FIRST_CMD_TYPE, ENGINE_CTRL_GET_NAME_FROM_CMD, ENGINE_CTRL_GET_NAME_LEN_FROM_CMD, ENGINE_CTRL_GET_NEXT_CMD_TYPE, ENGINE_CTRL_HAS_CTRL_FUNCTION, flags, identity(), int(), len, num, OPENSSL_free, OPENSSL_malloc, ret, sk_new_null(), sk_pop_free(), and util_flags().

00200         {
00201         static const int line_wrap = 78;
00202         int num;
00203         int ret = 0;
00204         char *name = NULL;
00205         char *desc = NULL;
00206         int flags;
00207         int xpos = 0;
00208         STACK *cmds = NULL;
00209         if(!ENGINE_ctrl(e, ENGINE_CTRL_HAS_CTRL_FUNCTION, 0, NULL, NULL) ||
00210                         ((num = ENGINE_ctrl(e, ENGINE_CTRL_GET_FIRST_CMD_TYPE,
00211                                         0, NULL, NULL)) <= 0))
00212                 {
00213 #if 0
00214                 BIO_printf(bio_out, "%s<no control commands>\n", indent);
00215 #endif
00216                 return 1;
00217                 }
00218 
00219         cmds = sk_new_null();
00220 
00221         if(!cmds)
00222                 goto err;
00223         do {
00224                 int len;
00225                 /* Get the command input flags */
00226                 if((flags = ENGINE_ctrl(e, ENGINE_CTRL_GET_CMD_FLAGS, num,
00227                                         NULL, NULL)) < 0)
00228                         goto err;
00229                 if (!(flags & ENGINE_CMD_FLAG_INTERNAL) || verbose >= 4)
00230                         {
00231                         /* Get the command name */
00232                         if((len = ENGINE_ctrl(e, ENGINE_CTRL_GET_NAME_LEN_FROM_CMD, num,
00233                                 NULL, NULL)) <= 0)
00234                                 goto err;
00235                         if((name = OPENSSL_malloc(len + 1)) == NULL)
00236                                 goto err;
00237                         if(ENGINE_ctrl(e, ENGINE_CTRL_GET_NAME_FROM_CMD, num, name,
00238                                 NULL) <= 0)
00239                                 goto err;
00240                         /* Get the command description */
00241                         if((len = ENGINE_ctrl(e, ENGINE_CTRL_GET_DESC_LEN_FROM_CMD, num,
00242                                 NULL, NULL)) < 0)
00243                                 goto err;
00244                         if(len > 0)
00245                                 {
00246                                 if((desc = OPENSSL_malloc(len + 1)) == NULL)
00247                                         goto err;
00248                                 if(ENGINE_ctrl(e, ENGINE_CTRL_GET_DESC_FROM_CMD, num, desc,
00249                                         NULL) <= 0)
00250                                         goto err;
00251                                 }
00252                         /* Now decide on the output */
00253                         if(xpos == 0)
00254                                 /* Do an indent */
00255                                 xpos = BIO_printf(bio_out, indent);
00256                         else
00257                                 /* Otherwise prepend a ", " */
00258                                 xpos += BIO_printf(bio_out, ", ");
00259                         if(verbose == 1)
00260                                 {
00261                                 /* We're just listing names, comma-delimited */
00262                                 if((xpos > (int)strlen(indent)) &&
00263                                         (xpos + (int)strlen(name) > line_wrap))
00264                                         {
00265                                         BIO_printf(bio_out, "\n");
00266                                         xpos = BIO_printf(bio_out, indent);
00267                                         }
00268                                 xpos += BIO_printf(bio_out, "%s", name);
00269                                 }
00270                         else
00271                                 {
00272                                 /* We're listing names plus descriptions */
00273                                 BIO_printf(bio_out, "%s: %s\n", name,
00274                                         (desc == NULL) ? "<no description>" : desc);
00275                                 /* ... and sometimes input flags */
00276                                 if((verbose >= 3) && !util_flags(bio_out, flags,
00277                                         indent))
00278                                         goto err;
00279                                 xpos = 0;
00280                                 }
00281                         }
00282                 OPENSSL_free(name); name = NULL;
00283                 if(desc) { OPENSSL_free(desc); desc = NULL; }
00284                 /* Move to the next command */
00285                 num = ENGINE_ctrl(e, ENGINE_CTRL_GET_NEXT_CMD_TYPE,
00286                                         num, NULL, NULL);
00287                 } while(num > 0);
00288         if(xpos > 0)
00289                 BIO_printf(bio_out, "\n");
00290         ret = 1;
00291 err:
00292         if(cmds) sk_pop_free(cmds, identity);
00293         if(name) OPENSSL_free(name);
00294         if(desc) OPENSSL_free(desc);
00295         return ret;
00296         }


Variable Documentation

const char* engine_usage[] [static]
 

Initial value:

{
"usage: engine opts [engine ...]\n",
" -v[v[v[v]]] - verbose mode, for each engine, list its 'control commands'\n",
"               -vv will additionally display each command's description\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",
" -t[t]       - for each engine, check that they are really available\n",
"               -tt will display error trace for unavailable engines\n",
" -pre <cmd>  - runs command 'cmd' against the ENGINE before any attempts\n",
"               to load it (if -t is used)\n",
" -post <cmd> - runs command 'cmd' against the ENGINE after loading it\n",
"               (only used if -t is also provided)\n",
" NB: -pre and -post will be applied to all ENGINEs supplied on the command\n",
" line, or all supported ENGINEs if none are specified.\n",
" Eg. '-pre \"SO_PATH:/lib/libdriver.so\"' calls command \"SO_PATH\" with\n",
" argument \"/lib/libdriver.so\".\n",
NULL
}

Definition at line 75 of file engine.c.


© sourcejam.com 2005-2008