summaryrefslogtreecommitdiff
path: root/source3/rpcclient
diff options
context:
space:
mode:
Diffstat (limited to 'source3/rpcclient')
-rw-r--r--source3/rpcclient/cmd_lsarpc.c65
-rw-r--r--source3/rpcclient/cmd_netlogon.c9
-rw-r--r--source3/rpcclient/cmd_samr.c429
-rw-r--r--source3/rpcclient/cmd_spoolss.c10
-rw-r--r--source3/rpcclient/cmd_srvsvc.c131
-rw-r--r--source3/rpcclient/rpcclient.c86
-rw-r--r--source3/rpcclient/samsync.c59
7 files changed, 519 insertions, 270 deletions
diff --git a/source3/rpcclient/cmd_lsarpc.c b/source3/rpcclient/cmd_lsarpc.c
index 56ae4c6e68..067325c06e 100644
--- a/source3/rpcclient/cmd_lsarpc.c
+++ b/source3/rpcclient/cmd_lsarpc.c
@@ -2,7 +2,8 @@
Unix SMB/CIFS implementation.
RPC pipe client
- Copyright (C) Tim Potter 2000
+ Copyright (C) Tim Potter 2000
+ Copyright (C) Rafal Szczesniak 2002
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -95,18 +96,19 @@ static NTSTATUS cmd_lsa_lookup_names(struct cli_state *cli,
result = cli_lsa_lookup_names(cli, mem_ctx, &pol, argc - 1,
(const char**)(argv + 1), &sids, &types);
- if (!NT_STATUS_IS_OK(result) &&
- NT_STATUS_V(result) != NT_STATUS_V(STATUS_SOME_UNMAPPED))
+ if (!NT_STATUS_IS_OK(result) && NT_STATUS_V(result) !=
+ NT_STATUS_V(STATUS_SOME_UNMAPPED))
goto done;
+ result = NT_STATUS_OK;
+
/* Print results */
for (i = 0; i < (argc - 1); i++) {
fstring sid_str;
-
sid_to_string(sid_str, &sids[i]);
- printf("%s %s (%d)\n", argv[i + 1], sid_str,
- types[i]);
+ printf("%s %s (%s: %d)\n", argv[i + 1], sid_str,
+ sid_type_lookup(types[i]), types[i]);
}
done:
@@ -147,7 +149,7 @@ static NTSTATUS cmd_lsa_lookup_sids(struct cli_state *cli, TALLOC_CTX *mem_ctx,
goto done;
}
- for (i = 0; i < (argc - 1); i++)
+ for (i = 0; i < argc - 1; i++)
string_to_sid(&sids[i], argv[i + 1]);
/* Lookup the SIDs */
@@ -155,17 +157,19 @@ static NTSTATUS cmd_lsa_lookup_sids(struct cli_state *cli, TALLOC_CTX *mem_ctx,
result = cli_lsa_lookup_sids(cli, mem_ctx, &pol, argc - 1, sids,
&domains, &names, &types);
- if (!NT_STATUS_IS_OK(result) &&
- NT_STATUS_V(result) != NT_STATUS_V(STATUS_SOME_UNMAPPED))
+ if (!NT_STATUS_IS_OK(result) && NT_STATUS_V(result) !=
+ NT_STATUS_V(STATUS_SOME_UNMAPPED))
goto done;
+ result = NT_STATUS_OK;
+
/* Print results */
for (i = 0; i < (argc - 1); i++) {
fstring sid_str;
sid_to_string(sid_str, &sids[i]);
- printf("%s [%s]\\[%s] (%d)\n", sid_str,
+ printf("%s %s\\%s (%d)\n", sid_str,
domains[i] ? domains[i] : "*unknown*",
names[i] ? names[i] : "*unknown*", types[i]);
}
@@ -184,17 +188,31 @@ static NTSTATUS cmd_lsa_enum_trust_dom(struct cli_state *cli,
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
DOM_SID *domain_sids;
char **domain_names;
+
+ /* defaults, but may be changed using params */
uint32 enum_ctx = 0;
- uint32 num_domains;
+ uint32 preferred_maxnum = 5;
+ uint32 num_domains = 0;
int i;
- if (argc != 1) {
- printf("Usage: %s\n", argv[0]);
+ if (argc > 3) {
+ printf("Usage: %s [preferred max number (%d)] [enum context (0)]\n",
+ argv[0], preferred_maxnum);
return NT_STATUS_OK;
}
+ /* enumeration context */
+ if (argc >= 2 && argv[1]) {
+ preferred_maxnum = atoi(argv[1]);
+ }
+
+ /* preferred maximum number */
+ if (argc == 3 && argv[2]) {
+ enum_ctx = atoi(argv[2]);
+ }
+
result = cli_lsa_open_policy(cli, mem_ctx, True,
- SEC_RIGHTS_MAXIMUM_ALLOWED,
+ POLICY_VIEW_LOCAL_INFORMATION,
&pol);
if (!NT_STATUS_IS_OK(result))
@@ -203,14 +221,14 @@ static NTSTATUS cmd_lsa_enum_trust_dom(struct cli_state *cli,
/* Lookup list of trusted domains */
result = cli_lsa_enum_trust_dom(cli, mem_ctx, &pol, &enum_ctx,
- &num_domains, &domain_names,
- &domain_sids);
-
- if (!NT_STATUS_IS_OK(result))
- goto done;
-
- /* Print results */
-
+ &preferred_maxnum, &num_domains,
+ &domain_names, &domain_sids);
+ if (!NT_STATUS_IS_OK(result) &&
+ !NT_STATUS_EQUAL(result, NT_STATUS_NO_MORE_ENTRIES) &&
+ !NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES))
+ goto done;
+
+ /* Print results: list of names and sids returned in this response. */
for (i = 0; i < num_domains; i++) {
fstring sid_str;
@@ -447,6 +465,7 @@ static NTSTATUS cmd_lsa_lookupprivvalue(struct cli_state *cli,
goto done;
/* Print results */
+
printf("%u:%u (0x%x:0x%x)\n", luid.high, luid.low, luid.high, luid.low);
done:
@@ -498,7 +517,7 @@ struct cmd_set lsarpc_commands[] = {
{ "lsaquery", cmd_lsa_query_info_policy, PIPE_LSARPC, "Query info policy", "" },
{ "lookupsids", cmd_lsa_lookup_sids, PIPE_LSARPC, "Convert SIDs to names", "" },
{ "lookupnames", cmd_lsa_lookup_names, PIPE_LSARPC, "Convert names to SIDs", "" },
- { "enumtrust", cmd_lsa_enum_trust_dom, PIPE_LSARPC, "Enumerate trusted domains", "" },
+ { "enumtrust", cmd_lsa_enum_trust_dom, PIPE_LSARPC, "Enumerate trusted domains", "Usage: [preferred max number] [enum context (0)]" },
{ "enumprivs", cmd_lsa_enum_privilege, PIPE_LSARPC, "Enumerate privileges", "" },
{ "getdispname", cmd_lsa_get_dispname, PIPE_LSARPC, "Get the privilege name", "" },
{ "lsaenumsid", cmd_lsa_enum_sids, PIPE_LSARPC, "Enumerate the LSA SIDS", "" },
diff --git a/source3/rpcclient/cmd_netlogon.c b/source3/rpcclient/cmd_netlogon.c
index 4d67cba1b5..2e89572660 100644
--- a/source3/rpcclient/cmd_netlogon.c
+++ b/source3/rpcclient/cmd_netlogon.c
@@ -174,7 +174,8 @@ static NTSTATUS cmd_netlogon_sam_sync(struct cli_state *cli,
goto done;
}
- result = cli_nt_setup_creds(cli, trust_passwd);
+ result = new_cli_nt_setup_creds(cli, (lp_server_role() == ROLE_DOMAIN_MEMBER) ?
+ SEC_CHAN_WKSTA : SEC_CHAN_BDC, trust_passwd);
if (!NT_STATUS_IS_OK(result)) {
fprintf(stderr, "Error initialising session creds\n");
@@ -237,7 +238,8 @@ static NTSTATUS cmd_netlogon_sam_deltas(struct cli_state *cli,
goto done;
}
- result = cli_nt_setup_creds(cli, trust_passwd);
+ result = new_cli_nt_setup_creds(cli, (lp_server_role() == ROLE_DOMAIN_MEMBER) ?
+ SEC_CHAN_WKSTA : SEC_CHAN_BDC, trust_passwd);
if (!NT_STATUS_IS_OK(result)) {
fprintf(stderr, "Error initialising session creds\n");
@@ -299,7 +301,8 @@ static NTSTATUS cmd_netlogon_sam_logon(struct cli_state *cli,
goto done;
}
- result = cli_nt_setup_creds(cli, trust_passwd);
+ result = new_cli_nt_setup_creds(cli, (lp_server_role() == ROLE_DOMAIN_MEMBER) ?
+ SEC_CHAN_WKSTA : SEC_CHAN_BDC, trust_passwd);
if (!NT_STATUS_IS_OK(result)) {
fprintf(stderr, "Error initialising session creds\n");
diff --git a/source3/rpcclient/cmd_samr.c b/source3/rpcclient/cmd_samr.c
index ee46fc64a5..eae24683d2 100644
--- a/source3/rpcclient/cmd_samr.c
+++ b/source3/rpcclient/cmd_samr.c
@@ -79,13 +79,13 @@ static void display_sam_user_info_21(SAM_USER_INFO_21 *usr)
printf("\tunknown_2[0..31]...\n"); /* user passwords? */
- printf("\tuser_rid :\t%x\n" , usr->user_rid ); /* User ID */
- printf("\tgroup_rid:\t%x\n" , usr->group_rid); /* Group ID */
- printf("\tacb_info :\t%04x\n", usr->acb_info ); /* Account Control Info */
+ printf("\tuser_rid :\t0x%x\n" , usr->user_rid ); /* User ID */
+ printf("\tgroup_rid:\t0x%x\n" , usr->group_rid); /* Group ID */
+ printf("\tacb_info :\t0x%04x\n", usr->acb_info ); /* Account Control Info */
- printf("\tunknown_3:\t%08x\n", usr->unknown_3); /* 0x00ff ffff */
+ printf("\tunknown_3:\t0x%08x\n", usr->unknown_3); /* 0x00ff ffff */
printf("\tlogon_divs:\t%d\n", usr->logon_divs); /* 0x0000 00a8 which is 168 which is num hrs in a week */
- printf("\tunknown_5:\t%08x\n", usr->unknown_5); /* 0x0002 0000 */
+ printf("\tunknown_5:\t0x%08x\n", usr->unknown_5); /* 0x0002 0000 */
printf("\tpadding1[0..7]...\n");
@@ -253,16 +253,24 @@ static NTSTATUS cmd_samr_query_user(struct cli_state *cli,
POLICY_HND connect_pol, domain_pol, user_pol;
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
uint32 info_level = 21;
+ uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
SAM_USERINFO_CTR *user_ctr;
fstring server;
uint32 user_rid;
- if (argc != 2) {
- printf("Usage: %s rid\n", argv[0]);
+ if ((argc < 2) || (argc > 4)) {
+ printf("Usage: %s rid [info level] [access mask] \n", argv[0]);
return NT_STATUS_OK;
}
sscanf(argv[1], "%i", &user_rid);
+
+ if (argc > 2)
+ sscanf(argv[2], "%i", &info_level);
+
+ if (argc > 3)
+ sscanf(argv[3], "%x", &access_mask);
+
slprintf (server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
strupper (server);
@@ -281,7 +289,7 @@ static NTSTATUS cmd_samr_query_user(struct cli_state *cli,
goto done;
result = cli_samr_open_user(cli, mem_ctx, &domain_pol,
- MAXIMUM_ALLOWED_ACCESS,
+ access_mask,
user_rid, &user_pol);
if (!NT_STATUS_IS_OK(result))
@@ -354,16 +362,23 @@ static NTSTATUS cmd_samr_query_group(struct cli_state *cli,
POLICY_HND connect_pol, domain_pol, group_pol;
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
uint32 info_level = 1;
+ uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
GROUP_INFO_CTR group_ctr;
fstring server;
uint32 group_rid;
- if (argc != 2) {
- printf("Usage: %s rid\n", argv[0]);
+ if ((argc < 2) || (argc > 4)) {
+ printf("Usage: %s rid [info level] [access mask]\n", argv[0]);
return NT_STATUS_OK;
}
sscanf(argv[1], "%i", &group_rid);
+
+ if (argc > 2)
+ sscanf(argv[2], "%i", &info_level);
+
+ if (argc > 3)
+ sscanf(argv[3], "%x", &access_mask);
slprintf (server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
strupper (server);
@@ -382,7 +397,7 @@ static NTSTATUS cmd_samr_query_group(struct cli_state *cli,
goto done;
result = cli_samr_open_group(cli, mem_ctx, &domain_pol,
- MAXIMUM_ALLOWED_ACCESS,
+ access_mask,
group_rid, &group_pol);
if (!NT_STATUS_IS_OK(result))
@@ -414,45 +429,49 @@ static NTSTATUS cmd_samr_query_usergroups(struct cli_state *cli,
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
uint32 num_groups,
user_rid;
+ uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
DOM_GID *user_gids;
int i;
fstring server;
- if (argc != 2) {
- printf("Usage: %s rid\n", argv[0]);
+ if ((argc < 2) || (argc > 3)) {
+ printf("Usage: %s rid [access mask]\n", argv[0]);
return NT_STATUS_OK;
}
sscanf(argv[1], "%i", &user_rid);
+
+ if (argc > 2)
+ sscanf(argv[2], "%x", &access_mask);
slprintf (server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
strupper (server);
result = cli_samr_connect(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
&connect_pol);
- if (!NT_STATUS_IS_OK(result)) {
+
+ if (!NT_STATUS_IS_OK(result))
goto done;
- }
result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
MAXIMUM_ALLOWED_ACCESS,
&domain_sid, &domain_pol);
- if (!NT_STATUS_IS_OK(result)) {
+
+ if (!NT_STATUS_IS_OK(result))
goto done;
- }
result = cli_samr_open_user(cli, mem_ctx, &domain_pol,
- MAXIMUM_ALLOWED_ACCESS,
+ access_mask,
user_rid, &user_pol);
- if (!NT_STATUS_IS_OK(result)) {
+
+ if (!NT_STATUS_IS_OK(result))
goto done;
- }
result = cli_samr_query_usergroups(cli, mem_ctx, &user_pol,
&num_groups, &user_gids);
- if (!NT_STATUS_IS_OK(result)) {
+
+ if (!NT_STATUS_IS_OK(result))
goto done;
- }
for (i = 0; i < num_groups; i++) {
printf("\tgroup rid:[0x%x] attr:[0x%x]\n",
@@ -472,6 +491,7 @@ static NTSTATUS cmd_samr_query_useraliases(struct cli_state *cli,
POLICY_HND connect_pol, domain_pol;
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
uint32 user_rid, num_aliases, *alias_rids;
+ uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
int i;
fstring server;
DOM_SID tmp_sid;
@@ -480,45 +500,47 @@ static NTSTATUS cmd_samr_query_useraliases(struct cli_state *cli,
string_to_sid(&global_sid_Builtin, "S-1-5-32");
- if (argc != 3) {
- printf("Usage: %s builtin|domain rid\n", argv[0]);
+ if ((argc < 3) || (argc > 4)) {
+ printf("Usage: %s builtin|domain rid [access mask]\n", argv[0]);
return NT_STATUS_OK;
}
sscanf(argv[2], "%i", &user_rid);
+
+ if (argc > 3)
+ sscanf(argv[3], "%x", &access_mask);
slprintf (server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
strupper (server);
result = cli_samr_connect(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
&connect_pol);
- if (!NT_STATUS_IS_OK(result)) {
+
+ if (!NT_STATUS_IS_OK(result))
goto done;
- }
if (StrCaseCmp(argv[1], "domain")==0)
result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
- MAXIMUM_ALLOWED_ACCESS,
+ access_mask,
&domain_sid, &domain_pol);
else if (StrCaseCmp(argv[1], "builtin")==0)
result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
- MAXIMUM_ALLOWED_ACCESS,
+ access_mask,
&global_sid_Builtin, &domain_pol);
else
return NT_STATUS_OK;
- if (!NT_STATUS_IS_OK(result)) {
+ if (!NT_STATUS_IS_OK(result))
goto done;
- }
sid_copy(&tmp_sid, &domain_sid);
sid_append_rid(&tmp_sid, user_rid);
init_dom_sid2(&sid, &tmp_sid);
result = cli_samr_query_useraliases(cli, mem_ctx, &domain_pol, 1, &sid, &num_aliases, &alias_rids);
- if (!NT_STATUS_IS_OK(result)) {
+
+ if (!NT_STATUS_IS_OK(result))
goto done;
- }
for (i = 0; i < num_aliases; i++) {
printf("\tgroup rid:[0x%x]\n", alias_rids[i]);
@@ -537,45 +559,49 @@ static NTSTATUS cmd_samr_query_groupmem(struct cli_state *cli,
POLICY_HND connect_pol, domain_pol, group_pol;
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
uint32 num_members, *group_rids, *group_attrs, group_rid;
+ uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
int i;
fstring server;
- if (argc != 2) {
- printf("Usage: %s rid\n", argv[0]);
+ if ((argc < 2) || (argc > 3)) {
+ printf("Usage: %s rid [access mask]\n", argv[0]);
return NT_STATUS_OK;
}
sscanf(argv[1], "%i", &group_rid);
+
+ if (argc > 2)
+ sscanf(argv[2], "%x", &access_mask);
slprintf (server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
strupper (server);
result = cli_samr_connect(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
&connect_pol);
- if (!NT_STATUS_IS_OK(result)) {
+
+ if (!NT_STATUS_IS_OK(result))
goto done;
- }
result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
MAXIMUM_ALLOWED_ACCESS,
&domain_sid, &domain_pol);
- if (!NT_STATUS_IS_OK(result)) {
+
+ if (!NT_STATUS_IS_OK(result))
goto done;
- }
result = cli_samr_open_group(cli, mem_ctx, &domain_pol,
- MAXIMUM_ALLOWED_ACCESS,
+ access_mask,
group_rid, &group_pol);
- if (!NT_STATUS_IS_OK(result)) {
+
+ if (!NT_STATUS_IS_OK(result))
goto done;
- }
result = cli_samr_query_groupmem(cli, mem_ctx, &group_pol,
&num_members, &group_rids,
&group_attrs);
- if (!NT_STATUS_IS_OK(result)) {
+
+ if (!NT_STATUS_IS_OK(result))
goto done;
- }
for (i = 0; i < num_members; i++) {
printf("\trid:[0x%x] attr:[0x%x]\n", group_rids[i],
@@ -595,47 +621,71 @@ static NTSTATUS cmd_samr_enum_dom_groups(struct cli_state *cli,
POLICY_HND connect_pol, domain_pol;
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
uint32 start_idx, size, num_dom_groups, i;
+ uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
struct acct_info *dom_groups;
+ BOOL got_connect_pol = False, got_domain_pol = False;
- if (argc != 1) {
- printf("Usage: %s\n", argv[0]);
+ if ((argc < 1) || (argc > 2)) {
+ printf("Usage: %s [access_mask]\n", argv[0]);
return NT_STATUS_OK;
}
+
+ if (argc > 1)
+ sscanf(argv[1], "%x", &access_mask);
/* Get sam policy handle */
result = cli_samr_connect(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
&connect_pol);
- if (!NT_STATUS_IS_OK(result)) {
+
+ if (!NT_STATUS_IS_OK(result))
goto done;
- }
+
+ got_connect_pol = True;
/* Get domain policy handle */
+
result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
- MAXIMUM_ALLOWED_ACCESS,
+ access_mask,
&domain_sid, &domain_pol);
- if (!NT_STATUS_IS_OK(result)) {
+
+ if (!NT_STATUS_IS_OK(result))
goto done;
- }
+
+ got_domain_pol = True;
/* Enumerate domain groups */
start_idx = 0;
size = 0xffff;
- result = cli_samr_enum_dom_groups(cli, mem_ctx, &domain_pol,
- &start_idx, size,
- &dom_groups, &num_dom_groups);
+ do {
+ result = cli_samr_enum_dom_groups(
+ cli, mem_ctx, &domain_pol, &start_idx, size,
+ &dom_groups, &num_dom_groups);
+
+ if (NT_STATUS_IS_OK(result) ||
+ NT_STATUS_V(result) == NT_STATUS_V(STATUS_MORE_ENTRIES)) {
+
+ for (i = 0; i < num_dom_groups; i++)
+ printf("group:[%s] rid:[0x%x]\n",
+ dom_groups[i].acct_name,
+ dom_groups[i].rid);
+ }
- for (i = 0; i < num_dom_groups; i++)
- printf("group:[%s] rid:[0x%x]\n", dom_groups[i].acct_name,
- dom_groups[i].rid);
+ } while (NT_STATUS_V(result) == NT_STATUS_V(STATUS_MORE_ENTRIES));
done:
+ if (got_domain_pol)
+ cli_samr_close(cli, mem_ctx, &domain_pol);
+
+ if (got_connect_pol)
+ cli_samr_close(cli, mem_ctx, &connect_pol);
+
return result;
}
-/* Enumerate domain groups */
+/* Enumerate alias groups */
static NTSTATUS cmd_samr_enum_als_groups(struct cli_state *cli,
TALLOC_CTX *mem_ctx,
@@ -643,55 +693,77 @@ static NTSTATUS cmd_samr_enum_als_groups(struct cli_state *cli,
{
POLICY_HND connect_pol, domain_pol;
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
- uint32 start_idx, size, num_dom_groups, i;
- struct acct_info *dom_groups;
+ uint32 start_idx, size, num_als_groups, i;
+ uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
+ struct acct_info *als_groups;
DOM_SID global_sid_Builtin;
+ BOOL got_connect_pol = False, got_domain_pol = False;
string_to_sid(&global_sid_Builtin, "S-1-5-32");
- if (argc != 2) {
- printf("Usage: %s builtin|domain\n", argv[0]);
+ if ((argc < 2) || (argc > 3)) {
+ printf("Usage: %s builtin|domain [access mask]\n", argv[0]);
return NT_STATUS_OK;
}
+
+ if (argc > 2)
+ sscanf(argv[2], "%x", &access_mask);
/* Get sam policy handle */
result = cli_samr_connect(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
&connect_pol);
- if (!NT_STATUS_IS_OK(result)) {
+
+ if (!NT_STATUS_IS_OK(result))
goto done;
- }
+
+ got_connect_pol = True;
/* Get domain policy handle */
if (StrCaseCmp(argv[1], "domain")==0)
result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
- MAXIMUM_ALLOWED_ACCESS,
+ access_mask,
&domain_sid, &domain_pol);
else if (StrCaseCmp(argv[1], "builtin")==0)
result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
- MAXIMUM_ALLOWED_ACCESS,
+ access_mask,
&global_sid_Builtin, &domain_pol);
else
return NT_STATUS_OK;
- if (!NT_STATUS_IS_OK(result)) {
+
+ if (!NT_STATUS_IS_OK(result))
goto done;
- }
- /* Enumerate domain groups */
+ got_domain_pol = True;
+
+ /* Enumerate alias groups */
start_idx = 0;
- size = 0xffff;
+ size = 0xffff; /* Number of groups to retrieve */
- result = cli_samr_enum_als_groups(cli, mem_ctx, &domain_pol,
- &start_idx, size,
- &dom_groups, &num_dom_groups);
+ do {
+ result = cli_samr_enum_als_groups(
+ cli, mem_ctx, &domain_pol, &start_idx, size,
+ &als_groups, &num_als_groups);
- for (i = 0; i < num_dom_groups; i++)
- printf("group:[%s] rid:[0x%x]\n", dom_groups[i].acct_name,
- dom_groups[i].rid);
+ if (NT_STATUS_IS_OK(result) ||
+ NT_STATUS_V(result) == NT_STATUS_V(STATUS_MORE_ENTRIES)) {
+
+ for (i = 0; i < num_als_groups; i++)
+ printf("group:[%s] rid:[0x%x]\n",
+ als_groups[i].acct_name,
+ als_groups[i].rid);
+ }
+ } while (NT_STATUS_V(result) == NT_STATUS_V(STATUS_MORE_ENTRIES));
done:
+ if (got_domain_pol)
+ cli_samr_close(cli, mem_ctx, &domain_pol);
+
+ if (got_connect_pol)
+ cli_samr_close(cli, mem_ctx, &connect_pol);
+
return result;
}
@@ -704,46 +776,59 @@ static NTSTATUS cmd_samr_query_aliasmem(struct cli_state *cli,
POLICY_HND connect_pol, domain_pol, alias_pol;
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
uint32 alias_rid, num_members, i;
+ uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
DOM_SID *alias_sids;
+ DOM_SID global_sid_Builtin;
+
+ string_to_sid(&global_sid_Builtin, "S-1-5-32");
- if (argc != 2) {
- printf("Usage: %s rid\n", argv[0]);
+ if ((argc < 3) || (argc > 4)) {
+ printf("Usage: %s builtin|domain rid [access mask]\n", argv[0]);
return NT_STATUS_OK;
}
- sscanf(argv[1], "%i", &alias_rid);
+ sscanf(argv[2], "%i", &alias_rid);
+
+ if (argc > 3)
+ sscanf(argv[3], "%x", &access_mask);
/* Open SAMR handle */
result = cli_samr_connect(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
&connect_pol);
- if (!NT_STATUS_IS_OK(result)) {
+
+ if (!NT_STATUS_IS_OK(result))
goto done;
- }
/* Open handle on domain */
+
+ if (StrCaseCmp(argv[1], "domain")==0)
+ result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
+ MAXIMUM_ALLOWED_ACCESS,
+ &domain_sid, &domain_pol);
+ else if (StrCaseCmp(argv[1], "builtin")==0)
+ result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
+ MAXIMUM_ALLOWED_ACCESS,
+ &global_sid_Builtin, &domain_pol);
+ else
+ return NT_STATUS_OK;
- result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
- MAXIMUM_ALLOWED_ACCESS,
- &domain_sid, &domain_pol);
- if (!NT_STATUS_IS_OK(result)) {
+ if (!NT_STATUS_IS_OK(result))
goto done;
- }
/* Open handle on alias */
result = cli_samr_open_alias(cli, mem_ctx, &domain_pol,
- MAXIMUM_ALLOWED_ACCESS,
+ access_mask,
alias_rid, &alias_pol);
- if (!NT_STATUS_IS_OK(result)) {
+ if (!NT_STATUS_IS_OK(result))
goto done;
- }
result = cli_samr_query_aliasmem(cli, mem_ctx, &alias_pol,
&num_members, &alias_sids);
- if (!NT_STATUS_IS_OK(result)) {
+
+ if (!NT_STATUS_IS_OK(result))
goto done;
- }
for (i = 0; i < num_members; i++) {
fstring sid_str;
@@ -765,7 +850,8 @@ static NTSTATUS cmd_samr_query_dispinfo(struct cli_state *cli,
POLICY_HND connect_pol, domain_pol;
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
uint32 start_idx=0, max_entries=250, num_entries, i;
- int info_level = 1;
+ uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
+ uint32 info_level = 1;
SAM_DISPINFO_CTR ctr;
SAM_DISPINFO_1 info1;
SAM_DISPINFO_2 info2;
@@ -773,8 +859,8 @@ static NTSTATUS cmd_samr_query_dispinfo(struct cli_state *cli,
SAM_DISPINFO_4 info4;
SAM_DISPINFO_5 info5;
- if (argc > 4) {
- printf("Usage: %s [info level] [start index] [max entries]\n", argv[0]);
+ if (argc > 5) {
+ printf("Usage: %s [info level] [start index] [max entries] [access mask]\n", argv[0]);
return NT_STATUS_OK;
}
@@ -786,22 +872,25 @@ static NTSTATUS cmd_samr_query_dispinfo(struct cli_state *cli,
if (argc >= 4)
sscanf(argv[3], "%i", &max_entries);
+
+ if (argc >= 5)
+ sscanf(argv[4], "%x", &access_mask);
/* Get sam policy handle */
result = cli_samr_connect(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS, &connect_pol);
- if (!NT_STATUS_IS_OK(result)) {
+
+ if (!NT_STATUS_IS_OK(result))
goto done;
- }
/* Get domain policy handle */
result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
- MAXIMUM_ALLOWED_ACCESS,
+ access_mask,
&domain_sid, &domain_pol);
- if (!NT_STATUS_IS_OK(result)) {
+
+ if (!NT_STATUS_IS_OK(result))
goto done;
- }
/* Query display info */
@@ -832,11 +921,18 @@ static NTSTATUS cmd_samr_query_dispinfo(struct cli_state *cli,
}
- do {
+ while(1) {
+
result = cli_samr_query_dispinfo(cli, mem_ctx, &domain_pol,
&start_idx, info_level,
&num_entries, max_entries, &ctr);
+ if (!NT_STATUS_IS_OK(result) && !NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES))
+ break;
+
+ if (num_entries == 0)
+ break;
+
for (i = 0; i < num_entries; i++) {
switch (info_level) {
case 1:
@@ -856,7 +952,8 @@ static NTSTATUS cmd_samr_query_dispinfo(struct cli_state *cli,
break;
}
}
- } while (!NT_STATUS_IS_OK(result));
+ }
+
done:
return result;
}
@@ -869,45 +966,49 @@ static NTSTATUS cmd_samr_query_dominfo(struct cli_state *cli,
{
POLICY_HND connect_pol, domain_pol;
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
- int switch_value = 2;
+ uint32 switch_level = 2;
+ uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
SAM_UNK_CTR ctr;
if (argc > 2) {
- printf("Usage: %s [infolevel]\n", argv[0]);
+ printf("Usage: %s [info level] [access mask]\n", argv[0]);
return NT_STATUS_OK;
}
- if (argc == 2)
- sscanf(argv[1], "%i", &switch_value);
+ if (argc > 1)
+ sscanf(argv[1], "%i", &switch_level);
+
+ if (argc > 2)
+ sscanf(argv[2], "%x", &access_mask);
/* Get sam policy handle */
result = cli_samr_connect(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
&connect_pol);
- if (!NT_STATUS_IS_OK(result)) {
+
+ if (!NT_STATUS_IS_OK(result))
goto done;
- }
/* Get domain policy handle */
result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
- MAXIMUM_ALLOWED_ACCESS,
+ access_mask,
&domain_sid, &domain_pol);
- if (!NT_STATUS_IS_OK(result)) {
+
+ if (!NT_STATUS_IS_OK(result))
goto done;
- }
/* Query domain info */
result = cli_samr_query_dom_info(cli, mem_ctx, &domain_pol,
- switch_value, &ctr);
- if (!NT_STATUS_IS_OK(result)) {
+ switch_level, &ctr);
+
+ if (!NT_STATUS_IS_OK(result))
goto done;
- }
/* Display domain info */
- switch (switch_value) {
+ switch (switch_level) {
case 1:
display_sam_unk_info_1(&ctr.info.inf1);
break;
@@ -916,7 +1017,7 @@ static NTSTATUS cmd_samr_query_dominfo(struct cli_state *cli,
break;
default:
printf("cannot display domain info for switch value %d\n",
- switch_value);
+ switch_level);
break;
}
@@ -938,30 +1039,34 @@ static NTSTATUS cmd_samr_create_dom_user(struct cli_state *cli,
char *acct_name;
uint16 acb_info;
uint32 unknown, user_rid;
+ uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
- if (argc != 2) {
- printf("Usage: %s username\n", argv[0]);
+ if ((argc < 2) || (argc > 3)) {
+ printf("Usage: %s username [access mask]\n", argv[0]);
return NT_STATUS_OK;
}
acct_name = argv[1];
+
+ if (argc > 2)
+ sscanf(argv[2], "%x", &access_mask);
/* Get sam policy handle */
result = cli_samr_connect(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
&connect_pol);
- if (!NT_STATUS_IS_OK(result)) {
+
+ if (!NT_STATUS_IS_OK(result))
goto done;
- }
/* Get domain policy handle */
result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
- MAXIMUM_ALLOWED_ACCESS,
+ access_mask,
&domain_sid, &domain_pol);
- if (!NT_STATUS_IS_OK(result)) {
+
+ if (!NT_STATUS_IS_OK(result))
goto done;
- }
/* Create domain user */
@@ -971,9 +1076,9 @@ static NTSTATUS cmd_samr_create_dom_user(struct cli_state *cli,
result = cli_samr_create_dom_user(cli, mem_ctx, &domain_pol,
acct_name, acb_info, unknown,
&user_pol, &user_rid);
- if (!NT_STATUS_IS_OK(result)) {
+
+ if (!NT_STATUS_IS_OK(result))
goto done;
- }
done:
return result;
@@ -989,7 +1094,7 @@ static NTSTATUS cmd_samr_lookup_names(struct cli_state *cli,
POLICY_HND connect_pol, domain_pol;
uint32 flags = 0x000003e8; /* Unknown */
uint32 num_rids, num_names, *name_types, *rids;
- char **names;
+ const char **names;
int i;
DOM_SID global_sid_Builtin;
@@ -1007,9 +1112,8 @@ static NTSTATUS cmd_samr_lookup_names(struct cli_state *cli,
result = cli_samr_connect(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
&connect_pol);
- if (!NT_STATUS_IS_OK(result)) {
+ if (!NT_STATUS_IS_OK(result))
goto done;
- }
if (StrCaseCmp(argv[1], "domain")==0)
result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
@@ -1022,14 +1126,13 @@ static NTSTATUS cmd_samr_lookup_names(struct cli_state *cli,
else
return NT_STATUS_OK;
- if (!NT_STATUS_IS_OK(result)) {
+ if (!NT_STATUS_IS_OK(result))
goto done;
- }
/* Look up names */
num_names = argc - 2;
- names = (char **)talloc(mem_ctx, sizeof(char *) * num_names);
+ names = (const char **)talloc(mem_ctx, sizeof(char *) * num_names);
for (i = 0; i < argc - 2; i++)
names[i] = argv[i + 2];
@@ -1038,9 +1141,8 @@ static NTSTATUS cmd_samr_lookup_names(struct cli_state *cli,
flags, num_names, names,
&num_rids, &rids, &name_types);
- if (!NT_STATUS_IS_OK(result)) {
+ if (!NT_STATUS_IS_OK(result))
goto done;
- }
/* Display results */
@@ -1075,17 +1177,15 @@ static NTSTATUS cmd_samr_lookup_rids(struct cli_state *cli,
result = cli_samr_connect(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
&connect_pol);
- if (!NT_STATUS_IS_OK(result)) {
+ if (!NT_STATUS_IS_OK(result))
goto done;
- }
result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
MAXIMUM_ALLOWED_ACCESS,
&domain_sid, &domain_pol);
- if (!NT_STATUS_IS_OK(result)) {
+ if (!NT_STATUS_IS_OK(result))
goto done;
- }
/* Look up rids */
@@ -1099,9 +1199,8 @@ static NTSTATUS cmd_samr_lookup_rids(struct cli_state *cli,
flags, num_rids, rids,
&num_names, &names, &name_types);
- if (!NT_STATUS_IS_OK(result)) {
+ if (!NT_STATUS_IS_OK(result))
goto done;
- }
/* Display results */
@@ -1120,28 +1219,30 @@ static NTSTATUS cmd_samr_delete_dom_user(struct cli_state *cli,
{
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
POLICY_HND connect_pol, domain_pol, user_pol;
+ uint32 access_mask = MAXIMUM_ALLOWED_ACCESS;
- if (argc != 2) {
+ if ((argc < 2) || (argc > 3)) {
printf("Usage: %s username\n", argv[0]);
return NT_STATUS_OK;
}
+
+ if (argc > 2)
+ sscanf(argv[2], "%x", &access_mask);
/* Get sam policy and domain handles */
result = cli_samr_connect(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
&connect_pol);
- if (!NT_STATUS_IS_OK(result)) {
+ if (!NT_STATUS_IS_OK(result))
goto done;
- }
result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
MAXIMUM_ALLOWED_ACCESS,
&domain_sid, &domain_pol);
- if (!NT_STATUS_IS_OK(result)) {
+ if (!NT_STATUS_IS_OK(result))
goto done;
- }
/* Get handle on user */
@@ -1150,30 +1251,27 @@ static NTSTATUS cmd_samr_delete_dom_user(struct cli_state *cli,
uint32 flags = 0x000003e8; /* Unknown */
result = cli_samr_lookup_names(cli, mem_ctx, &domain_pol,
- flags, 1, &argv[1],
+ flags, 1, (const char **)&argv[1],
&num_rids, &user_rids,
&name_types);
- if (!NT_STATUS_IS_OK(result)) {
+ if (!NT_STATUS_IS_OK(result))
goto done;
- }
result = cli_samr_open_user(cli, mem_ctx, &domain_pol,
- MAXIMUM_ALLOWED_ACCESS,
+ access_mask,
user_rids[0], &user_pol);
- if (!NT_STATUS_IS_OK(result)) {
+ if (!NT_STATUS_IS_OK(result))
goto done;
- }
}
/* Delete user */
result = cli_samr_delete_dom_user(cli, mem_ctx, &user_pol);
- if (!NT_STATUS_IS_OK(result)) {
+ if (!NT_STATUS_IS_OK(result))
goto done;
- }
/* Display results */
@@ -1199,19 +1297,19 @@ static NTSTATUS cmd_samr_query_sec_obj(struct cli_state *cli,
ctx=talloc_init();
- if (argc > 2) {
+ if ((argc < 1) || (argc > 2)) {
printf("Usage: %s [rid|-d]\n", argv[0]);
printf("\tSpecify rid for security on user, -d for security on domain\n");
return NT_STATUS_OK;
}
- if (argc == 2) {
+ if (argc > 1) {
if (strcmp(argv[1], "-d") == 0)
domain = True;
else
sscanf(argv[1], "%i", &user_rid);
}
-
+
slprintf (server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
strupper (server);
result = cli_samr_connect(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
@@ -1261,6 +1359,30 @@ done:
return result;
}
+static NTSTATUS cmd_samr_get_dom_pwinfo(struct cli_state *cli,
+ TALLOC_CTX *mem_ctx,
+ int argc, char **argv)
+{
+ NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
+ uint16 unk_0, unk_1, unk_2;
+
+ if (argc != 1) {
+ printf("Usage: %s\n", argv[0]);
+ return NT_STATUS_OK;
+ }
+
+ result = cli_samr_get_dom_pwinfo(cli, mem_ctx, &unk_0, &unk_1, &unk_2);
+
+ if (NT_STATUS_IS_OK(result)) {
+ printf("unk_0 = 0x%08x\n", unk_0);
+ printf("unk_1 = 0x%08x\n", unk_1);
+ printf("unk_2 = 0x%08x\n", unk_2);
+ }
+
+ return result;
+}
+
+
/* List of commands exported by this module */
struct cmd_set samr_commands[] = {
@@ -1283,6 +1405,7 @@ struct cmd_set samr_commands[] = {
{ "samlookuprids", cmd_samr_lookup_rids, PIPE_SAMR, "Look up names", "" },
{ "deletedomuser", cmd_samr_delete_dom_user, PIPE_SAMR, "Delete domain user", "" },
{ "samquerysecobj", cmd_samr_query_sec_obj, PIPE_SAMR, "Query SAMR security object", "" },
+ { "getdompwinfo", cmd_samr_get_dom_pwinfo, PIPE_SAMR, "Retrieve domain password info", "" },
{ NULL }
};
diff --git a/source3/rpcclient/cmd_spoolss.c b/source3/rpcclient/cmd_spoolss.c
index 9c63ec17c0..47e3f123ba 100644
--- a/source3/rpcclient/cmd_spoolss.c
+++ b/source3/rpcclient/cmd_spoolss.c
@@ -1647,10 +1647,12 @@ static NTSTATUS cmd_spoolss_setprinterdata(struct cli_state *cli,
printf("%s\n", timestring(True));
printf("\tchange_id (before set)\t:[0x%x]\n", info->change_id);
-
/* Set the printer data */
- result = cli_spoolss_setprinterdata(cli, mem_ctx, &pol, argv[2], argv[3]);
+ result = cli_spoolss_setprinterdata(
+ cli, mem_ctx, &pol, argv[2], REG_SZ, argv[3],
+ strlen(argv[3]) + 1);
+
if (!W_ERROR_IS_OK(result)) {
printf ("Unable to set [%s=%s]!\n", argv[2], argv[3]);
goto done;
@@ -1776,10 +1778,10 @@ static NTSTATUS cmd_spoolss_enum_jobs(struct cli_state *cli,
for (i = 0; i < num_jobs; i++) {
switch(level) {
case 1:
- display_job_info_1(&ctr.job.job_info_1[i]);
+ display_job_info_1(ctr.job.job_info_1[i]);
break;
case 2:
- display_job_info_2(&ctr.job.job_info_2[i]);
+ display_job_info_2(ctr.job.job_info_2[i]);
break;
default:
d_printf("unknown info level %d\n", level);
diff --git a/source3/rpcclient/cmd_srvsvc.c b/source3/rpcclient/cmd_srvsvc.c
index 6fbd152dfb..43bfb25048 100644
--- a/source3/rpcclient/cmd_srvsvc.c
+++ b/source3/rpcclient/cmd_srvsvc.c
@@ -4,7 +4,7 @@
Copyright (C) Andrew Tridgell 1992-1999
Copyright (C) Luke Kenneth Casson Leighton 1996 - 1999
- Copyright (C) Tim Potter 2000
+ Copyright (C) Tim Potter 2000,2002
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -221,6 +221,132 @@ static NTSTATUS cmd_srvsvc_srv_query_info(struct cli_state *cli,
return result;
}
+static void display_share_info_1(SRV_SHARE_INFO_1 *info1)
+{
+ fstring netname = "", remark = "";
+
+ rpcstr_pull_unistr2_fstring(netname, &info1->info_1_str.uni_netname);
+ rpcstr_pull_unistr2_fstring(remark, &info1->info_1_str.uni_remark);
+
+ printf("netname: %s\n", netname);
+ printf("\tremark:\t%s\n", remark);
+}
+
+static void display_share_info_2(SRV_SHARE_INFO_2 *info2)
+{
+ fstring netname = "", remark = "", path = "", passwd = "";
+
+ rpcstr_pull_unistr2_fstring(netname, &info2->info_2_str.uni_netname);
+ rpcstr_pull_unistr2_fstring(remark, &info2->info_2_str.uni_remark);
+ rpcstr_pull_unistr2_fstring(path, &info2->info_2_str.uni_path);
+ rpcstr_pull_unistr2_fstring(passwd, &info2->info_2_str.uni_passwd);
+
+ printf("netname: %s\n", netname);
+ printf("\tremark:\t%s\n", remark);
+ printf("\tpath:\t%s\n", path);
+ printf("\tpassword:\t%s\n", passwd);
+}
+
+static NTSTATUS cmd_srvsvc_net_share_enum(struct cli_state *cli,
+ TALLOC_CTX *mem_ctx,
+ int argc, char **argv)
+{
+ uint32 info_level = 2;
+ SRV_SHARE_INFO_CTR ctr;
+ WERROR result;
+ ENUM_HND hnd;
+ uint32 preferred_len = 0xffffffff, i;
+
+ if (argc > 2) {
+ printf("Usage: %s [infolevel]\n", argv[0]);
+ return NT_STATUS_OK;
+ }
+
+ if (argc == 2)
+ info_level = atoi(argv[1]);
+
+ init_enum_hnd(&hnd, 0);
+
+ result = cli_srvsvc_net_share_enum(
+ cli, mem_ctx, info_level, &ctr, preferred_len, &hnd);
+
+ if (!W_ERROR_IS_OK(result))
+ goto done;
+
+ /* Display results */
+
+ switch (info_level) {
+ case 1:
+ for (i = 0; i < ctr.num_entries; i++)
+ display_share_info_1(&ctr.share.info1[i]);
+ break;
+ case 2:
+ for (i = 0; i < ctr.num_entries; i++)
+ display_share_info_2(&ctr.share.info2[i]);
+ break;
+ default:
+ printf("unsupported info level %d\n", info_level);
+ break;
+ }
+
+ done:
+ return W_ERROR_IS_OK(result) ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;
+}
+
+static NTSTATUS cmd_srvsvc_net_remote_tod(struct cli_state *cli,
+ TALLOC_CTX *mem_ctx,
+ int argc, char **argv)
+{
+ TIME_OF_DAY_INFO tod;
+ WERROR result;
+
+ if (argc > 1) {
+ printf("Usage: %s\n", argv[0]);
+ return NT_STATUS_OK;
+ }
+
+ result = cli_srvsvc_net_remote_tod(
+ cli, mem_ctx, cli->srv_name_slash, &tod);
+
+ if (!W_ERROR_IS_OK(result))
+ goto done;
+
+ done:
+ return W_ERROR_IS_OK(result) ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;
+}
+
+static NTSTATUS cmd_srvsvc_net_file_enum(struct cli_state *cli,
+ TALLOC_CTX *mem_ctx,
+ int argc, char **argv)
+{
+ uint32 info_level = 3;
+ SRV_FILE_INFO_CTR ctr;
+ WERROR result;
+ ENUM_HND hnd;
+ uint32 preferred_len = 0;
+
+ if (argc > 2) {
+ printf("Usage: %s [infolevel]\n", argv[0]);
+ return NT_STATUS_OK;
+ }
+
+ if (argc == 2)
+ info_level = atoi(argv[1]);
+
+ init_enum_hnd(&hnd, 0);
+
+ ZERO_STRUCT(ctr);
+
+ result = cli_srvsvc_net_file_enum(
+ cli, mem_ctx, info_level, NULL, &ctr, preferred_len, &hnd);
+
+ if (!W_ERROR_IS_OK(result))
+ goto done;
+
+ done:
+ return W_ERROR_IS_OK(result) ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;
+}
+
/* List of commands exported by this module */
struct cmd_set srvsvc_commands[] = {
@@ -228,6 +354,9 @@ struct cmd_set srvsvc_commands[] = {
{ "SRVSVC" },
{ "srvinfo", cmd_srvsvc_srv_query_info, PIPE_SRVSVC, "Server query info", "" },
+ { "netshareenum", cmd_srvsvc_net_share_enum, PIPE_SRVSVC, "Enumerate shares", "" },
+ { "netfileenum", cmd_srvsvc_net_file_enum, PIPE_SRVSVC, "Enumerate open files", "" },
+ { "netremotetod", cmd_srvsvc_net_remote_tod, PIPE_SRVSVC, "Fetch remote time of day", "" },
{ NULL }
};
diff --git a/source3/rpcclient/rpcclient.c b/source3/rpcclient/rpcclient.c
index 193c27e8a0..a62c3d8365 100644
--- a/source3/rpcclient/rpcclient.c
+++ b/source3/rpcclient/rpcclient.c
@@ -186,7 +186,7 @@ static void get_username (char *username)
/* Fetch the SID for this computer */
-void fetch_machine_sid(struct cli_state *cli)
+static void fetch_machine_sid(struct cli_state *cli)
{
POLICY_HND pol;
NTSTATUS result = NT_STATUS_OK;
@@ -199,7 +199,7 @@ void fetch_machine_sid(struct cli_state *cli)
if (!(mem_ctx=talloc_init()))
{
- DEBUG(0,("fetch_domain_sid: talloc_init returned NULL!\n"));
+ DEBUG(0,("fetch_machine_sid: talloc_init returned NULL!\n"));
goto error;
}
@@ -576,17 +576,18 @@ static NTSTATUS process_cmd(struct cli_state *cli, char *cmd)
/* Print usage information */
static void usage(void)
{
- printf("Usage: rpcclient server [options]\n");
+ printf("Usage: rpcclient [options] server\n");
- printf("\t-A or --authfile authfile file containing user credentials\n");
- printf("\t-c or --command \"command string\" execute semicolon separated cmds\n");
- printf("\t-d or --debug debuglevel set the debuglevel\n");
- printf("\t-l or --logfile logfile logfile to use instead of stdout\n");
+ printf("\t-A or --authfile authfile File containing user credentials\n");
+ printf("\t-c or --command \"command string\" Execute semicolon separated cmds\n");
+ printf("\t-d or --debug debuglevel Set the debuglevel\n");
+ printf("\t-l or --logfile logfile Logfile to use instead of stdout\n");
printf("\t-h or --help Print this help message.\n");
- printf("\t-N or --nopass don't ask for a password\n");
- printf("\t-s or --conf configfile specify an alternative config file\n");
- printf("\t-U or --user username set the network username\n");
- printf("\t-W or --workgroup domain set the domain name for user account\n");
+ printf("\t-N or --nopass Don't ask for a password\n");
+ printf("\t-s or --conf configfile Specify an alternative config file\n");
+ printf("\t-U or --user username Set the network username\n");
+ printf("\t-W or --workgroup domain Set the domain name for user account\n");
+ printf("\t-I or --dest-ip ip Specify destination IP address\n");
printf("\n");
}
@@ -594,24 +595,23 @@ static void usage(void)
int main(int argc, char *argv[])
{
- extern char *optarg;
- extern int optind;
extern pstring global_myname;
static int got_pass = 0;
BOOL interactive = True;
int opt;
int olddebug;
static char *cmdstr = "";
+ const char *server;
struct cli_state *cli;
fstring password="",
username="",
- domain="",
- server="";
+ domain="";
static char *opt_authfile=NULL,
*opt_username=NULL,
*opt_domain=NULL,
*opt_configfile=NULL,
- *opt_logfile=NULL;
+ *opt_logfile=NULL,
+ *opt_ipaddr=NULL;
static int opt_debuglevel;
pstring logfile;
struct cmd_set **cmd_set;
@@ -633,7 +633,8 @@ static void usage(void)
{"command", 'c', POPT_ARG_STRING, &cmdstr},
{"logfile", 'l', POPT_ARG_STRING, &opt_logfile, 'l'},
{"help", 'h', POPT_ARG_NONE, 0, 'h'},
- { 0, 0, 0, 0}
+ {"dest-ip", 'I', POPT_ARG_STRING, &opt_ipaddr, 'I'},
+ { NULL }
};
@@ -649,54 +650,53 @@ static void usage(void)
return 0;
}
- if (strncmp("//", argv[1], 2) == 0 || strncmp("\\\\", argv[1], 2) == 0)
- argv[1] += 2;
-
- pstrcpy(server, argv[1]);
-
- argv++;
- argc--;
-
- pc = poptGetContext(NULL, argc, (const char **) argv, long_options,
- POPT_CONTEXT_KEEP_FIRST);
+ pc = poptGetContext("rpcclient", argc, (const char **) argv,
+ long_options, 0);
while((opt = poptGetNextOpt(pc)) != -1) {
switch (opt) {
case 'A':
/* only get the username, password, and domain from the file */
- read_authfile (opt_authfile, username,
- password, domain);
+ read_authfile (opt_authfile, username, password, domain);
if (strlen (password))
got_pass = 1;
break;
-
+
case 'l':
slprintf(logfile, sizeof(logfile) - 1, "%s.client",
opt_logfile);
lp_set_logfile(logfile);
interactive = False;
- break;
-
+ break;
+
case 's':
pstrcpy(dyn_CONFIGFILE, opt_configfile);
break;
-
+
case 'd':
DEBUGLEVEL = opt_debuglevel;
break;
-
+
case 'U': {
char *lp;
+
pstrcpy(username,opt_username);
+
if ((lp=strchr_m(username,'%'))) {
*lp = 0;
pstrcpy(password,lp+1);
got_pass = 1;
- memset(strchr_m(opt_username,'%')+1,'X',strlen(password));
+ memset(strchr_m(opt_username,'%') + 1, 'X',
+ strlen(password));
}
break;
}
-
+ case 'I':
+ if (!inet_aton(opt_ipaddr, &server_ip)) {
+ fprintf(stderr, "%s not a valid IP address\n",
+ opt_ipaddr);
+ return 1;
+ }
case 'W':
pstrcpy(domain, opt_domain);
break;
@@ -708,6 +708,16 @@ static void usage(void)
}
}
+ /* Get server as remaining unparsed argument. Print usage if more
+ than one unparsed argument is present. */
+
+ server = poptGetArg(pc);
+
+ if (!server || poptGetArg(pc)) {
+ usage();
+ return 1;
+ }
+
poptFreeContext(pc);
/* the following functions are part of the Samba debugging
@@ -731,7 +741,7 @@ static void usage(void)
/* Resolve the IP address */
- if (!resolve_name(server, &server_ip, 0x20)) {
+ if (!opt_ipaddr && !resolve_name(server, &server_ip, 0x20)) {
DEBUG(1,("Unable to resolve %s\n", server));
return 1;
}
@@ -755,7 +765,7 @@ static void usage(void)
&server_ip, 0,
"IPC$", "IPC",
username, domain,
- password, strlen(password));
+ password, 0);
if (!NT_STATUS_IS_OK(nt_status)) {
DEBUG(1,("Cannot connect to server. Error was %s\n", nt_errstr(nt_status)));
diff --git a/source3/rpcclient/samsync.c b/source3/rpcclient/samsync.c
index 14f7ed8953..5b64cbc47d 100644
--- a/source3/rpcclient/samsync.c
+++ b/source3/rpcclient/samsync.c
@@ -396,51 +396,19 @@ static void usage(void)
printf("\n");
}
-/* Initialise client credentials for authenticated pipe access */
-
-void init_rpcclient_creds(struct ntuser_creds *creds, char* username,
- char* domain, char* password)
-{
- ZERO_STRUCTP(creds);
-
- if (lp_encrypted_passwords()) {
- pwd_make_lm_nt_16(&creds->pwd, password);
- } else {
- pwd_set_cleartext(&creds->pwd, password);
- }
-
- fstrcpy(creds->user_name, username);
- fstrcpy(creds->domain, domain);
-
- if (! *username) {
- creds->pwd.null_pwd = True;
- }
-}
-
/* Connect to primary domain controller */
-static struct cli_state *init_connection(struct cli_state *cli,
+static struct cli_state *init_connection(struct cli_state **cli,
char *username, char *domain,
char *password)
{
- struct ntuser_creds creds;
extern pstring global_myname;
struct in_addr *dest_ip;
- struct nmb_name calling, called;
int count;
fstring dest_host;
/* Initialise cli_state information */
- ZERO_STRUCTP(cli);
-
- if (!cli_initialise(cli)) {
- return NULL;
- }
-
- init_rpcclient_creds(&creds, username, domain, password);
- cli_init_creds(cli, &creds);
-
/* Look up name of PDC controller */
if (!get_dc_list(True, lp_workgroup(), &dest_ip, &count)) {
@@ -456,20 +424,15 @@ static struct cli_state *init_connection(struct cli_state *cli,
return NULL;
}
- get_myname((*global_myname)?NULL:global_myname);
- strupper(global_myname);
-
- make_nmb_name(&called, dns_to_netbios_name(dest_host), 0x20);
- make_nmb_name(&calling, dns_to_netbios_name(global_myname), 0);
-
- /* Establish a SMB connection */
-
- if (!cli_establish_connection(cli, dest_host, dest_ip, &calling,
- &called, "IPC$", "IPC", False, True)) {
+ if (NT_STATUS_IS_OK(cli_full_connection(cli, global_myname, dest_host,
+ dest_ip, 0,
+ "IPC$", "IPC",
+ username, domain,
+ password, 0))) {
+ return *cli;
+ } else {
return NULL;
}
-
- return cli;
}
/* Main function */
@@ -477,7 +440,7 @@ static struct cli_state *init_connection(struct cli_state *cli,
int main(int argc, char **argv)
{
BOOL do_sam_sync = False, do_sam_repl = False;
- struct cli_state cli;
+ struct cli_state *cli;
NTSTATUS result;
int opt;
pstring logfile;
@@ -605,10 +568,10 @@ static struct cli_state *init_connection(struct cli_state *cli,
return 1;
if (do_sam_sync)
- result = sam_sync(&cli, trust_passwd, do_smbpasswd_output, verbose);
+ result = sam_sync(cli, trust_passwd, do_smbpasswd_output, verbose);
if (do_sam_repl)
- result = sam_repl(&cli, trust_passwd, low_serial);
+ result = sam_repl(cli, trust_passwd, low_serial);
if (!NT_STATUS_IS_OK(result)) {
DEBUG(0, ("%s\n", nt_errstr(result)));