summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
Diffstat (limited to 'source3')
-rw-r--r--source3/utils/net.c24
-rw-r--r--source3/utils/net_rap.c54
-rw-r--r--source3/utils/net_rpc.c29
-rw-r--r--source3/utils/net_rpc_join.c7
-rw-r--r--source3/utils/net_rpc_shell.c7
5 files changed, 72 insertions, 49 deletions
diff --git a/source3/utils/net.c b/source3/utils/net.c
index 962da0b39e..9c327f162d 100644
--- a/source3/utils/net.c
+++ b/source3/utils/net.c
@@ -465,13 +465,14 @@ BOOL net_find_pdc(struct in_addr *server_ip, fstring server_name, const char *do
return False;
}
-struct cli_state *net_make_ipc_connection( unsigned flags )
+NTSTATUS net_make_ipc_connection(unsigned flags, struct cli_state **pcli)
{
- return net_make_ipc_connection_ex( NULL, NULL, NULL, flags );
+ return net_make_ipc_connection_ex(NULL, NULL, NULL, flags, pcli);
}
-struct cli_state *net_make_ipc_connection_ex( const char *domain, const char *server,
- struct in_addr *ip, unsigned flags)
+NTSTATUS net_make_ipc_connection_ex(const char *domain, const char *server,
+ struct in_addr *ip, unsigned flags,
+ struct cli_state **pcli)
{
char *server_name = NULL;
struct in_addr server_ip;
@@ -481,7 +482,8 @@ struct cli_state *net_make_ipc_connection_ex( const char *domain, const char *se
if ( !server || !ip ) {
if (!net_find_server(domain, flags, &server_ip, &server_name)) {
d_fprintf(stderr, "Unable to find a suitable server\n");
- return NULL;
+ nt_status = NT_STATUS_UNSUCCESSFUL;
+ goto done;
}
} else {
server_name = SMB_STRDUP( server );
@@ -500,13 +502,17 @@ struct cli_state *net_make_ipc_connection_ex( const char *domain, const char *se
saf_store( cli->server_domain, cli->desthost );
SAFE_FREE(server_name);
- if (NT_STATUS_IS_OK(nt_status)) {
- return cli;
- } else {
+ if (!NT_STATUS_IS_OK(nt_status)) {
d_fprintf(stderr, "Connection failed: %s\n",
nt_errstr(nt_status));
- return NULL;
+ cli = NULL;
}
+
+done:
+ if (pcli != NULL) {
+ *pcli = cli;
+ }
+ return nt_status;
}
static int net_user(int argc, const char **argv)
diff --git a/source3/utils/net_rap.c b/source3/utils/net_rap.c
index 56d6deab73..74eda61331 100644
--- a/source3/utils/net_rap.c
+++ b/source3/utils/net_rap.c
@@ -83,7 +83,7 @@ static int rap_file_close(int argc, const char **argv)
return net_rap_file_usage(argc, argv);
}
- if (!(cli = net_make_ipc_connection(0)))
+ if (!NT_STATUS_IS_OK(net_make_ipc_connection(0, &cli)))
return -1;
ret = cli_NetFileClose(cli, atoi(argv[0]));
@@ -98,7 +98,7 @@ static int rap_file_info(int argc, const char **argv)
if (argc == 0)
return net_rap_file_usage(argc, argv);
- if (!(cli = net_make_ipc_connection(0)))
+ if (!NT_STATUS_IS_OK(net_make_ipc_connection(0, &cli)))
return -1;
ret = cli_NetFileGetInfo(cli, atoi(argv[0]), one_file_fn);
@@ -128,7 +128,7 @@ int net_rap_file(int argc, const char **argv)
struct cli_state *cli;
int ret;
- if (!(cli = net_make_ipc_connection(0)))
+ if (!NT_STATUS_IS_OK(net_make_ipc_connection(0, &cli)))
return -1;
/* list open files */
@@ -172,7 +172,7 @@ static int rap_share_delete(int argc, const char **argv)
return net_rap_share_usage(argc, argv);
}
- if (!(cli = net_make_ipc_connection(0)))
+ if (!NT_STATUS_IS_OK(net_make_ipc_connection(0, &cli)))
return -1;
ret = cli_NetShareDelete(cli, argv[0]);
@@ -194,7 +194,7 @@ static int rap_share_add(int argc, const char **argv)
return net_rap_share_usage(argc, argv);
}
- if (!(cli = net_make_ipc_connection(0)))
+ if (!NT_STATUS_IS_OK(net_make_ipc_connection(0, &cli)))
return -1;
sharename = SMB_STRDUP(argv[0]);
@@ -234,7 +234,7 @@ int net_rap_share(int argc, const char **argv)
struct cli_state *cli;
int ret;
- if (!(cli = net_make_ipc_connection(0)))
+ if (!NT_STATUS_IS_OK(net_make_ipc_connection(0, &cli)))
return -1;
if (opt_long_list_entries) {
@@ -320,7 +320,7 @@ static int rap_session_info(int argc, const char **argv)
struct cli_state *cli;
int ret;
- if (!(cli = net_make_ipc_connection(0)))
+ if (!NT_STATUS_IS_OK(net_make_ipc_connection(0, &cli)))
return -1;
if (argc == 0)
@@ -346,7 +346,7 @@ static int rap_session_delete(int argc, const char **argv)
struct cli_state *cli;
int ret;
- if (!(cli = net_make_ipc_connection(0)))
+ if (!NT_STATUS_IS_OK(net_make_ipc_connection(0, &cli)))
return -1;
if (argc == 0)
@@ -370,7 +370,7 @@ int net_rap_session(int argc, const char **argv)
struct cli_state *cli;
int ret;
- if (!(cli = net_make_ipc_connection(0)))
+ if (!NT_STATUS_IS_OK(net_make_ipc_connection(0, &cli)))
return -1;
d_printf("Computer User name "\
@@ -412,7 +412,7 @@ static int net_rap_server_name(int argc, const char *argv[])
struct cli_state *cli;
char *name;
- if (!(cli = net_make_ipc_connection(0)))
+ if (!NT_STATUS_IS_OK(net_make_ipc_connection(0, &cli)))
return -1;
if (!cli_get_server_name(NULL, cli, &name)) {
@@ -444,7 +444,7 @@ int net_rap_server(int argc, const char **argv)
}
}
- if (!(cli = net_make_ipc_connection(0)))
+ if (!NT_STATUS_IS_OK(net_make_ipc_connection(0, &cli)))
return -1;
d_printf("\nEnumerating servers in this domain or workgroup: \n\n"\
@@ -472,7 +472,7 @@ int net_rap_domain(int argc, const char **argv)
struct cli_state *cli;
int ret;
- if (!(cli = net_make_ipc_connection(0)))
+ if (!NT_STATUS_IS_OK(net_make_ipc_connection(0, &cli)))
return -1;
d_printf("\nEnumerating domains:\n\n"\
@@ -569,7 +569,7 @@ static int rap_printq_info(int argc, const char **argv)
if (argc == 0)
return net_rap_printq_usage(argc, argv);
- if (!(cli = net_make_ipc_connection(0)))
+ if (!NT_STATUS_IS_OK(net_make_ipc_connection(0, &cli)))
return -1;
d_printf(PRINTQ_ENUM_DISPLAY, cli->desthost); /* list header */
@@ -586,7 +586,7 @@ static int rap_printq_delete(int argc, const char **argv)
if (argc == 0)
return net_rap_printq_usage(argc, argv);
- if (!(cli = net_make_ipc_connection(0)))
+ if (!NT_STATUS_IS_OK(net_make_ipc_connection(0, &cli)))
return -1;
ret = cli_printjob_del(cli, atoi(argv[0]));
@@ -606,7 +606,7 @@ int net_rap_printq(int argc, const char **argv)
};
if (argc == 0) {
- if (!(cli = net_make_ipc_connection(0)))
+ if (!NT_STATUS_IS_OK(net_make_ipc_connection(0, &cli)))
return -1;
d_printf(PRINTQ_ENUM_DISPLAY, cli->desthost); /* list header */
@@ -652,7 +652,7 @@ static int rap_user_delete(int argc, const char **argv)
return net_rap_user_usage(argc, argv);
}
- if (!(cli = net_make_ipc_connection(0)))
+ if (!NT_STATUS_IS_OK(net_make_ipc_connection(0, &cli)))
return -1;
ret = cli_NetUserDelete(cli, argv[0]);
@@ -671,7 +671,7 @@ static int rap_user_add(int argc, const char **argv)
return net_rap_user_usage(argc, argv);
}
- if (!(cli = net_make_ipc_connection(0)))
+ if (!NT_STATUS_IS_OK(net_make_ipc_connection(0, &cli)))
return -1;
safe_strcpy(userinfo.user_name, argv[0], sizeof(userinfo.user_name)-1);
@@ -700,7 +700,7 @@ static int rap_user_info(int argc, const char **argv)
return net_rap_user_usage(argc, argv);
}
- if (!(cli = net_make_ipc_connection(0)))
+ if (!NT_STATUS_IS_OK(net_make_ipc_connection(0, &cli)))
return -1;
ret = cli_NetUserGetGroups(cli, argv[0], group_member_fn, NULL);
@@ -720,7 +720,7 @@ int net_rap_user(int argc, const char **argv)
if (argc == 0) {
struct cli_state *cli;
- if (!(cli = net_make_ipc_connection(0)))
+ if (!NT_STATUS_IS_OK(net_make_ipc_connection(0, &cli)))
goto done;
if (opt_long_list_entries) {
d_printf("\nUser name Comment"\
@@ -768,7 +768,7 @@ static int rap_group_delete(int argc, const char **argv)
return net_rap_group_usage(argc, argv);
}
- if (!(cli = net_make_ipc_connection(0)))
+ if (!NT_STATUS_IS_OK(net_make_ipc_connection(0, &cli)))
return -1;
ret = cli_NetGroupDelete(cli, argv[0]);
@@ -787,7 +787,7 @@ static int rap_group_add(int argc, const char **argv)
return net_rap_group_usage(argc, argv);
}
- if (!(cli = net_make_ipc_connection(0)))
+ if (!NT_STATUS_IS_OK(net_make_ipc_connection(0, &cli)))
return -1;
/* BB check for length 21 or smaller explicitly ? BB */
@@ -811,7 +811,7 @@ int net_rap_group(int argc, const char **argv)
if (argc == 0) {
struct cli_state *cli;
int ret;
- if (!(cli = net_make_ipc_connection(0)))
+ if (!NT_STATUS_IS_OK(net_make_ipc_connection(0, &cli)))
return -1;
if (opt_long_list_entries) {
d_printf("Group name Comment\n");
@@ -852,7 +852,7 @@ static int rap_groupmember_add(int argc, const char **argv)
return net_rap_groupmember_usage(argc, argv);
}
- if (!(cli = net_make_ipc_connection(0)))
+ if (!NT_STATUS_IS_OK(net_make_ipc_connection(0, &cli)))
return -1;
ret = cli_NetGroupAddUser(cli, argv[0], argv[1]);
@@ -869,7 +869,7 @@ static int rap_groupmember_delete(int argc, const char **argv)
return net_rap_groupmember_usage(argc, argv);
}
- if (!(cli = net_make_ipc_connection(0)))
+ if (!NT_STATUS_IS_OK(net_make_ipc_connection(0, &cli)))
return -1;
ret = cli_NetGroupDelUser(cli, argv[0], argv[1]);
@@ -886,7 +886,7 @@ static int rap_groupmember_list(int argc, const char **argv)
return net_rap_groupmember_usage(argc, argv);
}
- if (!(cli = net_make_ipc_connection(0)))
+ if (!NT_STATUS_IS_OK(net_make_ipc_connection(0, &cli)))
return -1;
ret = cli_NetGroupGetUsers(cli, argv[0], group_member_fn, NULL );
@@ -962,7 +962,7 @@ int net_rap_service(int argc, const char **argv)
if (argc == 0) {
struct cli_state *cli;
int ret;
- if (!(cli = net_make_ipc_connection(0)))
+ if (!NT_STATUS_IS_OK(net_make_ipc_connection(0, &cli)))
return -1;
if (opt_long_list_entries) {
@@ -996,7 +996,7 @@ int net_rap_password(int argc, const char **argv)
if (argc < 3)
return net_rap_password_usage(argc, argv);
- if (!(cli = net_make_ipc_connection(0)))
+ if (!NT_STATUS_IS_OK(net_make_ipc_connection(0, &cli)))
return -1;
/* BB Add check for password lengths? */
diff --git a/source3/utils/net_rpc.c b/source3/utils/net_rpc.c
index 273a4c7dbd..e44d33d874 100644
--- a/source3/utils/net_rpc.c
+++ b/source3/utils/net_rpc.c
@@ -115,7 +115,12 @@ int run_rpc_command(struct cli_state *cli_arg,
/* make use of cli_state handed over as an argument, if possible */
if (!cli_arg) {
- cli = net_make_ipc_connection(conn_flags);
+ nt_status = net_make_ipc_connection(conn_flags, &cli);
+ if (!NT_STATUS_IS_OK(nt_status)) {
+ DEBUG(1, ("failed to make ipc connection: %s\n",
+ nt_errstr(nt_status)));
+ return -1;
+ }
} else {
cli = cli_arg;
}
@@ -5821,8 +5826,10 @@ static int rpc_trustdom_vampire(int argc, const char **argv)
};
/* open \PIPE\lsarpc and open policy handle */
- if (!(cli = net_make_ipc_connection(NET_FLAGS_PDC))) {
- DEBUG(0, ("Couldn't connect to domain controller\n"));
+ nt_status = net_make_ipc_connection(NET_FLAGS_PDC, &cli);
+ if (!NT_STATUS_IS_OK(nt_status)) {
+ DEBUG(0, ("Couldn't connect to domain controller: %s\n",
+ nt_errstr(nt_status)));
talloc_destroy(mem_ctx);
return -1;
};
@@ -5964,8 +5971,10 @@ static int rpc_trustdom_list(int argc, const char **argv)
};
/* open \PIPE\lsarpc and open policy handle */
- if (!(cli = net_make_ipc_connection(NET_FLAGS_PDC))) {
- DEBUG(0, ("Couldn't connect to domain controller\n"));
+ nt_status = net_make_ipc_connection(NET_FLAGS_PDC, &cli);
+ if (!NT_STATUS_IS_OK(nt_status)) {
+ DEBUG(0, ("Couldn't connect to domain controller: %s\n",
+ nt_errstr(nt_status)));
talloc_destroy(mem_ctx);
return -1;
};
@@ -6132,8 +6141,10 @@ static int rpc_trustdom_list(int argc, const char **argv)
d_printf("%s%s", trusting_dom_names[i], padding);
/* connect to remote domain controller */
- remote_cli = net_make_ipc_connection(NET_FLAGS_PDC | NET_FLAGS_ANONYMOUS);
- if (remote_cli) {
+ nt_status = net_make_ipc_connection(
+ NET_FLAGS_PDC | NET_FLAGS_ANONYMOUS,
+ &remote_cli);
+ if (NT_STATUS_IS_OK(nt_status)) {
/* query for domain's sid */
if (run_rpc_command(remote_cli, PI_LSARPC, 0, rpc_query_domain_sid, argc, argv))
d_fprintf(stderr, "couldn't get domain's sid\n");
@@ -6141,7 +6152,9 @@ static int rpc_trustdom_list(int argc, const char **argv)
cli_shutdown(remote_cli);
} else {
- d_fprintf(stderr, "domain controller is not responding\n");
+ d_fprintf(stderr, "domain controller is not "
+ "responding: %s\n",
+ nt_errstr(nt_status));
};
};
diff --git a/source3/utils/net_rpc_join.c b/source3/utils/net_rpc_join.c
index 1097eb9575..571d8016b9 100644
--- a/source3/utils/net_rpc_join.c
+++ b/source3/utils/net_rpc_join.c
@@ -64,7 +64,8 @@ int net_rpc_join_ok(const char *domain, const char *server, struct in_addr *ip )
}
/* Connect to remote machine */
- if (!(cli = net_make_ipc_connection_ex(domain, server, ip, conn_flags))) {
+ ntret = net_make_ipc_connection_ex(domain, server, ip, conn_flags, &cli);
+ if (!NT_STATUS_IS_OK(ntret)) {
return -1;
}
@@ -180,8 +181,10 @@ int net_rpc_join_newstyle(int argc, const char **argv)
/* Make authenticated connection to remote machine */
- if (!(cli = net_make_ipc_connection(NET_FLAGS_PDC)))
+ result = net_make_ipc_connection(NET_FLAGS_PDC, &cli);
+ if (!NT_STATUS_IS_OK(result)) {
return 1;
+ }
if (!(mem_ctx = talloc_init("net_rpc_join_newstyle"))) {
DEBUG(0, ("Could not initialise talloc context\n"));
diff --git a/source3/utils/net_rpc_shell.c b/source3/utils/net_rpc_shell.c
index 474ca098e7..206e18776b 100644
--- a/source3/utils/net_rpc_shell.c
+++ b/source3/utils/net_rpc_shell.c
@@ -218,9 +218,10 @@ int net_rpc_shell(int argc, const char **argv)
return -1;
}
- ctx->cli = net_make_ipc_connection(0);
- if (ctx->cli == NULL) {
- d_fprintf(stderr, "Could not open connection\n");
+ status = net_make_ipc_connection(0, &(ctx->cli));
+ if (!NT_STATUS_IS_OK(status)) {
+ d_fprintf(stderr, "Could not open connection: %s\n",
+ nt_errstr(status));
return -1;
}