summaryrefslogtreecommitdiff
path: root/source3/rpc_parse
diff options
context:
space:
mode:
Diffstat (limited to 'source3/rpc_parse')
-rw-r--r--source3/rpc_parse/parse_lsa.c76
-rw-r--r--source3/rpc_parse/parse_misc.c45
-rw-r--r--source3/rpc_parse/parse_samr.c2
3 files changed, 96 insertions, 27 deletions
diff --git a/source3/rpc_parse/parse_lsa.c b/source3/rpc_parse/parse_lsa.c
index 91b54b9c83..415737ebfb 100644
--- a/source3/rpc_parse/parse_lsa.c
+++ b/source3/rpc_parse/parse_lsa.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) Andrew Bartlett 2002.
*
* 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
@@ -523,40 +524,63 @@ BOOL lsa_io_q_enum_trust_dom(char *desc, LSA_Q_ENUM_TRUST_DOM *q_e,
Inits an LSA_R_ENUM_TRUST_DOM structure.
********************************************************************/
-void init_r_enum_trust_dom(TALLOC_CTX *ctx, LSA_R_ENUM_TRUST_DOM *r_e, uint32 enum_context,
- char *domain_name, DOM_SID *domain_sid,
- NTSTATUS status)
+void init_r_enum_trust_dom(TALLOC_CTX *ctx, LSA_R_ENUM_TRUST_DOM *r_e, uint32 enum_context,
+ uint32 requested_num_domains, uint32 num_domains, TRUSTDOM **td)
{
+ int i;
+
DEBUG(5, ("init_r_enum_trust_dom\n"));
r_e->enum_context = enum_context;
-
- if (NT_STATUS_IS_OK(status)) {
- int len_domain_name = strlen(domain_name) + 1;
-
- r_e->num_domains = 1;
- r_e->ptr_enum_domains = 1;
- r_e->num_domains2 = 1;
-
- if (!(r_e->hdr_domain_name = (UNIHDR2 *)talloc(ctx,sizeof(UNIHDR2))))
- return;
+ r_e->num_domains = 0;
+ r_e->ptr_enum_domains = 0;
+ r_e->num_domains2 = 0;
+
+ if (num_domains == 0) {
+ r_e->status = NT_STATUS_NO_MORE_ENTRIES;
- if (!(r_e->uni_domain_name = (UNISTR2 *)talloc(ctx,sizeof(UNISTR2))))
+ } else {
+ /*
+ * allocating empty arrays of unicode headers, strings
+ * and sids of enumerated trusted domains
+ */
+ if (!(r_e->hdr_domain_name = (UNIHDR2 *)talloc(ctx,sizeof(UNIHDR2) * num_domains))) {
+ r_e->status = NT_STATUS_NO_MEMORY;
return;
+ }
+
+ if (!(r_e->uni_domain_name = (UNISTR2 *)talloc(ctx,sizeof(UNISTR2) * num_domains))) {
+ r_e->status = NT_STATUS_NO_MEMORY;
+ return;
+ }
- if (!(r_e->domain_sid = (DOM_SID2 *)talloc(ctx,sizeof(DOM_SID2))))
+ if (!(r_e->domain_sid = (DOM_SID2 *)talloc(ctx,sizeof(DOM_SID2) * num_domains))) {
+ r_e->status = NT_STATUS_NO_MEMORY;
return;
+ }
+
+ r_e->num_domains = num_domains;
+ r_e->num_domains2 = num_domains;
+
+ for (i = 0; i < num_domains; i++) {
+
+ /* don't know what actually is this for */
+ r_e->ptr_enum_domains = 1;
+
+ init_uni_hdr2(&r_e->hdr_domain_name[i], strlen_w((td[i])->name));
+ init_dom_sid2(&r_e->domain_sid[i], &(td[i])->sid);
+
+ init_unistr2_w(ctx, &r_e->uni_domain_name[i], (td[i])->name);
+
+ };
+
+ if (num_domains < requested_num_domains) {
+ r_e->status = NT_STATUS_NO_MORE_ENTRIES;
+ } else {
+ r_e->status = NT_STATUS_OK;
+ }
+ }
- init_uni_hdr2(&r_e->hdr_domain_name[0], len_domain_name);
- init_unistr2 (&r_e->uni_domain_name[0], domain_name,
- len_domain_name);
- init_dom_sid2(&r_e->domain_sid[0], domain_sid);
- } else {
- r_e->num_domains = 0;
- r_e->ptr_enum_domains = 0;
- }
-
- r_e->status = status;
}
/*******************************************************************
@@ -603,7 +627,7 @@ BOOL lsa_io_r_enum_trust_dom(char *desc, LSA_R_ENUM_TRUST_DOM *r_e,
for (i = 0; i < num_domains; i++) {
if(!smb_io_unistr2 ("", &r_e->uni_domain_name[i],
- r_e->hdr_domain_name[i].buffer,
+ r_e->hdr_domain_name[i].buffer,
ps, depth))
return False;
if(!smb_io_dom_sid2("", &r_e->domain_sid[i], ps,
diff --git a/source3/rpc_parse/parse_misc.c b/source3/rpc_parse/parse_misc.c
index 73f285e320..f326681c64 100644
--- a/source3/rpc_parse/parse_misc.c
+++ b/source3/rpc_parse/parse_misc.c
@@ -916,6 +916,51 @@ void init_unistr2(UNISTR2 *str, const char *buf, size_t len)
rpcstr_push((char *)str->buffer, buf, len, STR_TERMINATE);
}
+/**
+ * Inits a UNISTR2 structure.
+ * @param ctx talloc context to allocate string on
+ * @param str pointer to string to create
+ * @param buf UCS2 null-terminated buffer to init from
+*/
+
+void init_unistr2_w(TALLOC_CTX *ctx, UNISTR2 *str, const smb_ucs2_t *buf)
+{
+ uint32 len = strlen_w(buf);
+ uint32 max_len = len;
+ uint32 alloc_len;
+
+ ZERO_STRUCTP(str);
+
+ /* set up string lengths. */
+ str->uni_max_len = len;
+ str->undoc = 0;
+ str->uni_str_len = len;
+
+ if (max_len < MAX_UNISTRLEN)
+ max_len = MAX_UNISTRLEN;
+
+ alloc_len = (max_len + 1) * sizeof(uint16);
+
+ str->buffer = (uint16 *)talloc_zero(ctx, alloc_len);
+ if ((str->buffer == NULL) && (alloc_len > 0))
+ {
+ smb_panic("init_unistr2_w: malloc fail\n");
+ return;
+ }
+
+ /*
+ * don't move this test above ! The UNISTR2 must be initialized !!!
+ * jfm, 7/7/2001.
+ */
+ if (buf==NULL)
+ return;
+
+ /* Yes, this is a strncpy( foo, bar, strlen(bar)) - but as
+ long as the buffer above is talloc()ed correctly then this
+ is the correct thing to do */
+ strncpy_w(str->buffer, buf, len + 1);
+}
+
/*******************************************************************
Inits a UNISTR2 structure from a UNISTR
********************************************************************/
diff --git a/source3/rpc_parse/parse_samr.c b/source3/rpc_parse/parse_samr.c
index 4edc0678af..b8a558665f 100644
--- a/source3/rpc_parse/parse_samr.c
+++ b/source3/rpc_parse/parse_samr.c
@@ -4535,7 +4535,7 @@ inits a SAMR_Q_LOOKUP_NAMES structure.
NTSTATUS init_samr_q_lookup_names(TALLOC_CTX *ctx, SAMR_Q_LOOKUP_NAMES * q_u,
POLICY_HND *pol, uint32 flags,
- uint32 num_names, char **name)
+ uint32 num_names, const char **name)
{
uint32 i;