Removed version number from file header.
[samba.git] / source3 / rpc_parse / parse_srv.c
1 /* 
2  *  Unix SMB/CIFS implementation.
3  *  RPC Pipe client / server routines
4  *  Copyright (C) Andrew Tridgell              1992-1997,
5  *  Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
6  *  Copyright (C) Paul Ashton                       1997.
7  *  Copyright (C) Jeremy Allison                    1999.
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.
13  *  
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.
18  *  
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.
22  */
23
24 #include "includes.h"
25
26 /*******************************************************************
27  Inits a SH_INFO_1_STR structure
28 ********************************************************************/
29
30 void init_srv_share_info1_str(SH_INFO_1_STR *sh1, char *net_name, char *remark)
31 {
32         DEBUG(5,("init_srv_share_info1_str\n"));
33
34         init_unistr2(&sh1->uni_netname, net_name, strlen(net_name)+1);
35         init_unistr2(&sh1->uni_remark, remark, strlen(remark)+1);
36 }
37
38 /*******************************************************************
39  Reads or writes a structure.
40 ********************************************************************/
41
42 static BOOL srv_io_share_info1_str(char *desc, SH_INFO_1_STR *sh1, prs_struct *ps, int depth)
43 {
44         if (sh1 == NULL)
45                 return False;
46
47         prs_debug(ps, depth, desc, "srv_io_share_info1_str");
48         depth++;
49
50         if(!prs_align(ps))
51                 return False;
52         if(!smb_io_unistr2("", &sh1->uni_netname, True, ps, depth))
53                 return False;
54
55         if(!prs_align(ps))
56                 return False;
57         if(!smb_io_unistr2("", &sh1->uni_remark, True, ps, depth))
58                 return False;
59
60         return True;
61 }
62
63 /*******************************************************************
64  makes a SH_INFO_1 structure
65 ********************************************************************/
66
67 void init_srv_share_info1(SH_INFO_1 *sh1, char *net_name, uint32 type, char *remark)
68 {
69         DEBUG(5,("init_srv_share_info1: %s %8x %s\n", net_name, type, remark));
70
71         sh1->ptr_netname = (net_name != NULL) ? 1 : 0;
72         sh1->type        = type;
73         sh1->ptr_remark  = (remark != NULL) ? 1 : 0;
74 }
75
76 /*******************************************************************
77  Reads or writes a structure.
78 ********************************************************************/
79
80 static BOOL srv_io_share_info1(char *desc, SH_INFO_1 *sh1, prs_struct *ps, int depth)
81 {
82         if (sh1 == NULL)
83                 return False;
84
85         prs_debug(ps, depth, desc, "srv_io_share_info1");
86         depth++;
87
88         if(!prs_align(ps))
89                 return False;
90
91         if(!prs_uint32("ptr_netname", ps, depth, &sh1->ptr_netname))
92                 return False;
93         if(!prs_uint32("type       ", ps, depth, &sh1->type))
94                 return False;
95         if(!prs_uint32("ptr_remark ", ps, depth, &sh1->ptr_remark))
96                 return False;
97
98         return True;
99 }
100
101 /*******************************************************************
102  Inits a SH_INFO_2_STR structure
103 ********************************************************************/
104
105 void init_srv_share_info2_str(SH_INFO_2_STR *sh2,
106                                 char *net_name, char *remark,
107                                 char *path, char *passwd)
108 {
109         DEBUG(5,("init_srv_share_info2_str\n"));
110
111         init_unistr2(&sh2->uni_netname, net_name, strlen(net_name)+1);
112         init_unistr2(&sh2->uni_remark, remark, strlen(remark)+1);
113         init_unistr2(&sh2->uni_path, path, strlen(path)+1);
114         init_unistr2(&sh2->uni_passwd, passwd, strlen(passwd)+1);
115 }
116
117 /*******************************************************************
118  Reads or writes a structure.
119 ********************************************************************/
120
121 static BOOL srv_io_share_info2_str(char *desc, SH_INFO_2_STR *sh2, prs_struct *ps, int depth)
122 {
123         if (sh2 == NULL)
124                 return False;
125
126         prs_debug(ps, depth, desc, "srv_io_share_info2_str");
127         depth++;
128
129         if(!prs_align(ps))
130                 return False;
131         if(!smb_io_unistr2("", &sh2->uni_netname, True, ps, depth))
132                 return False;
133
134         if(!prs_align(ps))
135                 return False;
136         if(!smb_io_unistr2("", &sh2->uni_remark, True, ps, depth))
137                 return False;
138
139         if(!prs_align(ps))
140                 return False;
141         if(!smb_io_unistr2("", &sh2->uni_path, True, ps, depth))
142                 return False;
143
144         if(!prs_align(ps))
145                 return False;
146         if(!smb_io_unistr2("", &sh2->uni_passwd, True, ps, depth))
147                 return False;
148
149         return True;
150 }
151
152 /*******************************************************************
153  Inits a SH_INFO_2 structure
154 ********************************************************************/
155
156 void init_srv_share_info2(SH_INFO_2 *sh2,
157                                 char *net_name, uint32 type, char *remark,
158                                 uint32 perms, uint32 max_uses, uint32 num_uses,
159                                 char *path, char *passwd)
160 {
161         DEBUG(5,("init_srv_share_info2: %s %8x %s\n", net_name, type, remark));
162
163         sh2->ptr_netname = (net_name != NULL) ? 1 : 0;
164         sh2->type        = type;
165         sh2->ptr_remark  = (remark != NULL) ? 1 : 0;
166         sh2->perms       = perms;
167         sh2->max_uses    = max_uses;
168         sh2->num_uses    = num_uses;
169         sh2->type        = type;
170         sh2->ptr_path    = (path != NULL) ? 1 : 0;
171         sh2->ptr_passwd  = (passwd != NULL) ? 1 : 0;
172 }
173
174 /*******************************************************************
175  Reads or writes a structure.
176 ********************************************************************/
177
178 static BOOL srv_io_share_info2(char *desc, SH_INFO_2 *sh2, prs_struct *ps, int depth)
179 {
180         if (sh2 == NULL)
181                 return False;
182
183         prs_debug(ps, depth, desc, "srv_io_share_info2");
184         depth++;
185
186         if(!prs_align(ps))
187                 return False;
188
189         if(!prs_uint32("ptr_netname", ps, depth, &sh2->ptr_netname))
190                 return False;
191         if(!prs_uint32("type       ", ps, depth, &sh2->type))
192                 return False;
193         if(!prs_uint32("ptr_remark ", ps, depth, &sh2->ptr_remark))
194                 return False;
195         if(!prs_uint32("perms      ", ps, depth, &sh2->perms))
196                 return False;
197         if(!prs_uint32("max_uses   ", ps, depth, &sh2->max_uses))
198                 return False;
199         if(!prs_uint32("num_uses   ", ps, depth, &sh2->num_uses))
200                 return False;
201         if(!prs_uint32("ptr_path   ", ps, depth, &sh2->ptr_path))
202                 return False;
203         if(!prs_uint32("ptr_passwd ", ps, depth, &sh2->ptr_passwd))
204                 return False;
205
206         return True;
207 }
208
209 /*******************************************************************
210  Inits a SH_INFO_502 structure
211 ********************************************************************/
212
213 void init_srv_share_info502(SH_INFO_502 *sh502,
214                                 char *net_name, uint32 type, char *remark,
215                                 uint32 perms, uint32 max_uses, uint32 num_uses,
216                                 char *path, char *passwd, SEC_DESC *psd, size_t sd_size)
217 {
218         DEBUG(5,("init_srv_share_info502: %s %8x %s\n", net_name, type, remark));
219
220         ZERO_STRUCTP(sh502);
221
222         sh502->ptr_netname = (net_name != NULL) ? 1 : 0;
223         sh502->type        = type;
224         sh502->ptr_remark  = (remark != NULL) ? 1 : 0;
225         sh502->perms       = perms;
226         sh502->max_uses    = max_uses;
227         sh502->num_uses    = num_uses;
228         sh502->type        = type;
229         sh502->ptr_path    = (path != NULL) ? 1 : 0;
230         sh502->ptr_passwd  = (passwd != NULL) ? 1 : 0;
231         sh502->sd_size     = (uint32)sd_size;
232         sh502->ptr_sd      = (psd != NULL) ? 1 : 0;
233 }
234
235 /*******************************************************************
236  Reads or writes a structure.
237 ********************************************************************/
238
239 static BOOL srv_io_share_info502(char *desc, SH_INFO_502 *sh502, prs_struct *ps, int depth)
240 {
241         if (sh502 == NULL)
242                 return False;
243
244         prs_debug(ps, depth, desc, "srv_io_share_info502");
245         depth++;
246
247         if(!prs_align(ps))
248                 return False;
249
250         if(!prs_uint32("ptr_netname", ps, depth, &sh502->ptr_netname))
251                 return False;
252         if(!prs_uint32("type       ", ps, depth, &sh502->type))
253                 return False;
254         if(!prs_uint32("ptr_remark ", ps, depth, &sh502->ptr_remark))
255                 return False;
256         if(!prs_uint32("perms      ", ps, depth, &sh502->perms))
257                 return False;
258         if(!prs_uint32("max_uses   ", ps, depth, &sh502->max_uses))
259                 return False;
260         if(!prs_uint32("num_uses   ", ps, depth, &sh502->num_uses))
261                 return False;
262         if(!prs_uint32("ptr_path   ", ps, depth, &sh502->ptr_path))
263                 return False;
264         if(!prs_uint32("ptr_passwd ", ps, depth, &sh502->ptr_passwd))
265                 return False;
266         if(!prs_uint32("sd_size    ", ps, depth, &sh502->sd_size))
267                 return False;
268         if(!prs_uint32("ptr_sd     ", ps, depth, &sh502->ptr_sd))
269                 return False;
270
271         return True;
272 }
273
274 /*******************************************************************
275  Inits a SH_INFO_502_STR structure
276 ********************************************************************/
277
278 void init_srv_share_info502_str(SH_INFO_502_STR *sh502str,
279                                 SH_INFO_502 *ptrs,
280                                 char *net_name, char *remark,
281                                 char *path, char *passwd, SEC_DESC *psd, size_t sd_size)
282 {
283         DEBUG(5,("init_srv_share_info502_str\n"));
284
285         sh502str->ptrs = ptrs;
286
287         if(sh502str->ptrs->ptr_netname)
288                 init_unistr2(&sh502str->uni_netname, net_name, strlen(net_name)+1);
289         if(sh502str->ptrs->ptr_remark)
290                 init_unistr2(&sh502str->uni_remark, remark, strlen(remark)+1);
291         if(sh502str->ptrs->ptr_path)
292                 init_unistr2(&sh502str->uni_path, path, strlen(path)+1);
293         if(sh502str->ptrs->ptr_passwd)
294                 init_unistr2(&sh502str->uni_passwd, passwd, strlen(passwd)+1);
295         if(sh502str->ptrs->ptr_sd) {
296                 sh502str->sd = psd;
297                 sh502str->sd_size = sd_size;
298         }
299 }
300
301 /*******************************************************************
302  Reads or writes a structure.
303 ********************************************************************/
304
305 static BOOL srv_io_share_info502_str(char *desc, SH_INFO_502_STR *sh502, prs_struct *ps, int depth)
306 {
307         if (sh502 == NULL)
308                 return False;
309
310         prs_debug(ps, depth, desc, "srv_io_share_info502_str");
311         depth++;
312
313         if(!prs_align(ps))
314                 return False;
315
316         if(sh502->ptrs->ptr_netname) {
317                 if(!smb_io_unistr2("", &sh502->uni_netname, True, ps, depth))
318                         return False;
319         }
320
321         if(!prs_align(ps))
322                 return False;
323
324         if(sh502->ptrs->ptr_remark) {
325                 if(!smb_io_unistr2("", &sh502->uni_remark, True, ps, depth))
326                         return False;
327         }
328
329         if(!prs_align(ps))
330                 return False;
331
332         if(sh502->ptrs->ptr_path) {
333                 if(!smb_io_unistr2("", &sh502->uni_path, True, ps, depth))
334                         return False;
335         }
336
337         if(!prs_align(ps))
338                 return False;
339
340         if(sh502->ptrs->ptr_passwd) {
341                 if(!smb_io_unistr2("", &sh502->uni_passwd, True, ps, depth))
342                         return False;
343         }
344
345         if(!prs_align(ps))
346                 return False;
347
348         if(sh502->ptrs->ptr_sd) {
349                 if(!prs_uint32("sd_size   ", ps, depth, &sh502->sd_size))
350                         return False;
351                 if (!sec_io_desc(desc, &sh502->sd, ps, depth))
352                         return False;
353         }
354
355         return True;
356 }
357
358 /*******************************************************************
359  Reads or writes a structure.
360 ********************************************************************/
361
362 static BOOL srv_io_share_info1005(char* desc, SRV_SHARE_INFO_1005* sh1005,
363                                   prs_struct* ps, int depth)
364 {
365         if(sh1005 == NULL)
366                 return False;
367
368         prs_debug(ps, depth, desc, "srv_io_share_info1005");
369                 depth++;
370
371         if(!prs_align(ps))
372                 return False;
373
374         if(!prs_uint32("dfs_root_flag", ps, depth, &sh1005->dfs_root_flag))
375                 return False;
376
377         return True;
378 }   
379
380 /*******************************************************************
381  Reads or writes a structure.
382 ********************************************************************/
383
384 static BOOL srv_io_share_info1501(char* desc, SRV_SHARE_INFO_1501* sh1501,
385                                   prs_struct* ps, int depth)
386 {
387         if(sh1501 == NULL)
388                 return False;
389
390         prs_debug(ps, depth, desc, "srv_io_share_info1501");
391         depth++;
392
393         if(!prs_align(ps))
394                 return False;
395
396         if (!sec_io_desc_buf(desc, &sh1501->sdb, ps, depth))
397                 return False;
398
399         return True;
400 }   
401
402 /*******************************************************************
403  Reads or writes a structure.
404 ********************************************************************/
405
406 static BOOL srv_io_srv_share_ctr(char *desc, SRV_SHARE_INFO_CTR *ctr, prs_struct *ps, int depth)
407 {
408         if (ctr == NULL)
409                 return False;
410
411         prs_debug(ps, depth, desc, "srv_io_srv_share_ctr");
412         depth++;
413
414         if (UNMARSHALLING(ps)) {
415                 memset(ctr, '\0', sizeof(SRV_SHARE_INFO_CTR));
416         }
417
418         if(!prs_align(ps))
419                 return False;
420
421         if(!prs_uint32("info_level", ps, depth, &ctr->info_level))
422                 return False;
423
424         if (ctr->info_level == 0)
425                 return True;
426
427         if(!prs_uint32("switch_value", ps, depth, &ctr->switch_value))
428                 return False;
429         if(!prs_uint32("ptr_share_info", ps, depth, &ctr->ptr_share_info))
430                 return False;
431
432         if (ctr->ptr_share_info == 0)
433                 return True;
434
435         if(!prs_uint32("num_entries", ps, depth, &ctr->num_entries))
436                 return False;
437         if(!prs_uint32("ptr_entries", ps, depth, &ctr->ptr_entries))
438                 return False;
439
440         if (ctr->ptr_entries == 0) {
441                 if (ctr->num_entries == 0)
442                         return True;
443                 else
444                         return False;
445         }
446
447         if(!prs_uint32("num_entries2", ps, depth, &ctr->num_entries2))
448                 return False;
449
450         if (ctr->num_entries2 != ctr->num_entries)
451                 return False;
452
453         switch (ctr->switch_value) {
454         case 1:
455         {
456                 SRV_SHARE_INFO_1 *info1 = ctr->share.info1;
457                 int num_entries = ctr->num_entries;
458                 int i;
459
460                 if (UNMARSHALLING(ps)) {
461                         if (!(info1 = (SRV_SHARE_INFO_1 *)prs_alloc_mem(ps, num_entries * sizeof(SRV_SHARE_INFO_1))))
462                                 return False;
463                         ctr->share.info1 = info1;
464                 }
465
466                 for (i = 0; i < num_entries; i++) {
467                         if(!srv_io_share_info1("", &info1[i].info_1, ps, depth))
468                                 return False;
469                 }
470
471                 for (i = 0; i < num_entries; i++) {
472                         if(!srv_io_share_info1_str("", &info1[i].info_1_str, ps, depth))
473                                 return False;
474                 }
475
476                 break;
477         }
478
479         case 2:
480         {
481                 SRV_SHARE_INFO_2 *info2 = ctr->share.info2;
482                 int num_entries = ctr->num_entries;
483                 int i;
484
485                 if (UNMARSHALLING(ps)) {
486                         if (!(info2 = (SRV_SHARE_INFO_2 *)prs_alloc_mem(ps,num_entries * sizeof(SRV_SHARE_INFO_2))))
487                                 return False;
488                         ctr->share.info2 = info2;
489                 }
490
491                 for (i = 0; i < num_entries; i++) {
492                         if(!srv_io_share_info2("", &info2[i].info_2, ps, depth))
493                                 return False;
494                 }
495
496                 for (i = 0; i < num_entries; i++) {
497                         if(!srv_io_share_info2_str("", &info2[i].info_2_str, ps, depth))
498                                 return False;
499                 }
500
501                 break;
502         }
503
504         case 502:
505         {
506                 SRV_SHARE_INFO_502 *info502 = ctr->share.info502;
507                 int num_entries = ctr->num_entries;
508                 int i;
509
510                 if (UNMARSHALLING(ps)) {
511                         if (!(info502 = (SRV_SHARE_INFO_502 *)prs_alloc_mem(ps,num_entries * sizeof(SRV_SHARE_INFO_502))))
512                                 return False;
513                         ctr->share.info502 = info502;
514                 }
515
516                 for (i = 0; i < num_entries; i++) {
517                         if(!srv_io_share_info502("", &info502[i].info_502, ps, depth))
518                                 return False;
519                 }
520
521                 for (i = 0; i < num_entries; i++) {
522                         info502[i].info_502_str.ptrs = &info502[i].info_502;
523                         if(!srv_io_share_info502_str("", &info502[i].info_502_str, ps, depth))
524                                 return False;
525                 }
526
527                 break;
528         }
529
530         default:
531                 DEBUG(5,("%s no share info at switch_value %d\n",
532                          tab_depth(depth), ctr->switch_value));
533                 break;
534         }
535
536         return True;
537 }
538
539 /*******************************************************************
540  Inits a SRV_Q_NET_SHARE_ENUM structure.
541 ********************************************************************/
542
543 void init_srv_q_net_share_enum(SRV_Q_NET_SHARE_ENUM *q_n, 
544                                 char *srv_name, uint32 info_level,
545                                 uint32 preferred_len, ENUM_HND *hnd)
546 {
547
548         DEBUG(5,("init_q_net_share_enum\n"));
549
550         init_buf_unistr2(&q_n->uni_srv_name, &q_n->ptr_srv_name, srv_name);
551
552         q_n->ctr.info_level = q_n->ctr.switch_value = info_level;
553         q_n->ctr.ptr_share_info = 0;
554         q_n->preferred_len = preferred_len;
555
556         memcpy(&q_n->enum_hnd, hnd, sizeof(*hnd));
557 }
558
559 /*******************************************************************
560  Reads or writes a structure.
561 ********************************************************************/
562
563 BOOL srv_io_q_net_share_enum(char *desc, SRV_Q_NET_SHARE_ENUM *q_n, prs_struct *ps, int depth)
564 {
565         if (q_n == NULL)
566                 return False;
567
568         prs_debug(ps, depth, desc, "srv_io_q_net_share_enum");
569         depth++;
570
571         if(!prs_align(ps))
572                 return False;
573
574         if(!prs_uint32("ptr_srv_name", ps, depth, &q_n->ptr_srv_name))
575                 return False;
576         if(!smb_io_unistr2("", &q_n->uni_srv_name, True, ps, depth))
577                 return False;
578
579         if(!srv_io_srv_share_ctr("share_ctr", &q_n->ctr, ps, depth))
580                 return False;
581
582         if(!prs_align(ps))
583                 return False;
584
585         if(!prs_uint32("preferred_len", ps, depth, &q_n->preferred_len))
586                 return False;
587
588         if(!smb_io_enum_hnd("enum_hnd", &q_n->enum_hnd, ps, depth))
589                 return False;
590
591         return True;
592 }
593
594 /*******************************************************************
595  Reads or writes a structure.
596 ********************************************************************/
597
598 BOOL srv_io_r_net_share_enum(char *desc, SRV_R_NET_SHARE_ENUM *r_n, prs_struct *ps, int depth)
599 {
600         if (r_n == NULL)
601                 return False;
602
603         prs_debug(ps, depth, desc, "srv_io_r_net_share_enum");
604         depth++;
605
606         if(!srv_io_srv_share_ctr("share_ctr", &r_n->ctr, ps, depth))
607                 return False;
608
609         if(!prs_align(ps))
610                 return False;
611
612         if(!prs_uint32("total_entries", ps, depth, &r_n->total_entries))
613                 return False;
614         if(!smb_io_enum_hnd("enum_hnd", &r_n->enum_hnd, ps, depth))
615                 return False;
616         if(!prs_ntstatus("status     ", ps, depth, &r_n->status))
617                 return False;
618
619         return True;
620 }
621
622 /*******************************************************************
623  Reads or writes a structure.
624 ********************************************************************/
625
626 BOOL srv_io_q_net_share_get_info(char *desc, SRV_Q_NET_SHARE_GET_INFO *q_n, prs_struct *ps, int depth)
627 {
628         if (q_n == NULL)
629                 return False;
630
631         prs_debug(ps, depth, desc, "srv_io_q_net_share_get_info");
632         depth++;
633
634         if(!prs_align(ps))
635                 return False;
636
637         if(!prs_uint32("ptr_srv_name", ps, depth, &q_n->ptr_srv_name))
638                 return False;
639         if(!smb_io_unistr2("", &q_n->uni_srv_name, True, ps, depth))
640                 return False;
641
642         if(!smb_io_unistr2("", &q_n->uni_share_name, True, ps, depth))
643                 return False;
644
645         if(!prs_align(ps))
646                 return False;
647
648         if(!prs_uint32("info_level", ps, depth, &q_n->info_level))
649                 return False;
650
651         return True;
652 }
653
654 /*******************************************************************
655  Reads or writes a structure.
656 ********************************************************************/
657
658 static BOOL srv_io_srv_share_info(char *desc, prs_struct *ps, int depth, SRV_SHARE_INFO *r_n)
659 {
660         if (r_n == NULL)
661                 return False;
662
663         prs_debug(ps, depth, desc, "srv_io_srv_share_info");
664         depth++;
665
666         if(!prs_align(ps))
667                 return False;
668
669         if(!prs_uint32("switch_value ", ps, depth, &r_n->switch_value ))
670                 return False;
671
672         if(!prs_uint32("ptr_share_ctr", ps, depth, &r_n->ptr_share_ctr))
673                 return False;
674
675         if (r_n->ptr_share_ctr != 0) {
676                 switch (r_n->switch_value) {
677                 case 1:
678                         if(!srv_io_share_info1("", &r_n->share.info1.info_1, ps, depth))
679                                 return False;
680
681                         if(!srv_io_share_info1_str("", &r_n->share.info1.info_1_str, ps, depth))
682                                 return False;
683
684                         break;
685                 case 2:
686                         if(!srv_io_share_info2("", &r_n->share.info2.info_2, ps, depth))
687                                 return False;
688
689                         if(!srv_io_share_info2_str("", &r_n->share.info2.info_2_str, ps, depth))
690                                 return False;
691
692                         break;
693                 case 502:
694                         if(!srv_io_share_info502("", &r_n->share.info502.info_502, ps, depth))
695                                 return False;
696
697                         /*allow access to pointers in the str part. */
698                         r_n->share.info502.info_502_str.ptrs = &r_n->share.info502.info_502;
699
700                         if(!srv_io_share_info502_str("", &r_n->share.info502.info_502_str, ps, depth))
701                                 return False;
702                         break;
703                 case 1005:
704                         if(!srv_io_share_info1005("", &r_n->share.info1005, ps, depth))
705                                 return False;           
706                         break;
707                 case 1501:
708                         if (!srv_io_share_info1501("", &r_n->share.info1501, ps, depth))
709                                 return False;
710                 default:
711                         DEBUG(5,("%s no share info at switch_value %d\n",
712                                  tab_depth(depth), r_n->switch_value));
713                         break;
714                 }
715         }
716
717         return True;
718 }
719
720 /*******************************************************************
721  Reads or writes a structure.
722 ********************************************************************/
723
724 BOOL srv_io_r_net_share_get_info(char *desc, SRV_R_NET_SHARE_GET_INFO *r_n, prs_struct *ps, int depth)
725 {
726         if (r_n == NULL)
727                 return False;
728
729         prs_debug(ps, depth, desc, "srv_io_r_net_share_get_info");
730         depth++;
731
732         if(!prs_align(ps))
733                 return False;
734
735         if(!srv_io_srv_share_info("info  ", ps, depth, &r_n->info))
736                 return False;
737
738         if(!prs_align(ps))
739                 return False;
740
741         if(!prs_ntstatus("status", ps, depth, &r_n->status))
742                 return False;
743
744         return True;
745 }
746
747 /*******************************************************************
748  Reads or writes a structure.
749 ********************************************************************/
750
751 BOOL srv_io_q_net_share_set_info(char *desc, SRV_Q_NET_SHARE_SET_INFO *q_n, prs_struct *ps, int depth)
752 {
753         if (q_n == NULL)
754                 return False;
755
756         prs_debug(ps, depth, desc, "srv_io_q_net_share_set_info");
757         depth++;
758
759         if(!prs_align(ps))
760                 return False;
761
762         if(!prs_uint32("ptr_srv_name", ps, depth, &q_n->ptr_srv_name))
763                 return False;
764         if(!smb_io_unistr2("", &q_n->uni_srv_name, True, ps, depth))
765                 return False;
766
767         if(!smb_io_unistr2("", &q_n->uni_share_name, True, ps, depth))
768                 return False;
769
770         if(!prs_align(ps))
771                 return False;
772
773         if(!prs_uint32("info_level", ps, depth, &q_n->info_level))
774                 return False;
775
776         if(!prs_align(ps))
777                 return False;
778
779         if(!srv_io_srv_share_info("info  ", ps, depth, &q_n->info))
780                 return False;
781
782         return True;
783 }
784
785 /*******************************************************************
786  Reads or writes a structure.
787 ********************************************************************/
788
789 BOOL srv_io_r_net_share_set_info(char *desc, SRV_R_NET_SHARE_SET_INFO *q_n, prs_struct *ps, int depth)
790 {
791         if (q_n == NULL)
792                 return False;
793
794         prs_debug(ps, depth, desc, "srv_io_r_net_share_set_info");
795         depth++;
796
797         if(!prs_align(ps))
798                 return False;
799
800         if(!prs_uint32("switch_value  ", ps, depth, &q_n->switch_value))
801                 return False;
802         if(!prs_ntstatus("status        ", ps, depth, &q_n->status))
803                 return False;
804
805         return True;
806 }       
807
808 /*******************************************************************
809  Reads or writes a structure.
810 ********************************************************************/
811
812 BOOL srv_io_q_net_share_add(char *desc, SRV_Q_NET_SHARE_ADD *q_n, prs_struct *ps, int depth)
813 {
814         if (q_n == NULL)
815                 return False;
816
817         prs_debug(ps, depth, desc, "srv_io_q_net_share_add");
818         depth++;
819
820         if(!prs_align(ps))
821                 return False;
822
823         if(!prs_uint32("ptr_srv_name", ps, depth, &q_n->ptr_srv_name))
824                 return False;
825         if(!smb_io_unistr2("", &q_n->uni_srv_name, True, ps, depth))
826                 return False;
827
828         if(!prs_align(ps))
829                 return False;
830
831         if(!prs_uint32("info_level", ps, depth, &q_n->info_level))
832                 return False;
833
834         if(!prs_align(ps))
835                 return False;
836
837         if(!srv_io_srv_share_info("info  ", ps, depth, &q_n->info))
838                 return False;
839
840         return True;
841 }
842
843 /*******************************************************************
844  Reads or writes a structure.
845 ********************************************************************/
846
847 BOOL srv_io_r_net_share_add(char *desc, SRV_R_NET_SHARE_ADD *q_n, prs_struct *ps, int depth)
848 {
849         if (q_n == NULL)
850                 return False;
851
852         prs_debug(ps, depth, desc, "srv_io_r_net_share_add");
853         depth++;
854
855         if(!prs_align(ps))
856                 return False;
857
858         if(!prs_uint32("switch_value  ", ps, depth, &q_n->switch_value))
859                 return False;
860         if(!prs_ntstatus("status        ", ps, depth, &q_n->status))
861                 return False;
862
863         return True;
864 }       
865
866 /*******************************************************************
867  Reads or writes a structure.
868 ********************************************************************/
869
870 BOOL srv_io_q_net_share_del(char *desc, SRV_Q_NET_SHARE_DEL *q_n, prs_struct *ps, int depth)
871 {
872         if (q_n == NULL)
873                 return False;
874
875         prs_debug(ps, depth, desc, "srv_io_q_net_share_del");
876         depth++;
877
878         if(!prs_align(ps))
879                 return False;
880
881         if(!prs_uint32("ptr_srv_name", ps, depth, &q_n->ptr_srv_name))
882                 return False;
883         if(!smb_io_unistr2("", &q_n->uni_srv_name, True, ps, depth))
884                 return False;
885
886         if(!smb_io_unistr2("", &q_n->uni_share_name, True, ps, depth))
887                 return False;
888
889         return True;
890 }
891
892 /*******************************************************************
893  Reads or writes a structure.
894 ********************************************************************/
895
896 BOOL srv_io_r_net_share_del(char *desc, SRV_R_NET_SHARE_DEL *q_n, prs_struct *ps, int depth)
897 {
898         if (q_n == NULL)
899                 return False;
900
901         prs_debug(ps, depth, desc, "srv_io_r_net_share_del");
902         depth++;
903
904         if(!prs_align(ps))
905                 return False;
906
907         if(!prs_ntstatus("status        ", ps, depth, &q_n->status))
908                 return False;
909
910         return True;
911 }       
912
913 /*******************************************************************
914  Inits a SESS_INFO_0_STR structure
915 ********************************************************************/
916
917 void init_srv_sess_info0_str(SESS_INFO_0_STR *ss0, char *name)
918 {
919         DEBUG(5,("init_srv_sess_info0_str\n"));
920
921         init_unistr2(&ss0->uni_name, name, strlen(name)+1);
922 }
923
924 /*******************************************************************
925  Reads or writes a structure.
926 ********************************************************************/
927
928 static BOOL srv_io_sess_info0_str(char *desc,  SESS_INFO_0_STR *ss0, prs_struct *ps, int depth)
929 {
930         if (ss0 == NULL)
931                 return False;
932
933         prs_debug(ps, depth, desc, "srv_io_sess_info0_str");
934         depth++;
935
936         if(!prs_align(ps))
937                 return False;
938
939         if(!smb_io_unistr2("", &ss0->uni_name, True, ps, depth))
940                 return False;
941
942         return True;
943 }
944
945 /*******************************************************************
946  Inits a SESS_INFO_0 structure
947 ********************************************************************/
948
949 void init_srv_sess_info0(SESS_INFO_0 *ss0, char *name)
950 {
951         DEBUG(5,("init_srv_sess_info0: %s\n", name));
952
953         ss0->ptr_name = (name != NULL) ? 1 : 0;
954 }
955
956 /*******************************************************************
957  Reads or writes a structure.
958 ********************************************************************/
959
960 static BOOL srv_io_sess_info0(char *desc, SESS_INFO_0 *ss0, prs_struct *ps, int depth)
961 {
962         if (ss0 == NULL)
963                 return False;
964
965         prs_debug(ps, depth, desc, "srv_io_sess_info0");
966         depth++;
967
968         if(!prs_align(ps))
969                 return False;
970
971         if(!prs_uint32("ptr_name", ps, depth, &ss0->ptr_name))
972                 return False;
973
974         return True;
975 }
976
977 /*******************************************************************
978  Reads or writes a structure.
979 ********************************************************************/
980
981 static BOOL srv_io_srv_sess_info_0(char *desc, SRV_SESS_INFO_0 *ss0, prs_struct *ps, int depth)
982 {
983         if (ss0 == NULL)
984                 return False;
985
986         prs_debug(ps, depth, desc, "srv_io_srv_sess_info_0");
987         depth++;
988
989         if(!prs_align(ps))
990                 return False;
991
992         if(!prs_uint32("num_entries_read", ps, depth, &ss0->num_entries_read))
993                 return False;
994         if(!prs_uint32("ptr_sess_info", ps, depth, &ss0->ptr_sess_info))
995                 return False;
996
997         if (ss0->ptr_sess_info != 0) {
998                 int i;
999                 int num_entries = ss0->num_entries_read;
1000
1001                 if (num_entries > MAX_SESS_ENTRIES) {
1002                         num_entries = MAX_SESS_ENTRIES; /* report this! */
1003                 }
1004
1005                 if(!prs_uint32("num_entries_read2", ps, depth, &ss0->num_entries_read2))
1006                         return False;
1007
1008                 SMB_ASSERT_ARRAY(ss0->info_0, num_entries);
1009
1010                 for (i = 0; i < num_entries; i++) {
1011                         if(!srv_io_sess_info0("", &ss0->info_0[i], ps, depth))
1012                                 return False;
1013                 }
1014
1015                 for (i = 0; i < num_entries; i++) {
1016                         if(!srv_io_sess_info0_str("", &ss0->info_0_str[i], ps, depth))
1017                                 return False;
1018                 }
1019
1020                 if(!prs_align(ps))
1021                         return False;
1022         }
1023
1024         return True;
1025 }
1026
1027 /*******************************************************************
1028  Inits a SESS_INFO_1_STR structure
1029 ********************************************************************/
1030
1031 void init_srv_sess_info1_str(SESS_INFO_1_STR *ss1, char *name, char *user)
1032 {
1033         DEBUG(5,("init_srv_sess_info1_str\n"));
1034
1035         init_unistr2(&ss1->uni_name, name, strlen(name)+1);
1036         init_unistr2(&ss1->uni_user, name, strlen(user)+1);
1037 }
1038
1039 /*******************************************************************
1040  Reads or writes a structure.
1041 ********************************************************************/
1042
1043 static BOOL srv_io_sess_info1_str(char *desc, SESS_INFO_1_STR *ss1, prs_struct *ps, int depth)
1044 {
1045         if (ss1 == NULL)
1046                 return False;
1047
1048         prs_debug(ps, depth, desc, "srv_io_sess_info1_str");
1049         depth++;
1050
1051         if(!prs_align(ps))
1052                 return False;
1053
1054         if(!smb_io_unistr2("", &ss1->uni_name, True, ps, depth))
1055                 return False;
1056         if(!smb_io_unistr2("", &(ss1->uni_user), True, ps, depth))
1057                 return False;
1058
1059         return True;
1060 }
1061
1062 /*******************************************************************
1063  Inits a SESS_INFO_1 structure
1064 ********************************************************************/
1065
1066 void init_srv_sess_info1(SESS_INFO_1 *ss1, 
1067                                 char *name, char *user,
1068                                 uint32 num_opens, uint32 open_time, uint32 idle_time,
1069                                 uint32 user_flags)
1070 {
1071         DEBUG(5,("init_srv_sess_info1: %s\n", name));
1072
1073         ss1->ptr_name = (name != NULL) ? 1 : 0;
1074         ss1->ptr_user = (user != NULL) ? 1 : 0;
1075
1076         ss1->num_opens  = num_opens;
1077         ss1->open_time  = open_time;
1078         ss1->idle_time  = idle_time;
1079         ss1->user_flags = user_flags;
1080 }
1081
1082 /*******************************************************************
1083 reads or writes a structure.
1084 ********************************************************************/
1085
1086 static BOOL srv_io_sess_info1(char *desc, SESS_INFO_1 *ss1, prs_struct *ps, int depth)
1087 {
1088         if (ss1 == NULL)
1089                 return False;
1090
1091         prs_debug(ps, depth, desc, "srv_io_sess_info1");
1092         depth++;
1093
1094         if(!prs_align(ps))
1095                 return False;
1096
1097         if(!prs_uint32("ptr_name  ", ps, depth, &ss1->ptr_name))
1098                 return False;
1099         if(!prs_uint32("ptr_user  ", ps, depth, &ss1->ptr_user))
1100                 return False;
1101
1102         if(!prs_uint32("num_opens ", ps, depth, &ss1->num_opens))
1103                 return False;
1104         if(!prs_uint32("open_time ", ps, depth, &ss1->open_time))
1105                 return False;
1106         if(!prs_uint32("idle_time ", ps, depth, &ss1->idle_time))
1107                 return False;
1108         if(!prs_uint32("user_flags", ps, depth, &ss1->user_flags))
1109                 return False;
1110
1111         return True;
1112 }
1113
1114 /*******************************************************************
1115  Reads or writes a structure.
1116 ********************************************************************/
1117
1118 static BOOL srv_io_srv_sess_info_1(char *desc, SRV_SESS_INFO_1 *ss1, prs_struct *ps, int depth)
1119 {
1120         if (ss1 == NULL)
1121                 return False;
1122
1123         prs_debug(ps, depth, desc, "srv_io_srv_sess_info_1");
1124         depth++;
1125
1126         if(!prs_align(ps))
1127                 return False;
1128
1129         if(!prs_uint32("num_entries_read", ps, depth, &ss1->num_entries_read))
1130                 return False;
1131         if(!prs_uint32("ptr_sess_info", ps, depth, &ss1->ptr_sess_info))
1132                 return False;
1133
1134         if (ss1->ptr_sess_info != 0) {
1135                 int i;
1136                 int num_entries = ss1->num_entries_read;
1137
1138                 if (num_entries > MAX_SESS_ENTRIES) {
1139                         num_entries = MAX_SESS_ENTRIES; /* report this! */
1140                 }
1141
1142                 if(!prs_uint32("num_entries_read2", ps, depth, &ss1->num_entries_read2))
1143                         return False;
1144
1145                 SMB_ASSERT_ARRAY(ss1->info_1, num_entries);
1146
1147                 for (i = 0; i < num_entries; i++) {
1148                         if(!srv_io_sess_info1("", &ss1->info_1[i], ps, depth))
1149                                 return False;
1150                 }
1151
1152                 for (i = 0; i < num_entries; i++) {
1153                         if(!srv_io_sess_info1_str("", &ss1->info_1_str[i], ps, depth))
1154                                 return False;
1155                 }
1156
1157                 if(!prs_align(ps))
1158                         return False;
1159         }
1160
1161         return True;
1162 }
1163
1164 /*******************************************************************
1165  Reads or writes a structure.
1166 ********************************************************************/
1167
1168 static BOOL srv_io_srv_sess_ctr(char *desc, SRV_SESS_INFO_CTR **pp_ctr, prs_struct *ps, int depth)
1169 {
1170         SRV_SESS_INFO_CTR *ctr = *pp_ctr;
1171
1172         prs_debug(ps, depth, desc, "srv_io_srv_sess_ctr");
1173         depth++;
1174
1175         if(UNMARSHALLING(ps)) {
1176                 ctr = *pp_ctr = (SRV_SESS_INFO_CTR *)prs_alloc_mem(ps, sizeof(SRV_SESS_INFO_CTR));
1177                 if (ctr == NULL)
1178                         return False;
1179         }
1180
1181         if (ctr == NULL)
1182                 return False;
1183
1184         if(!prs_align(ps))
1185                 return False;
1186
1187         if(!prs_uint32("switch_value", ps, depth, &ctr->switch_value))
1188                 return False;
1189         if(!prs_uint32("ptr_sess_ctr", ps, depth, &ctr->ptr_sess_ctr))
1190                 return False;
1191
1192         if (ctr->ptr_sess_ctr != 0) {
1193                 switch (ctr->switch_value) {
1194                 case 0:
1195                         if(!srv_io_srv_sess_info_0("", &ctr->sess.info0, ps, depth))
1196                                 return False;
1197                         break;
1198                 case 1:
1199                         if(!srv_io_srv_sess_info_1("", &ctr->sess.info1, ps, depth))
1200                                 return False;
1201                         break;
1202                 default:
1203                         DEBUG(5,("%s no session info at switch_value %d\n",
1204                                  tab_depth(depth), ctr->switch_value));
1205                         break;
1206                 }
1207         }
1208
1209         return True;
1210 }
1211
1212 /*******************************************************************
1213  Inits a SRV_Q_NET_SESS_ENUM structure.
1214 ********************************************************************/
1215
1216 void init_srv_q_net_sess_enum(SRV_Q_NET_SESS_ENUM *q_n, 
1217                                 char *srv_name, char *qual_name,
1218                                 uint32 sess_level, SRV_SESS_INFO_CTR *ctr,
1219                                 uint32 preferred_len,
1220                                 ENUM_HND *hnd)
1221 {
1222         q_n->ctr = ctr;
1223
1224         DEBUG(5,("init_q_net_sess_enum\n"));
1225
1226         init_buf_unistr2(&q_n->uni_srv_name, &q_n->ptr_srv_name, srv_name);
1227         init_buf_unistr2(&q_n->uni_qual_name, &q_n->ptr_qual_name, qual_name);
1228
1229         q_n->sess_level    = sess_level;
1230         q_n->preferred_len = preferred_len;
1231
1232         memcpy(&q_n->enum_hnd, hnd, sizeof(*hnd));
1233 }
1234
1235 /*******************************************************************
1236  Reads or writes a structure.
1237 ********************************************************************/
1238
1239 BOOL srv_io_q_net_sess_enum(char *desc, SRV_Q_NET_SESS_ENUM *q_n, prs_struct *ps, int depth)
1240 {
1241         if (q_n == NULL)
1242                 return False;
1243
1244         prs_debug(ps, depth, desc, "srv_io_q_net_sess_enum");
1245         depth++;
1246
1247         if(!prs_align(ps))
1248                 return False;
1249
1250         if(!prs_uint32("ptr_srv_name", ps, depth, &q_n->ptr_srv_name))
1251                 return False;
1252         if(!smb_io_unistr2("", &q_n->uni_srv_name, True, ps, depth))
1253                 return False;
1254
1255         if(!prs_align(ps))
1256                 return False;
1257
1258         if(!prs_uint32("ptr_qual_name", ps, depth, &q_n->ptr_qual_name))
1259                 return False;
1260         if(!smb_io_unistr2("", &q_n->uni_qual_name, q_n->ptr_qual_name, ps, depth))
1261                 return False;
1262
1263         if(!prs_align(ps))
1264                 return False;
1265
1266         if(!prs_uint32("sess_level", ps, depth, &q_n->sess_level))
1267                 return False;
1268         
1269         if (q_n->sess_level != -1) {
1270                 if(!srv_io_srv_sess_ctr("sess_ctr", &q_n->ctr, ps, depth))
1271                         return False;
1272         }
1273
1274         if(!prs_uint32("preferred_len", ps, depth, &q_n->preferred_len))
1275                 return False;
1276
1277         if(!smb_io_enum_hnd("enum_hnd", &q_n->enum_hnd, ps, depth))
1278                 return False;
1279
1280         return True;
1281 }
1282
1283 /*******************************************************************
1284  Reads or writes a structure.
1285 ********************************************************************/
1286
1287 BOOL srv_io_r_net_sess_enum(char *desc, SRV_R_NET_SESS_ENUM *r_n, prs_struct *ps, int depth)
1288 {
1289         if (r_n == NULL)
1290                 return False;
1291
1292         prs_debug(ps, depth, desc, "srv_io_r_net_sess_enum");
1293         depth++;
1294
1295         if(!prs_align(ps))
1296                 return False;
1297
1298         if(!prs_uint32("sess_level", ps, depth, &r_n->sess_level))
1299                 return False;
1300
1301         if (r_n->sess_level != -1) {
1302                 if(!srv_io_srv_sess_ctr("sess_ctr", &r_n->ctr, ps, depth))
1303                         return False;
1304         }
1305
1306         if(!prs_uint32("total_entries", ps, depth, &r_n->total_entries))
1307                 return False;
1308         if(!smb_io_enum_hnd("enum_hnd", &r_n->enum_hnd, ps, depth))
1309                 return False;
1310         if(!prs_ntstatus("status     ", ps, depth, &r_n->status))
1311                 return False;
1312
1313         return True;
1314 }
1315
1316 /*******************************************************************
1317  Inits a CONN_INFO_0 structure
1318 ********************************************************************/
1319
1320 void init_srv_conn_info0(CONN_INFO_0 *ss0, uint32 id)
1321 {
1322         DEBUG(5,("init_srv_conn_info0\n"));
1323
1324         ss0->id = id;
1325 }
1326
1327 /*******************************************************************
1328  Reads or writes a structure.
1329 ********************************************************************/
1330
1331 static BOOL srv_io_conn_info0(char *desc, CONN_INFO_0 *ss0, prs_struct *ps, int depth)
1332 {
1333         if (ss0 == NULL)
1334                 return False;
1335
1336         prs_debug(ps, depth, desc, "srv_io_conn_info0");
1337         depth++;
1338
1339         if(!prs_align(ps))
1340                 return False;
1341
1342         if(!prs_uint32("id", ps, depth, &ss0->id))
1343                 return False;
1344
1345         return True;
1346 }
1347
1348 /*******************************************************************
1349  Reads or writes a structure.
1350 ********************************************************************/
1351
1352 static BOOL srv_io_srv_conn_info_0(char *desc, SRV_CONN_INFO_0 *ss0, prs_struct *ps, int depth)
1353 {
1354         if (ss0 == NULL)
1355                 return False;
1356
1357         prs_debug(ps, depth, desc, "srv_io_srv_conn_info_0");
1358         depth++;
1359
1360         if(!prs_align(ps))
1361                 return False;
1362
1363         if(!prs_uint32("num_entries_read", ps, depth, &ss0->num_entries_read))
1364                 return False;
1365         if(!prs_uint32("ptr_conn_info", ps, depth, &ss0->ptr_conn_info))
1366                 return False;
1367
1368         if (ss0->ptr_conn_info != 0) {
1369                 int i;
1370                 int num_entries = ss0->num_entries_read;
1371
1372                 if (num_entries > MAX_CONN_ENTRIES) {
1373                         num_entries = MAX_CONN_ENTRIES; /* report this! */
1374                 }
1375
1376                 if(!prs_uint32("num_entries_read2", ps, depth, &ss0->num_entries_read2))
1377                         return False;
1378
1379                 for (i = 0; i < num_entries; i++) {
1380                         if(!srv_io_conn_info0("", &ss0->info_0[i], ps, depth))
1381                                 return False;
1382                 }
1383
1384                 if(!prs_align(ps))
1385                         return False;
1386         }
1387
1388         return True;
1389 }
1390
1391 /*******************************************************************
1392  Inits a CONN_INFO_1_STR structure
1393 ********************************************************************/
1394
1395 void init_srv_conn_info1_str(CONN_INFO_1_STR *ss1, char *usr_name, char *net_name)
1396 {
1397         DEBUG(5,("init_srv_conn_info1_str\n"));
1398
1399         init_unistr2(&ss1->uni_usr_name, usr_name, strlen(usr_name)+1);
1400         init_unistr2(&ss1->uni_net_name, net_name, strlen(net_name)+1);
1401 }
1402
1403 /*******************************************************************
1404  Reads or writes a structure.
1405 ********************************************************************/
1406
1407 static BOOL srv_io_conn_info1_str(char *desc, CONN_INFO_1_STR *ss1, prs_struct *ps, int depth)
1408 {
1409         if (ss1 == NULL)
1410                 return False;
1411
1412         prs_debug(ps, depth, desc, "srv_io_conn_info1_str");
1413         depth++;
1414
1415         if(!prs_align(ps))
1416                 return False;
1417
1418         if(!smb_io_unistr2("", &ss1->uni_usr_name, True, ps, depth))
1419                 return False;
1420         if(!smb_io_unistr2("", &ss1->uni_net_name, True, ps, depth))
1421                 return False;
1422
1423         return True;
1424 }
1425
1426 /*******************************************************************
1427  Inits a CONN_INFO_1 structure
1428 ********************************************************************/
1429
1430 void init_srv_conn_info1(CONN_INFO_1 *ss1, 
1431                                 uint32 id, uint32 type,
1432                                 uint32 num_opens, uint32 num_users, uint32 open_time,
1433                                 char *usr_name, char *net_name)
1434 {
1435         DEBUG(5,("init_srv_conn_info1: %s %s\n", usr_name, net_name));
1436
1437         ss1->id        = id       ;
1438         ss1->type      = type     ;
1439         ss1->num_opens = num_opens ;
1440         ss1->num_users = num_users;
1441         ss1->open_time = open_time;
1442
1443         ss1->ptr_usr_name = (usr_name != NULL) ? 1 : 0;
1444         ss1->ptr_net_name = (net_name != NULL) ? 1 : 0;
1445 }
1446
1447 /*******************************************************************
1448  Reads or writes a structure.
1449 ********************************************************************/
1450
1451 static BOOL srv_io_conn_info1(char *desc, CONN_INFO_1 *ss1, prs_struct *ps, int depth)
1452 {
1453         if (ss1 == NULL)
1454                 return False;
1455
1456         prs_debug(ps, depth, desc, "srv_io_conn_info1");
1457         depth++;
1458
1459         if(!prs_align(ps))
1460                 return False;
1461
1462         if(!prs_uint32("id          ", ps, depth, &ss1->id))
1463                 return False;
1464         if(!prs_uint32("type        ", ps, depth, &ss1->type))
1465                 return False;
1466         if(!prs_uint32("num_opens   ", ps, depth, &ss1->num_opens))
1467                 return False;
1468         if(!prs_uint32("num_users   ", ps, depth, &ss1->num_users))
1469                 return False;
1470         if(!prs_uint32("open_time   ", ps, depth, &ss1->open_time))
1471                 return False;
1472
1473         if(!prs_uint32("ptr_usr_name", ps, depth, &ss1->ptr_usr_name))
1474                 return False;
1475         if(!prs_uint32("ptr_net_name", ps, depth, &ss1->ptr_net_name))
1476                 return False;
1477
1478         return True;
1479 }
1480
1481 /*******************************************************************
1482  Reads or writes a structure.
1483 ********************************************************************/
1484
1485 static BOOL srv_io_srv_conn_info_1(char *desc, SRV_CONN_INFO_1 *ss1, prs_struct *ps, int depth)
1486 {
1487         if (ss1 == NULL)
1488                 return False;
1489
1490         prs_debug(ps, depth, desc, "srv_io_srv_conn_info_1");
1491         depth++;
1492
1493         if(!prs_align(ps))
1494                 return False;
1495
1496         if(!prs_uint32("num_entries_read", ps, depth, &ss1->num_entries_read))
1497                 return False;
1498         if(!prs_uint32("ptr_conn_info", ps, depth, &ss1->ptr_conn_info))
1499                 return False;
1500
1501         if (ss1->ptr_conn_info != 0) {
1502                 int i;
1503                 int num_entries = ss1->num_entries_read;
1504
1505                 if (num_entries > MAX_CONN_ENTRIES) {
1506                         num_entries = MAX_CONN_ENTRIES; /* report this! */
1507                 }
1508
1509                 if(!prs_uint32("num_entries_read2", ps, depth, &ss1->num_entries_read2))
1510                         return False;
1511
1512                 for (i = 0; i < num_entries; i++) {
1513                         if(!srv_io_conn_info1("", &ss1->info_1[i], ps, depth))
1514                                 return False;
1515                 }
1516
1517                 for (i = 0; i < num_entries; i++) {
1518                         if(!srv_io_conn_info1_str("", &ss1->info_1_str[i], ps, depth))
1519                                 return False;
1520                 }
1521
1522                 if(!prs_align(ps))
1523                         return False;
1524         }
1525
1526         return True;
1527 }
1528
1529 /*******************************************************************
1530  Reads or writes a structure.
1531 ********************************************************************/
1532
1533 static BOOL srv_io_srv_conn_ctr(char *desc, SRV_CONN_INFO_CTR **pp_ctr, prs_struct *ps, int depth)
1534 {
1535         SRV_CONN_INFO_CTR *ctr = *pp_ctr;
1536
1537         prs_debug(ps, depth, desc, "srv_io_srv_conn_ctr");
1538         depth++;
1539
1540         if (UNMARSHALLING(ps)) {
1541                 ctr = *pp_ctr = (SRV_CONN_INFO_CTR *)prs_alloc_mem(ps, sizeof(SRV_CONN_INFO_CTR));
1542                 if (ctr == NULL)
1543                         return False;
1544         }
1545                 
1546         if (ctr == NULL)
1547                 return False;
1548
1549         if(!prs_align(ps))
1550                 return False;
1551
1552         if(!prs_uint32("switch_value", ps, depth, &ctr->switch_value))
1553                 return False;
1554         if(!prs_uint32("ptr_conn_ctr", ps, depth, &ctr->ptr_conn_ctr))
1555                 return False;
1556
1557         if (ctr->ptr_conn_ctr != 0) {
1558                 switch (ctr->switch_value) {
1559                 case 0:
1560                         if(!srv_io_srv_conn_info_0("", &ctr->conn.info0, ps, depth))
1561                                 return False;
1562                         break;
1563                 case 1:
1564                         if(!srv_io_srv_conn_info_1("", &ctr->conn.info1, ps, depth))
1565                                 return False;
1566                         break;
1567                 default:
1568                         DEBUG(5,("%s no connection info at switch_value %d\n",
1569                                  tab_depth(depth), ctr->switch_value));
1570                         break;
1571                 }
1572         }
1573
1574         return True;
1575 }
1576
1577 /*******************************************************************
1578   Reads or writes a structure.
1579 ********************************************************************/
1580
1581 void init_srv_q_net_conn_enum(SRV_Q_NET_CONN_ENUM *q_n, 
1582                                 char *srv_name, char *qual_name,
1583                                 uint32 conn_level, SRV_CONN_INFO_CTR *ctr,
1584                                 uint32 preferred_len,
1585                                 ENUM_HND *hnd)
1586 {
1587         DEBUG(5,("init_q_net_conn_enum\n"));
1588
1589         q_n->ctr = ctr;
1590
1591         init_buf_unistr2(&q_n->uni_srv_name, &q_n->ptr_srv_name, srv_name );
1592         init_buf_unistr2(&q_n->uni_qual_name, &q_n->ptr_qual_name, qual_name);
1593
1594         q_n->conn_level    = conn_level;
1595         q_n->preferred_len = preferred_len;
1596
1597         memcpy(&q_n->enum_hnd, hnd, sizeof(*hnd));
1598 }
1599
1600 /*******************************************************************
1601  Reads or writes a structure.
1602 ********************************************************************/
1603
1604 BOOL srv_io_q_net_conn_enum(char *desc, SRV_Q_NET_CONN_ENUM *q_n, prs_struct *ps, int depth)
1605 {
1606         if (q_n == NULL)
1607                 return False;
1608
1609         prs_debug(ps, depth, desc, "srv_io_q_net_conn_enum");
1610         depth++;
1611
1612         if(!prs_align(ps))
1613                 return False;
1614
1615         if(!prs_uint32("ptr_srv_name ", ps, depth, &q_n->ptr_srv_name))
1616                 return False;
1617         if(!smb_io_unistr2("", &q_n->uni_srv_name, q_n->ptr_srv_name, ps, depth))
1618                 return False;
1619
1620         if(!prs_align(ps))
1621                 return False;
1622
1623         if(!prs_uint32("ptr_qual_name", ps, depth, &q_n->ptr_qual_name))
1624                 return False;
1625         if(!smb_io_unistr2("", &q_n->uni_qual_name, q_n->ptr_qual_name, ps, depth))
1626                 return False;
1627
1628         if(!prs_align(ps))
1629                 return False;
1630
1631         if(!prs_uint32("conn_level", ps, depth, &q_n->conn_level))
1632                 return False;
1633         
1634         if (q_n->conn_level != -1) {
1635                 if(!srv_io_srv_conn_ctr("conn_ctr", &q_n->ctr, ps, depth))
1636                         return False;
1637         }
1638
1639         if(!prs_uint32("preferred_len", ps, depth, &q_n->preferred_len))
1640                 return False;
1641
1642         if(!smb_io_enum_hnd("enum_hnd", &q_n->enum_hnd, ps, depth))
1643                 return False;
1644
1645         return True;
1646 }
1647
1648 /*******************************************************************
1649  Reads or writes a structure.
1650 ********************************************************************/
1651
1652 BOOL srv_io_r_net_conn_enum(char *desc,  SRV_R_NET_CONN_ENUM *r_n, prs_struct *ps, int depth)
1653 {
1654         if (r_n == NULL)
1655                 return False;
1656
1657         prs_debug(ps, depth, desc, "srv_io_r_net_conn_enum");
1658         depth++;
1659
1660         if(!prs_align(ps))
1661                 return False;
1662
1663         if(!prs_uint32("conn_level", ps, depth, &r_n->conn_level))
1664                 return False;
1665
1666         if (r_n->conn_level != -1) {
1667                 if(!srv_io_srv_conn_ctr("conn_ctr", &r_n->ctr, ps, depth))
1668                         return False;
1669         }
1670
1671         if(!prs_uint32("total_entries", ps, depth, &r_n->total_entries))
1672                 return False;
1673         if(!smb_io_enum_hnd("enum_hnd", &r_n->enum_hnd, ps, depth))
1674                 return False;
1675         if(!prs_ntstatus("status     ", ps, depth, &r_n->status))
1676                 return False;
1677
1678         return True;
1679 }
1680
1681 /*******************************************************************
1682  Inits a FILE_INFO_3_STR structure
1683 ********************************************************************/
1684
1685 void init_srv_file_info3_str(FILE_INFO_3_STR *fi3, char *user_name, char *path_name)
1686 {
1687         DEBUG(5,("init_srv_file_info3_str\n"));
1688
1689         init_unistr2(&fi3->uni_path_name, path_name, strlen(path_name)+1);
1690         init_unistr2(&fi3->uni_user_name, user_name, strlen(user_name)+1);
1691 }
1692
1693 /*******************************************************************
1694  Reads or writes a structure.
1695 ********************************************************************/
1696
1697 static BOOL srv_io_file_info3_str(char *desc, FILE_INFO_3_STR *sh1, prs_struct *ps, int depth)
1698 {
1699         if (sh1 == NULL)
1700                 return False;
1701
1702         prs_debug(ps, depth, desc, "srv_io_file_info3_str");
1703         depth++;
1704
1705         if(!prs_align(ps))
1706                 return False;
1707
1708         if(!smb_io_unistr2("", &sh1->uni_path_name, True, ps, depth))
1709                 return False;
1710         if(!smb_io_unistr2("", &sh1->uni_user_name, True, ps, depth))
1711                 return False;
1712
1713         return True;
1714 }
1715
1716 /*******************************************************************
1717  Inits a FILE_INFO_3 structure
1718 ********************************************************************/
1719
1720 void init_srv_file_info3(FILE_INFO_3 *fl3,
1721                                 uint32 id, uint32 perms, uint32 num_locks,
1722                                 char *path_name, char *user_name)
1723 {
1724         DEBUG(5,("init_srv_file_info3: %s %s\n", path_name, user_name));
1725
1726         fl3->id        = id;    
1727         fl3->perms     = perms;
1728         fl3->num_locks = num_locks;
1729
1730         fl3->ptr_path_name = (path_name != NULL) ? 1 : 0;
1731         fl3->ptr_user_name = (user_name != NULL) ? 1 : 0;
1732 }
1733
1734 /*******************************************************************
1735  Reads or writes a structure.
1736 ********************************************************************/
1737
1738 static BOOL srv_io_file_info3(char *desc, FILE_INFO_3 *fl3, prs_struct *ps, int depth)
1739 {
1740         if (fl3 == NULL)
1741                 return False;
1742
1743         prs_debug(ps, depth, desc, "srv_io_file_info3");
1744         depth++;
1745
1746         if(!prs_align(ps))
1747                 return False;
1748
1749         if(!prs_uint32("id           ", ps, depth, &fl3->id))
1750                 return False;
1751         if(!prs_uint32("perms        ", ps, depth, &fl3->perms))
1752                 return False;
1753         if(!prs_uint32("num_locks    ", ps, depth, &fl3->num_locks))
1754                 return False;
1755         if(!prs_uint32("ptr_path_name", ps, depth, &fl3->ptr_path_name))
1756                 return False;
1757         if(!prs_uint32("ptr_user_name", ps, depth, &fl3->ptr_user_name))
1758                 return False;
1759
1760         return True;
1761 }
1762
1763 /*******************************************************************
1764  Reads or writes a structure.
1765 ********************************************************************/
1766
1767 static BOOL srv_io_srv_file_info_3(char *desc, SRV_FILE_INFO_3 *fl3, prs_struct *ps, int depth)
1768 {
1769         if (fl3 == NULL)
1770                 return False;
1771
1772         prs_debug(ps, depth, desc, "srv_io_file_3_fl3");
1773         depth++;
1774
1775         if(!prs_align(ps))
1776                 return False;
1777
1778         if(!prs_uint32("num_entries_read", ps, depth, &fl3->num_entries_read))
1779                 return False;
1780         if(!prs_uint32("ptr_file_fl3", ps, depth, &fl3->ptr_file_info))
1781                 return False;
1782
1783         if (fl3->ptr_file_info != 0) {
1784                 int i;
1785                 int num_entries = fl3->num_entries_read;
1786
1787                 if (num_entries > MAX_FILE_ENTRIES) {
1788                         num_entries = MAX_FILE_ENTRIES; /* report this! */
1789                 }
1790
1791                 if(!prs_uint32("num_entries_read2", ps, depth, &fl3->num_entries_read2))
1792                         return False;
1793
1794                 for (i = 0; i < num_entries; i++) {
1795                         if(!srv_io_file_info3("", &fl3->info_3[i], ps, depth))
1796                                 return False;
1797                 }
1798
1799                 for (i = 0; i < num_entries; i++) {
1800                         if(!srv_io_file_info3_str("", &fl3->info_3_str[i], ps, depth))
1801                                 return False;
1802                 }
1803
1804                 if(!prs_align(ps))
1805                         return False;
1806         }
1807
1808         return True;
1809 }
1810
1811 /*******************************************************************
1812  Reads or writes a structure.
1813 ********************************************************************/
1814
1815 static BOOL srv_io_srv_file_ctr(char *desc, SRV_FILE_INFO_CTR **pp_ctr, prs_struct *ps, int depth)
1816 {
1817         SRV_FILE_INFO_CTR *ctr = *pp_ctr;
1818
1819         if (UNMARSHALLING(ps)) {
1820                 ctr = *pp_ctr = (SRV_FILE_INFO_CTR *)prs_alloc_mem(ps, sizeof(SRV_FILE_INFO_CTR));
1821                 if (ctr == NULL)
1822                         return False;
1823         }
1824
1825         if (ctr == NULL)
1826                 return False;
1827
1828         prs_debug(ps, depth, desc, "srv_io_srv_file_ctr");
1829         depth++;
1830
1831         if(!prs_align(ps))
1832                 return False;
1833
1834         if(!prs_uint32("switch_value", ps, depth, &ctr->switch_value))
1835                 return False;
1836         if(!prs_uint32("ptr_file_ctr", ps, depth, &ctr->ptr_file_ctr))
1837                 return False;
1838
1839         if (ctr->ptr_file_ctr != 0) {
1840                 switch (ctr->switch_value) {
1841                 case 3:
1842                         if(!srv_io_srv_file_info_3("", &ctr->file.info3, ps, depth))
1843                                 return False;
1844                         break;
1845                 default:
1846                         DEBUG(5,("%s no file info at switch_value %d\n",
1847                                  tab_depth(depth), ctr->switch_value));
1848                         break;
1849                 }
1850         }
1851
1852         return True;
1853 }
1854
1855 /*******************************************************************
1856  Inits a SRV_Q_NET_FILE_ENUM structure.
1857 ********************************************************************/
1858
1859 void init_srv_q_net_file_enum(SRV_Q_NET_FILE_ENUM *q_n, 
1860                                 char *srv_name, char *qual_name,
1861                                 uint32 file_level, SRV_FILE_INFO_CTR *ctr,
1862                                 uint32 preferred_len,
1863                                 ENUM_HND *hnd)
1864 {
1865         DEBUG(5,("init_q_net_file_enum\n"));
1866
1867         q_n->ctr = ctr;
1868
1869         init_buf_unistr2(&q_n->uni_srv_name, &q_n->ptr_srv_name, srv_name);
1870         init_buf_unistr2(&q_n->uni_qual_name, &q_n->ptr_qual_name, qual_name);
1871
1872         q_n->file_level    = file_level;
1873         q_n->preferred_len = preferred_len;
1874
1875         memcpy(&q_n->enum_hnd, hnd, sizeof(*hnd));
1876 }
1877
1878 /*******************************************************************
1879  Reads or writes a structure.
1880 ********************************************************************/
1881
1882 BOOL srv_io_q_net_file_enum(char *desc, SRV_Q_NET_FILE_ENUM *q_n, prs_struct *ps, int depth)
1883 {
1884         if (q_n == NULL)
1885                 return False;
1886
1887         prs_debug(ps, depth, desc, "srv_io_q_net_file_enum");
1888         depth++;
1889
1890         if(!prs_align(ps))
1891                 return False;
1892
1893         if(!prs_uint32("ptr_srv_name", ps, depth, &q_n->ptr_srv_name))
1894                 return False;
1895         if(!smb_io_unistr2("", &q_n->uni_srv_name, True, ps, depth))
1896                 return False;
1897
1898         if(!prs_align(ps))
1899                 return False;
1900
1901         if(!prs_uint32("ptr_qual_name", ps, depth, &q_n->ptr_qual_name))
1902                 return False;
1903         if(!smb_io_unistr2("", &q_n->uni_qual_name, q_n->ptr_qual_name, ps, depth))
1904                 return False;
1905
1906         if(!prs_align(ps))
1907                 return False;
1908
1909         if(!prs_uint32("file_level", ps, depth, &q_n->file_level))
1910                 return False;
1911
1912         if (q_n->file_level != -1) {
1913                 if(!srv_io_srv_file_ctr("file_ctr", &q_n->ctr, ps, depth))
1914                         return False;
1915         }
1916
1917         if(!prs_uint32("preferred_len", ps, depth, &q_n->preferred_len))
1918                 return False;
1919
1920         if(!smb_io_enum_hnd("enum_hnd", &q_n->enum_hnd, ps, depth))
1921                 return False;
1922
1923         return True;
1924 }
1925
1926 /*******************************************************************
1927  Reads or writes a structure.
1928 ********************************************************************/
1929
1930 BOOL srv_io_r_net_file_enum(char *desc, SRV_R_NET_FILE_ENUM *r_n, prs_struct *ps, int depth)
1931 {
1932         if (r_n == NULL)
1933                 return False;
1934
1935         prs_debug(ps, depth, desc, "srv_io_r_net_file_enum");
1936         depth++;
1937
1938         if(!prs_align(ps))
1939                 return False;
1940
1941         if(!prs_uint32("file_level", ps, depth, &r_n->file_level))
1942                 return False;
1943
1944         if (r_n->file_level != 0) {
1945                 if(!srv_io_srv_file_ctr("file_ctr", &r_n->ctr, ps, depth))
1946                         return False;
1947         }
1948
1949         if(!prs_uint32("total_entries", ps, depth, &r_n->total_entries))
1950                 return False;
1951         if(!smb_io_enum_hnd("enum_hnd", &r_n->enum_hnd, ps, depth))
1952                 return False;
1953         if(!prs_ntstatus("status     ", ps, depth, &r_n->status))
1954                 return False;
1955
1956         return True;
1957 }
1958
1959 /*******************************************************************
1960  Inits a SRV_INFO_100 structure.
1961  ********************************************************************/
1962
1963 void init_srv_info_100(SRV_INFO_100 *sv100, uint32 platform_id, char *name)
1964 {
1965         DEBUG(5,("init_srv_info_100\n"));
1966
1967         sv100->platform_id  = platform_id;
1968         init_buf_unistr2(&sv100->uni_name, &sv100->ptr_name, name);
1969 }
1970
1971 /*******************************************************************
1972  Reads or writes a SRV_INFO_101 structure.
1973  ********************************************************************/
1974
1975 static BOOL srv_io_info_100(char *desc, SRV_INFO_100 *sv100, prs_struct *ps, int depth)
1976 {
1977         if (sv100 == NULL)
1978                 return False;
1979
1980         prs_debug(ps, depth, desc, "srv_io_info_100");
1981         depth++;
1982
1983         if(!prs_align(ps))
1984                 return False;
1985
1986         if(!prs_uint32("platform_id ", ps, depth, &sv100->platform_id))
1987                 return False;
1988         if(!prs_uint32("ptr_name    ", ps, depth, &sv100->ptr_name))
1989                 return False;
1990
1991         if(!smb_io_unistr2("uni_name    ", &sv100->uni_name, True, ps, depth))
1992                 return False;
1993
1994         return True;
1995 }
1996
1997
1998 /*******************************************************************
1999  Inits a SRV_INFO_101 structure.
2000  ********************************************************************/
2001
2002 void init_srv_info_101(SRV_INFO_101 *sv101, uint32 platform_id, char *name,
2003                                 uint32 ver_major, uint32 ver_minor,
2004                                 uint32 srv_type, char *comment)
2005 {
2006         DEBUG(5,("init_srv_info_101\n"));
2007
2008         sv101->platform_id  = platform_id;
2009         init_buf_unistr2(&sv101->uni_name, &sv101->ptr_name, name);
2010         sv101->ver_major    = ver_major;
2011         sv101->ver_minor    = ver_minor;
2012         sv101->srv_type     = srv_type;
2013         init_buf_unistr2(&sv101->uni_comment, &sv101->ptr_comment, comment);
2014 }
2015
2016 /*******************************************************************
2017  Reads or writes a SRV_INFO_101 structure.
2018  ********************************************************************/
2019
2020 static BOOL srv_io_info_101(char *desc, SRV_INFO_101 *sv101, prs_struct *ps, int depth)
2021 {
2022         if (sv101 == NULL)
2023                 return False;
2024
2025         prs_debug(ps, depth, desc, "srv_io_info_101");
2026         depth++;
2027
2028         if(!prs_align(ps))
2029                 return False;
2030
2031         if(!prs_uint32("platform_id ", ps, depth, &sv101->platform_id))
2032                 return False;
2033         if(!prs_uint32("ptr_name    ", ps, depth, &sv101->ptr_name))
2034                 return False;
2035         if(!prs_uint32("ver_major   ", ps, depth, &sv101->ver_major))
2036                 return False;
2037         if(!prs_uint32("ver_minor   ", ps, depth, &sv101->ver_minor))
2038                 return False;
2039         if(!prs_uint32("srv_type    ", ps, depth, &sv101->srv_type))
2040                 return False;
2041         if(!prs_uint32("ptr_comment ", ps, depth, &sv101->ptr_comment))
2042                 return False;
2043
2044         if(!prs_align(ps))
2045                 return False;
2046
2047         if(!smb_io_unistr2("uni_name    ", &sv101->uni_name, True, ps, depth))
2048                 return False;
2049         if(!smb_io_unistr2("uni_comment ", &sv101->uni_comment, True, ps, depth))
2050                 return False;
2051
2052         return True;
2053 }
2054
2055 /*******************************************************************
2056  Inits a SRV_INFO_102 structure.
2057  ********************************************************************/
2058
2059 void init_srv_info_102(SRV_INFO_102 *sv102, uint32 platform_id, char *name,
2060                                 char *comment, uint32 ver_major, uint32 ver_minor,
2061                                 uint32 srv_type, uint32 users, uint32 disc, uint32 hidden,
2062                                 uint32 announce, uint32 ann_delta, uint32 licenses,
2063                                 char *usr_path)
2064 {
2065         DEBUG(5,("init_srv_info_102\n"));
2066
2067         sv102->platform_id  = platform_id;
2068         init_buf_unistr2(&sv102->uni_name, &sv102->ptr_name, name);
2069         sv102->ver_major    = ver_major;
2070         sv102->ver_minor    = ver_minor;
2071         sv102->srv_type     = srv_type;
2072         init_buf_unistr2(&sv102->uni_comment, &sv102->ptr_comment, comment);
2073
2074         /* same as 101 up to here */
2075
2076         sv102->users        = users;
2077         sv102->disc         = disc;
2078         sv102->hidden       = hidden;
2079         sv102->announce     = announce;
2080         sv102->ann_delta    =ann_delta;
2081         sv102->licenses     = licenses;
2082         init_buf_unistr2(&sv102->uni_usr_path, &sv102->ptr_usr_path, usr_path);
2083 }
2084
2085
2086 /*******************************************************************
2087  Reads or writes a SRV_INFO_102 structure.
2088  ********************************************************************/
2089
2090 static BOOL srv_io_info_102(char *desc, SRV_INFO_102 *sv102, prs_struct *ps, int depth)
2091 {
2092         if (sv102 == NULL)
2093                 return False;
2094
2095         prs_debug(ps, depth, desc, "srv_io_info102");
2096         depth++;
2097
2098         if(!prs_align(ps))
2099                 return False;
2100
2101         if(!prs_uint32("platform_id ", ps, depth, &sv102->platform_id))
2102                 return False;
2103         if(!prs_uint32("ptr_name    ", ps, depth, &sv102->ptr_name))
2104                 return False;
2105         if(!prs_uint32("ver_major   ", ps, depth, &sv102->ver_major))
2106                 return False;
2107         if(!prs_uint32("ver_minor   ", ps, depth, &sv102->ver_minor))
2108                 return False;
2109         if(!prs_uint32("srv_type    ", ps, depth, &sv102->srv_type))
2110                 return False;
2111         if(!prs_uint32("ptr_comment ", ps, depth, &sv102->ptr_comment))
2112                 return False;
2113
2114         /* same as 101 up to here */
2115
2116         if(!prs_uint32("users       ", ps, depth, &sv102->users))
2117                 return False;
2118         if(!prs_uint32("disc        ", ps, depth, &sv102->disc))
2119                 return False;
2120         if(!prs_uint32("hidden      ", ps, depth, &sv102->hidden))
2121                 return False;
2122         if(!prs_uint32("announce    ", ps, depth, &sv102->announce))
2123                 return False;
2124         if(!prs_uint32("ann_delta   ", ps, depth, &sv102->ann_delta))
2125                 return False;
2126         if(!prs_uint32("licenses    ", ps, depth, &sv102->licenses))
2127                 return False;
2128         if(!prs_uint32("ptr_usr_path", ps, depth, &sv102->ptr_usr_path))
2129                 return False;
2130
2131         if(!smb_io_unistr2("uni_name    ", &sv102->uni_name, True, ps, depth))
2132                 return False;
2133         if(!prs_align(ps))
2134                 return False;
2135         if(!smb_io_unistr2("uni_comment ", &sv102->uni_comment, True, ps, depth))
2136                 return False;
2137         if(!prs_align(ps))
2138                 return False;
2139         if(!smb_io_unistr2("uni_usr_path", &sv102->uni_usr_path, True, ps, depth))
2140                 return False;
2141
2142         return True;
2143 }
2144
2145 /*******************************************************************
2146  Reads or writes a SRV_INFO_102 structure.
2147  ********************************************************************/
2148
2149 static BOOL srv_io_info_ctr(char *desc, SRV_INFO_CTR *ctr, prs_struct *ps, int depth)
2150 {
2151         if (ctr == NULL)
2152                 return False;
2153
2154         prs_debug(ps, depth, desc, "srv_io_info_ctr");
2155         depth++;
2156
2157         if(!prs_align(ps))
2158                 return False;
2159
2160         if(!prs_uint32("switch_value", ps, depth, &ctr->switch_value))
2161                 return False;
2162         if(!prs_uint32("ptr_srv_ctr ", ps, depth, &ctr->ptr_srv_ctr))
2163                 return False;
2164
2165         if (ctr->ptr_srv_ctr != 0 && ctr->switch_value != 0 && ctr != NULL) {
2166                 switch (ctr->switch_value) {
2167                 case 100:
2168                         if(!srv_io_info_100("sv100", &ctr->srv.sv100, ps, depth))
2169                                 return False;
2170                         break;
2171                 case 101:
2172                         if(!srv_io_info_101("sv101", &ctr->srv.sv101, ps, depth))
2173                                 return False;
2174                         break;
2175                 case 102:
2176                         if(!srv_io_info_102("sv102", &ctr->srv.sv102, ps, depth))
2177                                 return False;
2178                         break;
2179                 default:
2180                         DEBUG(5,("%s no server info at switch_value %d\n",
2181                                          tab_depth(depth), ctr->switch_value));
2182                         break;
2183                 }
2184                 if(!prs_align(ps))
2185                         return False;
2186         }
2187
2188         return True;
2189 }
2190
2191 /*******************************************************************
2192  Inits a SRV_Q_NET_SRV_GET_INFO structure.
2193  ********************************************************************/
2194
2195 void init_srv_q_net_srv_get_info(SRV_Q_NET_SRV_GET_INFO *srv,
2196                                 char *server_name, uint32 switch_value)
2197 {
2198         DEBUG(5,("init_srv_q_net_srv_get_info\n"));
2199
2200         init_buf_unistr2(&srv->uni_srv_name, &srv->ptr_srv_name, server_name);
2201
2202         srv->switch_value = switch_value;
2203 }
2204
2205 /*******************************************************************
2206  Reads or writes a structure.
2207 ********************************************************************/
2208
2209 BOOL srv_io_q_net_srv_get_info(char *desc, SRV_Q_NET_SRV_GET_INFO *q_n, prs_struct *ps, int depth)
2210 {
2211         if (q_n == NULL)
2212                 return False;
2213
2214         prs_debug(ps, depth, desc, "srv_io_q_net_srv_get_info");
2215         depth++;
2216
2217         if(!prs_align(ps))
2218                 return False;
2219
2220         if(!prs_uint32("ptr_srv_name  ", ps, depth, &q_n->ptr_srv_name))
2221                 return False;
2222         if(!smb_io_unistr2("", &q_n->uni_srv_name, True, ps, depth))
2223                 return False;
2224
2225         if(!prs_align(ps))
2226                 return False;
2227
2228         if(!prs_uint32("switch_value  ", ps, depth, &q_n->switch_value))
2229                 return False;
2230
2231         return True;
2232 }
2233
2234 /*******************************************************************
2235  Inits a SRV_R_NET_SRV_GET_INFO structure.
2236  ********************************************************************/
2237
2238 void init_srv_r_net_srv_get_info(SRV_R_NET_SRV_GET_INFO *srv,
2239                                 uint32 switch_value, SRV_INFO_CTR *ctr, NTSTATUS status)
2240 {
2241         DEBUG(5,("init_srv_r_net_srv_get_info\n"));
2242
2243         srv->ctr = ctr;
2244
2245         if (NT_STATUS_IS_OK(status)) {
2246                 srv->ctr->switch_value = switch_value;
2247                 srv->ctr->ptr_srv_ctr  = 1;
2248         } else {
2249                 srv->ctr->switch_value = 0;
2250                 srv->ctr->ptr_srv_ctr  = 0;
2251         }
2252
2253         srv->status = status;
2254 }
2255
2256 /*******************************************************************
2257  Inits a SRV_R_NET_SRV_SET_INFO structure.
2258  ********************************************************************/
2259
2260 void init_srv_r_net_srv_set_info(SRV_R_NET_SRV_SET_INFO *srv,
2261                                  uint32 switch_value, NTSTATUS status)
2262 {
2263         DEBUG(5,("init_srv_r_net_srv_set_info\n"));
2264
2265         srv->switch_value = switch_value;
2266         srv->status = status;
2267 }
2268
2269 /*******************************************************************
2270  Reads or writes a structure.
2271 ********************************************************************/
2272
2273 BOOL srv_io_q_net_srv_set_info(char *desc, SRV_Q_NET_SRV_SET_INFO *q_n, 
2274                                prs_struct *ps, int depth)
2275 {
2276         prs_debug(ps, depth, desc, "srv_io_q_net_srv_set_info");
2277         depth++;
2278
2279         if(!prs_align(ps))
2280                 return False;
2281
2282         if(!prs_uint32("ptr_srv_name  ", ps, depth, &q_n->ptr_srv_name))
2283                 return False;
2284         if(!smb_io_unistr2("", &q_n->uni_srv_name, True, ps, depth))
2285                 return False;
2286
2287         if(!prs_align(ps))
2288                 return False;
2289
2290         if(!prs_uint32("switch_value  ", ps, depth, &q_n->switch_value))
2291                 return False;
2292
2293         if (UNMARSHALLING(ps)) {
2294                 q_n->ctr = (SRV_INFO_CTR *)
2295                         prs_alloc_mem(ps, sizeof(SRV_INFO_CTR));
2296
2297                 if (!q_n->ctr)
2298                         return False;
2299         }
2300
2301         if(!srv_io_info_ctr("ctr", q_n->ctr, ps, depth))
2302                 return False;
2303
2304         return True;
2305 }
2306
2307 /*******************************************************************
2308  Reads or writes a structure.
2309  ********************************************************************/
2310
2311 BOOL srv_io_r_net_srv_get_info(char *desc, SRV_R_NET_SRV_GET_INFO *r_n, prs_struct *ps, int depth)
2312 {
2313         if (r_n == NULL)
2314                 return False;
2315
2316         prs_debug(ps, depth, desc, "srv_io_r_net_srv_get_info");
2317         depth++;
2318
2319         if(!prs_align(ps))
2320                 return False;
2321
2322         if(!srv_io_info_ctr("ctr", r_n->ctr, ps, depth))
2323                 return False;
2324
2325         if(!prs_ntstatus("status      ", ps, depth, &r_n->status))
2326                 return False;
2327
2328         return True;
2329 }
2330
2331 /*******************************************************************
2332  Reads or writes a structure.
2333  ********************************************************************/
2334
2335 BOOL srv_io_r_net_srv_set_info(char *desc, SRV_R_NET_SRV_SET_INFO *r_n, 
2336                                prs_struct *ps, int depth)
2337 {
2338         prs_debug(ps, depth, desc, "srv_io_r_net_srv_set_info");
2339         depth++;
2340
2341         if(!prs_align(ps))
2342                 return False;
2343
2344         if(!prs_uint32("switch_value  ", ps, depth, &r_n->switch_value))
2345                 return False;
2346
2347         if(!prs_ntstatus("status ", ps, depth, &r_n->status))
2348                 return False;
2349
2350         return True;
2351 }
2352
2353 /*******************************************************************
2354  Reads or writes a structure.
2355  ********************************************************************/
2356
2357 BOOL srv_io_q_net_remote_tod(char *desc, SRV_Q_NET_REMOTE_TOD *q_n, prs_struct *ps, int depth)
2358 {
2359         if (q_n == NULL)
2360                 return False;
2361
2362         prs_debug(ps, depth, desc, "srv_io_q_net_remote_tod");
2363         depth++;
2364
2365         if(!prs_align(ps))
2366                 return False;
2367
2368         if(!prs_uint32("ptr_srv_name  ", ps, depth, &q_n->ptr_srv_name))
2369                 return False;
2370         if(!smb_io_unistr2("", &q_n->uni_srv_name, True, ps, depth))
2371                 return False;
2372
2373         return True;
2374 }
2375
2376 /*******************************************************************
2377  Reads or writes a TIME_OF_DAY_INFO structure.
2378  ********************************************************************/
2379
2380 static BOOL srv_io_time_of_day_info(char *desc, TIME_OF_DAY_INFO *tod, prs_struct *ps, int depth)
2381 {
2382         if (tod == NULL)
2383                 return False;
2384
2385         prs_debug(ps, depth, desc, "srv_io_time_of_day_info");
2386         depth++;
2387
2388         if(!prs_align(ps))
2389                 return False;
2390         
2391         if(!prs_uint32("elapsedt   ", ps, depth, &tod->elapsedt))
2392                 return False;
2393         if(!prs_uint32("msecs      ", ps, depth, &tod->msecs))
2394                 return False;
2395         if(!prs_uint32("hours      ", ps, depth, &tod->hours))
2396                 return False;
2397         if(!prs_uint32("mins       ", ps, depth, &tod->mins))
2398                 return False;
2399         if(!prs_uint32("secs       ", ps, depth, &tod->secs))
2400                 return False;
2401         if(!prs_uint32("hunds      ", ps, depth, &tod->hunds))
2402                 return False;
2403         if(!prs_uint32("timezone   ", ps, depth, &tod->zone))
2404                 return False;
2405         if(!prs_uint32("tintervals ", ps, depth, &tod->tintervals))
2406                 return False;
2407         if(!prs_uint32("day        ", ps, depth, &tod->day))
2408                 return False;
2409         if(!prs_uint32("month      ", ps, depth, &tod->month))
2410                 return False;
2411         if(!prs_uint32("year       ", ps, depth, &tod->year))
2412                 return False;
2413         if(!prs_uint32("weekday    ", ps, depth, &tod->weekday))
2414                 return False;
2415
2416         return True;
2417 }
2418
2419 /*******************************************************************
2420  Inits a TIME_OF_DAY_INFO structure.
2421  ********************************************************************/
2422
2423 void init_time_of_day_info(TIME_OF_DAY_INFO *tod, uint32 elapsedt, uint32 msecs,
2424                            uint32 hours, uint32 mins, uint32 secs, uint32 hunds,
2425                            uint32 zone, uint32 tintervals, uint32 day,
2426                            uint32 month, uint32 year, uint32 weekday)
2427 {
2428         DEBUG(5,("init_time_of_day_info\n"));
2429
2430         tod->elapsedt   = elapsedt;
2431         tod->msecs      = msecs;
2432         tod->hours      = hours;
2433         tod->mins       = mins;
2434         tod->secs       = secs;
2435         tod->hunds      = hunds;
2436         tod->zone       = zone;
2437         tod->tintervals = tintervals;
2438         tod->day        = day;
2439         tod->month      = month;
2440         tod->year       = year;
2441         tod->weekday    = weekday;
2442 }
2443
2444
2445 /*******************************************************************
2446  Reads or writes a structure.
2447  ********************************************************************/
2448
2449 BOOL srv_io_r_net_remote_tod(char *desc, SRV_R_NET_REMOTE_TOD *r_n, prs_struct *ps, int depth)
2450 {
2451         if (r_n == NULL)
2452                 return False;
2453
2454         prs_debug(ps, depth, desc, "srv_io_r_net_remote_tod");
2455         depth++;
2456
2457         if(!prs_align(ps))
2458                 return False;
2459         
2460         if(!prs_uint32("ptr_srv_tod ", ps, depth, &r_n->ptr_srv_tod))
2461                 return False;
2462
2463         if(!srv_io_time_of_day_info("tod", r_n->tod, ps, depth))
2464                 return False;
2465
2466         if(!prs_ntstatus("status      ", ps, depth, &r_n->status))
2467                 return False;
2468
2469         return True;
2470 }
2471
2472 /*******************************************************************
2473  Reads or writes a structure.
2474  ********************************************************************/
2475
2476 BOOL srv_io_q_net_disk_enum(char *desc, SRV_Q_NET_DISK_ENUM *q_n, prs_struct *ps, int depth)
2477 {
2478         if (q_n == NULL)
2479                 return False;
2480
2481         prs_debug(ps, depth, desc, "srv_io_q_net_disk_enum");
2482         depth++;
2483
2484         if(!prs_align(ps))
2485                 return False;
2486
2487         if(!prs_uint32("ptr_srv_name", ps, depth, &q_n->ptr_srv_name))
2488                 return False;
2489
2490         if(!smb_io_unistr2("", &q_n->uni_srv_name, True, ps, depth))
2491                 return False;
2492
2493         if(!prs_align(ps))
2494                 return False;
2495
2496         if(!prs_uint32("level", ps, depth, &q_n->disk_enum_ctr.level))
2497                 return False;
2498
2499         if(!prs_uint32("entries_read", ps, depth, &q_n->disk_enum_ctr.entries_read))
2500                 return False;
2501
2502         if(!prs_uint32("buffer", ps, depth, &q_n->disk_enum_ctr.disk_info_ptr))
2503                 return False;
2504
2505         if(!prs_align(ps))
2506                 return False;
2507
2508         if(!prs_uint32("preferred_len", ps, depth, &q_n->preferred_len))
2509                 return False;
2510         if(!smb_io_enum_hnd("enum_hnd", &q_n->enum_hnd, ps, depth))
2511                 return False;
2512
2513         return True;
2514 }
2515
2516 /*******************************************************************
2517  Reads or writes a structure.
2518  ********************************************************************/
2519
2520 BOOL srv_io_r_net_disk_enum(char *desc, SRV_R_NET_DISK_ENUM *r_n, prs_struct *ps, int depth)
2521 {
2522         int i;
2523
2524         if (r_n == NULL)
2525                 return False;
2526
2527         prs_debug(ps, depth, desc, "srv_io_r_net_disk_enum");
2528         depth++;
2529
2530         if(!prs_align(ps))
2531                 return False;
2532
2533         if(!prs_uint32("entries_read", ps, depth, &r_n->disk_enum_ctr.entries_read))
2534                 return False;
2535         if(!prs_uint32("ptr_disk_info", ps, depth, &r_n->disk_enum_ctr.disk_info_ptr))
2536                 return False;
2537
2538         /*this may be max, unknown, actual?*/
2539
2540         if(!prs_uint32("max_elements", ps, depth, &r_n->disk_enum_ctr.entries_read))
2541                 return False;
2542         if(!prs_uint32("unknown", ps, depth, &r_n->disk_enum_ctr.unknown))
2543                 return False;
2544         if(!prs_uint32("actual_elements", ps, depth, &r_n->disk_enum_ctr.entries_read))
2545                 return False;
2546
2547         for(i=0; i < r_n->disk_enum_ctr.entries_read; i++) {
2548
2549                 if(!prs_uint32("unknown", ps, depth, &r_n->disk_enum_ctr.disk_info[i].unknown))
2550                         return False;
2551    
2552                 if(!smb_io_unistr3("disk_name", &r_n->disk_enum_ctr.disk_info[i].disk_name, ps, depth))
2553                         return False;
2554
2555                 if(!prs_align(ps))
2556                         return False;
2557         }
2558
2559         if(!prs_uint32("total_entries", ps, depth, &r_n->total_entries))
2560                 return False;
2561
2562         if(!smb_io_enum_hnd("enum_hnd", &r_n->enum_hnd, ps, depth))
2563                 return False;
2564
2565         if(!prs_ntstatus("status", ps, depth, &r_n->status))
2566                 return False;
2567
2568         return True;
2569 }
2570
2571 /*******************************************************************
2572  Reads or writes a structure.
2573  ********************************************************************/
2574
2575 BOOL srv_io_q_net_name_validate(char *desc, SRV_Q_NET_NAME_VALIDATE *q_n, prs_struct *ps, int depth)
2576 {
2577         if (q_n == NULL)
2578                 return False;
2579
2580         prs_debug(ps, depth, desc, "srv_io_q_net_name_validate");
2581         depth++;
2582
2583         if(!prs_align(ps))
2584                 return False;
2585
2586         if(!prs_uint32("ptr_srv_name", ps, depth, &q_n->ptr_srv_name))
2587                 return False;
2588
2589         if(!smb_io_unistr2("", &q_n->uni_srv_name, True, ps, depth))
2590                 return False;
2591
2592         if(!prs_align(ps))
2593                 return False;
2594
2595         if(!smb_io_unistr2("", &q_n->uni_name, True, ps, depth))
2596                 return False;
2597
2598         if(!prs_align(ps))
2599                 return False;
2600
2601         if(!prs_uint32("type", ps, depth, &q_n->type))
2602                 return False;
2603
2604         if(!prs_uint32("flags", ps, depth, &q_n->flags))
2605                 return False;
2606
2607         return True;
2608 }
2609
2610 /*******************************************************************
2611  Reads or writes a structure.
2612  ********************************************************************/
2613
2614 BOOL srv_io_r_net_name_validate(char *desc, SRV_R_NET_NAME_VALIDATE *r_n, prs_struct *ps, int depth)
2615 {
2616         if (r_n == NULL)
2617                 return False;
2618
2619         prs_debug(ps, depth, desc, "srv_io_r_net_name_validate");
2620         depth++;
2621
2622         if(!prs_align(ps))
2623                 return False;
2624
2625         if(!prs_ntstatus("status", ps, depth, &r_n->status))
2626                 return False;
2627
2628         return True;
2629 }
2630
2631 /*******************************************************************
2632  Reads or writes a structure.
2633 ********************************************************************/
2634
2635 BOOL srv_io_q_net_file_query_secdesc(char *desc, SRV_Q_NET_FILE_QUERY_SECDESC *q_n, prs_struct *ps, int depth)
2636 {
2637         if (q_n == NULL)
2638                 return False;
2639
2640         prs_debug(ps, depth, desc, "srv_io_q_net_file_query_secdesc");
2641         depth++;
2642
2643         if(!prs_align(ps))
2644                 return False;
2645
2646         if(!prs_uint32("ptr_srv_name", ps, depth, &q_n->ptr_srv_name))
2647                 return False;
2648
2649         if(!smb_io_unistr2("", &q_n->uni_srv_name, True, ps, depth))
2650                 return False;
2651
2652         if(!prs_align(ps))
2653                 return False;
2654
2655         if(!prs_uint32("ptr_qual_name", ps, depth, &q_n->ptr_qual_name))
2656                 return False;
2657
2658         if(!smb_io_unistr2("", &q_n->uni_qual_name, True, ps, depth))
2659                 return False;
2660
2661         if(!prs_align(ps))
2662                 return False;
2663
2664         if(!smb_io_unistr2("", &q_n->uni_file_name, True, ps, depth))
2665                 return False;
2666
2667         if(!prs_uint32("unknown1", ps, depth, &q_n->unknown1))
2668                 return False;
2669
2670         if(!prs_uint32("unknown2", ps, depth, &q_n->unknown2))
2671                 return False;
2672
2673         if(!prs_uint32("unknown3", ps, depth, &q_n->unknown3))
2674                 return False;
2675
2676         return True;
2677 }
2678
2679 /*******************************************************************
2680  Reads or writes a structure.
2681 ********************************************************************/
2682
2683 BOOL srv_io_r_net_file_query_secdesc(char *desc, SRV_R_NET_FILE_QUERY_SECDESC *r_n, prs_struct *ps, int depth)
2684 {
2685         if (r_n == NULL)
2686                 return False;
2687
2688         prs_debug(ps, depth, desc, "srv_io_r_net_file_query_secdesc");
2689         depth++;
2690
2691         if(!prs_align(ps))
2692                 return False;
2693
2694         if(!prs_uint32("ptr_response", ps, depth, &r_n->ptr_response))
2695                 return False;
2696
2697         if(!prs_uint32("size_response", ps, depth, &r_n->size_response))
2698                 return False;
2699
2700         if(!prs_uint32("ptr_secdesc", ps, depth, &r_n->ptr_secdesc))
2701                 return False;
2702
2703         if(!prs_uint32("size_secdesc", ps, depth, &r_n->size_secdesc))
2704                 return False;
2705
2706         if(!sec_io_desc("sec_desc", &r_n->sec_desc, ps, depth))
2707                 return False;
2708
2709         if(!prs_align(ps))
2710                 return False;
2711
2712         if(!prs_ntstatus("status", ps, depth, &r_n->status))
2713                 return False;
2714
2715         return True;
2716 }
2717
2718 /*******************************************************************
2719  Reads or writes a structure.
2720 ********************************************************************/
2721
2722 BOOL srv_io_q_net_file_set_secdesc(char *desc, SRV_Q_NET_FILE_SET_SECDESC *q_n, prs_struct *ps, int depth)
2723 {
2724         if (q_n == NULL)
2725                 return False;
2726
2727         prs_debug(ps, depth, desc, "srv_io_q_net_file_set_secdesc");
2728         depth++;
2729
2730         if(!prs_align(ps))
2731                 return False;
2732
2733         if(!prs_uint32("ptr_srv_name", ps, depth, &q_n->ptr_srv_name))
2734                 return False;
2735
2736         if(!smb_io_unistr2("", &q_n->uni_srv_name, True, ps, depth))
2737                 return False;
2738
2739         if(!prs_align(ps))
2740                 return False;
2741
2742         if(!prs_uint32("ptr_qual_name", ps, depth, &q_n->ptr_qual_name))
2743                 return False;
2744
2745         if(!smb_io_unistr2("", &q_n->uni_qual_name, True, ps, depth))
2746                 return False;
2747
2748         if(!prs_align(ps))
2749                 return False;
2750
2751         if(!smb_io_unistr2("", &q_n->uni_file_name, True, ps, depth))
2752                 return False;
2753
2754         if(!prs_align(ps))
2755                 return False;
2756
2757         if(!prs_uint32("sec_info", ps, depth, &q_n->sec_info))
2758                 return False;
2759
2760         if(!prs_uint32("size_set", ps, depth, &q_n->size_set))
2761                 return False;
2762
2763         if(!prs_uint32("ptr_secdesc", ps, depth, &q_n->ptr_secdesc))
2764                 return False;
2765
2766         if(!prs_uint32("size_secdesc", ps, depth, &q_n->size_secdesc))
2767                 return False;
2768
2769         if(!sec_io_desc("sec_desc", &q_n->sec_desc, ps, depth))
2770                 return False;
2771
2772         return True;
2773 }
2774
2775 /*******************************************************************
2776  Reads or writes a structure.
2777 ********************************************************************/
2778
2779 BOOL srv_io_r_net_file_set_secdesc(char *desc, SRV_R_NET_FILE_SET_SECDESC *r_n, prs_struct *ps, int depth)
2780 {
2781         if (r_n == NULL)
2782                 return False;
2783
2784         prs_debug(ps, depth, desc, "srv_io_r_net_file_set_secdesc");
2785         depth++;
2786
2787         if(!prs_align(ps))
2788                 return False;
2789
2790         if(!prs_ntstatus("status", ps, depth, &r_n->status))
2791                 return False;
2792
2793         return True;
2794 }