From patchwork Sun Mar 21 23:39:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kristof Provost via Openvpn-devel X-Patchwork-Id: 1652 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director10.mail.ord1d.rsapps.net ([172.30.191.6]) by backend30.mail.ord1d.rsapps.net with LMTP id sITVBLR2WGBdWwAAIUCqbw (envelope-from ) for ; Mon, 22 Mar 2021 06:51:32 -0400 Received: from proxy1.mail.ord1d.rsapps.net ([172.30.191.6]) by director10.mail.ord1d.rsapps.net with LMTP id WNiEBLR2WGASdgAApN4f7A (envelope-from ) for ; Mon, 22 Mar 2021 06:51:32 -0400 Received: from smtp7.gate.ord1c ([172.30.191.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy1.mail.ord1d.rsapps.net with LMTPS id qL9/BLR2WGDrdAAAasrz9Q (envelope-from ) for ; Mon, 22 Mar 2021 06:51:32 -0400 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.ord1c.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=pass header.d=lists.sourceforge.net; dkim=fail (signature verification failed) header.d=sourceforge.net; dkim=fail (signature verification failed) header.d=sf.net; dkim=fail (signature verification failed) header.d=rozman.si; dmarc=pass (p=none; dis=none) header.from=lists.sourceforge.net X-Suspicious-Flag: NO X-Classification-ID: 8fa9b128-8afc-11eb-9a37-bc305bf04148-1-1 Received: from [216.105.38.7] ([216.105.38.7:39064] helo=lists.sourceforge.net) by smtp7.gate.ord1c.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id C5/60-07265-3B678506; Mon, 22 Mar 2021 06:51:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.sourceforge.net; s=beta; h=Content-Transfer-Encoding:Content-Type: Reply-To:From:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Subject:MIME-Version:Message-Id:Date:To:Sender:Cc: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=cv6SoC8MrFmNejfGyQUk9m5DfhuWmgVXDnrggjWixq0=; b=R0p0wfOdITv3H+1yxFZdez9H3I SDHfT+oRPCZ5l3sIfLOIlnoVvja7aEhs6+5f5GXoUUx94St72HppIKtZHRiTQ45s9TPrM4/vopkcG mvtvoYpo9SccyOkHZxzrnDYsPtkMQbZuHQoljPbVSOxwfUafndeg3fpq0BoDcqTVfWEU=; Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1lOI8d-0003fG-Bz; Mon, 22 Mar 2021 10:50:23 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lOI8b-0003f8-IS for openvpn-devel@lists.sourceforge.net; Mon, 22 Mar 2021 10:50:21 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: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=oofJggOc2lqKmBHsCZTYhwDEBx8J29CPKVKtV9r2qUU=; b=ar7VAeIY/e0rhHZKKgnYRJNkUp idusAriFjlmyT8Ho88wfTOB06KpaO8HLJorlxXekJU6CRa276J7ZNjcBtJkE5vjKtdSu8LC/cy9va deNsj0lX6hddHon3Tjijcg+VuhvebE1Si+jr9dKaO3MjqRW3DRca8IGlIM40R1YES/r8=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Subject:Cc:To:From :Sender:Reply-To:Content-Type: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=oofJggOc2lqKmBHsCZTYhwDEBx8J29CPKVKtV9r2qUU=; b=R ecKWlfiy4vcGYCPKEJYkRyAr+oEp1Q/05yakAp37VDrvw+hDhiTTDvRAOT42aUMOyyZyrur3xAHc8 HmXI9HCOfLsba6dKoBJ3nWnQY1k2lPATKiwjoGVRP6QOo+uv0ZLpo9L+WnH0aCnVzCohwy9gWQ0VN JW/bVtyu2D02tKKQ=; Received: from krn.amebis.si ([93.103.235.207]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.3) id 1lOI8R-0001Wb-0b for openvpn-devel@lists.sourceforge.net; Mon, 22 Mar 2021 10:50:21 +0000 Received: by krn.amebis.si (Postfix, from userid 982) id 2ACE018E878A; Mon, 22 Mar 2021 11:40:05 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rozman.si; s=default; t=1616409605; bh=oofJggOc2lqKmBHsCZTYhwDEBx8J29CPKVKtV9r2qUU=; h=From:To:Cc:Subject:Date:From; b=ee4D4INlZrZSil+dhDynvDMabcNgleTPdbp/oO8T0mdgZg7FX86BLtIZXR/y7Kmzy iIZsu42D6w/KlyXUbLF3lV1bT4lJDZ5NZlGXE4i7WE6IF2wvtASZ/LpTOUkPZTL5cd 576ohUXmdYtNV3LwaPKSEa9ULIt2g+jGfRhCfk08= X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on krn.amebis.doma X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 Received: from SR6.amebis.doma (unknown [IPv6:2a01:260:4101:1464:a506:9854:23ad:d966]) by krn.amebis.si (Postfix) with ESMTP id 3696218E8787; Mon, 22 Mar 2021 11:40:03 +0100 (CET) To: openvpn-devel@lists.sourceforge.net Date: Mon, 22 Mar 2021 11:39:57 +0100 Message-Id: <20210322103957.1234-1-simon@rozman.si> X-Mailer: git-send-email 2.30.0.windows.2 MIME-Version: 1.0 X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-Headers-End: 1lOI8R-0001Wb-0b Subject: [Openvpn-devel] [PATCH] openvpnserv: Cache last error before it is overridden 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: , X-Patchwork-Original-From: Simon Rozman via Openvpn-devel From: Kristof Provost via Openvpn-devel Reply-To: Simon Rozman Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox FormatMessage() sets the last error according to its own success. This looses the original error code leading to mismatched error message and error number when sprintfted together resulting in confusing event log message. Signed-off-by: Simon Rozman Acked-by: Gert Doering --- src/openvpnserv/common.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/openvpnserv/common.c b/src/openvpnserv/common.c index 48769be4..ebd08677 100644 --- a/src/openvpnserv/common.c +++ b/src/openvpnserv/common.c @@ -228,12 +228,14 @@ out: LPCTSTR GetLastErrorText() { + DWORD error; static TCHAR buf[256]; DWORD len; LPTSTR tmp = NULL; + error = GetLastError(); len = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ARGUMENT_ARRAY, - NULL, GetLastError(), LANG_NEUTRAL, (LPTSTR)&tmp, 0, NULL); + NULL, error, LANG_NEUTRAL, (LPTSTR)&tmp, 0, NULL); if (len == 0 || (long) _countof(buf) < (long) len + 14) { @@ -242,7 +244,7 @@ GetLastErrorText() else { tmp[_tcslen(tmp) - 2] = TEXT('\0'); /* remove CR/LF characters */ - openvpn_sntprintf(buf, _countof(buf), TEXT("%s (0x%x)"), tmp, GetLastError()); + openvpn_sntprintf(buf, _countof(buf), TEXT("%s (0x%x)"), tmp, error); } if (tmp)