[Openvpn-devel,v3,02/13] client-connect: Refactor multi_client_connect_source_ccd

Message ID 20181112115627.5096-3-arne@rfc2549.org
State Superseded
Headers show
Series Deferred client-connect patch set | expand

Commit Message

Arne Schwabe Nov. 12, 2018, 12:56 a.m. UTC
From: Fabian Knittel <fabian.knittel@lettink.de>

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>
Signed-off-by: Arne Schwabe <arne@rfc2549.org>
---
 src/openvpn/multi.c | 31 +++++++++++++++----------------
 1 file changed, 15 insertions(+), 16 deletions(-)

Patch

diff --git a/src/openvpn/multi.c b/src/openvpn/multi.c
index 13106fcc..282464fb 100644
--- a/src/openvpn/multi.c
+++ b/src/openvpn/multi.c
@@ -2064,31 +2064,30 @@  multi_client_connect_source_ccd(struct multi_context *m,
                                      &gc);
 
         /* try common-name file */
-        if (platform_test_file(ccd_file))
+        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);
+            ccd_file = NULL;
         }
-        else /* try default file */
+        /* try default file */
         {
             ccd_file = platform_gen_path(mi->context.options.client_config_dir,
                                          CCD_DEFAULT,
                                          &gc);
-
-            if (platform_test_file(ccd_file))
+            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);
+                ccd_file = NULL;
             }
         }
+
+        if (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);
     }
 }