r23554: Fix bug #4711 by makeing cli_connect return an NTSTATUS.
authorJeremy Allison <jra@samba.org>
Wed, 20 Jun 2007 17:38:42 +0000 (17:38 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 17:23:28 +0000 (12:23 -0500)
Long overdue fix....
Jeremy.
(This used to be commit 073fdc5a58139796dbaa7ea9833dca5308f11282)

13 files changed:
source3/auth/auth_server.c
source3/client/client.c
source3/libsmb/cliconnect.c
source3/libsmb/clidfs.c
source3/libsmb/libsmbclient.c
source3/libsmb/passchange.c
source3/nmbd/nmbd_synclists.c
source3/torture/locktest.c
source3/torture/masktest.c
source3/torture/torture.c
source3/utils/net_rpc.c
source3/utils/net_time.c
source3/web/diagnose.c

index 4351f96eeb364b28197722dad27f48464905b9cb..f862ba0f1a0fc9c605e8533f1219148a7863824c 100644 (file)
@@ -49,6 +49,8 @@ static struct cli_state *server_cryptkey(TALLOC_CTX *mem_ctx)
        p = pserver;
 
         while(next_token( &p, desthost, LIST_SEP, sizeof(desthost))) {
+               NTSTATUS status;
+
                standard_sub_basic(current_user_info.smb_name, current_user_info.domain,
                                   desthost, sizeof(desthost));
                strupper_m(desthost);
@@ -72,11 +74,14 @@ static struct cli_state *server_cryptkey(TALLOC_CTX *mem_ctx)
                        return NULL;
                }
 
-               if (cli_connect(cli, desthost, &dest_ip)) {
+               status = cli_connect(cli, desthost, &dest_ip);
+               if (NT_STATUS_IS_OK(status)) {
                        DEBUG(3,("connected to password server %s\n",desthost));
                        connected_ok = True;
                        break;
                }
+               DEBUG(10,("server_cryptkey: failed to connect to server %s. Error %s\n",
+                       desthost, nt_errstr(status) ));
        }
 
        if (!connected_ok) {
index 2df5c67db12b1c77d0072f2d67ae2cb540de1084..35716ab13cb4017982ef0db2b932e226ac2beda3 100644 (file)
@@ -3845,6 +3845,7 @@ static int do_message_op(void)
        fstring server_name;
        char name_type_hex[10];
        int msg_port;
+       NTSTATUS status;
 
        make_nmb_name(&calling, calling_name, 0x0);
        make_nmb_name(&called , desthost, name_type);
@@ -3861,12 +3862,17 @@ static int do_message_op(void)
 
        msg_port = port ? port : 139;
 
-       if (!(cli=cli_initialise()) || (cli_set_port(cli, msg_port) != msg_port) ||
-           !cli_connect(cli, server_name, &ip)) {
+       if (!(cli=cli_initialise()) || (cli_set_port(cli, msg_port) != msg_port)) {
                d_printf("Connection to %s failed\n", desthost);
                return 1;
        }
 
+       status = cli_connect(cli, server_name, &ip);
+       if (!NT_STATUS_IS_OK(status)) {
+               d_printf("Connection to %s failed. Error %s\n", desthost, nt_errstr(status));
+               return 1;
+       }
+
        if (!cli_session_request(cli, &calling, &called)) {
                d_printf("session request failed\n");
                cli_cm_shutdown();
index 86834ad081b6fd7508d0ba60c20d442d8a5adf25..78386ce503e9f35590b1a849f1c20b7fdbb74fbb 100644 (file)
@@ -1401,7 +1401,7 @@ BOOL cli_session_request(struct cli_state *cli,
  Open the client sockets.
 ****************************************************************************/
 
-BOOL cli_connect(struct cli_state *cli, const char *host, struct in_addr *ip)
+NTSTATUS cli_connect(struct cli_state *cli, const char *host, struct in_addr *ip)
 {
        int name_type = 0x20;
        char *p;
@@ -1419,7 +1419,7 @@ BOOL cli_connect(struct cli_state *cli, const char *host, struct in_addr *ip)
        
        if (!ip || is_zero_ip(*ip)) {
                 if (!resolve_name(cli->desthost, &cli->dest_ip, name_type)) {
-                        return False;
+                       return NT_STATUS_BAD_NETWORK_NAME;
                 }
                if (ip) *ip = cli->dest_ip;
        } else {
@@ -1444,12 +1444,12 @@ BOOL cli_connect(struct cli_state *cli, const char *host, struct in_addr *ip)
        if (cli->fd == -1) {
                DEBUG(1,("Error connecting to %s (%s)\n",
                         ip?inet_ntoa(*ip):host,strerror(errno)));
-               return False;
+               return map_nt_error_from_unix(errno);
        }
 
        set_socket_options(cli->fd,user_socket_options);
 
-       return True;
+       return NT_STATUS_OK;
 }
 
 /**
@@ -1503,15 +1503,12 @@ again:
 
        DEBUG(3,("Connecting to host=%s\n", dest_host));
        
-       if (!cli_connect(cli, dest_host, &ip)) {
-               DEBUG(1,("cli_start_connection: failed to connect to %s (%s)\n",
-                        nmb_namestr(&called), inet_ntoa(ip)));
+       nt_status = cli_connect(cli, dest_host, &ip);
+       if (!NT_STATUS_IS_OK(nt_status)) {
+               DEBUG(1,("cli_start_connection: failed to connect to %s (%s). Error %s\n",
+                        nmb_namestr(&called), inet_ntoa(ip), nt_errstr(nt_status) ));
                cli_shutdown(cli);
-               if (is_zero_ip(ip)) {
-                       return NT_STATUS_BAD_NETWORK_NAME;
-               } else {
-                       return NT_STATUS_CONNECTION_REFUSED;
-               }
+               return nt_status;
        }
 
        if (retry)
@@ -1656,6 +1653,7 @@ BOOL attempt_netbios_session_request(struct cli_state **ppcli, const char *srcho
        }
 
        if (!cli_session_request(*ppcli, &calling, &called)) {
+               NTSTATUS status;
                struct nmb_name smbservername;
 
                make_nmb_name(&smbservername , "*SMBSERVER", 0x20);
@@ -1685,7 +1683,8 @@ with error %s.\n", desthost, cli_errstr(*ppcli) ));
                        return False;
                }
 
-               if (!cli_connect(*ppcli, desthost, pdest_ip) ||
+               status = cli_connect(*ppcli, desthost, pdest_ip);
+               if (!NT_STATUS_IS_OK(status) ||
                                !cli_session_request(*ppcli, &calling, &smbservername)) {
                        DEBUG(0,("attempt_netbios_session_request: %s rejected the session for \
 name *SMBSERVER with error %s\n", desthost, cli_errstr(*ppcli) ));
index 4009b98b418404bc8920f7b348b658cd02323fb7..d5e31b5eb853343d42802b95381b591b8b914904 100644 (file)
@@ -69,6 +69,7 @@ static struct cli_state *do_connect( const char *server, const char *share,
        pstring servicename;
        char *sharename;
        fstring newserver, newshare;
+       NTSTATUS status;
        
        /* make a copy so we don't modify the global string 'service' */
        pstrcpy(servicename, share);
@@ -94,11 +95,15 @@ static struct cli_state *do_connect( const char *server, const char *share,
                ip = dest_ip;
 
        /* have to open a new connection */
-       if (!(c=cli_initialise()) || (cli_set_port(c, port) != port) ||
-           !cli_connect(c, server_n, &ip)) {
+       if (!(c=cli_initialise()) || (cli_set_port(c, port) != port)) {
                d_printf("Connection to %s failed\n", server_n);
                return NULL;
        }
+       status = cli_connect(c, server_n, &ip);
+       if (!NT_STATUS_IS_OK(status)) {
+               d_printf("Connection to %s failed (Error %s)\n", server_n, nt_errstr(status));
+               return NULL;
+       }
 
        c->protocol = max_protocol;
        c->use_kerberos = use_kerberos;
index 725916e737b9b9a59b0dda562a0a959b75b7ab8b..c36bb21ff40962dca1aaa00129a78451920713cf 100644 (file)
@@ -675,7 +675,8 @@ smbc_server(SMBCCTX *context,
         int port_try_first;
         int port_try_next;
         const char *username_used;
-  
+       NTSTATUS status;
+
        zero_ip(&ip);
        ZERO_STRUCT(c);
 
@@ -795,17 +796,19 @@ smbc_server(SMBCCTX *context,
 
         c->port = port_try_first;
 
-       if (!cli_connect(c, server_n, &ip)) {
+       status = cli_connect(c, server_n, &ip);
+       if (!NT_STATUS_IS_OK(status)) {
 
                 /* First connection attempt failed.  Try alternate port. */
                 c->port = port_try_next;
 
-                if (!cli_connect(c, server_n, &ip)) {
-                        cli_shutdown(c);
-                        errno = ETIMEDOUT;
-                        return NULL;
-                }
-       }
+                status = cli_connect(c, server_n, &ip);
+               if (!NT_STATUS_IS_OK(status)) {
+                       cli_shutdown(c);
+                       errno = ETIMEDOUT;
+                       return NULL;
+               }
+       }
 
        if (!cli_session_request(c, &calling, &called)) {
                cli_shutdown(c);
index 5b4b0896c0f2e35f85beb8d3e45b6dcf74eb1938..bfa513d002f23862e6b28d5c1cd800b538c86b48 100644 (file)
@@ -39,7 +39,7 @@ NTSTATUS remote_password_change(const char *remote_machine, const char *user_nam
        *err_str = '\0';
 
        if(!resolve_name( remote_machine, &ip, 0x20)) {
-               slprintf(err_str, err_str_len-1, "unable to find an IP address for machine %s.\n",
+               slprintf(err_str, err_str_len-1, "Unable to find an IP address for machine %s.\n",
                        remote_machine );
                return NT_STATUS_UNSUCCESSFUL;
        }
@@ -49,10 +49,10 @@ NTSTATUS remote_password_change(const char *remote_machine, const char *user_nam
                return NT_STATUS_NO_MEMORY;
        }
 
-       if (!cli_connect(cli, remote_machine, &ip)) {
-               slprintf(err_str, err_str_len-1, "unable to connect to SMB server on machine %s. Error was : %s.\n",
-                       remote_machine, cli_errstr(cli) );
-               result = cli_nt_error(cli);
+       result = cli_connect(cli, remote_machine, &ip);
+       if (!NT_STATUS_IS_OK(result)) {
+               slprintf(err_str, err_str_len-1, "Unable to connect to SMB server on machine %s. Error was : %s.\n",
+                       remote_machine, nt_errstr(result) );
                cli_shutdown(cli);
                return result;
        }
index 7fe39676c6f1960456b9132219a3325361abc387..fa1a41a5af70e983e7ac47d4070e76d2dbdfc8e8 100644 (file)
@@ -71,6 +71,7 @@ static void sync_child(char *name, int nm_type,
        struct cli_state *cli;
        uint32 local_type = local ? SV_TYPE_LOCAL_LIST_ONLY : 0;
        struct nmb_name called, calling;
+       NTSTATUS status;
 
        /* W2K DMB's return empty browse lists on port 445. Use 139.
         * Patch from Andy Levine andyl@epicrealm.com.
@@ -81,7 +82,12 @@ static void sync_child(char *name, int nm_type,
                return;
        }
 
-       if (!cli_set_port(cli, 139) || !cli_connect(cli, name, &ip)) {
+       if (!cli_set_port(cli, 139)) {
+               return;
+       }
+
+       status = cli_connect(cli, name, &ip);
+       if (!NT_STATUS_IS_OK(status)) {
                return;
        }
 
index 7a970488b37fbaaebec931f4ecd63f8be27a7064..8d3234e367fd4bd05ba9e99870dcf1c06bf68b2f 100644 (file)
@@ -165,6 +165,7 @@ static struct cli_state *connect_one(char *share, int snum)
        struct in_addr ip;
        fstring myname;
        static int count;
+       NTSTATUS status;
 
        fstrcpy(server,share+2);
        share = strchr_m(server,'\\');
@@ -185,11 +186,17 @@ static struct cli_state *connect_one(char *share, int snum)
         zero_ip(&ip);
 
        /* have to open a new connection */
-       if (!(c=cli_initialise()) || !cli_connect(c, server_n, &ip)) {
+       if (!(c=cli_initialise())) {
                DEBUG(0,("Connection to %s failed\n", server_n));
                return NULL;
        }
 
+       status = cli_connect(c, server_n, &ip);
+       if (!NT_STATUS_IS_OK(status)) {
+               DEBUG(0,("Connection to %s failed. Error %s\n", server_n, nt_errstr(status) ));
+               return NULL;
+       }
+
        c->use_kerberos = use_kerberos;
 
        if (!cli_session_request(c, &calling, &called)) {
index 0d6c0b16f28e30c4ab2c1ab0315b1ec8bf3aae3f..e98cf81f33329c0851eb1322516ce11d4ead416b 100644 (file)
@@ -170,6 +170,7 @@ static struct cli_state *connect_one(char *share)
        char *server_n;
        char *server;
        struct in_addr ip;
+       NTSTATUS status;
 
        server = share+2;
        share = strchr_m(server,'\\');
@@ -188,11 +189,17 @@ static struct cli_state *connect_one(char *share)
         zero_ip(&ip);
 
        /* have to open a new connection */
-       if (!(c=cli_initialise()) || !cli_connect(c, server_n, &ip)) {
+       if (!(c=cli_initialise())) {
                DEBUG(0,("Connection to %s failed\n", server_n));
                return NULL;
        }
 
+       status = cli_connect(c, server_n, &ip);
+       if (!NT_STATUS_IS_OK(status)) {
+               DEBUG(0,("Connection to %s failed. Error %s\n", server_n, nt_errstr(status) ));
+               return NULL;
+       }
+
        c->protocol = max_protocol;
 
        if (!cli_session_request(c, &calling, &called)) {
index 39495c6a3e7b2c3ccc23a9a24287b8d2d019ba5c..92599e276528fd2073f8c061fcb324ba578899ed 100644 (file)
@@ -102,6 +102,7 @@ static struct cli_state *open_nbt_connection(void)
        struct nmb_name called, calling;
        struct in_addr ip;
        struct cli_state *c;
+       NTSTATUS status;
 
        make_nmb_name(&calling, myname, 0x0);
        make_nmb_name(&called , host, 0x20);
@@ -115,8 +116,9 @@ static struct cli_state *open_nbt_connection(void)
 
        c->port = port_to_use;
 
-       if (!cli_connect(c, host, &ip)) {
-               printf("Failed to connect with %s\n", host);
+       status = cli_connect(c, host, &ip);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("Failed to connect with %s. Error %s\n", host, nt_errstr(status) );
                return NULL;
        }
 
@@ -131,8 +133,9 @@ static struct cli_state *open_nbt_connection(void)
                 * Well, that failed, try *SMBSERVER ... 
                 * However, we must reconnect as well ...
                 */
-               if (!cli_connect(c, host, &ip)) {
-                       printf("Failed to connect with %s\n", host);
+               status = cli_connect(c, host, &ip);
+               if (!NT_STATUS_IS_OK(status)) {
+                       printf("Failed to connect with %s. Error %s\n", host, nt_errstr(status) );
                        return NULL;
                }
 
index e2639fe896f073feb1f74934f4219dc748017ed0..315b56100f2610d7b124bf9cddaeeba70067218d 100644 (file)
@@ -6206,6 +6206,7 @@ BOOL net_rpc_check(unsigned flags)
        BOOL ret = False;
        struct in_addr server_ip;
        char *server_name = NULL;
+       NTSTATUS status;
 
        /* flags (i.e. server type) may depend on command */
        if (!net_find_server(NULL, flags, &server_ip, &server_name))
@@ -6215,7 +6216,8 @@ BOOL net_rpc_check(unsigned flags)
                return False;
        }
 
-       if (!cli_connect(cli, server_name, &server_ip))
+       status = cli_connect(cli, server_name, &server_ip);
+       if (!NT_STATUS_IS_OK(status))
                goto done;
        if (!attempt_netbios_session_request(&cli, global_myname(), 
                                             server_name, &server_ip))
index f6269627dab44bc2bd24769a4de04f0698fd8467..5e952780d326387264e424771d22d8912061695e 100644 (file)
@@ -29,14 +29,16 @@ static time_t cli_servertime(const char *host, struct in_addr *ip, int *zone)
        struct nmb_name calling, called;
        time_t ret = 0;
        struct cli_state *cli = NULL;
+       NTSTATUS status;
 
        cli = cli_initialise();
        if (!cli) {
                goto done;
        }
 
-       if (!cli_connect(cli, host, ip)) {
-               fprintf(stderr,"Can't contact server\n");
+       status = cli_connect(cli, host, ip);
+       if (!NT_STATUS_IS_OK(status)) {
+               fprintf(stderr,"Can't contact server %s. Error %s\n", host, nt_errstr(status));
                goto done;
        }
 
index b53e139ca94496ed420b884f8b78bebe977ad181..5f05d8ac9e92892b3a62abbb3bba1f6aa7414ef9 100644 (file)
@@ -60,12 +60,14 @@ BOOL nmbd_running(void)
    then closing it */
 BOOL smbd_running(void)
 {
+       NTSTATUS status;
        struct cli_state *cli;
 
        if ((cli = cli_initialise()) == NULL)
                return False;
 
-       if (!cli_connect(cli, global_myname(), &loopback_ip)) {
+       status = cli_connect(cli, global_myname(), &loopback_ip);
+       if (!NT_STATUS_IS_OK(status)) {
                cli_shutdown(cli);
                return False;
        }