Avoid warnings for no-engine and PEDANTIC
[oweals/openssl.git] / apps / pkcs12.c
index e345cf14899a01d0b39df79a69e9c109c1b9b139..5136acdc5759c8e32038a33b3bff10596277c705 100644 (file)
@@ -120,7 +120,9 @@ int MAIN(int argc, char **argv)
     char *passin = NULL, *passout = NULL;
     char *inrand = NULL;
     char *CApath = NULL, *CAfile = NULL;
+#ifndef OPENSSL_NO_ENGINE
     char *engine=NULL;
+#endif
 
     apps_startup();
 
@@ -252,11 +254,13 @@ int MAIN(int argc, char **argv)
                        args++; 
                        CAfile = *args;
                    } else badarg = 1;
+#ifndef OPENSSL_NO_ENGINE
                } else if (!strcmp(*args,"-engine")) {
                    if (args[1]) {
                        args++; 
                        engine = *args;
                    } else badarg = 1;
+#endif
                } else badarg = 1;
 
        } else badarg = 1;
@@ -304,14 +308,18 @@ int MAIN(int argc, char **argv)
        BIO_printf (bio_err, "-password p   set import/export password source\n");
        BIO_printf (bio_err, "-passin p     input file pass phrase source\n");
        BIO_printf (bio_err, "-passout p    output file pass phrase source\n");
+#ifndef OPENSSL_NO_ENGINE
        BIO_printf (bio_err, "-engine e     use engine e, possibly a hardware device.\n");
+#endif
        BIO_printf(bio_err,  "-rand file%cfile%c...\n", LIST_SEPARATOR_CHAR, LIST_SEPARATOR_CHAR);
        BIO_printf(bio_err,  "              load the file (or the files in the directory) into\n");
        BIO_printf(bio_err,  "              the random number generator\n");
        goto end;
     }
 
+#ifndef OPENSSL_NO_ENGINE
     e = setup_engine(bio_err, engine, 0);
+#endif
 
     if(passarg) {
        if(export_cert) passargout = passarg;
@@ -399,7 +407,7 @@ int MAIN(int argc, char **argv)
 #ifdef CRYPTO_MDEBUG
     CRYPTO_push_info("read MAC password");
 #endif
-       if(EVP_read_pw_string (macpass, 50, "Enter MAC Password:", export_cert))
+       if(EVP_read_pw_string (macpass, sizeof macpass, "Enter MAC Password:", export_cert))
        {
            BIO_printf (bio_err, "Can't read Password\n");
            goto end;
@@ -427,7 +435,7 @@ int MAIN(int argc, char **argv)
        CRYPTO_push_info("process -export_cert");
        CRYPTO_push_info("reading private key");
 #endif
-       key = load_key(bio_err, keyname ? keyname : infile, FORMAT_PEM,
+       key = load_key(bio_err, keyname ? keyname : infile, FORMAT_PEM, 1,
                passin, e, "private key");
        if (!key) {
                goto export_end;
@@ -508,9 +516,10 @@ int MAIN(int argc, char **argv)
                    /* Exclude verified certificate */
                    for (i = 1; i < sk_X509_num (chain2) ; i++) 
                        sk_X509_push(certs, sk_X509_value (chain2, i));
-               }
-               sk_X509_free(chain2);
-               if (vret) {
+                   /* Free first certificate */
+                   X509_free(sk_X509_value(chain2, 0));
+                   sk_X509_free(chain2);
+               } else {
                        BIO_printf (bio_err, "Error %s getting chain.\n",
                                        X509_verify_cert_error_string(vret));
                        goto export_end;
@@ -537,8 +546,6 @@ int MAIN(int argc, char **argv)
        }
        sk_X509_pop_free(certs, X509_free);
        certs = NULL;
-       /* ucert is part of certs so it is already freed */
-       ucert = NULL;
 
 #ifdef CRYPTO_MDEBUG
        CRYPTO_pop_info();
@@ -546,7 +553,7 @@ int MAIN(int argc, char **argv)
 #endif
 
        if(!noprompt &&
-               EVP_read_pw_string(pass, 50, "Enter Export Password:", 1)) {
+               EVP_read_pw_string(pass, sizeof pass, "Enter Export Password:", 1)) {
            BIO_printf (bio_err, "Can't read Password\n");
            goto export_end;
         }
@@ -627,7 +634,6 @@ int MAIN(int argc, char **argv)
        if (certs) sk_X509_pop_free(certs, X509_free);
        if (safes) sk_PKCS7_pop_free(safes, PKCS7_free);
        if (bags) sk_PKCS12_SAFEBAG_pop_free(bags, PKCS12_SAFEBAG_free);
-       if (ucert) X509_free(ucert);
 
 #ifdef CRYPTO_MDEBUG
        CRYPTO_pop_info();
@@ -644,7 +650,7 @@ int MAIN(int argc, char **argv)
 #ifdef CRYPTO_MDEBUG
     CRYPTO_push_info("read import password");
 #endif
-    if(!noprompt && EVP_read_pw_string(pass, 50, "Enter Import Password:", 0)) {
+    if(!noprompt && EVP_read_pw_string(pass, sizeof pass, "Enter Import Password:", 0)) {
        BIO_printf (bio_err, "Can't read Password\n");
        goto end;
     }
@@ -698,7 +704,7 @@ int MAIN(int argc, char **argv)
     if(passin) OPENSSL_free(passin);
     if(passout) OPENSSL_free(passout);
     apps_shutdown();
-    EXIT(ret);
+    OPENSSL_EXIT(ret);
 }
 
 int dump_certs_keys_p12 (BIO *out, PKCS12 *p12, char *pass,