summaryrefslogtreecommitdiff
path: root/source3/rpcclient
diff options
context:
space:
mode:
authorGerald Carter <jerry@samba.org>2001-03-14 20:22:57 +0000
committerGerald Carter <jerry@samba.org>2001-03-14 20:22:57 +0000
commitfb3d8452e5250973eae682dd4a13bf530ccfc56a (patch)
tree1efd72d8a26b7485e8df6cf9bc93cb617fa50f6c /source3/rpcclient
parent762c6e3f84141a1c7ef697f1b0a3339d655c86ad (diff)
downloadsamba-fb3d8452e5250973eae682dd4a13bf530ccfc56a.tar.gz
samba-fb3d8452e5250973eae682dd4a13bf530ccfc56a.tar.bz2
samba-fb3d8452e5250973eae682dd4a13bf530ccfc56a.zip
set of changes in the beginning of bringing rpcclient changes
back to working order. The main change is that the cli_*() RPC functions from libsmb/*.c now should accept a struct cli_state*. The reason for this is that rpcclient should establish the connection to the server at startup so that it is not necessary to keep the clear test or password hash in memory for each command. enumports and enumprinters now works as well. lsa* functions have been tested. SAMR calls may or may not work (one of the core dumps I know), but it compiles :-) jerry (This used to be commit d98ac8852ae6b39b6fcff92c346ba56d9e63c518)
Diffstat (limited to 'source3/rpcclient')
-rw-r--r--source3/rpcclient/cmd_lsarpc.c104
-rw-r--r--source3/rpcclient/cmd_samr.c166
-rw-r--r--source3/rpcclient/cmd_spoolss.c69
-rw-r--r--source3/rpcclient/rpcclient.c224
4 files changed, 294 insertions, 269 deletions
diff --git a/source3/rpcclient/cmd_lsarpc.c b/source3/rpcclient/cmd_lsarpc.c
index 694dd4d81a..3ae0b1e11d 100644
--- a/source3/rpcclient/cmd_lsarpc.c
+++ b/source3/rpcclient/cmd_lsarpc.c
@@ -26,13 +26,10 @@ extern int DEBUGLEVEL;
extern pstring server;
/* Look up domain related information on a remote host */
-
-static uint32 cmd_lsa_query_info_policy(int argc, char **argv)
+static uint32 cmd_lsa_query_info_policy(struct cli_state *cli, int argc, char **argv)
{
- struct cli_state cli;
POLICY_HND pol;
uint32 result = NT_STATUS_UNSUCCESSFUL;
- struct ntuser_creds creds;
BOOL got_policy_hnd = False;
DOM_SID dom_sid;
fstring sid_str, domain_name;
@@ -47,16 +44,13 @@ static uint32 cmd_lsa_query_info_policy(int argc, char **argv)
info_class = atoi(argv[1]);
}
- /* Open a lsa handle */
-
- ZERO_STRUCT(cli);
- init_rpcclient_creds(&creds);
-
- if (cli_lsa_initialise(&cli, server, &creds) == NULL) {
- goto done;
+ /* Initialise RPC connection */
+ if (!cli_nt_session_open (cli, PIPE_LSARPC)) {
+ fprintf (stderr, "Could not initialize samr pipe!\n");
+ return NT_STATUS_UNSUCCESSFUL;
}
- if ((result = cli_lsa_open_policy(&cli, True,
+ if ((result = cli_lsa_open_policy(cli, True,
SEC_RIGHTS_MAXIMUM_ALLOWED,
&pol)) != NT_STATUS_NOPROBLEMO) {
goto done;
@@ -66,7 +60,7 @@ static uint32 cmd_lsa_query_info_policy(int argc, char **argv)
/* Lookup info policy */
- if ((result = cli_lsa_query_info_policy(&cli, &pol, info_class,
+ if ((result = cli_lsa_query_info_policy(cli, &pol, info_class,
domain_name, &dom_sid))
!= NT_STATUS_NOPROBLEMO) {
goto done;
@@ -76,23 +70,21 @@ static uint32 cmd_lsa_query_info_policy(int argc, char **argv)
printf("domain %s has sid %s\n", domain_name, sid_str);
- done:
+done:
if (got_policy_hnd) {
- cli_lsa_close(&cli, &pol);
+ cli_lsa_close(cli, &pol);
}
- cli_lsa_shutdown(&cli);
+ cli_nt_session_close(cli);
return result;
}
/* Resolve a list of names to a list of sids */
-static uint32 cmd_lsa_lookup_names(int argc, char **argv)
+static uint32 cmd_lsa_lookup_names(struct cli_state *cli, int argc, char **argv)
{
- struct cli_state cli;
- struct ntuser_creds creds;
POLICY_HND pol;
uint32 result = NT_STATUS_UNSUCCESSFUL;
BOOL got_policy_hnd = False;
@@ -105,16 +97,14 @@ static uint32 cmd_lsa_lookup_names(int argc, char **argv)
return 0;
}
- /* Open a lsa handle */
-
- ZERO_STRUCT(cli);
- init_rpcclient_creds(&creds);
-
- if (cli_lsa_initialise(&cli, server, &creds) == NULL) {
- goto done;
+ /* Initialise RPC connection */
+ if (!cli_nt_session_open (cli, PIPE_LSARPC)) {
+ fprintf (stderr, "Could not initialize samr pipe!\n");
+ return NT_STATUS_UNSUCCESSFUL;
}
- if ((result = cli_lsa_open_policy(&cli, True,
+
+ if ((result = cli_lsa_open_policy(cli, True,
SEC_RIGHTS_MAXIMUM_ALLOWED,
&pol)) != NT_STATUS_NOPROBLEMO) {
goto done;
@@ -125,7 +115,7 @@ static uint32 cmd_lsa_lookup_names(int argc, char **argv)
/* Lookup the names */
if ((result = cli_lsa_lookup_names(
- &cli, &pol, argc - 1, &argv[1], &sids, &types, &num_names) !=
+ cli, &pol, argc - 1, &argv[1], &sids, &types, &num_names) !=
NT_STATUS_NOPROBLEMO)) {
goto done;
}
@@ -146,22 +136,20 @@ static uint32 cmd_lsa_lookup_names(int argc, char **argv)
done:
if (got_policy_hnd) {
- cli_lsa_close(&cli, &pol);
+ cli_lsa_close(cli, &pol);
}
- cli_lsa_shutdown(&cli);
+ cli_nt_session_close(cli);
return result;
}
/* Resolve a list of SIDs to a list of names */
-static uint32 cmd_lsa_lookup_sids(int argc, char **argv)
+static uint32 cmd_lsa_lookup_sids(struct cli_state *cli, int argc, char **argv)
{
- struct cli_state cli;
POLICY_HND pol;
uint32 result = NT_STATUS_UNSUCCESSFUL;
- struct ntuser_creds creds;
BOOL got_policy_hnd = False;
DOM_SID *sids;
char **names;
@@ -173,16 +161,13 @@ static uint32 cmd_lsa_lookup_sids(int argc, char **argv)
return 0;
}
- /* Open a lsa handle */
-
- ZERO_STRUCT(cli);
- init_rpcclient_creds(&creds);
-
- if (cli_lsa_initialise(&cli, server, &creds) == NULL) {
- goto done;
+ /* Initialise RPC connection */
+ if (!cli_nt_session_open (cli, PIPE_LSARPC)) {
+ fprintf (stderr, "Could not initialize samr pipe!\n");
+ return NT_STATUS_UNSUCCESSFUL;
}
- if ((result = cli_lsa_open_policy(&cli, True,
+ if ((result = cli_lsa_open_policy(cli, True,
SEC_RIGHTS_MAXIMUM_ALLOWED,
&pol)) != NT_STATUS_NOPROBLEMO) {
goto done;
@@ -205,7 +190,7 @@ static uint32 cmd_lsa_lookup_sids(int argc, char **argv)
/* Lookup the SIDs */
- if ((result = cli_lsa_lookup_sids(&cli, &pol, argc - 1, sids,
+ if ((result = cli_lsa_lookup_sids(cli, &pol, argc - 1, sids,
&names, &types, &num_names) !=
NT_STATUS_NOPROBLEMO)) {
goto done;
@@ -233,22 +218,20 @@ static uint32 cmd_lsa_lookup_sids(int argc, char **argv)
done:
if (got_policy_hnd) {
- cli_lsa_close(&cli, &pol);
+ cli_lsa_close(cli, &pol);
}
- cli_lsa_shutdown(&cli);
+ cli_nt_session_close(cli);
return result;
}
/* Enumerate list of trusted domains */
-static uint32 cmd_lsa_enum_trust_dom(int argc, char **argv)
+static uint32 cmd_lsa_enum_trust_dom(struct cli_state *cli, int argc, char **argv)
{
- struct cli_state cli;
POLICY_HND pol;
uint32 result = NT_STATUS_UNSUCCESSFUL;
- struct ntuser_creds creds;
BOOL got_policy_hnd = False;
DOM_SID *domain_sids;
char **domain_names;
@@ -259,16 +242,13 @@ static uint32 cmd_lsa_enum_trust_dom(int argc, char **argv)
return 0;
}
- /* Open a lsa handle */
-
- ZERO_STRUCT(cli);
- init_rpcclient_creds(&creds);
-
- if (cli_lsa_initialise(&cli, server, &creds) == NULL) {
- goto done;
+ /* Initialise RPC connection */
+ if (!cli_nt_session_open (cli, PIPE_LSARPC)) {
+ fprintf (stderr, "Could not initialize samr pipe!\n");
+ return NT_STATUS_UNSUCCESSFUL;
}
- if ((result = cli_lsa_open_policy(&cli, True,
+ if ((result = cli_lsa_open_policy(cli, True,
SEC_RIGHTS_MAXIMUM_ALLOWED,
&pol)) != NT_STATUS_NOPROBLEMO) {
goto done;
@@ -278,7 +258,7 @@ static uint32 cmd_lsa_enum_trust_dom(int argc, char **argv)
/* Lookup list of trusted domains */
- if ((result = cli_lsa_enum_trust_dom(&cli, &pol, &enum_ctx,
+ if ((result = cli_lsa_enum_trust_dom(cli, &pol, &enum_ctx,
&num_domains, &domain_names,
&domain_sids)
!= NT_STATUS_NOPROBLEMO)) {
@@ -306,10 +286,10 @@ static uint32 cmd_lsa_enum_trust_dom(int argc, char **argv)
done:
if (got_policy_hnd) {
- cli_lsa_close(&cli, &pol);
+ cli_lsa_close(cli, &pol);
}
- cli_lsa_shutdown(&cli);
+ cli_nt_session_close(cli);
return result;
}
@@ -317,9 +297,9 @@ static uint32 cmd_lsa_enum_trust_dom(int argc, char **argv)
/* List of commands exported by this module */
struct cmd_set lsarpc_commands[] = {
- { "lsaquery", cmd_lsa_query_info_policy, "Query info policy" },
- { "lookupsids", cmd_lsa_lookup_sids, "Convert SIDs to names" },
- { "lookupnames", cmd_lsa_lookup_names, "Convert names to SIDs" },
- { "enumtrust", cmd_lsa_enum_trust_dom, "Enumerate trusted domains" },
+ { "lsaquery", cmd_lsa_query_info_policy, "Query info policy" },
+ { "lookupsids", cmd_lsa_lookup_sids, "Convert SIDs to names" },
+ { "lookupnames",cmd_lsa_lookup_names, "Convert names to SIDs" },
+ { "enumtrust", cmd_lsa_enum_trust_dom, "Enumerate trusted domains" },
{ NULL, NULL, NULL }
};
diff --git a/source3/rpcclient/cmd_samr.c b/source3/rpcclient/cmd_samr.c
index 59830e7742..c7bed1368e 100644
--- a/source3/rpcclient/cmd_samr.c
+++ b/source3/rpcclient/cmd_samr.c
@@ -95,15 +95,16 @@ static void display_sam_user_info_21(SAM_USER_INFO_21 *usr)
}
}
-/* Query user information */
-
-static uint32 cmd_samr_query_user(int argc, char **argv)
+/**********************************************************************
+ * Query user information
+ */
+static uint32 cmd_samr_query_user(struct cli_state *cli, int argc, char **argv)
{
- struct cli_state cli;
POLICY_HND connect_pol, domain_pol, user_pol;
- uint32 result = NT_STATUS_UNSUCCESSFUL, info_level = 21;
- struct ntuser_creds creds;
- BOOL got_connect_pol = False, got_domain_pol = False,
+ uint32 result = NT_STATUS_UNSUCCESSFUL,
+ info_level = 21;
+ BOOL got_connect_pol = False,
+ got_domain_pol = False,
got_user_pol = False;
SAM_USERINFO_CTR user_ctr;
SAM_USER_INFO_21 info_21;
@@ -113,25 +114,22 @@ static uint32 cmd_samr_query_user(int argc, char **argv)
return 0;
}
- /* Open a lsa handle */
-
- ZERO_STRUCT(cli);
- init_rpcclient_creds(&creds);
-
- if (!cli_samr_initialise(&cli, server, &creds)) {
- goto done;
+ /* Initialise RPC connection */
+ if (!cli_nt_session_open (cli, PIPE_SAMR)) {
+ fprintf (stderr, "Could not initialize samr pipe!\n");
+ return NT_STATUS_UNSUCCESSFUL;
}
- if ((result = cli_samr_connect(&cli, server, MAXIMUM_ALLOWED_ACCESS,
+ if ((result = cli_samr_connect(cli, server, MAXIMUM_ALLOWED_ACCESS,
&connect_pol)) !=
NT_STATUS_NOPROBLEMO) {
goto done;
}
got_connect_pol = True;
- fetch_domain_sid();
+ fetch_domain_sid(cli);
- if ((result = cli_samr_open_domain(&cli, &connect_pol,
+ if ((result = cli_samr_open_domain(cli, &connect_pol,
MAXIMUM_ALLOWED_ACCESS,
&domain_sid, &domain_pol))
!= NT_STATUS_NOPROBLEMO) {
@@ -140,7 +138,7 @@ static uint32 cmd_samr_query_user(int argc, char **argv)
got_domain_pol = True;
- if ((result = cli_samr_open_user(&cli, &domain_pol,
+ if ((result = cli_samr_open_user(cli, &domain_pol,
MAXIMUM_ALLOWED_ACCESS,
0x1f4, &user_pol))
!= NT_STATUS_NOPROBLEMO) {
@@ -154,7 +152,7 @@ static uint32 cmd_samr_query_user(int argc, char **argv)
user_ctr.info.id21 = &info_21;
- if ((result = cli_samr_query_userinfo(&cli, &user_pol, info_level,
+ if ((result = cli_samr_query_userinfo(cli, &user_pol, info_level,
&user_ctr))
!= NT_STATUS_NOPROBLEMO) {
goto done;
@@ -162,12 +160,12 @@ static uint32 cmd_samr_query_user(int argc, char **argv)
display_sam_user_info_21(&info_21);
- done:
- if (got_user_pol) cli_samr_close(&cli, &user_pol);
- if (got_domain_pol) cli_samr_close(&cli, &domain_pol);
- if (got_connect_pol) cli_samr_close(&cli, &connect_pol);
+done:
+ if (got_user_pol) cli_samr_close(cli, &user_pol);
+ if (got_domain_pol) cli_samr_close(cli, &domain_pol);
+ if (got_connect_pol) cli_samr_close(cli, &connect_pol);
- cli_samr_shutdown(&cli);
+ cli_nt_session_close(cli);
return result;
}
@@ -215,14 +213,13 @@ static void display_group_info_ctr(GROUP_INFO_CTR *ctr)
}
}
-/* Query group information */
-
-static uint32 cmd_samr_query_group(int argc, char **argv)
+/***********************************************************************
+ * Query group information
+ */
+static uint32 cmd_samr_query_group(struct cli_state *cli, int argc, char **argv)
{
- struct cli_state cli;
POLICY_HND connect_pol, domain_pol, group_pol;
uint32 result = NT_STATUS_UNSUCCESSFUL, info_level = 1;
- struct ntuser_creds creds;
BOOL got_connect_pol = False, got_domain_pol = False,
got_group_pol = False;
GROUP_INFO_CTR group_ctr;
@@ -232,25 +229,22 @@ static uint32 cmd_samr_query_group(int argc, char **argv)
return 0;
}
- /* Open a lsa handle */
-
- ZERO_STRUCT(cli);
- init_rpcclient_creds(&creds);
-
- if (!cli_samr_initialise(&cli, server, &creds)) {
- goto done;
+ /* Initialise RPC connection */
+ if (!cli_nt_session_open (cli, PIPE_SAMR)) {
+ fprintf (stderr, "Could not initialize samr pipe!\n");
+ return NT_STATUS_UNSUCCESSFUL;
}
- if ((result = cli_samr_connect(&cli, server, MAXIMUM_ALLOWED_ACCESS,
+ if ((result = cli_samr_connect(cli, server, MAXIMUM_ALLOWED_ACCESS,
&connect_pol)) !=
NT_STATUS_NOPROBLEMO) {
goto done;
}
got_connect_pol = True;
- fetch_domain_sid();
+ fetch_domain_sid(cli);
- if ((result = cli_samr_open_domain(&cli, &connect_pol,
+ if ((result = cli_samr_open_domain(cli, &connect_pol,
MAXIMUM_ALLOWED_ACCESS,
&domain_sid, &domain_pol))
!= NT_STATUS_NOPROBLEMO) {
@@ -259,7 +253,7 @@ static uint32 cmd_samr_query_group(int argc, char **argv)
got_domain_pol = True;
- if ((result = cli_samr_open_group(&cli, &domain_pol,
+ if ((result = cli_samr_open_group(cli, &domain_pol,
MAXIMUM_ALLOWED_ACCESS,
0x202, &group_pol))
!= NT_STATUS_NOPROBLEMO) {
@@ -270,7 +264,7 @@ static uint32 cmd_samr_query_group(int argc, char **argv)
ZERO_STRUCT(group_ctr);
- if ((result = cli_samr_query_groupinfo(&cli, &group_pol, info_level,
+ if ((result = cli_samr_query_groupinfo(cli, &group_pol, info_level,
&group_ctr))
!= NT_STATUS_NOPROBLEMO) {
goto done;
@@ -278,24 +272,22 @@ static uint32 cmd_samr_query_group(int argc, char **argv)
display_group_info_ctr(&group_ctr);
- done:
- if (got_group_pol) cli_samr_close(&cli, &group_pol);
- if (got_domain_pol) cli_samr_close(&cli, &domain_pol);
- if (got_connect_pol) cli_samr_close(&cli, &connect_pol);
+done:
+ if (got_group_pol) cli_samr_close(cli, &group_pol);
+ if (got_domain_pol) cli_samr_close(cli, &domain_pol);
+ if (got_connect_pol) cli_samr_close(cli, &connect_pol);
- cli_samr_shutdown(&cli);
+ cli_nt_session_close(cli);
return result;
}
/* Query groups a user is a member of */
-static uint32 cmd_samr_query_usergroups(int argc, char **argv)
+static uint32 cmd_samr_query_usergroups(struct cli_state *cli, int argc, char **argv)
{
- struct cli_state cli;
POLICY_HND connect_pol, domain_pol, user_pol;
uint32 result = NT_STATUS_UNSUCCESSFUL;
- struct ntuser_creds creds;
BOOL got_connect_pol = False, got_domain_pol = False,
got_user_pol = False;
uint32 num_groups, user_rid;
@@ -309,25 +301,22 @@ static uint32 cmd_samr_query_usergroups(int argc, char **argv)
sscanf(argv[1], "%i", &user_rid);
- /* Open a lsa handle */
-
- ZERO_STRUCT(cli);
- init_rpcclient_creds(&creds);
-
- if (!cli_samr_initialise(&cli, server, &creds)) {
- goto done;
+ /* Initialise RPC connection */
+ if (!cli_nt_session_open (cli, PIPE_SAMR)) {
+ fprintf (stderr, "Could not initialize samr pipe!\n");
+ return NT_STATUS_UNSUCCESSFUL;
}
- if ((result = cli_samr_connect(&cli, server, MAXIMUM_ALLOWED_ACCESS,
+ if ((result = cli_samr_connect(cli, server, MAXIMUM_ALLOWED_ACCESS,
&connect_pol)) !=
NT_STATUS_NOPROBLEMO) {
goto done;
}
got_connect_pol = True;
- fetch_domain_sid();
+ fetch_domain_sid(cli);
- if ((result = cli_samr_open_domain(&cli, &connect_pol,
+ if ((result = cli_samr_open_domain(cli, &connect_pol,
MAXIMUM_ALLOWED_ACCESS,
&domain_sid, &domain_pol))
!= NT_STATUS_NOPROBLEMO) {
@@ -336,7 +325,7 @@ static uint32 cmd_samr_query_usergroups(int argc, char **argv)
got_domain_pol = True;
- if ((result = cli_samr_open_user(&cli, &domain_pol,
+ if ((result = cli_samr_open_user(cli, &domain_pol,
MAXIMUM_ALLOWED_ACCESS,
user_rid, &user_pol))
!= NT_STATUS_NOPROBLEMO) {
@@ -345,7 +334,7 @@ static uint32 cmd_samr_query_usergroups(int argc, char **argv)
got_user_pol = True;
- if ((result = cli_samr_query_usergroups(&cli, &user_pol,
+ if ((result = cli_samr_query_usergroups(cli, &user_pol,
&num_groups, &user_gids))
!= NT_STATUS_NOPROBLEMO) {
goto done;
@@ -357,24 +346,23 @@ static uint32 cmd_samr_query_usergroups(int argc, char **argv)
}
done:
- if (got_user_pol) cli_samr_close(&cli, &user_pol);
- if (got_domain_pol) cli_samr_close(&cli, &domain_pol);
- if (got_connect_pol) cli_samr_close(&cli, &connect_pol);
+ if (got_user_pol) cli_samr_close(cli, &user_pol);
+ if (got_domain_pol) cli_samr_close(cli, &domain_pol);
+ if (got_connect_pol) cli_samr_close(cli, &connect_pol);
- cli_samr_shutdown(&cli);
+ cli_nt_session_close(cli);
return result;
}
/* Query members of a group */
-static uint32 cmd_samr_query_groupmem(int argc, char **argv)
+static uint32 cmd_samr_query_groupmem(struct cli_state *cli, int argc, char **argv)
{
- struct cli_state cli;
POLICY_HND connect_pol, domain_pol, group_pol;
uint32 result = NT_STATUS_UNSUCCESSFUL;
- struct ntuser_creds creds;
- BOOL got_connect_pol = False, got_domain_pol = False,
+ BOOL got_connect_pol = False,
+ got_domain_pol = False,
got_group_pol = False;
uint32 num_members, *group_rids, *group_attrs, group_rid;
int i;
@@ -386,25 +374,22 @@ static uint32 cmd_samr_query_groupmem(int argc, char **argv)
sscanf(argv[1], "%i", &group_rid);
- /* Open a lsa handle */
-
- ZERO_STRUCT(cli);
- init_rpcclient_creds(&creds);
-
- if (!cli_samr_initialise(&cli, server, &creds)) {
- goto done;
+ /* Initialise RPC connection */
+ if (!cli_nt_session_open (cli, PIPE_SAMR)) {
+ fprintf (stderr, "Could not initialize samr pipe!\n");
+ return NT_STATUS_UNSUCCESSFUL;
}
-
- if ((result = cli_samr_connect(&cli, server, MAXIMUM_ALLOWED_ACCESS,
+
+ if ((result = cli_samr_connect(cli, server, MAXIMUM_ALLOWED_ACCESS,
&connect_pol)) !=
NT_STATUS_NOPROBLEMO) {
goto done;
}
got_connect_pol = True;
- fetch_domain_sid();
+ fetch_domain_sid(cli);
- if ((result = cli_samr_open_domain(&cli, &connect_pol,
+ if ((result = cli_samr_open_domain(cli, &connect_pol,
MAXIMUM_ALLOWED_ACCESS,
&domain_sid, &domain_pol))
!= NT_STATUS_NOPROBLEMO) {
@@ -413,7 +398,7 @@ static uint32 cmd_samr_query_groupmem(int argc, char **argv)
got_domain_pol = True;
- if ((result = cli_samr_open_group(&cli, &domain_pol,
+ if ((result = cli_samr_open_group(cli, &domain_pol,
MAXIMUM_ALLOWED_ACCESS,
group_rid, &group_pol))
!= NT_STATUS_NOPROBLEMO) {
@@ -422,7 +407,7 @@ static uint32 cmd_samr_query_groupmem(int argc, char **argv)
got_group_pol = True;
- if ((result = cli_samr_query_groupmem(&cli, &group_pol,
+ if ((result = cli_samr_query_groupmem(cli, &group_pol,
&num_members, &group_rids,
&group_attrs))
!= NT_STATUS_NOPROBLEMO) {
@@ -435,11 +420,11 @@ static uint32 cmd_samr_query_groupmem(int argc, char **argv)
}
done:
- if (got_group_pol) cli_samr_close(&cli, &group_pol);
- if (got_domain_pol) cli_samr_close(&cli, &domain_pol);
- if (got_connect_pol) cli_samr_close(&cli, &connect_pol);
+ if (got_group_pol) cli_samr_close(cli, &group_pol);
+ if (got_domain_pol) cli_samr_close(cli, &domain_pol);
+ if (got_connect_pol) cli_samr_close(cli, &connect_pol);
- cli_samr_shutdown(&cli);
+ cli_nt_session_close(cli);
return result;
}
@@ -447,9 +432,10 @@ static uint32 cmd_samr_query_groupmem(int argc, char **argv)
/* List of commands exported by this module */
struct cmd_set samr_commands[] = {
- { "queryuser", cmd_samr_query_user, "Query user info" },
- { "querygroup", cmd_samr_query_group, "Query group info" },
- { "queryusergroups", cmd_samr_query_usergroups, "Query user groups" },
- { "querygroupmem", cmd_samr_query_groupmem, "Query group membership" },
+ { "queryuser", cmd_samr_query_user, "Query user info" },
+ { "querygroup", cmd_samr_query_group, "Query group info" },
+ { "queryusergroups", cmd_samr_query_usergroups, "Query user groups" },
+ { "querygroupmem", cmd_samr_query_groupmem, "Query group membership" },
{ NULL, NULL, NULL }
};
+
diff --git a/source3/rpcclient/cmd_spoolss.c b/source3/rpcclient/cmd_spoolss.c
index a312bc8889..c7989d6882 100644
--- a/source3/rpcclient/cmd_spoolss.c
+++ b/source3/rpcclient/cmd_spoolss.c
@@ -224,11 +224,9 @@ static void display_print_info_3(PRINTER_INFO_3 *i3)
/* Enumerate printers */
-static uint32 cmd_spoolss_enum_printers(int argc, char **argv)
+static uint32 cmd_spoolss_enum_printers(struct cli_state *cli, int argc, char **argv)
{
uint32 result = NT_STATUS_UNSUCCESSFUL, info_level = 1;
- struct cli_state cli;
- struct ntuser_creds creds;
PRINTER_INFO_CTR ctr;
int returned;
@@ -242,19 +240,14 @@ static uint32 cmd_spoolss_enum_printers(int argc, char **argv)
}
/* Initialise RPC connection */
-
- ZERO_STRUCT(cli);
- init_rpcclient_creds(&creds);
-
- if (cli_spoolss_initialise(&cli, server, &creds) == NULL) {
- goto done;
+ if (!cli_nt_session_open (cli, PIPE_SPOOLSS)) {
+ fprintf (stderr, "Could not initialize spoolss pipe!\n");
+ return NT_STATUS_UNSUCCESSFUL;
}
/* Enumerate printers */
-
ZERO_STRUCT(ctr);
-
- result = cli_spoolss_enum_printers(&cli, PRINTER_ENUM_LOCAL,
+ result = cli_spoolss_enum_printers(cli, PRINTER_ENUM_LOCAL,
info_level, &returned, &ctr);
if (result == NT_STATUS_NOPROBLEMO) {
@@ -277,8 +270,7 @@ static uint32 cmd_spoolss_enum_printers(int argc, char **argv)
}
}
- done:
- cli_spoolss_shutdown(&cli);
+ cli_nt_session_close(cli);
return result;
}
@@ -314,11 +306,9 @@ static void display_port_info_2(PORT_INFO_2 *i2)
/* Enumerate ports */
-static uint32 cmd_spoolss_enum_ports(int argc, char **argv)
+static uint32 cmd_spoolss_enum_ports(struct cli_state *cli, int argc, char **argv)
{
uint32 result = NT_STATUS_UNSUCCESSFUL, info_level = 1;
- struct cli_state cli;
- struct ntuser_creds creds;
PORT_INFO_CTR ctr;
int returned;
@@ -332,19 +322,15 @@ static uint32 cmd_spoolss_enum_ports(int argc, char **argv)
}
/* Initialise RPC connection */
-
- ZERO_STRUCT(cli);
- init_rpcclient_creds(&creds);
-
- if (cli_spoolss_initialise(&cli, server, &creds) == NULL) {
- goto done;
+ if (!cli_nt_session_open (cli, PIPE_SPOOLSS)) {
+ fprintf (stderr, "Could not initialize spoolss pipe!\n");
+ return NT_STATUS_UNSUCCESSFUL;
}
- /* Enumerate printers */
-
+ /* Enumerate ports */
ZERO_STRUCT(ctr);
- result = cli_spoolss_enum_ports(&cli, info_level, &returned, &ctr);
+ result = cli_spoolss_enum_ports(cli, info_level, &returned, &ctr);
if (result == NT_STATUS_NOPROBLEMO) {
int i;
@@ -364,21 +350,18 @@ static uint32 cmd_spoolss_enum_ports(int argc, char **argv)
}
}
- done:
- cli_spoolss_shutdown(&cli);
+ cli_nt_session_close(cli);
return result;
}
/* Get printer information */
-static uint32 cmd_spoolss_getprinter(int argc, char **argv)
+static uint32 cmd_spoolss_getprinter(struct cli_state *cli, int argc, char **argv)
{
- struct cli_state cli;
POLICY_HND pol;
uint32 result, info_level = 1;
BOOL opened_hnd = False;
- struct ntuser_creds creds;
PRINTER_INFO_CTR ctr;
fstring printer_name, station_name;
@@ -388,12 +371,9 @@ static uint32 cmd_spoolss_getprinter(int argc, char **argv)
}
/* Initialise RPC connection */
-
- ZERO_STRUCT(cli);
- init_rpcclient_creds(&creds);
-
- if (cli_spoolss_initialise(&cli, server, &creds) == NULL) {
- goto done;
+ if (!cli_nt_session_open (cli, PIPE_SPOOLSS)) {
+ fprintf (stderr, "Could not initialize spoolss pipe!\n");
+ return NT_STATUS_UNSUCCESSFUL;
}
/* Open a printer handle */
@@ -408,7 +388,7 @@ static uint32 cmd_spoolss_getprinter(int argc, char **argv)
slprintf(station_name, sizeof(fstring), "\\\\%s", global_myname);
if ((result = cli_spoolss_open_printer_ex(
- &cli, printer_name, "", MAXIMUM_ALLOWED_ACCESS, station_name,
+ cli, printer_name, "", MAXIMUM_ALLOWED_ACCESS, station_name,
username, &pol)) != NT_STATUS_NOPROBLEMO) {
goto done;
}
@@ -416,8 +396,7 @@ static uint32 cmd_spoolss_getprinter(int argc, char **argv)
opened_hnd = True;
/* Get printer info */
-
- if ((result = cli_spoolss_getprinter(&cli, &pol, info_level, &ctr))
+ if ((result = cli_spoolss_getprinter(cli, &pol, info_level, &ctr))
!= NT_STATUS_NOPROBLEMO) {
goto done;
}
@@ -443,9 +422,9 @@ static uint32 cmd_spoolss_getprinter(int argc, char **argv)
}
done:
- if (opened_hnd) cli_spoolss_closeprinter(&cli, &pol);
+ if (opened_hnd) cli_spoolss_closeprinter(cli, &pol);
- cli_spoolss_shutdown(&cli);
+ cli_nt_session_close(cli);
return result;
}
@@ -454,9 +433,9 @@ static uint32 cmd_spoolss_getprinter(int argc, char **argv)
struct cmd_set spoolss_commands[] = {
- { "enumprinters", cmd_spoolss_enum_printers, "Enumerate printers" },
- { "enumports", cmd_spoolss_enum_ports, "Enumerate printer ports" },
- { "getprinter", cmd_spoolss_getprinter, "Get printer info" },
+ { "enumprinters", cmd_spoolss_enum_printers, "Enumerate printers" },
+ { "enumports", cmd_spoolss_enum_ports, "Enumerate printer ports" },
+ { "getprinter", cmd_spoolss_getprinter, "Get printer info" },
{ NULL, NULL, NULL }
};
diff --git a/source3/rpcclient/rpcclient.c b/source3/rpcclient/rpcclient.c
index fce66b6b9b..7cdd73a592 100644
--- a/source3/rpcclient/rpcclient.c
+++ b/source3/rpcclient/rpcclient.c
@@ -23,50 +23,45 @@
#include "includes.h"
extern int DEBUGLEVEL;
-
-/* Connect info */
+extern fstring debugf;
+
+/* Various pipe commands */
+extern struct cmd_set lsarpc_commands[];
+extern struct cmd_set samr_commands[];
+extern struct cmd_set spoolss_commands[];
pstring password;
pstring username;
pstring workgroup;
pstring server;
-/* Various pipe commands */
-
-extern struct cmd_set lsarpc_commands[];
-extern struct cmd_set samr_commands[];
-extern struct cmd_set spoolss_commands[];
DOM_SID domain_sid;
-/* Fetch the SID for this domain */
-void fetch_domain_sid(void)
+/* Fetch the SID for this domain */
+void fetch_domain_sid(struct cli_state *cli)
{
- struct cli_state cli;
POLICY_HND pol;
uint32 result = 0, info_class = 5;
- struct ntuser_creds creds;
fstring domain_name;
static BOOL got_domain_sid;
if (got_domain_sid) return;
- ZERO_STRUCT(cli);
- init_rpcclient_creds(&creds);
- if (cli_lsa_initialise(&cli, server, &creds) == NULL) {
+ if (!cli_nt_session_open (cli, PIPE_LSARPC)) {
fprintf(stderr, "could not initialise lsa pipe\n");
goto error;
}
-
- if ((result = cli_lsa_open_policy(&cli, True,
+
+ if ((result = cli_lsa_open_policy(cli, True,
SEC_RIGHTS_MAXIMUM_ALLOWED,
&pol) != NT_STATUS_NOPROBLEMO)) {
goto error;
}
- if ((result = cli_lsa_query_info_policy(&cli, &pol, info_class,
+ if ((result = cli_lsa_query_info_policy(cli, &pol, info_class,
domain_name, &domain_sid))
!= NT_STATUS_NOPROBLEMO) {
goto error;
@@ -74,8 +69,8 @@ void fetch_domain_sid(void)
got_domain_sid = True;
- cli_lsa_close(&cli, &pol);
- cli_lsa_shutdown(&cli);
+ cli_lsa_close(cli, &pol);
+ cli_nt_session_close(cli);
return;
@@ -91,7 +86,8 @@ void fetch_domain_sid(void)
/* Initialise client credentials for authenticated pipe access */
-void init_rpcclient_creds(struct ntuser_creds *creds)
+void init_rpcclient_creds(struct ntuser_creds *creds, char* username,
+ char* workgroup, char* password)
{
ZERO_STRUCTP(creds);
@@ -112,7 +108,7 @@ static struct cmd_list {
struct cmd_set *cmd_set;
} *cmd_list;
-static uint32 cmd_help(int argc, char **argv)
+static uint32 cmd_help(struct cli_state *cli, int argc, char **argv)
{
struct cmd_list *temp_list;
@@ -129,7 +125,7 @@ static uint32 cmd_help(int argc, char **argv)
return 0;
}
-static uint32 cmd_debuglevel(int argc, char **argv)
+static uint32 cmd_debuglevel(struct cli_state *cli, int argc, char **argv)
{
if (argc > 2) {
printf("Usage: %s [debuglevel]\n", argv[0]);
@@ -145,7 +141,7 @@ static uint32 cmd_debuglevel(int argc, char **argv)
return NT_STATUS_NOPROBLEMO;
}
-static uint32 cmd_quit(int argc, char **argv)
+static uint32 cmd_quit(struct cli_state *cli, int argc, char **argv)
{
exit(0);
}
@@ -153,10 +149,10 @@ static uint32 cmd_quit(int argc, char **argv)
/* Build in rpcclient commands */
static struct cmd_set rpcclient_commands[] = {
- { "help", cmd_help, "Print list of commands" },
+ { "help", cmd_help, "Print list of commands" },
{ "debuglevel", cmd_debuglevel, "Set debug level" },
- { "quit", cmd_quit, "Exit program" },
- { "?", cmd_help, "Print list of commands" },
+ { "quit", cmd_quit, "Exit program" },
+ { "?", cmd_help, "Print list of commands" },
{ NULL, NULL, NULL }
};
@@ -176,7 +172,7 @@ void add_command_set(struct cmd_set *cmd_set)
DLIST_ADD(cmd_list, entry);
}
-static uint32 do_cmd(struct cmd_set *cmd_entry, char *cmd)
+static uint32 do_cmd(struct cli_state *cli, struct cmd_set *cmd_entry, char *cmd)
{
char *p = cmd, **argv = NULL;
uint32 result;
@@ -218,7 +214,7 @@ static uint32 do_cmd(struct cmd_set *cmd_entry, char *cmd)
/* Call the function */
- result = cmd_entry->fn(argc, argv);
+ result = cmd_entry->fn(cli, argc, argv);
/* Cleanup */
@@ -233,7 +229,7 @@ static uint32 do_cmd(struct cmd_set *cmd_entry, char *cmd)
/* Process a command entered at the prompt or as part of -c */
-static uint32 process_cmd(char *cmd)
+static uint32 process_cmd(struct cli_state *cli, char *cmd)
{
struct cmd_list *temp_list;
BOOL found = False;
@@ -253,7 +249,7 @@ static uint32 process_cmd(char *cmd)
while(temp_set->name) {
if (strequal(buf, temp_set->name)) {
found = True;
- result = do_cmd(temp_set, cmd);
+ result = do_cmd(cli, temp_set, cmd);
goto done;
}
temp_set++;
@@ -273,18 +269,59 @@ static uint32 process_cmd(char *cmd)
return result;
}
-/* Print usage information */
+/************************************************************************/
+struct cli_state *setup_connection(struct cli_state *cli, char *system_name,
+ struct ntuser_creds *creds)
+{
+ struct in_addr dest_ip;
+ struct nmb_name calling, called;
+ fstring dest_host;
+ extern pstring global_myname;
+ struct ntuser_creds anon;
+
+ /* Initialise cli_state information */
+ if (!cli_initialise(cli)) {
+ return NULL;
+ }
+ if (!creds) {
+ ZERO_STRUCT(anon);
+ anon.pwd.null_pwd = 1;
+ creds = &anon;
+ }
+
+ cli_init_creds(cli, creds);
+
+ /* Establish a SMB connection */
+ if (!resolve_srv_name(system_name, dest_host, &dest_ip)) {
+ return NULL;
+ }
+
+ make_nmb_name(&called, dns_to_netbios_name(dest_host), 0x20);
+ make_nmb_name(&calling, dns_to_netbios_name(global_myname), 0);
+
+ if (!cli_establish_connection(cli, dest_host, &dest_ip, &calling,
+ &called, "IPC$", "IPC", False, True)) {
+ return NULL;
+ }
+
+ return cli;
+}
+
+
+/* Print usage information */
static void usage(char *pname)
{
printf("Usage: %s server [options]\n", pname);
- printf("\t-N don't ask for a password\n");
+ printf("\t-c \"command string\" execute semicolon separated cmds\n");
printf("\t-d debuglevel set the debuglevel\n");
+ printf("\t-l logfile name of logfile to use as opposed to stdout\n");
printf("\t-h Print this help message.\n");
+ printf("\t-N don't ask for a password\n");
+ printf("\t-s configfile specify an alternative config file\n");
printf("\t-U username set the network username\n");
printf("\t-W workgroup set the workgroup name\n");
- printf("\t-c command string execute semicolon separated cmds\n");
printf("\n");
}
@@ -297,41 +334,24 @@ static void usage(char *pname)
struct in_addr dest_ip;
extern pstring global_myname;
BOOL got_pass = False;
+ BOOL interactive = True;
BOOL have_ip = False;
int opt;
+ int olddebug;
pstring cmdstr = "", servicesf = CONFIGFILE;
- extern FILE *dbf;
+ struct ntuser_creds creds;
+ struct cli_state cli;
setlinebuf(stdout);
- dbf = stderr;
-
- setup_logging(argv[0], True);
#ifdef HAVE_LIBREADLINE
/* Allow conditional parsing of the ~/.inputrc file. */
rl_readline_name = "rpcclient";
#endif
- DEBUGLEVEL = 2;
-
- /* Load smb.conf file */
-
- charset_initialise();
-
- if (!lp_load(servicesf,True,False,False)) {
- fprintf(stderr, "Can't load %s\n", servicesf);
- }
-
- codepage_initialise(lp_client_code_page());
- load_interfaces();
-
- TimeInit();
-
- get_myname((*global_myname)?NULL:global_myname);
- strupper(global_myname);
+ DEBUGLEVEL = 1;
/* Parse options */
-
if (argc < 2) {
usage(argv[0]);
return 0;
@@ -342,21 +362,35 @@ static void usage(char *pname)
argv++;
argc--;
- while ((opt = getopt(argc, argv, "s:Nd:I:U:W:c:")) != EOF) {
+ while ((opt = getopt(argc, argv, "s:Nd:I:U:W:c:l:")) != EOF) {
switch (opt) {
- case 's':
- pstrcpy(servicesf, optarg);
- break;
- case 'N':
+ case 'c':
+ pstrcpy(cmdstr, optarg);
got_pass = True;
break;
+
case 'd':
DEBUGLEVEL = atoi(optarg);
break;
+
case 'I':
dest_ip = *interpret_addr2(optarg);
have_ip = True;
break;
+
+ case 'l':
+ slprintf(debugf, sizeof(debugf) - 1, "%s.client", optarg);
+ interactive = False;
+ break;
+
+ case 'N':
+ got_pass = True;
+ break;
+
+ case 's':
+ pstrcpy(servicesf, optarg);
+ break;
+
case 'U': {
char *lp;
pstrcpy(username,optarg);
@@ -368,50 +402,95 @@ static void usage(char *pname)
}
break;
}
+
case 'W':
pstrcpy(workgroup, optarg);
break;
- case 'c':
- pstrcpy(cmdstr, optarg);
- got_pass = True;
- break;
+
case 'h':
default:
usage(argv[0]);
exit(1);
}
}
+
+ /* the following functions are part of the Samba debugging
+ facilities. See lib/debug.c */
+ setup_logging (argv[0], interactive);
+ if (!interactive)
+ reopen_logs();
- /* Load command lists */
+ charset_initialise();
+
+ /* FIXME! How to get this DEBUGLEVEL to last over lp_load()? */
+ olddebug = DEBUGLEVEL;
+ /* Load smb.conf file */
+ if (!lp_load(servicesf,True,False,False)) {
+ fprintf(stderr, "Can't load %s\n", servicesf);
+ }
+ DEBUGLEVEL = olddebug;
+
+ codepage_initialise(lp_client_code_page());
+ load_interfaces();
+
+ TimeInit();
+
+ get_myname((*global_myname)?NULL:global_myname);
+ strupper(global_myname);
+
+ /*
+ * initialize the credentials struct. Get password
+ * from stdin if necessary
+ */
+ if (!got_pass) {
+ init_rpcclient_creds (&creds, username, workgroup, "");
+ pwd_read(&creds.pwd, "Password : ", lp_encrypted_passwords());
+ }
+ else {
+ init_rpcclient_creds (&creds, username, workgroup, password);
+ }
+ memset(password,'X',strlen(password));
+
+ /* open a connection to the specified server */
+ ZERO_STRUCTP (&cli);
+ if (!setup_connection (&cli, server, &creds)) {
+ return 0;
+ }
+
+ /* There are no pointers in ntuser_creds struct so zero it out */
+ ZERO_STRUCTP (&creds);
+
+
+ /* Load command lists */
add_command_set(rpcclient_commands);
+ add_command_set(spoolss_commands);
add_command_set(lsarpc_commands);
add_command_set(samr_commands);
- add_command_set(spoolss_commands);
- /* Do anything specified with -c */
+ /* Do anything specified with -c */
if (cmdstr[0]) {
pstring cmd;
char *p = cmdstr;
uint32 result;
while(next_token(&p, cmd, ";", sizeof(pstring))) {
- result = process_cmd(cmd);
+ result = process_cmd(&cli, cmd);
}
return 0;
}
- /* Loop around accepting commands */
+ /* Loop around accepting commands */
while(1) {
pstring prompt, cmd;
uint32 result;
ZERO_STRUCT(cmd);
- slprintf(prompt, sizeof(prompt) - 1, "rpcclient> ");
+ slprintf(prompt, sizeof(prompt) - 1, "rpcclient $> ");
#if HAVE_READLINE
cmd = readline(prompt);
@@ -424,8 +503,9 @@ static void usage(char *pname)
cmd[strlen(cmd) - 1] = '\0';
#endif
- result = process_cmd(cmd);
+ result = process_cmd(&cli, cmd);
}
-
+
return 0;
}
+