locking.c: Added fix for race condition in slow share mode code.
[kai/samba.git] / source3 / lsaparse.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 #if 0 /* NEED TO DO THIS TO GET A COMPILE - LUKE PLEASE CHECK THIS !!! */
28 /*******************************************************************
29 reads or writes an LSA_R_OPEN_POL structure.
30 ********************************************************************/
31 char* lsa_io_r_open_pol(BOOL io, LSA_R_OPEN_POL *r_p, char *q, char *base, int align)
32 {
33         if (r_p == NULL) return NULL;
34
35         q = smb_io_pol_hnd(io, &(r_p->pol), q, base, align);
36
37         RW_IVAL(io, q, r_p->status, 0); q += 4;
38
39         return q;
40 }
41
42 /*******************************************************************
43 reads or writes an LSA_Q_QUERY_INFO structure.
44 ********************************************************************/
45 char* lsa_io_q_query(BOOL io, LSA_Q_QUERY_INFO *q_q, char *q, char *base, int align)
46 {
47         if (q_q == NULL) return NULL;
48
49         RW_SVAL(io, q, q_q->info_class, 0); q += 2;
50
51         return q;
52 }
53
54 /*******************************************************************
55 reads or writes an LSA_Q_QUERY_INFO structure.
56 ********************************************************************/
57 char* lsa_io_r_query(BOOL io, LSA_R_QUERY_INFO *r_q, char *q, char *base, int align)
58 {
59         if (r_q == NULL) return NULL;
60
61         RW_IVAL(io, q, r_q->undoc_buffer, 0); q += 4;
62
63         if (r_q->undoc_buffer != 0)
64         {
65                 RW_SVAL(io, q, r_q->info_class, 0); q += 2;
66
67                 switch (r_q->info_class)
68                 {
69                         case 3:
70                         {
71                                 q = smb_io_dom_query_3(io, &(r_q->dom.id3), q, base, align);
72                                 break;
73                         }
74                         case 5:
75                         {
76                                 q = smb_io_dom_query_5(io, &(r_q->dom.id3), q, base, align);
77                                 break;
78                         }
79                         default:
80                         {
81                                 /* PANIC! */
82                                 break;
83                         }
84                 }
85         }
86
87         RW_IVAL(io, q, r_q->status, 0); q += 4;
88
89         return q;
90 }
91
92 /*******************************************************************
93 reads or writes a structure.
94 ********************************************************************/
95 char* lsa_io_q_lookup_sids(BOOL io, LSA_Q_LOOKUP_SIDS *q_s, char *q, char *base, int align)
96 {
97         int i;
98
99         if (q_s == NULL) return NULL;
100
101         q = align_offset(q, base, align);
102         
103     q = smb_io_pol_hnd(io, &(q_s->pol_hnd), q, base, align); /* policy handle */
104
105         RW_IVAL(io, q, q_s->num_entries, 0); q += 4;
106         RW_IVAL(io, q, q_s->buffer_dom_sid, 0); q += 4; /* undocumented domain SID buffer pointer */
107         RW_IVAL(io, q, q_s->buffer_dom_name, 0); q += 4; /* undocumented domain name buffer pointer */
108
109         for (i = 0; i < q_s->num_entries; i++)
110         {
111                 RW_IVAL(io, q, q_s->buffer_lookup_sids[i], 0); q += 4; /* undocumented domain SID pointers to be looked up. */
112         }
113
114         for (i = 0; i < q_s->num_entries; i++)
115         {
116                 q = smb_io_dom_sid(io, &(q_s->dom_sids[i]), q, base, align); /* domain SIDs to be looked up. */
117         }
118
119         RW_PCVAL(io, q, q_s->undoc, 16); q += 16; /* completely undocumented 16 bytes */
120
121         return q;
122 }
123
124 /*******************************************************************
125 reads or writes a structure.
126 ********************************************************************/
127 char* lsa_io_r_lookup_sids(BOOL io, LSA_R_LOOKUP_SIDS *r_s, char *q, char *base, int align)
128 {
129         int i;
130
131         if (r_s == NULL) return NULL;
132
133         q = align_offset(q, base, align);
134         
135         q = smb_io_dom_r_ref(io, &(r_s->dom_ref), q, base, align); /* domain reference info */
136
137         RW_IVAL(io, q, r_s->num_entries, 0); q += 4;
138         RW_IVAL(io, q, r_s->undoc_buffer, 0); q += 4;
139         RW_IVAL(io, q, r_s->num_entries2, 0); q += 4;
140
141         for (i = 0; i < r_s->num_entries2; i++)
142         {
143                 q = smb_io_dom_sid2(io, &(r_s->dom_sid[i]), q, base, align); /* domain SIDs being looked up */
144         }
145
146         RW_IVAL(io, q, r_s->num_entries3, 0); q += 4;
147
148         RW_IVAL(io, q, r_s->status, 0); q += 4;
149
150         return q;
151 }
152
153 /*******************************************************************
154 reads or writes a structure.
155 ********************************************************************/
156 char* lsa_io_q_lookup_rids(BOOL io, LSA_Q_LOOKUP_RIDS *q_r, char *q, char *base, int align)
157 {
158         int i;
159
160         if (q_r == NULL) return NULL;
161
162         q = align_offset(q, base, align);
163         
164     q = smb_io_pol_hnd(io, &(q_r->pol_hnd), q, base, align); /* policy handle */
165
166         RW_IVAL(io, q, q_r->num_entries, 0); q += 4;
167         RW_IVAL(io, q, q_r->num_entries2, 0); q += 4;
168         RW_IVAL(io, q, q_r->buffer_dom_sid, 0); q += 4; /* undocumented domain SID buffer pointer */
169         RW_IVAL(io, q, q_r->buffer_dom_name, 0); q += 4; /* undocumented domain name buffer pointer */
170
171         for (i = 0; i < q_r->num_entries; i++)
172         {
173                 q = smb_io_dom_name(io, &(q_r->lookup_name[i]), q, base, 0); /* names to be looked up */
174         }
175
176         RW_PCVAL(io, q, q_r->undoc, UNKNOWN_LEN); q += UNKNOWN_LEN; /* completely undocumented bytes of unknown length */
177
178         return q;
179 }
180
181 /*******************************************************************
182 reads or writes a structure.
183 ********************************************************************/
184 char* lsa_io_r_lookup_rids(BOOL io, LSA_R_LOOKUP_RIDS *r_r, char *q, char *base, int align)
185 {
186         int i;
187
188         if (r_r == NULL) return NULL;
189
190         q = align_offset(q, base, align);
191         
192         q = smb_io_dom_r_ref(io, &(r_r->dom_ref), q, base, align); /* domain reference info */
193
194         RW_IVAL(io, q, r_r->num_entries, 0); q += 4;
195         RW_IVAL(io, q, r_r->undoc_buffer, 0); q += 4;
196         RW_IVAL(io, q, r_r->num_entries2, 0); q += 4;
197
198         for (i = 0; i < r_r->num_entries2; i++)
199         {
200                 q = smb_io_dom_rid2(io, &(r_r->dom_rid[i]), q, base, align); /* domain RIDs being looked up */
201         }
202
203         RW_IVAL(io, q, r_r->num_entries3, 0); q += 4;
204
205         RW_IVAL(io, q, r_r->status, 0); q += 4;
206
207         return q;
208 }
209
210 /*******************************************************************
211 reads or writes a structure.
212 ********************************************************************/
213 char* lsa_io_q_req_chal(BOOL io, LSA_Q_REQ_CHAL *q_c, char *q, char *base, int align)
214 {
215         if (q_c == NULL) return NULL;
216
217         q = align_offset(q, base, align);
218     
219         q = smb_io_unistr2(io, &(q_c->uni_logon_srv), q, base, align); /* logon server unicode string */
220         q = smb_io_unistr2(io, &(q_c->uni_logon_clnt), q, base, align); /* logon client unicode string */
221         q = smb_io_chal(io, &(q_c->clnt_chal), q, base, align); /* client challenge */
222
223         return q;
224 }
225
226 /*******************************************************************
227 reads or writes a structure.
228 ********************************************************************/
229 char* lsa_io_r_req_chal(BOOL io, LSA_R_REQ_CHAL *r_c, char *q, char *base, int align)
230 {
231         if (r_c == NULL) return NULL;
232
233         q = align_offset(q, base, align);
234     
235         q = smb_io_chal(io, &(r_c->srv_chal), q, base, align); /* server challenge */
236
237         RW_IVAL(io, q, r_c->status, 0); q += 4;
238
239         return q;
240 }
241
242
243 /*******************************************************************
244 reads or writes a structure.
245 ********************************************************************/
246 char* lsa_io_q_auth2(BOOL io, LSA_Q_AUTH_2 *q_a, char *q, char *base, int align)
247 {
248         if (q_a == NULL) return NULL;
249
250         q = align_offset(q, base, align);
251     
252         q = smb_io_log_info (io, &(q_a->clnt_id), q, base, align); /* client identification info */
253         q = smb_io_chal     (io, &(q_a->clnt_chal), q, base, align); /* client-calculated credentials */
254         q = smb_io_neg_flags(io, &(q_a->clnt_flgs), q, base, align);
255
256         return q;
257 }
258
259 /*******************************************************************
260 reads or writes a structure.
261 ********************************************************************/
262 char* lsa_io_r_auth_2(BOOL io, LSA_R_AUTH_2 *r_a, char *q, char *base, int align)
263 {
264         if (r_a == NULL) return NULL;
265
266         q = align_offset(q, base, align);
267     
268         q = smb_io_chal     (io, &(r_a->srv_chal), q, base, align); /* server challenge */
269         q = smb_io_neg_flags(io, &(r_a->srv_flgs), q, base, align);
270
271         RW_IVAL(io, q, r_a->status, 0); q += 4;
272
273         return q;
274 }
275
276
277 /*******************************************************************
278 reads or writes a structure.
279 ********************************************************************/
280 char* lsa_io_q_srv_pwset(BOOL io, LSA_Q_SRV_PWSET *q_s, char *q, char *base, int align)
281 {
282         if (q_s == NULL) return NULL;
283
284         q = align_offset(q, base, align);
285     
286         q = smb_io_clnt_info(io, &(q_s->clnt_id), q, base, align); /* client identification/authentication info */
287         RW_PCVAL(io, q, q_s->pwd, 16); q += 16; /* new password - undocumented */
288
289         return q;
290 }
291
292 /*******************************************************************
293 reads or writes a structure.
294 ********************************************************************/
295 char* lsa_io_r_srv_pwset(BOOL io, LSA_R_SRV_PWSET *r_s, char *q, char *base, int align)
296 {
297         if (r_s == NULL) return NULL;
298
299         q = align_offset(q, base, align);
300     
301         q = smb_io_chal(io, &(r_s->srv_chal), q, base, align); /* server challenge */
302
303         RW_IVAL(io, q, r_s->status, 0); q += 4;
304
305         return q;
306 }
307
308 /* LSA_USER_INFO */
309
310 /*******************************************************************
311 reads or writes a structure.
312 ********************************************************************/
313 char* lsa_io_user_info(BOOL io, LSA_USER_INFO *usr, char *q, char *base, int align)
314 {
315         int i;
316
317         if (usr == NULL) return NULL;
318
319         q = align_offset(q, base, align);
320         
321         RW_IVAL(io, q, usr->undoc_buffer, 0); q += 4;
322
323         q = smb_io_time(io, &(usr->logon_time)           , q, base, align); /* logon time */
324         q = smb_io_time(io, &(usr->logoff_time)          , q, base, align); /* logoff time */
325         q = smb_io_time(io, &(usr->kickoff_time)         , q, base, align); /* kickoff time */
326         q = smb_io_time(io, &(usr->pass_last_set_time)   , q, base, align); /* password last set time */
327         q = smb_io_time(io, &(usr->pass_can_change_time) , q, base, align); /* password can change time */
328         q = smb_io_time(io, &(usr->pass_must_change_time), q, base, align); /* password must change time */
329
330         q = smb_io_unihdr(io, &(usr->hdr_user_name)   , q, base, align); /* username unicode string header */
331         q = smb_io_unihdr(io, &(usr->hdr_full_name)   , q, base, align); /* user's full name unicode string header */
332         q = smb_io_unihdr(io, &(usr->hdr_logon_script), q, base, align); /* logon script unicode string header */
333         q = smb_io_unihdr(io, &(usr->hdr_profile_path), q, base, align); /* profile path unicode string header */
334         q = smb_io_unihdr(io, &(usr->hdr_home_dir)    , q, base, align); /* home directory unicode string header */
335         q = smb_io_unihdr(io, &(usr->hdr_dir_drive)   , q, base, align); /* home directory drive unicode string header */
336
337         RW_SVAL(io, q, usr->logon_count , 0); q += 2;  /* logon count */
338         RW_SVAL(io, q, usr->bad_pw_count, 0); q += 2; /* bad password count */
339
340         RW_IVAL(io, q, usr->user_id      , 0); q += 4;       /* User ID */
341         RW_IVAL(io, q, usr->group_id     , 0); q += 4;      /* Group ID */
342         RW_IVAL(io, q, usr->num_groups   , 0); q += 4;    /* num groups */
343         RW_IVAL(io, q, usr->buffer_groups, 0); q += 4; /* undocumented buffer pointer to groups. */
344         RW_IVAL(io, q, usr->user_flgs    , 0); q += 4;     /* user flags */
345
346         RW_PCVAL(io, q, usr->sess_key, 16); q += 16; /* unused user session key */
347
348         q = smb_io_unihdr(io, &(usr->hdr_logon_srv), q, base, align); /* logon server unicode string header */
349         q = smb_io_unihdr(io, &(usr->hdr_logon_dom), q, base, align); /* logon domain unicode string header */
350
351         RW_IVAL(io, q, usr->buffer_dom_id, 0); q += 4; /* undocumented logon domain id pointer */
352         RW_PCVAL(io, q, usr->padding, 40); q += 40; /* unused padding bytes? */
353
354         RW_IVAL(io, q, usr->num_sids, 0); q += 4; /* 0 - num_sids */
355         RW_IVAL(io, q, usr->buffer_sids, 0); q += 4; /* NULL - undocumented pointer to SIDs. */
356         
357         q = smb_io_unistr2(io, &(usr->uni_user_name)   , q, base, align); /* username unicode string */
358         q = smb_io_unistr2(io, &(usr->uni_full_name)   , q, base, align); /* user's full name unicode string */
359         q = smb_io_unistr2(io, &(usr->uni_logon_script), q, base, align); /* logon script unicode string */
360         q = smb_io_unistr2(io, &(usr->uni_profile_path), q, base, align); /* profile path unicode string */
361         q = smb_io_unistr2(io, &(usr->uni_home_dir)    , q, base, align); /* home directory unicode string */
362         q = smb_io_unistr2(io, &(usr->uni_dir_drive)   , q, base, align); /* home directory drive unicode string */
363
364         RW_IVAL(io, q, usr->num_groups2, 0); q += 4;        /* num groups */
365         for (i = 0; i < usr->num_groups2; i++)
366         {
367                 q = smb_io_gid(io, &(usr->gids[i]), q, base, align); /* group info */
368         }
369
370         q = smb_io_unistr2(io, &( usr->uni_logon_srv), q, base, align); /* logon server unicode string */
371         q = smb_io_unistr2(io, &( usr->uni_logon_dom), q, base, align); /* logon domain unicode string */
372
373         q = smb_io_dom_sid(io, &(usr->undoc_dom_sids[0]), q, base, align); /* undocumented - domain SIDs */
374         q = smb_io_dom_sid(io, &(usr->undoc_dom_sids[1]), q, base, align); /* undocumented - domain SIDs */
375         q = smb_io_dom_sid(io, &(usr->dom_sid), q, base, align);           /* domain SID */
376
377         return q;
378 }
379
380 /*******************************************************************
381 reads or writes a structure.
382 ********************************************************************/
383 char* lsa_io_q_sam_logon(BOOL io, LSA_Q_SAM_LOGON *q_l, char *q, char *base, int align)
384 {
385         if (q_l == NULL) return NULL;
386
387         q = align_offset(q, base, align);
388         
389         q = smb_io_sam_info(io, &(q_l->sam_id), q, base, align);           /* domain SID */
390
391         return q;
392 }
393
394 /*******************************************************************
395 reads or writes a structure.
396 ********************************************************************/
397 char* lsa_io_r_sam_logon(BOOL io, LSA_R_SAM_LOGON *r_l, char *q, char *base, int align)
398 {
399         if (r_l == NULL) return NULL;
400
401         q = align_offset(q, base, align);
402         
403         RW_IVAL(io, q, r_l->buffer_creds, 0); q += 4; /* undocumented buffer pointer */
404         q = smb_io_cred(io, &(r_l->srv_creds), q, base, align); /* server credentials.  server time stamp appears to be ignored. */
405
406         RW_IVAL(io, q, r_l->buffer_user, 0); q += 4;
407         if (r_l->buffer_user != 0)
408         {
409                 q = lsa_io_user_info(io, r_l->user, q, base, align);
410         }
411
412         RW_IVAL(io, q, r_l->auth_resp, 0); q += 4; /* 1 - Authoritative response; 0 - Non-Auth? */
413
414         RW_IVAL(io, q, r_l->status, 0); q += 4;
415
416         return q;
417 }
418
419 /*******************************************************************
420 reads or writes a structure.
421 ********************************************************************/
422 char* lsa_io_q_sam_logoff(BOOL io, LSA_Q_SAM_LOGOFF *q_l, char *q, char *base, int align)
423 {
424         if (q_l == NULL) return NULL;
425
426         q = align_offset(q, base, align);
427         
428         q = smb_io_sam_info(io, &(q_l->sam_id), q, base, align);           /* domain SID */
429
430         return q;
431 }
432
433 /*******************************************************************
434 reads or writes a structure.
435 ********************************************************************/
436 char* lsa_io_r_sam_logoff(BOOL io, LSA_R_SAM_LOGOFF *r_l, char *q, char *base, int align)
437 {
438         if (r_l == NULL) return NULL;
439
440         q = align_offset(q, base, align);
441         
442         RW_IVAL(io, q, r_l->buffer_creds, 0); q += 4; /* undocumented buffer pointer */
443         q = smb_io_cred(io, &(r_l->srv_creds), q, base, align); /* server credentials.  server time stamp appears to be ignored. */
444
445         RW_IVAL(io, q, r_l->status, 0); q += 4;
446
447         return q;
448 }
449
450 #endif /* 0 LUKE PLEASE CHECK !! */
451 #if 0
452 /*******************************************************************
453 reads or writes a structure.
454 ********************************************************************/
455  char* lsa_io_(BOOL io, *, char *q, char *base, int align)
456 {
457         if (== NULL) return NULL;
458
459         q = align_offset(q, base, align);
460         
461         RW_IVAL(io, q, , 0); q += 4;
462
463         return q;
464 }
465 #endif
466
467