]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
console: Simplify query_user_add interface
authorFrank Lichtenheld <frank@lichtenheld.com>
Fri, 10 Oct 2025 09:47:44 +0000 (11:47 +0200)
committerGert Doering <gert@greenie.muc.de>
Fri, 10 Oct 2025 09:51:38 +0000 (11:51 +0200)
- Removes unused field prompt_len
- Change field reponse_len to int since that
  is what the code actually expects. Most callers
  user a constant either way.

Change-Id: I04542e678f81d5d4a853b4370d9b8adc4dac1212
Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1216
Message-Id: <20251010094753.2825-1-gert@greenie.muc.de>
URL: https://sourceforge.net/p/openvpn/mailman/message/59244794/
Signed-off-by: Gert Doering <gert@greenie.muc.de>
src/openvpn/console.c
src/openvpn/console.h
src/openvpn/console_builtin.c
src/openvpn/misc.c
src/openvpn/pkcs11.c

index bdceaf2128445bc115ae7a841864750801f07671..3cb23b36b6270421c69a058a4f795008d3b952d1 100644 (file)
@@ -53,14 +53,14 @@ query_user_clear(void)
 
 
 void
-query_user_add(char *prompt, size_t prompt_len, char *resp, size_t resp_len, bool echo)
+query_user_add(char *prompt, char *resp, int resp_len, bool echo)
 {
     int i;
 
     /* Ensure input is sane.  All these must be present otherwise it is
      * a programming error.
      */
-    ASSERT(prompt_len > 0 && prompt != NULL && resp_len > 0 && resp != NULL);
+    ASSERT(prompt != NULL && resp_len > 0 && resp != NULL);
 
     /* Seek to the last unused slot */
     for (i = 0; i < QUERY_USER_NUMSLOTS; i++)
@@ -74,7 +74,6 @@ query_user_add(char *prompt, size_t prompt_len, char *resp, size_t resp_len, boo
 
     /* Save the information needed for the user interaction */
     query_user[i].prompt = prompt;
-    query_user[i].prompt_len = prompt_len;
     query_user[i].response = resp;
     query_user[i].response_len = resp_len;
     query_user[i].echo = echo;
index 14b61169939e826eefff5901c43e2a64371133e5..fba2a098971de2635c86679702291b3b0e7c6cd2 100644 (file)
  */
 struct _query_user
 {
-    char *prompt;        /**< Prompt to present to the user */
-    size_t prompt_len;   /**< Length of the prompt string */
-    char *response;      /**< The user's response */
-    size_t response_len; /**< Length the of the user response */
-    bool echo;           /**< True: The user should see what is being typed, otherwise mask it */
+    char *prompt;     /**< Prompt to present to the user */
+    char *response;   /**< The user's response */
+    int response_len; /**< Length the of the user response */
+    bool echo;        /**< True: The user should see what is being typed, otherwise mask it */
 };
 
 #define QUERY_USER_NUMSLOTS 10
@@ -53,13 +52,12 @@ void query_user_clear(void);
  * Adds an item to ask the user for
  *
  * @param prompt     Prompt to display to the user
- * @param prompt_len Length of the prompt string
  * @param resp       String containing the user response
  * @param resp_len   Length of the response string
  * @param echo       Should the user input be echoed to the user?  If False, input will be masked
  *
  */
-void query_user_add(char *prompt, size_t prompt_len, char *resp, size_t resp_len, bool echo);
+void query_user_add(char *prompt, char *resp, int resp_len, bool echo);
 
 
 /**
@@ -117,10 +115,10 @@ query_user_exec(void)
  *
  */
 static inline bool
-query_user_SINGLE(char *prompt, size_t prompt_len, char *resp, size_t resp_len, bool echo)
+query_user_SINGLE(char *prompt, char *resp, int resp_len, bool echo)
 {
     query_user_clear();
-    query_user_add(prompt, prompt_len, resp, resp_len, echo);
+    query_user_add(prompt, resp, resp_len, echo);
     return query_user_exec();
 }
 
index 71c00252dd41abd7448ce6135ba36fef6d2b7dc6..2a925d62f0faac5a8372d66393dfe47f92f32e7a 100644 (file)
 
 #include "win32.h"
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wconversion"
-#endif
-
 /**
  * Get input from a Windows console.
  *
@@ -73,7 +68,7 @@ get_console_input_win32(const char *prompt, const bool echo, char *input, const
     HANDLE in = GetStdHandle(STD_INPUT_HANDLE);
     int orig_stderr = get_orig_stderr(); /* guaranteed to be always valid */
     if ((in == INVALID_HANDLE_VALUE) || win32_service_interrupt(&win32_signal)
-        || (_write(orig_stderr, prompt, strlen(prompt)) == -1))
+        || (_write(orig_stderr, prompt, (unsigned int)strlen(prompt)) == -1))
     {
         msg(M_WARN | M_ERRNO, "get_console_input_win32(): unexpected error");
         return false;
@@ -139,10 +134,6 @@ get_console_input_win32(const char *prompt, const bool echo, char *input, const
     return false;
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 #endif /* _WIN32 */
 
 
@@ -273,11 +264,6 @@ get_console_input(const char *prompt, const bool echo, char *input, const int ca
     return ret;
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wconversion"
-#endif
-
 /**
  * @copydoc query_user_exec()
  *
@@ -309,7 +295,3 @@ query_user_exec_builtin(void)
 
     return ret;
 }
-
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
index caf4725e4f0267a2045a5856cf7a8763e93d59f1..188f44ef82f3825903de35829b714f66355308c0 100644 (file)
@@ -239,8 +239,7 @@ get_user_pass_cr(struct user_pass *up, const char *auth_file, const char *prefix
                 struct buffer user_prompt = alloc_buf_gc(128, &gc);
 
                 buf_printf(&user_prompt, "NEED-OK|%s|%s:", prefix, up->username);
-                if (!query_user_SINGLE(BSTR(&user_prompt), BLEN(&user_prompt), up->password,
-                                       USER_PASS_LEN, false))
+                if (!query_user_SINGLE(BSTR(&user_prompt), up->password, USER_PASS_LEN, false))
                 {
                     msg(M_FATAL, "ERROR: could not read %s ok-confirmation from stdin", prefix);
                 }
@@ -362,7 +361,7 @@ get_user_pass_cr(struct user_pass *up, const char *auth_file, const char *prefix
                     buf_printf(&challenge, "CHALLENGE: %s", ac->challenge_text);
                     buf_set_write(&packed_resp, (uint8_t *)up->password, USER_PASS_LEN);
 
-                    if (!query_user_SINGLE(BSTR(&challenge), BLEN(&challenge), response,
+                    if (!query_user_SINGLE(BSTR(&challenge), response,
                                            USER_PASS_LEN, BOOL_CAST(ac->flags & CR_ECHO)))
                     {
                         msg(M_FATAL, "ERROR: could not read challenge response from stdin");
@@ -387,14 +386,12 @@ get_user_pass_cr(struct user_pass *up, const char *auth_file, const char *prefix
 
                 if (username_from_stdin && !(flags & GET_USER_PASS_PASSWORD_ONLY))
                 {
-                    query_user_add(BSTR(&user_prompt), BLEN(&user_prompt), up->username,
-                                   USER_PASS_LEN, true);
+                    query_user_add(BSTR(&user_prompt), up->username, USER_PASS_LEN, true);
                 }
 
                 if (password_from_stdin)
                 {
-                    query_user_add(BSTR(&pass_prompt), BLEN(&pass_prompt), up->password,
-                                   USER_PASS_LEN, false);
+                    query_user_add(BSTR(&pass_prompt), up->password, USER_PASS_LEN, false);
                 }
 
                 if (!query_user_exec())
@@ -421,8 +418,7 @@ get_user_pass_cr(struct user_pass *up, const char *auth_file, const char *prefix
                     challenge = alloc_buf_gc(14 + strlen(auth_challenge), &gc);
                     buf_printf(&challenge, "CHALLENGE: %s", auth_challenge);
 
-                    if (!query_user_SINGLE(BSTR(&challenge), BLEN(&challenge), response,
-                                           USER_PASS_LEN,
+                    if (!query_user_SINGLE(BSTR(&challenge), response, USER_PASS_LEN,
                                            BOOL_CAST(flags & GET_USER_PASS_STATIC_CHALLENGE_ECHO)))
                     {
                         msg(M_FATAL, "ERROR: could not retrieve static challenge response");
index 16149caf17922f4e7cca9afde4fe2cff3559d15d..ce641356374beed19a59eab511a216fbcca0e39a 100644 (file)
@@ -671,7 +671,7 @@ _pkcs11_openvpn_show_pkcs11_ids_pin_prompt(void *const global_data, void *const
     ASSERT(token != NULL);
 
     buf_printf(&pass_prompt, "Please enter '%s' token PIN or 'cancel': ", token->display);
-    if (!query_user_SINGLE(BSTR(&pass_prompt), BLEN(&pass_prompt), pin, pin_max, false))
+    if (!query_user_SINGLE(BSTR(&pass_prompt), pin, (int)pin_max, false))
     {
         msg(M_FATAL, "Could not retrieve the PIN");
     }