From patchwork Sun Mar 28 02:51:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?T=C3=B5ivo_Leedj=C3=A4rv?= X-Patchwork-Id: 1670 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director7.mail.ord1d.rsapps.net ([172.31.255.6]) by backend30.mail.ord1d.rsapps.net with LMTP id WGUFC0OKYGB6BAAAIUCqbw (envelope-from ) for ; Sun, 28 Mar 2021 09:53:07 -0400 Received: from proxy16.mail.iad3b.rsapps.net ([172.31.255.6]) by director7.mail.ord1d.rsapps.net with LMTP id oM3ICkOKYGCkQgAAovjBpQ (envelope-from ) for ; Sun, 28 Mar 2021 09:53:07 -0400 Received: from smtp22.gate.iad3b ([172.31.255.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy16.mail.iad3b.rsapps.net with LMTPS id mDGxAkOKYGDdDAAAPj+4aA (envelope-from ) for ; Sun, 28 Mar 2021 09:53:07 -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: smtp22.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; 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: ec0e2b0e-8fcc-11eb-ba67-52540041dff8-1-1 Received: from [216.105.38.7] ([216.105.38.7:45806] helo=lists.sourceforge.net) by smtp22.gate.iad3b.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 0F/ED-26206-24A80606; Sun, 28 Mar 2021 09:53:06 -0400 Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1lQVpq-0002EM-QS; Sun, 28 Mar 2021 13:52:10 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lQVpo-0002Ds-GN for openvpn-devel@lists.sourceforge.net; Sun, 28 Mar 2021 13:52:08 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:Content-Type:To:Subject: Message-ID:Date:From:MIME-Version:Sender:Reply-To:Cc: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=5ORUpcZQQDf9Q2GLW2HLtb09d7FYO6guB5w5naaZALc=; b=dqkKGVq9SJUKcamwhoz4BCtTkd pLjzOil/PReDdXb4TbGwAKA991l0GUv1l3FDiN06XO+skp4jsrH/HqJ7lPQZF7KTLgcEeNhJogCLa RPs2kxYCJDfUOpGhz/9nyLQRemz+gOByqkgXfMZM5GhdH2yzVYG03Dt+Z1d8KnkWaqa8=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:Content-Type:To:Subject:Message-ID:Date:From: MIME-Version:Sender:Reply-To:Cc: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=5ORUpcZQQDf9Q2GLW2HLtb09d7FYO6guB5w5naaZALc=; b=d nt1DkA4OLO5+DZy+txndU8WObrulp/6+88GI0G3qefJK/wT2jV6elBSEHNEM0OWO2uh5t/2NOouoo A1Y9NYx2PLNZg/jCOlP1C9e8rt2vY5ZJjxju7yyrgk0O5M6sN2SVDM6wToYjfK0T8GQXRk9kZdy6q xYwwjVmvZnsgogw0=; Received: from mail-ua1-f47.google.com ([209.85.222.47]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.92.2) id 1lQVpc-004XQw-9l for openvpn-devel@lists.sourceforge.net; Sun, 28 Mar 2021 13:52:08 +0000 Received: by mail-ua1-f47.google.com with SMTP id c2so3168244uaj.3 for ; Sun, 28 Mar 2021 06:51:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to :content-transfer-encoding; bh=5ORUpcZQQDf9Q2GLW2HLtb09d7FYO6guB5w5naaZALc=; b=Yjv2FmX42WwwwxjJJvCDleZlev/BdNrZ7YbhXakt2gPE1dO3QPlsB9z9zovZKYeTyL snz/8TE3O8A1X9Av58x2/ruK2f35NgD6docaIKwoYUUXm7Eu+sPWANETAPpi0i7eASaX L3V1z/UHjg/SA91+epv+zmrrGR4MUjagVHBUBq3EIELdktj0febSZ/ES4p6hWceGeGzo Vbc/1DF9QTpiFjj0vyMS/dNUOPqguFb1c/k0nx8iFKcBGVBbzERSSw2YitxSoPu0UtZx GrvoUN+w3fvDoJFiveneOsQbww9cpsDU8ZeXoUbG1sSCj3+p73SWHXQS9wyLMz+2GsJW jRxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to :content-transfer-encoding; bh=5ORUpcZQQDf9Q2GLW2HLtb09d7FYO6guB5w5naaZALc=; b=WupJYyT1fnZixwGuLs5qqjuRbhsNApp4oKQvElh2llz3WXN4d56Z3WwMu2Gkznrt8A W9bi9tqNo3JKQ8m1T2pwxX400eVJYIS8yCdOohqeu4LnLR6qmKXvBHaVVR/pufqWvDed /XU2p66OC5JlRVxUfVwPaLsMY3uKM6qt1VX74x5XwXcinFOaz0ILLLmbHemAdck54Egp iD6UoCFuPyoNFnTt/7c5rso1oPeCvENjmER5twflb9pmL6MQ3BNJ7jdC5edKGSaP6rBe VcVTYxbPQutnE8L6oUksb01gKQIHBObg2fgW6jyQq3PUyg+M+53ncaEwj6VeaGqDBeFL avsQ== X-Gm-Message-State: AOAM532/1JLLUklLMhZ+RLL65FQ5QCdL339sQ0TdZDv9PxxqDMjmUeD8 FBceJDVDGbcRBmYi5jODwxrqb/IgfCXKYZa5RUmg9dyD X-Google-Smtp-Source: ABdhPJzj23We6OMc9+l1f0reXIATm4q5pj5GO7CP7Y3s4ZaV0RxbBCP7kZ2gsLw+fphpQR9LGTt58lJioc+HYXFx284= X-Received: by 2002:ab0:703a:: with SMTP id u26mr12340416ual.34.1616939510483; Sun, 28 Mar 2021 06:51:50 -0700 (PDT) MIME-Version: 1.0 From: =?utf-8?q?T=C3=B5ivo_Leedj=C3=A4rv?= Date: Sun, 28 Mar 2021 15:51:39 +0200 Message-ID: To: openvpn-devel@lists.sourceforge.net 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 (toivol[at]gmail.com) 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: configure.ac] -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [209.85.222.47 listed in wl.mailspike.net] -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [209.85.222.47 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: 1lQVpc-004XQw-9l Subject: [Openvpn-devel] [PATCH v2] Stop using deprecated getpass() 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: , Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox The getpass() function is present in SUSv2, but marked LEGACY. It is removed in POSIX.1-2001. Additionally, on Solaris getpass() returns maximum 9 bytes. This will make longer passwords fail with no possibility for user to know what is happening. This patch removes usage of getpass() completely and replaces it with direct implementation of what getpass() does: opens tty (existing code), outputs the prompt (existing code), turns off echoing (new code), reads one line (existing code shared with echoed mode), restores tty state (new code) and closes tty (existing code). Patch v2: incorporate review feedback, incl. style fixes, merge termios.h check in configure.ac with an existing AC_CHECK_HEADERS, add error check and logging after tcsettattr() when restoring tty settings Signed-off-by: Tõivo Leedjärv --- configure.ac | 4 +-- src/openvpn/console_builtin.c | 60 +++++++++++++++++++++-------------- 2 files changed, 39 insertions(+), 25 deletions(-) * Open the current console TTY for read/write operations @@ -177,7 +181,7 @@ close_tty(FILE *fp) } } -#endif /* HAVE_GETPASS */ +#endif /* HAVE_TERMIOS_H */ /** @@ -201,7 +205,9 @@ get_console_input(const char *prompt, const bool echo, char *input, const int ca #if defined(_WIN32) return get_console_input_win32(prompt, echo, input, capacity); -#elif defined(HAVE_GETPASS) +#elif defined(HAVE_TERMIOS_H) + bool restore_tty = false; + struct termios tty_tmp, tty_save; /* did we --daemon'ize before asking for passwords? * (in which case neither stdin or stderr are connected to a tty and @@ -220,33 +226,41 @@ get_console_input(const char *prompt, const bool echo, char *input, const int ca close(fd); } - if (echo) - { - FILE *fp; + FILE *fp = open_tty(true); + fprintf(fp, "%s", prompt); + fflush(fp); + close_tty(fp); - fp = open_tty(true); - fprintf(fp, "%s", prompt); - fflush(fp); - close_tty(fp); + fp = open_tty(false); - fp = open_tty(false); - if (fgets(input, capacity, fp) != NULL) - { - chomp(input); - ret = true; - } - close_tty(fp); + if (!echo && (tcgetattr(fileno(fp), &tty_tmp) == 0)) + { + tty_save = tty_tmp; + tty_tmp.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL | ISIG); + restore_tty = (tcsetattr(fileno(fp), TCSAFLUSH, &tty_tmp) == 0); } - else + + if (fgets(input, capacity, fp) != NULL) + { + chomp(input); + ret = true; + } + + if (restore_tty) { - char *gp = getpass(prompt); - if (gp) + if (tcsetattr(fileno(fp), TCSAFLUSH, &tty_save) == -1) { - strncpynt(input, gp, capacity); - secure_memzero(gp, strlen(gp)); - ret = true; + msg(M_WARN | M_ERRNO, "tcsetattr() failed to restore tty settings"); } + + /* Echo the non-echoed newline */ + close_tty(fp); + fp = open_tty(true); + fprintf(fp, "\n"); + fflush(fp); } + + close_tty(fp); #else /* if defined(_WIN32) */ msg(M_FATAL, "Sorry, but I can't get console input on this OS (%s)", prompt); #endif /* if defined(_WIN32) */ -- 2.26.2 diff --git a/configure.ac b/configure.ac index 428bebed..6668bbcf 100644 --- a/configure.ac +++ b/configure.ac @@ -438,7 +438,7 @@ AC_CHECK_HEADERS([ \ sys/time.h sys/ioctl.h sys/stat.h \ sys/mman.h sys/file.h sys/wait.h \ unistd.h signal.h libgen.h stropts.h \ - syslog.h pwd.h grp.h \ + syslog.h pwd.h grp.h termios.h \ sys/sockio.h sys/uio.h linux/sockios.h \ linux/types.h poll.h sys/epoll.h err.h \ ]) @@ -652,7 +652,7 @@ AC_FUNC_FORK AC_CHECK_FUNCS([ \ daemon chroot getpwnam setuid nice system getpid dup dup2 \ - getpass syslog openlog mlockall getrlimit getgrnam setgid \ + syslog openlog mlockall getrlimit getgrnam setgid \ setgroups stat flock readv writev time gettimeofday \ ctime memset vsnprintf strdup \ setsid chdir putenv getpeername unlink \ diff --git a/src/openvpn/console_builtin.c b/src/openvpn/console_builtin.c index 445928bf..22ac9f79 100644 --- a/src/openvpn/console_builtin.c +++ b/src/openvpn/console_builtin.c @@ -40,6 +40,10 @@ #include "buffer.h" #include "misc.h" +#ifdef HAVE_TERMIOS_H +#include +#endif + #ifdef _WIN32 #include "win32.h" @@ -138,7 +142,7 @@ get_console_input_win32(const char *prompt, const bool echo, char *input, const #endif /* _WIN32 */ -#ifdef HAVE_GETPASS +#ifdef HAVE_TERMIOS_H /**