Remove the static "struct client_connection" mess which is part of
[jra/samba/.git] / source3 / client / client.c
index c40c04e9c676b35051186cb727f5d08acc0d8e99..6491f39ed0d1e3a243986720e852d9f297e8df27 100644 (file)
@@ -45,7 +45,7 @@ const char *cmd_ptr = NULL;
 static int io_bufsize = 524288;
 
 static int name_type = 0x20;
-extern int max_protocol;
+static int max_protocol = PROTOCOL_NT1;
 
 static int process_tok(char *tok);
 static int cmd_help(void);
@@ -747,11 +747,11 @@ static void do_list_helper(const char *mntpoint, file_info *f, const char *mask,
                                return;
                        }
                        p = strrchr_m(mask2,CLI_DIRSEP_CHAR);
-                       if (!p) {
-                               TALLOC_FREE(dir);
-                               return;
+                       if (p) {
+                               p[1] = 0;
+                       } else {
+                               mask2[0] = '\0';
                        }
-                       p[1] = 0;
                        mask2 = talloc_asprintf_append(mask2,
                                        "%s%s*",
                                        f->name,
@@ -1419,7 +1419,7 @@ static bool do_altname(const char *name)
 
 static int cmd_quit(void)
 {
-       cli_cm_shutdown();
+       cli_shutdown(cli);
        exit(0);
        /* NOTREACHED */
        return 0;
@@ -1714,7 +1714,7 @@ static int do_put(const char *rname, const char *lname, bool reput)
        }
 
        if (f == x_stdin) {
-               cli_cm_shutdown();
+               cli_shutdown(cli);
                exit(0);
        }
 
@@ -1784,13 +1784,13 @@ static struct file_list {
  Free a file_list structure.
 ****************************************************************************/
 
-static void free_file_list (struct file_list *list_head)
+static void free_file_list (struct file_list *l_head)
 {
        struct file_list *list, *next;
 
-       for (list = list_head; list; list = next) {
+       for (list = l_head; list; list = next) {
                next = list->next;
-               DLIST_REMOVE(list_head, list);
+               DLIST_REMOVE(l_head, list);
                SAFE_FREE(list->file_path);
                SAFE_FREE(list);
        }
@@ -3815,7 +3815,7 @@ static int cmd_logon(void)
 
 static int cmd_list_connect(void)
 {
-       cli_cm_display();
+       cli_cm_display(cli);
        return 0;
 }
 
@@ -4051,7 +4051,8 @@ static int process_command_string(const char *cmd_in)
        if (!cli) {
                cli = cli_cm_open(talloc_tos(), NULL,
                                have_ip ? dest_ss_str : desthost,
-                               service, true, smb_encrypt);
+                               service, true, smb_encrypt,
+                               max_protocol, port, name_type);
                if (!cli) {
                        return 1;
                }
@@ -4516,7 +4517,8 @@ static int process(const char *base_directory)
 
        cli = cli_cm_open(talloc_tos(), NULL,
                        have_ip ? dest_ss_str : desthost,
-                       service, true, smb_encrypt);
+                       service, true, smb_encrypt,
+                       max_protocol, port, name_type);
        if (!cli) {
                return 1;
        }
@@ -4524,7 +4526,7 @@ static int process(const char *base_directory)
        if (base_directory && *base_directory) {
                rc = do_cd(base_directory);
                if (rc) {
-                       cli_cm_shutdown();
+                       cli_shutdown(cli);
                        return rc;
                }
        }
@@ -4535,7 +4537,7 @@ static int process(const char *base_directory)
                process_stdin();
        }
 
-       cli_cm_shutdown();
+       cli_shutdown(cli);
        return rc;
 }
 
@@ -4548,7 +4550,8 @@ static int do_host_query(const char *query_host)
        struct sockaddr_storage ss;
 
        cli = cli_cm_open(talloc_tos(), NULL,
-                       query_host, "IPC$", true, smb_encrypt);
+                       query_host, "IPC$", true, smb_encrypt,
+                       max_protocol, port, name_type);
        if (!cli)
                return 1;
 
@@ -4565,10 +4568,10 @@ static int do_host_query(const char *query_host)
                /* Workgroups simply don't make sense over anything
                   else but port 139... */
 
-               cli_cm_shutdown();
-               cli_cm_set_port( 139 );
+               cli_shutdown(cli);
                cli = cli_cm_open(talloc_tos(), NULL,
-                               query_host, "IPC$", true, smb_encrypt);
+                               query_host, "IPC$", true, smb_encrypt,
+                               max_protocol, 139, name_type);
        }
 
        if (cli == NULL) {
@@ -4578,7 +4581,7 @@ static int do_host_query(const char *query_host)
 
        list_servers(lp_workgroup());
 
-       cli_cm_shutdown();
+       cli_shutdown(cli);
 
        return(0);
 }
