From patchwork Mon Nov 30 01:39:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arne Schwabe X-Patchwork-Id: 1533 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director8.mail.ord1d.rsapps.net ([172.31.255.6]) by backend41.mail.ord1d.rsapps.net with LMTP id SPeIMrXrxF9rOgAAqwncew (envelope-from ) for ; Mon, 30 Nov 2020 07:55:17 -0500 Received: from proxy18.mail.iad3b.rsapps.net ([172.31.255.6]) by director8.mail.ord1d.rsapps.net with LMTP id oK9aMrXrxF8kCgAAfY0hYg (envelope-from ) for ; Mon, 30 Nov 2020 07:55:17 -0500 Received: from smtp7.gate.iad3b ([172.31.255.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy18.mail.iad3b.rsapps.net with LMTPS id iACZKbXrxF/BWgAA3NpJmQ (envelope-from ) for ; Mon, 30 Nov 2020 07:55:17 -0500 X-Spam-Threshold: 95 X-Spam-Score: 0 X-Spam-Flag: NO X-Virus-Scanned: OK X-Orig-To: openvpnslackdevel@openvpn.net X-Originating-Ip: [216.105.38.7] Authentication-Results: smtp7.gate.iad3b.rsapps.net; iprev=pass policy.iprev="216.105.38.7"; spf=pass smtp.mailfrom="openvpn-devel-bounces@lists.sourceforge.net" smtp.helo="lists.sourceforge.net"; dkim=fail (signature verification failed) header.d=sourceforge.net; dkim=fail (signature verification failed) header.d=sf.net; dmarc=none (p=nil; dis=none) header.from=rfc2549.org X-Suspicious-Flag: YES X-Classification-ID: 4b6a32d8-330b-11eb-82d7-525400e292e5-1-1 Received: from [216.105.38.7] ([216.105.38.7:37760] helo=lists.sourceforge.net) by smtp7.gate.iad3b.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 85/09-06552-5BBE4CF5; Mon, 30 Nov 2020 07:55:17 -0500 Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1kjihB-0003Ts-Ar; Mon, 30 Nov 2020 12:54:21 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kjiTF-0002u3-MI for openvpn-devel@lists.sourceforge.net; Mon, 30 Nov 2020 12:39:57 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Message-Id:Date:Subject:To:From:Sender:Reply-To:Cc: MIME-Version:Content-Type:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=xOl/rxD8j2FYlXQ1opGEMsB8wy38DT+hbaXcZd3RoZ0=; b=Ne/Fgj0gpQth9F77It20w4hCEz eCOexgkazo7WrKYCfcFIl26i9yzOTiSG7+Id7TnlMK+YIQOMK27kPFgES5pEPyWqK1mQvxjtlzv/n fCfHhgu6NtgkXZNDy7wQ4A5W1L4XiFo1jk6KxYUS4cyLlvjFeaLepEO9yg72F6JQL4YE=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Message-Id:Date:Subject:To:From:Sender:Reply-To:Cc:MIME-Version: Content-Type:Content-Transfer-Encoding:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=xOl/rxD8j2FYlXQ1opGEMsB8wy38DT+hbaXcZd3RoZ0=; b=Ph9A6vYhPpQg3IJyQeOfklEoBo f6QtU1Z+GoQ8DAHXQgOyIaDaP5OJ6+B7gzEYmwHJHqbnME45iNguxGmijhWMrY4kVA/UomgO+yMNk Kb+3us+xhD9peBZumlHTSSTfGzSYxh5o51Ny63zoNLuwhXhGom9BhxxHuhGVC1UbAGPA=; Received: from mail.blinkt.de ([192.26.174.232]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.2) id 1kjiT7-006cWE-67 for openvpn-devel@lists.sourceforge.net; Mon, 30 Nov 2020 12:39:57 +0000 Received: from kamera.blinkt.de ([2001:638:502:390:20c:29ff:fec8:535c]) by mail.blinkt.de with smtp (Exim 4.94 (FreeBSD)) (envelope-from ) id 1kjiSm-000C3m-NE for openvpn-devel@lists.sourceforge.net; Mon, 30 Nov 2020 13:39:28 +0100 Received: (nullmailer pid 21882 invoked by uid 10006); Mon, 30 Nov 2020 12:39:28 -0000 From: Arne Schwabe To: openvpn-devel@lists.sourceforge.net Date: Mon, 30 Nov 2020 13:39:28 +0100 Message-Id: <20201130123928.21837-1-arne@rfc2549.org> X-Mailer: git-send-email 2.17.1 X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. 0.0 URIBL_BLOCKED ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [URIs: rfc2549.org] 0.2 HEADER_FROM_DIFFERENT_DOMAINS From and EnvelopeFrom 2nd level mail domains are different 0.0 SPF_NONE SPF: sender does not publish an SPF Record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record X-Headers-End: 1kjiT7-006cWE-67 Subject: [Openvpn-devel] [PATCH] Fix auth-token not being updated if auth-nocache is set X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox 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 Acked-by: Gert Doering --- src/openvpn/misc.c | 9 +++++++-- 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 1038b383..c0c72dd7 100644 --- a/src/openvpn/misc.c +++ b/src/openvpn/misc.c @@ -510,10 +510,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 a03d94e2..8c3a1227 100644 --- a/src/openvpn/misc.h +++ b/src/openvpn/misc.h @@ -145,6 +145,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);