From 1c753c010f9bff550cf763c8980d94eabc02893f Mon Sep 17 00:00:00 2001 From: Vitezslav Crhonek Date: Tue, 10 Jan 2023 12:46:13 +0100 Subject: [PATCH] Replace obsolete getpass function --- replace-getpass.patch | 61 +++++++++++++++++++++++++++++++++++++++++++ wsmancli.spec | 7 ++++- 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 replace-getpass.patch diff --git a/replace-getpass.patch b/replace-getpass.patch new file mode 100644 index 0000000..eb25fe3 --- /dev/null +++ b/replace-getpass.patch @@ -0,0 +1,61 @@ +diff -up wsmancli-2.6.0/src/wsman.c.orig wsmancli-2.6.0/src/wsman.c +--- wsmancli-2.6.0/src/wsman.c.orig 2023-01-09 11:46:15.771553135 +0100 ++++ wsmancli-2.6.0/src/wsman.c 2023-01-09 11:54:13.968830290 +0100 +@@ -40,6 +40,7 @@ + #include + #include + #include ++#include + + #ifdef HAVE_UNISTD_H + #include +@@ -57,6 +58,8 @@ + extern char *getpass (const char *__prompt); + #endif + ++#define BASE_LEN 21 ++ + static long int server_port = 0; + static char *cainfo = NULL; + static char *cert = NULL; +@@ -498,6 +501,10 @@ request_usr_pwd( WsManClient *client, ws + char *pw; + char user[21]; + char *p; ++ char c; ++ int len = BASE_LEN; ++ int pos = 0; ++ struct termios term; + + /* + * fprintf(stdout,"Authentication failed, please retry\n"); +@@ -560,8 +567,28 @@ request_usr_pwd( WsManClient *client, ws + } + + /* but always ask for the password !? */ +- pw = (char *)getpass("Password: "); ++ /* set no echo */ ++ tcgetattr(1, &term); ++ term.c_lflag &= ~ECHO; ++ tcsetattr(1, TCSANOW, &term); ++ /* get pass */ ++ pw = (char*) u_malloc(sizeof(char) * len); ++ pw[0] = '\0'; ++ printf("Password: "); ++ fflush(stdout); ++ while ((c = fgetc(stdin)) != '\n') { ++ pw[pos++] = (char) c; ++ if (pos >= len) { ++ len += BASE_LEN; ++ pw = realloc(pw, len); ++ } ++ } ++ pw[pos] = '\0'; + *password = u_strdup_printf ("%s", pw); ++ u_free(pw); ++ /* set echo back again */ ++ term.c_lflag |= ECHO; ++ tcsetattr(1, TCSANOW, &term); + + /* make backup, *password will become free'd when next try of http-auth fails */ + if (*password) { diff --git a/wsmancli.spec b/wsmancli.spec index 086a7f4..b057838 100644 --- a/wsmancli.spec +++ b/wsmancli.spec @@ -1,6 +1,6 @@ Name: wsmancli Version: 2.6.0 -Release: 18%{?dist} +Release: 19%{?dist} License: BSD Url: http://www.openwsman.org/ # You can get this tarball here: @@ -15,6 +15,7 @@ BuildRequires: autoconf automake libtool Requires: openwsman curl Patch0: missing-pthread-symbols.patch Patch1: http-unauthorized-improve.patch +Patch2: replace-getpass.patch Summary: WS-Management-Command line Interface %description @@ -25,6 +26,7 @@ systems using Web Services Management protocol. %setup -q %patch0 -p1 %patch1 -p1 -b .http-unauthorized-improve +%patch2 -p1 -b .replace-getpass cp -fp %SOURCE1 %SOURCE2 %SOURCE3 .; %build @@ -43,6 +45,9 @@ make DESTDIR=%{buildroot} install %doc COPYING README AUTHORS %changelog +* Tue Jan 10 2023 Vitezslav Crhonek - 2.6.0-19 +- Replace obsolete getpass function + * Thu Sep 08 2022 Vitezslav Crhonek - 2.6.0-18 - Improve handling of HTTP 401 Unauthorized