1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-01 21:18:10 +03:00

restructuring samr client code.

This commit is contained in:
Luke Leighton 0001-01-01 00:00:00 +00:00
parent 4d5b860802
commit a78607b5db
3 changed files with 154 additions and 114 deletions

View File

@ -1738,7 +1738,7 @@ BOOL cli_nt_logoff(struct cli_state *cli, uint16 fnum, NET_ID_INFO_CTR *ctr);
/*The following definitions come from rpc_client/cli_lsarpc.c */ /*The following definitions come from rpc_client/cli_lsarpc.c */
BOOL lsa_open_policy(struct cli_state *cli, uint16 fnum, BOOL lsa_open_policy(struct cli_state *cli, uint16 fnum,
char *server_name, POLICY_HND *hnd, const char *server_name, POLICY_HND *hnd,
BOOL sec_qos); BOOL sec_qos);
BOOL lsa_open_secret(struct cli_state *cli, uint16 fnum, BOOL lsa_open_secret(struct cli_state *cli, uint16 fnum,
POLICY_HND *hnd_pol, char *secret_name, uint32 des_access, POLICY_HND *hnd_pol, char *secret_name, uint32 des_access,
@ -3215,6 +3215,13 @@ void cmd_sam_del_groupmem(struct client_info *info);
void cmd_sam_delete_dom_group(struct client_info *info); void cmd_sam_delete_dom_group(struct client_info *info);
void cmd_sam_add_groupmem(struct client_info *info); void cmd_sam_add_groupmem(struct client_info *info);
void cmd_sam_create_dom_group(struct client_info *info); void cmd_sam_create_dom_group(struct client_info *info);
uint32 sam_query_usergroups(struct cli_state *cli, uint16 fnum,
POLICY_HND *pol_dom,
uint32 user_rid,
uint32 *num_groups,
DOM_GID **gid,
char ***name,
uint32 **type);
int msrpc_sam_enum_users(struct client_info *info, int msrpc_sam_enum_users(struct client_info *info,
struct acct_info **sam, struct acct_info **sam,
uint32 *num_sam_entries, uint32 *num_sam_entries,
@ -3228,7 +3235,7 @@ BOOL sam_query_dominfo(struct client_info *info, DOM_SID *sid1,
uint32 switch_value, SAM_UNK_CTR *ctr); uint32 switch_value, SAM_UNK_CTR *ctr);
void cmd_sam_query_dominfo(struct client_info *info); void cmd_sam_query_dominfo(struct client_info *info);
void cmd_sam_enum_aliases(struct client_info *info); void cmd_sam_enum_aliases(struct client_info *info);
BOOL sam_query_groupmem(struct client_info *info, uint16 fnum, BOOL sam_query_groupmem(struct cli_state *cli, uint16 fnum,
POLICY_HND *pol_dom, POLICY_HND *pol_dom,
uint32 group_rid, uint32 group_rid,
uint32 *num_names, uint32 *num_names,

View File

@ -36,7 +36,7 @@ extern int DEBUGLEVEL;
do a LSA Open Policy do a LSA Open Policy
****************************************************************************/ ****************************************************************************/
BOOL lsa_open_policy(struct cli_state *cli, uint16 fnum, BOOL lsa_open_policy(struct cli_state *cli, uint16 fnum,
char *server_name, POLICY_HND *hnd, const char *server_name, POLICY_HND *hnd,
BOOL sec_qos) BOOL sec_qos)
{ {
prs_struct rbuf; prs_struct rbuf;

View File

@ -447,6 +447,7 @@ void cmd_sam_add_aliasmem(struct client_info *info)
int i; int i;
POLICY_HND sam_pol; POLICY_HND sam_pol;
POLICY_HND pol_dom; POLICY_HND pol_dom;
POLICY_HND lsa_pol;
sid_copy(&sid1, &info->dom.level5_sid); sid_copy(&sid1, &info->dom.level5_sid);
sid_to_string(sid, &sid1); sid_to_string(sid, &sid1);
@ -488,15 +489,15 @@ void cmd_sam_add_aliasmem(struct client_info *info)
/* lookup domain controller; receive a policy handle */ /* lookup domain controller; receive a policy handle */
res3 = res3 ? lsa_open_policy(smb_cli, fnum_lsa, res3 = res3 ? lsa_open_policy(smb_cli, fnum_lsa,
srv_name, srv_name,
&info->dom.lsa_info_pol, True) : False; &lsa_pol, True) : False;
/* send lsa lookup sids call */ /* send lsa lookup sids call */
res4 = res3 ? lsa_lookup_names(smb_cli, fnum_lsa, res4 = res3 ? lsa_lookup_names(smb_cli, fnum_lsa,
&info->dom.lsa_info_pol, &lsa_pol,
num_names, names, num_names, names,
&sids, NULL, &num_sids) : False; &sids, NULL, &num_sids) : False;
res3 = res3 ? lsa_close(smb_cli, fnum_lsa, &info->dom.lsa_info_pol) : False; res3 = res3 ? lsa_close(smb_cli, fnum_lsa, &lsa_pol) : False;
cli_nt_session_close(smb_cli, fnum_lsa); cli_nt_session_close(smb_cli, fnum_lsa);
@ -1203,7 +1204,7 @@ void cmd_sam_create_dom_group(struct client_info *info)
} }
} }
static void req_user_info(struct client_info *info, uint16 fnum, static void req_user_info(struct cli_state *cli, uint16 fnum,
POLICY_HND *pol_dom, POLICY_HND *pol_dom,
uint32 user_rid) uint32 user_rid)
{ {
@ -1219,7 +1220,7 @@ static void req_user_info(struct client_info *info, uint16 fnum,
} }
} }
static void query_groupinfo(struct client_info *info, uint16 fnum, static void query_groupinfo(struct cli_state *cli, uint16 fnum,
POLICY_HND *pol_dom, POLICY_HND *pol_dom,
uint32 group_rid) uint32 group_rid)
{ {
@ -1238,53 +1239,75 @@ static void query_groupinfo(struct client_info *info, uint16 fnum,
} }
} }
static void req_group_info(struct client_info *info, uint16 fnum, /****************************************************************************
SAM Query User Groups.
****************************************************************************/
uint32 sam_query_usergroups(struct cli_state *cli, uint16 fnum,
POLICY_HND *pol_dom, POLICY_HND *pol_dom,
uint32 user_rid) uint32 user_rid,
{ uint32 *num_groups,
uint32 num_groups; DOM_GID **gid,
DOM_GID *gid = NULL; char ***name,
uint32 **type)
{
uint32 num_names = 0;
(*gid) = NULL;
/* send user group query */ /* send user group query */
if (get_samr_query_usergroups(smb_cli, fnum, if (get_samr_query_usergroups(smb_cli, fnum,
pol_dom, pol_dom,
user_rid, &num_groups, &gid) && user_rid, num_groups, gid) &&
gid != NULL) gid != NULL)
{ {
uint32 i; uint32 i;
uint32 num_names; uint32 *rid_mem;
uint32 *rid_mem = NULL;
char **name = NULL;
uint32 *type = NULL;
rid_mem = (uint32*)malloc(num_groups * sizeof(rid_mem[0])); rid_mem = (uint32*)malloc((*num_groups) * sizeof(rid_mem[0]));
if (rid_mem == NULL) if (rid_mem == NULL)
{ {
free(gid); free(*gid);
return; (*gid) = NULL;
return 0;
} }
for (i = 0; i < num_groups; i++) for (i = 0; i < (*num_groups); i++)
{ {
rid_mem[i] = gid[i].g_rid; rid_mem[i] = (*gid)[i].g_rid;
} }
if (samr_query_lookup_rids(smb_cli, fnum, if (samr_query_lookup_rids(smb_cli, fnum,
pol_dom, 0x3e8, pol_dom, 0x3e8,
num_groups, rid_mem, (*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_HEADER , num_names, *name, *type);
display_group_members(out_hnd, ACTION_ENUMERATE, 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); display_group_members(out_hnd, ACTION_FOOTER , num_names, *name, *type);
} }
}
free_char_array(num_names, name); return num_names;
if (type != NULL) }
{
free(type); static void req_group_info(struct cli_state *cli, uint16 fnum,
} POLICY_HND *pol_dom,
uint32 user_rid)
{
uint32 num_groups;
uint32 num_names;
DOM_GID *gid = NULL;
char **name = NULL;
uint32 *type = NULL;
num_names = sam_query_usergroups(cli, fnum, pol_dom, user_rid,
&num_groups, &gid,
&name, &type);
free_char_array(num_names, name);
if (type != NULL)
{
free(type);
} }
if (gid != NULL) if (gid != NULL)
@ -1293,7 +1316,7 @@ static void req_group_info(struct client_info *info, uint16 fnum,
} }
} }
static void req_alias_info(uint16 fnum, static void req_alias_info(struct cli_state *cli, uint16 fnum,
POLICY_HND *pol_dom, POLICY_HND *pol_dom,
DOM_SID *sid1, uint32 user_rid) DOM_SID *sid1, uint32 user_rid)
{ {
@ -1312,7 +1335,7 @@ static void req_alias_info(uint16 fnum,
ptr_sid[0] = 1; ptr_sid[0] = 1;
/* send user alias query */ /* send user alias query */
if (samr_query_useraliases(smb_cli, fnum, if (samr_query_useraliases(cli, fnum,
pol_dom, pol_dom,
ptr_sid, als_sid, &num_aliases, &rid)) ptr_sid, als_sid, &num_aliases, &rid))
{ {
@ -1320,7 +1343,7 @@ static void req_alias_info(uint16 fnum,
char **name = NULL; char **name = NULL;
uint32 *type = NULL; uint32 *type = NULL;
if (samr_query_lookup_rids(smb_cli, fnum, if (samr_query_lookup_rids(cli, fnum,
pol_dom, 0x3e8, pol_dom, 0x3e8,
num_aliases, rid, num_aliases, rid,
&num_names, &name, &type)) &num_names, &name, &type))
@ -1452,18 +1475,18 @@ int msrpc_sam_enum_users(struct client_info *info,
if (request_group_info) if (request_group_info)
{ {
req_group_info(info, fnum, &pol_dom, user_rid); req_group_info(smb_cli, fnum, &pol_dom, user_rid);
} }
if (request_user_info) if (request_user_info)
{ {
req_user_info(info, fnum, &pol_dom, user_rid); req_user_info(smb_cli, fnum, &pol_dom, user_rid);
} }
if (request_alias_info) if (request_alias_info)
{ {
req_alias_info(fnum, &pol_dom, &sid1, user_rid); req_alias_info(smb_cli, fnum, &pol_dom, &sid1, user_rid);
req_alias_info(fnum, &pol_blt, &sid1, user_rid); req_alias_info(smb_cli, fnum, &pol_blt, &sid1, user_rid);
} }
} }
} }
@ -1818,6 +1841,74 @@ void cmd_sam_query_dominfo(struct client_info *info)
} }
static void req_samr_aliasmem(struct cli_state *cli, uint16 fnum,
const char *srv_name,
POLICY_HND *pol_dom, uint32 alias_rid)
{
uint32 num_aliases;
DOM_SID2 sid_mem[MAX_LOOKUP_SIDS];
/* send user aliases query */
if (get_samr_query_aliasmem(smb_cli, fnum,
pol_dom,
alias_rid, &num_aliases, sid_mem))
{
uint16 fnum_lsa;
POLICY_HND lsa_pol;
BOOL res3 = True;
BOOL res4 = True;
char **names = NULL;
int num_names = 0;
DOM_SID **sids = NULL;
uint32 i;
if (num_aliases != 0)
{
sids = (DOM_SID**)malloc(num_aliases * sizeof(DOM_SID*));
}
res3 = sids != NULL;
if (res3)
{
for (i = 0; i < num_aliases; i++)
{
sids[i] = &sid_mem[i].sid;
}
}
/* open LSARPC session. */
res3 = res3 ? cli_nt_session_open(smb_cli, PIPE_LSARPC, &fnum_lsa) : False;
/* lookup domain controller; receive a policy handle */
res3 = res3 ? lsa_open_policy(smb_cli, fnum_lsa,
srv_name,
&lsa_pol, True) : False;
/* send lsa lookup sids call */
res4 = res3 ? lsa_lookup_sids(smb_cli, fnum_lsa,
&lsa_pol,
num_aliases, sids,
&names, NULL, &num_names) : False;
res3 = res3 ? lsa_close(smb_cli, fnum_lsa, &lsa_pol) : False;
cli_nt_session_close(smb_cli, fnum_lsa);
if (res4 && names != NULL)
{
display_alias_members(out_hnd, ACTION_HEADER , num_names, names);
display_alias_members(out_hnd, ACTION_ENUMERATE, num_names, names);
display_alias_members(out_hnd, ACTION_FOOTER , num_names, names);
}
free_char_array(num_names, names);
if (sids != NULL)
{
free(sids);
}
}
}
/**************************************************************************** /****************************************************************************
SAM aliases query. SAM aliases query.
****************************************************************************/ ****************************************************************************/
@ -1893,79 +1984,21 @@ void cmd_sam_enum_aliases(struct client_info *info)
if (res) if (res)
{ {
for (alias_idx = 0; alias_idx < num_sam_entries; alias_idx++) for (alias_idx = 0; alias_idx < num_sam_entries; alias_idx++)
{
uint32 alias_rid = sam[alias_idx].rid;
report(out_hnd, "Alias RID: %8x Group Name: %s\n",
alias_rid,
sam[alias_idx].acct_name);
if (request_member_info)
{ {
uint32 num_aliases; uint32 alias_rid = sam[alias_idx].rid;
DOM_SID2 sid_mem[MAX_LOOKUP_SIDS];
/* send user aliases query */ report(out_hnd, "Alias RID: %8x Group Name: %s\n",
if (get_samr_query_aliasmem(smb_cli, fnum, alias_rid,
&pol_dom, sam[alias_idx].acct_name);
alias_rid, &num_aliases, sid_mem))
if (request_member_info)
{ {
uint16 fnum_lsa; req_samr_aliasmem(smb_cli, fnum,
BOOL res3 = True; srv_name, &pol_dom, alias_rid);
BOOL res4 = True;
char **names = NULL;
int num_names = 0;
DOM_SID **sids = NULL;
uint32 i;
if (num_aliases != 0)
{
sids = (DOM_SID**)malloc(num_aliases * sizeof(DOM_SID*));
}
res3 = sids != NULL;
if (res3)
{
for (i = 0; i < num_aliases; i++)
{
sids[i] = &sid_mem[i].sid;
}
}
/* open LSARPC session. */
res3 = res3 ? cli_nt_session_open(smb_cli, PIPE_LSARPC, &fnum_lsa) : False;
/* lookup domain controller; receive a policy handle */
res3 = res3 ? lsa_open_policy(smb_cli, fnum_lsa,
srv_name,
&info->dom.lsa_info_pol, True) : False;
/* send lsa lookup sids call */
res4 = res3 ? lsa_lookup_sids(smb_cli, fnum_lsa,
&info->dom.lsa_info_pol,
num_aliases, sids,
&names, NULL, &num_names) : False;
res3 = res3 ? lsa_close(smb_cli, fnum_lsa, &info->dom.lsa_info_pol) : False;
cli_nt_session_close(smb_cli, fnum_lsa);
if (res4 && names != NULL)
{
display_alias_members(out_hnd, ACTION_HEADER , num_names, names);
display_alias_members(out_hnd, ACTION_ENUMERATE, num_names, names);
display_alias_members(out_hnd, ACTION_FOOTER , num_names, names);
}
free_char_array(num_names, names);
if (sids != NULL)
{
free(sids);
}
} }
} }
} }
}
res = res ? samr_close(smb_cli, fnum, res = res ? samr_close(smb_cli, fnum,
&sam_pol) : False; &sam_pol) : False;
@ -1991,7 +2024,7 @@ void cmd_sam_enum_aliases(struct client_info *info)
} }
} }
BOOL sam_query_groupmem(struct client_info *info, uint16 fnum, BOOL sam_query_groupmem(struct cli_state *cli, uint16 fnum,
POLICY_HND *pol_dom, POLICY_HND *pol_dom,
uint32 group_rid, uint32 group_rid,
uint32 *num_names, uint32 *num_names,
@ -2009,7 +2042,7 @@ BOOL sam_query_groupmem(struct client_info *info, uint16 fnum,
*type = NULL; *type = NULL;
/* get group members */ /* get group members */
res3 = get_samr_query_groupmem(smb_cli, fnum, res3 = get_samr_query_groupmem(cli, fnum,
pol_dom, pol_dom,
group_rid, &num_mem, rid_mem, &attr_mem); group_rid, &num_mem, rid_mem, &attr_mem);
@ -2025,7 +2058,7 @@ BOOL sam_query_groupmem(struct client_info *info, uint16 fnum,
rid_copy[i] = (*rid_mem)[i]; rid_copy[i] = (*rid_mem)[i];
} }
/* resolve names */ /* resolve names */
res3 = samr_query_lookup_rids(smb_cli, fnum, res3 = samr_query_lookup_rids(cli, fnum,
pol_dom, 1000, pol_dom, 1000,
num_mem, rid_copy, num_names, name, type); num_mem, rid_copy, num_names, name, type);
} }
@ -2064,7 +2097,7 @@ BOOL sam_query_groupmem(struct client_info *info, uint16 fnum,
return res3; return res3;
} }
static void req_groupmem_info(struct client_info *info, uint16 fnum, static void req_groupmem_info(struct cli_state *cli, uint16 fnum,
POLICY_HND *pol_dom, POLICY_HND *pol_dom,
uint32 group_rid) uint32 group_rid)
{ {
@ -2073,7 +2106,7 @@ static void req_groupmem_info(struct client_info *info, uint16 fnum,
uint32 *type = NULL; uint32 *type = NULL;
uint32 *rid_mem = NULL; uint32 *rid_mem = NULL;
if (sam_query_groupmem(info, fnum, pol_dom, group_rid, if (sam_query_groupmem(cli, fnum, pol_dom, group_rid,
&num_names, &rid_mem, &name, &type)) &num_names, &rid_mem, &name, &type))
{ {
display_group_members(out_hnd, ACTION_HEADER , num_names, name, type); display_group_members(out_hnd, ACTION_HEADER , num_names, name, type);
@ -2165,11 +2198,11 @@ uint32 msrpc_sam_enum_groups(struct client_info *info,
if (request_group_info) if (request_group_info)
{ {
query_groupinfo(info, fnum, &pol_dom, group_rid); query_groupinfo(smb_cli, fnum, &pol_dom, group_rid);
} }
if (request_member_info) if (request_member_info)
{ {
req_groupmem_info(info, fnum, &pol_dom, group_rid); req_groupmem_info(smb_cli, fnum, &pol_dom, group_rid);
} }
} }
} }