diff options
-rw-r--r-- | src/openvpn/misc.c | 9 | ||||
-rw-r--r-- | src/openvpn/misc.h | 11 |
2 files changed, 18 insertions, 2 deletions
diff --git a/src/openvpn/misc.c b/src/openvpn/misc.c index 9c5e96e..e3a2ef3 100644 --- a/src/openvpn/misc.c +++ b/src/openvpn/misc.c @@ -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; } diff --git a/src/openvpn/misc.h b/src/openvpn/misc.h index 8a34f43..59c8ae2 100644 --- a/src/openvpn/misc.h +++ b/src/openvpn/misc.h @@ -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); |