]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
client-connect: Refactor multi_client_connect_source_ccd
authorFabian Knittel <fabian.knittel@lettink.de>
Sat, 11 Jul 2020 09:36:44 +0000 (11:36 +0200)
committerGert Doering <gert@greenie.muc.de>
Tue, 14 Jul 2020 13:20:15 +0000 (15:20 +0200)
Refactor multi_client_connect_source_ccd(), so that
options_server_import() (or the success path in general) is only
entered in one place within the function.

Signed-off-by: Fabian Knittel <fabian.knittel@lettink.de>
Patch V5: Simplify the logic even further to make it more easy to
understand.

Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Antonio Quartulli <antonio@openvpn.net>
Message-Id: <20200711093655.23686-3-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg20287.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
src/openvpn/multi.c

index d3840539874e3b490419539ba8a33ffb5a5132d0..7d360221eca2caa6c1c1616553c5b2197f63ae11 100644 (file)
@@ -2173,15 +2173,30 @@ multi_client_connect_source_ccd(struct multi_context *m,
     if (mi->context.options.client_config_dir)
     {
         struct gc_arena gc = gc_new();
-        const char *ccd_file;
+        const char *ccd_file = NULL;
+
+        const char *ccd_client =
+            platform_gen_path(mi->context.options.client_config_dir,
+                              tls_common_name(mi->context.c2.tls_multi, false),
+                              &gc);
+
+        const char *ccd_default =
+            platform_gen_path(mi->context.options.client_config_dir,
+                              CCD_DEFAULT, &gc);
 
-        ccd_file = platform_gen_path(mi->context.options.client_config_dir,
-                                     tls_common_name(mi->context.c2.tls_multi,
-                                                     false),
-                                     &gc);
 
         /* try common-name file */
-        if (platform_test_file(ccd_file))
+        if (platform_test_file(ccd_client))
+        {
+            ccd_file = ccd_client;
+        }
+        /* try default file */
+        else if (platform_test_file(ccd_default))
+        {
+            ccd_file = ccd_default;
+        }
+
+        if (ccd_file)
         {
             options_server_import(&mi->context.options,
                                   ccd_file,
@@ -2190,22 +2205,6 @@ multi_client_connect_source_ccd(struct multi_context *m,
                                   option_types_found,
                                   mi->context.c2.es);
         }
-        else /* try default file */
-        {
-            ccd_file = platform_gen_path(mi->context.options.client_config_dir,
-                                         CCD_DEFAULT,
-                                         &gc);
-
-            if (platform_test_file(ccd_file))
-            {
-                options_server_import(&mi->context.options,
-                                      ccd_file,
-                                      D_IMPORT_ERRORS|M_OPTERR,
-                                      CLIENT_CONNECT_OPT_MASK,
-                                      option_types_found,
-                                      mi->context.c2.es);
-            }
-        }
         gc_free(&gc);
     }
 }