it now all compiles - so try enabling it by default and see what explodes on the...
[kai/samba.git] / source3 / rpc_parse / parse_dfs.c
1 /* 
2  *  Unix SMB/Netbios implementation.
3  *  Version 1.9.
4  *  MSDfs RPC Pipe client / server routines
5  *  Copyright (C) Andrew Tridgell              1992-2000,
6  *  Copyright (C) Luke Kenneth Casson Leighton 1996-2000,
7  *  Copyright (C) Shirish Kalele               2000.
8  *  Copyright (C) Jeremy Allison                                2001.
9  *  
10  *  This program is free software; you can redistribute it and/or modify
11  *  it under the terms of the GNU General Public License as published by
12  *  the Free Software Foundation; either version 2 of the License, or
13  *  (at your option) any later version.
14  *  
15  *  This program is distributed in the hope that it will be useful,
16  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  *  GNU General Public License for more details.
19  *  
20  *  You should have received a copy of the GNU General Public License
21  *  along with this program; if not, write to the Free Software
22  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23  */
24
25 #include "includes.h"
26 #include "nterr.h"
27 #include "rpc_parse.h"   
28
29 extern int DEBUGLEVEL;
30
31 /******************************************************************* 
32 Make a DFS_Q_DFS_QUERY structure
33 *******************************************************************/
34
35 void init_dfs_q_dfs_exist(DFS_Q_DFS_EXIST *q_d)
36 {
37         q_d->dummy = 0;
38 }
39
40 /*************************************************************
41  Read/write a DFS_Q_DFS_EXIST structure - dummy...
42  ************************************************************/
43
44 BOOL dfs_io_q_dfs_exist(char *desc, DFS_Q_DFS_EXIST *q_d, prs_struct *ps, int depth)
45 {
46         if(q_d == NULL)
47                 return False;
48   
49         prs_debug(ps, depth, desc, "dfs_io_q_dfs_exist");
50
51         return True;
52 }
53   
54 /*************************************************************
55  Read/write a DFS_R_DFS_EXIST structure
56  ************************************************************/
57
58 BOOL dfs_io_r_dfs_exist(char *desc, DFS_R_DFS_EXIST *q_d, prs_struct *ps, int depth)
59 {
60         if(q_d == NULL)
61                 return False;
62   
63         prs_debug(ps, depth, desc, "dfs_io_r_dfs_exist");
64         depth++;
65
66         if(!prs_align(ps))
67                 return False;
68
69         if(!prs_uint32("exist flag", ps, 0, &q_d->status))
70                 return False;
71
72         return True;
73 }
74   
75 /******************************************************************* 
76 Make a DFS_Q_DFS_REMOVE structure
77 *******************************************************************/
78
79 BOOL init_dfs_q_dfs_remove(DFS_Q_DFS_REMOVE *q_d, char *entrypath, 
80                            char *servername, char *sharename)
81 {
82         DEBUG(5,("init_dfs_q_dfs_remove\n"));
83         init_unistr2(&q_d->DfsEntryPath, entrypath,  strlen(entrypath)+1);
84         init_unistr2(&q_d->ServerName,   servername, strlen(servername)+1);
85         init_unistr2(&q_d->ShareName,    sharename,  strlen(sharename)+1);
86         q_d->ptr_ServerName = q_d->ptr_ShareName = 1;
87         return True;
88 }
89
90 /******************************************************************* 
91 Read/write a DFS_Q_DFS_REMOVE structure
92 *******************************************************************/
93
94 BOOL dfs_io_q_dfs_remove(char *desc, DFS_Q_DFS_REMOVE *q_d, prs_struct *ps, int depth)
95 {
96         if(q_d == NULL)
97                 return False;
98
99         prs_debug(ps, depth, desc, "dfs_io_q_dfs_remove");
100         depth++;
101   
102         if(!prs_align(ps))
103                 return False;
104   
105         if(!smb_io_unistr2("DfsEntryPath",&q_d->DfsEntryPath, 1, ps, depth))
106                 return False;
107
108         if(!prs_align(ps))
109                 return False;
110
111         if(!prs_uint32("ptr_ServerName", ps, depth, &q_d->ptr_ServerName))
112                 return False;
113         if(q_d->ptr_ServerName)
114                 if (!smb_io_unistr2("ServerName",&q_d->ServerName, q_d->ptr_ServerName, ps, depth))
115                         return False;
116         if(!prs_align(ps))
117                 return False;
118
119         if(!prs_uint32("ptr_ShareName", ps, depth, &q_d->ptr_ShareName))
120                 return False;
121         if(q_d->ptr_ShareName)
122                 if (!smb_io_unistr2("ShareName",&q_d->ShareName,  q_d->ptr_ShareName, ps, depth))
123                         return False;
124         if(!prs_align(ps))
125                 return False;
126
127         return True;
128 }
129
130 /******************************************************************* 
131 Read/write a DFS_R_DFS_REMOVE structure
132 *******************************************************************/
133
134 BOOL dfs_io_r_dfs_remove(char *desc, DFS_R_DFS_REMOVE *r_d, prs_struct *ps, int depth)
135 {
136         if(r_d == NULL) 
137                 return False;
138
139         prs_debug(ps, depth, desc, "dfs_io_r_dfs_remove");
140         depth++;
141
142         if(!prs_ntstatus("status", ps, depth, &r_d->status))
143                 return False;
144
145         return True;
146 }
147
148 /******************************************************************* 
149 Make a DFS_Q_DFS_ADD structure
150 *******************************************************************/
151
152 BOOL init_dfs_q_dfs_add(DFS_Q_DFS_ADD *q_d, char *entrypath, char *servername,
153                         char *sharename, char *comment, uint32 flags)
154 {
155         DEBUG(5,("init_dfs_q_dfs_add\n"));
156         q_d->ptr_DfsEntryPath = q_d->ptr_ServerName = q_d->ptr_ShareName = 1;
157         init_unistr2(&q_d->DfsEntryPath, entrypath,  strlen(entrypath)+1);
158         init_unistr2(&q_d->ServerName,   servername, strlen(servername)+1);
159         init_unistr2(&q_d->ShareName,    sharename,  strlen(sharename)+1);
160         if(comment != NULL) {
161                 init_unistr2(&q_d->Comment,      comment,    strlen(comment)+1);
162                 q_d->ptr_Comment = 1;
163         } else {
164                 q_d->ptr_Comment = 0;
165         }
166
167         q_d->Flags = flags;
168         return True;
169 }
170
171 /************************************************************
172  Read/write a DFS_Q_DFS_ADD structure
173  ************************************************************/
174
175 BOOL dfs_io_q_dfs_add(char *desc, DFS_Q_DFS_ADD *q_d, prs_struct *ps, int depth)
176 {
177         if(q_d == NULL)
178                 return False;
179
180         prs_debug(ps, depth, desc, "dfs_io_q_dfs_add");
181         depth++;
182   
183         if(!prs_align(ps))
184                 return False;
185   
186         if(!smb_io_unistr2("DfsEntryPath",&q_d->DfsEntryPath, 1, ps, depth))
187                 return False;
188         if(!prs_align(ps))
189                 return False;
190
191         if(!smb_io_unistr2("ServerName",&q_d->ServerName, 1, ps, depth))
192                 return False;
193         if(!prs_align(ps))
194                 return False;
195
196         if(!prs_uint32("ptr_ShareName", ps, depth, &q_d->ptr_ShareName))
197                 return False;
198         if(!smb_io_unistr2("ShareName",&q_d->ShareName,  1, ps, depth))
199                 return False;
200         if(!prs_align(ps))
201                 return False;
202
203         if(!prs_uint32("ptr_Comment", ps, depth, &q_d->ptr_Comment))
204                 return False;
205         if(!smb_io_unistr2("",&q_d->Comment, q_d->ptr_Comment , ps, depth))
206                 return False;
207         if(!prs_align(ps))
208                 return False;
209
210         if(!prs_uint32("Flags", ps, depth, &q_d->Flags))
211                 return True;
212
213         return True;
214 }
215
216 /************************************************************
217  Read/write a DFS_R_DFS_ADD structure 
218  ************************************************************/
219
220 BOOL dfs_io_r_dfs_add(char *desc, DFS_R_DFS_ADD *r_d, prs_struct *ps, int depth)
221 {
222         if(r_d == NULL)
223                 return False;
224
225         prs_debug(ps, depth, desc, "dfs_io_r_dfs_add");
226         depth++;
227
228         if(!prs_ntstatus("status", ps, depth, &r_d->status))
229                 return False;
230
231         return True;
232 }
233
234 BOOL init_dfs_q_dfs_get_info(DFS_Q_DFS_GET_INFO *q_d, char *entrypath,
235                              char *servername, char *sharename, 
236                              uint32 info_level)
237 {
238         DEBUG(5,("init_dfs_q2_get_info\n"));
239         init_unistr2(&q_d->uni_path, entrypath,  strlen(entrypath)+1);
240         init_unistr2(&q_d->uni_server,   servername, strlen(servername)+1);
241         init_unistr2(&q_d->uni_share,    sharename,  strlen(sharename)+1);
242         q_d->level = info_level;
243         q_d->ptr_server = q_d->ptr_share = 1;
244         return True;
245 }
246
247 /************************************************************
248  Read/write a DFS_Q_GET_INFO structure
249  ************************************************************/
250
251 BOOL dfs_io_q_dfs_get_info(char* desc, DFS_Q_DFS_GET_INFO* q_i, prs_struct* ps, int depth)
252 {
253         if(q_i == NULL)
254                 return False;
255
256         prs_debug(ps, depth, desc, "dfs_io_q_dfs_get_info");
257         depth++;
258
259         if(!smb_io_unistr2("",&q_i->uni_path, 1, ps, depth))
260                 return False;
261
262         if(!prs_align(ps))
263                 return False;
264
265         if(!prs_uint32("ptr_server", ps, depth, &q_i->ptr_server))
266                 return False;
267
268         if(q_i->ptr_server)
269                 if (!smb_io_unistr2("",&q_i->uni_server, q_i->ptr_server, ps, depth))
270                         return False;
271         if(!prs_align(ps))
272                 return False;
273
274         if(!prs_uint32("ptr_share", ps, depth, &q_i->ptr_share))
275                 return False;
276         if(q_i->ptr_share)
277                 if(!smb_io_unistr2("", &q_i->uni_share, q_i->ptr_share, ps, depth))
278                         return False;
279         if(!prs_align(ps))
280                 return False;
281
282         if(!prs_uint32("level", ps, depth, &q_i->level))
283                 return False;
284         return True;
285 }
286
287 /************************************************************
288  Read/write a DFS_R_GET_INFO structure
289  ************************************************************/
290
291 BOOL dfs_io_r_dfs_get_info(char* desc, DFS_R_DFS_GET_INFO* r_i, prs_struct* ps, int depth)
292 {
293         if(r_i == NULL)
294                 return False;
295   
296         if(!prs_uint32("level", ps, depth, &r_i->level))
297                 return False;
298         if(!prs_uint32("ptr_ctr", ps, depth, &r_i->ptr_ctr))
299                 return False;
300
301         if(!dfs_io_dfs_info_ctr("", &r_i->ctr, 1, r_i->level, ps, depth))
302                 return False;
303         if(!prs_ntstatus("status", ps, depth, &r_i->status))
304                 return False;
305         return True;
306 }
307                            
308 /************************************************************
309  Make a DFS_Q_DFS_ENUM structure
310  ************************************************************/
311 BOOL init_dfs_q_dfs_enum(DFS_Q_DFS_ENUM *q_d, uint32 level, DFS_INFO_CTR *ctr)
312 {
313         q_d->level = level;
314         q_d->maxpreflen = -1;
315         q_d->ptr_buffer = 1;
316         q_d->level2 = level;
317   
318         q_d->ptr_num_entries = 1;
319         q_d->num_entries = 0;
320         q_d->num_entries2 = 0;
321         q_d->reshnd.ptr_hnd = 1;
322         q_d->reshnd.handle = 0;
323         return True;
324 }
325   
326 /************************************************************
327  Read or write the DFS_Q_DFS_ENUM structure 
328  ************************************************************/
329
330 BOOL dfs_io_q_dfs_enum(char *desc, DFS_Q_DFS_ENUM *q_d, prs_struct *ps, int depth)
331 {
332         if(q_d == NULL)
333                 return False;
334
335         prs_debug(ps, depth, desc, "dfs_io_q_dfs_enum");
336         depth++;
337   
338         if(!prs_align(ps))
339                 return False;
340   
341         if(!prs_uint32("level", ps, depth, &q_d->level))
342                 return False;
343         if(!prs_uint32("maxpreflen", ps, depth, &q_d->maxpreflen))
344                 return False;
345         if(!prs_uint32("ptr_buffer", ps, depth, &q_d->ptr_buffer))
346                 return False;
347         if(!prs_uint32("level2", ps, depth, &q_d->level2))
348                 return False;
349         if(!prs_uint32("level3", ps, depth, &q_d->level2))
350                 return False;
351   
352         if(!prs_uint32("ptr_num_entries", ps, depth, &q_d->ptr_num_entries))
353                 return False;
354         if(!prs_uint32("num_entries", ps, depth, &q_d->num_entries))
355                 return False;
356         if(!prs_uint32("num_entries2", ps, depth, &q_d->num_entries2))
357                 return False;
358         if(!smb_io_enum_hnd("resume_hnd",&q_d->reshnd, ps, depth))
359                 return False;
360         return True;
361 }
362
363 /************************************************************
364  Read/write a DFS_INFO_CTR structure
365  ************************************************************/
366
367 BOOL dfs_io_dfs_info_ctr(char* desc, DFS_INFO_CTR* ctr, uint32 num_entries, uint32 level, prs_struct* ps, int depth)
368 {
369         int i=0;
370
371         switch(level) {
372         case 1:
373                 depth++;
374                 /* should depend on whether marshalling or unmarshalling! */
375                 if(UNMARSHALLING(ps)) {
376                         ctr->dfs.info1 = (DFS_INFO_1 *)prs_alloc_mem(ps, sizeof(DFS_INFO_1)*num_entries);
377                         if (!ctr->dfs.info1)
378                                 return False;
379                 }
380
381                 for(i=0;i<num_entries;i++) {
382                         if(!prs_uint32("ptr_entrypath",ps, depth, &ctr->dfs.info1[i].ptr_entrypath))
383                                 return False;
384                 }
385                 for(i=0;i<num_entries;i++) {
386                         if(!smb_io_unistr2("", &ctr->dfs.info1[i].entrypath, ctr->dfs.info1[i].ptr_entrypath, ps, depth))
387                                 return False;
388                         if(!prs_align(ps))
389                                 return False;
390                 }
391                 depth--;
392                 break;
393         case 2:
394                 depth++;
395                 if(UNMARSHALLING(ps)) {
396                         ctr->dfs.info2 = (DFS_INFO_2 *)prs_alloc_mem(ps, num_entries*sizeof(DFS_INFO_2));
397                         if (!ctr->dfs.info2)
398                                 return False;
399                 }
400
401                 for(i=0;i<num_entries;i++) {
402                         if(!prs_uint32("ptr_entrypath", ps, depth, &ctr->dfs.info2[i].ptr_entrypath))
403                                 return False;
404                         if(!prs_uint32("ptr_comment", ps, depth, &ctr->dfs.info2[i].ptr_comment))
405                                 return False;
406                         if(!prs_uint32("state", ps, depth, &ctr->dfs.info2[i].state))
407                                 return False;
408                         if(!prs_uint32("num_storages", ps, depth, &ctr->dfs.info2[i].num_storages))
409                                 return False;
410                 }
411                 for(i=0;i<num_entries;i++) {
412                         if(!smb_io_unistr2("", &ctr->dfs.info2[i].entrypath, ctr->dfs.info2[i].ptr_entrypath, ps, depth))
413                                 return False;
414                         if(!prs_align(ps))
415                                 return False;
416                         if(!smb_io_unistr2("",&ctr->dfs.info2[i].comment, ctr->dfs.info2[i].ptr_comment, ps, depth))
417                                 return False;
418                         if(!prs_align(ps))
419                                 return False;
420                 }
421                 depth--;
422                 break;
423         case 3:
424                 depth++;
425                 if(UNMARSHALLING(ps)) {
426                         ctr->dfs.info3 = (DFS_INFO_3 *)prs_alloc_mem(ps, num_entries*sizeof(DFS_INFO_3));
427                         if (!ctr->dfs.info3)
428                                 return False;
429                 }
430
431                 for(i=0;i<num_entries;i++) {
432                         if(!prs_uint32("ptr_entrypath", ps, depth, &ctr->dfs.info3[i].ptr_entrypath))
433                                 return False;
434                         if(!prs_uint32("ptr_comment", ps, depth, &ctr->dfs.info3[i].ptr_comment))
435                                 return False;
436                         if(!prs_uint32("state", ps, depth, &ctr->dfs.info3[i].state))
437                                 return False;
438                         if(!prs_uint32("num_storages", ps, depth, &ctr->dfs.info3[i].num_storages))
439                                 return False;
440                         if(!prs_uint32("ptr_storages", ps, depth, &ctr->dfs.info3[i].ptr_storages))
441                                 return False;
442                 }
443                 for(i=0;i<num_entries;i++) {
444                         if(!smb_io_unistr2("", &ctr->dfs.info3[i].entrypath, ctr->dfs.info3[i].ptr_entrypath, ps, depth))
445                                 return False;
446                         if(!prs_align(ps))
447                                 return False;
448                         if(!smb_io_unistr2("", &ctr->dfs.info3[i].comment, ctr->dfs.info3[i].ptr_comment, ps, depth))
449                                 return False;
450                         if(!prs_align(ps))
451                                 return False;
452                         if(!prs_uint32("num_storage_infos", ps, depth, &ctr->dfs.info3[i].num_storage_infos))
453                                 return False;
454
455                         if(!dfs_io_dfs_storage_info("storage_info", &ctr->dfs.info3[i], ps, depth))
456                                 return False;
457                 }
458         }
459
460         return True;
461 }
462
463 /************************************************************
464  Read/write a DFS_R_DFS_ENUM structure
465  ************************************************************/
466
467 BOOL dfs_io_r_dfs_enum(char *desc, DFS_R_DFS_ENUM *q_d, prs_struct *ps, int depth)
468 {
469         DFS_INFO_CTR *ctr;
470         if(q_d == NULL)
471                 return False;
472         ctr = q_d->ctr;
473         if(ctr == NULL)
474                 return False;
475
476         prs_debug(ps, depth, desc, "dfs_io_r_dfs_enum");
477         depth++;
478
479         if(!prs_align(ps))
480                 return False;
481
482         if(!prs_uint32("ptr_buffer", ps, depth, &q_d->ptr_buffer))
483                 return False;
484         if(!prs_uint32("level", ps, depth, &q_d->level))
485                 return False;
486         if(!prs_uint32("level2", ps, depth, &ctr->switch_value))
487                 return False;
488         if(!prs_uint32("ptr_num_entries", ps, depth, &q_d->ptr_num_entries))
489                 return False;
490         if(q_d->ptr_num_entries)
491                 if(!prs_uint32("num_entries", ps, depth, &q_d->num_entries))
492                         return False;
493         if(!prs_uint32("ptr_num_entries2", ps, depth, &q_d->ptr_num_entries2))
494                 return False;
495         if(q_d->ptr_num_entries2)
496                 if(!prs_uint32("num_entries2", ps, depth, &ctr->num_entries))
497                         return False;
498
499         if(!dfs_io_dfs_info_ctr("", ctr, q_d->num_entries, q_d->level, ps, depth))
500                 return False;
501
502         if(!smb_io_enum_hnd("resume_hnd", &q_d->reshnd, ps, depth))
503                 return False;
504         if(!prs_ntstatus("status", ps, depth, &q_d->status))
505                 return False;
506         return True;
507 }
508
509 BOOL dfs_io_dfs_storage_info(char *desc, DFS_INFO_3* info3, prs_struct *ps, int depth)
510 {
511         int i=0;
512         if(info3 == NULL)
513                 return False;
514   
515         prs_debug(ps, depth, desc, "smb_io_dfs_storage_info");
516         depth++;
517
518         if(UNMARSHALLING(ps)) {
519                 info3->storages = (DFS_STORAGE_INFO *)prs_alloc_mem(ps, info3->num_storage_infos*sizeof(DFS_STORAGE_INFO));
520                 if (!info3->storages)
521                         return False;
522         }
523
524         for(i=0;i<info3->num_storage_infos;i++) {
525                 if(!prs_uint32("storage_state", ps, depth, &info3->storages[i].state))
526                         return False;
527                 if(!prs_uint32("ptr_servername", ps, depth, &info3->storages[i].ptr_servername))
528                         return False;
529                 if(!prs_uint32("ptr_sharename", ps, depth, &info3->storages[i].ptr_sharename))
530                         return False;
531         }
532
533         for(i=0;i<info3->num_storage_infos;i++) {
534                 if(!smb_io_unistr2("servername", &info3->storages[i].servername, info3->storages[i].ptr_servername, ps, depth))
535                         return False;
536                 if(!prs_align(ps))
537                         return False;
538                 if(!smb_io_unistr2("sharename", &info3->storages[i].sharename, info3->storages[i].ptr_sharename, ps, depth))
539                         return False;
540                 if(!prs_align(ps))
541                         return False;
542         }
543
544         return True;
545 }