1
0
mirror of https://github.com/samba-team/samba.git synced 2025-02-26 21:57:41 +03:00

s3-util: Fix asking for username and password in smbget.

If the user specified the username in the URI with with:

  smb://DOMAIN;user:secret@server/share

the tool should not prompt for the username nor the password.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=12175

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>

(cherry picked from commit f5401ff3146aabc5fb2dac25e4856c6c3756c8f7)

Autobuild-User(v4-5-test): Stefan Metzmacher <metze@samba.org>
Autobuild-Date(v4-5-test): Sun Aug 28 22:02:12 CEST 2016 on sn-devel-144
This commit is contained in:
Andreas Schneider 2016-08-25 14:24:08 +02:00 committed by Stefan Metzmacher
parent 372fb30da7
commit 6c6fb451e3

View File

@ -105,7 +105,6 @@ static void get_auth_data(const char *srv, const char *shr, char *wg, int wglen,
static char *savedwg; static char *savedwg;
static char *savedun; static char *savedun;
static char *savedpw; static char *savedpw;
char tmp[128];
if (hasasked) { if (hasasked) {
strncpy(wg, savedwg, wglen - 1); strncpy(wg, savedwg, wglen - 1);
@ -115,23 +114,22 @@ static void get_auth_data(const char *srv, const char *shr, char *wg, int wglen,
} }
hasasked = true; hasasked = true;
if (!opt.nonprompt && !opt.username_specified) { /*
printf("Username for %s at %s [guest] ", shr, srv); * If no user has been specified un is initialized with the current
if (fgets(tmp, sizeof(tmp), stdin) == NULL) { * username of the user who started smbget.
return; */
} if (opt.username_specified) {
if ((strlen(tmp) > 0) && (tmp[strlen(tmp) - 1] == '\n')) {
tmp[strlen(tmp) - 1] = '\0';
}
strncpy(un, tmp, unlen - 1);
} else if (opt.username != NULL) {
strncpy(un, opt.username, unlen - 1); strncpy(un, opt.username, unlen - 1);
} }
if (!opt.nonprompt && !opt.password_specified) { if (!opt.nonprompt && !opt.password_specified && pw[0] == '\0') {
char *prompt; char *prompt;
if (asprintf(&prompt, "Password for %s at %s: ", shr, srv) == int rc;
-1) {
rc = asprintf(&prompt,
"Password for [%s] connecting to //%s/%s: ",
un, shr, srv);
if (rc == -1) {
return; return;
} }
(void)samba_getpass(prompt, pw, pwlen, false, false); (void)samba_getpass(prompt, pw, pwlen, false, false);