summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2007-06-20 17:38:42 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:23:28 -0500
commitce02d0dfcbeeeec316578322257d998589090c6f (patch)
tree3855284b3cede5e054a0149b8afef432dfbcb318
parent04c75d9c95c5321d1fe5455671074b0e46f0df77 (diff)
downloadsamba-ce02d0dfcbeeeec316578322257d998589090c6f.tar.gz
samba-ce02d0dfcbeeeec316578322257d998589090c6f.tar.bz2
samba-ce02d0dfcbeeeec316578322257d998589090c6f.zip
r23554: Fix bug #4711 by makeing cli_connect return an NTSTATUS.
Long overdue fix.... Jeremy. (This used to be commit 073fdc5a58139796dbaa7ea9833dca5308f11282)
-rw-r--r--source3/auth/auth_server.c7
-rw-r--r--source3/client/client.c10
-rw-r--r--source3/libsmb/cliconnect.c25
-rw-r--r--source3/libsmb/clidfs.c9
-rw-r--r--source3/libsmb/libsmbclient.c19
-rw-r--r--source3/libsmb/passchange.c10
-rw-r--r--source3/nmbd/nmbd_synclists.c8
-rw-r--r--source3/torture/locktest.c9
-rw-r--r--source3/torture/masktest.c9
-rw-r--r--source3/torture/torture.c11
-rw-r--r--source3/utils/net_rpc.c4
-rw-r--r--source3/utils/net_time.c6
-rw-r--r--source3/web/diagnose.c4
13 files changed, 89 insertions, 42 deletions
diff --git a/source3/auth/auth_server.c b/source3/auth/auth_server.c
index 4351f96eeb..f862ba0f1a 100644
--- a/source3/auth/auth_server.c
+++ b/source3/auth/auth_server.c
@@ -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) {
diff --git a/source3/client/client.c b/source3/client/client.c
index 2df5c67db1..35716ab13c 100644
--- a/source3/client/client.c
+++ b/source3/client/client.c
@@ -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();
diff --git a/source3/libsmb/cliconnect.c b/source3/libsmb/cliconnect.c
index 86834ad081..78386ce503 100644
--- a/source3/libsmb/cliconnect.c
+++ b/source3/libsmb/cliconnect.c
@@ -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) ));
diff --git a/source3/libsmb/clidfs.c b/source3/libsmb/clidfs.c
index 4009b98b41..d5e31b5eb8 100644
--- a/source3/libsmb/clidfs.c
+++ b/source3/libsmb/clidfs.c
@@ -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;
diff --git a/source3/libsmb/libsmbclient.c b/source3/libsmb/libsmbclient.c
index 725916e737..c36bb21ff4 100644
--- a/source3/libsmb/libsmbclient.c
+++ b/source3/libsmb/libsmbclient.c
@@ -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);
diff --git a/source3/libsmb/passchange.c b/source3/libsmb/passchange.c
index 5b4b0896c0..bfa513d002 100644
--- a/source3/libsmb/passchange.c
+++ b/source3/libsmb/passchange.c
@@ -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;
}
diff --git a/source3/nmbd/nmbd_synclists.c b/source3/nmbd/nmbd_synclists.c
index 7fe39676c6..fa1a41a5af 100644
--- a/source3/nmbd/nmbd_synclists.c
+++ b/source3/nmbd/nmbd_synclists.c
@@ -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;
}
diff --git a/source3/torture/locktest.c b/source3/torture/locktest.c
index 7a970488b3..8d3234e367 100644
--- a/source3/torture/locktest.c
+++ b/source3/torture/locktest.c
@@ -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)) {
diff --git a/source3/torture/masktest.c b/source3/torture/masktest.c
index 0d6c0b16f2..e98cf81f33 100644
--- a/source3/torture/masktest.c
+++ b/source3/torture/masktest.c
@@ -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)) {
diff --git a/source3/torture/torture.c b/source3/torture/torture.c
index 39495c6a3e..92599e2765 100644
--- a/source3/torture/torture.c
+++ b/source3/torture/torture.c
@@ -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;
}
diff --git a/source3/utils/net_rpc.c b/source3/utils/net_rpc.c
index e2639fe896..315b56100f 100644
--- a/source3/utils/net_rpc.c
+++ b/source3/utils/net_rpc.c
@@ -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))
diff --git a/source3/utils/net_time.c b/source3/utils/net_time.c
index f6269627da..5e952780d3 100644
--- a/source3/utils/net_time.c
+++ b/source3/utils/net_time.c
@@ -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;
}
diff --git a/source3/web/diagnose.c b/source3/web/diagnose.c
index b53e139ca9..5f05d8ac9e 100644
--- a/source3/web/diagnose.c
+++ b/source3/web/diagnose.c
@@ -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;
}