Update to wsmancli-2.6.2

This commit is contained in:
Vitezslav Crhonek 2023-05-19 08:51:27 +02:00
parent bc6857af64
commit cc8bdd3218
5 changed files with 8 additions and 203 deletions

8
.gitignore vendored
View File

@ -1,7 +1 @@
wsmancli-2.2.3.tar.bz2
/wsmancli-2.2.4.tar.bz2
/wsmancli-2.2.5.tar.bz2
/wsmancli-2.2.7.1.tar.bz2
/wsmancli-2.3.0.tar.bz2
/v2.3.1.tar.gz
/wsmancli-2.6.0.tar.gz
/wsmancli-2.6.2.tar.gz

View File

@ -1,127 +0,0 @@
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 2015-06-11 10:50:04.000000000 +0200
+++ wsmancli-2.6.0/src/wsman.c 2022-07-19 09:09:48.518951546 +0200
@@ -63,7 +63,11 @@ static char *cert = NULL;
static char *sslkey = NULL;
static char *endpoint = NULL;
static char *username = NULL;
+static char *username_given = NULL; /* copy of either the username from env or cmdline*/
+static char *username_prev = NULL; /* input username to request_usr_pwd() when called last time */
static char *password = NULL;
+static char *password_given = NULL; /* copy of either the password from env or cmdline */
+static char *password_prev = NULL; /* input password to request_usr_pwd() when called last time */
static char *server = "localhost";
static char *agent = NULL;
static char *url_path = NULL;
@@ -495,28 +499,79 @@ request_usr_pwd( WsManClient *client, ws
char user[21];
char *p;
- fprintf(stdout,"Authentication failed, please retry\n");
- /*
- fprintf(stdout, "%s authentication is used\n",
- wsmc_transport_get_auth_name( auth));
- */
- printf("User name: ");
- fflush(stdout);
- if ( (p = fgets(user, 20, stdin) ) != NULL )
- {
-
- if (strchr(user, '\n'))
- (*(strchr(user, '\n'))) = '\0';
- *username = u_strdup_printf ("%s", user);
- } else {
- *username = NULL;
+ /*
+ * fprintf(stdout,"Authentication failed, please retry\n");
+ *
+ * this message shall not be printed by this function as it cannot decide on the
+ * reason it was called for. It does not control the authentication process.
+ * wsmc_handler is better suited for such a decision making.
+ */
+
+ if (username_given) {
+ if (password_given) {
+ /* Initially provided combination of password and username is not valid.
+ * Request user to type both. Here I assume, that wsmc_handler called back to
+ * this function after trying a first authentication using these credentials.
+ */
+ } else {
+ /* Initially no password was provided => no authentication tried during first
+ * iteration of while loop in wsmc_handler. Check previously typed credentials
+ */
+ if (username_prev) {
+ /* This is a second call of this function, assuming only wsmc_handler is using it
+ * as a callback function. Therefore, there must have been a previous attempt to
+ * authenticate, but this previous combination of username and password did not
+ * lead to a successful authentication. Request new credentials, username_prev will
+ * be set each time after user has provided a username.
+ */
+ } else {
+ /* First time wsmc_handler calls back to this function. No password given on the
+ * command line or via the environment variable. Therefore wsmc_handler cannot
+ * have tried http authentication. A username was given on the command line or
+ * via an environment variable. And the user wants us to try this name at least
+ * at first. So, let's do him a favour and use it. When we are called back again,
+ * we will ask the user to provide a new name or the same, but a different password.
+ */
+ *username = u_strdup(username_given);
+ }
+ }
+ }
+
+ if (*username == NULL) {
+ printf("User name: ");
+ fflush(stdout);
+ if ( (p = fgets(user, 20, stdin) ) != NULL )
+ {
+ if (strchr(user, '\n'))
+ (*(strchr(user, '\n'))) = '\0';
+ *username = u_strdup_printf ("%s", user);
+ } else {
+ *username = NULL;
+ }
+ }
+
+ /* after successfull receipt of a new username, store a copy at username_prev */
+ if (*username) {
+ if ( username_prev ) {
+ u_free(username_prev);
+ username_prev = NULL;
+ }
+ username_prev = u_strdup(*username);
}
+ /* but always ask for the password !? */
pw = (char *)getpass("Password: ");
*password = u_strdup_printf ("%s", pw);
-}
-
+ /* make backup, *password will become free'd when next try of http-auth fails */
+ if (*password) {
+ if (password_prev) {
+ u_free(password_prev);
+ password_prev = NULL;
+ }
+ password_prev = u_strdup(*password);
+ }
+}
static void
wsman_options_set_properties(client_opt_t *options)
@@ -647,6 +702,14 @@ int main(int argc, char **argv)
exit(EXIT_FAILURE);
}
+ /* save copies of username or password when given on the command line or via environment variables */
+ if ( username != NULL ) {
+ username_given = u_strdup(username);
+ }
+ if ( password != NULL ) {
+ password_given = u_strdup(password);
+ }
+
filename = (char *) config_file;
if (filename) {

View File

@ -1,61 +0,0 @@
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 <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <termios.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
@@ -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) {

View File

@ -1 +1 @@
df418d6d78160fd4f88f890a8953907a wsmancli-2.6.0.tar.gz
SHA512 (wsmancli-2.6.2.tar.gz) = 9b1c99b18d2f9f6125a48bb4639ffa970b67fd4ac2dae401a0b9205ab7a0650ebd77737ce386761143aedefd18a59b92407a63831568ca5597e92281df8414b0

View File

@ -1,6 +1,6 @@
Name: wsmancli
Version: 2.6.0
Release: 21%{?dist}
Version: 2.6.2
Release: 1%{?dist}
License: BSD-3-Clause
Url: http://www.openwsman.org/
# You can get this tarball here:
@ -14,8 +14,6 @@ BuildRequires: openwsman-devel >= 2.1.0 pkgconfig curl-devel
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
@ -24,9 +22,7 @@ systems using Web Services Management protocol.
%prep
%setup -q
%patch0 -p1
%patch1 -p1 -b .http-unauthorized-improve
%patch2 -p1 -b .replace-getpass
%autopatch -p1
cp -fp %SOURCE1 %SOURCE2 %SOURCE3 .;
%build
@ -45,6 +41,9 @@ make DESTDIR=%{buildroot} install
%doc COPYING README AUTHORS
%changelog
* Fri May 19 2023 Vitezslav Crhonek <vcrhonek@redhat.com> - 2.6.2-1
- Update to wsmancli-2.6.2
* Tue Apr 25 2023 Vitezslav Crhonek <vcrhonek@redhat.com> - 2.6.0-21
- SPDX migration