r10227: more ntsvcs code for the MMC service control plugin. Making some progress
[Samba.git] / source / rpc_parse / parse_dfs.c
blobf102e950042be73287d1299458561c45bf33d873
1 /*
2 * Unix SMB/CIFS implementation.
3 * MSDfs RPC Pipe client / server routines
4 * Copyright (C) Andrew Tridgell 1992-2000,
5 * Copyright (C) Luke Kenneth Casson Leighton 1996-2000,
6 * Copyright (C) Shirish Kalele 2000.
7 * Copyright (C) Jeremy Allison 2001.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "includes.h"
26 #undef DBGC_CLASS
27 #define DBGC_CLASS DBGC_RPC_PARSE
29 /*******************************************************************
30 Make a DFS_Q_DFS_QUERY structure
31 *******************************************************************/
33 void init_dfs_q_dfs_exist(DFS_Q_DFS_EXIST *q_d)
35 q_d->dummy = 0;
38 /*************************************************************
39 Read/write a DFS_Q_DFS_EXIST structure - dummy...
40 ************************************************************/
42 BOOL dfs_io_q_dfs_exist(const char *desc, DFS_Q_DFS_EXIST *q_d, prs_struct *ps, int depth)
44 if(q_d == NULL)
45 return False;
47 prs_debug(ps, depth, desc, "dfs_io_q_dfs_exist");
49 return True;
52 /*************************************************************
53 Read/write a DFS_R_DFS_EXIST structure
54 ************************************************************/
56 BOOL dfs_io_r_dfs_exist(const char *desc, DFS_R_DFS_EXIST *q_d, prs_struct *ps, int depth)
58 if(q_d == NULL)
59 return False;
61 prs_debug(ps, depth, desc, "dfs_io_r_dfs_exist");
62 depth++;
64 if(!prs_align(ps))
65 return False;
67 if(!prs_uint32("exist flag", ps, 0, &q_d->status))
68 return False;
70 return True;
73 /*******************************************************************
74 Make a DFS_Q_DFS_REMOVE structure
75 *******************************************************************/
77 BOOL init_dfs_q_dfs_remove(DFS_Q_DFS_REMOVE *q_d, const char *entrypath,
78 const char *servername, const char *sharename)
80 DEBUG(5,("init_dfs_q_dfs_remove\n"));
81 init_unistr2(&q_d->DfsEntryPath, entrypath, UNI_STR_TERMINATE);
82 init_unistr2(&q_d->ServerName, servername, UNI_STR_TERMINATE);
83 init_unistr2(&q_d->ShareName, sharename, UNI_STR_TERMINATE);
84 q_d->ptr_ServerName = q_d->ptr_ShareName = 1;
85 return True;
88 /*******************************************************************
89 Read/write a DFS_Q_DFS_REMOVE structure
90 *******************************************************************/
92 BOOL dfs_io_q_dfs_remove(const char *desc, DFS_Q_DFS_REMOVE *q_d, prs_struct *ps, int depth)
94 if(q_d == NULL)
95 return False;
97 prs_debug(ps, depth, desc, "dfs_io_q_dfs_remove");
98 depth++;
100 if(!prs_align(ps))
101 return False;
103 if(!smb_io_unistr2("DfsEntryPath",&q_d->DfsEntryPath, 1, ps, depth))
104 return False;
106 if(!prs_align(ps))
107 return False;
109 if(!prs_uint32("ptr_ServerName", ps, depth, &q_d->ptr_ServerName))
110 return False;
111 if(q_d->ptr_ServerName)
112 if (!smb_io_unistr2("ServerName",&q_d->ServerName, q_d->ptr_ServerName, ps, depth))
113 return False;
114 if(!prs_align(ps))
115 return False;
117 if(!prs_uint32("ptr_ShareName", ps, depth, &q_d->ptr_ShareName))
118 return False;
119 if(q_d->ptr_ShareName)
120 if (!smb_io_unistr2("ShareName",&q_d->ShareName, q_d->ptr_ShareName, ps, depth))
121 return False;
122 if(!prs_align(ps))
123 return False;
125 return True;
128 /*******************************************************************
129 Read/write a DFS_R_DFS_REMOVE structure
130 *******************************************************************/
132 BOOL dfs_io_r_dfs_remove(const char *desc, DFS_R_DFS_REMOVE *r_d, prs_struct *ps, int depth)
134 if(r_d == NULL)
135 return False;
137 prs_debug(ps, depth, desc, "dfs_io_r_dfs_remove");
138 depth++;
140 if(!prs_werror("status", ps, depth, &r_d->status))
141 return False;
143 return True;
146 /*******************************************************************
147 Make a DFS_Q_DFS_ADD structure
148 *******************************************************************/
150 BOOL init_dfs_q_dfs_add(DFS_Q_DFS_ADD *q_d, const char *entrypath,
151 const char *servername, const char *sharename,
152 const char *comment, uint32 flags)
154 DEBUG(5,("init_dfs_q_dfs_add\n"));
155 q_d->ptr_DfsEntryPath = q_d->ptr_ServerName = q_d->ptr_ShareName = 1;
156 init_unistr2(&q_d->DfsEntryPath, entrypath, UNI_STR_TERMINATE);
157 init_unistr2(&q_d->ServerName, servername, UNI_STR_TERMINATE);
158 init_unistr2(&q_d->ShareName, sharename, UNI_STR_TERMINATE);
159 if(comment != NULL) {
160 init_unistr2(&q_d->Comment, comment,UNI_STR_TERMINATE);
161 q_d->ptr_Comment = 1;
162 } else {
163 q_d->ptr_Comment = 0;
166 q_d->Flags = flags;
167 return True;
170 /************************************************************
171 Read/write a DFS_Q_DFS_ADD structure
172 ************************************************************/
174 BOOL dfs_io_q_dfs_add(const char *desc, DFS_Q_DFS_ADD *q_d, prs_struct *ps, int depth)
176 if(q_d == NULL)
177 return False;
179 prs_debug(ps, depth, desc, "dfs_io_q_dfs_add");
180 depth++;
182 if(!prs_align(ps))
183 return False;
185 if(!smb_io_unistr2("DfsEntryPath",&q_d->DfsEntryPath, 1, ps, depth))
186 return False;
187 if(!prs_align(ps))
188 return False;
190 if(!smb_io_unistr2("ServerName",&q_d->ServerName, 1, ps, depth))
191 return False;
192 if(!prs_align(ps))
193 return False;
195 if(!prs_uint32("ptr_ShareName", ps, depth, &q_d->ptr_ShareName))
196 return False;
197 if(!smb_io_unistr2("ShareName",&q_d->ShareName, 1, ps, depth))
198 return False;
199 if(!prs_align(ps))
200 return False;
202 if(!prs_uint32("ptr_Comment", ps, depth, &q_d->ptr_Comment))
203 return False;
204 if(!smb_io_unistr2("",&q_d->Comment, q_d->ptr_Comment , ps, depth))
205 return False;
206 if(!prs_align(ps))
207 return False;
209 if(!prs_uint32("Flags", ps, depth, &q_d->Flags))
210 return True;
212 return True;
215 /************************************************************
216 Read/write a DFS_R_DFS_ADD structure
217 ************************************************************/
219 BOOL dfs_io_r_dfs_add(const char *desc, DFS_R_DFS_ADD *r_d, prs_struct *ps, int depth)
221 if(r_d == NULL)
222 return False;
224 prs_debug(ps, depth, desc, "dfs_io_r_dfs_add");
225 depth++;
227 if(!prs_werror("status", ps, depth, &r_d->status))
228 return False;
230 return True;
233 BOOL init_dfs_q_dfs_get_info(DFS_Q_DFS_GET_INFO *q_d, const char *entrypath,
234 const char *servername, const char *sharename,
235 uint32 info_level)
237 DEBUG(5,("init_dfs_q2_get_info\n"));
238 init_unistr2(&q_d->uni_path, entrypath, UNI_STR_TERMINATE);
239 init_unistr2(&q_d->uni_server, servername, UNI_STR_TERMINATE);
240 init_unistr2(&q_d->uni_share, sharename, UNI_STR_TERMINATE);
241 q_d->level = info_level;
242 q_d->ptr_server = q_d->ptr_share = 1;
243 return True;
246 /************************************************************
247 Read/write a DFS_Q_GET_INFO structure
248 ************************************************************/
250 BOOL dfs_io_q_dfs_get_info(const char *desc, DFS_Q_DFS_GET_INFO* q_i, prs_struct* ps, int depth)
252 if(q_i == NULL)
253 return False;
255 prs_debug(ps, depth, desc, "dfs_io_q_dfs_get_info");
256 depth++;
258 if(!smb_io_unistr2("",&q_i->uni_path, 1, ps, depth))
259 return False;
261 if(!prs_align(ps))
262 return False;
264 if(!prs_uint32("ptr_server", ps, depth, &q_i->ptr_server))
265 return False;
267 if(q_i->ptr_server)
268 if (!smb_io_unistr2("",&q_i->uni_server, q_i->ptr_server, ps, depth))
269 return False;
270 if(!prs_align(ps))
271 return False;
273 if(!prs_uint32("ptr_share", ps, depth, &q_i->ptr_share))
274 return False;
275 if(q_i->ptr_share)
276 if(!smb_io_unistr2("", &q_i->uni_share, q_i->ptr_share, ps, depth))
277 return False;
278 if(!prs_align(ps))
279 return False;
281 if(!prs_uint32("level", ps, depth, &q_i->level))
282 return False;
283 return True;
286 /************************************************************
287 Read/write a DFS_R_GET_INFO structure
288 ************************************************************/
290 BOOL dfs_io_r_dfs_get_info(const char *desc, DFS_R_DFS_GET_INFO* r_i, prs_struct* ps, int depth)
292 if(r_i == NULL)
293 return False;
295 if(!prs_uint32("level", ps, depth, &r_i->level))
296 return False;
297 if(!prs_uint32("ptr_ctr", ps, depth, &r_i->ptr_ctr))
298 return False;
300 if(!dfs_io_dfs_info_ctr("", &r_i->ctr, 1, r_i->level, ps, depth))
301 return False;
302 if(!prs_werror("status", ps, depth, &r_i->status))
303 return False;
304 return True;
307 /************************************************************
308 Make a DFS_Q_DFS_ENUM structure
309 ************************************************************/
310 BOOL init_dfs_q_dfs_enum(DFS_Q_DFS_ENUM *q_d, uint32 level, DFS_INFO_CTR *ctr)
312 q_d->level = level;
313 q_d->maxpreflen = -1;
314 q_d->ptr_buffer = 1;
315 q_d->level2 = level;
317 q_d->ptr_num_entries = 1;
318 q_d->num_entries = 0;
319 q_d->num_entries2 = 0;
320 q_d->reshnd.ptr_hnd = 1;
321 q_d->reshnd.handle = 0;
322 return True;
325 /************************************************************
326 Read or write the DFS_Q_DFS_ENUM structure
327 ************************************************************/
329 BOOL dfs_io_q_dfs_enum(const char *desc, DFS_Q_DFS_ENUM *q_d, prs_struct *ps, int depth)
331 if(q_d == NULL)
332 return False;
334 prs_debug(ps, depth, desc, "dfs_io_q_dfs_enum");
335 depth++;
337 if(!prs_align(ps))
338 return False;
340 if(!prs_uint32("level", ps, depth, &q_d->level))
341 return False;
342 if(!prs_uint32("maxpreflen", ps, depth, &q_d->maxpreflen))
343 return False;
344 if(!prs_uint32("ptr_buffer", ps, depth, &q_d->ptr_buffer))
345 return False;
346 if(!prs_uint32("level2", ps, depth, &q_d->level2))
347 return False;
348 if(!prs_uint32("level3", ps, depth, &q_d->level2))
349 return False;
351 if(!prs_uint32("ptr_num_entries", ps, depth, &q_d->ptr_num_entries))
352 return False;
353 if(!prs_uint32("num_entries", ps, depth, &q_d->num_entries))
354 return False;
355 if(!prs_uint32("num_entries2", ps, depth, &q_d->num_entries2))
356 return False;
357 if(!smb_io_enum_hnd("resume_hnd",&q_d->reshnd, ps, depth))
358 return False;
359 return True;
362 /************************************************************
363 Read/write a DFS_INFO_CTR structure
364 ************************************************************/
366 BOOL dfs_io_dfs_info_ctr(const char *desc, DFS_INFO_CTR* ctr, uint32 num_entries, uint32 level, prs_struct* ps, int depth)
368 int i=0;
370 switch(level) {
371 case 1:
372 depth++;
373 /* should depend on whether marshalling or unmarshalling! */
374 if(UNMARSHALLING(ps)) {
375 ctr->dfs.info1 = PRS_ALLOC_MEM(ps, DFS_INFO_1, num_entries);
376 if (!ctr->dfs.info1)
377 return False;
380 for(i=0;i<num_entries;i++) {
381 if(!prs_uint32("ptr_entrypath",ps, depth, &ctr->dfs.info1[i].ptr_entrypath))
382 return False;
384 for(i=0;i<num_entries;i++) {
385 if(!smb_io_unistr2("", &ctr->dfs.info1[i].entrypath, ctr->dfs.info1[i].ptr_entrypath, ps, depth))
386 return False;
387 if(!prs_align(ps))
388 return False;
390 depth--;
391 break;
392 case 2:
393 depth++;
394 if(UNMARSHALLING(ps)) {
395 ctr->dfs.info2 = PRS_ALLOC_MEM(ps, DFS_INFO_2, num_entries);
396 if (!ctr->dfs.info2)
397 return False;
400 for(i=0;i<num_entries;i++) {
401 if(!prs_uint32("ptr_entrypath", ps, depth, &ctr->dfs.info2[i].ptr_entrypath))
402 return False;
403 if(!prs_uint32("ptr_comment", ps, depth, &ctr->dfs.info2[i].ptr_comment))
404 return False;
405 if(!prs_uint32("state", ps, depth, &ctr->dfs.info2[i].state))
406 return False;
407 if(!prs_uint32("num_storages", ps, depth, &ctr->dfs.info2[i].num_storages))
408 return False;
410 for(i=0;i<num_entries;i++) {
411 if(!smb_io_unistr2("", &ctr->dfs.info2[i].entrypath, ctr->dfs.info2[i].ptr_entrypath, ps, depth))
412 return False;
413 if(!prs_align(ps))
414 return False;
415 if(!smb_io_unistr2("",&ctr->dfs.info2[i].comment, ctr->dfs.info2[i].ptr_comment, ps, depth))
416 return False;
417 if(!prs_align(ps))
418 return False;
420 depth--;
421 break;
422 case 3:
423 depth++;
424 if(UNMARSHALLING(ps)) {
425 ctr->dfs.info3 = PRS_ALLOC_MEM(ps, DFS_INFO_3, num_entries);
426 if (!ctr->dfs.info3)
427 return False;
430 for(i=0;i<num_entries;i++) {
431 if(!prs_uint32("ptr_entrypath", ps, depth, &ctr->dfs.info3[i].ptr_entrypath))
432 return False;
433 if(!prs_uint32("ptr_comment", ps, depth, &ctr->dfs.info3[i].ptr_comment))
434 return False;
435 if(!prs_uint32("state", ps, depth, &ctr->dfs.info3[i].state))
436 return False;
437 if(!prs_uint32("num_storages", ps, depth, &ctr->dfs.info3[i].num_storages))
438 return False;
439 if(!prs_uint32("ptr_storages", ps, depth, &ctr->dfs.info3[i].ptr_storages))
440 return False;
442 for(i=0;i<num_entries;i++) {
443 if(!smb_io_unistr2("", &ctr->dfs.info3[i].entrypath, ctr->dfs.info3[i].ptr_entrypath, ps, depth))
444 return False;
445 if(!prs_align(ps))
446 return False;
447 if(!smb_io_unistr2("", &ctr->dfs.info3[i].comment, ctr->dfs.info3[i].ptr_comment, ps, depth))
448 return False;
449 if(!prs_align(ps))
450 return False;
451 if(!prs_uint32("num_storage_infos", ps, depth, &ctr->dfs.info3[i].num_storage_infos))
452 return False;
454 if(!dfs_io_dfs_storage_info("storage_info", &ctr->dfs.info3[i], ps, depth))
455 return False;
459 return True;
462 /************************************************************
463 Read/write a DFS_R_DFS_ENUM structure
464 ************************************************************/
466 BOOL dfs_io_r_dfs_enum(const char *desc, DFS_R_DFS_ENUM *q_d, prs_struct *ps, int depth)
468 DFS_INFO_CTR *ctr;
469 if(q_d == NULL)
470 return False;
471 ctr = q_d->ctr;
472 if(ctr == NULL)
473 return False;
475 prs_debug(ps, depth, desc, "dfs_io_r_dfs_enum");
476 depth++;
478 if(!prs_align(ps))
479 return False;
481 if(!prs_uint32("ptr_buffer", ps, depth, &q_d->ptr_buffer))
482 return False;
483 if(!prs_uint32("level", ps, depth, &q_d->level))
484 return False;
485 if(!prs_uint32("level2", ps, depth, &ctr->switch_value))
486 return False;
487 if(!prs_uint32("ptr_num_entries", ps, depth, &q_d->ptr_num_entries))
488 return False;
489 if(q_d->ptr_num_entries)
490 if(!prs_uint32("num_entries", ps, depth, &q_d->num_entries))
491 return False;
492 if(!prs_uint32("ptr_num_entries2", ps, depth, &q_d->ptr_num_entries2))
493 return False;
494 if(q_d->ptr_num_entries2)
495 if(!prs_uint32("num_entries2", ps, depth, &ctr->num_entries))
496 return False;
498 if(!dfs_io_dfs_info_ctr("", ctr, q_d->num_entries, q_d->level, ps, depth))
499 return False;
501 if(!smb_io_enum_hnd("resume_hnd", &q_d->reshnd, ps, depth))
502 return False;
503 if(!prs_werror("status", ps, depth, &q_d->status))
504 return False;
505 return True;
508 BOOL dfs_io_dfs_storage_info(const char *desc, DFS_INFO_3* info3, prs_struct *ps, int depth)
510 int i=0;
511 if(info3 == NULL)
512 return False;
514 prs_debug(ps, depth, desc, "smb_io_dfs_storage_info");
515 depth++;
517 if(UNMARSHALLING(ps)) {
518 info3->storages = PRS_ALLOC_MEM(ps, DFS_STORAGE_INFO, info3->num_storage_infos);
519 if (!info3->storages)
520 return False;
523 for(i=0;i<info3->num_storage_infos;i++) {
524 if(!prs_uint32("storage_state", ps, depth, &info3->storages[i].state))
525 return False;
526 if(!prs_uint32("ptr_servername", ps, depth, &info3->storages[i].ptr_servername))
527 return False;
528 if(!prs_uint32("ptr_sharename", ps, depth, &info3->storages[i].ptr_sharename))
529 return False;
532 for(i=0;i<info3->num_storage_infos;i++) {
533 if(!smb_io_unistr2("servername", &info3->storages[i].servername, info3->storages[i].ptr_servername, ps, depth))
534 return False;
535 if(!prs_align(ps))
536 return False;
537 if(!smb_io_unistr2("sharename", &info3->storages[i].sharename, info3->storages[i].ptr_sharename, ps, depth))
538 return False;
539 if(!prs_align(ps))
540 return False;
543 return True;