first pass at updating head branch to be to be the same as the SAMBA_2_0 branch
[kai/samba-autobuild/.git] / source3 / rpc_parse / parse_srv.c
1
2 /* 
3  *  Unix SMB/Netbios implementation.
4  *  Version 1.9.
5  *  RPC Pipe client / server routines
6  *  Copyright (C) Andrew Tridgell              1992-1997,
7  *  Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
8  *  Copyright (C) Paul Ashton                       1997.
9  *  Copyright (C) Jeremy Allison                    1999.
10  *  
11  *  This program is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2 of the License, or
14  *  (at your option) any later version.
15  *  
16  *  This program is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *  
21  *  You should have received a copy of the GNU General Public License
22  *  along with this program; if not, write to the Free Software
23  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24  */
25
26
27 #include "includes.h"
28
29 extern int DEBUGLEVEL;
30
31 /*******************************************************************
32  Inits a SH_INFO_1_STR structure
33 ********************************************************************/
34
35 void init_srv_share_info1_str(SH_INFO_1_STR *sh1, char *net_name, char *remark)
36 {
37         DEBUG(5,("init_srv_share_info1_str\n"));
38
39         init_unistr2(&sh1->uni_netname, net_name, strlen(net_name)+1);
40         init_unistr2(&sh1->uni_remark, remark, strlen(remark)+1);
41 }
42
43 /*******************************************************************
44  Reads or writes a structure.
45 ********************************************************************/
46
47 static BOOL srv_io_share_info1_str(char *desc, SH_INFO_1_STR *sh1, prs_struct *ps, int depth)
48 {
49         if (sh1 == NULL)
50                 return False;
51
52         prs_debug(ps, depth, desc, "srv_io_share_info1_str");
53         depth++;
54
55         if(!prs_align(ps))
56                 return False;
57
58         if(!smb_io_unistr2("", &sh1->uni_netname, True, ps, depth))
59                 return False;
60         if(!smb_io_unistr2("", &sh1->uni_remark, True, ps, depth))
61                 return False;
62
63         return True;
64 }
65
66 /*******************************************************************
67  makes a SH_INFO_1 structure
68 ********************************************************************/
69
70 void init_srv_share_info1(SH_INFO_1 *sh1, char *net_name, uint32 type, char *remark)
71 {
72         DEBUG(5,("init_srv_share_info1: %s %8x %s\n", net_name, type, remark));
73
74         sh1->ptr_netname = (net_name != NULL) ? 1 : 0;
75         sh1->type        = type;
76         sh1->ptr_remark  = (remark != NULL) ? 1 : 0;
77 }
78
79 /*******************************************************************
80  Reads or writes a structure.
81 ********************************************************************/
82
83 static BOOL srv_io_share_info1(char *desc, SH_INFO_1 *sh1, prs_struct *ps, int depth)
84 {
85         if (sh1 == NULL)
86                 return False;
87
88         prs_debug(ps, depth, desc, "srv_io_share_info1");
89         depth++;
90
91         if(!prs_align(ps))
92                 return False;
93
94         if(!prs_uint32("ptr_netname", ps, depth, &sh1->ptr_netname))
95                 return False;
96         if(!prs_uint32("type       ", ps, depth, &sh1->type))
97                 return False;
98         if(!prs_uint32("ptr_remark ", ps, depth, &sh1->ptr_remark))
99                 return False;
100
101         return True;
102 }
103
104 /*******************************************************************
105  Inits a SH_INFO_2_STR structure
106 ********************************************************************/
107
108 void init_srv_share_info2_str(SH_INFO_2_STR *sh2,
109                                 char *net_name, char *remark,
110                                 char *path, char *passwd)
111 {
112         DEBUG(5,("init_srv_share_info2_str\n"));
113
114         init_unistr2(&sh2->uni_netname, net_name, strlen(net_name)+1);
115         init_unistr2(&sh2->uni_remark, remark, strlen(remark)+1);
116         init_unistr2(&sh2->uni_path, path, strlen(path)+1);
117         init_unistr2(&sh2->uni_passwd, passwd, strlen(passwd)+1);
118 }
119
120 /*******************************************************************
121  Reads or writes a structure.
122 ********************************************************************/
123
124 static BOOL srv_io_share_info2_str(char *desc, SH_INFO_2_STR *sh2, prs_struct *ps, int depth)
125 {
126         if (sh2 == NULL)
127                 return False;
128
129         prs_debug(ps, depth, desc, "srv_io_share_info2_str");
130         depth++;
131
132         if(!prs_align(ps))
133                 return False;
134
135         if(!smb_io_unistr2("", &sh2->uni_netname, True, ps, depth))
136                 return False;
137         if(!smb_io_unistr2("", &sh2->uni_remark, True, ps, depth))
138                 return False;
139         if(!smb_io_unistr2("", &sh2->uni_path, True, ps, depth))
140                 return False;
141         if(!smb_io_unistr2("", &sh2->uni_passwd, True, ps, depth))
142                 return False;
143
144         return True;
145 }
146
147 /*******************************************************************
148  Inits a SH_INFO_2 structure
149 ********************************************************************/
150
151 void init_srv_share_info2(SH_INFO_2 *sh2,
152                                 char *net_name, uint32 type, char *remark,
153                                 uint32 perms, uint32 max_uses, uint32 num_uses,
154                                 char *path, char *passwd)
155 {
156         DEBUG(5,("init_srv_share_info2: %s %8x %s\n", net_name, type, remark));
157
158         sh2->ptr_netname = (net_name != NULL) ? 1 : 0;
159         sh2->type        = type;
160         sh2->ptr_remark  = (remark != NULL) ? 1 : 0;
161         sh2->perms       = perms;
162         sh2->max_uses    = max_uses;
163         sh2->num_uses    = num_uses;
164         sh2->type        = type;
165         sh2->ptr_path    = (path != NULL) ? 1 : 0;
166         sh2->ptr_passwd  = (passwd != NULL) ? 1 : 0;
167 }
168
169 /*******************************************************************
170  Reads or writes a structure.
171 ********************************************************************/
172
173 static BOOL srv_io_share_info2(char *desc, SH_INFO_2 *sh2, prs_struct *ps, int depth)
174 {
175         if (sh2 == NULL)
176                 return False;
177
178         prs_debug(ps, depth, desc, "srv_io_share_info2");
179         depth++;
180
181         if(!prs_align(ps))
182                 return False;
183
184         if(!prs_uint32("ptr_netname", ps, depth, &sh2->ptr_netname))
185                 return False;
186         if(!prs_uint32("type       ", ps, depth, &sh2->type))
187                 return False;
188         if(!prs_uint32("ptr_remark ", ps, depth, &sh2->ptr_remark))
189                 return False;
190         if(!prs_uint32("perms      ", ps, depth, &sh2->perms))
191                 return False;
192         if(!prs_uint32("max_uses   ", ps, depth, &sh2->max_uses))
193                 return False;
194         if(!prs_uint32("num_uses   ", ps, depth, &sh2->num_uses))
195                 return False;
196         if(!prs_uint32("ptr_path   ", ps, depth, &sh2->ptr_path))
197                 return False;
198         if(!prs_uint32("ptr_passwd ", ps, depth, &sh2->ptr_passwd))
199                 return False;
200
201         return True;
202 }
203
204 /*******************************************************************
205  Reads or writes a structure.
206 ********************************************************************/
207
208 static BOOL srv_io_srv_share_ctr(char *desc, SRV_SHARE_INFO_CTR *ctr, prs_struct *ps, int depth)
209 {
210         if (ctr == NULL)
211                 return False;
212
213         prs_debug(ps, depth, desc, "srv_io_srv_share_ctr");
214         depth++;
215
216         if (UNMARSHALLING(ps)) {
217                 memset(ctr, '\0', sizeof(SRV_SHARE_INFO_CTR));
218         }
219
220         if(!prs_align(ps))
221                 return False;
222
223         if(!prs_uint32("info_level", ps, depth, &ctr->info_level))
224                 return False;
225
226         if (ctr->info_level == 0)
227                 return True;
228
229         if(!prs_uint32("switch_value", ps, depth, &ctr->switch_value))
230                 return False;
231         if(!prs_uint32("ptr_share_info", ps, depth, &ctr->ptr_share_info))
232                 return False;
233
234         if (ctr->ptr_share_info == 0)
235                 return True;
236
237         if(!prs_uint32("num_entries", ps, depth, &ctr->num_entries))
238                 return False;
239         if(!prs_uint32("ptr_entries", ps, depth, &ctr->ptr_entries))
240                 return False;
241
242         if (ctr->ptr_entries == 0) {
243                 if (ctr->num_entries == 0)
244                         return True;
245                 else
246                         return False;
247         }
248
249         if(!prs_uint32("num_entries2", ps, depth, &ctr->num_entries2))
250                 return False;
251
252         if (ctr->num_entries2 != ctr->num_entries)
253                 return False;
254
255         switch (ctr->switch_value) {
256         case 1:
257         {
258                 SRV_SHARE_INFO_1 *info1 = ctr->share.info1;
259                 int num_entries = ctr->num_entries;
260                 int i;
261
262                 if (UNMARSHALLING(ps)) {
263                         if (!(info1 = malloc(num_entries * sizeof(SRV_SHARE_INFO_1))))
264                                 return False;
265                         memset(info1, '\0', num_entries * sizeof(SRV_SHARE_INFO_1));
266                         ctr->share.info1 = info1;
267                 }
268
269                 for (i = 0; i < num_entries; i++) {
270                         if(!srv_io_share_info1("", &info1[i].info_1, ps, depth))
271                                 return False;
272                 }
273
274                 for (i = 0; i < num_entries; i++) {
275                         if(!srv_io_share_info1_str("", &info1[i].info_1_str, ps, depth))
276                                 return False;
277                 }
278
279                 break;
280         }
281
282         case 2:
283         {
284                 SRV_SHARE_INFO_2 *info2 = ctr->share.info2;
285                 int num_entries = ctr->num_entries;
286                 int i;
287
288                 if (UNMARSHALLING(ps)) {
289                         if (!(info2 = malloc(num_entries * sizeof(SRV_SHARE_INFO_2))))
290                                 return False;
291                         memset(info2, '\0', num_entries * sizeof(SRV_SHARE_INFO_2));
292                         ctr->share.info2 = info2;
293                 }
294
295                 for (i = 0; i < num_entries; i++) {
296                         if(!srv_io_share_info2("", &info2[i].info_2, ps, depth))
297                                 return False;
298                 }
299
300                 for (i = 0; i < num_entries; i++) {
301                         if(!srv_io_share_info2_str("", &info2[i].info_2_str, ps, depth))
302                                 return False;
303                 }
304
305                 break;
306         }
307
308         default:
309                 DEBUG(5,("%s no share info at switch_value %d\n",
310                          tab_depth(depth), ctr->switch_value));
311                 break;
312         }
313
314         return True;
315 }
316
317 /*******************************************************************
318  Frees a SRV_SHARE_INFO_CTR structure.
319 ********************************************************************/
320
321 void free_srv_share_info_ctr(SRV_SHARE_INFO_CTR *ctr)
322 {
323         if(!ctr)
324                 return;
325         if(ctr->share.info)
326                 free(ctr->share.info);
327         memset(ctr, '\0', sizeof(SRV_SHARE_INFO_CTR));
328 }
329
330 /*******************************************************************
331  Frees a SRV_Q_NET_SHARE_ENUM structure.
332 ********************************************************************/
333
334 void free_srv_q_net_share_enum(SRV_Q_NET_SHARE_ENUM *q_n)
335 {
336         if(!q_n)
337                 return;
338         free_srv_share_info_ctr(&q_n->ctr);
339         memset(q_n, '\0', sizeof(SRV_Q_NET_SHARE_ENUM));
340 }
341
342 /*******************************************************************
343  Frees a SRV_R_NET_SHARE_ENUM structure.
344 ********************************************************************/
345
346 void free_srv_r_net_share_enum(SRV_R_NET_SHARE_ENUM *r_n)
347 {
348         if(!r_n)
349                 return;
350         free_srv_share_info_ctr(&r_n->ctr);
351         memset(r_n, '\0', sizeof(SRV_R_NET_SHARE_ENUM));
352 }
353
354 /*******************************************************************
355  Inits a SRV_Q_NET_SHARE_ENUM structure.
356 ********************************************************************/
357
358 void init_srv_q_net_share_enum(SRV_Q_NET_SHARE_ENUM *q_n, 
359                                 char *srv_name, uint32 info_level,
360                                 uint32 preferred_len, ENUM_HND *hnd)
361 {
362
363         DEBUG(5,("init_q_net_share_enum\n"));
364
365         init_buf_unistr2(&q_n->uni_srv_name, &q_n->ptr_srv_name, srv_name);
366
367         q_n->ctr.info_level = q_n->ctr.switch_value = info_level;
368         q_n->ctr.ptr_share_info = 0;
369         q_n->preferred_len = preferred_len;
370
371         memcpy(&q_n->enum_hnd, hnd, sizeof(*hnd));
372 }
373
374 /*******************************************************************
375  Reads or writes a structure.
376 ********************************************************************/
377
378 BOOL srv_io_q_net_share_enum(char *desc, SRV_Q_NET_SHARE_ENUM *q_n, prs_struct *ps, int depth)
379 {
380         if (q_n == NULL)
381                 return False;
382
383         prs_debug(ps, depth, desc, "srv_io_q_net_share_enum");
384         depth++;
385
386         if(!prs_align(ps))
387                 return False;
388
389         if(!prs_uint32("ptr_srv_name", ps, depth, &q_n->ptr_srv_name))
390                 return False;
391         if(!smb_io_unistr2("", &q_n->uni_srv_name, True, ps, depth))
392                 return False;
393
394         if(!srv_io_srv_share_ctr("share_ctr", &q_n->ctr, ps, depth))
395                 return False;
396
397         if(!prs_align(ps))
398                 return False;
399
400         if(!prs_uint32("preferred_len", ps, depth, &q_n->preferred_len))
401                 return False;
402
403         if(!smb_io_enum_hnd("enum_hnd", &q_n->enum_hnd, ps, depth))
404                 return False;
405
406         return True;
407 }
408
409 /*******************************************************************
410  Reads or writes a structure.
411 ********************************************************************/
412
413 BOOL srv_io_r_net_share_enum(char *desc, SRV_R_NET_SHARE_ENUM *r_n, prs_struct *ps, int depth)
414 {
415         if (r_n == NULL)
416                 return False;
417
418         prs_debug(ps, depth, desc, "srv_io_r_net_share_enum");
419         depth++;
420
421         if(!srv_io_srv_share_ctr("share_ctr", &r_n->ctr, ps, depth))
422                 return False;
423
424         if(!prs_align(ps))
425                 return False;
426
427         if(!prs_uint32("total_entries", ps, depth, &r_n->total_entries))
428                 return False;
429         if(!smb_io_enum_hnd("enum_hnd", &r_n->enum_hnd, ps, depth))
430                 return False;
431         if(!prs_uint32("status     ", ps, depth, &r_n->status))
432                 return False;
433
434         return True;
435 }
436
437 /*******************************************************************
438  Frees a SRV_Q_NET_SHARE_GET_INFO structure.
439 ********************************************************************/
440
441 void free_srv_q_net_share_get_info(SRV_Q_NET_SHARE_GET_INFO *q_n)
442 {
443         if(!q_n)
444                 return;
445         memset(q_n, '\0', sizeof(SRV_Q_NET_SHARE_GET_INFO));
446 }
447
448 /*******************************************************************
449  Frees a SRV_R_NET_SHARE_GET_INFO structure.
450 ********************************************************************/
451
452 void free_srv_r_net_share_get_info(SRV_R_NET_SHARE_GET_INFO *r_n)
453 {
454         if(!r_n)
455                 return;
456         memset(r_n, '\0', sizeof(SRV_R_NET_SHARE_GET_INFO));
457 }
458
459 /*******************************************************************
460  Reads or writes a structure.
461 ********************************************************************/
462
463 BOOL srv_io_q_net_share_get_info(char *desc, SRV_Q_NET_SHARE_GET_INFO *q_n, prs_struct *ps, int depth)
464 {
465         if (q_n == NULL)
466                 return False;
467
468         prs_debug(ps, depth, desc, "srv_io_q_net_share_get_info");
469         depth++;
470
471         if(!prs_align(ps))
472                 return False;
473
474         if(!prs_uint32("ptr_srv_name", ps, depth, &q_n->ptr_srv_name))
475                 return False;
476         if(!smb_io_unistr2("", &q_n->uni_srv_name, True, ps, depth))
477                 return False;
478
479         if(!smb_io_unistr2("", &q_n->uni_share_name, True, ps, depth))
480                 return False;
481
482         if(!prs_align(ps))
483                 return False;
484
485         if(!prs_uint32("info_level", ps, depth, &q_n->info_level))
486                 return False;
487
488         return True;
489 }
490
491 /*******************************************************************
492  Reads or writes a structure.
493 ********************************************************************/
494
495 BOOL srv_io_r_net_share_get_info(char *desc, SRV_R_NET_SHARE_GET_INFO *r_n, prs_struct *ps, int depth)
496 {
497         if (r_n == NULL)
498                 return False;
499
500         prs_debug(ps, depth, desc, "srv_io_r_net_share_get_info");
501         depth++;
502
503         if(!prs_align(ps))
504                 return False;
505
506         if(!prs_uint32("switch_value ", ps, depth, &r_n->switch_value ))
507                 return False;
508
509         if(!prs_uint32("ptr_share_ctr", ps, depth, &r_n->ptr_share_ctr))
510                 return False;
511
512         if (r_n->ptr_share_ctr != 0) {
513                 switch (r_n->switch_value) {
514                 case 1:
515                         if(!srv_io_share_info1("", &r_n->share.info1.info_1, ps, depth))
516                                 return False;
517
518                         if(!srv_io_share_info1_str("", &r_n->share.info1.info_1_str, ps, depth))
519                                 return False;
520
521                         break;
522                 case 2:
523                         if(!srv_io_share_info2("", &r_n->share.info2.info_2, ps, depth))
524                                 return False;
525
526                         if(!srv_io_share_info2_str("", &r_n->share.info2.info_2_str, ps, depth))
527                                 return False;
528
529                         break;
530                 default:
531                         DEBUG(5,("%s no share info at switch_value %d\n",
532                                  tab_depth(depth), r_n->switch_value));
533                         break;
534                 }
535         }
536
537         if(!prs_align(ps))
538                 return False;
539
540         if(!prs_uint32("status", ps, depth, &r_n->status))
541                 return False;
542
543         return True;
544 }
545
546 /*******************************************************************
547  Inits a SESS_INFO_0_STR structure
548 ********************************************************************/
549
550 void init_srv_sess_info0_str(SESS_INFO_0_STR *ss0, char *name)
551 {
552         DEBUG(5,("init_srv_sess_info0_str\n"));
553
554         init_unistr2(&ss0->uni_name, name, strlen(name)+1);
555 }
556
557 /*******************************************************************
558  Reads or writes a structure.
559 ********************************************************************/
560
561 static BOOL srv_io_sess_info0_str(char *desc,  SESS_INFO_0_STR *ss0, prs_struct *ps, int depth)
562 {
563         if (ss0 == NULL)
564                 return False;
565
566         prs_debug(ps, depth, desc, "srv_io_sess_info0_str");
567         depth++;
568
569         if(!prs_align(ps))
570                 return False;
571
572         if(!smb_io_unistr2("", &ss0->uni_name, True, ps, depth))
573                 return False;
574
575         return True;
576 }
577
578 /*******************************************************************
579  Inits a SESS_INFO_0 structure
580 ********************************************************************/
581
582 void init_srv_sess_info0(SESS_INFO_0 *ss0, char *name)
583 {
584         DEBUG(5,("init_srv_sess_info0: %s\n", name));
585
586         ss0->ptr_name = (name != NULL) ? 1 : 0;
587 }
588
589 /*******************************************************************
590  Reads or writes a structure.
591 ********************************************************************/
592
593 static BOOL srv_io_sess_info0(char *desc, SESS_INFO_0 *ss0, prs_struct *ps, int depth)
594 {
595         if (ss0 == NULL)
596                 return False;
597
598         prs_debug(ps, depth, desc, "srv_io_sess_info0");
599         depth++;
600
601         if(!prs_align(ps))
602                 return False;
603
604         if(!prs_uint32("ptr_name", ps, depth, &ss0->ptr_name))
605                 return False;
606
607         return True;
608 }
609
610 /*******************************************************************
611  Reads or writes a structure.
612 ********************************************************************/
613
614 static BOOL srv_io_srv_sess_info_0(char *desc, SRV_SESS_INFO_0 *ss0, prs_struct *ps, int depth)
615 {
616         if (ss0 == NULL)
617                 return False;
618
619         prs_debug(ps, depth, desc, "srv_io_srv_sess_info_0");
620         depth++;
621
622         if(!prs_align(ps))
623                 return False;
624
625         if(!prs_uint32("num_entries_read", ps, depth, &ss0->num_entries_read))
626                 return False;
627         if(!prs_uint32("ptr_sess_info", ps, depth, &ss0->ptr_sess_info))
628                 return False;
629
630         if (ss0->ptr_sess_info != 0) {
631                 int i;
632                 int num_entries = ss0->num_entries_read;
633
634                 if (num_entries > MAX_SESS_ENTRIES) {
635                         num_entries = MAX_SESS_ENTRIES; /* report this! */
636                 }
637
638                 if(!prs_uint32("num_entries_read2", ps, depth, &ss0->num_entries_read2))
639                         return False;
640
641                 SMB_ASSERT_ARRAY(ss0->info_0, num_entries);
642
643                 for (i = 0; i < num_entries; i++) {
644                         if(!srv_io_sess_info0("", &ss0->info_0[i], ps, depth))
645                                 return False;
646                 }
647
648                 for (i = 0; i < num_entries; i++) {
649                         if(!srv_io_sess_info0_str("", &ss0->info_0_str[i], ps, depth))
650                                 return False;
651                 }
652
653                 if(!prs_align(ps))
654                         return False;
655         }
656
657         return True;
658 }
659
660 /*******************************************************************
661  Inits a SESS_INFO_1_STR structure
662 ********************************************************************/
663
664 void init_srv_sess_info1_str(SESS_INFO_1_STR *ss1, char *name, char *user)
665 {
666         DEBUG(5,("init_srv_sess_info1_str\n"));
667
668         init_unistr2(&ss1->uni_name, name, strlen(name)+1);
669         init_unistr2(&ss1->uni_user, name, strlen(user)+1);
670 }
671
672 /*******************************************************************
673  Reads or writes a structure.
674 ********************************************************************/
675
676 static BOOL srv_io_sess_info1_str(char *desc, SESS_INFO_1_STR *ss1, prs_struct *ps, int depth)
677 {
678         if (ss1 == NULL)
679                 return False;
680
681         prs_debug(ps, depth, desc, "srv_io_sess_info1_str");
682         depth++;
683
684         if(!prs_align(ps))
685                 return False;
686
687         if(!smb_io_unistr2("", &ss1->uni_name, True, ps, depth))
688                 return False;
689         if(!smb_io_unistr2("", &(ss1->uni_user), True, ps, depth))
690                 return False;
691
692         return True;
693 }
694
695 /*******************************************************************
696  Inits a SESS_INFO_1 structure
697 ********************************************************************/
698
699 void init_srv_sess_info1(SESS_INFO_1 *ss1, 
700                                 char *name, char *user,
701                                 uint32 num_opens, uint32 open_time, uint32 idle_time,
702                                 uint32 user_flags)
703 {
704         DEBUG(5,("init_srv_sess_info1: %s\n", name));
705
706         ss1->ptr_name = (name != NULL) ? 1 : 0;
707         ss1->ptr_user = (user != NULL) ? 1 : 0;
708
709         ss1->num_opens  = num_opens;
710         ss1->open_time  = open_time;
711         ss1->idle_time  = idle_time;
712         ss1->user_flags = user_flags;
713 }
714
715 /*******************************************************************
716 reads or writes a structure.
717 ********************************************************************/
718
719 static BOOL srv_io_sess_info1(char *desc, SESS_INFO_1 *ss1, prs_struct *ps, int depth)
720 {
721         if (ss1 == NULL)
722                 return False;
723
724         prs_debug(ps, depth, desc, "srv_io_sess_info1");
725         depth++;
726
727         if(!prs_align(ps))
728                 return False;
729
730         if(!prs_uint32("ptr_name  ", ps, depth, &ss1->ptr_name))
731                 return False;
732         if(!prs_uint32("ptr_user  ", ps, depth, &ss1->ptr_user))
733                 return False;
734
735         if(!prs_uint32("num_opens ", ps, depth, &ss1->num_opens))
736                 return False;
737         if(!prs_uint32("open_time ", ps, depth, &ss1->open_time))
738                 return False;
739         if(!prs_uint32("idle_time ", ps, depth, &ss1->idle_time))
740                 return False;
741         if(!prs_uint32("user_flags", ps, depth, &ss1->user_flags))
742                 return False;
743
744         return True;
745 }
746
747 /*******************************************************************
748  Reads or writes a structure.
749 ********************************************************************/
750
751 static BOOL srv_io_srv_sess_info_1(char *desc, SRV_SESS_INFO_1 *ss1, prs_struct *ps, int depth)
752 {
753         if (ss1 == NULL)
754                 return False;
755
756         prs_debug(ps, depth, desc, "srv_io_srv_sess_info_1");
757         depth++;
758
759         if(!prs_align(ps))
760                 return False;
761
762         if(!prs_uint32("num_entries_read", ps, depth, &ss1->num_entries_read))
763                 return False;
764         if(!prs_uint32("ptr_sess_info", ps, depth, &ss1->ptr_sess_info))
765                 return False;
766
767         if (ss1->ptr_sess_info != 0) {
768                 int i;
769                 int num_entries = ss1->num_entries_read;
770
771                 if (num_entries > MAX_SESS_ENTRIES) {
772                         num_entries = MAX_SESS_ENTRIES; /* report this! */
773                 }
774
775                 if(!prs_uint32("num_entries_read2", ps, depth, &ss1->num_entries_read2))
776                         return False;
777
778                 SMB_ASSERT_ARRAY(ss1->info_1, num_entries);
779
780                 for (i = 0; i < num_entries; i++) {
781                         if(!srv_io_sess_info1("", &ss1->info_1[i], ps, depth))
782                                 return False;
783                 }
784
785                 for (i = 0; i < num_entries; i++) {
786                         if(!srv_io_sess_info1_str("", &ss1->info_1_str[i], ps, depth))
787                                 return False;
788                 }
789
790                 if(!prs_align(ps))
791                         return False;
792         }
793
794         return True;
795 }
796
797 /*******************************************************************
798  Reads or writes a structure.
799 ********************************************************************/
800
801 static BOOL srv_io_srv_sess_ctr(char *desc, SRV_SESS_INFO_CTR *ctr, prs_struct *ps, int depth)
802 {
803         if (ctr == NULL)
804                 return False;
805
806         prs_debug(ps, depth, desc, "srv_io_srv_sess_ctr");
807         depth++;
808
809         if(!prs_align(ps))
810                 return False;
811
812         if(!prs_uint32("switch_value", ps, depth, &ctr->switch_value))
813                 return False;
814         if(!prs_uint32("ptr_sess_ctr", ps, depth, &ctr->ptr_sess_ctr))
815                 return False;
816
817         if (ctr->ptr_sess_ctr != 0) {
818                 switch (ctr->switch_value) {
819                 case 0:
820                         if(!srv_io_srv_sess_info_0("", &ctr->sess.info0, ps, depth))
821                                 return False;
822                         break;
823                 case 1:
824                         if(!srv_io_srv_sess_info_1("", &ctr->sess.info1, ps, depth))
825                                 return False;
826                         break;
827                 default:
828                         DEBUG(5,("%s no session info at switch_value %d\n",
829                                  tab_depth(depth), ctr->switch_value));
830                         break;
831                 }
832         }
833
834         return True;
835 }
836
837 /*******************************************************************
838  Inits a SRV_Q_NET_SESS_ENUM structure.
839 ********************************************************************/
840
841 void init_srv_q_net_sess_enum(SRV_Q_NET_SESS_ENUM *q_n, 
842                                 char *srv_name, char *qual_name,
843                                 uint32 sess_level, SRV_SESS_INFO_CTR *ctr,
844                                 uint32 preferred_len,
845                                 ENUM_HND *hnd)
846 {
847         q_n->ctr = ctr;
848
849         DEBUG(5,("init_q_net_sess_enum\n"));
850
851         init_buf_unistr2(&q_n->uni_srv_name, &q_n->ptr_srv_name, srv_name);
852         init_buf_unistr2(&q_n->uni_qual_name, &q_n->ptr_qual_name, qual_name);
853
854         q_n->sess_level    = sess_level;
855         q_n->preferred_len = preferred_len;
856
857         memcpy(&q_n->enum_hnd, hnd, sizeof(*hnd));
858 }
859
860 /*******************************************************************
861  Reads or writes a structure.
862 ********************************************************************/
863
864 BOOL srv_io_q_net_sess_enum(char *desc, SRV_Q_NET_SESS_ENUM *q_n, prs_struct *ps, int depth)
865 {
866         if (q_n == NULL)
867                 return False;
868
869         prs_debug(ps, depth, desc, "srv_io_q_net_sess_enum");
870         depth++;
871
872         if(!prs_align(ps))
873                 return False;
874
875         if(!prs_uint32("ptr_srv_name", ps, depth, &q_n->ptr_srv_name))
876                 return False;
877         if(!smb_io_unistr2("", &q_n->uni_srv_name, True, ps, depth))
878                 return False;
879
880         if(!prs_align(ps))
881                 return False;
882
883         if(!prs_uint32("ptr_qual_name", ps, depth, &q_n->ptr_qual_name))
884                 return False;
885         if(!smb_io_unistr2("", &q_n->uni_qual_name, q_n->ptr_qual_name, ps, depth))
886                 return False;
887
888         if(!prs_align(ps))
889                 return False;
890
891         if(!prs_uint32("sess_level", ps, depth, &q_n->sess_level))
892                 return False;
893         
894         if (q_n->sess_level != -1) {
895                 if(!srv_io_srv_sess_ctr("sess_ctr", q_n->ctr, ps, depth))
896                         return False;
897         }
898
899         if(!prs_uint32("preferred_len", ps, depth, &q_n->preferred_len))
900                 return False;
901
902         if(!smb_io_enum_hnd("enum_hnd", &q_n->enum_hnd, ps, depth))
903                 return False;
904
905         return True;
906 }
907
908 /*******************************************************************
909  Reads or writes a structure.
910 ********************************************************************/
911
912 BOOL srv_io_r_net_sess_enum(char *desc, SRV_R_NET_SESS_ENUM *r_n, prs_struct *ps, int depth)
913 {
914         if (r_n == NULL)
915                 return False;
916
917         prs_debug(ps, depth, desc, "srv_io_r_net_sess_enum");
918         depth++;
919
920         if(!prs_align(ps))
921                 return False;
922
923         if(!prs_uint32("sess_level", ps, depth, &r_n->sess_level))
924                 return False;
925
926         if (r_n->sess_level != -1) {
927                 if(!srv_io_srv_sess_ctr("sess_ctr", r_n->ctr, ps, depth))
928                         return False;
929         }
930
931         if(!prs_uint32("total_entries", ps, depth, &r_n->total_entries))
932                 return False;
933         if(!smb_io_enum_hnd("enum_hnd", &r_n->enum_hnd, ps, depth))
934                 return False;
935         if(!prs_uint32("status     ", ps, depth, &r_n->status))
936                 return False;
937
938         return True;
939 }
940
941 /*******************************************************************
942  Inits a CONN_INFO_0 structure
943 ********************************************************************/
944
945 void init_srv_conn_info0(CONN_INFO_0 *ss0, uint32 id)
946 {
947         DEBUG(5,("init_srv_conn_info0\n"));
948
949         ss0->id = id;
950 }
951
952 /*******************************************************************
953  Reads or writes a structure.
954 ********************************************************************/
955
956 static BOOL srv_io_conn_info0(char *desc, CONN_INFO_0 *ss0, prs_struct *ps, int depth)
957 {
958         if (ss0 == NULL)
959                 return False;
960
961         prs_debug(ps, depth, desc, "srv_io_conn_info0");
962         depth++;
963
964         if(!prs_align(ps))
965                 return False;
966
967         if(!prs_uint32("id", ps, depth, &ss0->id))
968                 return False;
969
970         return True;
971 }
972
973 /*******************************************************************
974  Reads or writes a structure.
975 ********************************************************************/
976
977 static BOOL srv_io_srv_conn_info_0(char *desc, SRV_CONN_INFO_0 *ss0, prs_struct *ps, int depth)
978 {
979         if (ss0 == NULL)
980                 return False;
981
982         prs_debug(ps, depth, desc, "srv_io_srv_conn_info_0");
983         depth++;
984
985         if(!prs_align(ps))
986                 return False;
987
988         if(!prs_uint32("num_entries_read", ps, depth, &ss0->num_entries_read))
989                 return False;
990         if(!prs_uint32("ptr_conn_info", ps, depth, &ss0->ptr_conn_info))
991                 return False;
992
993         if (ss0->ptr_conn_info != 0) {
994                 int i;
995                 int num_entries = ss0->num_entries_read;
996
997                 if (num_entries > MAX_CONN_ENTRIES) {
998                         num_entries = MAX_CONN_ENTRIES; /* report this! */
999                 }
1000
1001                 if(!prs_uint32("num_entries_read2", ps, depth, &ss0->num_entries_read2))
1002                         return False;
1003
1004                 for (i = 0; i < num_entries; i++) {
1005                         if(!srv_io_conn_info0("", &ss0->info_0[i], ps, depth))
1006                                 return False;
1007                 }
1008
1009                 if(!prs_align(ps))
1010                         return False;
1011         }
1012
1013         return True;
1014 }
1015
1016 /*******************************************************************
1017  Inits a CONN_INFO_1_STR structure
1018 ********************************************************************/
1019
1020 void init_srv_conn_info1_str(CONN_INFO_1_STR *ss1, char *usr_name, char *net_name)
1021 {
1022         DEBUG(5,("init_srv_conn_info1_str\n"));
1023
1024         init_unistr2(&ss1->uni_usr_name, usr_name, strlen(usr_name)+1);
1025         init_unistr2(&ss1->uni_net_name, net_name, strlen(net_name)+1);
1026 }
1027
1028 /*******************************************************************
1029  Reads or writes a structure.
1030 ********************************************************************/
1031
1032 static BOOL srv_io_conn_info1_str(char *desc, CONN_INFO_1_STR *ss1, prs_struct *ps, int depth)
1033 {
1034         if (ss1 == NULL)
1035                 return False;
1036
1037         prs_debug(ps, depth, desc, "srv_io_conn_info1_str");
1038         depth++;
1039
1040         if(!prs_align(ps))
1041                 return False;
1042
1043         if(!smb_io_unistr2("", &ss1->uni_usr_name, True, ps, depth))
1044                 return False;
1045         if(!smb_io_unistr2("", &ss1->uni_net_name, True, ps, depth))
1046                 return False;
1047
1048         return True;
1049 }
1050
1051 /*******************************************************************
1052  Inits a CONN_INFO_1 structure
1053 ********************************************************************/
1054
1055 void init_srv_conn_info1(CONN_INFO_1 *ss1, 
1056                                 uint32 id, uint32 type,
1057                                 uint32 num_opens, uint32 num_users, uint32 open_time,
1058                                 char *usr_name, char *net_name)
1059 {
1060         DEBUG(5,("init_srv_conn_info1: %s %s\n", usr_name, net_name));
1061
1062         ss1->id        = id       ;
1063         ss1->type      = type     ;
1064         ss1->num_opens = num_opens ;
1065         ss1->num_users = num_users;
1066         ss1->open_time = open_time;
1067
1068         ss1->ptr_usr_name = (usr_name != NULL) ? 1 : 0;
1069         ss1->ptr_net_name = (net_name != NULL) ? 1 : 0;
1070 }
1071
1072 /*******************************************************************
1073  Reads or writes a structure.
1074 ********************************************************************/
1075
1076 static BOOL srv_io_conn_info1(char *desc, CONN_INFO_1 *ss1, prs_struct *ps, int depth)
1077 {
1078         if (ss1 == NULL)
1079                 return False;
1080
1081         prs_debug(ps, depth, desc, "srv_io_conn_info1");
1082         depth++;
1083
1084         if(!prs_align(ps))
1085                 return False;
1086
1087         if(!prs_uint32("id          ", ps, depth, &ss1->id))
1088                 return False;
1089         if(!prs_uint32("type        ", ps, depth, &ss1->type))
1090                 return False;
1091         if(!prs_uint32("num_opens   ", ps, depth, &ss1->num_opens))
1092                 return False;
1093         if(!prs_uint32("num_users   ", ps, depth, &ss1->num_users))
1094                 return False;
1095         if(!prs_uint32("open_time   ", ps, depth, &ss1->open_time))
1096                 return False;
1097
1098         if(!prs_uint32("ptr_usr_name", ps, depth, &ss1->ptr_usr_name))
1099                 return False;
1100         if(!prs_uint32("ptr_net_name", ps, depth, &ss1->ptr_net_name))
1101                 return False;
1102
1103         return True;
1104 }
1105
1106 /*******************************************************************
1107  Reads or writes a structure.
1108 ********************************************************************/
1109
1110 static BOOL srv_io_srv_conn_info_1(char *desc, SRV_CONN_INFO_1 *ss1, prs_struct *ps, int depth)
1111 {
1112         if (ss1 == NULL)
1113                 return False;
1114
1115         prs_debug(ps, depth, desc, "srv_io_srv_conn_info_1");
1116         depth++;
1117
1118         if(!prs_align(ps))
1119                 return False;
1120
1121         if(!prs_uint32("num_entries_read", ps, depth, &ss1->num_entries_read))
1122                 return False;
1123         if(!prs_uint32("ptr_conn_info", ps, depth, &ss1->ptr_conn_info))
1124                 return False;
1125
1126         if (ss1->ptr_conn_info != 0) {
1127                 int i;
1128                 int num_entries = ss1->num_entries_read;
1129
1130                 if (num_entries > MAX_CONN_ENTRIES) {
1131                         num_entries = MAX_CONN_ENTRIES; /* report this! */
1132                 }
1133
1134                 if(!prs_uint32("num_entries_read2", ps, depth, &ss1->num_entries_read2))
1135                         return False;
1136
1137                 for (i = 0; i < num_entries; i++) {
1138                         if(!srv_io_conn_info1("", &ss1->info_1[i], ps, depth))
1139                                 return False;
1140                 }
1141
1142                 for (i = 0; i < num_entries; i++) {
1143                         if(!srv_io_conn_info1_str("", &ss1->info_1_str[i], ps, depth))
1144                                 return False;
1145                 }
1146
1147                 if(!prs_align(ps))
1148                         return False;
1149         }
1150
1151         return True;
1152 }
1153
1154 /*******************************************************************
1155  Reads or writes a structure.
1156 ********************************************************************/
1157
1158 static BOOL srv_io_srv_conn_ctr(char *desc, SRV_CONN_INFO_CTR *ctr, prs_struct *ps, int depth)
1159 {
1160         if (ctr == NULL)
1161                 return False;
1162
1163         prs_debug(ps, depth, desc, "srv_io_srv_conn_ctr");
1164         depth++;
1165
1166         if(!prs_align(ps))
1167                 return False;
1168
1169         if(!prs_uint32("switch_value", ps, depth, &ctr->switch_value))
1170                 return False;
1171         if(!prs_uint32("ptr_conn_ctr", ps, depth, &ctr->ptr_conn_ctr))
1172                 return False;
1173
1174         if (ctr->ptr_conn_ctr != 0) {
1175                 switch (ctr->switch_value) {
1176                 case 0:
1177                         if(!srv_io_srv_conn_info_0("", &ctr->conn.info0, ps, depth))
1178                                 return False;
1179                         break;
1180                 case 1:
1181                         if(!srv_io_srv_conn_info_1("", &ctr->conn.info1, ps, depth))
1182                                 return False;
1183                         break;
1184                 default:
1185                         DEBUG(5,("%s no connection info at switch_value %d\n",
1186                                  tab_depth(depth), ctr->switch_value));
1187                         break;
1188                 }
1189         }
1190
1191         return True;
1192 }
1193
1194 /*******************************************************************
1195   Reads or writes a structure.
1196 ********************************************************************/
1197
1198 void init_srv_q_net_conn_enum(SRV_Q_NET_CONN_ENUM *q_n, 
1199                                 char *srv_name, char *qual_name,
1200                                 uint32 conn_level, SRV_CONN_INFO_CTR *ctr,
1201                                 uint32 preferred_len,
1202                                 ENUM_HND *hnd)
1203 {
1204         DEBUG(5,("init_q_net_conn_enum\n"));
1205
1206         q_n->ctr = ctr;
1207
1208         init_buf_unistr2(&q_n->uni_srv_name, &q_n->ptr_srv_name, srv_name );
1209         init_buf_unistr2(&q_n->uni_qual_name, &q_n->ptr_qual_name, qual_name);
1210
1211         q_n->conn_level    = conn_level;
1212         q_n->preferred_len = preferred_len;
1213
1214         memcpy(&q_n->enum_hnd, hnd, sizeof(*hnd));
1215 }
1216
1217 /*******************************************************************
1218  Reads or writes a structure.
1219 ********************************************************************/
1220
1221 BOOL srv_io_q_net_conn_enum(char *desc, SRV_Q_NET_CONN_ENUM *q_n, prs_struct *ps, int depth)
1222 {
1223         if (q_n == NULL)
1224                 return False;
1225
1226         prs_debug(ps, depth, desc, "srv_io_q_net_conn_enum");
1227         depth++;
1228
1229         if(!prs_align(ps))
1230                 return False;
1231
1232         if(!prs_uint32("ptr_srv_name ", ps, depth, &q_n->ptr_srv_name))
1233                 return False;
1234         if(!smb_io_unistr2("", &q_n->uni_srv_name, q_n->ptr_srv_name, ps, depth))
1235                 return False;
1236
1237         if(!prs_align(ps))
1238                 return False;
1239
1240         if(!prs_uint32("ptr_qual_name", ps, depth, &q_n->ptr_qual_name))
1241                 return False;
1242         if(!smb_io_unistr2("", &q_n->uni_qual_name, q_n->ptr_qual_name, ps, depth))
1243                 return False;
1244
1245         if(!prs_align(ps))
1246                 return False;
1247
1248         if(!prs_uint32("conn_level", ps, depth, &q_n->conn_level))
1249                 return False;
1250         
1251         if (q_n->conn_level != -1) {
1252                 if(!srv_io_srv_conn_ctr("conn_ctr", q_n->ctr, ps, depth))
1253                         return False;
1254         }
1255
1256         if(!prs_uint32("preferred_len", ps, depth, &q_n->preferred_len))
1257                 return False;
1258
1259         if(!smb_io_enum_hnd("enum_hnd", &q_n->enum_hnd, ps, depth))
1260                 return False;
1261
1262         return True;
1263 }
1264
1265 /*******************************************************************
1266  Reads or writes a structure.
1267 ********************************************************************/
1268
1269 BOOL srv_io_r_net_conn_enum(char *desc,  SRV_R_NET_CONN_ENUM *r_n, prs_struct *ps, int depth)
1270 {
1271         if (r_n == NULL)
1272                 return False;
1273
1274         prs_debug(ps, depth, desc, "srv_io_r_net_conn_enum");
1275         depth++;
1276
1277         if(!prs_align(ps))
1278                 return False;
1279
1280         if(!prs_uint32("conn_level", ps, depth, &r_n->conn_level))
1281                 return False;
1282
1283         if (r_n->conn_level != -1) {
1284                 if(!srv_io_srv_conn_ctr("conn_ctr", r_n->ctr, ps, depth))
1285                         return False;
1286         }
1287
1288         if(!prs_uint32("total_entries", ps, depth, &r_n->total_entries))
1289                 return False;
1290         if(!smb_io_enum_hnd("enum_hnd", &r_n->enum_hnd, ps, depth))
1291                 return False;
1292         if(!prs_uint32("status     ", ps, depth, &r_n->status))
1293                 return False;
1294
1295         return True;
1296 }
1297
1298 /*******************************************************************
1299  Inits a FILE_INFO_3_STR structure
1300 ********************************************************************/
1301
1302 void init_srv_file_info3_str(FILE_INFO_3_STR *fi3, char *user_name, char *path_name)
1303 {
1304         DEBUG(5,("init_srv_file_info3_str\n"));
1305
1306         init_unistr2(&fi3->uni_path_name, path_name, strlen(path_name)+1);
1307         init_unistr2(&fi3->uni_user_name, user_name, strlen(user_name)+1);
1308 }
1309
1310 /*******************************************************************
1311  Reads or writes a structure.
1312 ********************************************************************/
1313
1314 static BOOL srv_io_file_info3_str(char *desc, FILE_INFO_3_STR *sh1, prs_struct *ps, int depth)
1315 {
1316         if (sh1 == NULL)
1317                 return False;
1318
1319         prs_debug(ps, depth, desc, "srv_io_file_info3_str");
1320         depth++;
1321
1322         if(!prs_align(ps))
1323                 return False;
1324
1325         if(!smb_io_unistr2("", &sh1->uni_path_name, True, ps, depth))
1326                 return False;
1327         if(!smb_io_unistr2("", &sh1->uni_user_name, True, ps, depth))
1328                 return False;
1329
1330         return True;
1331 }
1332
1333 /*******************************************************************
1334  Inits a FILE_INFO_3 structure
1335 ********************************************************************/
1336
1337 void init_srv_file_info3(FILE_INFO_3 *fl3,
1338                                 uint32 id, uint32 perms, uint32 num_locks,
1339                                 char *path_name, char *user_name)
1340 {
1341         DEBUG(5,("init_srv_file_info3: %s %s\n", path_name, user_name));
1342
1343         fl3->id        = id;    
1344         fl3->perms     = perms;
1345         fl3->num_locks = num_locks;
1346
1347         fl3->ptr_path_name = (path_name != NULL) ? 1 : 0;
1348         fl3->ptr_user_name = (user_name != NULL) ? 1 : 0;
1349 }
1350
1351 /*******************************************************************
1352  Reads or writes a structure.
1353 ********************************************************************/
1354
1355 static BOOL srv_io_file_info3(char *desc, FILE_INFO_3 *fl3, prs_struct *ps, int depth)
1356 {
1357         if (fl3 == NULL)
1358                 return False;
1359
1360         prs_debug(ps, depth, desc, "srv_io_file_info3");
1361         depth++;
1362
1363         if(!prs_align(ps))
1364                 return False;
1365
1366         if(!prs_uint32("id           ", ps, depth, &fl3->id))
1367                 return False;
1368         if(!prs_uint32("perms        ", ps, depth, &fl3->perms))
1369                 return False;
1370         if(!prs_uint32("num_locks    ", ps, depth, &fl3->num_locks))
1371                 return False;
1372         if(!prs_uint32("ptr_path_name", ps, depth, &fl3->ptr_path_name))
1373                 return False;
1374         if(!prs_uint32("ptr_user_name", ps, depth, &fl3->ptr_user_name))
1375                 return False;
1376
1377         return True;
1378 }
1379
1380 /*******************************************************************
1381  Reads or writes a structure.
1382 ********************************************************************/
1383
1384 static BOOL srv_io_srv_file_info_3(char *desc, SRV_FILE_INFO_3 *fl3, prs_struct *ps, int depth)
1385 {
1386         if (fl3 == NULL)
1387                 return False;
1388
1389         prs_debug(ps, depth, desc, "srv_io_file_3_fl3");
1390         depth++;
1391
1392         if(!prs_align(ps))
1393                 return False;
1394
1395         if(!prs_uint32("num_entries_read", ps, depth, &fl3->num_entries_read))
1396                 return False;
1397         if(!prs_uint32("ptr_file_fl3", ps, depth, &fl3->ptr_file_info))
1398                 return False;
1399
1400         if (fl3->ptr_file_info != 0) {
1401                 int i;
1402                 int num_entries = fl3->num_entries_read;
1403
1404                 if (num_entries > MAX_FILE_ENTRIES) {
1405                         num_entries = MAX_FILE_ENTRIES; /* report this! */
1406                 }
1407
1408                 if(!prs_uint32("num_entries_read2", ps, depth, &fl3->num_entries_read2))
1409                         return False;
1410
1411                 for (i = 0; i < num_entries; i++) {
1412                         if(!srv_io_file_info3("", &fl3->info_3[i], ps, depth))
1413                                 return False;
1414                 }
1415
1416                 for (i = 0; i < num_entries; i++) {
1417                         if(!srv_io_file_info3_str("", &fl3->info_3_str[i], ps, depth))
1418                                 return False;
1419                 }
1420
1421                 if(!prs_align(ps))
1422                         return False;
1423         }
1424
1425         return True;
1426 }
1427
1428 /*******************************************************************
1429  Reads or writes a structure.
1430 ********************************************************************/
1431
1432 static BOOL srv_io_srv_file_ctr(char *desc, SRV_FILE_INFO_CTR *ctr, prs_struct *ps, int depth)
1433 {
1434         if (ctr == NULL)
1435                 return False;
1436
1437         prs_debug(ps, depth, desc, "srv_io_srv_file_ctr");
1438         depth++;
1439
1440         if(!prs_align(ps))
1441                 return False;
1442
1443         if(!prs_uint32("switch_value", ps, depth, &ctr->switch_value))
1444                 return False;
1445         if(!prs_uint32("ptr_file_ctr", ps, depth, &ctr->ptr_file_ctr))
1446                 return False;
1447
1448         if (ctr->ptr_file_ctr != 0) {
1449                 switch (ctr->switch_value) {
1450                 case 3:
1451                         if(!srv_io_srv_file_info_3("", &ctr->file.info3, ps, depth))
1452                                 return False;
1453                         break;
1454                 default:
1455                         DEBUG(5,("%s no file info at switch_value %d\n",
1456                                  tab_depth(depth), ctr->switch_value));
1457                         break;
1458                 }
1459         }
1460
1461         return True;
1462 }
1463
1464 /*******************************************************************
1465  Inits a SRV_Q_NET_FILE_ENUM structure.
1466 ********************************************************************/
1467
1468 void init_srv_q_net_file_enum(SRV_Q_NET_FILE_ENUM *q_n, 
1469                                 char *srv_name, char *qual_name,
1470                                 uint32 file_level, SRV_FILE_INFO_CTR *ctr,
1471                                 uint32 preferred_len,
1472                                 ENUM_HND *hnd)
1473 {
1474         DEBUG(5,("init_q_net_file_enum\n"));
1475
1476         q_n->ctr = ctr;
1477
1478         init_buf_unistr2(&q_n->uni_srv_name, &q_n->ptr_srv_name, srv_name);
1479         init_buf_unistr2(&q_n->uni_qual_name, &q_n->ptr_qual_name, qual_name);
1480
1481         q_n->file_level    = file_level;
1482         q_n->preferred_len = preferred_len;
1483
1484         memcpy(&q_n->enum_hnd, hnd, sizeof(*hnd));
1485 }
1486
1487 /*******************************************************************
1488  Reads or writes a structure.
1489 ********************************************************************/
1490
1491 BOOL srv_io_q_net_file_enum(char *desc, SRV_Q_NET_FILE_ENUM *q_n, prs_struct *ps, int depth)
1492 {
1493         if (q_n == NULL)
1494                 return False;
1495
1496         prs_debug(ps, depth, desc, "srv_io_q_net_file_enum");
1497         depth++;
1498
1499         if(!prs_align(ps))
1500                 return False;
1501
1502         if(!prs_uint32("ptr_srv_name", ps, depth, &q_n->ptr_srv_name))
1503                 return False;
1504         if(!smb_io_unistr2("", &q_n->uni_srv_name, True, ps, depth))
1505                 return False;
1506
1507         if(!prs_align(ps))
1508                 return False;
1509
1510         if(!prs_uint32("ptr_qual_name", ps, depth, &q_n->ptr_qual_name))
1511                 return False;
1512         if(!smb_io_unistr2("", &q_n->uni_qual_name, q_n->ptr_qual_name, ps, depth))
1513                 return False;
1514
1515         if(!prs_align(ps))
1516                 return False;
1517
1518         if(!prs_uint32("file_level", ps, depth, &q_n->file_level))
1519                 return False;
1520
1521         if (q_n->file_level != -1) {
1522                 if(!srv_io_srv_file_ctr("file_ctr", q_n->ctr, ps, depth))
1523                         return False;
1524         }
1525
1526         if(!prs_uint32("preferred_len", ps, depth, &q_n->preferred_len))
1527                 return False;
1528
1529         if(!smb_io_enum_hnd("enum_hnd", &q_n->enum_hnd, ps, depth))
1530                 return False;
1531
1532         return True;
1533 }
1534
1535 /*******************************************************************
1536  Reads or writes a structure.
1537 ********************************************************************/
1538
1539 BOOL srv_io_r_net_file_enum(char *desc, SRV_R_NET_FILE_ENUM *r_n, prs_struct *ps, int depth)
1540 {
1541         if (r_n == NULL)
1542                 return False;
1543
1544         prs_debug(ps, depth, desc, "srv_io_r_net_file_enum");
1545         depth++;
1546
1547         if(!prs_align(ps))
1548                 return False;
1549
1550         if(!prs_uint32("file_level", ps, depth, &r_n->file_level))
1551                 return False;
1552
1553         if (r_n->file_level != 0) {
1554                 if(!srv_io_srv_file_ctr("file_ctr", r_n->ctr, ps, depth))
1555                         return False;
1556         }
1557
1558         if(!prs_uint32("total_entries", ps, depth, &r_n->total_entries))
1559                 return False;
1560         if(!smb_io_enum_hnd("enum_hnd", &r_n->enum_hnd, ps, depth))
1561                 return False;
1562         if(!prs_uint32("status     ", ps, depth, &r_n->status))
1563                 return False;
1564
1565         return True;
1566 }
1567
1568 /*******************************************************************
1569  Inits a SRV_INFO_101 structure.
1570  ********************************************************************/
1571
1572 void init_srv_info_101(SRV_INFO_101 *sv101, uint32 platform_id, char *name,
1573                                 uint32 ver_major, uint32 ver_minor,
1574                                 uint32 srv_type, char *comment)
1575 {
1576         DEBUG(5,("init_srv_info_101\n"));
1577
1578         sv101->platform_id  = platform_id;
1579         init_buf_unistr2(&sv101->uni_name, &sv101->ptr_name, name);
1580         sv101->ver_major    = ver_major;
1581         sv101->ver_minor    = ver_minor;
1582         sv101->srv_type     = srv_type;
1583         init_buf_unistr2(&sv101->uni_comment, &sv101->ptr_comment, comment);
1584 }
1585
1586 /*******************************************************************
1587  Reads or writes a SRV_INFO_101 structure.
1588  ********************************************************************/
1589
1590 static BOOL srv_io_info_101(char *desc, SRV_INFO_101 *sv101, prs_struct *ps, int depth)
1591 {
1592         if (sv101 == NULL)
1593                 return False;
1594
1595         prs_debug(ps, depth, desc, "srv_io_info_101");
1596         depth++;
1597
1598         if(!prs_align(ps))
1599                 return False;
1600
1601         if(!prs_uint32("platform_id ", ps, depth, &sv101->platform_id))
1602                 return False;
1603         if(!prs_uint32("ptr_name    ", ps, depth, &sv101->ptr_name))
1604                 return False;
1605         if(!prs_uint32("ver_major   ", ps, depth, &sv101->ver_major))
1606                 return False;
1607         if(!prs_uint32("ver_minor   ", ps, depth, &sv101->ver_minor))
1608                 return False;
1609         if(!prs_uint32("srv_type    ", ps, depth, &sv101->srv_type))
1610                 return False;
1611         if(!prs_uint32("ptr_comment ", ps, depth, &sv101->ptr_comment))
1612                 return False;
1613
1614         if(!prs_align(ps))
1615                 return False;
1616
1617         if(!smb_io_unistr2("uni_name    ", &sv101->uni_name, True, ps, depth))
1618                 return False;
1619         if(!smb_io_unistr2("uni_comment ", &sv101->uni_comment, True, ps, depth))
1620                 return False;
1621
1622         return True;
1623 }
1624
1625 /*******************************************************************
1626  Inits a SRV_INFO_102 structure.
1627  ********************************************************************/
1628
1629 void init_srv_info_102(SRV_INFO_102 *sv102, uint32 platform_id, char *name,
1630                                 char *comment, uint32 ver_major, uint32 ver_minor,
1631                                 uint32 srv_type, uint32 users, uint32 disc, uint32 hidden,
1632                                 uint32 announce, uint32 ann_delta, uint32 licenses,
1633                                 char *usr_path)
1634 {
1635         DEBUG(5,("init_srv_info_102\n"));
1636
1637         sv102->platform_id  = platform_id;
1638         init_buf_unistr2(&sv102->uni_name, &sv102->ptr_name, name);
1639         sv102->ver_major    = ver_major;
1640         sv102->ver_minor    = ver_minor;
1641         sv102->srv_type     = srv_type;
1642         init_buf_unistr2(&sv102->uni_comment, &sv102->ptr_comment, comment);
1643
1644         /* same as 101 up to here */
1645
1646         sv102->users        = users;
1647         sv102->disc         = disc;
1648         sv102->hidden       = hidden;
1649         sv102->announce     = announce;
1650         sv102->ann_delta    =ann_delta;
1651         sv102->licenses     = licenses;
1652         init_buf_unistr2(&sv102->uni_usr_path, &sv102->ptr_usr_path, usr_path);
1653 }
1654
1655
1656 /*******************************************************************
1657  Reads or writes a SRV_INFO_102 structure.
1658  ********************************************************************/
1659
1660 static BOOL srv_io_info_102(char *desc, SRV_INFO_102 *sv102, prs_struct *ps, int depth)
1661 {
1662         if (sv102 == NULL)
1663                 return False;
1664
1665         prs_debug(ps, depth, desc, "srv_io_info102");
1666         depth++;
1667
1668         if(!prs_align(ps))
1669                 return False;
1670
1671         if(!prs_uint32("platform_id ", ps, depth, &sv102->platform_id))
1672                 return False;
1673         if(!prs_uint32("ptr_name    ", ps, depth, &sv102->ptr_name))
1674                 return False;
1675         if(!prs_uint32("ver_major   ", ps, depth, &sv102->ver_major))
1676                 return False;
1677         if(!prs_uint32("ver_minor   ", ps, depth, &sv102->ver_minor))
1678                 return False;
1679         if(!prs_uint32("srv_type    ", ps, depth, &sv102->srv_type))
1680                 return False;
1681         if(!prs_uint32("ptr_comment ", ps, depth, &sv102->ptr_comment))
1682                 return False;
1683
1684         /* same as 101 up to here */
1685
1686         if(!prs_uint32("users       ", ps, depth, &sv102->users))
1687                 return False;
1688         if(!prs_uint32("disc        ", ps, depth, &sv102->disc))
1689                 return False;
1690         if(!prs_uint32("hidden      ", ps, depth, &sv102->hidden))
1691                 return False;
1692         if(!prs_uint32("announce    ", ps, depth, &sv102->announce))
1693                 return False;
1694         if(!prs_uint32("ann_delta   ", ps, depth, &sv102->ann_delta))
1695                 return False;
1696         if(!prs_uint32("licenses    ", ps, depth, &sv102->licenses))
1697                 return False;
1698         if(!prs_uint32("ptr_usr_path", ps, depth, &sv102->ptr_usr_path))
1699                 return False;
1700
1701         if(!smb_io_unistr2("uni_name    ", &sv102->uni_name, True, ps, depth))
1702                 return False;
1703         if(!prs_align(ps))
1704                 return False;
1705         if(!smb_io_unistr2("uni_comment ", &sv102->uni_comment, True, ps, depth))
1706                 return False;
1707         if(!prs_align(ps))
1708                 return False;
1709         if(!smb_io_unistr2("uni_usr_path", &sv102->uni_usr_path, True, ps, depth))
1710                 return False;
1711
1712         return True;
1713 }
1714
1715 /*******************************************************************
1716  Reads or writes a SRV_INFO_102 structure.
1717  ********************************************************************/
1718
1719 static BOOL srv_io_info_ctr(char *desc, SRV_INFO_CTR *ctr, prs_struct *ps, int depth)
1720 {
1721         if (ctr == NULL)
1722                 return False;
1723
1724         prs_debug(ps, depth, desc, "srv_io_info_ctr");
1725         depth++;
1726
1727         if(!prs_align(ps))
1728                 return False;
1729
1730         if(!prs_uint32("switch_value", ps, depth, &ctr->switch_value))
1731                 return False;
1732         if(!prs_uint32("ptr_srv_ctr ", ps, depth, &ctr->ptr_srv_ctr))
1733                 return False;
1734
1735         if (ctr->ptr_srv_ctr != 0 && ctr->switch_value != 0 && ctr != NULL) {
1736                 switch (ctr->switch_value) {
1737                 case 101:
1738                         if(!srv_io_info_101("sv101", &ctr->srv.sv101, ps, depth))
1739                                 return False;
1740                         break;
1741                 case 102:
1742                         if(!srv_io_info_102("sv102", &ctr->srv.sv102, ps, depth))
1743                                 return False;
1744                         break;
1745                 default:
1746                         DEBUG(5,("%s no server info at switch_value %d\n",
1747                                          tab_depth(depth), ctr->switch_value));
1748                         break;
1749                 }
1750                 if(!prs_align(ps))
1751                         return False;
1752         }
1753
1754         return True;
1755 }
1756
1757 /*******************************************************************
1758  Inits a SRV_Q_NET_SRV_GET_INFO structure.
1759  ********************************************************************/
1760
1761 void init_srv_q_net_srv_get_info(SRV_Q_NET_SRV_GET_INFO *srv,
1762                                 char *server_name, uint32 switch_value)
1763 {
1764         DEBUG(5,("init_srv_q_net_srv_get_info\n"));
1765
1766         init_buf_unistr2(&srv->uni_srv_name, &srv->ptr_srv_name, server_name);
1767
1768         srv->switch_value = switch_value;
1769 }
1770
1771 /*******************************************************************
1772  Reads or writes a structure.
1773 ********************************************************************/
1774
1775 BOOL srv_io_q_net_srv_get_info(char *desc, SRV_Q_NET_SRV_GET_INFO *q_n, prs_struct *ps, int depth)
1776 {
1777         if (q_n == NULL)
1778                 return False;
1779
1780         prs_debug(ps, depth, desc, "srv_io_q_net_srv_get_info");
1781         depth++;
1782
1783         if(!prs_align(ps))
1784                 return False;
1785
1786         if(!prs_uint32("ptr_srv_name  ", ps, depth, &q_n->ptr_srv_name))
1787                 return False;
1788         if(!smb_io_unistr2("", &q_n->uni_srv_name, True, ps, depth))
1789                 return False;
1790
1791         if(!prs_align(ps))
1792                 return False;
1793
1794         if(!prs_uint32("switch_value  ", ps, depth, &q_n->switch_value))
1795                 return False;
1796
1797         return True;
1798 }
1799
1800 /*******************************************************************
1801  Inits a SRV_R_NET_SRV_GET_INFO structure.
1802  ********************************************************************/
1803
1804 void init_srv_r_net_srv_get_info(SRV_R_NET_SRV_GET_INFO *srv,
1805                                 uint32 switch_value, SRV_INFO_CTR *ctr, uint32 status)
1806 {
1807         DEBUG(5,("init_srv_r_net_srv_get_info\n"));
1808
1809         srv->ctr = ctr;
1810
1811         if (status == 0x0) {
1812                 srv->ctr->switch_value = switch_value;
1813                 srv->ctr->ptr_srv_ctr  = 1;
1814         } else {
1815                 srv->ctr->switch_value = 0;
1816                 srv->ctr->ptr_srv_ctr  = 0;
1817         }
1818
1819         srv->status = status;
1820 }
1821
1822 /*******************************************************************
1823  Reads or writes a structure.
1824  ********************************************************************/
1825
1826 BOOL srv_io_r_net_srv_get_info(char *desc, SRV_R_NET_SRV_GET_INFO *r_n, prs_struct *ps, int depth)
1827 {
1828         if (r_n == NULL)
1829                 return False;
1830
1831         prs_debug(ps, depth, desc, "srv_io_r_net_srv_get_info");
1832         depth++;
1833
1834         if(!prs_align(ps))
1835                 return False;
1836
1837         if(!srv_io_info_ctr("ctr", r_n->ctr, ps, depth))
1838                 return False;
1839
1840         if(!prs_uint32("status      ", ps, depth, &r_n->status))
1841                 return False;
1842
1843         return True;
1844 }
1845
1846
1847 /*******************************************************************
1848  Reads or writes a structure.
1849  ********************************************************************/
1850
1851 BOOL srv_io_q_net_remote_tod(char *desc, SRV_Q_NET_REMOTE_TOD *q_n, prs_struct *ps, int depth)
1852 {
1853         if (q_n == NULL)
1854                 return False;
1855
1856         prs_debug(ps, depth, desc, "srv_io_q_net_remote_tod");
1857         depth++;
1858
1859         if(!prs_align(ps))
1860                 return False;
1861
1862         if(!prs_uint32("ptr_srv_name  ", ps, depth, &q_n->ptr_srv_name))
1863                 return False;
1864         if(!smb_io_unistr2("", &q_n->uni_srv_name, True, ps, depth))
1865                 return False;
1866
1867         return True;
1868 }
1869
1870 /*******************************************************************
1871  Reads or writes a TIME_OF_DAY_INFO structure.
1872  ********************************************************************/
1873
1874 static BOOL srv_io_time_of_day_info(char *desc, TIME_OF_DAY_INFO *tod, prs_struct *ps, int depth)
1875 {
1876         if (tod == NULL)
1877                 return False;
1878
1879         prs_debug(ps, depth, desc, "srv_io_time_of_day_info");
1880         depth++;
1881
1882         if(!prs_align(ps))
1883                 return False;
1884         
1885         if(!prs_uint32("elapsedt   ", ps, depth, &tod->elapsedt))
1886                 return False;
1887         if(!prs_uint32("msecs      ", ps, depth, &tod->msecs))
1888                 return False;
1889         if(!prs_uint32("hours      ", ps, depth, &tod->hours))
1890                 return False;
1891         if(!prs_uint32("mins       ", ps, depth, &tod->mins))
1892                 return False;
1893         if(!prs_uint32("secs       ", ps, depth, &tod->secs))
1894                 return False;
1895         if(!prs_uint32("hunds      ", ps, depth, &tod->hunds))
1896                 return False;
1897         if(!prs_uint32("timezone   ", ps, depth, &tod->zone))
1898                 return False;
1899         if(!prs_uint32("tintervals ", ps, depth, &tod->tintervals))
1900                 return False;
1901         if(!prs_uint32("day        ", ps, depth, &tod->day))
1902                 return False;
1903         if(!prs_uint32("month      ", ps, depth, &tod->month))
1904                 return False;
1905         if(!prs_uint32("year       ", ps, depth, &tod->year))
1906                 return False;
1907         if(!prs_uint32("weekday    ", ps, depth, &tod->weekday))
1908                 return False;
1909
1910         return True;
1911 }
1912
1913 /*******************************************************************
1914  Inits a TIME_OF_DAY_INFO structure.
1915  ********************************************************************/
1916
1917 void init_time_of_day_info(TIME_OF_DAY_INFO *tod, uint32 elapsedt, uint32 msecs,
1918                            uint32 hours, uint32 mins, uint32 secs, uint32 hunds,
1919                            uint32 zone, uint32 tintervals, uint32 day,
1920                            uint32 month, uint32 year, uint32 weekday)
1921 {
1922         DEBUG(5,("init_time_of_day_info\n"));
1923
1924         tod->elapsedt   = elapsedt;
1925         tod->msecs      = msecs;
1926         tod->hours      = hours;
1927         tod->mins       = mins;
1928         tod->secs       = secs;
1929         tod->hunds      = hunds;
1930         tod->zone       = zone;
1931         tod->tintervals = tintervals;
1932         tod->day        = day;
1933         tod->month      = month;
1934         tod->year       = year;
1935         tod->weekday    = weekday;
1936 }
1937
1938
1939 /*******************************************************************
1940  Reads or writes a structure.
1941  ********************************************************************/
1942
1943 BOOL srv_io_r_net_remote_tod(char *desc, SRV_R_NET_REMOTE_TOD *r_n, prs_struct *ps, int depth)
1944 {
1945         if (r_n == NULL)
1946                 return False;
1947
1948         prs_debug(ps, depth, desc, "srv_io_r_net_remote_tod");
1949         depth++;
1950
1951         if(!prs_align(ps))
1952                 return False;
1953         
1954         if(!prs_uint32("ptr_srv_tod ", ps, depth, &r_n->ptr_srv_tod))
1955                 return False;
1956
1957         if(!srv_io_time_of_day_info("tod", r_n->tod, ps, depth))
1958                 return False;
1959
1960         if(!prs_uint32("status      ", ps, depth, &r_n->status))
1961                 return False;
1962
1963         return True;
1964 }