summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGerald Carter <jerry@samba.org>2005-04-06 22:27:55 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 10:56:30 -0500
commitb137b7cc4720ca9d99eab2bb198be1b112c2e24c (patch)
tree357cbbc9122d1766d2532ffe60aa463686f57c81
parent978ca8486031e43754a3c23757f361bf3a85f335 (diff)
downloadsamba-b137b7cc4720ca9d99eab2bb198be1b112c2e24c.tar.gz
samba-b137b7cc4720ca9d99eab2bb198be1b112c2e24c.tar.bz2
samba-b137b7cc4720ca9d99eab2bb198be1b112c2e24c.zip
r6228: remove BUFHDR2 and clean up LsaEnumTrustedDomains()
Tested client and server code. (This used to be commit efb3ac4c69c72c0fa01c558951fa357893562bce)
-rw-r--r--source3/include/rpc_lsa.h46
-rw-r--r--source3/include/rpc_misc.h9
-rw-r--r--source3/rpc_client/cli_lsarpc.c90
-rw-r--r--source3/rpc_parse/parse_lsa.c136
-rw-r--r--source3/rpc_parse/parse_misc.c69
-rw-r--r--source3/rpc_parse/parse_reg.c2
-rw-r--r--source3/rpc_server/srv_lsa_nt.c1
7 files changed, 167 insertions, 186 deletions
diff --git a/source3/include/rpc_lsa.h b/source3/include/rpc_lsa.h
index 69d8f53a6d..8eaf68a234 100644
--- a/source3/include/rpc_lsa.h
+++ b/source3/include/rpc_lsa.h
@@ -1,9 +1,10 @@
/*
Unix SMB/CIFS implementation.
SMB parameters and setup
- Copyright (C) Andrew Tridgell 1992-1997
- Copyright (C) Luke Kenneth Casson Leighton 1996-1997
- Copyright (C) Paul Ashton 1997
+ Copyright (C) Andrew Tridgell 1992-1997
+ Copyright (C) Luke Kenneth Casson Leighton 1996-1997
+ Copyright (C) Paul Ashton 1997
+ Copyright (C) Gerald (Jerry) Carter 2005
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -305,32 +306,33 @@ typedef struct lsa_r_query_info2
NTSTATUS status;
} LSA_R_QUERY_INFO2;
-/* LSA_Q_ENUM_TRUST_DOM - LSA enumerate trusted domains */
-typedef struct lsa_enum_trust_dom_info
-{
- POLICY_HND pol; /* policy handle */
- uint32 enum_context; /* enumeration context handle */
- uint32 preferred_len; /* preferred maximum length */
+/*******************************************************/
+typedef struct {
+ POLICY_HND pol;
+ uint32 enum_context;
+ uint32 preferred_len; /* preferred maximum length */
} LSA_Q_ENUM_TRUST_DOM;
-/* LSA_R_ENUM_TRUST_DOM - response to LSA enumerate trusted domains */
-typedef struct lsa_r_enum_trust_dom_info
-{
- uint32 enum_context; /* enumeration context handle */
- uint32 num_domains; /* number of domains */
- uint32 ptr_enum_domains; /* buffer pointer to num domains */
-
- /* this lot is only added if ptr_enum_domains is non-NULL */
- uint32 num_domains2; /* number of domains */
- UNIHDR2 *hdr_domain_name;
- UNISTR2 *uni_domain_name;
- DOM_SID2 *domain_sid;
+typedef struct {
+ UNISTR4 name;
+ DOM_SID2 *sid;
+} DOMAIN_INFO;
- NTSTATUS status; /* return code */
+typedef struct {
+ uint32 count;
+ DOMAIN_INFO *domains;
+} DOMAIN_LIST;
+typedef struct {
+ uint32 enum_context;
+ uint32 count;
+ DOMAIN_LIST *domlist;
+ NTSTATUS status;
} LSA_R_ENUM_TRUST_DOM;
+/*******************************************************/
+
/* LSA_Q_CLOSE */
typedef struct lsa_q_close_info
{
diff --git a/source3/include/rpc_misc.h b/source3/include/rpc_misc.h
index 3cece400db..e93d6610ba 100644
--- a/source3/include/rpc_misc.h
+++ b/source3/include/rpc_misc.h
@@ -215,13 +215,6 @@ typedef struct {
uint32 buffer;
} UNIHDR;
-typedef struct {
- UNIHDR unihdr;
- uint32 buffer; /* 32 bit buffer pointer */
-} UNIHDR2;
-
-
-
/**********************************************************************
* UNICODE string variations
**********************************************************************/
@@ -248,7 +241,7 @@ typedef struct { /* UNISTR3 - XXXX not sure about this structure */
} UNISTR3;
-typedef struct { /* UNIHDR + (UNISTR2*) */
+typedef struct { /* Buffer wrapped around a UNISTR2 */
uint16 length; /* number of bytes not counting NULL terminatation */
uint16 size; /* number of bytes including NULL terminatation */
UNISTR2 *string;
diff --git a/source3/rpc_client/cli_lsarpc.c b/source3/rpc_client/cli_lsarpc.c
index 81d535e54c..f404b5144a 100644
--- a/source3/rpc_client/cli_lsarpc.c
+++ b/source3/rpc_client/cli_lsarpc.c
@@ -24,6 +24,7 @@
*/
#include "includes.h"
+#include "rpc_client.h"
/** @defgroup lsa LSA - Local Security Architecture
* @ingroup rpc_client
@@ -636,89 +637,68 @@ NTSTATUS cli_lsa_enum_trust_dom(struct cli_state *cli, TALLOC_CTX *mem_ctx,
char ***domain_names, DOM_SID **domain_sids)
{
prs_struct qbuf, rbuf;
- LSA_Q_ENUM_TRUST_DOM q;
- LSA_R_ENUM_TRUST_DOM r;
- NTSTATUS result;
+ LSA_Q_ENUM_TRUST_DOM in;
+ LSA_R_ENUM_TRUST_DOM out;
int i;
+ fstring tmp;
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Marshall data and send request */
+ ZERO_STRUCT(in);
+ ZERO_STRUCT(out);
/* 64k is enough for about 2000 trusted domains */
- init_q_enum_trust_dom(&q, pol, *enum_ctx, 0x10000);
-
- if (!lsa_io_q_enum_trust_dom("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, PI_LSARPC, LSA_ENUMTRUSTDOM, &qbuf, &rbuf)) {
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
- /* Unmarshall response */
-
- if (!lsa_io_r_enum_trust_dom("", &r, &rbuf, 0)) {
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
+
+ init_q_enum_trust_dom(&in, pol, *enum_ctx, 0x10000);
- result = r.status;
+ CLI_DO_RPC( cli, mem_ctx, PI_LSARPC, LSA_ENUMTRUSTDOM,
+ in, out,
+ qbuf, rbuf,
+ lsa_io_q_enum_trust_dom,
+ lsa_io_r_enum_trust_dom,
+ NT_STATUS_UNSUCCESSFUL );
- if (!NT_STATUS_IS_OK(result) &&
- !NT_STATUS_EQUAL(result, NT_STATUS_NO_MORE_ENTRIES) &&
- !NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES)) {
- /* An actual error ocured */
+ /* check for an actual error */
- goto done;
+ if ( !NT_STATUS_IS_OK(out.status)
+ && !NT_STATUS_EQUAL(out.status, NT_STATUS_NO_MORE_ENTRIES)
+ && !NT_STATUS_EQUAL(out.status, STATUS_MORE_ENTRIES) )
+ {
+ return out.status;
}
-
+
/* Return output parameters */
- if (r.num_domains) {
+ *num_domains = out.count;
+ *enum_ctx = out.enum_context;
+
+ if ( out.count ) {
/* Allocate memory for trusted domain names and sids */
- *domain_names = TALLOC_ARRAY(mem_ctx, char *, r.num_domains);
-
- if (!*domain_names) {
+ if ( !(*domain_names = TALLOC_ARRAY(mem_ctx, char *, out.count)) ) {
DEBUG(0, ("cli_lsa_enum_trust_dom(): out of memory\n"));
- result = NT_STATUS_NO_MEMORY;
- goto done;
+ return NT_STATUS_NO_MEMORY;
}
- *domain_sids = TALLOC_ARRAY(mem_ctx, DOM_SID, r.num_domains);
- if (!domain_sids) {
+ if ( !(*domain_sids = TALLOC_ARRAY(mem_ctx, DOM_SID, out.count)) ) {
DEBUG(0, ("cli_lsa_enum_trust_dom(): out of memory\n"));
- result = NT_STATUS_NO_MEMORY;
- goto done;
+ return NT_STATUS_NO_MEMORY;
}
/* Copy across names and sids */
- for (i = 0; i < r.num_domains; i++) {
- fstring tmp;
+ for (i = 0; i < out.count; i++) {
- unistr2_to_ascii(tmp, &r.uni_domain_name[i],
- sizeof(tmp) - 1);
+ rpcstr_pull( tmp, out.domlist->domains[i].name.string->buffer,
+ sizeof(tmp), out.domlist->domains[i].name.length, 0);
(*domain_names)[i] = talloc_strdup(mem_ctx, tmp);
- sid_copy(&(*domain_sids)[i], &r.domain_sid[i].sid);
+
+ sid_copy(&(*domain_sids)[i], &out.domlist->domains[i].sid->sid );
}
}
- *num_domains = r.num_domains;
- *enum_ctx = r.enum_context;
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
+ return out.status;
}
diff --git a/source3/rpc_parse/parse_lsa.c b/source3/rpc_parse/parse_lsa.c
index 649cb7845a..ab3d3fcfe8 100644
--- a/source3/rpc_parse/parse_lsa.c
+++ b/source3/rpc_parse/parse_lsa.c
@@ -6,6 +6,7 @@
* Copyright (C) Paul Ashton 1997,
* Copyright (C) Andrew Bartlett 2002,
* Copyright (C) Jim McDonough <jmcd@us.ibm.com> 2002.
+ * Copyright (C) Gerald )Jerry) Carter 2005
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -516,100 +517,99 @@ void init_r_enum_trust_dom(TALLOC_CTX *ctx, LSA_R_ENUM_TRUST_DOM *r_e, uint32 en
DEBUG(5, ("init_r_enum_trust_dom\n"));
- r_e->enum_context = enum_context;
- r_e->num_domains = num_domains;
- r_e->ptr_enum_domains = 0;
- r_e->num_domains2 = num_domains;
-
- if (num_domains != 0) {
+ r_e->enum_context = enum_context;
+ r_e->count = num_domains;
+
+ if ( num_domains != 0 ) {
- /*
- * allocating empty arrays of unicode headers, strings
- * and sids of enumerated trusted domains
- */
- if (!(r_e->hdr_domain_name = TALLOC_ARRAY(ctx,UNIHDR2,num_domains))) {
- r_e->status = NT_STATUS_NO_MEMORY;
- return;
- }
+ /* allocate container memory */
- if (!(r_e->uni_domain_name = TALLOC_ARRAY(ctx,UNISTR2,num_domains))) {
- r_e->status = NT_STATUS_NO_MEMORY;
- return;
- }
-
- if (!(r_e->domain_sid = TALLOC_ARRAY(ctx,DOM_SID2,num_domains))) {
+ r_e->domlist = TALLOC_P( ctx, DOMAIN_LIST );
+ r_e->domlist->domains = TALLOC_ARRAY( ctx, DOMAIN_INFO, r_e->count );
+
+ if ( !r_e->domlist || !r_e->domlist->domains ) {
r_e->status = NT_STATUS_NO_MEMORY;
return;
}
+
+ r_e->domlist->count = r_e->count;
+
+ /* initialize the list of domains and their sid */
+
+ for (i = 0; i < num_domains; i++) {
+ if ( !(r_e->domlist->domains[i].sid = TALLOC_P(ctx, DOM_SID2)) ) {
+ r_e->status = NT_STATUS_NO_MEMORY;
+ return;
+ }
- for (i = 0; i < num_domains; i++) {
-
- /* don't know what actually is this for */
- r_e->ptr_enum_domains = 1;
-
- init_dom_sid2(&r_e->domain_sid[i], &(td[i])->sid);
-
- init_unistr2_w(ctx, &r_e->uni_domain_name[i], (td[i])->name);
- init_uni_hdr2(&r_e->hdr_domain_name[i], &r_e->uni_domain_name[i]);
-
- };
+ init_dom_sid2(r_e->domlist->domains[i].sid, &(td[i])->sid);
+ init_unistr4_w(ctx, &r_e->domlist->domains[i].name, (td[i])->name);
+ }
}
}
/*******************************************************************
- Reads or writes an LSA_R_ENUM_TRUST_DOM structure.
********************************************************************/
-BOOL lsa_io_r_enum_trust_dom(const char *desc, LSA_R_ENUM_TRUST_DOM *r_e,
- prs_struct *ps, int depth)
+BOOL lsa_io_domain_list( const char *desc, prs_struct *ps, int depth, DOMAIN_LIST *domlist )
{
- prs_debug(ps, depth, desc, "lsa_io_r_enum_trust_dom");
+ int i;
+
+ prs_debug(ps, depth, desc, "lsa_io_domain_list");
depth++;
- if(!prs_uint32("enum_context ", ps, depth, &r_e->enum_context))
- return False;
- if(!prs_uint32("num_domains ", ps, depth, &r_e->num_domains))
- return False;
- if(!prs_uint32("ptr_enum_domains", ps, depth, &r_e->ptr_enum_domains))
+ if(!prs_uint32("count", ps, depth, &domlist->count))
return False;
- if (r_e->ptr_enum_domains) {
- int i, num_domains;
+ if ( domlist->count == 0 )
+ return True;
+
+ if ( UNMARSHALLING(ps) ) {
+ if ( !(domlist->domains = PRS_ALLOC_MEM( ps, DOMAIN_INFO, domlist->count )) )
+ return False;
+ }
+
+ /* headers */
+
+ for ( i=0; i<domlist->count; i++ ) {
+ if ( !prs_unistr4_hdr("name_header", ps, depth, &domlist->domains[i].name) )
+ return False;
+ if ( !smb_io_dom_sid2_p("sid_header", ps, depth, &domlist->domains[i].sid) )
+ return False;
+ }
- if(!prs_uint32("num_domains2", ps, depth, &r_e->num_domains2))
+ /* data */
+
+ for ( i=0; i<domlist->count; i++ ) {
+ if ( !prs_unistr4_str("name", ps, depth, &domlist->domains[i].name) )
return False;
+ if( !smb_io_dom_sid2("sid", domlist->domains[i].sid, ps, depth) )
+ return False;
+ }
+
+ return True;
+}
- num_domains = r_e->num_domains2;
+/*******************************************************************
+ Reads or writes an LSA_R_ENUM_TRUST_DOM structure.
+********************************************************************/
- if (UNMARSHALLING(ps)) {
- if (!(r_e->hdr_domain_name = PRS_ALLOC_MEM(ps,UNIHDR2,num_domains)))
- return False;
+BOOL lsa_io_r_enum_trust_dom(const char *desc, LSA_R_ENUM_TRUST_DOM *r_e,
+ prs_struct *ps, int depth)
+{
+ prs_debug(ps, depth, desc, "lsa_io_r_enum_trust_dom");
+ depth++;
- if (!(r_e->uni_domain_name = PRS_ALLOC_MEM(ps,UNISTR2,num_domains)))
- return False;
+ if(!prs_uint32("enum_context", ps, depth, &r_e->enum_context))
+ return False;
- if (!(r_e->domain_sid = PRS_ALLOC_MEM(ps,DOM_SID2,num_domains)))
- return False;
- }
+ if(!prs_uint32("count", ps, depth, &r_e->count))
+ return False;
- for (i = 0; i < num_domains; i++) {
- if(!smb_io_unihdr2 ("", &r_e->hdr_domain_name[i], ps,
- depth))
- return False;
- }
+ if ( !prs_pointer("trusted_domains", ps, depth, (void**)&r_e->domlist, sizeof(DOMAIN_LIST), (PRS_POINTER_CAST)lsa_io_domain_list))
+ return False;
- for (i = 0; i < num_domains; i++) {
- if(!smb_io_unistr2 ("", &r_e->uni_domain_name[i],
- r_e->hdr_domain_name[i].buffer,
- ps, depth))
- return False;
- if(!smb_io_dom_sid2("", &r_e->domain_sid[i], ps,
- depth))
- return False;
- }
- }
-
if(!prs_ntstatus("status", ps, depth, &r_e->status))
return False;
diff --git a/source3/rpc_parse/parse_misc.c b/source3/rpc_parse/parse_misc.c
index 57f44f9f85..858366d4ad 100644
--- a/source3/rpc_parse/parse_misc.c
+++ b/source3/rpc_parse/parse_misc.c
@@ -4,6 +4,7 @@
* Copyright (C) Andrew Tridgell 1992-1997,
* Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
* Copyright (C) Paul Ashton 1997.
+ * Copyright (C) Gerald (Jerry) Carter 2005
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -280,6 +281,33 @@ void init_dom_sid2(DOM_SID2 *sid2, const DOM_SID *sid)
Reads or writes a DOM_SID2 structure.
********************************************************************/
+BOOL smb_io_dom_sid2_p(const char *desc, prs_struct *ps, int depth, DOM_SID2 **sid2)
+{
+ uint32 data_p;
+
+ /* caputure the pointer value to stream */
+
+ data_p = (uint32) *sid2;
+
+ if ( !prs_uint32("dom_sid2_p", ps, depth, &data_p ))
+ return False;
+
+ /* we're done if there is no data */
+
+ if ( !data_p )
+ return True;
+
+ if (UNMARSHALLING(ps)) {
+ if ( !(*sid2 = PRS_ALLOC_MEM(ps, DOM_SID2, 1)) )
+ return False;
+ }
+
+ return True;
+}
+/*******************************************************************
+ Reads or writes a DOM_SID2 structure.
+********************************************************************/
+
BOOL smb_io_dom_sid2(const char *desc, DOM_SID2 *sid, prs_struct *ps, int depth)
{
if (sid == NULL)
@@ -485,39 +513,6 @@ BOOL smb_io_hdrbuf(const char *desc, BUFHDR *hdr, prs_struct *ps, int depth)
}
/*******************************************************************
-creates a UNIHDR2 structure.
-********************************************************************/
-
-void init_uni_hdr2(UNIHDR2 *hdr, UNISTR2 *str2)
-{
- init_uni_hdr(&hdr->unihdr, str2);
- hdr->buffer = (str2->uni_str_len > 0) ? 1 : 0;
-}
-
-/*******************************************************************
- Reads or writes a UNIHDR2 structure.
-********************************************************************/
-
-BOOL smb_io_unihdr2(const char *desc, UNIHDR2 *hdr2, prs_struct *ps, int depth)
-{
- if (hdr2 == NULL)
- return False;
-
- prs_debug(ps, depth, desc, "smb_io_unihdr2");
- depth++;
-
- if(!prs_align(ps))
- return False;
-
- if(!smb_io_unihdr("hdr", &hdr2->unihdr, ps, depth))
- return False;
- if(!prs_uint32("buffer", ps, depth, &hdr2->buffer))
- return False;
-
- return True;
-}
-
-/*******************************************************************
Inits a UNISTR structure.
********************************************************************/
@@ -913,6 +908,14 @@ void init_unistr4(UNISTR4 *uni4, const char *buf, enum unistr2_term_codes flags)
uni4->size = 2 * (uni4->string->uni_max_len);
}
+void init_unistr4_w( TALLOC_CTX *ctx, UNISTR4 *uni4, const smb_ucs2_t *buf )
+{
+ uni4->string = TALLOC_P( ctx, UNISTR2 );
+ init_unistr2_w( ctx, uni4->string, buf );
+
+ uni4->length = 2 * (uni4->string->uni_str_len);
+ uni4->size = 2 * (uni4->string->uni_max_len);
+}
/**
* Inits a UNISTR2 structure.
diff --git a/source3/rpc_parse/parse_reg.c b/source3/rpc_parse/parse_reg.c
index 09e19bf701..e76c536cee 100644
--- a/source3/rpc_parse/parse_reg.c
+++ b/source3/rpc_parse/parse_reg.c
@@ -271,8 +271,10 @@ BOOL reg_io_q_create_key(const char *desc, REG_Q_CREATE_KEY *q_u,
ps, depth))
return False;
+#if 0
if(!prs_uint32("unknown_2", ps, depth, &q_u->unknown_2))
return False;
+#endif
return True;
}
diff --git a/source3/rpc_server/srv_lsa_nt.c b/source3/rpc_server/srv_lsa_nt.c
index 58189fec78..f5f22d8cc0 100644
--- a/source3/rpc_server/srv_lsa_nt.c
+++ b/source3/rpc_server/srv_lsa_nt.c
@@ -523,6 +523,7 @@ NTSTATUS _lsa_enum_trust_dom(pipes_struct *p, LSA_Q_ENUM_TRUST_DOM *q_u, LSA_R_E
}
/* set up the lsa_enum_trust_dom response */
+
init_r_enum_trust_dom(p->mem_ctx, r_u, enum_context, max_num_domains, num_domains, trust_doms);
return r_u->status;