summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source3/include/proto.h4
-rw-r--r--source3/rpc_client/cli_samr.c53
-rw-r--r--source3/rpcclient/cmd_samr.c43
3 files changed, 55 insertions, 45 deletions
diff --git a/source3/include/proto.h b/source3/include/proto.h
index 50c6477d80..e83e0320de 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -1903,9 +1903,9 @@ BOOL samr_unknown_38(struct cli_state *cli, uint16 fnum, char *srv_name);
BOOL samr_query_dom_info(struct cli_state *cli, uint16 fnum,
POLICY_HND *domain_pol, uint16 switch_value,
SAM_UNK_CTR *ctr);
-BOOL samr_enum_dom_groups(struct cli_state *cli, uint16 fnum,
+uint32 samr_enum_dom_groups(struct cli_state *cli, uint16 fnum,
POLICY_HND *pol,
- uint32 start_idx, uint32 size,
+ uint32 *start_idx, uint32 size,
struct acct_info **sam,
uint32 *num_sam_groups);
BOOL samr_enum_dom_aliases(struct cli_state *cli, uint16 fnum,
diff --git a/source3/rpc_client/cli_samr.c b/source3/rpc_client/cli_samr.c
index a1faade6db..41bdd0e3d1 100644
--- a/source3/rpc_client/cli_samr.c
+++ b/source3/rpc_client/cli_samr.c
@@ -546,21 +546,24 @@ BOOL samr_query_dom_info(struct cli_state *cli, uint16 fnum,
/****************************************************************************
do a SAMR enumerate groups
****************************************************************************/
-BOOL samr_enum_dom_groups(struct cli_state *cli, uint16 fnum,
+uint32 samr_enum_dom_groups(struct cli_state *cli, uint16 fnum,
POLICY_HND *pol,
- uint32 start_idx, uint32 size,
+ uint32 *start_idx, uint32 size,
struct acct_info **sam,
uint32 *num_sam_groups)
{
+ uint32 status = 0x0;
prs_struct data;
prs_struct rdata;
SAMR_Q_ENUM_DOM_GROUPS q_e;
- BOOL valid_pol = False;
DEBUG(4,("SAMR Enum SAM DB max size:%x\n", size));
- if (pol == NULL || num_sam_groups == NULL) return False;
+ if (pol == NULL || num_sam_groups == NULL)
+ {
+ return NT_STATUS_INVALID_PARAMETER | 0xC0000000;
+ }
/* create and send a MSRPC command with api SAMR_ENUM_DOM_GROUPS */
@@ -568,7 +571,7 @@ BOOL samr_enum_dom_groups(struct cli_state *cli, uint16 fnum,
prs_init(&rdata, 0 , 4, SAFETY_MARGIN, True );
/* store the parameters */
- make_samr_q_enum_dom_groups(&q_e, pol, start_idx, size);
+ make_samr_q_enum_dom_groups(&q_e, pol, *start_idx, size);
/* turn parameters into data stream */
samr_io_q_enum_dom_groups("", &q_e, &data, 0);
@@ -581,40 +584,37 @@ BOOL samr_enum_dom_groups(struct cli_state *cli, uint16 fnum,
samr_io_r_enum_dom_groups("", &r_e, &rdata, 0);
+ status = r_e.status;
p = rdata.offset != 0;
if (p && r_e.status != 0)
{
/* report error code */
DEBUG(4,("SAMR_R_ENUM_DOM_GROUPS: %s\n", get_nt_error_msg(r_e.status)));
- p = False;
+ p = (r_e.status == STATUS_MORE_ENTRIES);
}
if (p)
{
- uint32 i;
- int name_idx = 0;
-
- *num_sam_groups = r_e.num_entries2;
- if (*num_sam_groups > MAX_SAM_ENTRIES)
- {
- *num_sam_groups = MAX_SAM_ENTRIES;
- DEBUG(2,("samr_enum_dom_groups: sam group entries limited to %d\n",
- *num_sam_groups));
- }
+ uint32 i = (*num_sam_groups);
+ uint32 j = 0;
+ uint32 name_idx = 0;
- *sam = (struct acct_info*) malloc(sizeof(struct acct_info) * (*num_sam_groups));
+ (*num_sam_groups) += r_e.num_entries2;
+ (*sam) = (struct acct_info*) Realloc((*sam),
+ sizeof(struct acct_info) * (*num_sam_groups));
if ((*sam) == NULL)
{
- *num_sam_groups = 0;
+ (*num_sam_groups) = 0;
+ i = 0;
}
- for (i = 0; i < *num_sam_groups; i++)
+ for (j = 0; i < (*num_sam_groups) && j < r_e.num_entries2; j++, i++)
{
- (*sam)[i].rid = r_e.sam[i].rid;
+ (*sam)[i].rid = r_e.sam[j].rid;
(*sam)[i].acct_name[0] = 0;
(*sam)[i].acct_desc[0] = 0;
- if (r_e.sam[i].hdr_name.buffer)
+ if (r_e.sam[j].hdr_name.buffer)
{
unistr2_to_ascii((*sam)[i].acct_name, &r_e.uni_grp_name[name_idx], sizeof((*sam)[i].acct_name)-1);
name_idx++;
@@ -622,14 +622,19 @@ BOOL samr_enum_dom_groups(struct cli_state *cli, uint16 fnum,
DEBUG(5,("samr_enum_dom_groups: idx: %4d rid: %8x acct: %s\n",
i, (*sam)[i].rid, (*sam)[i].acct_name));
}
- valid_pol = True;
+ (*start_idx) = r_e.next_idx;
+ }
+ else if (status == 0x0)
+ {
+ status = NT_STATUS_INVALID_PARAMETER | 0xC0000000;
}
+
}
prs_mem_free(&data );
prs_mem_free(&rdata );
- return valid_pol;
+ return status;
}
/****************************************************************************
@@ -735,7 +740,6 @@ uint32 samr_enum_dom_users(struct cli_state *cli, uint16 fnum,
prs_struct rdata;
SAMR_Q_ENUM_DOM_USERS q_e;
- BOOL valid_pol = False;
DEBUG(4,("SAMR Enum SAM DB max size:%x\n", size));
@@ -803,7 +807,6 @@ uint32 samr_enum_dom_users(struct cli_state *cli, uint16 fnum,
DEBUG(5,("samr_enum_dom_users: idx: %4d rid: %8x acct: %s\n",
i, (*sam)[i].rid, (*sam)[i].acct_name));
}
- valid_pol = True;
(*start_idx) = r_e.next_idx;
}
else if (status == 0x0)
diff --git a/source3/rpcclient/cmd_samr.c b/source3/rpcclient/cmd_samr.c
index c1c09948e7..f0ce84e3ef 100644
--- a/source3/rpcclient/cmd_samr.c
+++ b/source3/rpcclient/cmd_samr.c
@@ -1397,7 +1397,7 @@ int msrpc_sam_enum_users(struct client_info *info,
uint16 acb_mask = 0;
uint16 unk_1 = 0x0;
uint32 ace_perms = 0x304; /* access control permissions */
- uint32 status = STATUS_MORE_ENTRIES;
+ uint32 status;
POLICY_HND sam_pol;
POLICY_HND pol_dom;
POLICY_HND pol_blt;
@@ -1450,13 +1450,14 @@ int msrpc_sam_enum_users(struct client_info *info,
if (res1)
{
/* read some users */
- while (status == STATUS_MORE_ENTRIES)
+ do
{
status = samr_enum_dom_users(smb_cli, fnum,
&pol_dom,
- &start_idx, acb_mask, unk_1, 0x10000,
+ &start_idx, acb_mask, unk_1, 0x100000,
sam, num_sam_entries);
- }
+
+ } while (status == STATUS_MORE_ENTRIES);
if ((*num_sam_entries) == 0)
{
@@ -2137,9 +2138,9 @@ uint32 msrpc_sam_enum_groups(struct client_info *info,
DOM_SID sid1;
BOOL res = True;
uint32 ace_perms = 0x02000000; /* access control permissions. */
- uint32 group_idx;
POLICY_HND sam_pol;
POLICY_HND pol_dom;
+ uint32 status;
sid_copy(&sid1, &info->dom.level5_sid);
@@ -2175,19 +2176,25 @@ uint32 msrpc_sam_enum_groups(struct client_info *info,
(*sam) = NULL;
- /* read some groups */
- res = res ? samr_enum_dom_groups(smb_cli, fnum,
- &pol_dom,
- 0x0, 0x100000,
- sam, num_sam_entries) : False;
-
- if (res && (*num_sam_entries) == 0)
- {
- report(out_hnd, "No groups\n");
- }
-
if (res)
{
+ uint32 group_idx;
+ uint32 start_idx = 0;
+ /* read some groups */
+ do
+ {
+ status = samr_enum_dom_groups(smb_cli, fnum,
+ &pol_dom,
+ &start_idx, 0x100000,
+ sam, num_sam_entries);
+
+ } while (status == STATUS_MORE_ENTRIES);
+
+ if ((*num_sam_entries) == 0)
+ {
+ report(out_hnd, "No groups\n");
+ }
+
for (group_idx = 0; group_idx < (*num_sam_entries); group_idx++)
{
uint32 group_rid = (*sam)[group_idx].rid;
@@ -2236,8 +2243,8 @@ void cmd_sam_enum_groups(struct client_info *info)
BOOL request_group_info = False;
fstring tmp;
int i;
- struct acct_info *sam;
- uint32 num_sam_entries;
+ struct acct_info *sam = NULL;
+ uint32 num_sam_entries = 0;
for (i = 0; i < 3; i++)
{