smbget: fix recursive download
[ambi/samba.git] / source3 / utils / smbget.c
index b3ce7432ede71d01bafeca836f23f916bd6aa667..7302507a0ee284bed0dc6c73881bcebbfe9e0380 100644 (file)
@@ -91,10 +91,18 @@ static void human_readable(off_t s, char *buffer, int l)
 static void get_auth_data(const char *srv, const char *shr, char *wg, int wglen, char *un, int unlen, char *pw, int pwlen)
 {
        static char hasasked = 0;
+       static fstring savedwg;
+       static fstring savedun;
+       static fstring savedpw;
        char *wgtmp, *usertmp;
        char tmp[128];
 
-       if(hasasked) return;
+       if (hasasked) {
+               strncpy(wg, savedwg, wglen-1);
+               strncpy(un, savedun, unlen-1);
+               strncpy(pw, savedpw, pwlen-1);
+               return;
+       }
        hasasked = 1;
 
        if(!nonprompt && !username) {
@@ -119,6 +127,11 @@ static void get_auth_data(const char *srv, const char *shr, char *wg, int wglen,
 
        if(workgroup)strncpy(wg, workgroup, wglen-1);
 
+       // save the values found for later
+       strncpy(savedwg, wg, sizeof(savedwg)-1);
+       strncpy(savedun, un, sizeof(savedun)-1);
+       strncpy(savedpw, pw, sizeof(savedpw)-1);
+
        wgtmp = SMB_STRNDUP(wg, wglen); 
        usertmp = SMB_STRNDUP(un, unlen);
        if(!quiet)printf("Using workgroup %s, %s%s\n", wgtmp, *usertmp?"user ":"guest user", usertmp);