]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
Fix auth-token not being updated if auth-nocache is set
authorArne Schwabe <arne@rfc2549.org>
Mon, 30 Nov 2020 12:39:28 +0000 (13:39 +0100)
committerGert Doering <gert@greenie.muc.de>
Mon, 30 Nov 2020 15:44:58 +0000 (16:44 +0100)
This fixes the auth-token not being updated if auth-nocache is set. Our
set_auth_token method ensures that the auth-token always has a username
but is a little bit too strict in the check.

Also add doxygen documentation and remove null checks. We use this function
only with non-null pointers and it makes it a bit nicer to read.

Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20201130123928.21837-1-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg21291.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit fb789947ab1eba3e68fb8e4b3551d095a53962bd)

src/openvpn/misc.c
src/openvpn/misc.h

index 9c5e96ed728b82e5ade14bd5726771388d09102d..e3a2ef3153b8d58c4c97dd83f02dbdad2e9d494e 100644 (file)
@@ -1324,10 +1324,15 @@ void
 set_auth_token(struct user_pass *up, struct user_pass *tk, const char *token)
 {
 
-    if (token && strlen(token) && up && up->defined)
+    if (strlen(token) && (up->defined || tk->defined))
     {
+        /* auth-token has no password, so it needs the username
+         * either already set or copied from up */
         strncpynt(tk->password, token, USER_PASS_LEN);
-        strncpynt(tk->username, up->username, USER_PASS_LEN);
+        if (up->defined)
+        {
+            strncpynt(tk->username, up->username, USER_PASS_LEN);
+        }
         tk->defined = true;
     }
 
index 8a34f431619b92f140dd60ff9ead00a87bebd673..59c8ae2342cf6241690533eca0ac920a106a5624 100644 (file)
@@ -259,6 +259,17 @@ void fail_user_pass(const char *prefix,
 
 void purge_user_pass(struct user_pass *up, const bool force);
 
+/**
+ * Sets the auth-token to token if a username is available from either
+ * up or already present in tk. The method will also purge up if
+ * the auth-nocache option is active.
+ *
+ * @param up        (non Auth-token) Username/password
+ * @param tk        auth-token userpass to set
+ * @param token     token to use as password for the
+ *
+ * @note    all parameters to this function must not be null.
+ */
 void set_auth_token(struct user_pass *up, struct user_pass *tk,
                     const char *token);