Index: auth/auth_server.c =================================================================== --- auth/auth_server.c (revision 23553) +++ auth/auth_server.c (working copy) @@ -49,6 +49,8 @@ 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 @@ 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: libsmb/clidfs.c =================================================================== --- libsmb/clidfs.c (revision 23553) +++ libsmb/clidfs.c (working copy) @@ -69,6 +69,7 @@ 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 @@ 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: libsmb/libsmbclient.c =================================================================== --- libsmb/libsmbclient.c (revision 23553) +++ libsmb/libsmbclient.c (working copy) @@ -675,7 +675,8 @@ int port_try_first; int port_try_next; const char *username_used; - + NTSTATUS status; + zero_ip(&ip); ZERO_STRUCT(c); @@ -795,17 +796,19 @@ 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: libsmb/passchange.c =================================================================== --- libsmb/passchange.c (revision 23553) +++ libsmb/passchange.c (working copy) @@ -39,7 +39,7 @@ *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 @@ 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: libsmb/cliconnect.c =================================================================== --- libsmb/cliconnect.c (revision 23553) +++ libsmb/cliconnect.c (working copy) @@ -1402,7 +1402,7 @@ 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; @@ -1420,7 +1420,7 @@ 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 { @@ -1445,12 +1445,12 @@ 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; } /** @@ -1504,15 +1504,12 @@ 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) @@ -1657,6 +1654,7 @@ } if (!cli_session_request(*ppcli, &calling, &called)) { + NTSTATUS status; struct nmb_name smbservername; make_nmb_name(&smbservername , "*SMBSERVER", 0x20); @@ -1686,7 +1684,8 @@ 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: web/diagnose.c =================================================================== --- web/diagnose.c (revision 23553) +++ web/diagnose.c (working copy) @@ -60,12 +60,14 @@ 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; } Index: nmbd/nmbd_synclists.c =================================================================== --- nmbd/nmbd_synclists.c (revision 23553) +++ nmbd/nmbd_synclists.c (working copy) @@ -71,6 +71,7 @@ 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,10 +82,15 @@ 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; + } + make_nmb_name(&calling, local_machine, 0x0); make_nmb_name(&called , name, nm_type); Index: utils/net_time.c =================================================================== --- utils/net_time.c (revision 23553) +++ utils/net_time.c (working copy) @@ -29,14 +29,16 @@ 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: utils/net_rpc.c =================================================================== --- utils/net_rpc.c (revision 23553) +++ utils/net_rpc.c (working copy) @@ -6314,6 +6314,7 @@ 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)) @@ -6323,7 +6324,8 @@ 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: torture/torture.c =================================================================== --- torture/torture.c (revision 23553) +++ torture/torture.c (working copy) @@ -102,6 +102,7 @@ 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 @@ 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 @@ * 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: torture/locktest.c =================================================================== --- torture/locktest.c (revision 23553) +++ torture/locktest.c (working copy) @@ -165,6 +165,7 @@ struct in_addr ip; fstring myname; static int count; + NTSTATUS status; fstrcpy(server,share+2); share = strchr_m(server,'\\'); @@ -185,11 +186,17 @@ 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: torture/masktest.c =================================================================== --- torture/masktest.c (revision 23553) +++ torture/masktest.c (working copy) @@ -170,6 +170,7 @@ char *server_n; char *server; struct in_addr ip; + NTSTATUS status; server = share+2; share = strchr_m(server,'\\'); @@ -188,11 +189,17 @@ 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: client/client.c =================================================================== --- client/client.c (revision 23553) +++ client/client.c (working copy) @@ -3796,6 +3796,7 @@ 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); @@ -3812,12 +3813,17 @@ 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();