From 946d358646977e265cb36b34324a1145c6121870 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 9 Nov 2003 02:21:24 +0000 Subject: lsa_LookupNames now works (This used to be commit fba3a7ad22edcbe394861e42b5e5c53709e9d5fe) --- source4/librpc/idl/lsa.idl | 23 +++++++++- source4/librpc/ndr/ndr_basic.c | 29 ++++++++++++- source4/librpc/ndr/ndr_lsa.c | 97 +++++++++++++++++++++++++++++++++++++++++- source4/librpc/ndr/ndr_lsa.h | 30 +++++++++++++ source4/librpc/rpc/rpc_lsa.c | 20 +++++++++ 5 files changed, 195 insertions(+), 4 deletions(-) (limited to 'source4/librpc') diff --git a/source4/librpc/idl/lsa.idl b/source4/librpc/idl/lsa.idl index c807f19d49..886b8fd225 100644 --- a/source4/librpc/idl/lsa.idl +++ b/source4/librpc/idl/lsa.idl @@ -57,7 +57,7 @@ typedef struct { uint16 name_len; uint16 name_size; - unistr *name; + unistr_noterm *name; } lsa_Name; typedef struct { @@ -90,4 +90,25 @@ [in] uint16 level, [in,out,ref] uint32 *count ); + + typedef struct { + uint16 sid_type; + uint32 rid; + uint32 sid_index; + } lsa_TranslatedSid; + + typedef struct { + uint32 count; + [size_is(count)] lsa_TranslatedSid *sids; + } lsa_TransSidArray; + + NTSTATUS lsa_LookupNames ( + [in,ref] policy_handle *handle, + [in] uint32 num_names, + [in,ref,size_is(num_names)] lsa_Name *names, + [out] lsa_RefDomainList *domains, + [in,out,ref] lsa_TransSidArray *sids, + [in] uint16 level, + [in,out,ref] uint32 *count + ); } diff --git a/source4/librpc/ndr/ndr_basic.c b/source4/librpc/ndr/ndr_basic.c index 3e6d0b30e6..6ada49997f 100644 --- a/source4/librpc/ndr/ndr_basic.c +++ b/source4/librpc/ndr/ndr_basic.c @@ -221,7 +221,7 @@ 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?1:0); + return ndr_push_uint32(ndr, p?0xaabbccdd:0); } /* @@ -242,6 +242,25 @@ NTSTATUS ndr_push_unistr(struct ndr_push *ndr, const char *s) return NT_STATUS_OK; } +/* + push a comformant, variable ucs2 string onto the wire from a C string + don't send the null +*/ +NTSTATUS ndr_push_unistr_noterm(struct ndr_push *ndr, const char *s) +{ + char *ws; + ssize_t len; + len = push_ucs2_talloc(ndr->mem_ctx, (smb_ucs2_t **)&ws, s); + if (len == -1) { + return NT_STATUS_INVALID_PARAMETER; + } + NDR_CHECK(ndr_push_uint32(ndr, len/2 - 1)); + NDR_CHECK(ndr_push_uint32(ndr, 0)); + NDR_CHECK(ndr_push_uint32(ndr, len/2 - 1)); + NDR_CHECK(ndr_push_bytes(ndr, ws, len - 2)); + return NT_STATUS_OK; +} + /* pull a comformant, variable ucs2 string from the wire into a C string */ @@ -268,6 +287,14 @@ NTSTATUS ndr_pull_unistr(struct ndr_pull *ndr, const char **s) return NT_STATUS_OK; } +/* + pull a comformant, variable ucs2 string from the wire into a C string +*/ +NTSTATUS ndr_pull_unistr_noterm(struct ndr_pull *ndr, const char **s) +{ + return ndr_pull_unistr(ndr, s); +} + /* push a 4 byte offset pointer, remembering where we are so we can later fill in the correct value diff --git a/source4/librpc/ndr/ndr_lsa.c b/source4/librpc/ndr/ndr_lsa.c index 8e42b3786b..12b981c1e7 100644 --- a/source4/librpc/ndr/ndr_lsa.c +++ b/source4/librpc/ndr/ndr_lsa.c @@ -267,7 +267,7 @@ static NTSTATUS ndr_push_lsa_Name(struct ndr_push *ndr, int ndr_flags, struct ls buffers: if (!(ndr_flags & NDR_BUFFERS)) goto done; if (r->name) { - NDR_CHECK(ndr_push_unistr(ndr, r->name)); + NDR_CHECK(ndr_push_unistr_noterm(ndr, r->name)); } done: return NT_STATUS_OK; @@ -288,7 +288,7 @@ static NTSTATUS ndr_pull_lsa_Name(struct ndr_pull *ndr, int ndr_flags, struct ls buffers: if (!(ndr_flags & NDR_BUFFERS)) goto done; if (r->name) { - NDR_CHECK(ndr_pull_unistr(ndr, &r->name)); + NDR_CHECK(ndr_pull_unistr_noterm(ndr, &r->name)); } done: return NT_STATUS_OK; @@ -457,3 +457,96 @@ NTSTATUS ndr_pull_lsa_LookupSids(struct ndr_pull *ndr, struct lsa_LookupSids *r) return NT_STATUS_OK; } +static NTSTATUS ndr_push_lsa_TranslatedSid(struct ndr_push *ndr, int ndr_flags, struct lsa_TranslatedSid *r) +{ + if (!(ndr_flags & NDR_SCALARS)) goto buffers; + NDR_CHECK(ndr_push_uint16(ndr, r->sid_type)); + NDR_CHECK(ndr_push_uint32(ndr, r->rid)); + NDR_CHECK(ndr_push_uint32(ndr, r->sid_index)); +buffers: + if (!(ndr_flags & NDR_BUFFERS)) goto done; +done: + return NT_STATUS_OK; +} + +static NTSTATUS ndr_pull_lsa_TranslatedSid(struct ndr_pull *ndr, int ndr_flags, struct lsa_TranslatedSid *r) +{ + if (!(ndr_flags & NDR_SCALARS)) goto buffers; + NDR_CHECK(ndr_pull_uint16(ndr, &r->sid_type)); + NDR_CHECK(ndr_pull_uint32(ndr, &r->rid)); + NDR_CHECK(ndr_pull_uint32(ndr, &r->sid_index)); +buffers: + if (!(ndr_flags & NDR_BUFFERS)) goto done; +done: + return NT_STATUS_OK; +} + +static NTSTATUS ndr_push_lsa_TransSidArray(struct ndr_push *ndr, int ndr_flags, struct lsa_TransSidArray *r) +{ + if (!(ndr_flags & NDR_SCALARS)) goto buffers; + NDR_CHECK(ndr_push_uint32(ndr, r->count)); + NDR_CHECK(ndr_push_ptr(ndr, r->sids)); +buffers: + if (!(ndr_flags & NDR_BUFFERS)) goto done; + if (r->sids) { + NDR_CHECK(ndr_push_array(ndr, ndr_flags, r->sids, sizeof(r->sids[0]), r->count, (ndr_push_flags_fn_t)ndr_push_lsa_TranslatedSid)); + } +done: + return NT_STATUS_OK; +} + +static NTSTATUS ndr_pull_lsa_TransSidArray(struct ndr_pull *ndr, int ndr_flags, struct lsa_TransSidArray *r) +{ + uint32 _ptr_sids; + if (!(ndr_flags & NDR_SCALARS)) goto buffers; + NDR_CHECK(ndr_pull_uint32(ndr, &r->count)); + NDR_CHECK(ndr_pull_uint32(ndr, &_ptr_sids)); + if (_ptr_sids) { + NDR_ALLOC(ndr, r->sids); + } else { + r->sids = NULL; + } +buffers: + if (!(ndr_flags & NDR_BUFFERS)) goto done; + if (r->sids) { + NDR_CHECK(ndr_pull_array(ndr, ndr_flags, (void **)&r->sids, sizeof(r->sids[0]), r->count, (ndr_pull_flags_fn_t)ndr_pull_lsa_TranslatedSid)); + } +done: + return NT_STATUS_OK; +} + +NTSTATUS ndr_push_lsa_LookupNames(struct ndr_push *ndr, struct lsa_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) { + int ndr_flags = NDR_SCALARS|NDR_BUFFERS; + NDR_CHECK(ndr_push_array(ndr, ndr_flags, r->in.names, sizeof(r->in.names[0]), r->in.num_names, (ndr_push_flags_fn_t)ndr_push_lsa_Name)); + } + NDR_CHECK(ndr_push_lsa_TransSidArray(ndr, NDR_SCALARS|NDR_BUFFERS, r->in.sids)); + NDR_CHECK(ndr_push_uint16(ndr, r->in.level)); + NDR_CHECK(ndr_push_uint32(ndr, *r->in.count)); + + return NT_STATUS_OK; +} + +NTSTATUS ndr_pull_lsa_LookupNames(struct ndr_pull *ndr, struct lsa_LookupNames *r) +{ + uint32 _ptr_domains; + NDR_ALLOC(ndr, r->out.domains); + NDR_CHECK(ndr_pull_uint32(ndr, &_ptr_domains)); + if (_ptr_domains) { + NDR_ALLOC(ndr, r->out.domains); + } else { + r->out.domains = NULL; + } + if (r->out.domains) { + NDR_CHECK(ndr_pull_lsa_RefDomainList(ndr, NDR_SCALARS|NDR_BUFFERS, r->out.domains)); + } + NDR_CHECK(ndr_pull_lsa_TransSidArray(ndr, NDR_SCALARS|NDR_BUFFERS, r->out.sids)); + NDR_CHECK(ndr_pull_uint32(ndr, r->out.count)); + NDR_CHECK(ndr_pull_NTSTATUS(ndr, &r->out.result)); + + return NT_STATUS_OK; +} + diff --git a/source4/librpc/ndr/ndr_lsa.h b/source4/librpc/ndr/ndr_lsa.h index ef70c5d073..770138f349 100644 --- a/source4/librpc/ndr/ndr_lsa.h +++ b/source4/librpc/ndr/ndr_lsa.h @@ -112,3 +112,33 @@ struct lsa_LookupSids { }; +struct lsa_TranslatedSid { + uint16 sid_type; + uint32 rid; + uint32 sid_index; +}; + +struct lsa_TransSidArray { + uint32 count; + struct lsa_TranslatedSid *sids; +}; + +struct lsa_LookupNames { + struct { + struct policy_handle *handle; + uint32 num_names; + struct lsa_Name *names; + struct lsa_TransSidArray *sids; + uint16 level; + uint32 *count; + } in; + + struct { + struct lsa_RefDomainList *domains; + struct lsa_TransSidArray *sids; + uint32 *count; + NTSTATUS result; + } out; + +}; + diff --git a/source4/librpc/rpc/rpc_lsa.c b/source4/librpc/rpc/rpc_lsa.c index c6f6f80e73..82039244e7 100644 --- a/source4/librpc/rpc/rpc_lsa.c +++ b/source4/librpc/rpc/rpc_lsa.c @@ -168,3 +168,23 @@ NTSTATUS dcerpc_lsa_LookupSids(struct dcerpc_pipe *p, return r->out.result; } + +/* + LookupNames interface +*/ +NTSTATUS dcerpc_lsa_LookupNames(struct dcerpc_pipe *p, + TALLOC_CTX *mem_ctx, + struct lsa_LookupNames *r) +{ + NTSTATUS status; + + status = dcerpc_ndr_request(p, LSA_LOOKUPNAMES, mem_ctx, + (ndr_push_fn_t) ndr_push_lsa_LookupNames, + (ndr_pull_fn_t) ndr_pull_lsa_LookupNames, + r); + if (!NT_STATUS_IS_OK(status)) { + return status; + } + + return r->out.result; +} -- cgit