port latest changes from SAMBA_3_0 tree
[kamenim/samba.git] / source3 / client / client.c
index b498b5b4a88638521d4c50a799ce8ac71ea40100..ec29f44e6e0d261f3112c8d12410edd22574c15e 100644 (file)
@@ -438,7 +438,8 @@ static void add_to_do_list_queue(const char* entry)
        }
        if (do_list_queue)
        {
-               pstrcpy(do_list_queue + do_list_queue_end, entry);
+               safe_strcpy_base(do_list_queue + do_list_queue_end, 
+                                entry, do_list_queue, do_list_queue_size);
                do_list_queue_end = new_end;
                DEBUG(4,("added %s to do_list_queue (start=%d, end=%d)\n",
                         entry, (int)do_list_queue_start, (int)do_list_queue_end));
@@ -481,6 +482,11 @@ static void do_list_helper(file_info *f, const char *mask, void *state)
                        pstring mask2;
                        char *p;
 
+                       if (!f->name[0]) {
+                               d_printf("Empty dir name returned. Possible server misconfiguration.\n");
+                               return;
+                       }
+
                        pstrcpy(mask2, mask);
                        p = strrchr_m(mask2,'\\');
                        if (!p) return;
@@ -659,7 +665,7 @@ static int do_get(char *rname, char *lname, BOOL reget)
        GetTimeOfDay(&tp_start);
 
        if (lowercase) {
-               strlower(lname);
+               strlower_m(lname);
        }
 
        fnum = cli_open(cli, rname, O_RDONLY, DENY_NONE);
@@ -834,7 +840,7 @@ static void do_mget(file_info *finfo)
 
        unix_format(finfo->name);
        if (lowercase)
-               strlower(finfo->name);
+               strlower_m(finfo->name);
        
        if (!directory_exist(finfo->name,NULL) && 
            mkdir(finfo->name,0777) != 0) {
@@ -2108,7 +2114,7 @@ static struct
   
   /* Yes, this must be here, see crh's comment above. */
   {"!",NULL,"run a shell command on the local system",{COMPL_NONE,COMPL_NONE}},
-  {"",NULL,NULL,{COMPL_NONE,COMPL_NONE}}
+  {NULL,NULL,NULL,{COMPL_NONE,COMPL_NONE}}
 };
 
 
@@ -2261,8 +2267,14 @@ static char **remote_completion(const char *text, int len)
 {
        pstring dirmask;
        int i;
-       completion_remote_t info = { "", NULL, 1, len, text, len };
+       completion_remote_t info = { "", NULL, 1, 0, NULL, 0 };
 
+       /* can't have non-static intialisation on Sun CC, so do it
+          at run time here */
+       info.samelen = len;
+       info.text = text;
+       info.len = len;
+               
        if (len >= PATH_MAX)
                return(NULL);
 
@@ -2279,9 +2291,9 @@ static char **remote_completion(const char *text, int len)
        if (i > 0) {
                strncpy(info.dirmask, text, i+1);
                info.dirmask[i+1] = 0;
-               snprintf(dirmask, sizeof(dirmask), "%s%*s*", cur_dir, i-1, text);
+               pstr_sprintf(dirmask, "%s%*s*", cur_dir, i-1, text);
        } else
-               snprintf(dirmask, sizeof(dirmask), "%s*", cur_dir);
+               pstr_sprintf(dirmask, "%s*", cur_dir);
 
        if (cli_list(cli, dirmask, aDIR | aSYSTEM | aHIDDEN, completion_remote_filter, &info) < 0)
                goto cleanup;
@@ -2517,6 +2529,8 @@ static struct cli_state *do_connect(const char *server, const char *share)
 
        c->protocol = max_protocol;
        c->use_kerberos = use_kerberos;
+       cli_setup_signing_state(c, cmdline_auth_info.signing_state);
+               
 
        if (!cli_session_request(c, &calling, &called)) {
                char *p;
@@ -2557,6 +2571,9 @@ static struct cli_state *do_connect(const char *server, const char *share)
                if (password[0] || !username[0] || use_kerberos ||
                    !cli_session_setup(c, "", "", 0, "", 0, lp_workgroup())) { 
                        d_printf("session setup failed: %s\n", cli_errstr(c));
+                       if (NT_STATUS_V(cli_nt_error(c)) == 
+                           NT_STATUS_V(NT_STATUS_MORE_PROCESSING_REQUIRED))
+                               d_printf("did you forget to run kinit?\n");
                        cli_shutdown(c);
                        return NULL;
                }
@@ -2741,7 +2758,7 @@ static void remember_query_host(const char *arg,
                { "tar", 'T', POPT_ARG_STRING, NULL, 'T', "Command line tar", "<c|x>IXFqgbNan" },
                { "directory", 'D', POPT_ARG_STRING, NULL, 'D', "Start from directory", "DIR" },
                { "command", 'c', POPT_ARG_STRING, &cmdstr, 'c', "Execute semicolon separated commands" }, 
-               { "send-buffer", 'b', POPT_ARG_INT, NULL, 'b', "Changes the transmit/send buffer", "BYTES" },
+               { "send-buffer", 'b', POPT_ARG_INT, &io_bufsize, 'b', "Changes the transmit/send buffer", "BYTES" },
                { "port", 'p', POPT_ARG_INT, &port, 'p', "Port to connect to", "PORT" },
                POPT_COMMON_SAMBA
                POPT_COMMON_CONNECTION
@@ -2807,17 +2824,30 @@ static void remember_query_host(const char *arg,
                        max_protocol = interpret_protocol(poptGetOptArg(pc), max_protocol);
                        break;
                case 'T':
-                       if (!tar_parseargs(argc, argv, poptGetOptArg(pc), optind)) {
-                               poptPrintUsage(pc, stderr, 0);
-                               exit(1);
+                       /* We must use old option processing for this. Find the
+                        * position of the -T option in the raw argv[]. */
+                       {
+                               int i, optnum;
+                               for (i = 1; i < argc; i++) {
+                                       if (strncmp("-T", argv[i],2)==0)
+                                               break;
+                               }
+                               i++;
+                               if (!(optnum = tar_parseargs(argc, argv, poptGetOptArg(pc), i))) {
+                                       poptPrintUsage(pc, stderr, 0);
+                                       exit(1);
+                               }
+                               /* Now we must eat (optnum - i) options - they have
+                                * been processed by tar_parseargs().
+                                */
+                               optnum -= i;
+                               for (i = 0; i < optnum; i++)
+                                       poptGetOptArg(pc);
                        }
                        break;
                case 'D':
                        fstrcpy(base_directory,poptGetOptArg(pc));
                        break;
-               case 'b':
-                       io_bufsize = MAX(1, atoi(poptGetOptArg(pc)));
-                       break;
                }
        }
 
@@ -2837,7 +2867,7 @@ static void remember_query_host(const char *arg,
                }
        }
 
-       if (poptPeekArg(pc)) { 
+       if (poptPeekArg(pc) && !cmdline_auth_info.got_pass) { 
                cmdline_auth_info.got_pass = True;
                pstrcpy(cmdline_auth_info.password,poptGetArg(pc));  
        }
@@ -2856,6 +2886,7 @@ static void remember_query_host(const char *arg,
 
        pstrcpy(username, cmdline_auth_info.username);
        pstrcpy(password, cmdline_auth_info.password);
+
        use_kerberos = cmdline_auth_info.use_kerberos;
        got_pass = cmdline_auth_info.got_pass;