mirror of
https://github.com/samba-team/samba.git
synced 2025-08-04 08:22:08 +03:00
Merge of lsa lookup names/sids patch from HEAD.
(This used to be commit e57c162897
)
This commit is contained in:
@ -30,6 +30,7 @@
|
|||||||
#define NT_STATUS_NO_MORE_ENTRIES NT_STATUS(0x8000001a)
|
#define NT_STATUS_NO_MORE_ENTRIES NT_STATUS(0x8000001a)
|
||||||
|
|
||||||
#define STATUS_MORE_ENTRIES NT_STATUS(0x0105)
|
#define STATUS_MORE_ENTRIES NT_STATUS(0x0105)
|
||||||
|
#define STATUS_SOME_UNMAPPED NT_STATUS(0x0107)
|
||||||
#define ERROR_INVALID_PARAMETER NT_STATUS(0x0057)
|
#define ERROR_INVALID_PARAMETER NT_STATUS(0x0057)
|
||||||
#define ERROR_INSUFFICIENT_BUFFER NT_STATUS(0x007a)
|
#define ERROR_INSUFFICIENT_BUFFER NT_STATUS(0x007a)
|
||||||
#define STATUS_NOTIFY_ENUM_DIR NT_STATUS(0x010c)
|
#define STATUS_NOTIFY_ENUM_DIR NT_STATUS(0x010c)
|
||||||
|
@ -230,7 +230,7 @@ NTSTATUS cli_lsa_close(struct cli_state *cli, TALLOC_CTX *mem_ctx,
|
|||||||
|
|
||||||
NTSTATUS cli_lsa_lookup_sids(struct cli_state *cli, TALLOC_CTX *mem_ctx,
|
NTSTATUS cli_lsa_lookup_sids(struct cli_state *cli, TALLOC_CTX *mem_ctx,
|
||||||
POLICY_HND *pol, int num_sids, DOM_SID *sids,
|
POLICY_HND *pol, int num_sids, DOM_SID *sids,
|
||||||
char ***domains, char ***names, uint32 **types, int *num_names)
|
char ***domains, char ***names, uint32 **types)
|
||||||
{
|
{
|
||||||
prs_struct qbuf, rbuf;
|
prs_struct qbuf, rbuf;
|
||||||
LSA_Q_LOOKUP_SIDS q;
|
LSA_Q_LOOKUP_SIDS q;
|
||||||
@ -274,13 +274,13 @@ NTSTATUS cli_lsa_lookup_sids(struct cli_state *cli, TALLOC_CTX *mem_ctx,
|
|||||||
result = r.status;
|
result = r.status;
|
||||||
|
|
||||||
if (!NT_STATUS_IS_OK(result) &&
|
if (!NT_STATUS_IS_OK(result) &&
|
||||||
NT_STATUS_V(result) != NT_STATUS_V(NT_STATUS_FILES_OPEN)) {
|
NT_STATUS_V(result) != NT_STATUS_V(STATUS_SOME_UNMAPPED)) {
|
||||||
|
|
||||||
/* An actual error occured */
|
/* An actual error occured */
|
||||||
|
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Return output parameters */
|
/* Return output parameters */
|
||||||
|
|
||||||
if (r.mapped_count == 0) {
|
if (r.mapped_count == 0) {
|
||||||
@ -288,28 +288,28 @@ NTSTATUS cli_lsa_lookup_sids(struct cli_state *cli, TALLOC_CTX *mem_ctx,
|
|||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
(*num_names) = r.mapped_count;
|
if (!((*domains) = (char **)talloc(mem_ctx, sizeof(char *) *
|
||||||
result = NT_STATUS_OK;
|
num_sids))) {
|
||||||
|
|
||||||
if (!((*domains) = (char **)talloc(mem_ctx, sizeof(char *) * r.mapped_count))) {
|
|
||||||
DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
|
DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
|
||||||
result = NT_STATUS_UNSUCCESSFUL;
|
result = NT_STATUS_UNSUCCESSFUL;
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!((*names) = (char **)talloc(mem_ctx, sizeof(char *) * r.mapped_count))) {
|
if (!((*names) = (char **)talloc(mem_ctx, sizeof(char *) *
|
||||||
|
num_sids))) {
|
||||||
DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
|
DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
|
||||||
result = NT_STATUS_UNSUCCESSFUL;
|
result = NT_STATUS_UNSUCCESSFUL;
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!((*types) = (uint32 *)talloc(mem_ctx, sizeof(uint32) * r.mapped_count))) {
|
if (!((*types) = (uint32 *)talloc(mem_ctx, sizeof(uint32) *
|
||||||
|
num_sids))) {
|
||||||
DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
|
DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
|
||||||
result = NT_STATUS_UNSUCCESSFUL;
|
result = NT_STATUS_UNSUCCESSFUL;
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < r.mapped_count; i++) {
|
for (i = 0; i < num_sids; i++) {
|
||||||
fstring name, dom_name;
|
fstring name, dom_name;
|
||||||
uint32 dom_idx = t_names.name[i].domain_idx;
|
uint32 dom_idx = t_names.name[i].domain_idx;
|
||||||
|
|
||||||
@ -348,8 +348,9 @@ NTSTATUS cli_lsa_lookup_sids(struct cli_state *cli, TALLOC_CTX *mem_ctx,
|
|||||||
/** Lookup a list of names */
|
/** Lookup a list of names */
|
||||||
|
|
||||||
NTSTATUS cli_lsa_lookup_names(struct cli_state *cli, TALLOC_CTX *mem_ctx,
|
NTSTATUS cli_lsa_lookup_names(struct cli_state *cli, TALLOC_CTX *mem_ctx,
|
||||||
POLICY_HND *pol, int num_names, const char **names,
|
POLICY_HND *pol, int num_names,
|
||||||
DOM_SID **sids, uint32 **types, int *num_sids)
|
const char **names, DOM_SID **sids,
|
||||||
|
uint32 **types)
|
||||||
{
|
{
|
||||||
prs_struct qbuf, rbuf;
|
prs_struct qbuf, rbuf;
|
||||||
LSA_Q_LOOKUP_NAMES q;
|
LSA_Q_LOOKUP_NAMES q;
|
||||||
@ -388,13 +389,14 @@ NTSTATUS cli_lsa_lookup_names(struct cli_state *cli, TALLOC_CTX *mem_ctx,
|
|||||||
|
|
||||||
result = r.status;
|
result = r.status;
|
||||||
|
|
||||||
if (!NT_STATUS_IS_OK(result)) {
|
if (!NT_STATUS_IS_OK(result) &&
|
||||||
|
NT_STATUS_V(result) != NT_STATUS_V(STATUS_SOME_UNMAPPED)) {
|
||||||
|
|
||||||
/* An actual error occured */
|
/* An actual error occured */
|
||||||
|
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Return output parameters */
|
/* Return output parameters */
|
||||||
|
|
||||||
if (r.mapped_count == 0) {
|
if (r.mapped_count == 0) {
|
||||||
@ -402,22 +404,21 @@ NTSTATUS cli_lsa_lookup_names(struct cli_state *cli, TALLOC_CTX *mem_ctx,
|
|||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
(*num_sids) = r.mapped_count;
|
if (!((*sids = (DOM_SID *)talloc(mem_ctx, sizeof(DOM_SID) *
|
||||||
result = NT_STATUS_OK;
|
num_names)))) {
|
||||||
|
|
||||||
if (!((*sids = (DOM_SID *)talloc(mem_ctx, sizeof(DOM_SID) * r.mapped_count)))) {
|
|
||||||
DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
|
DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
|
||||||
result = NT_STATUS_UNSUCCESSFUL;
|
result = NT_STATUS_UNSUCCESSFUL;
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!((*types = (uint32 *)talloc(mem_ctx, sizeof(uint32) * r.mapped_count)))) {
|
if (!((*types = (uint32 *)talloc(mem_ctx, sizeof(uint32) *
|
||||||
|
num_names)))) {
|
||||||
DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
|
DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
|
||||||
result = NT_STATUS_UNSUCCESSFUL;
|
result = NT_STATUS_UNSUCCESSFUL;
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < r.mapped_count; i++) {
|
for (i = 0; i < num_names; i++) {
|
||||||
DOM_RID2 *t_rids = r.dom_rid;
|
DOM_RID2 *t_rids = r.dom_rid;
|
||||||
uint32 dom_idx = t_rids[i].rid_idx;
|
uint32 dom_idx = t_rids[i].rid_idx;
|
||||||
uint32 dom_rid = t_rids[i].rid;
|
uint32 dom_rid = t_rids[i].rid;
|
||||||
|
@ -534,6 +534,7 @@ nt_err_code_struct nt_errs[] =
|
|||||||
{ "NT_STATUS_QUOTA_LIST_INCONSISTENT", NT_STATUS_QUOTA_LIST_INCONSISTENT },
|
{ "NT_STATUS_QUOTA_LIST_INCONSISTENT", NT_STATUS_QUOTA_LIST_INCONSISTENT },
|
||||||
{ "NT_STATUS_FILE_IS_OFFLINE", NT_STATUS_FILE_IS_OFFLINE },
|
{ "NT_STATUS_FILE_IS_OFFLINE", NT_STATUS_FILE_IS_OFFLINE },
|
||||||
{ "NT_STATUS_NO_MORE_ENTRIES", NT_STATUS_NO_MORE_ENTRIES },
|
{ "NT_STATUS_NO_MORE_ENTRIES", NT_STATUS_NO_MORE_ENTRIES },
|
||||||
|
{ "STATUS_SOME_UNMAPPED", STATUS_SOME_UNMAPPED },
|
||||||
{ NULL, NT_STATUS(0) }
|
{ NULL, NT_STATUS(0) }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -187,7 +187,6 @@ static NTSTATUS name_to_sid(struct winbindd_domain *domain,
|
|||||||
NTSTATUS status;
|
NTSTATUS status;
|
||||||
DOM_SID *sids = NULL;
|
DOM_SID *sids = NULL;
|
||||||
uint32 *types = NULL;
|
uint32 *types = NULL;
|
||||||
int num_sids;
|
|
||||||
const char *full_name;
|
const char *full_name;
|
||||||
|
|
||||||
if (!(mem_ctx = talloc_init_named("name_to_sid[rpc] for [%s]\\[%s]", domain->name, name))) {
|
if (!(mem_ctx = talloc_init_named("name_to_sid[rpc] for [%s]\\[%s]", domain->name, name))) {
|
||||||
@ -209,7 +208,7 @@ static NTSTATUS name_to_sid(struct winbindd_domain *domain,
|
|||||||
}
|
}
|
||||||
|
|
||||||
status = cli_lsa_lookup_names(hnd->cli, mem_ctx, &hnd->pol, 1,
|
status = cli_lsa_lookup_names(hnd->cli, mem_ctx, &hnd->pol, 1,
|
||||||
&full_name, &sids, &types, &num_sids);
|
&full_name, &sids, &types);
|
||||||
|
|
||||||
/* Return rid and type if lookup successful */
|
/* Return rid and type if lookup successful */
|
||||||
if (NT_STATUS_IS_OK(status)) {
|
if (NT_STATUS_IS_OK(status)) {
|
||||||
@ -234,15 +233,13 @@ static NTSTATUS sid_to_name(struct winbindd_domain *domain,
|
|||||||
char **domains;
|
char **domains;
|
||||||
char **names;
|
char **names;
|
||||||
uint32 *types;
|
uint32 *types;
|
||||||
int num_names;
|
|
||||||
NTSTATUS status;
|
NTSTATUS status;
|
||||||
|
|
||||||
if (!(hnd = cm_get_lsa_handle(domain->name)))
|
if (!(hnd = cm_get_lsa_handle(domain->name)))
|
||||||
return NT_STATUS_UNSUCCESSFUL;
|
return NT_STATUS_UNSUCCESSFUL;
|
||||||
|
|
||||||
status = cli_lsa_lookup_sids(hnd->cli, mem_ctx, &hnd->pol,
|
status = cli_lsa_lookup_sids(hnd->cli, mem_ctx, &hnd->pol,
|
||||||
1, sid, &domains, &names, &types,
|
1, sid, &domains, &names, &types);
|
||||||
&num_names);
|
|
||||||
|
|
||||||
if (NT_STATUS_IS_OK(status)) {
|
if (NT_STATUS_IS_OK(status)) {
|
||||||
*type = types[0];
|
*type = types[0];
|
||||||
|
@ -78,7 +78,7 @@ static NTSTATUS cmd_lsa_lookup_names(struct cli_state *cli,
|
|||||||
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
|
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
|
||||||
DOM_SID *sids;
|
DOM_SID *sids;
|
||||||
uint32 *types;
|
uint32 *types;
|
||||||
int num_names, i;
|
int i;
|
||||||
|
|
||||||
if (argc == 1) {
|
if (argc == 1) {
|
||||||
printf("Usage: %s [name1 [name2 [...]]]\n", argv[0]);
|
printf("Usage: %s [name1 [name2 [...]]]\n", argv[0]);
|
||||||
@ -93,15 +93,15 @@ static NTSTATUS cmd_lsa_lookup_names(struct cli_state *cli,
|
|||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
result = cli_lsa_lookup_names(cli, mem_ctx, &pol, argc - 1,
|
result = cli_lsa_lookup_names(cli, mem_ctx, &pol, argc - 1,
|
||||||
(const char**)(argv + 1), &sids,
|
(const char**)(argv + 1), &sids, &types);
|
||||||
&types, &num_names);
|
|
||||||
|
|
||||||
if (!NT_STATUS_IS_OK(result))
|
if (!NT_STATUS_IS_OK(result) &&
|
||||||
|
NT_STATUS_V(result) != NT_STATUS_V(STATUS_SOME_UNMAPPED))
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
/* Print results */
|
/* Print results */
|
||||||
|
|
||||||
for (i = 0; i < num_names; i++) {
|
for (i = 0; i < (argc - 1); i++) {
|
||||||
fstring sid_str;
|
fstring sid_str;
|
||||||
|
|
||||||
sid_to_string(sid_str, &sids[i]);
|
sid_to_string(sid_str, &sids[i]);
|
||||||
@ -124,7 +124,7 @@ static NTSTATUS cmd_lsa_lookup_sids(struct cli_state *cli, TALLOC_CTX *mem_ctx,
|
|||||||
char **domains;
|
char **domains;
|
||||||
char **names;
|
char **names;
|
||||||
uint32 *types;
|
uint32 *types;
|
||||||
int num_names, i;
|
int i;
|
||||||
|
|
||||||
if (argc == 1) {
|
if (argc == 1) {
|
||||||
printf("Usage: %s [sid1 [sid2 [...]]]\n", argv[0]);
|
printf("Usage: %s [sid1 [sid2 [...]]]\n", argv[0]);
|
||||||
@ -147,20 +147,21 @@ static NTSTATUS cmd_lsa_lookup_sids(struct cli_state *cli, TALLOC_CTX *mem_ctx,
|
|||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < argc - 1; i++)
|
for (i = 0; i < (argc - 1); i++)
|
||||||
string_to_sid(&sids[i], argv[i + 1]);
|
string_to_sid(&sids[i], argv[i + 1]);
|
||||||
|
|
||||||
/* Lookup the SIDs */
|
/* Lookup the SIDs */
|
||||||
|
|
||||||
result = cli_lsa_lookup_sids(cli, mem_ctx, &pol, argc - 1, sids,
|
result = cli_lsa_lookup_sids(cli, mem_ctx, &pol, argc - 1, sids,
|
||||||
&domains, &names, &types, &num_names);
|
&domains, &names, &types);
|
||||||
|
|
||||||
if (!NT_STATUS_IS_OK(result))
|
if (!NT_STATUS_IS_OK(result) &&
|
||||||
|
NT_STATUS_V(result) != NT_STATUS_V(STATUS_SOME_UNMAPPED))
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
/* Print results */
|
/* Print results */
|
||||||
|
|
||||||
for (i = 0; i < num_names; i++) {
|
for (i = 0; i < (argc - 1); i++) {
|
||||||
fstring sid_str;
|
fstring sid_str;
|
||||||
|
|
||||||
sid_to_string(sid_str, &sids[i]);
|
sid_to_string(sid_str, &sids[i]);
|
||||||
|
@ -108,7 +108,6 @@ static void SidToString(fstring str, DOM_SID *sid)
|
|||||||
char **domains = NULL;
|
char **domains = NULL;
|
||||||
char **names = NULL;
|
char **names = NULL;
|
||||||
uint32 *types = NULL;
|
uint32 *types = NULL;
|
||||||
int num_names;
|
|
||||||
|
|
||||||
sid_to_string(str, sid);
|
sid_to_string(str, sid);
|
||||||
|
|
||||||
@ -118,8 +117,8 @@ static void SidToString(fstring str, DOM_SID *sid)
|
|||||||
|
|
||||||
if (!cacls_open_policy_hnd() ||
|
if (!cacls_open_policy_hnd() ||
|
||||||
!NT_STATUS_IS_OK(cli_lsa_lookup_sids(&lsa_cli, lsa_cli.mem_ctx,
|
!NT_STATUS_IS_OK(cli_lsa_lookup_sids(&lsa_cli, lsa_cli.mem_ctx,
|
||||||
&pol, 1, sid, &domains, &names,
|
&pol, 1, sid, &domains,
|
||||||
&types, &num_names)) ||
|
&names, &types)) ||
|
||||||
!domains || !domains[0] || !names || !names[0]) {
|
!domains || !domains[0] || !names || !names[0]) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -137,7 +136,6 @@ static BOOL StringToSid(DOM_SID *sid, const char *str)
|
|||||||
{
|
{
|
||||||
uint32 *types = NULL;
|
uint32 *types = NULL;
|
||||||
DOM_SID *sids = NULL;
|
DOM_SID *sids = NULL;
|
||||||
int num_sids;
|
|
||||||
BOOL result = True;
|
BOOL result = True;
|
||||||
|
|
||||||
if (strncmp(str, "S-", 2) == 0) {
|
if (strncmp(str, "S-", 2) == 0) {
|
||||||
@ -145,9 +143,9 @@ static BOOL StringToSid(DOM_SID *sid, const char *str)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!cacls_open_policy_hnd() ||
|
if (!cacls_open_policy_hnd() ||
|
||||||
!NT_STATUS_IS_OK(cli_lsa_lookup_names(&lsa_cli, lsa_cli.mem_ctx, &pol, 1,
|
!NT_STATUS_IS_OK(cli_lsa_lookup_names(&lsa_cli, lsa_cli.mem_ctx,
|
||||||
&str,
|
&pol, 1, &str, &sids,
|
||||||
&sids, &types, &num_sids))) {
|
&types))) {
|
||||||
result = False;
|
result = False;
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user