]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
apps: move global libctx and property query into their own file
authorPauli <pauli@openssl.org>
Thu, 10 Jun 2021 06:58:12 +0000 (16:58 +1000)
committerPauli <pauli@openssl.org>
Tue, 15 Jun 2021 08:26:47 +0000 (18:26 +1000)
The header has been split out so the functions should be as well.

Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15687)

apps/include/app_libctx.h
apps/lib/app_libctx.c [new file with mode: 0644]
apps/lib/apps.c
apps/lib/build.info

index 61b143b7dbb45f4814a0284bd1b84a49e6414fd8..17c0afc713d2c130f4fae86d9752cded0f9df1b5 100644 (file)
@@ -10,6 +10,8 @@
 #ifndef OSSL_APPS_LIBCTX_H
 # define OSSL_APPS_LIBCTX_H
 
+# include <openssl/types.h>
+
 OSSL_LIB_CTX *app_create_libctx(void);
 OSSL_LIB_CTX *app_get0_libctx(void);
 int app_set_propq(const char *arg);
diff --git a/apps/lib/app_libctx.c b/apps/lib/app_libctx.c
new file mode 100644 (file)
index 0000000..4b9ec40
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
+ *
+ * Licensed under the Apache License 2.0 (the "License").  You may not use
+ * this file except in compliance with the License.  You can obtain a copy
+ * in the file LICENSE in the source distribution or at
+ * https://www.openssl.org/source/license.html
+ */
+#include "app_libctx.h"
+#include "apps.h"
+
+static OSSL_LIB_CTX *app_libctx = NULL;
+static const char *app_propq = NULL;
+
+int app_set_propq(const char *arg)
+{
+    app_propq = arg;
+    return 1;
+}
+
+const char *app_get0_propq(void)
+{
+    return app_propq;
+}
+
+OSSL_LIB_CTX *app_get0_libctx(void)
+{
+    return app_libctx;
+}
+
+OSSL_LIB_CTX *app_create_libctx(void)
+{
+    /*
+     * Load the NULL provider into the default library context and create a
+     * library context which will then be used for any OPT_PROV options.
+     */
+    if (app_libctx == NULL) {
+        if (!app_provider_load(NULL, "null")) {
+            opt_printf_stderr( "Failed to create null provider\n");
+            return NULL;
+        }
+        app_libctx = OSSL_LIB_CTX_new();
+    }
+    if (app_libctx == NULL)
+        opt_printf_stderr("Failed to create library context\n");
+    return app_libctx;
+}
+
index 79fe4f8409e67b10a2329aef0008d0b03731e289..dfbc3ec5221c82c3ed643510e5516132cb208e4f 100644 (file)
@@ -69,8 +69,6 @@ typedef struct {
     unsigned long mask;
 } NAME_EX_TBL;
 
-static OSSL_LIB_CTX *app_libctx = NULL;
-
 static int set_table_opts(unsigned long *flags, const char *arg,
                           const NAME_EX_TBL * in_tbl);
 static int set_multi_opts(unsigned long *flags, const char *arg,
@@ -336,50 +334,13 @@ static char *app_get_pass(const char *arg, int keepbio)
     return OPENSSL_strdup(tpass);
 }
 
-OSSL_LIB_CTX *app_get0_libctx(void)
-{
-    return app_libctx;
-}
-
-static const char *app_propq = NULL;
-
-int app_set_propq(const char *arg)
-{
-    app_propq = arg;
-    return 1;
-}
-
-const char *app_get0_propq(void)
-{
-    return app_propq;
-}
-
-OSSL_LIB_CTX *app_create_libctx(void)
-{
-    /*
-     * Load the NULL provider into the default library context and create a
-     * library context which will then be used for any OPT_PROV options.
-     */
-    if (app_libctx == NULL) {
-
-        if (!app_provider_load(NULL, "null")) {
-            BIO_puts(bio_err, "Failed to create null provider\n");
-            return NULL;
-        }
-        app_libctx = OSSL_LIB_CTX_new();
-    }
-    if (app_libctx == NULL)
-        BIO_puts(bio_err, "Failed to create library context\n");
-    return app_libctx;
-}
-
 CONF *app_load_config_bio(BIO *in, const char *filename)
 {
     long errorline = -1;
     CONF *conf;
     int i;
 
-    conf = NCONF_new_ex(app_libctx, NULL);
+    conf = NCONF_new_ex(app_get0_libctx(), NULL);
     i = NCONF_load_bio(conf, in, &errorline);
     if (i > 0)
         return conf;
@@ -422,7 +383,7 @@ CONF *app_load_config_internal(const char *filename, int quiet)
         BIO_free(in);
     } else {
         /* Return empty config if filename is empty string. */
-        conf = NCONF_new_ex(app_libctx, NULL);
+        conf = NCONF_new_ex(app_get0_libctx(), NULL);
     }
     return conf;
 }
index 340ce29b0971d9c9a0d9a95e131797facde029d0..923ef5d92b83efc0167273896ee4ad2771dade7c 100644 (file)
@@ -10,7 +10,7 @@ ENDIF
 # Source for libapps
 $LIBAPPSSRC=apps.c apps_ui.c opt.c fmt.c s_cb.c s_socket.c app_rand.c \
         columns.c app_params.c names.c app_provider.c app_x509.c http_server.c \
-        engine.c engine_loader.c
+        engine.c engine_loader.c app_libctx.c
 
 IF[{- !$disabled{apps} -}]
   LIBS{noinst}=../libapps.a