mirror of
https://github.com/samba-team/samba.git
synced 2025-01-19 10:03:58 +03:00
added samalias <aliasname> rpcclient command (shows info on alias)
added samaliasmem <aliasname> rpcclient command (shows members in alias) added tab command-completion to SAM alias related commands (inc 2 above).
This commit is contained in:
parent
edb49e754b
commit
0c700fb609
@ -3331,6 +3331,8 @@ void cmd_sam_query_group(struct client_info *info);
|
||||
void cmd_sam_query_user(struct client_info *info);
|
||||
void cmd_sam_query_dispinfo(struct client_info *info);
|
||||
void cmd_sam_query_dominfo(struct client_info *info);
|
||||
void cmd_sam_query_aliasmem(struct client_info *info);
|
||||
void cmd_sam_query_alias(struct client_info *info);
|
||||
void cmd_sam_enum_aliases(struct client_info *info);
|
||||
void cmd_sam_enum_groups(struct client_info *info);
|
||||
|
||||
|
@ -925,10 +925,6 @@ uint32 msrpc_sam_enum_aliases(struct client_info *info,
|
||||
fstrcat(srv_name, info->dest_host);
|
||||
strupper(srv_name);
|
||||
|
||||
report(out_hnd, "SAM Enumerate Aliases\n");
|
||||
report(out_hnd, "From: %s To: %s Domain: %s SID: %s\n",
|
||||
info->myhostname, srv_name, domain, sid);
|
||||
|
||||
/* open SAMR session. negotiate credentials */
|
||||
res = res ? cli_nt_session_open(smb_cli, PIPE_SAMR, &fnum) : False;
|
||||
|
||||
@ -2647,6 +2643,199 @@ void cmd_sam_query_dominfo(struct client_info *info)
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
experimental SAM alias query members.
|
||||
****************************************************************************/
|
||||
void cmd_sam_query_aliasmem(struct client_info *info)
|
||||
{
|
||||
uint16 fnum;
|
||||
fstring srv_name;
|
||||
fstring domain;
|
||||
fstring sid_str;
|
||||
DOM_SID sid;
|
||||
BOOL res = True;
|
||||
BOOL res1 = True;
|
||||
|
||||
fstring alias_name;
|
||||
char *names[1];
|
||||
uint32 num_rids;
|
||||
uint32 rid[MAX_LOOKUP_SIDS];
|
||||
uint32 type[MAX_LOOKUP_SIDS];
|
||||
POLICY_HND sam_pol;
|
||||
POLICY_HND pol_dom;
|
||||
|
||||
fstrcpy(domain, info->dom.level5_dom);
|
||||
sid_copy(&sid, &info->dom.level5_sid);
|
||||
|
||||
if (sid.num_auths == 0)
|
||||
{
|
||||
report(out_hnd, "please use 'lsaquery' first, to ascertain the SID\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!next_token(NULL, alias_name, NULL, sizeof(alias_name)))
|
||||
{
|
||||
report(out_hnd, "samalias <name>\n");
|
||||
return;
|
||||
}
|
||||
|
||||
fstrcpy(srv_name, "\\\\");
|
||||
fstrcat(srv_name, info->dest_host);
|
||||
strupper(srv_name);
|
||||
|
||||
sid_to_string(sid_str, &sid);
|
||||
|
||||
report(out_hnd, "SAM Query Alias: %s\n", alias_name);
|
||||
report(out_hnd, "From: %s To: %s Domain: %s SID: %s\n",
|
||||
info->myhostname, srv_name, domain, sid_str);
|
||||
|
||||
/* open SAMR session. negotiate credentials */
|
||||
res = res ? cli_nt_session_open(smb_cli, PIPE_SAMR, &fnum) : False;
|
||||
|
||||
/* establish a connection. */
|
||||
res = res ? samr_connect(smb_cli, fnum,
|
||||
srv_name, 0x02000000,
|
||||
&sam_pol) : False;
|
||||
|
||||
/* connect to the domain */
|
||||
res = res ? samr_open_domain(smb_cli, fnum,
|
||||
&sam_pol, 0x304, &sid,
|
||||
&pol_dom) : False;
|
||||
|
||||
/* look up alias rid */
|
||||
names[0] = alias_name;
|
||||
res1 = res ? samr_query_lookup_names(smb_cli, fnum,
|
||||
&pol_dom, 0x3e8,
|
||||
1, names,
|
||||
&num_rids, rid, type) : False;
|
||||
|
||||
if (res1 && num_rids == 1)
|
||||
{
|
||||
res1 = req_aliasmem_info(smb_cli, fnum,
|
||||
&pol_dom,
|
||||
domain,
|
||||
&sid,
|
||||
rid[0],
|
||||
names[0],
|
||||
sam_display_alias_members);
|
||||
}
|
||||
|
||||
res = res ? samr_close(smb_cli, fnum,
|
||||
&sam_pol) : False;
|
||||
|
||||
res = res ? samr_close(smb_cli, fnum,
|
||||
&pol_dom) : False;
|
||||
|
||||
/* close the session */
|
||||
cli_nt_session_close(smb_cli, fnum);
|
||||
|
||||
if (res1)
|
||||
{
|
||||
DEBUG(5,("cmd_sam_query_alias: succeeded\n"));
|
||||
}
|
||||
else
|
||||
{
|
||||
DEBUG(5,("cmd_sam_query_alias: failed\n"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
experimental SAM alias query.
|
||||
****************************************************************************/
|
||||
void cmd_sam_query_alias(struct client_info *info)
|
||||
{
|
||||
uint16 fnum;
|
||||
fstring srv_name;
|
||||
fstring domain;
|
||||
fstring sid_str;
|
||||
DOM_SID sid;
|
||||
BOOL res = True;
|
||||
BOOL res1 = True;
|
||||
|
||||
fstring alias_name;
|
||||
char *names[1];
|
||||
uint32 num_rids;
|
||||
uint32 rid[MAX_LOOKUP_SIDS];
|
||||
uint32 type[MAX_LOOKUP_SIDS];
|
||||
POLICY_HND sam_pol;
|
||||
POLICY_HND pol_dom;
|
||||
|
||||
fstrcpy(domain, info->dom.level5_dom);
|
||||
sid_copy(&sid, &info->dom.level5_sid);
|
||||
|
||||
if (sid.num_auths == 0)
|
||||
{
|
||||
report(out_hnd, "please use 'lsaquery' first, to ascertain the SID\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!next_token(NULL, alias_name, NULL, sizeof(alias_name)))
|
||||
{
|
||||
report(out_hnd, "samalias <name>\n");
|
||||
return;
|
||||
}
|
||||
|
||||
fstrcpy(srv_name, "\\\\");
|
||||
fstrcat(srv_name, info->dest_host);
|
||||
strupper(srv_name);
|
||||
|
||||
sid_to_string(sid_str, &sid);
|
||||
|
||||
report(out_hnd, "SAM Query Alias: %s\n", alias_name);
|
||||
report(out_hnd, "From: %s To: %s Domain: %s SID: %s\n",
|
||||
info->myhostname, srv_name, domain, sid_str);
|
||||
|
||||
/* open SAMR session. negotiate credentials */
|
||||
res = res ? cli_nt_session_open(smb_cli, PIPE_SAMR, &fnum) : False;
|
||||
|
||||
/* establish a connection. */
|
||||
res = res ? samr_connect(smb_cli, fnum,
|
||||
srv_name, 0x02000000,
|
||||
&sam_pol) : False;
|
||||
|
||||
/* connect to the domain */
|
||||
res = res ? samr_open_domain(smb_cli, fnum,
|
||||
&sam_pol, 0x304, &sid,
|
||||
&pol_dom) : False;
|
||||
|
||||
/* look up alias rid */
|
||||
names[0] = alias_name;
|
||||
res1 = res ? samr_query_lookup_names(smb_cli, fnum,
|
||||
&pol_dom, 0x3e8,
|
||||
1, names,
|
||||
&num_rids, rid, type) : False;
|
||||
|
||||
if (res1 && num_rids == 1)
|
||||
{
|
||||
res1 = query_aliasinfo(smb_cli, fnum,
|
||||
&pol_dom,
|
||||
domain,
|
||||
&sid,
|
||||
rid[0],
|
||||
sam_display_alias_info);
|
||||
}
|
||||
|
||||
res = res ? samr_close(smb_cli, fnum,
|
||||
&sam_pol) : False;
|
||||
|
||||
res = res ? samr_close(smb_cli, fnum,
|
||||
&pol_dom) : False;
|
||||
|
||||
/* close the session */
|
||||
cli_nt_session_close(smb_cli, fnum);
|
||||
|
||||
if (res1)
|
||||
{
|
||||
DEBUG(5,("cmd_sam_query_alias: succeeded\n"));
|
||||
}
|
||||
else
|
||||
{
|
||||
DEBUG(5,("cmd_sam_query_alias: failed\n"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
SAM aliases query.
|
||||
****************************************************************************/
|
||||
|
@ -103,7 +103,8 @@ static void rpcclient_stop(void)
|
||||
#define COMPL_REGKEY 1
|
||||
#define COMPL_SAMUSR 3
|
||||
#define COMPL_SAMGRP 4
|
||||
#define COMPL_SVCLST 5
|
||||
#define COMPL_SAMALS 5
|
||||
#define COMPL_SVCLST 6
|
||||
|
||||
/****************************************************************************
|
||||
This defines the commands supported by this client
|
||||
@ -354,27 +355,27 @@ commands[] =
|
||||
{
|
||||
"addgroupmem",
|
||||
cmd_sam_add_groupmem,
|
||||
"<group rid> [member rid1] [member rid2] ... SAM Add Domain Group Member",
|
||||
{COMPL_SAMGRP, COMPL_SAMGRP}
|
||||
"<group rid> [user] [user] ... SAM Add Domain Group Member",
|
||||
{COMPL_SAMGRP, COMPL_SAMUSR}
|
||||
},
|
||||
|
||||
{
|
||||
"addaliasmem",
|
||||
cmd_sam_add_aliasmem,
|
||||
"<alias rid> [member sid1] [member sid2] ... SAM Add Domain Alias Member",
|
||||
{COMPL_NONE, COMPL_NONE}
|
||||
{COMPL_SAMALS, COMPL_NONE}
|
||||
},
|
||||
{
|
||||
"delgroupmem",
|
||||
cmd_sam_del_groupmem,
|
||||
"<group rid> [member rid1] [member rid2] ... SAM Delete Domain Group Member",
|
||||
{COMPL_SAMGRP, COMPL_SAMGRP}
|
||||
"<group rid> [user] [user] ... SAM Delete Domain Group Member",
|
||||
{COMPL_SAMGRP, COMPL_SAMUSR}
|
||||
},
|
||||
{
|
||||
"delaliasmem",
|
||||
cmd_sam_del_aliasmem,
|
||||
"<alias rid> [member sid1] [member sid2] ... SAM Delete Domain Alias Member",
|
||||
{COMPL_NONE, COMPL_NONE}
|
||||
{COMPL_SAMALS, COMPL_NONE}
|
||||
},
|
||||
{
|
||||
"creategroup",
|
||||
@ -404,7 +405,7 @@ commands[] =
|
||||
"delalias",
|
||||
cmd_sam_delete_dom_alias,
|
||||
"SAM Delete Domain Alias",
|
||||
{COMPL_NONE, COMPL_NONE}
|
||||
{COMPL_SAMALS, COMPL_NONE}
|
||||
},
|
||||
{
|
||||
"ntpass",
|
||||
@ -421,13 +422,25 @@ commands[] =
|
||||
{
|
||||
"samgroup",
|
||||
cmd_sam_query_group,
|
||||
"<username> SAM Group Query (experimental!)",
|
||||
"<groupname> SAM Group Query (experimental!)",
|
||||
{COMPL_SAMGRP, COMPL_NONE}
|
||||
},
|
||||
{
|
||||
"samalias",
|
||||
cmd_sam_query_alias,
|
||||
"<aliasname> SAM Alias Query",
|
||||
{COMPL_SAMALS, COMPL_NONE}
|
||||
},
|
||||
{
|
||||
"samaliasmem",
|
||||
cmd_sam_query_aliasmem,
|
||||
"<aliasname> SAM Alias Members",
|
||||
{COMPL_SAMALS, COMPL_NONE}
|
||||
},
|
||||
{
|
||||
"samgroupmem",
|
||||
cmd_sam_query_groupmem,
|
||||
"SAM Group Members (experimental!)",
|
||||
"SAM Group Members",
|
||||
{COMPL_SAMGRP, COMPL_NONE}
|
||||
},
|
||||
{
|
||||
@ -938,6 +951,43 @@ static char *complete_samenum_usr(char *text, int state)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static char *complete_samenum_als(char *text, int state)
|
||||
{
|
||||
static uint32 i = 0;
|
||||
static uint32 num_als = 0;
|
||||
static struct acct_info *sam = NULL;
|
||||
|
||||
if (state == 0)
|
||||
{
|
||||
free(sam);
|
||||
sam = NULL;
|
||||
num_als = 0;
|
||||
|
||||
/* Iterate all aliases */
|
||||
if (msrpc_sam_enum_aliases(&cli_info, &sam, &num_als,
|
||||
NULL, NULL, NULL) == 0)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
}
|
||||
|
||||
for (; i < num_als; i++)
|
||||
{
|
||||
char *als_name = sam[i].acct_name;
|
||||
if (text == NULL || text[0] == 0 ||
|
||||
strnequal(text, als_name, strlen(text)))
|
||||
{
|
||||
char *name = strdup(als_name);
|
||||
i++;
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static char *complete_samenum_grp(char *text, int state)
|
||||
{
|
||||
static uint32 i = 0;
|
||||
@ -1109,6 +1159,9 @@ static char **completion_fn(char *text, int start, int end)
|
||||
case COMPL_SAMGRP:
|
||||
return completion_matches(text, complete_samenum_grp);
|
||||
|
||||
case COMPL_SAMALS:
|
||||
return completion_matches(text, complete_samenum_als);
|
||||
|
||||
case COMPL_SAMUSR:
|
||||
return completion_matches(text, complete_samenum_usr);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user