summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source3/include/proto.h28
-rw-r--r--source3/include/rpc_samr.h4
-rw-r--r--source3/lib/util.c16
-rw-r--r--source3/rpc_client/cli_lsarpc.c2
-rw-r--r--source3/rpc_client/cli_samr.c40
-rw-r--r--source3/rpc_parse/parse_lsa.c2
-rw-r--r--source3/rpc_parse/parse_samr.c120
-rw-r--r--source3/rpcclient/cmd_samr.c191
-rw-r--r--source3/rpcclient/display.c2
9 files changed, 274 insertions, 131 deletions
diff --git a/source3/include/proto.h b/source3/include/proto.h
index 0021367ae0..a142f3e4b5 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -485,6 +485,7 @@ int set_maxfiles(int requested_max);
void reg_get_subkey(char *full_keyname, char *key_name, char *subkey_name);
BOOL reg_split_key(char *full_keyname, uint32 *reg_type, char *key_name);
BOOL become_user_permanently(uid_t uid, gid_t gid);
+void free_char_array(uint32 num_entries, char **entries);
/*The following definitions come from lib/util_file.c */
@@ -1747,7 +1748,7 @@ BOOL lsa_query_secret(struct cli_state *cli, uint16 fnum,
BOOL lsa_lookup_names(struct cli_state *cli, uint16 fnum,
POLICY_HND *hnd,
int num_names,
- const char **names,
+ char **names,
DOM_SID **sids,
uint8 **types,
int *num_sids);
@@ -1865,7 +1866,7 @@ BOOL create_samr_domain_group(struct cli_state *cli, uint16 fnum,
uint32 *rid);
BOOL get_samr_query_usergroups(struct cli_state *cli, uint16 fnum,
POLICY_HND *pol_open_domain, uint32 user_rid,
- uint32 *num_groups, DOM_GID *gid);
+ uint32 *num_groups, DOM_GID **gid);
BOOL delete_samr_dom_group(struct cli_state *cli, uint16 fnum,
POLICY_HND *pol_open_domain,
uint32 group_rid);
@@ -1958,7 +1959,7 @@ BOOL samr_query_lookup_domain(struct cli_state *cli, uint16 fnum,
DOM_SID *dom_sid);
BOOL samr_query_lookup_names(struct cli_state *cli, uint16 fnum,
POLICY_HND *pol, uint32 flags,
- uint32 num_names, const char **names,
+ uint32 num_names, char **names,
uint32 *num_rids,
uint32 rid[MAX_LOOKUP_SIDS],
uint32 type[MAX_LOOKUP_SIDS]);
@@ -1966,19 +1967,20 @@ BOOL samr_query_lookup_rids(struct cli_state *cli, uint16 fnum,
POLICY_HND *pol, uint32 flags,
uint32 num_rids, uint32 *rids,
uint32 *num_names,
- fstring names[MAX_LOOKUP_SIDS],
- uint32 type [MAX_LOOKUP_SIDS]);
+ char ***names,
+ uint32 **type);
BOOL samr_query_aliasmem(struct cli_state *cli, uint16 fnum,
POLICY_HND *alias_pol,
uint32 *num_mem, DOM_SID2 *sid);
BOOL samr_query_useraliases(struct cli_state *cli, uint16 fnum,
- POLICY_HND *pol, DOM_SID *sid,
- uint32 *num_aliases, uint32 *rid);
+ POLICY_HND *pol, uint32 *ptr_sid, DOM_SID2 *sid,
+ uint32 *num_aliases, uint32 **rid);
BOOL samr_query_groupmem(struct cli_state *cli, uint16 fnum,
POLICY_HND *group_pol,
uint32 *num_mem, uint32 *rid, uint32 *attr);
BOOL samr_query_usergroups(struct cli_state *cli, uint16 fnum,
- POLICY_HND *pol, uint32 *num_groups, DOM_GID *gid);
+ POLICY_HND *pol, uint32 *num_groups,
+ DOM_GID **gid);
BOOL samr_query_groupinfo(struct cli_state *cli, uint16 fnum,
POLICY_HND *pol,
uint16 switch_value, GROUP_INFO_CTR* ctr);
@@ -2123,7 +2125,7 @@ BOOL make_q_lookup_sids(LSA_Q_LOOKUP_SIDS *q_l, POLICY_HND *hnd,
BOOL lsa_io_q_lookup_sids(char *desc, LSA_Q_LOOKUP_SIDS *q_s, prs_struct *ps, int depth);
BOOL lsa_io_r_lookup_sids(char *desc, LSA_R_LOOKUP_SIDS *r_s, prs_struct *ps, int depth);
BOOL make_q_lookup_names(LSA_Q_LOOKUP_NAMES *q_l, POLICY_HND *hnd,
- int num_names, const char **names);
+ int num_names, char **names);
BOOL lsa_io_q_lookup_names(char *desc, LSA_Q_LOOKUP_NAMES *q_r, prs_struct *ps, int depth);
BOOL lsa_io_r_lookup_names(char *desc, LSA_R_LOOKUP_NAMES *r_r, prs_struct *ps, int depth);
BOOL make_lsa_q_close(LSA_Q_CLOSE *q_c, POLICY_HND *hnd);
@@ -2617,11 +2619,13 @@ BOOL samr_io_q_set_aliasinfo(char *desc, SAMR_Q_SET_ALIASINFO *q_u, prs_struct
BOOL samr_io_r_set_aliasinfo(char *desc, SAMR_R_SET_ALIASINFO *r_u, prs_struct *ps, int depth);
BOOL make_samr_q_query_useraliases(SAMR_Q_QUERY_USERALIASES *q_u,
POLICY_HND *hnd,
- DOM_SID *sid);
+ uint32 *ptr_sid, DOM_SID2 *sid);
BOOL samr_io_q_query_useraliases(char *desc, SAMR_Q_QUERY_USERALIASES *q_u, prs_struct *ps, int depth);
+void samr_free_q_query_useraliases(SAMR_Q_QUERY_USERALIASES *q_u);
BOOL make_samr_r_query_useraliases(SAMR_R_QUERY_USERALIASES *r_u,
uint32 num_rids, uint32 *rid, uint32 status);
BOOL samr_io_r_query_useraliases(char *desc, SAMR_R_QUERY_USERALIASES *r_u, prs_struct *ps, int depth);
+void samr_free_r_query_useraliases(SAMR_R_QUERY_USERALIASES *r_u);
BOOL make_samr_q_open_alias(SAMR_Q_OPEN_ALIAS *q_u, POLICY_HND *pol,
uint32 unknown_0, uint32 rid);
BOOL samr_io_q_open_alias(char *desc, SAMR_Q_OPEN_ALIAS *q_u, prs_struct *ps, int depth);
@@ -2664,7 +2668,7 @@ BOOL make_samr_r_query_aliasmem(SAMR_R_QUERY_ALIASMEM *r_u,
BOOL samr_io_r_query_aliasmem(char *desc, SAMR_R_QUERY_ALIASMEM *r_u, prs_struct *ps, int depth);
BOOL make_samr_q_lookup_names(SAMR_Q_LOOKUP_NAMES *q_u,
POLICY_HND *pol, uint32 flags,
- uint32 num_names, const char **name);
+ uint32 num_names, char **name);
BOOL samr_io_q_lookup_names(char *desc, SAMR_Q_LOOKUP_NAMES *q_u, prs_struct *ps, int depth);
BOOL make_samr_r_lookup_names(SAMR_R_LOOKUP_NAMES *r_u,
uint32 num_rids, uint32 *rid, uint8 *type, uint32 status);
@@ -3292,7 +3296,7 @@ void display_alias_rid_info(FILE *out_hnd, enum action_type action,
DOM_SID *sid,
uint32 num_rids, uint32 *rid);
void display_group_members(FILE *out_hnd, enum action_type action,
- uint32 num_mem, fstring *name, uint32 *type);
+ uint32 num_mem, char **name, uint32 *type);
void display_group_info1(FILE *out_hnd, enum action_type action, GROUP_INFO1 *info1);
void display_group_rid_info(FILE *out_hnd, enum action_type action,
uint32 num_gids, DOM_GID *gid);
diff --git a/source3/include/rpc_samr.h b/source3/include/rpc_samr.h
index cb66081696..0d55e40bc0 100644
--- a/source3/include/rpc_samr.h
+++ b/source3/include/rpc_samr.h
@@ -1193,8 +1193,8 @@ typedef struct q_samr_query_useraliases_info
uint32 ptr; /* buffer pointer */
uint32 num_sids2; /* number of rids being looked up */
- uint32 ptr_sid[MAX_LOOKUP_SIDS]; /* pointers to sids to be looked up */
- DOM_SID2 sid [MAX_LOOKUP_SIDS]; /* sids to be looked up. */
+ uint32 *ptr_sid; /* pointers to sids to be looked up */
+ DOM_SID2 *sid ; /* sids to be looked up. */
} SAMR_Q_QUERY_USERALIASES;
diff --git a/source3/lib/util.c b/source3/lib/util.c
index 9a4d0d9e25..8afa2f8c01 100644
--- a/source3/lib/util.c
+++ b/source3/lib/util.c
@@ -3219,3 +3219,19 @@ BOOL become_user_permanently(uid_t uid, gid_t gid)
return(True);
}
+
+void free_char_array(uint32 num_entries, char **entries)
+{
+ uint32 i;
+ if (entries != NULL)
+ {
+ for (i = 0; i < num_entries; i++)
+ {
+ if (entries[i] != NULL)
+ {
+ free(entries[i]);
+ }
+ }
+ free(entries);
+ }
+}
diff --git a/source3/rpc_client/cli_lsarpc.c b/source3/rpc_client/cli_lsarpc.c
index 002e98572d..0c65231cef 100644
--- a/source3/rpc_client/cli_lsarpc.c
+++ b/source3/rpc_client/cli_lsarpc.c
@@ -219,7 +219,7 @@ do a LSA Lookup Names
BOOL lsa_lookup_names(struct cli_state *cli, uint16 fnum,
POLICY_HND *hnd,
int num_names,
- const char **names,
+ char **names,
DOM_SID **sids,
uint8 **types,
int *num_sids)
diff --git a/source3/rpc_client/cli_samr.c b/source3/rpc_client/cli_samr.c
index 2272aa7cb8..c19a01d213 100644
--- a/source3/rpc_client/cli_samr.c
+++ b/source3/rpc_client/cli_samr.c
@@ -149,7 +149,7 @@ do a SAMR query user groups
****************************************************************************/
BOOL get_samr_query_usergroups(struct cli_state *cli, uint16 fnum,
POLICY_HND *pol_open_domain, uint32 user_rid,
- uint32 *num_groups, DOM_GID *gid)
+ uint32 *num_groups, DOM_GID **gid)
{
POLICY_HND pol_open_user;
BOOL ret = True;
@@ -1839,7 +1839,7 @@ do a SAMR Query Lookup Names
****************************************************************************/
BOOL samr_query_lookup_names(struct cli_state *cli, uint16 fnum,
POLICY_HND *pol, uint32 flags,
- uint32 num_names, const char **names,
+ uint32 num_names, char **names,
uint32 *num_rids,
uint32 rid[MAX_LOOKUP_SIDS],
uint32 type[MAX_LOOKUP_SIDS])
@@ -1926,8 +1926,8 @@ BOOL samr_query_lookup_rids(struct cli_state *cli, uint16 fnum,
POLICY_HND *pol, uint32 flags,
uint32 num_rids, uint32 *rids,
uint32 *num_names,
- fstring names[MAX_LOOKUP_SIDS],
- uint32 type [MAX_LOOKUP_SIDS])
+ char ***names,
+ uint32 **type)
{
prs_struct data;
prs_struct rdata;
@@ -1978,19 +1978,26 @@ BOOL samr_query_lookup_rids(struct cli_state *cli, uint16 fnum,
valid_query = True;
*num_names = r_o.num_names1;
- for (i = 0; i < r_o.num_names1; i++)
+ (*names) = malloc((*num_names) * sizeof(**names));
+ for (i = 0; (*names) != NULL && i < r_o.num_names1; i++)
{
- unistr2_to_ascii(names[i], &r_o.uni_name[i], sizeof(fstring)-1);
+ fstring tmp;
+ unistr2_to_ascii(tmp, &r_o.uni_name[i], sizeof(tmp)-1);
+ (*names)[i] = strdup(tmp);
}
- for (i = 0; i < r_o.num_types1; i++)
+
+ (*type) = malloc((*num_names) * sizeof(**type));
+ for (i = 0; (*type) != NULL && i < r_o.num_types1; i++)
{
- type[i] = r_o.type[i];
+ (*type)[i] = r_o.type[i];
}
}
else if (r_o.ptr_names == 0 && r_o.ptr_types == 0)
{
valid_query = True;
*num_names = 0;
+ *names = NULL;
+ *type = NULL;
}
else
{
@@ -2072,14 +2079,15 @@ BOOL samr_query_aliasmem(struct cli_state *cli, uint16 fnum,
do a SAMR Query User Aliases
****************************************************************************/
BOOL samr_query_useraliases(struct cli_state *cli, uint16 fnum,
- POLICY_HND *pol, DOM_SID *sid,
- uint32 *num_aliases, uint32 *rid)
+ POLICY_HND *pol, uint32 *ptr_sid, DOM_SID2 *sid,
+ uint32 *num_aliases, uint32 **rid)
{
prs_struct data;
prs_struct rdata;
SAMR_Q_QUERY_USERALIASES q_o;
BOOL valid_query = False;
+ ZERO_STRUCT(q_o);
DEBUG(4,("SAMR Query User Aliases.\n"));
@@ -2091,7 +2099,7 @@ BOOL samr_query_useraliases(struct cli_state *cli, uint16 fnum,
prs_init(&rdata, 0 , 4, SAFETY_MARGIN, True );
/* store the parameters */
- make_samr_q_query_useraliases(&q_o, pol, sid);
+ make_samr_q_query_useraliases(&q_o, pol, ptr_sid, sid);
/* turn parameters into data stream */
samr_io_q_query_useraliases("", &q_o, &data, 0);
@@ -2102,10 +2110,10 @@ BOOL samr_query_useraliases(struct cli_state *cli, uint16 fnum,
SAMR_R_QUERY_USERALIASES r_o;
BOOL p;
- /* get user info */
- r_o.rid = rid;
+ r_o.rid = NULL;
samr_io_r_query_useraliases("", &r_o, &rdata, 0);
+ *rid = r_o.rid;
p = rdata.offset != 0;
if (p && r_o.status != 0)
@@ -2197,7 +2205,8 @@ BOOL samr_query_groupmem(struct cli_state *cli, uint16 fnum,
do a SAMR Query User Groups
****************************************************************************/
BOOL samr_query_usergroups(struct cli_state *cli, uint16 fnum,
- POLICY_HND *pol, uint32 *num_groups, DOM_GID *gid)
+ POLICY_HND *pol, uint32 *num_groups,
+ DOM_GID **gid)
{
prs_struct data;
prs_struct rdata;
@@ -2227,9 +2236,10 @@ BOOL samr_query_usergroups(struct cli_state *cli, uint16 fnum,
BOOL p;
/* get user info */
- r_o.gid = gid;
+ r_o.gid = NULL;
samr_io_r_query_usergroups("", &r_o, &rdata, 0);
+ *gid = r_o.gid;
p = rdata.offset != 0;
if (p && r_o.status != 0)
diff --git a/source3/rpc_parse/parse_lsa.c b/source3/rpc_parse/parse_lsa.c
index 1f194aa874..4053da0721 100644
--- a/source3/rpc_parse/parse_lsa.c
+++ b/source3/rpc_parse/parse_lsa.c
@@ -906,7 +906,7 @@ BOOL lsa_io_r_lookup_sids(char *desc, LSA_R_LOOKUP_SIDS *r_s, prs_struct *ps, i
makes a structure.
********************************************************************/
BOOL make_q_lookup_names(LSA_Q_LOOKUP_NAMES *q_l, POLICY_HND *hnd,
- int num_names, const char **names)
+ int num_names, char **names)
{
int i;
if (q_l == NULL) return False;
diff --git a/source3/rpc_parse/parse_samr.c b/source3/rpc_parse/parse_samr.c
index f0c16469c5..9b5ed1d294 100644
--- a/source3/rpc_parse/parse_samr.c
+++ b/source3/rpc_parse/parse_samr.c
@@ -2689,6 +2689,12 @@ BOOL samr_io_r_query_usergroups(char *desc, SAMR_R_QUERY_USERGROUPS *r_u, prs_s
{
prs_uint32("num_entries2", ps, depth, &(r_u->num_entries2));
+ r_u->gid = malloc(r_u->num_entries2 * sizeof(r_u->gid[0]));
+ if (r_u->gid == NULL)
+ {
+ return False;
+ }
+
for (i = 0; i < r_u->num_entries2; i++)
{
prs_grow(ps);
@@ -3193,7 +3199,7 @@ makes a SAMR_Q_QUERY_USERALIASES structure.
********************************************************************/
BOOL make_samr_q_query_useraliases(SAMR_Q_QUERY_USERALIASES *q_u,
POLICY_HND *hnd,
- DOM_SID *sid)
+ uint32 *ptr_sid, DOM_SID2 *sid)
{
if (q_u == NULL || hnd == NULL) return False;
@@ -3205,10 +3211,8 @@ BOOL make_samr_q_query_useraliases(SAMR_Q_QUERY_USERALIASES *q_u,
q_u->ptr = 1;
q_u->num_sids2 = 1;
- {
- q_u->ptr_sid[0] = 1;
- make_dom_sid2(&q_u->sid[0], sid);
- }
+ q_u->ptr_sid = ptr_sid;
+ q_u->sid = sid;
return True;
}
@@ -3235,7 +3239,24 @@ BOOL samr_io_q_query_useraliases(char *desc, SAMR_Q_QUERY_USERALIASES *q_u, prs
prs_uint32("ptr ", ps, depth, &(q_u->ptr ));
prs_uint32("num_sids2", ps, depth, &(q_u->num_sids2));
- SMB_ASSERT_ARRAY(q_u->ptr_sid, q_u->num_sids2);
+ if (q_u->num_sids2 != 0)
+ {
+ q_u->ptr_sid = Realloc(q_u->ptr_sid, sizeof(q_u->ptr_sid[0]) *
+ q_u->num_sids2);
+ if (q_u->ptr_sid == NULL)
+ {
+ samr_free_q_query_useraliases(q_u);
+ return False;
+ }
+
+ q_u->sid = Realloc(q_u->sid,
+ sizeof(q_u->sid[0]) * q_u->num_sids2);
+ if (q_u->sid == NULL)
+ {
+ samr_free_q_query_useraliases(q_u);
+ return False;
+ }
+ }
for (i = 0; i < q_u->num_sids2; i++)
{
@@ -3255,9 +3276,31 @@ BOOL samr_io_q_query_useraliases(char *desc, SAMR_Q_QUERY_USERALIASES *q_u, prs
prs_align(ps);
+ if (!ps->io)
+ {
+ /* storing. memory no longer needed */
+ samr_free_q_query_useraliases(q_u);
+ }
return True;
}
+/*******************************************************************
+frees memory in a SAMR_Q_QUERY_USERALIASES structure.
+********************************************************************/
+void samr_free_q_query_useraliases(SAMR_Q_QUERY_USERALIASES *q_u)
+{
+ if (q_u->ptr_sid == NULL)
+ {
+ free(q_u->ptr_sid);
+ q_u->ptr_sid = NULL;
+ }
+
+ if (q_u->sid == NULL)
+ {
+ free(q_u->sid);
+ q_u->sid = NULL;
+ }
+}
/*******************************************************************
makes a SAMR_R_QUERY_USERALIASES structure.
@@ -3309,6 +3352,14 @@ BOOL samr_io_r_query_useraliases(char *desc, SAMR_R_QUERY_USERALIASES *r_u, prs
if (r_u->num_entries != 0)
{
+ r_u->rid = Realloc(r_u->rid,
+ sizeof(r_u->rid[0]) * r_u->num_entries);
+ if (r_u->rid == NULL)
+ {
+ samr_free_r_query_useraliases(r_u);
+ return False;
+ }
+
for (i = 0; i < r_u->num_entries2; i++)
{
slprintf(tmp, sizeof(tmp)-1, "rid[%02d]", i);
@@ -3318,10 +3369,27 @@ BOOL samr_io_r_query_useraliases(char *desc, SAMR_R_QUERY_USERALIASES *r_u, prs
prs_uint32("status", ps, depth, &(r_u->status));
+ if (!ps->io)
+ {
+ /* storing. memory no longer needed */
+ samr_free_r_query_useraliases(r_u);
+ }
return True;
}
/*******************************************************************
+frees memory in a SAMR_R_QUERY_USERALIASES structure.
+********************************************************************/
+void samr_free_r_query_useraliases(SAMR_R_QUERY_USERALIASES *r_u)
+{
+ if (r_u->rid == NULL)
+ {
+ free(r_u->rid);
+ r_u->rid = NULL;
+ }
+}
+
+/*******************************************************************
makes a SAMR_Q_OPEN_ALIAS structure.
********************************************************************/
BOOL make_samr_q_open_alias(SAMR_Q_OPEN_ALIAS *q_u, POLICY_HND *pol,
@@ -3426,8 +3494,6 @@ BOOL samr_io_q_lookup_rids(char *desc, SAMR_Q_LOOKUP_RIDS *q_u, prs_struct *ps,
prs_uint32("ptr ", ps, depth, &(q_u->ptr ));
prs_uint32("num_rids2", ps, depth, &(q_u->num_rids2));
- SMB_ASSERT_ARRAY(q_u->rid, q_u->num_rids2);
-
for (i = 0; i < q_u->num_rids2; i++)
{
prs_grow(ps);
@@ -3463,26 +3529,28 @@ BOOL make_samr_r_lookup_rids(SAMR_R_LOOKUP_RIDS *r_u,
r_u->ptr_types = 1;
r_u->num_types2 = num_names;
- r_u->hdr_name = malloc(num_names * sizeof(r_u->hdr_name[0]));
- if (r_u->hdr_name == NULL)
- {
- return False;
- }
- r_u->uni_name = malloc(num_names * sizeof(r_u->uni_name[0]));
- if (r_u->uni_name == NULL)
- {
- free(r_u->hdr_name);
- return False;
- }
- r_u->type = malloc(r_u->num_types2 * sizeof(r_u->type[0]));
- if (r_u->type == NULL)
+ if (num_names != 0)
{
- free(r_u->hdr_name);
- free(r_u->uni_name);
- return False;
+ r_u->hdr_name = malloc(num_names * sizeof(r_u->hdr_name[0]));
+ if (r_u->hdr_name == NULL)
+ {
+ samr_free_r_lookup_rids(r_u);
+ return False;
+ }
+ r_u->uni_name = malloc(num_names * sizeof(r_u->uni_name[0]));
+ if (r_u->uni_name == NULL)
+ {
+ samr_free_r_lookup_rids(r_u);
+ return False;
+ }
+ r_u->type = malloc(r_u->num_types2 * sizeof(r_u->type[0]));
+ if (r_u->type == NULL)
+ {
+ samr_free_r_lookup_rids(r_u);
+ return False;
+ }
}
-
for (i = 0; i < num_names; i++)
{
int len = name[i] != NULL ? strlen(name[i]) : 0;
@@ -4037,7 +4105,7 @@ makes a SAMR_Q_LOOKUP_NAMES structure.
********************************************************************/
BOOL make_samr_q_lookup_names(SAMR_Q_LOOKUP_NAMES *q_u,
POLICY_HND *pol, uint32 flags,
- uint32 num_names, const char **name)
+ uint32 num_names, char **name)
{
int i;
if (q_u == NULL) return False;
diff --git a/source3/rpcclient/cmd_samr.c b/source3/rpcclient/cmd_samr.c
index 9b12e3581c..910db7eae3 100644
--- a/source3/rpcclient/cmd_samr.c
+++ b/source3/rpcclient/cmd_samr.c
@@ -337,7 +337,7 @@ void cmd_sam_delete_dom_alias(struct client_info *info)
BOOL res2 = True;
uint32 ace_perms = 0x02000000; /* absolutely no idea. */
uint32 alias_rid = 0;
- const char *names[1];
+ char *names[1];
uint32 rid [MAX_LOOKUP_SIDS];
uint32 type[MAX_LOOKUP_SIDS];
uint32 num_rids;
@@ -435,7 +435,7 @@ void cmd_sam_add_aliasmem(struct client_info *info)
BOOL res4 = True;
uint32 ace_perms = 0x02000000; /* absolutely no idea. */
uint32 alias_rid;
- const char **names = NULL;
+ char **names = NULL;
int num_names = 0;
DOM_SID *sids = NULL;
int num_sids = 0;
@@ -557,18 +557,8 @@ void cmd_sam_add_aliasmem(struct client_info *info)
free(sids);
}
- if (names != NULL)
- {
- for (i = 0; i < num_names; i++)
- {
- if (names[i] != NULL)
- {
- free(((char**)(names))[i]);
- }
- }
- free(names);
- }
-
+ free_char_array(num_names, names);
+
if (res && res1 && res2)
{
DEBUG(5,("cmd_sam_add_aliasmem: succeeded\n"));
@@ -865,7 +855,7 @@ void cmd_sam_delete_dom_group(struct client_info *info)
BOOL res2 = True;
uint32 ace_perms = 0x02000000; /* absolutely no idea. */
uint32 group_rid = 0;
- const char *names[1];
+ char *names[1];
uint32 rid [MAX_LOOKUP_SIDS];
uint32 type[MAX_LOOKUP_SIDS];
uint32 num_rids;
@@ -960,12 +950,12 @@ void cmd_sam_add_groupmem(struct client_info *info)
BOOL res1 = True;
BOOL res2 = True;
uint32 ace_perms = 0x02000000; /* absolutely no idea. */
- uint32 group_rid = 0;
- uint32 group_type = SID_NAME_UNKNOWN;
- const char **names = NULL;
+ uint32 *group_rid = NULL;
+ uint32 *group_type = NULL;
+ char **names = NULL;
uint32 num_names = 0;
fstring group_name;
- const char *group_names[1];
+ char *group_names[1];
uint32 rid [MAX_LOOKUP_SIDS];
uint32 type[MAX_LOOKUP_SIDS];
uint32 num_rids;
@@ -1032,27 +1022,27 @@ void cmd_sam_add_groupmem(struct client_info *info)
res2 = res1 ? samr_query_lookup_names(smb_cli, fnum,
&info->dom.samr_pol_open_domain, 0x000003e8,
1, group_names,
- &num_group_rids, &group_rid, &group_type) : False;
+ &num_group_rids, group_rid, group_type) : False;
/* open the group */
res2 = res2 ? samr_open_group(smb_cli, fnum,
&info->dom.samr_pol_open_domain,
- 0x0000001f, group_rid, &group_pol) : False;
+ 0x0000001f, group_rid[0], &group_pol) : False;
- if (!res2 || group_type == SID_NAME_UNKNOWN)
+ if (!res2 || (group_type != NULL && group_type[0] == SID_NAME_UNKNOWN))
{
res2 = res1 ? samr_query_lookup_names(smb_cli, fnum,
&info->dom.samr_pol_open_builtindom, 0x000003e8,
1, group_names,
- &num_group_rids, &group_rid, &group_type) : False;
+ &num_group_rids, group_rid, group_type) : False;
/* open the group */
res2 = res2 ? samr_open_group(smb_cli, fnum,
&info->dom.samr_pol_open_builtindom,
- 0x0000001f, group_rid, &group_pol) : False;
+ 0x0000001f, group_rid[0], &group_pol) : False;
}
- if (group_type == SID_NAME_ALIAS)
+ if (group_type[0] == SID_NAME_ALIAS)
{
report(out_hnd, "%s is a local alias, not a group. Use addaliasmem command instead\n",
group_name);
@@ -1069,7 +1059,8 @@ void cmd_sam_add_groupmem(struct client_info *info)
if (res2)
{
- report(out_hnd, "RID added to Group 0x%x: 0x%x\n", group_rid, rid[i]);
+ report(out_hnd, "RID added to Group 0x%x: 0x%x\n",
+ group_rid[0], rid[i]);
}
}
@@ -1081,17 +1072,7 @@ void cmd_sam_add_groupmem(struct client_info *info)
/* close the session */
cli_nt_session_close(smb_cli, fnum);
- if (names != NULL)
- {
- for (i = 0; i < num_names; i++)
- {
- if (names[i] != NULL)
- {
- free(((char**)(names))[i]);
- }
- }
- free(names);
- }
+ free_char_array(num_names, names);
if (res && res1 && res2)
{
@@ -1103,6 +1084,15 @@ void cmd_sam_add_groupmem(struct client_info *info)
DEBUG(5,("cmd_sam_add_groupmem: failed\n"));
report(out_hnd, "Add Domain Group Member: FAILED\n");
}
+
+ if (group_rid != NULL)
+ {
+ free(group_rid);
+ }
+ if (group_type != NULL)
+ {
+ free(group_type);
+ }
}
@@ -1229,18 +1219,27 @@ static void req_group_info(struct client_info *info, uint16 fnum,
uint32 user_rid)
{
uint32 num_groups;
- DOM_GID gid[LSA_MAX_GROUPS];
+ DOM_GID *gid = NULL;
/* send user group query */
if (get_samr_query_usergroups(smb_cli, fnum,
&info->dom.samr_pol_open_domain,
- user_rid, &num_groups, gid))
+ user_rid, &num_groups, &gid) &&
+ gid != NULL)
{
int i;
uint32 num_names;
- uint32 rid_mem[MAX_LOOKUP_SIDS];
- fstring name [MAX_LOOKUP_SIDS];
- uint32 type [MAX_LOOKUP_SIDS];
+ uint32 *rid_mem = NULL;
+ char **name = NULL;
+ uint32 *type = NULL;
+
+ rid_mem = malloc(num_groups * sizeof(rid_mem[0]));
+
+ if (rid_mem == NULL)
+ {
+ free(gid);
+ return;
+ }
for (i = 0; i < num_groups; i++)
{
@@ -1250,12 +1249,23 @@ static void req_group_info(struct client_info *info, uint16 fnum,
if (samr_query_lookup_rids(smb_cli, fnum,
&info->dom.samr_pol_open_domain, 0x3e8,
num_groups, rid_mem,
- &num_names, name, type))
+ &num_names, &name, &type))
{
display_group_members(out_hnd, ACTION_HEADER , num_names, name, type);
display_group_members(out_hnd, ACTION_ENUMERATE, num_names, name, type);
display_group_members(out_hnd, ACTION_FOOTER , num_names, name, type);
}
+
+ free_char_array(num_names, name);
+ if (type != NULL)
+ {
+ free(type);
+ }
+ }
+
+ if (gid != NULL)
+ {
+ free(gid);
}
}
@@ -1263,50 +1273,89 @@ static void req_alias_info(struct client_info *info, uint16 fnum,
DOM_SID *sid1, uint32 user_rid)
{
uint32 num_aliases;
- uint32 rid[LSA_MAX_GROUPS];
- DOM_SID als_sid;
+ uint32 *rid = NULL;
+ uint32 *ptr_sid;
+ DOM_SID2 *als_sid;
+
+ ptr_sid = malloc(sizeof(ptr_sid[0]) * 1);
+ als_sid = malloc(sizeof(als_sid[0]) * 1);
+
+ make_dom_sid2(&als_sid[0], sid1);
+ sid_append_rid(&als_sid[0].sid, user_rid);
- sid_copy(&als_sid, sid1);
- sid_append_rid(&als_sid, user_rid);
+ ptr_sid[0] = 1;
/* send user alias query */
if (samr_query_useraliases(smb_cli, fnum,
&info->dom.samr_pol_open_domain,
- &als_sid, &num_aliases, rid))
+ ptr_sid, als_sid, &num_aliases, &rid))
{
uint32 num_names;
- fstring name [MAX_LOOKUP_SIDS];
- uint32 type [MAX_LOOKUP_SIDS];
+ char **name = NULL;
+ uint32 *type = NULL;
if (samr_query_lookup_rids(smb_cli, fnum,
&info->dom.samr_pol_open_domain, 0x3e8,
num_aliases, rid,
- &num_names, name, type))
+ &num_names, &name, &type))
{
display_group_members(out_hnd, ACTION_HEADER , num_names, name, type);
display_group_members(out_hnd, ACTION_ENUMERATE, num_names, name, type);
display_group_members(out_hnd, ACTION_FOOTER , num_names, name, type);
}
+
+ free_char_array(num_names, name);
+ if (type != NULL)
+ {
+ free(type);
+ }
+ }
+
+ if (rid != NULL)
+ {
+ free(rid);
+ rid = NULL;
}
/* send user alias query */
if (samr_query_useraliases(smb_cli, fnum,
&info->dom.samr_pol_open_builtindom,
- &als_sid, &num_aliases, rid))
+ ptr_sid, als_sid, &num_aliases, &rid))
{
uint32 num_names;
- fstring name [MAX_LOOKUP_SIDS];
- uint32 type [MAX_LOOKUP_SIDS];
+ char **name = NULL;
+ uint32 *type = NULL;
if (samr_query_lookup_rids(smb_cli, fnum,
&info->dom.samr_pol_open_builtindom, 0x3e8,
num_aliases, rid,
- &num_names, name, type))
+ &num_names, &name, &type))
{
display_group_members(out_hnd, ACTION_HEADER , num_names, name, type);
display_group_members(out_hnd, ACTION_ENUMERATE, num_names, name, type);
display_group_members(out_hnd, ACTION_FOOTER , num_names, name, type);
}
+ free_char_array(num_names, name);
+ if (type != NULL)
+ {
+ free(type);
+ }
+ }
+
+ if (ptr_sid != NULL)
+ {
+ free(ptr_sid);
+ ptr_sid = NULL;
+ }
+ if (rid != NULL)
+ {
+ free(rid);
+ rid = NULL;
+ }
+ if (als_sid != NULL)
+ {
+ free(als_sid);
+ als_sid = NULL;
}
}
@@ -1495,7 +1544,7 @@ void cmd_sam_query_user(struct client_info *info)
BOOL res1 = True;
fstring user_name;
- const char *names[1];
+ char *names[1];
uint32 num_rids;
uint32 rid[MAX_LOOKUP_SIDS];
uint32 type[MAX_LOOKUP_SIDS];
@@ -1900,17 +1949,7 @@ void cmd_sam_enum_aliases(struct client_info *info)
display_alias_members(out_hnd, ACTION_ENUMERATE, num_names, names);
display_alias_members(out_hnd, ACTION_FOOTER , num_names, names);
}
- if (names != NULL)
- {
- for (i = 0; i < num_names; i++)
- {
- if (names[i] != NULL)
- {
- free(names[i]);
- }
- }
- free(names);
- }
+ free_char_array(num_names, names);
if (sids != NULL)
{
free(sids);
@@ -1958,18 +1997,24 @@ static void req_groupmem_info(struct client_info *info, uint16 fnum,
{
BOOL res3 = True;
int num_names = 0;
- fstring names[MAX_LOOKUP_SIDS];
- uint32 types[MAX_LOOKUP_SIDS];
+ char **name = NULL;
+ uint32 *type = NULL;
res3 = samr_query_lookup_rids(smb_cli, fnum,
&info->dom.samr_pol_open_domain, 1000,
- num_mem, rid_mem, &num_names, names, types);
+ num_mem, rid_mem, &num_names, &name, &type);
if (res3)
{
- display_group_members(out_hnd, ACTION_HEADER , num_names, names, types);
- display_group_members(out_hnd, ACTION_ENUMERATE, num_names, names, types);
- display_group_members(out_hnd, ACTION_FOOTER , num_names, names, types);
+ display_group_members(out_hnd, ACTION_HEADER , num_names, name, type);
+ display_group_members(out_hnd, ACTION_ENUMERATE, num_names, name, type);
+ display_group_members(out_hnd, ACTION_FOOTER , num_names, name, type);
+ }
+
+ free_char_array(num_names, name);
+ if (type != NULL)
+ {
+ free(type);
}
}
}
diff --git a/source3/rpcclient/display.c b/source3/rpcclient/display.c
index 70a9f76f90..9b8a8154f3 100644
--- a/source3/rpcclient/display.c
+++ b/source3/rpcclient/display.c
@@ -1177,7 +1177,7 @@ void display_alias_rid_info(FILE *out_hnd, enum action_type action,
display group members
****************************************************************************/
void display_group_members(FILE *out_hnd, enum action_type action,
- uint32 num_mem, fstring *name, uint32 *type)
+ uint32 num_mem, char **name, uint32 *type)
{
switch (action)
{