[BACK]Return to openssl.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / openssl

Diff for /src/usr.bin/openssl/openssl.c between version 1.30 and 1.31

version 1.30, 2019/11/04 15:25:54 version 1.31, 2022/11/11 17:07:39
Line 137 
Line 137 
 #define FUNC_TYPE_MD_ALG        5  #define FUNC_TYPE_MD_ALG        5
 #define FUNC_TYPE_CIPHER_ALG    6  #define FUNC_TYPE_CIPHER_ALG    6
   
 int single_execution = 0;  
   
 typedef struct {  typedef struct {
         int type;          int type;
         const char *name;          const char *name;
Line 349 
Line 347 
   
 static LHASH_OF(FUNCTION) *prog_init(void);  static LHASH_OF(FUNCTION) *prog_init(void);
 static int do_cmd(LHASH_OF(FUNCTION) *prog, int argc, char *argv[]);  static int do_cmd(LHASH_OF(FUNCTION) *prog, int argc, char *argv[]);
   static void print_help(void);
 static void list_pkey(BIO * out);  static void list_pkey(BIO * out);
 static void list_cipher(BIO * out);  static void list_cipher(BIO * out);
 static void list_md(BIO * out);  static void list_md(BIO * out);
Line 385 
Line 384 
 main(int argc, char **argv)  main(int argc, char **argv)
 {  {
         ARGS arg;          ARGS arg;
 #define PROG_NAME_SIZE  39  
         char pname[PROG_NAME_SIZE + 1];  
         FUNCTION f, *fp;  
         const char *prompt;  
         char buf[1024];  
         char *to_free = NULL;          char *to_free = NULL;
         int n, i, ret = 0;          int i, ret = 0;
         char *p;          char *p;
         LHASH_OF(FUNCTION) * prog = NULL;          LHASH_OF(FUNCTION) * prog = NULL;
         long errline;          long errline;
Line 453 
Line 447 
   
         prog = prog_init();          prog = prog_init();
   
         /* first check the program name */  
         program_name(argv[0], pname, sizeof pname);  
   
         f.name = pname;  
         fp = lh_FUNCTION_retrieve(prog, &f);  
         if (fp != NULL) {  
                 argv[0] = pname;  
   
                 single_execution = 1;  
                 ret = fp->func(argc, argv);  
                 goto end;  
         }  
         /*          /*
          * ok, now check that there are not arguments, if there are, run with           * ok, now check that there are not arguments, if there are, run with
          * them, shifting the ssleay off the front           * them, shifting the executable name off the front
          */           */
         if (argc != 1) {          argc--;
                 argc--;          argv++;
                 argv++;  
   
                 single_execution = 1;          if (argc < 1) {
                 ret = do_cmd(prog, argc, argv);                  print_help();
                 if (ret < 0)  
                         ret = 0;  
                 goto end;                  goto end;
         }          }
         /* ok, lets enter the old 'OpenSSL>' mode */  
   
         for (;;) {          ret = do_cmd(prog, argc, argv);
           if (ret < 0)
                 ret = 0;                  ret = 0;
                 p = buf;  
                 n = sizeof buf;  
                 i = 0;  
                 for (;;) {  
                         p[0] = '\0';  
                         if (i++)  
                                 prompt = ">";  
                         else  
                                 prompt = "OpenSSL> ";  
                         fputs(prompt, stdout);  
                         fflush(stdout);  
                         if (!fgets(p, n, stdin))  
                                 goto end;  
                         if (p[0] == '\0')  
                                 goto end;  
                         i = strlen(p);  
                         if (i <= 1)  
                                 break;  
                         if (p[i - 2] != '\\')  
                                 break;  
                         i -= 2;  
                         p += i;  
                         n -= i;  
                 }  
                 if (!chopup_args(&arg, buf, &argc, &argv))  
                         break;  
   
                 ret = do_cmd(prog, argc, argv);  
                 if (ret < 0) {  
                         ret = 0;  
                         goto end;  
                 }  
                 if (ret != 0)  
                         BIO_printf(bio_err, "error in %s\n", argv[0]);  
                 (void) BIO_flush(bio_err);  
         }  
         BIO_printf(bio_err, "bad exit\n");  
         ret = 1;  
   
  end:   end:
         free(to_free);          free(to_free);
   
Line 554 
Line 495 
 do_cmd(LHASH_OF(FUNCTION) * prog, int argc, char *argv[])  do_cmd(LHASH_OF(FUNCTION) * prog, int argc, char *argv[])
 {  {
         FUNCTION f, *fp;          FUNCTION f, *fp;
         int i, ret = 1, tp, nl;          int ret = 1;
   
         if ((argc <= 0) || (argv[0] == NULL)) {          if ((argc <= 0) || (argv[0] == NULL)) {
                 ret = 0;                  ret = 0;
Line 585 
Line 526 
                         BIO_printf(bio_stdout, "%s\n", argv[0] + 3);                          BIO_printf(bio_stdout, "%s\n", argv[0] + 3);
                 BIO_free_all(bio_stdout);                  BIO_free_all(bio_stdout);
                 goto end;                  goto end;
         } else if ((strcmp(argv[0], "quit") == 0) ||  
             (strcmp(argv[0], "q") == 0) ||  
             (strcmp(argv[0], "exit") == 0) ||  
             (strcmp(argv[0], "bye") == 0)) {  
                 ret = -1;  
                 goto end;  
         } else if ((strcmp(argv[0], LIST_STANDARD_COMMANDS) == 0) ||          } else if ((strcmp(argv[0], LIST_STANDARD_COMMANDS) == 0) ||
             (strcmp(argv[0], LIST_MESSAGE_DIGEST_COMMANDS) == 0) ||              (strcmp(argv[0], LIST_MESSAGE_DIGEST_COMMANDS) == 0) ||
             (strcmp(argv[0], LIST_MESSAGE_DIGEST_ALGORITHMS) == 0) ||              (strcmp(argv[0], LIST_MESSAGE_DIGEST_ALGORITHMS) == 0) ||
Line 633 
Line 568 
                 BIO_printf(bio_err,                  BIO_printf(bio_err,
                     "openssl:Error: '%s' is an invalid command.\n",                      "openssl:Error: '%s' is an invalid command.\n",
                     argv[0]);                      argv[0]);
                 BIO_printf(bio_err, "\nStandard commands");                  print_help();
                 i = 0;                  ret = 0;
                 tp = 0;          }
                 for (fp = functions; fp->name != NULL; fp++) {   end:
                         nl = 0;          return (ret);
   }
   
   static void
   print_help(void)
   {
           FUNCTION *fp;
           int i = 0;
           int tp = 0;
           int nl;
   
           BIO_printf(bio_err, "\nStandard commands");
           for (fp = functions; fp->name != NULL; fp++) {
                   nl = 0;
 #ifdef OPENSSL_NO_CAMELLIA  #ifdef OPENSSL_NO_CAMELLIA
                         if (((i++) % 5) == 0)                  if (((i++) % 5) == 0)
 #else  #else
                         if (((i++) % 4) == 0)                  if (((i++) % 4) == 0)
 #endif  #endif
                         {                  {
                           BIO_printf(bio_err, "\n");
                           nl = 1;
                   }
                   if (fp->type != tp) {
                           tp = fp->type;
                           if (!nl)
                                 BIO_printf(bio_err, "\n");                                  BIO_printf(bio_err, "\n");
                                 nl = 1;                          if (tp == FUNC_TYPE_MD) {
                                   i = 1;
                                   BIO_printf(bio_err,
                                       "\nMessage Digest commands (see the `dgst' command for more details)\n");
                           } else if (tp == FUNC_TYPE_CIPHER) {
                                   i = 1;
                                   BIO_printf(bio_err, "\nCipher commands (see the `enc' command for more details)\n");
                         }                          }
                         if (fp->type != tp) {                  }
                                 tp = fp->type;  
                                 if (!nl)  
                                         BIO_printf(bio_err, "\n");  
                                 if (tp == FUNC_TYPE_MD) {  
                                         i = 1;  
                                         BIO_printf(bio_err,  
                                             "\nMessage Digest commands (see the `dgst' command for more details)\n");  
                                 } else if (tp == FUNC_TYPE_CIPHER) {  
                                         i = 1;  
                                         BIO_printf(bio_err, "\nCipher commands (see the `enc' command for more details)\n");  
                                 }  
                         }  
 #ifdef OPENSSL_NO_CAMELLIA  #ifdef OPENSSL_NO_CAMELLIA
                         BIO_printf(bio_err, "%-15s", fp->name);                  BIO_printf(bio_err, "%-15s", fp->name);
 #else  #else
                         BIO_printf(bio_err, "%-18s", fp->name);                  BIO_printf(bio_err, "%-18s", fp->name);
 #endif  #endif
                 }  
                 BIO_printf(bio_err, "\n\n");  
                 ret = 0;  
         }          }
  end:  
         return (ret);          BIO_printf(bio_err, "\n\n");
 }  }
   
 static int  static int

Legend:
Removed from v.1.30  
changed lines
  Added in v.1.31