From patchwork Fri Jun 18 05:52:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lev Stipakov X-Patchwork-Id: 1867 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director8.mail.ord1d.rsapps.net ([172.28.255.1]) by backend30.mail.ord1d.rsapps.net with LMTP id ot2LALNu0GB2dwAAIUCqbw (envelope-from ) for ; Mon, 21 Jun 2021 06:49:23 -0400 Received: from proxy7.mail.ord1c.rsapps.net ([172.28.255.1]) by director8.mail.ord1d.rsapps.net with LMTP id IPZ2O7Ju0GAdagAAfY0hYg (envelope-from ) for ; Mon, 21 Jun 2021 06:49:22 -0400 Received: from smtp36.gate.ord1c ([172.28.255.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy7.mail.ord1c.rsapps.net with LMTPS id GFwFO7Ju0GDwaQAAknS3pQ (envelope-from ) for ; Mon, 21 Jun 2021 06:49:22 -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: smtp36.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=fail (signature verification failed) header.d=sourceforge.net; dkim=fail (signature verification failed) header.d=sf.net; dkim=fail (signature verification failed) header.d=gmail.com; dmarc=fail (p=none; dis=none) header.from=gmail.com X-Suspicious-Flag: YES X-Classification-ID: 564d2fc6-d27e-11eb-8ea3-5452006630bd-1-1 Received: from [216.105.38.7] ([216.105.38.7:48562] helo=lists.sourceforge.net) by smtp36.gate.ord1c.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 70/0C-14468-2BE60D06; Mon, 21 Jun 2021 06:49:22 -0400 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 1lvHTO-0001qe-S4; Mon, 21 Jun 2021 10:48:10 +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 1lvHTN-0001qX-Te for openvpn-devel@lists.sourceforge.net; Mon, 21 Jun 2021 10:48:09 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: 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=PNDXUkbnE7oLuXnyizkMlosrwH9ZCfnmoQ446qfylDI=; b=DT6IMK32HG63V1azBlmpqPvfAO h+zOOitVVq2nwFozRfFcv3Q/RzlODAJQ2jeQnjgn4thS2ZgJtemcyjFJfjt5yPXGaD4iGFWwfSALZ 6Fii8VF+oTgEqENQIo4C2yj+6XjDDfyeIQY1V78eTJLi/lfdkBugpGne9A9ss6i1FJ34=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: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=PNDXUkbnE7oLuXnyizkMlosrwH9ZCfnmoQ446qfylDI=; b=hrAsmPy9Trrb8ZsD8HyQGH7gcH kfGuRgKmEeWuvhV/nAkOFIBsTFrJfKGBs55JTeBAYfdeld7uh4midSVmdbnk7mh6ZiRnaQuVU1MMm sTZj+DzXtgYgqOFK7uA/MZE114pi0tbJF72gGhHb0RFtB+fwq/VZE9huIvRaUCeq5KbM=; Received: from mail-wr1-f48.google.com ([209.85.221.48]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.92.3) id 1lvHTL-0004B7-TW for openvpn-devel@lists.sourceforge.net; Mon, 21 Jun 2021 10:48:12 +0000 Received: by mail-wr1-f48.google.com with SMTP id n7so19100991wri.3 for ; Mon, 21 Jun 2021 03:48:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=PNDXUkbnE7oLuXnyizkMlosrwH9ZCfnmoQ446qfylDI=; b=BFOZb7ioBEdaR9nNalwqqGF8KXEJG7bybWqRJa4fGBNz3FtQ8BfarexdGKWjIw9p7G Gq/arHNm0+QdjRWXziPncOAawKGOPnMBl14w2VmeH1w5Q0HrZ2JBCOL9/SY4MgJPQN53 QdEwPpDfwFp4IeyVGDDXbgTsv5RCyfcz5vOEcp/BxBYF7sWH6aEQ77zmoICdreuLqcPa esAnVH3nC1y9VSD9JNBeKonSEkRK4qmNTgI22a9p2RQhK/eSVV6eZlYTkQRKRuP/mKPM 8ELbiSGGD4HfUW3KLvsOr0ZQclM7uh/9LYEAKfWheubAN5XyArf4gxbdzp6Zugx1LuGv AUJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=PNDXUkbnE7oLuXnyizkMlosrwH9ZCfnmoQ446qfylDI=; b=C/gyF+o99hZ8Me85wB/YJ/gbZitaJYr4P3vGrROPmr92NaabaIm4WD+ASCAi7Fw2bD ZH9Rfsc4eemW6NagHRyhoYSjq698M9RWwjGlQV5cbXAgVQXdTrKpgH0sdyHJoiE0kVNY UHOKDWVhkCRY3o+WuybEwXxMkoCV5uz5L2U5bc/XQ4YFRZvvA4mAWCIvFKujuuv3cK5b YKmq46l6FpdTpXXzmEPFonWbk/CaWqoRKiomOB36XXHVJgxuoPqUhB6EUa2ll885JzPx Vcp0hqTGy6tqMZBmNHeGmUzvVkghveby/OStfT1bfJMC59L0olKJjFQB6FDrtQdb6Zp9 5EVw== X-Gm-Message-State: AOAM5320MiptOR1bAKqUkbbN4Ap/Z7hXGzi+2WeDJej2cbfkC8D0hpyk iaLFGvWHKP4uTa8xgJK0UQKXK/h0BvH/hQ== X-Google-Smtp-Source: ABdhPJygNktjRqBIBUG4kUojAPRonsCPAYCpsFK2iKNHO9J8P6LAUCFT/SElPGYdWoRwWxTHPFCyvQ== X-Received: by 2002:adf:c641:: with SMTP id u1mr27469828wrg.207.1624272482831; Mon, 21 Jun 2021 03:48:02 -0700 (PDT) Received: from LAPTOP-4L3N7KFS.localdomain (nat1.panoulu.net. [185.38.2.1]) by smtp.gmail.com with ESMTPSA id n42sm19085491wms.29.2021.06.21.03.48.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Jun 2021 03:48:02 -0700 (PDT) From: Lev Stipakov To: openvpn-devel@lists.sourceforge.net Date: Fri, 18 Jun 2021 18:52:41 +0300 Message-Id: <20210618155241.400-1-lstipakov@gmail.com> 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 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (lstipakov[at]gmail.com) -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [209.85.221.48 listed in wl.mailspike.net] -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [209.85.221.48 listed in list.dnswl.org] -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: 1lvHTL-0004B7-TW Subject: [Openvpn-devel] [PATCH] Fix management password prompt with redirected log 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: , Cc: Lev Stipakov MIME-Version: 1.0 Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox From: Lev Stipakov When management interface is password protected, openvpn writes "Enter Management Password" to stderr. As it turns out, when log is redirected to a file, that prompt is also written to that file and not to the "original" stderr. Moreover, on recent Insider build (21390.2025) openvpn exits with fatal error get_console_input_win32(): unexpected error: No such device or address (errno=6) while attempting to write that prompt. When redirecting stdout/stderr, we use _dup2() to associate stderr descriptor with the log file. This call closes file associated with stderr descriptor, which might explain why it has stopped working (original stderr is closed and WriteFile() fails) and on current versions it appears to work "by accident" - not failing but use redirected stderr instead of original one. I played a bit with DuplicateHandle() for STD_ERROR_HANDLE but got the same behavior. Fix fatal error on Insider build by always writing prompt to the new stderr and removing concept of "orig_stderr". For current Windows releases behavior doesn't change. Signed-off-by: Lev Stipakov --- src/openvpn/console_builtin.c | 2 +- src/openvpn/error.c | 31 ------------------------------- src/openvpn/error.h | 6 ------ 3 files changed, 1 insertion(+), 38 deletions(-) diff --git a/src/openvpn/console_builtin.c b/src/openvpn/console_builtin.c index 9bf36347..31214536 100644 --- a/src/openvpn/console_builtin.c +++ b/src/openvpn/console_builtin.c @@ -73,7 +73,7 @@ get_console_input_win32(const char *prompt, const bool echo, char *input, const input[0] = '\0'; in = GetStdHandle(STD_INPUT_HANDLE); - err = get_orig_stderr(); + err = GetStdHandle(STD_ERROR_HANDLE); if (in == INVALID_HANDLE_VALUE || err == INVALID_HANDLE_VALUE diff --git a/src/openvpn/error.c b/src/openvpn/error.c index b94d387c..e807435c 100644 --- a/src/openvpn/error.c +++ b/src/openvpn/error.c @@ -490,25 +490,6 @@ close_syslog(void) #endif } -#ifdef _WIN32 - -static HANDLE orig_stderr; - -HANDLE -get_orig_stderr(void) -{ - if (orig_stderr) - { - return orig_stderr; - } - else - { - return GetStdHandle(STD_ERROR_HANDLE); - } -} - -#endif - void redirect_stdout_stderr(const char *file, bool append) { @@ -549,18 +530,6 @@ redirect_stdout_stderr(const char *file, bool append) } } - /* save original stderr for password prompts */ - orig_stderr = GetStdHandle(STD_ERROR_HANDLE); - -#if 0 /* seems not be necessary with stdout/stderr redirection below*/ - /* set up for redirection */ - if (!SetStdHandle(STD_OUTPUT_HANDLE, log_handle) - || !SetStdHandle(STD_ERROR_HANDLE, log_handle)) - { - msg(M_ERR, "Error: cannot redirect stdout/stderr to --log file: %s", file); - } -#endif - /* direct stdout/stderr to point to log_handle */ log_fd = _open_osfhandle((intptr_t)log_handle, _O_TEXT); if (log_fd == -1) diff --git a/src/openvpn/error.h b/src/openvpn/error.h index f4528ef2..b91e54fb 100644 --- a/src/openvpn/error.h +++ b/src/openvpn/error.h @@ -255,12 +255,6 @@ void close_syslog(void); /* log file output */ void redirect_stdout_stderr(const char *file, bool append); -#ifdef _WIN32 -/* get original stderr handle, even if redirected by --log/--log-append */ -HANDLE get_orig_stderr(void); - -#endif - /* exit program */ void openvpn_exit(const int status);