sync with SAMBA_2_2
[Samba/gbeck.git] / source / rpc_parse / parse_dfs.c
blob6bae2ae4a6b895a9412f6f6cb93a41fdee9f446d
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.
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.
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.
25 #include "includes.h"
26 #include "nterr.h"
27 #include "rpc_parse.h"
29 extern int DEBUGLEVEL;
31 /*************************************************************
32 Read/write a DFS_Q_DFS_EXIST structure - dummy...
33 ************************************************************/
35 BOOL dfs_io_q_dfs_exist(char *desc, DFS_Q_DFS_EXIST *q_d, prs_struct *ps, int depth)
37 if(q_d == NULL)
38 return False;
40 prs_debug(ps, depth, desc, "dfs_io_q_dfs_exist");
42 return True;
45 /*************************************************************
46 Read/write a DFS_R_DFS_EXIST structure
47 ************************************************************/
49 BOOL dfs_io_r_dfs_exist(char *desc, DFS_R_DFS_EXIST *q_d, prs_struct *ps, int depth)
51 if(q_d == NULL)
52 return False;
54 prs_debug(ps, depth, desc, "dfs_io_r_dfs_exist");
55 depth++;
57 if(!prs_align(ps))
58 return False;
60 if(!prs_uint32("exist flag", ps, 0, &q_d->status))
61 return False;
63 return True;
66 /*******************************************************************
67 Make a DFS_Q_DFS_REMOVE structure
68 *******************************************************************/
70 BOOL make_dfs_q_dfs_remove(DFS_Q_DFS_REMOVE *q_d, char *entrypath,
71 char *servername, char *sharename)
73 DEBUG(5,("make_dfs_q_dfs_remove\n"));
74 init_unistr2(&q_d->DfsEntryPath, entrypath, strlen(entrypath)+1);
75 init_unistr2(&q_d->ServerName, servername, strlen(servername)+1);
76 init_unistr2(&q_d->ShareName, sharename, strlen(sharename)+1);
77 q_d->ptr_ServerName = q_d->ptr_ShareName = 1;
78 return True;
81 /*******************************************************************
82 Read/write a DFS_Q_DFS_REMOVE structure
83 *******************************************************************/
85 BOOL dfs_io_q_dfs_remove(char *desc, DFS_Q_DFS_REMOVE *q_d, prs_struct *ps, int depth)
87 if(q_d == NULL)
88 return False;
90 prs_debug(ps, depth, desc, "dfs_io_q_dfs_remove");
91 depth++;
93 if(!prs_align(ps))
94 return False;
96 if(!smb_io_unistr2("DfsEntryPath",&q_d->DfsEntryPath, 1, ps, depth))
97 return False;
99 if(!prs_align(ps))
100 return False;
102 if(!prs_uint32("ptr_ServerName", ps, depth, &q_d->ptr_ServerName))
103 return False;
104 if(q_d->ptr_ServerName)
105 if (!smb_io_unistr2("ServerName",&q_d->ServerName, q_d->ptr_ServerName, ps, depth))
106 return False;
107 if(!prs_align(ps))
108 return False;
110 if(!prs_uint32("ptr_ShareName", ps, depth, &q_d->ptr_ShareName))
111 return False;
112 if(q_d->ptr_ShareName)
113 if (!smb_io_unistr2("ShareName",&q_d->ShareName, q_d->ptr_ShareName, ps, depth))
114 return False;
115 if(!prs_align(ps))
116 return False;
118 return True;
121 /*******************************************************************
122 Read/write a DFS_R_DFS_REMOVE structure
123 *******************************************************************/
125 BOOL dfs_io_r_dfs_remove(char *desc, DFS_R_DFS_REMOVE *r_d, prs_struct *ps, int depth)
127 if(r_d == NULL)
128 return False;
130 prs_debug(ps, depth, desc, "dfs_io_r_dfs_remove");
131 depth++;
133 if(!prs_uint32("status", ps, depth, &r_d->status))
134 return False;
136 return True;
139 /*******************************************************************
140 Make a DFS_Q_DFS_ADD structure
141 *******************************************************************/
143 BOOL make_dfs_q_dfs_add(DFS_Q_DFS_ADD *q_d, char *entrypath, char *servername,
144 char *sharename, char *comment, uint32 flags)
146 DEBUG(5,("make_dfs_q_dfs_add\n"));
147 q_d->ptr_DfsEntryPath = q_d->ptr_ServerName = q_d->ptr_ShareName = 1;
148 init_unistr2(&q_d->DfsEntryPath, entrypath, strlen(entrypath)+1);
149 init_unistr2(&q_d->ServerName, servername, strlen(servername)+1);
150 init_unistr2(&q_d->ShareName, sharename, strlen(sharename)+1);
151 if(comment != NULL) {
152 init_unistr2(&q_d->Comment, comment, strlen(comment)+1);
153 q_d->ptr_Comment = 1;
154 } else {
155 q_d->ptr_Comment = 0;
158 q_d->Flags = flags;
159 return True;
162 /************************************************************
163 Read/write a DFS_Q_DFS_ADD structure
164 ************************************************************/
166 BOOL dfs_io_q_dfs_add(char *desc, DFS_Q_DFS_ADD *q_d, prs_struct *ps, int depth)
168 if(q_d == NULL)
169 return False;
171 prs_debug(ps, depth, desc, "dfs_io_q_dfs_add");
172 depth++;
174 if(!prs_align(ps))
175 return False;
177 if(!smb_io_unistr2("DfsEntryPath",&q_d->DfsEntryPath, 1, ps, depth))
178 return False;
179 if(!prs_align(ps))
180 return False;
182 if(!smb_io_unistr2("ServerName",&q_d->ServerName, 1, ps, depth))
183 return False;
184 if(!prs_align(ps))
185 return False;
187 if(!prs_uint32("ptr_ShareName", ps, depth, &q_d->ptr_ShareName))
188 return False;
189 if(!smb_io_unistr2("ShareName",&q_d->ShareName, 1, ps, depth))
190 return False;
191 if(!prs_align(ps))
192 return False;
194 if(!prs_uint32("ptr_Comment", ps, depth, &q_d->ptr_Comment))
195 return False;
196 if(!smb_io_unistr2("",&q_d->Comment, q_d->ptr_Comment , ps, depth))
197 return False;
198 if(!prs_align(ps))
199 return False;
201 if(!prs_uint32("Flags", ps, depth, &q_d->Flags))
202 return True;
204 return True;
207 /************************************************************
208 Read/write a DFS_R_DFS_ADD structure
209 ************************************************************/
211 BOOL dfs_io_r_dfs_add(char *desc, DFS_R_DFS_ADD *r_d, prs_struct *ps, int depth)
213 if(r_d == NULL)
214 return False;
216 prs_debug(ps, depth, desc, "dfs_io_r_dfs_add");
217 depth++;
219 if(!prs_uint32("status", ps, depth, &r_d->status))
220 return False;
222 return True;
225 /************************************************************
226 Read/write a DFS_Q_GET_INFO structure
227 ************************************************************/
229 BOOL dfs_io_q_dfs_get_info(char* desc, DFS_Q_DFS_GET_INFO* q_i, prs_struct* ps, int depth)
231 if(q_i == NULL)
232 return False;
234 prs_debug(ps, depth, desc, "dfs_io_q_dfs_get_info");
235 depth++;
237 if(!smb_io_unistr2("",&q_i->uni_path, 1, ps, depth))
238 return False;
240 if(!prs_align(ps))
241 return False;
243 if(!prs_uint32("ptr_server", ps, depth, &q_i->ptr_server))
244 return False;
246 if(q_i->ptr_server)
247 if (!smb_io_unistr2("",&q_i->uni_server, q_i->ptr_server, ps, depth))
248 return False;
249 if(!prs_align(ps))
250 return False;
252 if(!prs_uint32("ptr_share", ps, depth, &q_i->ptr_share))
253 return False;
254 if(q_i->ptr_share)
255 if(!smb_io_unistr2("", &q_i->uni_share, q_i->ptr_share, ps, depth))
256 return False;
257 if(!prs_align(ps))
258 return False;
260 if(!prs_uint32("level", ps, depth, &q_i->level))
261 return False;
262 return True;
265 /************************************************************
266 Read/write a DFS_R_GET_INFO structure
267 ************************************************************/
269 BOOL dfs_io_r_dfs_get_info(char* desc, DFS_R_DFS_GET_INFO* r_i, prs_struct* ps, int depth)
271 if(r_i == NULL)
272 return False;
274 if(!prs_uint32("level", ps, depth, &r_i->level))
275 return False;
276 if(!prs_uint32("ptr_ctr", ps, depth, &r_i->ptr_ctr))
277 return False;
279 if(!dfs_io_dfs_info_ctr("", &r_i->ctr, 1, r_i->level, ps, depth))
280 return False;
281 if(!prs_uint32("status", ps, depth, &r_i->status))
282 return False;
283 return True;
286 /************************************************************
287 Make a DFS_Q_DFS_ENUM structure
288 ************************************************************/
289 BOOL make_dfs_q_dfs_enum(DFS_Q_DFS_ENUM *q_d, uint32 level, DFS_INFO_CTR *ctr)
291 q_d->level = level;
292 q_d->maxpreflen = -1;
293 q_d->ptr_buffer = 1;
294 q_d->level2 = level;
296 q_d->ptr_num_entries = 1;
297 q_d->num_entries = 0;
298 q_d->num_entries2 = 0;
299 q_d->reshnd.ptr_hnd = 1;
300 q_d->reshnd.handle = 0;
301 return True;
304 /************************************************************
305 Read or write the DFS_Q_DFS_ENUM structure
306 ************************************************************/
308 BOOL dfs_io_q_dfs_enum(char *desc, DFS_Q_DFS_ENUM *q_d, prs_struct *ps, int depth)
310 if(q_d == NULL)
311 return False;
313 prs_debug(ps, depth, desc, "dfs_io_q_dfs_enum");
314 depth++;
316 if(!prs_align(ps))
317 return False;
319 if(!prs_uint32("level", ps, depth, &q_d->level))
320 return False;
321 if(!prs_uint32("maxpreflen", ps, depth, &q_d->maxpreflen))
322 return False;
323 if(!prs_uint32("ptr_buffer", ps, depth, &q_d->ptr_buffer))
324 return False;
325 if(!prs_uint32("level2", ps, depth, &q_d->level2))
326 return False;
327 if(!prs_uint32("level3", ps, depth, &q_d->level2))
328 return False;
330 if(!prs_uint32("ptr_num_entries", ps, depth, &q_d->ptr_num_entries))
331 return False;
332 if(!prs_uint32("num_entries", ps, depth, &q_d->num_entries))
333 return False;
334 if(!prs_uint32("num_entries2", ps, depth, &q_d->num_entries2))
335 return False;
336 if(!smb_io_enum_hnd("resume_hnd",&q_d->reshnd, ps, depth))
337 return False;
338 return True;
341 /************************************************************
342 Read/write a DFS_INFO_CTR structure
343 ************************************************************/
345 BOOL dfs_io_dfs_info_ctr(char* desc, DFS_INFO_CTR* ctr, uint32 num_entries, uint32 level, prs_struct* ps, int depth)
347 int i=0;
349 switch(level) {
350 case 1:
351 depth++;
352 /* should depend on whether marshalling or unmarshalling! */
353 if(UNMARSHALLING(ps)) {
354 ctr->dfs.info1 = (DFS_INFO_1 *)prs_alloc_mem(ps, sizeof(DFS_INFO_1)*num_entries);
355 if (!ctr->dfs.info1)
356 return False;
359 for(i=0;i<num_entries;i++) {
360 if(!prs_uint32("ptr_entrypath",ps, depth, &ctr->dfs.info1[i].ptr_entrypath))
361 return False;
363 for(i=0;i<num_entries;i++) {
364 if(!smb_io_unistr2("", &ctr->dfs.info1[i].entrypath, ctr->dfs.info1[i].ptr_entrypath, ps, depth))
365 return False;
366 if(!prs_align(ps))
367 return False;
369 depth--;
370 break;
371 case 2:
372 depth++;
373 if(UNMARSHALLING(ps)) {
374 ctr->dfs.info2 = (DFS_INFO_2 *)prs_alloc_mem(ps, num_entries*sizeof(DFS_INFO_2));
375 if (!ctr->dfs.info2)
376 return False;
379 for(i=0;i<num_entries;i++) {
380 if(!prs_uint32("ptr_entrypath", ps, depth, &ctr->dfs.info2[i].ptr_entrypath))
381 return False;
382 if(!prs_uint32("ptr_comment", ps, depth, &ctr->dfs.info2[i].ptr_comment))
383 return False;
384 if(!prs_uint32("state", ps, depth, &ctr->dfs.info2[i].state))
385 return False;
386 if(!prs_uint32("num_storages", ps, depth, &ctr->dfs.info2[i].num_storages))
387 return False;
389 for(i=0;i<num_entries;i++) {
390 if(!smb_io_unistr2("", &ctr->dfs.info2[i].entrypath, ctr->dfs.info2[i].ptr_entrypath, ps, depth))
391 return False;
392 if(!prs_align(ps))
393 return False;
394 if(!smb_io_unistr2("",&ctr->dfs.info2[i].comment, ctr->dfs.info2[i].ptr_comment, ps, depth))
395 return False;
396 if(!prs_align(ps))
397 return False;
399 depth--;
400 break;
401 case 3:
402 depth++;
403 if(UNMARSHALLING(ps)) {
404 ctr->dfs.info3 = (DFS_INFO_3 *)prs_alloc_mem(ps, num_entries*sizeof(DFS_INFO_3));
405 if (!ctr->dfs.info3)
406 return False;
409 for(i=0;i<num_entries;i++) {
410 if(!prs_uint32("ptr_entrypath", ps, depth, &ctr->dfs.info3[i].ptr_entrypath))
411 return False;
412 if(!prs_uint32("ptr_comment", ps, depth, &ctr->dfs.info3[i].ptr_comment))
413 return False;
414 if(!prs_uint32("state", ps, depth, &ctr->dfs.info3[i].state))
415 return False;
416 if(!prs_uint32("num_storages", ps, depth, &ctr->dfs.info3[i].num_storages))
417 return False;
418 if(!prs_uint32("ptr_storages", ps, depth, &ctr->dfs.info3[i].ptr_storages))
419 return False;
421 for(i=0;i<num_entries;i++) {
422 if(!smb_io_unistr2("", &ctr->dfs.info3[i].entrypath, ctr->dfs.info3[i].ptr_entrypath, ps, depth))
423 return False;
424 if(!prs_align(ps))
425 return False;
426 if(!smb_io_unistr2("", &ctr->dfs.info3[i].comment, ctr->dfs.info3[i].ptr_comment, ps, depth))
427 return False;
428 if(!prs_align(ps))
429 return False;
430 if(!prs_uint32("num_storage_infos", ps, depth, &ctr->dfs.info3[i].num_storage_infos))
431 return False;
433 if(!dfs_io_dfs_storage_info("storage_info", &ctr->dfs.info3[i], ps, depth))
434 return False;
438 return True;
441 /************************************************************
442 Read/write a DFS_R_DFS_ENUM structure
443 ************************************************************/
445 BOOL dfs_io_r_dfs_enum(char *desc, DFS_R_DFS_ENUM *q_d, prs_struct *ps, int depth)
447 DFS_INFO_CTR *ctr;
448 if(q_d == NULL)
449 return False;
450 ctr = q_d->ctr;
451 if(ctr == NULL)
452 return False;
454 prs_debug(ps, depth, desc, "dfs_io_r_dfs_enum");
455 depth++;
457 if(!prs_align(ps))
458 return False;
460 if(!prs_uint32("ptr_buffer", ps, depth, &q_d->ptr_buffer))
461 return False;
462 if(!prs_uint32("level", ps, depth, &q_d->level))
463 return False;
464 if(!prs_uint32("level2", ps, depth, &ctr->switch_value))
465 return False;
466 if(!prs_uint32("ptr_num_entries", ps, depth, &q_d->ptr_num_entries))
467 return False;
468 if(q_d->ptr_num_entries)
469 if(!prs_uint32("num_entries", ps, depth, &q_d->num_entries))
470 return False;
471 if(!prs_uint32("ptr_num_entries2", ps, depth, &q_d->ptr_num_entries2))
472 return False;
473 if(q_d->ptr_num_entries2)
474 if(!prs_uint32("num_entries2", ps, depth, &ctr->num_entries))
475 return False;
477 if(!dfs_io_dfs_info_ctr("", ctr, q_d->num_entries, q_d->level, ps, depth))
478 return False;
480 if(!smb_io_enum_hnd("resume_hnd", &q_d->reshnd, ps, depth))
481 return False;
482 if(!prs_uint32("status", ps, depth, &q_d->status))
483 return False;
484 return True;
487 BOOL dfs_io_dfs_storage_info(char *desc, DFS_INFO_3* info3, prs_struct *ps, int depth)
489 int i=0;
490 if(info3 == NULL)
491 return False;
493 prs_debug(ps, depth, desc, "smb_io_dfs_storage_info");
494 depth++;
496 if(UNMARSHALLING(ps)) {
497 info3->storages = (DFS_STORAGE_INFO *)prs_alloc_mem(ps, info3->num_storage_infos*sizeof(DFS_STORAGE_INFO));
498 if (!info3->storages)
499 return False;
502 for(i=0;i<info3->num_storage_infos;i++) {
503 if(!prs_uint32("storage_state", ps, depth, &info3->storages[i].state))
504 return False;
505 if(!prs_uint32("ptr_servername", ps, depth, &info3->storages[i].ptr_servername))
506 return False;
507 if(!prs_uint32("ptr_sharename", ps, depth, &info3->storages[i].ptr_sharename))
508 return False;
511 for(i=0;i<info3->num_storage_infos;i++) {
512 if(!smb_io_unistr2("servername", &info3->storages[i].servername, info3->storages[i].ptr_servername, ps, depth))
513 return False;
514 if(!prs_align(ps))
515 return False;
516 if(!smb_io_unistr2("sharename", &info3->storages[i].sharename, info3->storages[i].ptr_sharename, ps, depth))
517 return False;
518 if(!prs_align(ps))
519 return False;
522 return True;