]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
console_systemd: rename query_user_exec to query_user_systemd
authorFrank Lichtenheld <frank@lichtenheld.com>
Fri, 26 Jul 2024 10:40:32 +0000 (12:40 +0200)
committerGert Doering <gert@greenie.muc.de>
Fri, 26 Jul 2024 10:47:48 +0000 (12:47 +0200)
This allows us to override query_user_exec for unit
tests more consistently without having to jump through
weird hoops.

Fixes running test_pkcs11 with --enable-systemd.

While here also fix documentation comments for
query_user_exec*.

Change-Id: I379e1eb6dc57b9fe4bbdaefbd947a14326e7117a
Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20240726104032.2112-1-gert@greenie.muc.de>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg28983.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
src/openvpn/console.h
src/openvpn/console_systemd.c
tests/unit_tests/openvpn/test_pkcs11.c
tests/unit_tests/openvpn/test_user_pass.c

index 7358299d7befac2b70e98213bc0d9b15a51d62dc..72ae8e0815fd1e1b0f17279e6f99f919195850f5 100644 (file)
@@ -65,11 +65,10 @@ void query_user_add(char *prompt, size_t prompt_len,
 
 
 /**
- * Executes a configured setup, using the built-in method for querying the user.
+ * Loop through configured query_user slots, using the built-in method for
+ * querying the user.
  * This method uses the console/TTY directly.
  *
- * @param setup    Pointer to the setup defining what to ask the user
- *
  * @return True if executing all the defined steps completed successfully
  */
 bool query_user_exec_builtin(void);
@@ -77,21 +76,34 @@ bool query_user_exec_builtin(void);
 
 #if defined(ENABLE_SYSTEMD)
 /**
- * Executes a configured setup, using the compiled method for querying the user
+ * Loop through configured query_user slots, using the systemd method for
+ * querying the user.
+ * If systemd is not running it will fall back to use
+ * query_user_exec_builtin() instead.
  *
- * @param setup    Pointer to the setup defining what to ask the user
+ * @return True if executing all the defined steps completed successfully
+ */
+bool query_user_exec_systemd(void);
+
+/**
+ * Loop through configured query_user slots, using the compiled method for
+ * querying the user.
  *
  * @return True if executing all the defined steps completed successfully
  */
-bool query_user_exec(void);
+static inline bool
+query_user_exec(void)
+{
+    return query_user_exec_systemd();
+}
 
-#else  /* ENABLE_SYSTEMD not defined*/
+#else  /* ENABLE_SYSTEMD not defined */
 /**
  * Wrapper function enabling query_user_exec() if no alternative methods have
  * been enabled
  *
  */
-static bool
+static inline bool
 query_user_exec(void)
 {
     return query_user_exec_builtin();
index c7cf1adad38920818c004f5fb79ecf18da246640..cc91cd100786a825ed0962e7ab55eeaf26ba0436 100644 (file)
@@ -96,7 +96,7 @@ get_console_input_systemd(const char *prompt, const bool echo, char *input, cons
  *
  */
 bool
-query_user_exec(void)
+query_user_exec_systemd(void)
 {
     bool ret = true;  /* Presume everything goes okay */
     int i;
index 6d283a209b03921ae2fe87e0e3935c0e3435d1bd..5518fa15d0ab76262ed7239d3707ef796628f0a3 100644 (file)
@@ -75,6 +75,14 @@ query_user_clear(void)
 {
     assert_true(0);
 }
+#if defined(ENABLE_SYSTEMD)
+bool
+query_user_exec_systemd(void)
+{
+    assert_true(0);
+    return false;
+}
+#endif
 bool
 query_user_exec_builtin(void)
 {
index b43e65571dd0878468c8b5ae3f84d164a0f2fefc..de60291b7dc3dd8aed6e637d8f1c30de111a1a87 100644 (file)
 #include "config.h"
 #endif
 
-#undef ENABLE_SYSTEMD
-/* avoid redefining ENABLE_SYSTEMD in misc.c */
-#undef HAVE_CONFIG_H
-
 #include "syshead.h"
 #include "manage.h"
 
 struct management *management; /* global */
 
 /* mocking */
+#if defined(ENABLE_SYSTEMD)
+bool
+query_user_exec_systemd(void)
+{
+    return query_user_exec_builtin();
+}
+#endif
 bool
 query_user_exec_builtin(void)
 {