r238: Fix memleak
[Samba/gebeck_regimport.git] / source3 / rpc_parse / parse_ds.c
blob070f6be43a76780569199e266496daba6b804a8e
1 /*
2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines
5 * Copyright (C) Gerald Carter 2002-2003
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "includes.h"
24 /************************************************************************
25 ************************************************************************/
27 static BOOL ds_io_dominfobasic( const char *desc, prs_struct *ps, int depth, DSROLE_PRIMARY_DOMAIN_INFO_BASIC **basic)
29 DSROLE_PRIMARY_DOMAIN_INFO_BASIC *p = *basic;
31 if ( UNMARSHALLING(ps) )
32 p = *basic = (DSROLE_PRIMARY_DOMAIN_INFO_BASIC *)prs_alloc_mem(ps, sizeof(DSROLE_PRIMARY_DOMAIN_INFO_BASIC));
34 if ( !p )
35 return False;
37 if ( !prs_uint16("machine_role", ps, depth, &p->machine_role) )
38 return False;
39 if ( !prs_uint16("unknown", ps, depth, &p->unknown) )
40 return False;
42 if ( !prs_uint32("flags", ps, depth, &p->flags) )
43 return False;
45 if ( !prs_uint32("netbios_ptr", ps, depth, &p->netbios_ptr) )
46 return False;
47 if ( !prs_uint32("dnsname_ptr", ps, depth, &p->dnsname_ptr) )
48 return False;
49 if ( !prs_uint32("forestname_ptr", ps, depth, &p->forestname_ptr) )
50 return False;
52 if ( !smb_io_uuid("domain_guid", &p->domain_guid, ps, depth) )
53 return False;
55 if ( !smb_io_unistr2( "netbios_domain", &p->netbios_domain, p->netbios_ptr, ps, depth) )
56 return False;
57 if ( !prs_align(ps) )
58 return False;
60 if ( !smb_io_unistr2( "dns_domain", &p->dns_domain, p->dnsname_ptr, ps, depth) )
61 return False;
62 if ( !prs_align(ps) )
63 return False;
65 if ( !smb_io_unistr2( "forest_domain", &p->forest_domain, p->forestname_ptr, ps, depth) )
66 return False;
67 if ( !prs_align(ps) )
68 return False;
71 return True;
75 /************************************************************************
76 ************************************************************************/
78 BOOL ds_io_q_getprimdominfo( const char *desc, prs_struct *ps, int depth, DS_Q_GETPRIMDOMINFO *q_u)
80 prs_debug(ps, depth, desc, "ds_io_q_getprimdominfo");
81 depth++;
83 if(!prs_align(ps))
84 return False;
86 if ( !prs_uint16( "level", ps, depth, &q_u->level ) )
87 return False;
89 return True;
92 /************************************************************************
93 ************************************************************************/
95 BOOL ds_io_r_getprimdominfo( const char *desc, prs_struct *ps, int depth, DS_R_GETPRIMDOMINFO *r_u)
97 prs_debug(ps, depth, desc, "ds_io_r_getprimdominfo");
98 depth++;
100 if(!prs_align(ps))
101 return False;
103 if ( !prs_uint32( "ptr", ps, depth, &r_u->ptr ) )
104 return False;
106 if ( r_u->ptr )
108 if ( !prs_uint16( "level", ps, depth, &r_u->level ) )
109 return False;
111 if ( !prs_uint16( "unknown0", ps, depth, &r_u->unknown0 ) )
112 return False;
114 switch ( r_u->level )
116 case DsRolePrimaryDomainInfoBasic:
117 if ( !ds_io_dominfobasic( "dominfobasic", ps, depth, &r_u->info.basic ) )
118 return False;
119 break;
120 default:
121 return False;
125 if ( !prs_align(ps) )
126 return False;
128 if ( !prs_ntstatus("status", ps, depth, &r_u->status ) )
129 return False;
131 return True;
134 /************************************************************************
135 initialize a DS_ENUM_DOM_TRUSTS structure
136 ************************************************************************/
138 BOOL init_q_ds_enum_domain_trusts( DS_Q_ENUM_DOM_TRUSTS *q, const char *server,
139 uint32 flags )
141 q->flags = flags;
143 if ( server && *server )
144 q->server_ptr = 1;
145 else
146 q->server_ptr = 0;
148 init_unistr2( &q->server, server, UNI_STR_TERMINATE);
150 return True;
153 /************************************************************************
154 ************************************************************************/
156 static BOOL ds_io_domain_trusts( const char *desc, prs_struct *ps, int depth, DS_DOMAIN_TRUSTS *trust)
158 prs_debug(ps, depth, desc, "ds_io_dom_trusts_ctr");
159 depth++;
161 if ( !prs_uint32( "netbios_ptr", ps, depth, &trust->netbios_ptr ) )
162 return False;
164 if ( !prs_uint32( "dns_ptr", ps, depth, &trust->dns_ptr ) )
165 return False;
167 if ( !prs_uint32( "flags", ps, depth, &trust->flags ) )
168 return False;
170 if ( !prs_uint32( "parent_index", ps, depth, &trust->parent_index ) )
171 return False;
173 if ( !prs_uint32( "trust_type", ps, depth, &trust->trust_type ) )
174 return False;
176 if ( !prs_uint32( "trust_attributes", ps, depth, &trust->trust_attributes ) )
177 return False;
179 if ( !prs_uint32( "sid_ptr", ps, depth, &trust->sid_ptr ) )
180 return False;
182 if ( !smb_io_uuid("guid", &trust->guid, ps, depth) )
183 return False;
185 return True;
188 /************************************************************************
189 ************************************************************************/
191 static BOOL ds_io_dom_trusts_ctr( const char *desc, prs_struct *ps, int depth, DS_DOMAIN_TRUSTS_CTR *ctr)
193 int i;
195 prs_debug(ps, depth, desc, "ds_io_dom_trusts_ctr");
196 depth++;
198 if ( !prs_uint32( "ptr", ps, depth, &ctr->ptr ) )
199 return False;
201 if ( !prs_uint32( "max_count", ps, depth, &ctr->max_count ) )
202 return False;
204 /* are we done? */
206 if ( ctr->max_count == 0 )
207 return True;
209 /* allocate the domain trusts array are parse it */
211 ctr->trusts = (DS_DOMAIN_TRUSTS*)talloc(ps->mem_ctx, sizeof(DS_DOMAIN_TRUSTS)*ctr->max_count);
213 if ( !ctr->trusts )
214 return False;
216 /* this stinks; the static portion o fthe structure is read here and then
217 we need another loop to read the UNISTR2's and SID's */
219 for ( i=0; i<ctr->max_count;i++ ) {
220 if ( !ds_io_domain_trusts("domain_trusts", ps, depth, &ctr->trusts[i] ) )
221 return False;
224 for ( i=0; i<ctr->max_count; i++ ) {
226 if ( !smb_io_unistr2("netbios_domain", &ctr->trusts[i].netbios_domain, ctr->trusts[i].netbios_ptr, ps, depth) )
227 return False;
229 if(!prs_align(ps))
230 return False;
232 if ( !smb_io_unistr2("dns_domain", &ctr->trusts[i].dns_domain, ctr->trusts[i].dns_ptr, ps, depth) )
233 return False;
235 if(!prs_align(ps))
236 return False;
238 if ( ctr->trusts[i].sid_ptr ) {
239 if ( !smb_io_dom_sid2("sid", &ctr->trusts[i].sid, ps, depth ) )
240 return False;
244 return True;
247 /************************************************************************
248 initialize a DS_ENUM_DOM_TRUSTS request
249 ************************************************************************/
251 BOOL ds_io_q_enum_domain_trusts( const char *desc, prs_struct *ps, int depth, DS_Q_ENUM_DOM_TRUSTS *q_u)
253 prs_debug(ps, depth, desc, "ds_io_q_enum_domain_trusts");
254 depth++;
256 if ( !prs_align(ps) )
257 return False;
259 if ( !prs_uint32( "server_ptr", ps, depth, &q_u->server_ptr ) )
260 return False;
262 if ( !smb_io_unistr2("server", &q_u->server, q_u->server_ptr, ps, depth) )
263 return False;
265 if ( !prs_align(ps) )
266 return False;
268 if ( !prs_uint32( "flags", ps, depth, &q_u->flags ) )
269 return False;
271 return True;
274 /************************************************************************
275 ************************************************************************/
277 BOOL ds_io_r_enum_domain_trusts( const char *desc, prs_struct *ps, int depth, DS_R_ENUM_DOM_TRUSTS *r_u)
279 prs_debug(ps, depth, desc, "ds_io_r_enum_domain_trusts");
280 depth++;
282 if(!prs_align(ps))
283 return False;
285 if ( !prs_uint32( "num_domains", ps, depth, &r_u->num_domains ) )
286 return False;
288 if ( r_u->num_domains ) {
289 if ( !ds_io_dom_trusts_ctr("domains", ps, depth, &r_u->domains ) )
290 return False;
293 if(!prs_align(ps))
294 return False;
296 if ( !prs_ntstatus("status", ps, depth, &r_u->status ) )
297 return False;
299 return True;