r5917: First step in using the new cli_credentials structure. This patch
[bbaumbach/samba-autobuild/.git] / source4 / client / client.c
index 5413beb3ba37adf4ff3604cb09823446860bd876..fd5be736079f2f222f3ac669a69cd5a154604a79 100644 (file)
@@ -45,9 +45,6 @@ pstring cur_dir = "\\";
 static pstring cd_path = "";
 static pstring service;
 static pstring desthost;
-static pstring username;
-static pstring domain;
-static pstring password;
 static char *cmdstr = NULL;
 
 static int io_bufsize = 64512;
@@ -103,7 +100,7 @@ static double dir_total;
 #define USENMB
 
 /* some forward declarations */
-static struct smbcli_state *do_connect(const char *server, const char *share);
+static struct smbcli_state *do_connect(const char *server, const char *share, struct cli_credentials *cred);
 
 
 /*******************************************************************
@@ -202,7 +199,7 @@ static void send_message(void)
        int total_len = 0;
        int grp_id;
 
-       if (!smbcli_message_start(cli->tree, desthost, username, &grp_id)) {
+       if (!smbcli_message_start(cli->tree, desthost, cli_credentials_get_username(cmdline_credentials), &grp_id)) {
                d_printf("message start: %s\n", smbcli_errstr(cli->tree));
                return;
        }
@@ -216,7 +213,7 @@ static void send_message(void)
                int l=0;
                int c;
 
-               ZERO_ARRAY(msg);
+               ZERO_STRUCT(msg);
 
                for (l=0;l<maxlen && (c=fgetc(stdin))!=EOF;l++) {
                        if (c == '\n')
@@ -929,7 +926,7 @@ static void do_mget(struct clilist_file_info *finfo)
                strlower(discard_const_p(char, finfo->name));
        }
        
-       if (!directory_exist(finfo->name,NULL) && 
+       if (!directory_exist(finfo->name) && 
            mkdir(finfo->name,0777) != 0) {
                d_printf("failed to create directory %s\n",finfo->name);
                pstrcpy(cur_dir,saved_curdir);
@@ -1301,15 +1298,11 @@ static int cmd_put(const char **cmd_ptr)
        
        dos_clean_name(rname);
 
-       {
-               struct stat st;
-               /* allow '-' to represent stdin
-                  jdblair, 24.jun.98 */
-               if (!file_exist(lname,&st) &&
-                   (strcmp(lname,"-"))) {
-                       d_printf("%s does not exist\n",lname);
-                       return 1;
-               }
+       /* allow '-' to represent stdin
+          jdblair, 24.jun.98 */
+       if (!file_exist(lname) && (strcmp(lname,"-"))) {
+               d_printf("%s does not exist\n",lname);
+               return 1;
        }
 
        return do_put(rname, lname, False);
@@ -2479,7 +2472,6 @@ static int cmd_reput(const char **cmd_ptr)
        pstring remote_name;
        fstring buf;
        char *p = buf;
-       struct stat st;
        
        pstrcpy(remote_name, cur_dir);
        pstrcat(remote_name, "\\");
@@ -2490,7 +2482,7 @@ static int cmd_reput(const char **cmd_ptr)
        }
        pstrcpy(local_name, p);
   
-       if (!file_exist(local_name, &st)) {
+       if (!file_exist(local_name)) {
                d_printf("%s does not exist\n", local_name);
                return 1;
        }
@@ -2563,8 +2555,10 @@ static BOOL browse_host(const char *query_host)
        status = dcerpc_pipe_connect(&p, binding, 
                                     DCERPC_SRVSVC_UUID, 
                                     DCERPC_SRVSVC_VERSION,
-                                    domain, 
-                                    username, password);
+                                    lp_netbios_name(),
+                                    cli_credentials_get_domain(cmdline_credentials), 
+                                    cli_credentials_get_username(cmdline_credentials), 
+                                        cli_credentials_get_password(cmdline_credentials));
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("Failed to connect to %s - %s\n", 
                         binding, nt_errstr(status));
@@ -2757,7 +2751,7 @@ static int process_command_string(char *cmd)
        /* establish the connection if not already */
        
        if (!cli) {
-               cli = do_connect(desthost, service);
+               cli = do_connect(desthost, service, cmdline_credentials);
                if (!cli)
                        return 0;
        }
@@ -3043,7 +3037,7 @@ static void process_stdin(void)
 /***************************************************** 
 return a connection to a server
 *******************************************************/
-static struct smbcli_state *do_connect(const char *server, const char *share)
+static struct smbcli_state *do_connect(const char *server, const char *share, struct cli_credentials *cred)
 {
        struct smbcli_state *c;
        NTSTATUS status;
@@ -3054,7 +3048,9 @@ static struct smbcli_state *do_connect(const char *server, const char *share)
        }
        
        status = smbcli_full_connection(NULL, &c, lp_netbios_name(), server,
-                                       share, NULL, username, domain, password);
+                                       share, NULL, cli_credentials_get_username(cred), 
+                                                                cli_credentials_get_domain(cred), 
+                                                                cli_credentials_get_password(cred));
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("Connection to \\\\%s\\%s failed - %s\n", 
                         server, share, nt_errstr(status));
@@ -3072,7 +3068,7 @@ static int process(char *base_directory)
 {
        int rc = 0;
 
-       cli = do_connect(desthost, service);
+       cli = do_connect(desthost, service, cmdline_credentials);
        if (!cli) {
                return 1;
        }
@@ -3265,7 +3261,7 @@ static void remember_query_host(const char *arg,
        }
 
        if (poptPeekArg(pc)) { 
-               cmdline_set_userpassword(poptGetArg(pc));
+               cli_credentials_set_password(cmdline_credentials, poptGetArg(pc), CRED_SPECIFIED);
        }
 
        /*init_names(); */
@@ -3277,10 +3273,6 @@ static void remember_query_host(const char *arg,
 
        poptFreeContext(pc);
 
-       pstrcpy(username, cmdline_get_username());
-       pstrcpy(domain, cmdline_get_userdomain());
-       pstrcpy(password, cmdline_get_userpassword());
-
        DEBUG( 3, ( "Client started (version %s).\n", SAMBA_VERSION_STRING ) );
 
        talloc_free(mem_ctx);