Finally delete rpccli_ds_enum_domain_trusts() completly.
[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  initialize a DS_ENUM_DOM_TRUSTS structure
25 ************************************************************************/
26
27 bool init_q_ds_enum_domain_trusts( DS_Q_ENUM_DOM_TRUSTS *q, const char *server, uint32 flags )
28 {
29         q->flags = flags;
30         
31         if ( server && *server )
32                 q->server_ptr = 1;
33         else
34                 q->server_ptr = 0;
35
36         init_unistr2( &q->server, server, UNI_STR_TERMINATE);
37                 
38         return True;
39 }
40
41 /************************************************************************
42 ************************************************************************/
43
44 static bool ds_io_domain_trusts( const char *desc, DS_DOMAIN_TRUSTS *trust, prs_struct *ps, int depth)
45 {
46         prs_debug(ps, depth, desc, "ds_io_dom_trusts_ctr");
47         depth++;
48
49         if ( !prs_uint32( "netbios_ptr", ps, depth, &trust->netbios_ptr ) )
50                 return False;
51         
52         if ( !prs_uint32( "dns_ptr", ps, depth, &trust->dns_ptr ) )
53                 return False;
54         
55         if ( !prs_uint32( "flags", ps, depth, &trust->flags ) )
56                 return False;
57         
58         if ( !prs_uint32( "parent_index", ps, depth, &trust->parent_index ) )
59                 return False;
60         
61         if ( !prs_uint32( "trust_type", ps, depth, &trust->trust_type ) )
62                 return False;
63         
64         if ( !prs_uint32( "trust_attributes", ps, depth, &trust->trust_attributes ) )
65                 return False;
66         
67         if ( !prs_uint32( "sid_ptr", ps, depth, &trust->sid_ptr ) )
68                 return False;
69         
70         if ( !smb_io_uuid("guid", &trust->guid, ps, depth) )
71                 return False;
72         
73         return True;    
74 }
75
76 /************************************************************************
77 ************************************************************************/
78
79 static bool ds_io_dom_trusts_ctr( const char *desc, DS_DOMAIN_TRUSTS_CTR *ctr, prs_struct *ps, int depth)
80 {
81         int i;
82
83         prs_debug(ps, depth, desc, "ds_io_dom_trusts_ctr");
84         depth++;
85         
86         if ( !prs_uint32( "ptr", ps, depth, &ctr->ptr ) )
87                 return False;
88         
89         if ( !prs_uint32( "max_count", ps, depth, &ctr->max_count ) )
90                 return False;
91         
92         /* are we done? */
93         
94         if ( ctr->max_count == 0 )
95                 return True;
96         
97         /* allocate the domain trusts array are parse it */
98         
99         ctr->trusts = TALLOC_ARRAY(ps->mem_ctx, DS_DOMAIN_TRUSTS, ctr->max_count);
100         
101         if ( !ctr->trusts )
102                 return False;
103         
104         /* this stinks; the static portion o fthe structure is read here and then
105            we need another loop to read the UNISTR2's and SID's */
106            
107         for ( i=0; i<ctr->max_count;i++ ) {
108                 if ( !ds_io_domain_trusts("domain_trusts", &ctr->trusts[i], ps, depth) )
109                         return False;
110         }
111
112         for ( i=0; i<ctr->max_count; i++ ) {
113         
114                 if ( !smb_io_unistr2("netbios_domain", &ctr->trusts[i].netbios_domain, ctr->trusts[i].netbios_ptr, ps, depth) )
115                         return False;
116
117                 if(!prs_align(ps))
118                         return False;
119                 
120                 if ( !smb_io_unistr2("dns_domain", &ctr->trusts[i].dns_domain, ctr->trusts[i].dns_ptr, ps, depth) )
121                         return False;
122
123                 if(!prs_align(ps))
124                         return False;
125                         
126                 if ( ctr->trusts[i].sid_ptr ) {
127                         if ( !smb_io_dom_sid2("sid", &ctr->trusts[i].sid, ps, depth ) )
128                                 return False;           
129                 }
130         }
131         
132         return True;
133 }
134
135 /************************************************************************
136  initialize a DS_ENUM_DOM_TRUSTS request
137 ************************************************************************/
138
139 bool ds_io_q_enum_domain_trusts( const char *desc, DS_Q_ENUM_DOM_TRUSTS *q_u, prs_struct *ps, int depth)
140 {
141         prs_debug(ps, depth, desc, "ds_io_q_enum_domain_trusts");
142         depth++;
143
144         if ( !prs_align(ps) )
145                 return False;
146         
147         if ( !prs_uint32( "server_ptr", ps, depth, &q_u->server_ptr ) )
148                 return False;
149         
150         if ( !smb_io_unistr2("server", &q_u->server, q_u->server_ptr, ps, depth) )
151                         return False;
152         
153         if ( !prs_align(ps) )
154                 return False;
155         
156         if ( !prs_uint32( "flags", ps, depth, &q_u->flags ) )
157                 return False;
158         
159         return True;
160 }
161
162 /************************************************************************
163 ************************************************************************/
164
165 bool ds_io_r_enum_domain_trusts( const char *desc, DS_R_ENUM_DOM_TRUSTS *r_u, prs_struct *ps, int depth)
166 {
167         prs_debug(ps, depth, desc, "ds_io_r_enum_domain_trusts");
168         depth++;
169
170         if(!prs_align(ps))
171                 return False;
172
173         if ( !prs_uint32( "num_domains", ps, depth, &r_u->num_domains ) )
174                 return False;
175                 
176         if ( r_u->num_domains ) {
177                 if ( !ds_io_dom_trusts_ctr("domains", &r_u->domains, ps, depth) )
178                         return False;
179         }
180                 
181         if(!prs_align(ps))
182                 return False;
183                         
184         if ( !prs_ntstatus("status", ps, depth, &r_u->status ) )
185                 return False;           
186                 
187         return True;
188 }