@@ -4595,7 +4598,8 @@ static int do_tar_op(const char *base_directory)
        if (!cli) {
                cli = cli_cm_open(talloc_tos(), NULL,
                        have_ip ? dest_ss_str : desthost,
-                       service, true, smb_encrypt);
+                       service, true, smb_encrypt,
+                       max_protocol, port, name_type);
                if (!cli)
                        return 1;
        }
@@ -4605,14 +4609,14 @@ static int do_tar_op(const char *base_directory)
        if (base_directory && *base_directory)  {
                ret = do_cd(base_directory);
                if (ret) {
-                       cli_cm_shutdown();
+                       cli_shutdown(cli);
                        return ret;
                }
        }
 
        ret=process_tar();
 
-       cli_cm_shutdown();
+       cli_shutdown(cli);
 
        return(ret);
 }
@@ -4645,10 +4649,11 @@ static int do_message_op(struct user_auth_info *auth_info)
 
        msg_port = port ? port : 139;
 
-       if (!(cli=cli_initialise()) || (cli_set_port(cli, msg_port) != msg_port)) {
+       if (!(cli=cli_initialise())) {
                d_printf("Connection to %s failed\n", desthost);
                return 1;
        }
+       cli_set_port(cli, msg_port);
 
        status = cli_connect(cli, server_name, &ss);
        if (!NT_STATUS_IS_OK(status)) {
@@ -4658,12 +4663,12 @@ static int do_message_op(struct user_auth_info *auth_info)
 
        if (!cli_session_request(cli, &calling, &called)) {
                d_printf("session request failed\n");
-               cli_cm_shutdown();
+               cli_shutdown(cli);
                return 1;
        }
 
        send_message(get_cmdline_auth_info_username(auth_info));
-       cli_cm_shutdown();
+       cli_shutdown(cli);
 
        return 0;
 }
@@ -4786,13 +4791,12 @@ static int do_message_op(struct user_auth_info *auth_info)
                         * to port 139 instead of port 445. srl,crh
                         */
                        name_type = 0x03;
-                       cli_cm_set_dest_name_type( name_type );
                        desthost = talloc_strdup(frame,poptGetOptArg(pc));
                        if (!desthost) {
                                exit(ENOMEM);
                        }
                        if( !port )
-                               cli_cm_set_port( 139 );
+                               port = 139;
                        message = true;
                        break;
                case 'I':
@@ -4888,11 +4892,6 @@ static int do_message_op(struct user_auth_info *auth_info)
                                               poptGetArg(pc));
        }
 
-       /* check for the -P option */
-
-       if ( port != 0 )
-               cli_cm_set_port( port );
-
        /*
         * Don't load debug level from smb.conf. It should be
         * set by cmdline arg or remain default (0)
@@ -4975,7 +4974,7 @@ static int do_message_op(struct user_auth_info *auth_info)
 
        cli_cm_set_credentials(auth_info);
 
-       DEBUG(3,("Client started (version %s).\n", SAMBA_VERSION_STRING));
+       DEBUG(3,("Client started (version %s).\n", samba_version_string()));
 
        if (tar_type) {
                if (cmdstr)
@@ -4999,7 +4998,6 @@ static int do_message_op(struct user_auth_info *auth_info)
                        *p = 0;
                        p++;
                        sscanf(p, "%x", &name_type);
-                       cli_cm_set_dest_name_type( name_type );
                }
 
                return do_host_query(qhost);