2 Unix SMB/Netbios implementation.
4 Samba utility functions
5 Copyright (C) Luke Leighton 1996 - 1997 Paul Ashton 1997
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.
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.
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.
24 extern int DEBUGLEVEL;
27 /*******************************************************************
28 reads or writes an LSA_R_OPEN_POL structure.
29 ********************************************************************/
30 char* lsa_io_r_open_pol(BOOL io, LSA_R_OPEN_POL *r_p, char *q, char *base, int align, int depth)
32 if (r_p == NULL) return NULL;
34 DEBUG(5,("%slsa_io_r_open_pol\n", tab_depth(depth)));
37 q = smb_io_pol_hnd(io, &(r_p->pol), q, base, align);
39 DBG_RW_IVAL("status", depth, base, io, q, r_p->status); q += 4;
44 /*******************************************************************
45 reads or writes an LSA_Q_QUERY_INFO structure.
46 ********************************************************************/
47 char* lsa_io_q_query(BOOL io, LSA_Q_QUERY_INFO *q_q, char *q, char *base, int align, int depth)
49 if (q_q == NULL) return NULL;
51 DEBUG(5,("%s%04x lsa_io_q_query\n", tab_depth(depth), PTR_DIFF(q, base)));
54 q = smb_io_pol_hnd(io, &(q_q->pol), q, base, align);
56 DBG_RW_SVAL("info_class", depth, base, io, q, q_q->info_class); q += 2;
61 /*******************************************************************
62 reads or writes an LSA_Q_QUERY_INFO structure.
63 ********************************************************************/
64 char* lsa_io_r_query(BOOL io, LSA_R_QUERY_INFO *r_q, char *q, char *base, int align, int depth)
66 if (r_q == NULL) return NULL;
68 DEBUG(5,("%s%04x lsa_io_r_query\n", tab_depth(depth), PTR_DIFF(q, base)));
71 DBG_RW_IVAL("undoc_buffer", depth, base, io, q, r_q->undoc_buffer); q += 4;
73 if (r_q->undoc_buffer != 0)
75 DBG_RW_SVAL("info_class", depth, base, io, q, r_q->info_class); q += 2;
77 switch (r_q->info_class)
81 q = smb_io_dom_query_3(io, &(r_q->dom.id3), q, base, align);
86 q = smb_io_dom_query_5(io, &(r_q->dom.id3), q, base, align);
97 DBG_RW_IVAL("status", depth, base, io, q, r_q->status); q += 4;
102 /*******************************************************************
103 reads or writes a structure.
104 ********************************************************************/
105 char* lsa_io_q_lookup_sids(BOOL io, LSA_Q_LOOKUP_SIDS *q_s, char *q, char *base, int align, int depth)
109 if (q_s == NULL) return NULL;
111 DEBUG(5,("%s%04x lsa_io_q_lookup_sids\n", tab_depth(depth), PTR_DIFF(q, base)));
114 q = align_offset(q, base, align);
116 q = smb_io_pol_hnd(io, &(q_s->pol_hnd), q, base, align); /* policy handle */
118 DBG_RW_IVAL("num_entries", depth, base, io, q, q_s->num_entries); q += 4;
119 DBG_RW_IVAL("buffer_dom_sid", depth, base, io, q, q_s->buffer_dom_sid); q += 4; /* undocumented domain SID buffer pointer */
120 DBG_RW_IVAL("buffer_dom_name", depth, base, io, q, q_s->buffer_dom_name); q += 4; /* undocumented domain name buffer pointer */
122 for (i = 0; i < q_s->num_entries; i++)
125 sprintf(temp, "buffer_lookup_sids[%d]", i);
126 DBG_RW_IVAL(temp, depth, base, io, q, q_s->buffer_lookup_sids[i]); q += 4; /* undocumented domain SID pointers to be looked up. */
129 for (i = 0; i < q_s->num_entries; i++)
131 q = smb_io_dom_sid(io, &(q_s->dom_sids[i]), q, base, align); /* domain SIDs to be looked up. */
134 DBG_RW_PCVAL("undoc", depth, base, io, q, q_s->undoc, 16); q += 16; /* completely undocumented 16 bytes */
139 /*******************************************************************
140 reads or writes a structure.
141 ********************************************************************/
142 char* lsa_io_r_lookup_sids(BOOL io, LSA_R_LOOKUP_SIDS *r_s, char *q, char *base, int align, int depth)
146 if (r_s == NULL) return NULL;
148 DEBUG(5,("%s%04x lsa_io_r_lookup_sids\n", tab_depth(depth), PTR_DIFF(q, base)));
151 q = align_offset(q, base, align);
153 q = smb_io_dom_r_ref(io, &(r_s->dom_ref), q, base, align); /* domain reference info */
155 DBG_RW_IVAL("num_entries", depth, base, io, q, r_s->num_entries); q += 4;
156 DBG_RW_IVAL("undoc_buffer", depth, base, io, q, r_s->undoc_buffer); q += 4;
157 DBG_RW_IVAL("num_entries2", depth, base, io, q, r_s->num_entries2); q += 4;
159 for (i = 0; i < r_s->num_entries2; i++)
161 q = smb_io_dom_sid2(io, &(r_s->dom_sid[i]), q, base, align); /* domain SIDs being looked up */
164 DBG_RW_IVAL("num_entries3", depth, base, io, q, r_s->num_entries3); q += 4;
166 DBG_RW_IVAL("status", depth, base, io, q, r_s->status); q += 4;
171 /*******************************************************************
172 reads or writes a structure.
173 ********************************************************************/
174 char* lsa_io_q_lookup_rids(BOOL io, LSA_Q_LOOKUP_RIDS *q_r, char *q, char *base, int align, int depth)
178 if (q_r == NULL) return NULL;
180 DEBUG(5,("%s%04x lsa_io_q_lookup_rids\n", tab_depth(depth), PTR_DIFF(q, base)));
183 q = align_offset(q, base, align);
185 q = smb_io_pol_hnd(io, &(q_r->pol_hnd), q, base, align); /* policy handle */
187 DBG_RW_IVAL("num_entries", depth, base, io, q, q_r->num_entries); q += 4;
188 DBG_RW_IVAL("num_entries2", depth, base, io, q, q_r->num_entries2); q += 4;
189 DBG_RW_IVAL("buffer_dom_sid", depth, base, io, q, q_r->buffer_dom_sid); q += 4; /* undocumented domain SID buffer pointer */
190 DBG_RW_IVAL("buffer_dom_name", depth, base, io, q, q_r->buffer_dom_name); q += 4; /* undocumented domain name buffer pointer */
192 for (i = 0; i < q_r->num_entries; i++)
194 q = smb_io_dom_name(io, &(q_r->lookup_name[i]), q, base, 0); /* names to be looked up */
197 DBG_RW_PCVAL("undoc", depth, base, io, q, q_r->undoc, UNKNOWN_LEN); q += UNKNOWN_LEN; /* completely undocumented bytes of unknown length */
202 /*******************************************************************
203 reads or writes a structure.
204 ********************************************************************/
205 char* lsa_io_r_lookup_rids(BOOL io, LSA_R_LOOKUP_RIDS *r_r, char *q, char *base, int align, int depth)
209 if (r_r == NULL) return NULL;
211 DEBUG(5,("%s%04x lsa_io_r_lookup_rids\n", tab_depth(depth), PTR_DIFF(q, base)));
214 q = align_offset(q, base, align);
216 q = smb_io_dom_r_ref(io, &(r_r->dom_ref), q, base, align); /* domain reference info */
218 DBG_RW_IVAL("num_entries", depth, base, io, q, r_r->num_entries); q += 4;
219 DBG_RW_IVAL("undoc_buffer", depth, base, io, q, r_r->undoc_buffer); q += 4;
220 DBG_RW_IVAL("num_entries2", depth, base, io, q, r_r->num_entries2); q += 4;
222 for (i = 0; i < r_r->num_entries2; i++)
224 q = smb_io_dom_rid2(io, &(r_r->dom_rid[i]), q, base, align); /* domain RIDs being looked up */
227 DBG_RW_IVAL("num_entries3", depth, base, io, q, r_r->num_entries3); q += 4;
229 DBG_RW_IVAL("status", depth, base, io, q, r_r->status); q += 4;
234 /*******************************************************************
235 reads or writes a structure.
236 ********************************************************************/
237 char* lsa_io_q_req_chal(BOOL io, LSA_Q_REQ_CHAL *q_c, char *q, char *base, int align, int depth)
239 if (q_c == NULL) return NULL;
241 DEBUG(5,("%s%04x lsa_io_q_req_chal\n", tab_depth(depth), PTR_DIFF(q, base)));
244 q = align_offset(q, base, align);
246 q = smb_io_unistr2(io, &(q_c->uni_logon_srv), q, base, align); /* logon server unicode string */
247 q = smb_io_unistr2(io, &(q_c->uni_logon_clnt), q, base, align); /* logon client unicode string */
248 q = smb_io_chal(io, &(q_c->clnt_chal), q, base, align); /* client challenge */
253 /*******************************************************************
254 reads or writes a structure.
255 ********************************************************************/
256 char* lsa_io_r_req_chal(BOOL io, LSA_R_REQ_CHAL *r_c, char *q, char *base, int align, int depth)
258 if (r_c == NULL) return NULL;
260 DEBUG(5,("%s%04x lsa_io_r_req_chal\n", tab_depth(depth), PTR_DIFF(q, base)));
263 q = align_offset(q, base, align);
265 q = smb_io_chal(io, &(r_c->srv_chal), q, base, align); /* server challenge */
267 DBG_RW_IVAL("status", depth, base, io, q, r_c->status); q += 4;
273 /*******************************************************************
274 reads or writes a structure.
275 ********************************************************************/
276 char* lsa_io_q_auth_2(BOOL io, LSA_Q_AUTH_2 *q_a, char *q, char *base, int align, int depth)
278 if (q_a == NULL) return NULL;
280 DEBUG(5,("%s%04x lsa_io_q_auth_2\n", tab_depth(depth), PTR_DIFF(q, base)));
283 q = align_offset(q, base, align);
285 q = smb_io_log_info (io, &(q_a->clnt_id), q, base, align); /* client identification info */
286 q = smb_io_chal (io, &(q_a->clnt_chal), q, base, align); /* client-calculated credentials */
287 q = smb_io_neg_flags(io, &(q_a->clnt_flgs), q, base, align);
292 /*******************************************************************
293 reads or writes a structure.
294 ********************************************************************/
295 char* lsa_io_r_auth_2(BOOL io, LSA_R_AUTH_2 *r_a, char *q, char *base, int align, int depth)
297 if (r_a == NULL) return NULL;
299 DEBUG(5,("%s%04x lsa_io_r_auth_2\n", tab_depth(depth), PTR_DIFF(q, base)));
302 q = align_offset(q, base, align);
304 q = smb_io_chal (io, &(r_a->srv_chal), q, base, align); /* server challenge */
305 q = smb_io_neg_flags(io, &(r_a->srv_flgs), q, base, align);
307 DBG_RW_IVAL("status", depth, base, io, q, r_a->status); q += 4;
313 /*******************************************************************
314 reads or writes a structure.
315 ********************************************************************/
316 char* lsa_io_q_srv_pwset(BOOL io, LSA_Q_SRV_PWSET *q_s, char *q, char *base, int align, int depth)
318 if (q_s == NULL) return NULL;
320 DEBUG(5,("%s%04x lsa_io_q_srv_pwset\n", tab_depth(depth), PTR_DIFF(q, base)));
323 q = align_offset(q, base, align);
325 q = smb_io_clnt_info(io, &(q_s->clnt_id), q, base, align); /* client identification/authentication info */
326 DBG_RW_PCVAL("pwd", depth, base, io, q, q_s->pwd, 16); q += 16; /* new password - undocumented */
331 /*******************************************************************
332 reads or writes a structure.
333 ********************************************************************/
334 char* lsa_io_r_srv_pwset(BOOL io, LSA_R_SRV_PWSET *r_s, char *q, char *base, int align, int depth)
336 if (r_s == NULL) return NULL;
338 DEBUG(5,("%s%04x lsa_io_r_srv_pwset\n", tab_depth(depth), PTR_DIFF(q, base)));
341 q = align_offset(q, base, align);
343 q = smb_io_cred(io, &(r_s->srv_cred), q, base, align); /* server challenge */
345 DBG_RW_IVAL("status", depth, base, io, q, r_s->status); q += 4;
352 /*******************************************************************
353 reads or writes a structure.
354 ********************************************************************/
355 char* lsa_io_user_info(BOOL io, LSA_USER_INFO *usr, char *q, char *base, int align, int depth)
359 if (usr == NULL) return NULL;
361 DEBUG(5,("%s%04x lsa_io_user_info\n", tab_depth(depth), PTR_DIFF(q, base)));
364 q = align_offset(q, base, align);
366 DBG_RW_IVAL("", depth, base, io, q, usr->undoc_buffer); q += 4;
368 q = smb_io_time(io, &(usr->logon_time) , q, base, align); /* logon time */
369 q = smb_io_time(io, &(usr->logoff_time) , q, base, align); /* logoff time */
370 q = smb_io_time(io, &(usr->kickoff_time) , q, base, align); /* kickoff time */
371 q = smb_io_time(io, &(usr->pass_last_set_time) , q, base, align); /* password last set time */
372 q = smb_io_time(io, &(usr->pass_can_change_time) , q, base, align); /* password can change time */
373 q = smb_io_time(io, &(usr->pass_must_change_time), q, base, align); /* password must change time */
375 q = smb_io_unihdr(io, &(usr->hdr_user_name) , q, base, align); /* username unicode string header */
376 q = smb_io_unihdr(io, &(usr->hdr_full_name) , q, base, align); /* user's full name unicode string header */
377 q = smb_io_unihdr(io, &(usr->hdr_logon_script), q, base, align); /* logon script unicode string header */
378 q = smb_io_unihdr(io, &(usr->hdr_profile_path), q, base, align); /* profile path unicode string header */
379 q = smb_io_unihdr(io, &(usr->hdr_home_dir) , q, base, align); /* home directory unicode string header */
380 q = smb_io_unihdr(io, &(usr->hdr_dir_drive) , q, base, align); /* home directory drive unicode string header */
382 DBG_RW_SVAL("logon_count", depth, base, io, q, usr->logon_count ); q += 2; /* logon count */
383 DBG_RW_SVAL("bad_pw_count", depth, base, io, q, usr->bad_pw_count); q += 2; /* bad password count */
385 DBG_RW_IVAL("user_id", depth, base, io, q, usr->user_id ); q += 4; /* User ID */
386 DBG_RW_IVAL("group_id", depth, base, io, q, usr->group_id ); q += 4; /* Group ID */
387 DBG_RW_IVAL("num_groups", depth, base, io, q, usr->num_groups ); q += 4; /* num groups */
388 DBG_RW_IVAL("buffer_groups", depth, base, io, q, usr->buffer_groups); q += 4; /* undocumented buffer pointer to groups. */
389 DBG_RW_IVAL("user_flgs", depth, base, io, q, usr->user_flgs ); q += 4; /* user flags */
391 DBG_RW_PCVAL("", depth, base, io, q, usr->sess_key, 16); q += 16; /* unused user session key */
393 q = smb_io_unihdr(io, &(usr->hdr_logon_srv), q, base, align); /* logon server unicode string header */
394 q = smb_io_unihdr(io, &(usr->hdr_logon_dom), q, base, align); /* logon domain unicode string header */
396 DBG_RW_IVAL("buffer_dom_id", depth, base, io, q, usr->buffer_dom_id); q += 4; /* undocumented logon domain id pointer */
397 DBG_RW_PCVAL("padding", depth, base, io, q, usr->padding, 40); q += 40; /* unused padding bytes? */
399 DBG_RW_IVAL("num_other_sids", depth, base, io, q, usr->num_other_sids); q += 4; /* 0 - num_sids */
400 DBG_RW_IVAL("buffer_other_sids", depth, base, io, q, usr->buffer_other_sids); q += 4; /* NULL - undocumented pointer to SIDs. */
402 q = smb_io_unistr2(io, &(usr->uni_user_name) , q, base, align); /* username unicode string */
403 q = smb_io_unistr2(io, &(usr->uni_full_name) , q, base, align); /* user's full name unicode string */
404 q = smb_io_unistr2(io, &(usr->uni_logon_script), q, base, align); /* logon script unicode string */
405 q = smb_io_unistr2(io, &(usr->uni_profile_path), q, base, align); /* profile path unicode string */
406 q = smb_io_unistr2(io, &(usr->uni_home_dir) , q, base, align); /* home directory unicode string */
407 q = smb_io_unistr2(io, &(usr->uni_dir_drive) , q, base, align); /* home directory drive unicode string */
409 DBG_RW_IVAL("num_groups2", depth, base, io, q, usr->num_groups2); q += 4; /* num groups */
410 for (i = 0; i < usr->num_groups2; i++)
412 q = smb_io_gid(io, &(usr->gids[i]), q, base, align); /* group info */
415 q = smb_io_unistr2(io, &( usr->uni_logon_srv), q, base, align); /* logon server unicode string */
416 q = smb_io_unistr2(io, &( usr->uni_logon_dom), q, base, align); /* logon domain unicode string */
418 q = smb_io_dom_sid(io, &(usr->dom_sid), q, base, align); /* domain SID */
420 for (i = 0; i < usr->num_other_sids; i++)
422 q = smb_io_dom_sid(io, &(usr->other_sids[i]), q, base, align); /* other domain SIDs */
428 /*******************************************************************
429 reads or writes a structure.
430 ********************************************************************/
431 char* lsa_io_q_sam_logon(BOOL io, LSA_Q_SAM_LOGON *q_l, char *q, char *base, int align, int depth)
433 if (q_l == NULL) return NULL;
435 DEBUG(5,("%s%04x lsa_io_q_sam_logon\n", tab_depth(depth), PTR_DIFF(q, base)));
438 q = align_offset(q, base, align);
440 q = smb_io_sam_info(io, &(q_l->sam_id), q, base, align); /* domain SID */
445 /*******************************************************************
446 reads or writes a structure.
447 ********************************************************************/
448 char* lsa_io_r_sam_logon(BOOL io, LSA_R_SAM_LOGON *r_l, char *q, char *base, int align, int depth)
450 if (r_l == NULL) return NULL;
452 DEBUG(5,("%s%04x lsa_io_r_sam_logon\n", tab_depth(depth), PTR_DIFF(q, base)));
455 q = align_offset(q, base, align);
457 DBG_RW_IVAL("buffer_creds", depth, base, io, q, r_l->buffer_creds); q += 4; /* undocumented buffer pointer */
458 q = smb_io_cred(io, &(r_l->srv_creds), q, base, align); /* server credentials. server time stamp appears to be ignored. */
460 DBG_RW_IVAL("buffer_user", depth, base, io, q, r_l->buffer_user); q += 4;
461 if (r_l->buffer_user != 0)
463 q = lsa_io_user_info(io, r_l->user, q, base, align, depth);
466 DBG_RW_IVAL("auth_resp", depth, base, io, q, r_l->auth_resp); q += 4; /* 1 - Authoritative response; 0 - Non-Auth? */
468 DBG_RW_IVAL("status", depth, base, io, q, r_l->status); q += 4;
473 /*******************************************************************
474 reads or writes a structure.
475 ********************************************************************/
476 char* lsa_io_q_sam_logoff(BOOL io, LSA_Q_SAM_LOGOFF *q_l, char *q, char *base, int align, int depth)
478 if (q_l == NULL) return NULL;
480 DEBUG(5,("%s%04x lsa_io_q_sam_logoff\n", tab_depth(depth), PTR_DIFF(q, base)));
483 q = align_offset(q, base, align);
485 q = smb_io_sam_info(io, &(q_l->sam_id), q, base, align); /* domain SID */
490 /*******************************************************************
491 reads or writes a structure.
492 ********************************************************************/
493 char* lsa_io_r_sam_logoff(BOOL io, LSA_R_SAM_LOGOFF *r_l, char *q, char *base, int align, int depth)
495 if (r_l == NULL) return NULL;
497 DEBUG(5,("%s%04x lsa_io_r_sam_logoff\n", tab_depth(depth), PTR_DIFF(q, base)));
500 q = align_offset(q, base, align);
502 DBG_RW_IVAL("buffer_creds", depth, base, io, q, r_l->buffer_creds); q += 4; /* undocumented buffer pointer */
503 q = smb_io_cred(io, &(r_l->srv_creds), q, base, align); /* server credentials. server time stamp appears to be ignored. */
505 DBG_RW_IVAL("status", depth, base, io, q, r_l->status); q += 4;
511 /*******************************************************************
512 reads or writes a structure.
513 ********************************************************************/
514 char* lsa_io_(BOOL io, *, char *q, char *base, int align, int depth)
516 if (== NULL) return NULL;
518 q = align_offset(q, base, align);
520 DBG_RW_IVAL("", depth, base, io, q, ); q += 4;