[PATCH] Fix asking for username and password in smbget.
Jeremy Allison
jra at samba.org
Thu Aug 25 22:30:10 UTC 2016
On Thu, Aug 25, 2016 at 02:29:25PM +0200, Andreas Schneider wrote:
> The patch fixes get_auth_data() to deal with:
>
> smbget smb://DOMAIN;username:secret@server/share/file
>
> https://bugzilla.samba.org/show_bug.cgi?id=12175
>
> Review and push appreciated!
It's missing a removal of the now unused 'tmp'
variable. With that - LGTM.
Reiewed-by: Jeremy Allison <jra at samba.org>
> -- andreas
>
> --
> Andreas Schneider GPG-ID: CC014E3D
> Samba Team asn at samba.org
> www.samba.org
> From bd3001412d65298ce7eb8b32554ab50f90311014 Mon Sep 17 00:00:00 2001
> From: Andreas Schneider <asn at samba.org>
> Date: Thu, 25 Aug 2016 14:24:08 +0200
> Subject: [PATCH] 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 at samba.org>
> ---
> source3/utils/smbget.c | 25 ++++++++++++-------------
> 1 file changed, 12 insertions(+), 13 deletions(-)
>
> diff --git a/source3/utils/smbget.c b/source3/utils/smbget.c
> index 99261e3..74e33de 100644
> --- a/source3/utils/smbget.c
> +++ b/source3/utils/smbget.c
> @@ -115,23 +115,22 @@ static void get_auth_data(const char *srv, const char *shr, char *wg, int wglen,
> }
> hasasked = true;
>
> - if (!opt.nonprompt && !opt.username_specified) {
> - printf("Username for %s at %s [guest] ", shr, srv);
> - if (fgets(tmp, sizeof(tmp), stdin) == NULL) {
> - return;
> - }
> - if ((strlen(tmp) > 0) && (tmp[strlen(tmp) - 1] == '\n')) {
> - tmp[strlen(tmp) - 1] = '\0';
> - }
> - strncpy(un, tmp, unlen - 1);
> - } else if (opt.username != NULL) {
> + /*
> + * If no user has been specified un is initialized with the current
> + * username of the user who started smbget.
> + */
> + if (opt.username_specified) {
> strncpy(un, opt.username, unlen - 1);
> }
>
> - if (!opt.nonprompt && !opt.password_specified) {
> + if (!opt.nonprompt && !opt.password_specified && pw[0] == '\0') {
> char *prompt;
> - if (asprintf(&prompt, "Password for %s at %s: ", shr, srv) ==
> - -1) {
> + int rc;
> +
> + rc = asprintf(&prompt,
> + "Password for [%s] connecting to //%s/%s: ",
> + un, shr, srv);
> + if (rc == -1) {
> return;
> }
> (void)samba_getpass(prompt, pw, pwlen, false, false);
> --
> 2.9.3
>
More information about the samba-technical
mailing list