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)
32 if (r_p == NULL) return NULL;
34 q = smb_io_pol_hnd(io, &(r_p->pol), q, base, align);
36 RW_IVAL(io, q, r_p->status, 0); q += 4;
41 /*******************************************************************
42 reads or writes an LSA_Q_QUERY_INFO structure.
43 ********************************************************************/
44 char* lsa_io_q_query(BOOL io, LSA_Q_QUERY_INFO *q_q, char *q, char *base, int align)
46 if (q_q == NULL) return NULL;
48 q = smb_io_pol_hnd(io, &(q_q->pol), q, base, align);
50 RW_SVAL(io, q, q_q->info_class, 0); q += 2;
55 /*******************************************************************
56 reads or writes an LSA_Q_QUERY_INFO structure.
57 ********************************************************************/
58 char* lsa_io_r_query(BOOL io, LSA_R_QUERY_INFO *r_q, char *q, char *base, int align)
60 if (r_q == NULL) return NULL;
62 RW_IVAL(io, q, r_q->undoc_buffer, 0); q += 4;
64 if (r_q->undoc_buffer != 0)
66 RW_SVAL(io, q, r_q->info_class, 0); q += 2;
68 switch (r_q->info_class)
72 q = smb_io_dom_query_3(io, &(r_q->dom.id3), q, base, align);
77 q = smb_io_dom_query_5(io, &(r_q->dom.id3), q, base, align);
88 RW_IVAL(io, q, r_q->status, 0); q += 4;
93 /*******************************************************************
94 reads or writes a structure.
95 ********************************************************************/
96 char* lsa_io_q_lookup_sids(BOOL io, LSA_Q_LOOKUP_SIDS *q_s, char *q, char *base, int align)
100 if (q_s == NULL) return NULL;
102 q = align_offset(q, base, align);
104 q = smb_io_pol_hnd(io, &(q_s->pol_hnd), q, base, align); /* policy handle */
106 RW_IVAL(io, q, q_s->num_entries, 0); q += 4;
107 RW_IVAL(io, q, q_s->buffer_dom_sid, 0); q += 4; /* undocumented domain SID buffer pointer */
108 RW_IVAL(io, q, q_s->buffer_dom_name, 0); q += 4; /* undocumented domain name buffer pointer */
110 for (i = 0; i < q_s->num_entries; i++)
112 RW_IVAL(io, q, q_s->buffer_lookup_sids[i], 0); q += 4; /* undocumented domain SID pointers to be looked up. */
115 for (i = 0; i < q_s->num_entries; i++)
117 q = smb_io_dom_sid(io, &(q_s->dom_sids[i]), q, base, align); /* domain SIDs to be looked up. */
120 RW_PCVAL(io, q, q_s->undoc, 16); q += 16; /* completely undocumented 16 bytes */
125 /*******************************************************************
126 reads or writes a structure.
127 ********************************************************************/
128 char* lsa_io_r_lookup_sids(BOOL io, LSA_R_LOOKUP_SIDS *r_s, char *q, char *base, int align)
132 if (r_s == NULL) return NULL;
134 q = align_offset(q, base, align);
136 q = smb_io_dom_r_ref(io, &(r_s->dom_ref), q, base, align); /* domain reference info */
138 RW_IVAL(io, q, r_s->num_entries, 0); q += 4;
139 RW_IVAL(io, q, r_s->undoc_buffer, 0); q += 4;
140 RW_IVAL(io, q, r_s->num_entries2, 0); q += 4;
142 for (i = 0; i < r_s->num_entries2; i++)
144 q = smb_io_dom_sid2(io, &(r_s->dom_sid[i]), q, base, align); /* domain SIDs being looked up */
147 RW_IVAL(io, q, r_s->num_entries3, 0); q += 4;
149 RW_IVAL(io, q, r_s->status, 0); q += 4;
154 /*******************************************************************
155 reads or writes a structure.
156 ********************************************************************/
157 char* lsa_io_q_lookup_rids(BOOL io, LSA_Q_LOOKUP_RIDS *q_r, char *q, char *base, int align)
161 if (q_r == NULL) return NULL;
163 q = align_offset(q, base, align);
165 q = smb_io_pol_hnd(io, &(q_r->pol_hnd), q, base, align); /* policy handle */
167 RW_IVAL(io, q, q_r->num_entries, 0); q += 4;
168 RW_IVAL(io, q, q_r->num_entries2, 0); q += 4;
169 RW_IVAL(io, q, q_r->buffer_dom_sid, 0); q += 4; /* undocumented domain SID buffer pointer */
170 RW_IVAL(io, q, q_r->buffer_dom_name, 0); q += 4; /* undocumented domain name buffer pointer */
172 for (i = 0; i < q_r->num_entries; i++)
174 q = smb_io_dom_name(io, &(q_r->lookup_name[i]), q, base, 0); /* names to be looked up */
177 RW_PCVAL(io, q, q_r->undoc, UNKNOWN_LEN); q += UNKNOWN_LEN; /* completely undocumented bytes of unknown length */
182 /*******************************************************************
183 reads or writes a structure.
184 ********************************************************************/
185 char* lsa_io_r_lookup_rids(BOOL io, LSA_R_LOOKUP_RIDS *r_r, char *q, char *base, int align)
189 if (r_r == NULL) return NULL;
191 q = align_offset(q, base, align);
193 q = smb_io_dom_r_ref(io, &(r_r->dom_ref), q, base, align); /* domain reference info */
195 RW_IVAL(io, q, r_r->num_entries, 0); q += 4;
196 RW_IVAL(io, q, r_r->undoc_buffer, 0); q += 4;
197 RW_IVAL(io, q, r_r->num_entries2, 0); q += 4;
199 for (i = 0; i < r_r->num_entries2; i++)
201 q = smb_io_dom_rid2(io, &(r_r->dom_rid[i]), q, base, align); /* domain RIDs being looked up */
204 RW_IVAL(io, q, r_r->num_entries3, 0); q += 4;
206 RW_IVAL(io, q, r_r->status, 0); q += 4;
211 /*******************************************************************
212 reads or writes a structure.
213 ********************************************************************/
214 char* lsa_io_q_req_chal(BOOL io, LSA_Q_REQ_CHAL *q_c, char *q, char *base, int align)
216 if (q_c == NULL) return NULL;
218 q = align_offset(q, base, align);
220 q = smb_io_unistr2(io, &(q_c->uni_logon_srv), q, base, align); /* logon server unicode string */
221 q = smb_io_unistr2(io, &(q_c->uni_logon_clnt), q, base, align); /* logon client unicode string */
222 q = smb_io_chal(io, &(q_c->clnt_chal), q, base, align); /* client challenge */
227 /*******************************************************************
228 reads or writes a structure.
229 ********************************************************************/
230 char* lsa_io_r_req_chal(BOOL io, LSA_R_REQ_CHAL *r_c, char *q, char *base, int align)
232 if (r_c == NULL) return NULL;
234 q = align_offset(q, base, align);
236 q = smb_io_chal(io, &(r_c->srv_chal), q, base, align); /* server challenge */
238 RW_IVAL(io, q, r_c->status, 0); q += 4;
244 /*******************************************************************
245 reads or writes a structure.
246 ********************************************************************/
247 char* lsa_io_q_auth2(BOOL io, LSA_Q_AUTH_2 *q_a, char *q, char *base, int align)
249 if (q_a == NULL) return NULL;
251 q = align_offset(q, base, align);
253 q = smb_io_log_info (io, &(q_a->clnt_id), q, base, align); /* client identification info */
254 q = smb_io_chal (io, &(q_a->clnt_chal), q, base, align); /* client-calculated credentials */
255 q = smb_io_neg_flags(io, &(q_a->clnt_flgs), q, base, align);
260 /*******************************************************************
261 reads or writes a structure.
262 ********************************************************************/
263 char* lsa_io_r_auth_2(BOOL io, LSA_R_AUTH_2 *r_a, char *q, char *base, int align)
265 if (r_a == NULL) return NULL;
267 q = align_offset(q, base, align);
269 q = smb_io_chal (io, &(r_a->srv_chal), q, base, align); /* server challenge */
270 q = smb_io_neg_flags(io, &(r_a->srv_flgs), q, base, align);
272 RW_IVAL(io, q, r_a->status, 0); q += 4;
278 /*******************************************************************
279 reads or writes a structure.
280 ********************************************************************/
281 char* lsa_io_q_srv_pwset(BOOL io, LSA_Q_SRV_PWSET *q_s, char *q, char *base, int align)
283 if (q_s == NULL) return NULL;
285 q = align_offset(q, base, align);
287 q = smb_io_clnt_info(io, &(q_s->clnt_id), q, base, align); /* client identification/authentication info */
288 RW_PCVAL(io, q, q_s->pwd, 16); q += 16; /* new password - undocumented */
293 /*******************************************************************
294 reads or writes a structure.
295 ********************************************************************/
296 char* lsa_io_r_srv_pwset(BOOL io, LSA_R_SRV_PWSET *r_s, char *q, char *base, int align)
298 if (r_s == NULL) return NULL;
300 q = align_offset(q, base, align);
302 q = smb_io_cred(io, &(r_s->srv_cred), q, base, align); /* server challenge */
304 RW_IVAL(io, q, r_s->status, 0); q += 4;
311 /*******************************************************************
312 reads or writes a structure.
313 ********************************************************************/
314 char* lsa_io_user_info(BOOL io, LSA_USER_INFO *usr, char *q, char *base, int align)
318 if (usr == NULL) return NULL;
320 q = align_offset(q, base, align);
322 RW_IVAL(io, q, usr->undoc_buffer, 0); q += 4;
324 q = smb_io_time(io, &(usr->logon_time) , q, base, align); /* logon time */
325 q = smb_io_time(io, &(usr->logoff_time) , q, base, align); /* logoff time */
326 q = smb_io_time(io, &(usr->kickoff_time) , q, base, align); /* kickoff time */
327 q = smb_io_time(io, &(usr->pass_last_set_time) , q, base, align); /* password last set time */
328 q = smb_io_time(io, &(usr->pass_can_change_time) , q, base, align); /* password can change time */
329 q = smb_io_time(io, &(usr->pass_must_change_time), q, base, align); /* password must change time */
331 q = smb_io_unihdr(io, &(usr->hdr_user_name) , q, base, align); /* username unicode string header */
332 q = smb_io_unihdr(io, &(usr->hdr_full_name) , q, base, align); /* user's full name unicode string header */
333 q = smb_io_unihdr(io, &(usr->hdr_logon_script), q, base, align); /* logon script unicode string header */
334 q = smb_io_unihdr(io, &(usr->hdr_profile_path), q, base, align); /* profile path unicode string header */
335 q = smb_io_unihdr(io, &(usr->hdr_home_dir) , q, base, align); /* home directory unicode string header */
336 q = smb_io_unihdr(io, &(usr->hdr_dir_drive) , q, base, align); /* home directory drive unicode string header */
338 RW_SVAL(io, q, usr->logon_count , 0); q += 2; /* logon count */
339 RW_SVAL(io, q, usr->bad_pw_count, 0); q += 2; /* bad password count */
341 RW_IVAL(io, q, usr->user_id , 0); q += 4; /* User ID */
342 RW_IVAL(io, q, usr->group_id , 0); q += 4; /* Group ID */
343 RW_IVAL(io, q, usr->num_groups , 0); q += 4; /* num groups */
344 RW_IVAL(io, q, usr->buffer_groups, 0); q += 4; /* undocumented buffer pointer to groups. */
345 RW_IVAL(io, q, usr->user_flgs , 0); q += 4; /* user flags */
347 RW_PCVAL(io, q, usr->sess_key, 16); q += 16; /* unused user session key */
349 q = smb_io_unihdr(io, &(usr->hdr_logon_srv), q, base, align); /* logon server unicode string header */
350 q = smb_io_unihdr(io, &(usr->hdr_logon_dom), q, base, align); /* logon domain unicode string header */
352 RW_IVAL(io, q, usr->buffer_dom_id, 0); q += 4; /* undocumented logon domain id pointer */
353 RW_PCVAL(io, q, usr->padding, 40); q += 40; /* unused padding bytes? */
355 RW_IVAL(io, q, usr->num_other_sids, 0); q += 4; /* 0 - num_sids */
356 RW_IVAL(io, q, usr->buffer_other_sids, 0); q += 4; /* NULL - undocumented pointer to SIDs. */
358 q = smb_io_unistr2(io, &(usr->uni_user_name) , q, base, align); /* username unicode string */
359 q = smb_io_unistr2(io, &(usr->uni_full_name) , q, base, align); /* user's full name unicode string */
360 q = smb_io_unistr2(io, &(usr->uni_logon_script), q, base, align); /* logon script unicode string */
361 q = smb_io_unistr2(io, &(usr->uni_profile_path), q, base, align); /* profile path unicode string */
362 q = smb_io_unistr2(io, &(usr->uni_home_dir) , q, base, align); /* home directory unicode string */
363 q = smb_io_unistr2(io, &(usr->uni_dir_drive) , q, base, align); /* home directory drive unicode string */
365 RW_IVAL(io, q, usr->num_groups2, 0); q += 4; /* num groups */
366 for (i = 0; i < usr->num_groups2; i++)
368 q = smb_io_gid(io, &(usr->gids[i]), q, base, align); /* group info */
371 q = smb_io_unistr2(io, &( usr->uni_logon_srv), q, base, align); /* logon server unicode string */
372 q = smb_io_unistr2(io, &( usr->uni_logon_dom), q, base, align); /* logon domain unicode string */
374 q = smb_io_dom_sid(io, &(usr->dom_sid), q, base, align); /* domain SID */
376 for (i = 0; i < usr->num_other_sids; i++)
378 q = smb_io_dom_sid(io, &(usr->other_sids[i]), q, base, align); /* other domain SIDs */
384 /*******************************************************************
385 reads or writes a structure.
386 ********************************************************************/
387 char* lsa_io_q_sam_logon(BOOL io, LSA_Q_SAM_LOGON *q_l, char *q, char *base, int align)
389 if (q_l == NULL) return NULL;
391 q = align_offset(q, base, align);
393 q = smb_io_sam_info(io, &(q_l->sam_id), q, base, align); /* domain SID */
398 /*******************************************************************
399 reads or writes a structure.
400 ********************************************************************/
401 char* lsa_io_r_sam_logon(BOOL io, LSA_R_SAM_LOGON *r_l, char *q, char *base, int align)
403 if (r_l == NULL) return NULL;
405 q = align_offset(q, base, align);
407 RW_IVAL(io, q, r_l->buffer_creds, 0); q += 4; /* undocumented buffer pointer */
408 q = smb_io_cred(io, &(r_l->srv_creds), q, base, align); /* server credentials. server time stamp appears to be ignored. */
410 RW_IVAL(io, q, r_l->buffer_user, 0); q += 4;
411 if (r_l->buffer_user != 0)
413 q = lsa_io_user_info(io, r_l->user, q, base, align);
416 RW_IVAL(io, q, r_l->auth_resp, 0); q += 4; /* 1 - Authoritative response; 0 - Non-Auth? */
418 RW_IVAL(io, q, r_l->status, 0); q += 4;
423 /*******************************************************************
424 reads or writes a structure.
425 ********************************************************************/
426 char* lsa_io_q_sam_logoff(BOOL io, LSA_Q_SAM_LOGOFF *q_l, char *q, char *base, int align)
428 if (q_l == NULL) return NULL;
430 q = align_offset(q, base, align);
432 q = smb_io_sam_info(io, &(q_l->sam_id), q, base, align); /* domain SID */
437 /*******************************************************************
438 reads or writes a structure.
439 ********************************************************************/
440 char* lsa_io_r_sam_logoff(BOOL io, LSA_R_SAM_LOGOFF *r_l, char *q, char *base, int align)
442 if (r_l == NULL) return NULL;
444 q = align_offset(q, base, align);
446 RW_IVAL(io, q, r_l->buffer_creds, 0); q += 4; /* undocumented buffer pointer */
447 q = smb_io_cred(io, &(r_l->srv_creds), q, base, align); /* server credentials. server time stamp appears to be ignored. */
449 RW_IVAL(io, q, r_l->status, 0); q += 4;
455 /*******************************************************************
456 reads or writes a structure.
457 ********************************************************************/
458 char* lsa_io_(BOOL io, *, char *q, char *base, int align)
460 if (== NULL) return NULL;
462 q = align_offset(q, base, align);
464 RW_IVAL(io, q, , 0); q += 4;