]> 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 15:37:48 +0000 (17:37 +0200)
commit480e4cc14ff34fac72406ab1dd66290a91cc09f0
tree4615f1e8ddb07640b3336391e270ffcda8c9edee
parente55bedd4ea435f95d288e60691abc6e53b8bf014
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>
src/openvpn/console_builtin.c
src/openvpn/error.c
src/openvpn/error.h