]> git.ipfire.org Git - thirdparty/openvpn.git/commit
Fix console prompts with redirected log
authorLev Stipakov <lev@openvpn.net>
Fri, 25 Jun 2021 01:04:05 +0000 (04:04 +0300)
committerGert Doering <gert@greenie.muc.de>
Fri, 25 Jun 2021 16:00:13 +0000 (18:00 +0200)
commit86b247a40b919fa8e0a3de1c367087355bb10074
tree2f0986f44767088a9d2907edcd3792f288100cbd
parentb6012d80a198b5d7e8c2f399b92a1299c660a326
Fix console prompts with redirected log

When openvpn needs to prompt user for a password
(for example, to set management interface password),
the prompt is written to standard error device.

When log is redirected to a file, that prompt is 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 a 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
older versions it appears to work "by accident" - not failing
but use redirected stderr instead of original one.

Fix by creating new file descriptor with _dup() for stderr
before redirect and use this descriptor for writing prompts.

While on it, make code a bit more C99-ish by moving variables
declaration from the beginning of the scope to the actual
initialisation.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20210625010405.224-1-lstipakov@gmail.com>
URL: https://www.mail-archive.com/search?l=mid&q=20210625010405.224-1-lstipakov@gmail.com
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 480e4cc14ff34fac72406ab1dd66290a91cc09f0)
src/openvpn/console_builtin.c
src/openvpn/error.c
src/openvpn/error.h