mirror of
https://github.com/samba-team/samba.git
synced 2025-01-11 05:18:09 +03:00
added samr_LookupNames() and test code
(This used to be commit f8397cbc85
)
This commit is contained in:
parent
cde87e39c6
commit
308cc429eb
@ -264,18 +264,25 @@
|
||||
|
||||
typedef struct {
|
||||
uint32 count;
|
||||
[size_is(count)] uint32 *rids;
|
||||
} samr_Rids;
|
||||
[size_is(count)] uint32 *ids;
|
||||
} samr_Ids;
|
||||
|
||||
NTSTATUS samr_GetAliasMembership(
|
||||
[in,ref] policy_handle *handle,
|
||||
[in] samr_Sids *sids,
|
||||
[out] samr_Rids *rids
|
||||
[out] samr_Ids *rids
|
||||
);
|
||||
|
||||
/************************/
|
||||
/* Function 0x11 */
|
||||
NTSTATUS samr_LOOKUP_NAMES();
|
||||
|
||||
NTSTATUS samr_LookupNames(
|
||||
[in,ref] policy_handle *handle,
|
||||
[in] uint32 num_names,
|
||||
[in,ref,size_is(1000),length_is(num_names)] samr_Name *names,
|
||||
[out] samr_Ids rids,
|
||||
[out] samr_Ids types
|
||||
);
|
||||
|
||||
/************************/
|
||||
/* Function 0x12 */
|
||||
|
@ -65,6 +65,9 @@ struct ndr_push {
|
||||
uint32 offset;
|
||||
TALLOC_CTX *mem_ctx;
|
||||
|
||||
/* this is used to ensure we generate unique reference IDs */
|
||||
uint32 ptr_count;
|
||||
|
||||
/* this points at a list of offsets to the structures being processed.
|
||||
The first element in the list is the current structure */
|
||||
struct ndr_ofs_list *ofs_list;
|
||||
|
@ -151,6 +151,7 @@ struct ndr_push *ndr_push_init(void)
|
||||
return NULL;
|
||||
}
|
||||
ndr->offset = 0;
|
||||
ndr->ptr_count = 0;
|
||||
|
||||
return ndr;
|
||||
}
|
||||
|
@ -308,7 +308,15 @@ NTSTATUS ndr_push_length4_end(struct ndr_push *ndr, struct ndr_push_save *save)
|
||||
*/
|
||||
NTSTATUS ndr_push_ptr(struct ndr_push *ndr, const void *p)
|
||||
{
|
||||
return ndr_push_uint32(ndr, p?0xaabbccdd:0);
|
||||
uint32 ptr = 0;
|
||||
if (p) {
|
||||
/* we do this to ensure that we generate unique ref ids,
|
||||
which means we can handle the case where a MS programmer
|
||||
forgot to mark a pointer as unique */
|
||||
ndr->ptr_count++;
|
||||
ptr = 0xaabbcc00 + ndr->ptr_count;
|
||||
}
|
||||
return ndr_push_uint32(ndr, ptr);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -138,10 +138,6 @@ done:
|
||||
|
||||
NTSTATUS ndr_pull_security_descriptor(struct ndr_pull *ndr, int ndr_flags, struct security_descriptor *r)
|
||||
{
|
||||
uint32 _ptr_owner_sid;
|
||||
uint32 _ptr_group_sid;
|
||||
uint32 _ptr_sacl;
|
||||
uint32 _ptr_dacl;
|
||||
NDR_CHECK(ndr_pull_struct_start(ndr));
|
||||
if (!(ndr_flags & NDR_SCALARS)) goto buffers;
|
||||
NDR_CHECK(ndr_pull_align(ndr, 4));
|
||||
|
@ -176,8 +176,16 @@ NTSTATUS ndr_push_samr_GetAliasMembership(struct ndr_push *ndr, struct samr_GetA
|
||||
return NT_STATUS_OK;
|
||||
}
|
||||
|
||||
NTSTATUS ndr_push_samr_LOOKUP_NAMES(struct ndr_push *ndr, struct samr_LOOKUP_NAMES *r)
|
||||
NTSTATUS ndr_push_samr_LookupNames(struct ndr_push *ndr, struct samr_LookupNames *r)
|
||||
{
|
||||
NDR_CHECK(ndr_push_policy_handle(ndr, r->in.handle));
|
||||
NDR_CHECK(ndr_push_uint32(ndr, r->in.num_names));
|
||||
if (r->in.names) {
|
||||
NDR_CHECK(ndr_push_uint32(ndr, 1000));
|
||||
NDR_CHECK(ndr_push_uint32(ndr, 0));
|
||||
NDR_CHECK(ndr_push_uint32(ndr, r->in.num_names));
|
||||
NDR_CHECK(ndr_push_array(ndr, NDR_SCALARS|NDR_BUFFERS, r->in.names, sizeof(r->in.names[0]), r->in.num_names, (ndr_push_flags_fn_t)ndr_push_samr_Name));
|
||||
}
|
||||
|
||||
return NT_STATUS_OK;
|
||||
}
|
||||
@ -1110,23 +1118,23 @@ NTSTATUS ndr_pull_samr_EnumDomainAliases(struct ndr_pull *ndr, struct samr_EnumD
|
||||
return NT_STATUS_OK;
|
||||
}
|
||||
|
||||
NTSTATUS ndr_pull_samr_Rids(struct ndr_pull *ndr, int ndr_flags, struct samr_Rids *r)
|
||||
NTSTATUS ndr_pull_samr_Ids(struct ndr_pull *ndr, int ndr_flags, struct samr_Ids *r)
|
||||
{
|
||||
uint32 _ptr_rids;
|
||||
uint32 _ptr_ids;
|
||||
NDR_CHECK(ndr_pull_struct_start(ndr));
|
||||
if (!(ndr_flags & NDR_SCALARS)) goto buffers;
|
||||
NDR_CHECK(ndr_pull_align(ndr, 4));
|
||||
NDR_CHECK(ndr_pull_uint32(ndr, &r->count));
|
||||
NDR_CHECK(ndr_pull_uint32(ndr, &_ptr_rids));
|
||||
if (_ptr_rids) {
|
||||
NDR_ALLOC(ndr, r->rids);
|
||||
NDR_CHECK(ndr_pull_uint32(ndr, &_ptr_ids));
|
||||
if (_ptr_ids) {
|
||||
NDR_ALLOC(ndr, r->ids);
|
||||
} else {
|
||||
r->rids = NULL;
|
||||
r->ids = NULL;
|
||||
}
|
||||
ndr_pull_struct_end(ndr);
|
||||
buffers:
|
||||
if (!(ndr_flags & NDR_BUFFERS)) goto done;
|
||||
if (r->rids) {
|
||||
if (r->ids) {
|
||||
{
|
||||
uint32 _array_size;
|
||||
NDR_CHECK(ndr_pull_uint32(ndr, &_array_size));
|
||||
@ -1134,8 +1142,8 @@ buffers:
|
||||
return ndr_pull_error(ndr, NDR_ERR_ARRAY_SIZE, "Bad array size %u should be %u", _array_size, r->count);
|
||||
}
|
||||
}
|
||||
NDR_ALLOC_N_SIZE(ndr, r->rids, r->count, sizeof(r->rids[0]));
|
||||
NDR_CHECK(ndr_pull_array_uint32(ndr, NDR_SCALARS|NDR_BUFFERS, r->rids, r->count));
|
||||
NDR_ALLOC_N_SIZE(ndr, r->ids, r->count, sizeof(r->ids[0]));
|
||||
NDR_CHECK(ndr_pull_array_uint32(ndr, NDR_SCALARS|NDR_BUFFERS, r->ids, r->count));
|
||||
}
|
||||
done:
|
||||
return NT_STATUS_OK;
|
||||
@ -1151,15 +1159,17 @@ NTSTATUS ndr_pull_samr_GetAliasMembership(struct ndr_pull *ndr, struct samr_GetA
|
||||
r->out.rids = NULL;
|
||||
}
|
||||
if (r->out.rids) {
|
||||
NDR_CHECK(ndr_pull_samr_Rids(ndr, NDR_SCALARS|NDR_BUFFERS, r->out.rids));
|
||||
NDR_CHECK(ndr_pull_samr_Ids(ndr, NDR_SCALARS|NDR_BUFFERS, r->out.rids));
|
||||
}
|
||||
NDR_CHECK(ndr_pull_NTSTATUS(ndr, &r->out.result));
|
||||
|
||||
return NT_STATUS_OK;
|
||||
}
|
||||
|
||||
NTSTATUS ndr_pull_samr_LOOKUP_NAMES(struct ndr_pull *ndr, struct samr_LOOKUP_NAMES *r)
|
||||
NTSTATUS ndr_pull_samr_LookupNames(struct ndr_pull *ndr, struct samr_LookupNames *r)
|
||||
{
|
||||
NDR_CHECK(ndr_pull_samr_Ids(ndr, NDR_SCALARS|NDR_BUFFERS, &r->out.rids));
|
||||
NDR_CHECK(ndr_pull_samr_Ids(ndr, NDR_SCALARS|NDR_BUFFERS, &r->out.types));
|
||||
NDR_CHECK(ndr_pull_NTSTATUS(ndr, &r->out.result));
|
||||
|
||||
return NT_STATUS_OK;
|
||||
@ -3099,15 +3109,15 @@ void ndr_print_samr_Sids(struct ndr_print *ndr, const char *name, struct samr_Si
|
||||
ndr->depth--;
|
||||
}
|
||||
|
||||
void ndr_print_samr_Rids(struct ndr_print *ndr, const char *name, struct samr_Rids *r)
|
||||
void ndr_print_samr_Ids(struct ndr_print *ndr, const char *name, struct samr_Ids *r)
|
||||
{
|
||||
ndr_print_struct(ndr, name, "samr_Rids");
|
||||
ndr_print_struct(ndr, name, "samr_Ids");
|
||||
ndr->depth++;
|
||||
ndr_print_uint32(ndr, "count", r->count);
|
||||
ndr_print_ptr(ndr, "rids", r->rids);
|
||||
ndr_print_ptr(ndr, "ids", r->ids);
|
||||
ndr->depth++;
|
||||
if (r->rids) {
|
||||
ndr_print_array_uint32(ndr, "rids", r->rids, r->count);
|
||||
if (r->ids) {
|
||||
ndr_print_array_uint32(ndr, "ids", r->ids, r->count);
|
||||
}
|
||||
ndr->depth--;
|
||||
ndr->depth--;
|
||||
@ -3138,7 +3148,7 @@ void ndr_print_samr_GetAliasMembership(struct ndr_print *ndr, const char *name,
|
||||
ndr_print_ptr(ndr, "rids", r->out.rids);
|
||||
ndr->depth++;
|
||||
if (r->out.rids) {
|
||||
ndr_print_samr_Rids(ndr, "rids", r->out.rids);
|
||||
ndr_print_samr_Ids(ndr, "rids", r->out.rids);
|
||||
}
|
||||
ndr->depth--;
|
||||
ndr_print_NTSTATUS(ndr, "result", &r->out.result);
|
||||
@ -3147,18 +3157,29 @@ void ndr_print_samr_GetAliasMembership(struct ndr_print *ndr, const char *name,
|
||||
ndr->depth--;
|
||||
}
|
||||
|
||||
void ndr_print_samr_LOOKUP_NAMES(struct ndr_print *ndr, const char *name, int flags, struct samr_LOOKUP_NAMES *r)
|
||||
void ndr_print_samr_LookupNames(struct ndr_print *ndr, const char *name, int flags, struct samr_LookupNames *r)
|
||||
{
|
||||
ndr_print_struct(ndr, name, "samr_LOOKUP_NAMES");
|
||||
ndr_print_struct(ndr, name, "samr_LookupNames");
|
||||
ndr->depth++;
|
||||
if (flags & NDR_IN) {
|
||||
ndr_print_struct(ndr, "in", "samr_LOOKUP_NAMES");
|
||||
ndr_print_struct(ndr, "in", "samr_LookupNames");
|
||||
ndr->depth++;
|
||||
ndr_print_ptr(ndr, "handle", r->in.handle);
|
||||
ndr->depth++;
|
||||
ndr_print_policy_handle(ndr, "handle", r->in.handle);
|
||||
ndr->depth--;
|
||||
ndr_print_uint32(ndr, "num_names", r->in.num_names);
|
||||
ndr_print_ptr(ndr, "names", r->in.names);
|
||||
ndr->depth++;
|
||||
ndr_print_array(ndr, "names", r->in.names, sizeof(r->in.names[0]), r->in.num_names, (ndr_print_fn_t)ndr_print_samr_Name);
|
||||
ndr->depth--;
|
||||
ndr->depth--;
|
||||
}
|
||||
if (flags & NDR_OUT) {
|
||||
ndr_print_struct(ndr, "out", "samr_LOOKUP_NAMES");
|
||||
ndr_print_struct(ndr, "out", "samr_LookupNames");
|
||||
ndr->depth++;
|
||||
ndr_print_samr_Ids(ndr, "rids", &r->out.rids);
|
||||
ndr_print_samr_Ids(ndr, "types", &r->out.types);
|
||||
ndr_print_NTSTATUS(ndr, "result", &r->out.result);
|
||||
ndr->depth--;
|
||||
}
|
||||
|
@ -21,7 +21,7 @@
|
||||
#define DCERPC_SAMR_CREATE_DOM_ALIAS 14
|
||||
#define DCERPC_SAMR_ENUMDOMAINALIASES 15
|
||||
#define DCERPC_SAMR_GETALIASMEMBERSHIP 16
|
||||
#define DCERPC_SAMR_LOOKUP_NAMES 17
|
||||
#define DCERPC_SAMR_LOOKUPNAMES 17
|
||||
#define DCERPC_SAMR_LOOKUP_RIDS 18
|
||||
#define DCERPC_SAMR_OPENGROUP 19
|
||||
#define DCERPC_SAMR_QUERYGROUPINFO 20
|
||||
@ -404,9 +404,9 @@ struct samr_Sids {
|
||||
struct dom_sid2 *sids;
|
||||
};
|
||||
|
||||
struct samr_Rids {
|
||||
struct samr_Ids {
|
||||
uint32 count;
|
||||
uint32 *rids;
|
||||
uint32 *ids;
|
||||
};
|
||||
|
||||
struct samr_GetAliasMembership {
|
||||
@ -416,17 +416,22 @@ struct samr_GetAliasMembership {
|
||||
} in;
|
||||
|
||||
struct {
|
||||
struct samr_Rids *rids;
|
||||
struct samr_Ids *rids;
|
||||
NTSTATUS result;
|
||||
} out;
|
||||
|
||||
};
|
||||
|
||||
struct samr_LOOKUP_NAMES {
|
||||
struct samr_LookupNames {
|
||||
struct {
|
||||
struct policy_handle *handle;
|
||||
uint32 num_names;
|
||||
struct samr_Name *names;
|
||||
} in;
|
||||
|
||||
struct {
|
||||
struct samr_Ids rids;
|
||||
struct samr_Ids types;
|
||||
NTSTATUS result;
|
||||
} out;
|
||||
|
||||
|
@ -1064,8 +1064,6 @@ done:
|
||||
|
||||
NTSTATUS ndr_pull_spoolss_PrinterInfo2(struct ndr_pull *ndr, int ndr_flags, struct spoolss_PrinterInfo2 *r)
|
||||
{
|
||||
uint32 _ptr_devmode;
|
||||
uint32 _ptr_secdesc;
|
||||
NDR_CHECK(ndr_pull_struct_start(ndr));
|
||||
if (!(ndr_flags & NDR_SCALARS)) goto buffers;
|
||||
NDR_CHECK(ndr_pull_align(ndr, 4));
|
||||
|
@ -360,21 +360,21 @@ NTSTATUS dcerpc_samr_GetAliasMembership(struct dcerpc_pipe *p, TALLOC_CTX *mem_c
|
||||
return status;
|
||||
}
|
||||
|
||||
NTSTATUS dcerpc_samr_LOOKUP_NAMES(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct samr_LOOKUP_NAMES *r)
|
||||
NTSTATUS dcerpc_samr_LookupNames(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct samr_LookupNames *r)
|
||||
{
|
||||
NTSTATUS status;
|
||||
|
||||
if (p->flags & DCERPC_DEBUG_PRINT_IN) {
|
||||
NDR_PRINT_IN_DEBUG(samr_LOOKUP_NAMES, r);
|
||||
NDR_PRINT_IN_DEBUG(samr_LookupNames, r);
|
||||
}
|
||||
|
||||
status = dcerpc_ndr_request(p, DCERPC_SAMR_LOOKUP_NAMES, mem_ctx,
|
||||
(ndr_push_fn_t) ndr_push_samr_LOOKUP_NAMES,
|
||||
(ndr_pull_fn_t) ndr_pull_samr_LOOKUP_NAMES,
|
||||
status = dcerpc_ndr_request(p, DCERPC_SAMR_LOOKUPNAMES, mem_ctx,
|
||||
(ndr_push_fn_t) ndr_push_samr_LookupNames,
|
||||
(ndr_pull_fn_t) ndr_pull_samr_LookupNames,
|
||||
r);
|
||||
|
||||
if (NT_STATUS_IS_OK(status) && (p->flags & DCERPC_DEBUG_PRINT_OUT)) {
|
||||
NDR_PRINT_OUT_DEBUG(samr_LOOKUP_NAMES, r);
|
||||
NDR_PRINT_OUT_DEBUG(samr_LookupNames, r);
|
||||
}
|
||||
if (NT_STATUS_IS_OK(status)) status = r->out.result;
|
||||
|
||||
|
@ -22,6 +22,9 @@
|
||||
#include "includes.h"
|
||||
|
||||
|
||||
static BOOL test_QueryUserInfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
|
||||
struct policy_handle *handle);
|
||||
|
||||
/*
|
||||
this makes the debug code display the right thing
|
||||
*/
|
||||
@ -69,6 +72,22 @@ static BOOL test_QuerySecurity(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
|
||||
return True;
|
||||
}
|
||||
|
||||
static BOOL test_user_ops(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
|
||||
struct policy_handle *handle)
|
||||
{
|
||||
BOOL ret = True;
|
||||
|
||||
if (!test_QuerySecurity(p, mem_ctx, handle)) {
|
||||
ret = False;
|
||||
}
|
||||
|
||||
if (!test_QueryUserInfo(p, mem_ctx, handle)) {
|
||||
ret = False;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static BOOL test_CreateUser(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
|
||||
struct policy_handle *handle)
|
||||
@ -79,6 +98,7 @@ static BOOL test_CreateUser(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
|
||||
struct policy_handle acct_handle;
|
||||
uint32 rid;
|
||||
struct samr_Name name;
|
||||
BOOL ret = True;
|
||||
|
||||
init_samr_Name(&name, "samrtorturetest");
|
||||
|
||||
@ -104,6 +124,10 @@ static BOOL test_CreateUser(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
|
||||
}
|
||||
|
||||
|
||||
if (!test_user_ops(p, mem_ctx, &acct_handle)) {
|
||||
ret = False;
|
||||
}
|
||||
|
||||
printf("Testing DeleteUser\n");
|
||||
|
||||
d.in.handle = &acct_handle;
|
||||
@ -112,10 +136,10 @@ static BOOL test_CreateUser(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
|
||||
status = dcerpc_samr_DeleteUser(p, mem_ctx, &d);
|
||||
if (!NT_STATUS_IS_OK(status)) {
|
||||
printf("DeleteUser failed - %s\n", nt_errstr(status));
|
||||
return False;
|
||||
ret = False;
|
||||
}
|
||||
|
||||
return True;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static BOOL test_QueryAliasInfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
|
||||
@ -313,6 +337,7 @@ static BOOL test_EnumDomainUsers(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
|
||||
uint32 resume_handle=0;
|
||||
int i;
|
||||
BOOL ret = True;
|
||||
struct samr_LookupNames n;
|
||||
|
||||
printf("Testing EnumDomainUsers\n");
|
||||
|
||||
@ -332,12 +357,29 @@ static BOOL test_EnumDomainUsers(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
|
||||
return False;
|
||||
}
|
||||
|
||||
if (r.out.sam->count == 0) {
|
||||
return True;
|
||||
}
|
||||
|
||||
for (i=0;i<r.out.sam->count;i++) {
|
||||
if (!test_OpenUser(p, mem_ctx, handle, r.out.sam->entries[i].idx)) {
|
||||
ret = False;
|
||||
}
|
||||
}
|
||||
|
||||
printf("Testing LookupNames\n");
|
||||
n.in.handle = handle;
|
||||
n.in.num_names = r.out.sam->count;
|
||||
n.in.names = talloc(mem_ctx, r.out.sam->count * sizeof(struct samr_Name));
|
||||
for (i=0;i<r.out.sam->count;i++) {
|
||||
n.in.names[i] = r.out.sam->entries[i].name;
|
||||
}
|
||||
status = dcerpc_samr_LookupNames(p, mem_ctx, &n);
|
||||
if (!NT_STATUS_IS_OK(status)) {
|
||||
printf("LookupNames failed - %s\n", nt_errstr(status));
|
||||
return False;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user