summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2003-11-15 07:51:19 +0000
committerAndrew Tridgell <tridge@samba.org>2003-11-15 07:51:19 +0000
commitbcfbaa312a8493aa2b6ef76a7ebeee55625e5a9c (patch)
tree539a1fb803b4b762bad8fdbad9d1e6446d5240f0
parent5a28ca7bf3250f951826aa0726e4487b88062abe (diff)
downloadsamba-bcfbaa312a8493aa2b6ef76a7ebeee55625e5a9c.tar.gz
samba-bcfbaa312a8493aa2b6ef76a7ebeee55625e5a9c.tar.bz2
samba-bcfbaa312a8493aa2b6ef76a7ebeee55625e5a9c.zip
run LookupDomain on each domain returned from EnumDomains in samr
(This used to be commit 947b9f8ced486d34ee6710a921fb985ea14e2bb1)
-rw-r--r--source4/lib/util_str.c20
-rw-r--r--source4/librpc/idl/lsa.idl4
-rw-r--r--source4/librpc/idl/samr.idl23
-rw-r--r--source4/librpc/ndr/ndr_lsa.c4
-rw-r--r--source4/librpc/ndr/ndr_samr.c50
-rw-r--r--source4/librpc/ndr/ndr_samr.h19
-rw-r--r--source4/librpc/rpc/rpc_samr.c6
-rw-r--r--source4/torture/rpc/samr.c43
8 files changed, 133 insertions, 36 deletions
diff --git a/source4/lib/util_str.c b/source4/lib/util_str.c
index f689ae4355..b220820104 100644
--- a/source4/lib/util_str.c
+++ b/source4/lib/util_str.c
@@ -1066,6 +1066,26 @@ void strupper_m(char *s)
unix_strupper(s,strlen(s)+1,s,strlen(s)+1);
}
+
+/**
+ work out the number of multibyte chars in a string
+**/
+size_t strlen_m(const char *s)
+{
+ size_t count = 0;
+
+ while (*s && !(((unsigned char)s[0]) & 0x7F)) {
+ s++;
+ count++;
+ }
+
+ if (!*s)
+ return;
+
+ push_ucs2(NULL,tmpbuf,s, sizeof(tmpbuf), STR_TERMINATE);
+ return count + strlen_w(tmpbuf);
+}
+
/**
Convert a string to upper case.
**/
diff --git a/source4/librpc/idl/lsa.idl b/source4/librpc/idl/lsa.idl
index 622d34eef3..204466c784 100644
--- a/source4/librpc/idl/lsa.idl
+++ b/source4/librpc/idl/lsa.idl
@@ -25,8 +25,8 @@
/* Function: 0x02 */
typedef struct {
- uint16 name_len;
- uint16 name_size;
+ [value(2*strlen_m(r->name))] uint16 name_len;
+ [value(2*strlen_m(r->name))] uint16 name_size;
unistr_noterm *name;
} lsa_Name;
diff --git a/source4/librpc/idl/samr.idl b/source4/librpc/idl/samr.idl
index fd71c49369..6017f73f4e 100644
--- a/source4/librpc/idl/samr.idl
+++ b/source4/librpc/idl/samr.idl
@@ -35,19 +35,24 @@
/******************/
/* Function: 0x05 */
- NTSTATUS samr_LookupDomain ();
-
- /******************/
- /* Function: 0x06 */
-
typedef struct {
- uint16 name_len;
- uint16 name_size;
+ [value(2*strlen_m(r->name))] uint16 name_len;
+ [value(2*strlen_m(r->name))] uint16 name_size;
unistr_noterm *name;
} samr_Name;
+ NTSTATUS samr_LookupDomain (
+ [in,ref] policy_handle *handle,
+ [in,ref] samr_Name *domain,
+ [out] dom_sid2 *sid
+ );
+
+
+ /******************/
+ /* Function: 0x06 */
+
typedef struct {
- uint32 rid;
+ uint32 idx;
samr_Name name;
} samr_SamEntry;
@@ -287,7 +292,7 @@
/************************/
/* Function 0x3e */
- NTSTATUS samr_CONNECT4(
+ NTSTATUS samr_Connect4(
[in] unistr *system_name,
[in] uint32 unknown,
[in] uint32 access_mask,
diff --git a/source4/librpc/ndr/ndr_lsa.c b/source4/librpc/ndr/ndr_lsa.c
index 587093ed69..db17c1e63d 100644
--- a/source4/librpc/ndr/ndr_lsa.c
+++ b/source4/librpc/ndr/ndr_lsa.c
@@ -20,8 +20,8 @@ static NTSTATUS ndr_push_lsa_Name(struct ndr_push *ndr, int ndr_flags, struct ls
{
NDR_CHECK(ndr_push_align(ndr, 4));
if (!(ndr_flags & NDR_SCALARS)) goto buffers;
- NDR_CHECK(ndr_push_uint16(ndr, r->name_len));
- NDR_CHECK(ndr_push_uint16(ndr, r->name_size));
+ NDR_CHECK(ndr_push_uint16(ndr, 2*strlen_m(r->name)));
+ NDR_CHECK(ndr_push_uint16(ndr, 2*strlen_m(r->name)));
NDR_CHECK(ndr_push_ptr(ndr, r->name));
buffers:
if (!(ndr_flags & NDR_BUFFERS)) goto done;
diff --git a/source4/librpc/ndr/ndr_samr.c b/source4/librpc/ndr/ndr_samr.c
index 8258fe6bdf..8a972b426f 100644
--- a/source4/librpc/ndr/ndr_samr.c
+++ b/source4/librpc/ndr/ndr_samr.c
@@ -37,8 +37,26 @@ NTSTATUS ndr_push_samr_Shutdown(struct ndr_push *ndr, struct samr_Shutdown *r)
return NT_STATUS_OK;
}
+static NTSTATUS ndr_push_samr_Name(struct ndr_push *ndr, int ndr_flags, struct samr_Name *r)
+{
+ NDR_CHECK(ndr_push_align(ndr, 4));
+ if (!(ndr_flags & NDR_SCALARS)) goto buffers;
+ NDR_CHECK(ndr_push_uint16(ndr, 2*strlen_m(r->name)));
+ NDR_CHECK(ndr_push_uint16(ndr, 2*strlen_m(r->name)));
+ NDR_CHECK(ndr_push_ptr(ndr, r->name));
+buffers:
+ if (!(ndr_flags & NDR_BUFFERS)) goto done;
+ if (r->name) {
+ NDR_CHECK(ndr_push_unistr_noterm(ndr, r->name));
+ }
+done:
+ return NT_STATUS_OK;
+}
+
NTSTATUS ndr_push_samr_LookupDomain(struct ndr_push *ndr, struct samr_LookupDomain *r)
{
+ NDR_CHECK(ndr_push_policy_handle(ndr, r->in.handle));
+ NDR_CHECK(ndr_push_samr_Name(ndr, NDR_SCALARS|NDR_BUFFERS, r->in.domain));
return NT_STATUS_OK;
}
@@ -382,7 +400,7 @@ NTSTATUS ndr_push_samr_CONNECT3(struct ndr_push *ndr, struct samr_CONNECT3 *r)
return NT_STATUS_OK;
}
-NTSTATUS ndr_push_samr_CONNECT4(struct ndr_push *ndr, struct samr_CONNECT4 *r)
+NTSTATUS ndr_push_samr_Connect4(struct ndr_push *ndr, struct samr_Connect4 *r)
{
NDR_CHECK(ndr_push_ptr(ndr, r->in.system_name));
if (r->in.system_name) {
@@ -460,13 +478,6 @@ NTSTATUS ndr_pull_samr_Shutdown(struct ndr_pull *ndr, struct samr_Shutdown *r)
return NT_STATUS_OK;
}
-NTSTATUS ndr_pull_samr_LookupDomain(struct ndr_pull *ndr, struct samr_LookupDomain *r)
-{
- NDR_CHECK(ndr_pull_NTSTATUS(ndr, &r->out.result));
-
- return NT_STATUS_OK;
-}
-
static NTSTATUS ndr_pull_samr_Name(struct ndr_pull *ndr, int ndr_flags, struct samr_Name *r)
{
uint32 _ptr_name;
@@ -489,11 +500,28 @@ done:
return NT_STATUS_OK;
}
+NTSTATUS ndr_pull_samr_LookupDomain(struct ndr_pull *ndr, struct samr_LookupDomain *r)
+{
+ uint32 _ptr_sid;
+ NDR_CHECK(ndr_pull_uint32(ndr, &_ptr_sid));
+ if (_ptr_sid) {
+ NDR_ALLOC(ndr, r->out.sid);
+ } else {
+ r->out.sid = NULL;
+ }
+ if (r->out.sid) {
+ NDR_CHECK(ndr_pull_dom_sid2(ndr, r->out.sid));
+ }
+ NDR_CHECK(ndr_pull_NTSTATUS(ndr, &r->out.result));
+
+ return NT_STATUS_OK;
+}
+
static NTSTATUS ndr_pull_samr_SamEntry(struct ndr_pull *ndr, int ndr_flags, struct samr_SamEntry *r)
{
NDR_CHECK(ndr_pull_align(ndr, 4));
if (!(ndr_flags & NDR_SCALARS)) goto buffers;
- NDR_CHECK(ndr_pull_uint32(ndr, &r->rid));
+ NDR_CHECK(ndr_pull_uint32(ndr, &r->idx));
NDR_CHECK(ndr_pull_samr_Name(ndr, NDR_SCALARS, &r->name));
buffers:
if (!(ndr_flags & NDR_BUFFERS)) goto done;
@@ -935,7 +963,7 @@ NTSTATUS ndr_pull_samr_CONNECT3(struct ndr_pull *ndr, struct samr_CONNECT3 *r)
return NT_STATUS_OK;
}
-NTSTATUS ndr_pull_samr_CONNECT4(struct ndr_pull *ndr, struct samr_CONNECT4 *r)
+NTSTATUS ndr_pull_samr_Connect4(struct ndr_pull *ndr, struct samr_Connect4 *r)
{
NDR_CHECK(ndr_pull_policy_handle(ndr, r->out.handle));
NDR_CHECK(ndr_pull_NTSTATUS(ndr, &r->out.result));
@@ -997,7 +1025,7 @@ void ndr_print_samr_SamEntry(struct ndr_print *ndr, const char *name, struct sam
{
ndr_print_struct(ndr, name, "samr_SamEntry");
ndr->depth++;
- ndr_print_uint32(ndr, "rid", r->rid);
+ ndr_print_uint32(ndr, "idx", r->idx);
ndr_print_samr_Name(ndr, "name", &r->name);
ndr->depth--;
}
diff --git a/source4/librpc/ndr/ndr_samr.h b/source4/librpc/ndr/ndr_samr.h
index 20b58685de..f24dde1ec5 100644
--- a/source4/librpc/ndr/ndr_samr.h
+++ b/source4/librpc/ndr/ndr_samr.h
@@ -53,24 +53,27 @@ struct samr_Shutdown {
};
+struct samr_Name {
+ uint16 name_len;
+ uint16 name_size;
+ const char *name;
+};
+
struct samr_LookupDomain {
struct {
+ struct policy_handle *handle;
+ struct samr_Name *domain;
} in;
struct {
+ struct dom_sid2 *sid;
NTSTATUS result;
} out;
};
-struct samr_Name {
- uint16 name_len;
- uint16 name_size;
- const char *name;
-};
-
struct samr_SamEntry {
- uint32 rid;
+ uint32 idx;
struct samr_Name name;
};
@@ -645,7 +648,7 @@ struct samr_CONNECT3 {
};
-struct samr_CONNECT4 {
+struct samr_Connect4 {
struct {
const char *system_name;
uint32 unknown;
diff --git a/source4/librpc/rpc/rpc_samr.c b/source4/librpc/rpc/rpc_samr.c
index d007ebe07f..836ada5c0c 100644
--- a/source4/librpc/rpc/rpc_samr.c
+++ b/source4/librpc/rpc/rpc_samr.c
@@ -871,12 +871,12 @@ NTSTATUS dcerpc_samr_CONNECT3(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct
return r->out.result;
}
-NTSTATUS dcerpc_samr_CONNECT4(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct samr_CONNECT4 *r)
+NTSTATUS dcerpc_samr_Connect4(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct samr_Connect4 *r)
{
NTSTATUS status;
status = dcerpc_ndr_request(p, DCERPC_SAMR_CONNECT4, mem_ctx,
- (ndr_push_fn_t) ndr_push_samr_CONNECT4,
- (ndr_pull_fn_t) ndr_pull_samr_CONNECT4,
+ (ndr_push_fn_t) ndr_push_samr_Connect4,
+ (ndr_pull_fn_t) ndr_pull_samr_Connect4,
r);
if (!NT_STATUS_IS_OK(status)) {
return status;
diff --git a/source4/torture/rpc/samr.c b/source4/torture/rpc/samr.c
index 12d4ebbe93..2dd77e6ec5 100644
--- a/source4/torture/rpc/samr.c
+++ b/source4/torture/rpc/samr.c
@@ -21,6 +21,28 @@
#include "includes.h"
+static BOOL test_LookupDomain(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
+ struct policy_handle *handle, struct samr_Name *domain)
+{
+ NTSTATUS status;
+ struct samr_LookupDomain r;
+
+ printf("Testing LookupDomain(%s)\n", domain->name);
+
+ r.in.handle = handle;
+ r.in.domain = domain;
+
+ status = dcerpc_samr_LookupDomain(p, mem_ctx, &r);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("LookupDomain failed - %s\n", nt_errstr(status));
+ return False;
+ }
+
+ NDR_PRINT_DEBUG(dom_sid2, r.out.sid);
+
+ return True;
+}
+
static BOOL test_EnumDomains(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
struct policy_handle *handle)
@@ -28,7 +50,8 @@ static BOOL test_EnumDomains(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
NTSTATUS status;
struct samr_EnumDomains r;
uint32 resume_handle = 0;
- uint32 num_entries;
+ uint32 num_entries=0;
+ int i;
r.in.handle = handle;
r.in.resume_handle = &resume_handle;
@@ -44,6 +67,12 @@ static BOOL test_EnumDomains(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
NDR_PRINT_DEBUG(samr_SamArray, r.out.sam);
+ if (r.out.sam) {
+ for (i=0;i<r.out.sam->count;i++) {
+ test_LookupDomain(p, mem_ctx, handle, &r.out.sam->entries[i].name);
+ }
+ }
+
return True;
}
@@ -53,6 +82,7 @@ static BOOL test_Connect(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
{
NTSTATUS status;
struct samr_Connect r;
+ struct samr_Connect4 r4;
r.in.system_name = 0;
r.in.access_mask = SEC_RIGHTS_MAXIMUM_ALLOWED;
@@ -64,6 +94,17 @@ static BOOL test_Connect(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
return False;
}
+ r4.in.system_name = "win2003";
+ r4.in.unknown = 0;
+ r4.in.access_mask = SEC_RIGHTS_MAXIMUM_ALLOWED;
+ r4.out.handle = handle;
+
+ status = dcerpc_samr_Connect4(p, mem_ctx, &r4);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("Connect4 failed - %s\n", nt_errstr(status));
+ return False;
+ }
+
return True;
}