This is a set of generic SMB client routines. I needed this in a hurry
[kai/samba.git] / source3 / srvparse.c
1 /* 
2    Unix SMB/Netbios implementation.
3    Version 1.9.
4    Samba utility functions
5    Copyright (C) Luke Leighton 1996 - 1997  Paul Ashton 1997
6    
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11    
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16    
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #include "includes.h"
23
24 extern int DEBUGLEVEL;
25
26
27 /*******************************************************************
28 reads or writes a structure.
29 ********************************************************************/
30 char* srv_io_share_info1_str(BOOL io, SH_INFO_1_STR *sh1, char *q, char *base, int align, int depth)
31 {
32         if (sh1 == NULL) return NULL;
33
34         DEBUG(5,("%s%04x srv_io_share_info1_str\n", tab_depth(depth), PTR_DIFF(q, base)));
35         depth++;
36
37         q = align_offset(q, base, align);
38
39         q = smb_io_unistr2(io, &(sh1->uni_netname), q, base, align, depth); 
40         q = smb_io_unistr2(io, &(sh1->uni_remark ), q, base, align, depth); 
41
42         return q;
43 }
44
45 /*******************************************************************
46 reads or writes a structure.
47 ********************************************************************/
48 char* srv_io_share_info1(BOOL io, SH_INFO_1 *sh1, char *q, char *base, int align, int depth)
49 {
50         if (sh1 == NULL) return NULL;
51
52         DEBUG(5,("%s%04x srv_io_share_info1\n", tab_depth(depth), PTR_DIFF(q, base)));
53         depth++;
54
55         q = align_offset(q, base, align);
56
57         DBG_RW_IVAL("ptr_netname", depth, base, io, q, sh1->ptr_netname); q += 4;
58         DBG_RW_IVAL("type       ", depth, base, io, q, sh1->type       ); q += 4;
59         DBG_RW_IVAL("ptr_remark ", depth, base, io, q, sh1->ptr_remark); q += 4;
60
61         return q;
62 }
63
64 /*******************************************************************
65 reads or writes a structure.
66 ********************************************************************/
67 char* srv_io_share_1_ctr(BOOL io, SHARE_INFO_1_CTR *ctr, char *q, char *base, int align, int depth)
68 {
69         if (ctr == NULL) return NULL;
70
71         DEBUG(5,("%s%04x srv_io_share_1_ctr\n", tab_depth(depth), PTR_DIFF(q, base)));
72         depth++;
73
74         q = align_offset(q, base, align);
75
76         DBG_RW_IVAL("num_entries_read", depth, base, io, q, ctr->num_entries_read); q += 4;
77         DBG_RW_IVAL("ptr_share_info", depth, base, io, q, ctr->ptr_share_info); q += 4;
78
79         if (ctr->ptr_share_info != 0)
80         {
81                 int i;
82                 int num_entries = ctr->num_entries_read;
83                 if (num_entries > MAX_SHARE_ENTRIES)
84                 {
85                         num_entries = MAX_SHARE_ENTRIES; /* report this! */
86                 }
87
88                 DBG_RW_IVAL("num_entries_read2", depth, base, io, q, ctr->num_entries_read2); q += 4;
89
90                 for (i = 0; i < num_entries; i++)
91                 {
92                         q = srv_io_share_info1(io, &(ctr->info_1[i]), q, base, align, depth); 
93                 }
94
95                 for (i = 0; i < num_entries; i++)
96                 {
97                         q = srv_io_share_info1_str(io, &(ctr->info_1_str[i]), q, base, align, depth); 
98                 }
99
100                 q = align_offset(q, base, align);
101                 DBG_RW_IVAL("num_entries_read3", depth, base, io, q, ctr->num_entries_read3); q += 4;
102                 DBG_RW_IVAL("padding          ", depth, base, io, q, ctr->padding); q += 4;
103         }
104
105         return q;
106 }
107
108 /*******************************************************************
109 reads or writes a structure.
110 ********************************************************************/
111 char* srv_io_q_net_share_enum(BOOL io, SRV_Q_NET_SHARE_ENUM *q_n, char *q, char *base, int align, int depth)
112 {
113         if (q_n == NULL) return NULL;
114
115         DEBUG(5,("%s%04x srv_io_q_net_share_enum\n", tab_depth(depth), PTR_DIFF(q, base)));
116         depth++;
117
118         q = align_offset(q, base, align);
119
120         DBG_RW_IVAL("ptr_srv_name", depth, base, io, q, q_n->ptr_srv_name); q += 4;
121         q = smb_io_unistr2(io, &(q_n->uni_srv_name), q, base, align, depth); 
122
123         q = align_offset(q, base, align);
124
125         DBG_RW_IVAL("share_level   ", depth, base, io, q, q_n->share_level); q += 4;
126         DBG_RW_IVAL("switch_value  ", depth, base, io, q, q_n->switch_value); q += 4;
127
128         DBG_RW_IVAL("ptr_share_info", depth, base, io, q, q_n->ptr_share_info); q += 4;
129         if (q_n->ptr_share_info != 0)
130         {
131                 switch (q_n->switch_value)
132                 {
133                         case 1:
134                         {
135                                 q = srv_io_share_1_ctr(io, &(q_n->share.info1), q, base, align, depth); 
136                                 break;
137                         }
138                         default:
139                         {
140                                 DEBUG(5,("%s% no share info at switch_value %d\n",
141                                          tab_depth(depth), q_n->switch_value));
142                                 break;
143                         }
144                 }
145         }
146         DBG_RW_IVAL("preferred_len ", depth, base, io, q, q_n->preferred_len); q += 4;
147
148         return q;
149 }
150
151 /*******************************************************************
152 reads or writes a structure.
153 ********************************************************************/
154 char* srv_io_r_net_share_enum(BOOL io, SRV_R_NET_SHARE_ENUM *r_n, char *q, char *base, int align, int depth)
155 {
156         if (r_n == NULL) return NULL;
157
158         DEBUG(5,("%s%04x srv_io_q_net_share_enum\n", tab_depth(depth), PTR_DIFF(q, base)));
159         depth++;
160
161         q = align_offset(q, base, align);
162
163         DBG_RW_IVAL("share_level   ", depth, base, io, q, r_n->share_level); q += 4;
164         DBG_RW_IVAL("switch_value  ", depth, base, io, q, r_n->switch_value); q += 4;
165
166         DBG_RW_IVAL("ptr_share_info", depth, base, io, q, r_n->ptr_share_info); q += 4;
167         if (r_n->ptr_share_info != 0)
168         {
169                 switch (r_n->switch_value)
170                 {
171                         case 1:
172                         {
173                                 q = srv_io_share_1_ctr(io, &(r_n->share.info1), q, base, align, depth); 
174                                 break;
175                         }
176                         default:
177                         {
178                                 DEBUG(5,("%s% no share info at switch_value %d\n",
179                                          tab_depth(depth), r_n->switch_value));
180                                 break;
181                         }
182                 }
183         }
184         DBG_RW_IVAL("status        ", depth, base, io, q, r_n->status); q += 4;
185
186         return q;
187 }
188
189 #if 0
190 /*******************************************************************
191 reads or writes a structure.
192 ********************************************************************/
193  char* lsa_io_(BOOL io, *, char *q, char *base, int align, int depth)
194 {
195         if (== NULL) return NULL;
196
197         q = align_offset(q, base, align);
198         
199         DBG_RW_IVAL("", depth, base, io, q, ); q += 4;
200
201         return q;
202 }
203 #endif