r23801: The FSF has moved around a lot. This fixes their Mass Ave address.
[samba.git] / source3 / rpc_parse / parse_ds.c
1 /* 
2  *  Unix SMB/CIFS implementation.
3  *  RPC Pipe client / server routines
4  
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 3 of the License, or
10  *  (at your option) any later version.
11  *  
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.
16  *  
17  *  You should have received a copy of the GNU General Public License
18  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
19  */
20
21 #include "includes.h"
22
23 /************************************************************************
24 ************************************************************************/
25
26 static BOOL ds_io_dominfobasic(const char *desc, DSROLE_PRIMARY_DOMAIN_INFO_BASIC **basic, prs_struct *ps, int depth)
27 {
28         DSROLE_PRIMARY_DOMAIN_INFO_BASIC *p = *basic;
29         
30         if ( UNMARSHALLING(ps) ) {
31                 p = *basic = PRS_ALLOC_MEM(ps, DSROLE_PRIMARY_DOMAIN_INFO_BASIC, 1);
32         }
33                 
34         if ( !p )
35                 return False;
36                 
37         if ( !prs_uint16("machine_role", ps, depth, &p->machine_role) )
38                 return False;
39         if ( !prs_align(ps) )
40                 return False;
41
42         if ( !prs_uint32("flags", ps, depth, &p->flags) )
43                 return False;
44
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;
51                 
52         if ( !smb_io_uuid("domain_guid", &p->domain_guid, ps, depth) )
53                 return False;
54                 
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;
59         
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;
64         
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;
69         
70                 
71         return True;
72                 
73 }
74
75 /************************************************************************
76 ************************************************************************/
77
78 BOOL ds_io_q_getprimdominfo( const char *desc, DS_Q_GETPRIMDOMINFO *q_u, prs_struct *ps, int depth)
79 {
80         prs_debug(ps, depth, desc, "ds_io_q_getprimdominfo");
81         depth++;
82
83         if(!prs_align(ps))
84                 return False;
85
86         if ( !prs_uint16( "level", ps, depth, &q_u->level ) )
87                 return False;
88                 
89         return True;
90 }
91
92 /************************************************************************
93 ************************************************************************/
94
95 BOOL ds_io_r_getprimdominfo( const char *desc, DS_R_GETPRIMDOMINFO *r_u, prs_struct *ps, int depth)
96 {
97         prs_debug(ps, depth, desc, "ds_io_r_getprimdominfo");
98         depth++;
99
100         if(!prs_align(ps))
101                 return False;
102
103         if ( !prs_uint32( "ptr", ps, depth, &r_u->ptr ) )
104                 return False;
105                 
106         if ( r_u->ptr )
107         {
108                 if ( !prs_uint16( "level", ps, depth, &r_u->level ) )
109                         return False;
110         
111                 if ( !prs_uint16( "unknown0", ps, depth, &r_u->unknown0 ) )
112                         return False;
113                 
114                 switch ( r_u->level )
115                 {
116                         case DsRolePrimaryDomainInfoBasic:
117                                 if ( !ds_io_dominfobasic( "dominfobasic", &r_u->info.basic, ps, depth) )
118                                         return False;
119                                 break;
120                         default:
121                                 return False;
122                 }
123         }
124
125         if ( !prs_align(ps) )
126                 return False;
127         
128         if ( !prs_ntstatus("status", ps, depth, &r_u->status ) )
129                 return False;           
130                 
131         return True;
132 }
133
134 /************************************************************************
135  initialize a DS_ENUM_DOM_TRUSTS structure
136 ************************************************************************/
137
138 BOOL init_q_ds_enum_domain_trusts( DS_Q_ENUM_DOM_TRUSTS *q, const char *server, uint32 flags )
139 {
140         q->flags = flags;
141         
142         if ( server && *server )
143                 q->server_ptr = 1;
144         else
145                 q->server_ptr = 0;
146
147         init_unistr2( &q->server, server, UNI_STR_TERMINATE);
148                 
149         return True;
150 }
151
152 /************************************************************************
153 ************************************************************************/
154
155 static BOOL ds_io_domain_trusts( const char *desc, DS_DOMAIN_TRUSTS *trust, prs_struct *ps, int depth)
156 {
157         prs_debug(ps, depth, desc, "ds_io_dom_trusts_ctr");
158         depth++;
159
160         if ( !prs_uint32( "netbios_ptr", ps, depth, &trust->netbios_ptr ) )
161                 return False;
162         
163         if ( !prs_uint32( "dns_ptr", ps, depth, &trust->dns_ptr ) )
164                 return False;
165         
166         if ( !prs_uint32( "flags", ps, depth, &trust->flags ) )
167                 return False;
168         
169         if ( !prs_uint32( "parent_index", ps, depth, &trust->parent_index ) )
170                 return False;
171         
172         if ( !prs_uint32( "trust_type", ps, depth, &trust->trust_type ) )
173                 return False;
174         
175         if ( !prs_uint32( "trust_attributes", ps, depth, &trust->trust_attributes ) )
176                 return False;
177         
178         if ( !prs_uint32( "sid_ptr", ps, depth, &trust->sid_ptr ) )
179                 return False;
180         
181         if ( !smb_io_uuid("guid", &trust->guid, ps, depth) )
182                 return False;
183         
184         return True;    
185 }
186
187 /************************************************************************
188 ************************************************************************/
189
190 static BOOL ds_io_dom_trusts_ctr( const char *desc, DS_DOMAIN_TRUSTS_CTR *ctr, prs_struct *ps, int depth)
191 {
192         int i;
193
194         prs_debug(ps, depth, desc, "ds_io_dom_trusts_ctr");
195         depth++;
196         
197         if ( !prs_uint32( "ptr", ps, depth, &ctr->ptr ) )
198                 return False;
199         
200         if ( !prs_uint32( "max_count", ps, depth, &ctr->max_count ) )
201                 return False;
202         
203         /* are we done? */
204         
205         if ( ctr->max_count == 0 )
206                 return True;
207         
208         /* allocate the domain trusts array are parse it */
209         
210         ctr->trusts = TALLOC_ARRAY(ps->mem_ctx, DS_DOMAIN_TRUSTS, ctr->max_count);
211         
212         if ( !ctr->trusts )
213                 return False;
214         
215         /* this stinks; the static portion o fthe structure is read here and then
216            we need another loop to read the UNISTR2's and SID's */
217            
218         for ( i=0; i<ctr->max_count;i++ ) {
219                 if ( !ds_io_domain_trusts("domain_trusts", &ctr->trusts[i], ps, depth) )
220                         return False;
221         }
222
223         for ( i=0; i<ctr->max_count; i++ ) {
224         
225                 if ( !smb_io_unistr2("netbios_domain", &ctr->trusts[i].netbios_domain, ctr->trusts[i].netbios_ptr, ps, depth) )
226                         return False;
227
228                 if(!prs_align(ps))
229                         return False;
230                 
231                 if ( !smb_io_unistr2("dns_domain", &ctr->trusts[i].dns_domain, ctr->trusts[i].dns_ptr, ps, depth) )
232                         return False;
233
234                 if(!prs_align(ps))
235                         return False;
236                         
237                 if ( ctr->trusts[i].sid_ptr ) {
238                         if ( !smb_io_dom_sid2("sid", &ctr->trusts[i].sid, ps, depth ) )
239                                 return False;           
240                 }
241         }
242         
243         return True;
244 }
245
246 /************************************************************************
247  initialize a DS_ENUM_DOM_TRUSTS request
248 ************************************************************************/
249
250 BOOL ds_io_q_enum_domain_trusts( const char *desc, DS_Q_ENUM_DOM_TRUSTS *q_u, prs_struct *ps, int depth)
251 {
252         prs_debug(ps, depth, desc, "ds_io_q_enum_domain_trusts");
253         depth++;
254
255         if ( !prs_align(ps) )
256                 return False;
257         
258         if ( !prs_uint32( "server_ptr", ps, depth, &q_u->server_ptr ) )
259                 return False;
260         
261         if ( !smb_io_unistr2("server", &q_u->server, q_u->server_ptr, ps, depth) )
262                         return False;
263         
264         if ( !prs_align(ps) )
265                 return False;
266         
267         if ( !prs_uint32( "flags", ps, depth, &q_u->flags ) )
268                 return False;
269         
270         return True;
271 }
272
273 /************************************************************************
274 ************************************************************************/
275
276 BOOL ds_io_r_enum_domain_trusts( const char *desc, DS_R_ENUM_DOM_TRUSTS *r_u, prs_struct *ps, int depth)
277 {
278         prs_debug(ps, depth, desc, "ds_io_r_enum_domain_trusts");
279         depth++;
280
281         if(!prs_align(ps))
282                 return False;
283
284         if ( !prs_uint32( "num_domains", ps, depth, &r_u->num_domains ) )
285                 return False;
286                 
287         if ( r_u->num_domains ) {
288                 if ( !ds_io_dom_trusts_ctr("domains", &r_u->domains, ps, depth) )
289                         return False;
290         }
291                 
292         if(!prs_align(ps))
293                 return False;
294                         
295         if ( !prs_ntstatus("status", ps, depth, &r_u->status ) )
296                 return False;           
297                 
298         return True;
299 }