add WITH_SENDFILE profiling data (from Pierre Belanger)
[Samba.git] / source / rpc_parse / parse_net.c
blob988b7e32200f6397f7f43b4ff70846dc3ea63e2d
1 /*
2 * Unix SMB/Netbios implementation.
3 * Version 1.9.
4 * RPC Pipe client / server routines
5 * Copyright (C) Andrew Tridgell 1992-1997,
6 * Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
7 * Copyright (C) Paul Ashton 1997.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "includes.h"
26 /*******************************************************************
27 Reads or writes a structure.
28 ********************************************************************/
30 static BOOL net_io_neg_flags(char *desc, NEG_FLAGS *neg, prs_struct *ps, int depth)
32 if (neg == NULL)
33 return False;
35 prs_debug(ps, depth, desc, "net_io_neg_flags");
36 depth++;
38 if(!prs_align(ps))
39 return False;
41 if(!prs_uint32("neg_flags", ps, depth, &neg->neg_flags))
42 return False;
44 return True;
47 /*******************************************************************
48 Inits a NETLOGON_INFO_3 structure.
49 ********************************************************************/
51 static void init_netinfo_3(NETLOGON_INFO_3 *info, uint32 flags, uint32 logon_attempts)
53 info->flags = flags;
54 info->logon_attempts = logon_attempts;
55 info->reserved_1 = 0x0;
56 info->reserved_2 = 0x0;
57 info->reserved_3 = 0x0;
58 info->reserved_4 = 0x0;
59 info->reserved_5 = 0x0;
62 /*******************************************************************
63 Reads or writes a NETLOGON_INFO_3 structure.
64 ********************************************************************/
66 static BOOL net_io_netinfo_3(char *desc, NETLOGON_INFO_3 *info, prs_struct *ps, int depth)
68 if (info == NULL)
69 return False;
71 prs_debug(ps, depth, desc, "net_io_netinfo_3");
72 depth++;
74 if(!prs_align(ps))
75 return False;
77 if(!prs_uint32("flags ", ps, depth, &info->flags))
78 return False;
79 if(!prs_uint32("logon_attempts", ps, depth, &info->logon_attempts))
80 return False;
81 if(!prs_uint32("reserved_1 ", ps, depth, &info->reserved_1))
82 return False;
83 if(!prs_uint32("reserved_2 ", ps, depth, &info->reserved_2))
84 return False;
85 if(!prs_uint32("reserved_3 ", ps, depth, &info->reserved_3))
86 return False;
87 if(!prs_uint32("reserved_4 ", ps, depth, &info->reserved_4))
88 return False;
89 if(!prs_uint32("reserved_5 ", ps, depth, &info->reserved_5))
90 return False;
92 return True;
96 /*******************************************************************
97 Inits a NETLOGON_INFO_1 structure.
98 ********************************************************************/
100 static void init_netinfo_1(NETLOGON_INFO_1 *info, uint32 flags, uint32 pdc_status)
102 info->flags = flags;
103 info->pdc_status = pdc_status;
106 /*******************************************************************
107 Reads or writes a NETLOGON_INFO_1 structure.
108 ********************************************************************/
110 static BOOL net_io_netinfo_1(char *desc, NETLOGON_INFO_1 *info, prs_struct *ps, int depth)
112 if (info == NULL)
113 return False;
115 prs_debug(ps, depth, desc, "net_io_netinfo_1");
116 depth++;
118 if(!prs_align(ps))
119 return False;
121 if(!prs_uint32("flags ", ps, depth, &info->flags))
122 return False;
123 if(!prs_uint32("pdc_status", ps, depth, &info->pdc_status))
124 return False;
126 return True;
129 /*******************************************************************
130 Inits a NETLOGON_INFO_2 structure.
131 ********************************************************************/
133 static void init_netinfo_2(NETLOGON_INFO_2 *info, uint32 flags, uint32 pdc_status,
134 uint32 tc_status, char *trusted_dc_name)
136 int len_dc_name = strlen(trusted_dc_name);
137 info->flags = flags;
138 info->pdc_status = pdc_status;
139 info->ptr_trusted_dc_name = 1;
140 info->tc_status = tc_status;
142 if (trusted_dc_name != NULL)
143 init_unistr2(&info->uni_trusted_dc_name, trusted_dc_name, len_dc_name+1);
144 else
145 init_unistr2(&info->uni_trusted_dc_name, "", 1);
148 /*******************************************************************
149 Reads or writes a NETLOGON_INFO_2 structure.
150 ********************************************************************/
152 static BOOL net_io_netinfo_2(char *desc, NETLOGON_INFO_2 *info, prs_struct *ps, int depth)
154 if (info == NULL)
155 return False;
157 prs_debug(ps, depth, desc, "net_io_netinfo_2");
158 depth++;
160 if(!prs_align(ps))
161 return False;
163 if(!prs_uint32("flags ", ps, depth, &info->flags))
164 return False;
165 if(!prs_uint32("pdc_status ", ps, depth, &info->pdc_status))
166 return False;
167 if(!prs_uint32("ptr_trusted_dc_name", ps, depth, &info->ptr_trusted_dc_name))
168 return False;
169 if(!prs_uint32("tc_status ", ps, depth, &info->tc_status))
170 return False;
172 if (info->ptr_trusted_dc_name != 0) {
173 if(!smb_io_unistr2("unistr2", &info->uni_trusted_dc_name, info->ptr_trusted_dc_name, ps, depth))
174 return False;
177 if(!prs_align(ps))
178 return False;
180 return True;
183 /*******************************************************************
184 Reads or writes an NET_Q_LOGON_CTRL2 structure.
185 ********************************************************************/
187 BOOL net_io_q_logon_ctrl2(char *desc, NET_Q_LOGON_CTRL2 *q_l, prs_struct *ps, int depth)
189 if (q_l == NULL)
190 return False;
192 prs_debug(ps, depth, desc, "net_io_q_logon_ctrl2");
193 depth++;
195 if(!prs_align(ps))
196 return False;
198 if(!prs_uint32("ptr ", ps, depth, &q_l->ptr))
199 return False;
201 if(!smb_io_unistr2 ("", &q_l->uni_server_name, q_l->ptr, ps, depth))
202 return False;
204 if(!prs_align(ps))
205 return False;
207 if(!prs_uint32("function_code", ps, depth, &q_l->function_code))
208 return False;
209 if(!prs_uint32("query_level ", ps, depth, &q_l->query_level))
210 return False;
211 if(!prs_uint32("switch_value ", ps, depth, &q_l->switch_value))
212 return False;
214 return True;
217 /*******************************************************************
218 Inits an NET_Q_LOGON_CTRL2 structure.
219 ********************************************************************/
221 void init_net_q_logon_ctrl2(NET_Q_LOGON_CTRL2 *q_l, char *srv_name,
222 uint32 query_level)
224 DEBUG(5,("init_q_logon_ctrl2\n"));
226 q_l->function_code = 0x01;
227 q_l->query_level = query_level;
228 q_l->switch_value = 0x01;
230 init_unistr2(&q_l->uni_server_name, srv_name, strlen(srv_name) + 1);
233 /*******************************************************************
234 Inits an NET_R_LOGON_CTRL2 structure.
235 ********************************************************************/
237 void init_net_r_logon_ctrl2(NET_R_LOGON_CTRL2 *r_l, uint32 query_level,
238 uint32 flags, uint32 pdc_status,
239 uint32 logon_attempts, uint32 tc_status,
240 char *trusted_domain_name)
242 DEBUG(5,("init_r_logon_ctrl2\n"));
244 r_l->switch_value = query_level; /* should only be 0x1 */
246 switch (query_level) {
247 case 1:
248 r_l->ptr = 1; /* undocumented pointer */
249 init_netinfo_1(&r_l->logon.info1, flags, pdc_status);
250 r_l->status = NT_STATUS_OK;
251 break;
252 case 2:
253 r_l->ptr = 1; /* undocumented pointer */
254 init_netinfo_2(&r_l->logon.info2, flags, pdc_status,
255 tc_status, trusted_domain_name);
256 r_l->status = NT_STATUS_OK;
257 break;
258 case 3:
259 r_l->ptr = 1; /* undocumented pointer */
260 init_netinfo_3(&r_l->logon.info3, flags, logon_attempts);
261 r_l->status = NT_STATUS_OK;
262 break;
263 default:
264 DEBUG(2,("init_r_logon_ctrl2: unsupported switch value %d\n",
265 r_l->switch_value));
266 r_l->ptr = 0; /* undocumented pointer */
268 /* take a guess at an error code... */
269 r_l->status = NT_STATUS_INVALID_INFO_CLASS;
270 break;
274 /*******************************************************************
275 Reads or writes an NET_R_LOGON_CTRL2 structure.
276 ********************************************************************/
278 BOOL net_io_r_logon_ctrl2(char *desc, NET_R_LOGON_CTRL2 *r_l, prs_struct *ps, int depth)
280 if (r_l == NULL)
281 return False;
283 prs_debug(ps, depth, desc, "net_io_r_logon_ctrl2");
284 depth++;
286 if(!prs_uint32("switch_value ", ps, depth, &r_l->switch_value))
287 return False;
288 if(!prs_uint32("ptr ", ps, depth, &r_l->ptr))
289 return False;
291 if (r_l->ptr != 0) {
292 switch (r_l->switch_value) {
293 case 1:
294 if(!net_io_netinfo_1("", &r_l->logon.info1, ps, depth))
295 return False;
296 break;
297 case 2:
298 if(!net_io_netinfo_2("", &r_l->logon.info2, ps, depth))
299 return False;
300 break;
301 case 3:
302 if(!net_io_netinfo_3("", &r_l->logon.info3, ps, depth))
303 return False;
304 break;
305 default:
306 DEBUG(2,("net_io_r_logon_ctrl2: unsupported switch value %d\n",
307 r_l->switch_value));
308 break;
312 if(!prs_ntstatus("status ", ps, depth, &r_l->status))
313 return False;
315 return True;
318 /*******************************************************************
319 Reads or writes an NET_Q_LOGON_CTRL structure.
320 ********************************************************************/
322 BOOL net_io_q_logon_ctrl(char *desc, NET_Q_LOGON_CTRL *q_l, prs_struct *ps,
323 int depth)
325 prs_debug(ps, depth, desc, "net_io_q_logon_ctrl");
326 depth++;
328 if(!prs_align(ps))
329 return False;
331 if(!prs_uint32("ptr ", ps, depth, &q_l->ptr))
332 return False;
334 if(!smb_io_unistr2 ("", &q_l->uni_server_name, q_l->ptr, ps, depth))
335 return False;
337 if(!prs_align(ps))
338 return False;
340 if(!prs_uint32("function_code", ps, depth, &q_l->function_code))
341 return False;
342 if(!prs_uint32("query_level ", ps, depth, &q_l->query_level))
343 return False;
345 return True;
348 /*******************************************************************
349 Inits an NET_Q_LOGON_CTRL structure.
350 ********************************************************************/
352 void init_net_q_logon_ctrl(NET_Q_LOGON_CTRL *q_l, char *srv_name,
353 uint32 query_level)
355 DEBUG(5,("init_q_logon_ctrl\n"));
357 q_l->function_code = 0x01; /* ??? */
358 q_l->query_level = query_level;
360 init_unistr2(&q_l->uni_server_name, srv_name, strlen(srv_name) + 1);
363 /*******************************************************************
364 Inits an NET_R_LOGON_CTRL structure.
365 ********************************************************************/
367 void init_net_r_logon_ctrl(NET_R_LOGON_CTRL *r_l, uint32 query_level,
368 uint32 flags, uint32 pdc_status)
370 DEBUG(5,("init_r_logon_ctrl\n"));
372 r_l->switch_value = query_level; /* should only be 0x1 */
374 switch (query_level) {
375 case 1:
376 r_l->ptr = 1; /* undocumented pointer */
377 init_netinfo_1(&r_l->logon.info1, flags, pdc_status);
378 r_l->status = NT_STATUS_OK;
379 break;
380 default:
381 DEBUG(2,("init_r_logon_ctrl: unsupported switch value %d\n",
382 r_l->switch_value));
383 r_l->ptr = 0; /* undocumented pointer */
385 /* take a guess at an error code... */
386 r_l->status = NT_STATUS_INVALID_INFO_CLASS;
387 break;
391 /*******************************************************************
392 Reads or writes an NET_R_LOGON_CTRL structure.
393 ********************************************************************/
395 BOOL net_io_r_logon_ctrl(char *desc, NET_R_LOGON_CTRL *r_l, prs_struct *ps,
396 int depth)
398 prs_debug(ps, depth, desc, "net_io_r_logon_ctrl");
399 depth++;
401 if(!prs_uint32("switch_value ", ps, depth, &r_l->switch_value))
402 return False;
403 if(!prs_uint32("ptr ", ps, depth, &r_l->ptr))
404 return False;
406 if (r_l->ptr != 0) {
407 switch (r_l->switch_value) {
408 case 1:
409 if(!net_io_netinfo_1("", &r_l->logon.info1, ps, depth))
410 return False;
411 break;
412 default:
413 DEBUG(2,("net_io_r_logon_ctrl: unsupported switch value %d\n",
414 r_l->switch_value));
415 break;
419 if(!prs_ntstatus("status ", ps, depth, &r_l->status))
420 return False;
422 return True;
425 /*******************************************************************
426 Inits an NET_R_TRUST_DOM_LIST structure.
427 ********************************************************************/
429 void init_r_trust_dom(NET_R_TRUST_DOM_LIST *r_t,
430 uint32 num_doms, char *dom_name)
432 int i = 0;
434 DEBUG(5,("init_r_trust_dom\n"));
436 for (i = 0; i < MAX_TRUST_DOMS; i++) {
437 r_t->uni_trust_dom_name[i].uni_str_len = 0;
438 r_t->uni_trust_dom_name[i].uni_max_len = 0;
440 if (num_doms > MAX_TRUST_DOMS)
441 num_doms = MAX_TRUST_DOMS;
443 for (i = 0; i < num_doms; i++) {
444 fstring domain_name;
445 fstrcpy(domain_name, dom_name);
446 strupper(domain_name);
447 init_unistr2(&r_t->uni_trust_dom_name[i], domain_name, strlen(domain_name)+1);
448 /* the use of UNISTR2 here is non-standard. */
449 r_t->uni_trust_dom_name[i].undoc = 0x1;
452 r_t->status = NT_STATUS_OK;
455 /*******************************************************************
456 Reads or writes an NET_R_TRUST_DOM_LIST structure.
457 ********************************************************************/
459 BOOL net_io_r_trust_dom(char *desc, NET_R_TRUST_DOM_LIST *r_t, prs_struct *ps, int depth)
461 uint32 value;
463 if (r_t == NULL)
464 return False;
466 prs_debug(ps, depth, desc, "net_io_r_trust_dom");
467 depth++;
469 /* temporary code to give a valid response */
470 value=2;
471 if(!prs_uint32("status", ps, depth, &value))
472 return False;
474 value=1;
475 if(!prs_uint32("status", ps, depth, &value))
476 return False;
477 value=2;
478 if(!prs_uint32("status", ps, depth, &value))
479 return False;
481 value=0;
482 if(!prs_uint32("status", ps, depth, &value))
483 return False;
485 value=0;
486 if(!prs_uint32("status", ps, depth, &value))
487 return False;
489 /* old non working code */
490 #if 0
491 int i;
493 for (i = 0; i < MAX_TRUST_DOMS; i++) {
494 if (r_t->uni_trust_dom_name[i].uni_str_len == 0)
495 break;
496 if(!smb_io_unistr2("", &r_t->uni_trust_dom_name[i], True, ps, depth))
497 return False;
500 if(!prs_ntstatus("status", ps, depth, &r_t->status))
501 return False;
502 #endif
503 return True;
507 /*******************************************************************
508 Reads or writes an NET_Q_TRUST_DOM_LIST structure.
509 ********************************************************************/
511 BOOL net_io_q_trust_dom(char *desc, NET_Q_TRUST_DOM_LIST *q_l, prs_struct *ps, int depth)
513 if (q_l == NULL)
514 return False;
516 prs_debug(ps, depth, desc, "net_io_q_trust_dom");
517 depth++;
519 if(!prs_uint32("ptr ", ps, depth, &q_l->ptr))
520 return False;
521 if(!smb_io_unistr2 ("", &q_l->uni_server_name, q_l->ptr, ps, depth))
522 return False;
524 return True;
527 /*******************************************************************
528 Inits an NET_Q_REQ_CHAL structure.
529 ********************************************************************/
531 void init_q_req_chal(NET_Q_REQ_CHAL *q_c,
532 char *logon_srv, char *logon_clnt,
533 DOM_CHAL *clnt_chal)
535 DEBUG(5,("init_q_req_chal: %d\n", __LINE__));
537 q_c->undoc_buffer = 1; /* don't know what this buffer is */
539 init_unistr2(&q_c->uni_logon_srv, logon_srv , strlen(logon_srv )+1);
540 init_unistr2(&q_c->uni_logon_clnt, logon_clnt, strlen(logon_clnt)+1);
542 memcpy(q_c->clnt_chal.data, clnt_chal->data, sizeof(clnt_chal->data));
544 DEBUG(5,("init_q_req_chal: %d\n", __LINE__));
547 /*******************************************************************
548 Reads or writes an NET_Q_REQ_CHAL structure.
549 ********************************************************************/
551 BOOL net_io_q_req_chal(char *desc, NET_Q_REQ_CHAL *q_c, prs_struct *ps, int depth)
553 int old_align;
555 if (q_c == NULL)
556 return False;
558 prs_debug(ps, depth, desc, "net_io_q_req_chal");
559 depth++;
561 if(!prs_align(ps))
562 return False;
564 if(!prs_uint32("undoc_buffer", ps, depth, &q_c->undoc_buffer))
565 return False;
567 if(!smb_io_unistr2("", &q_c->uni_logon_srv, True, ps, depth)) /* logon server unicode string */
568 return False;
569 if(!smb_io_unistr2("", &q_c->uni_logon_clnt, True, ps, depth)) /* logon client unicode string */
570 return False;
572 old_align = ps->align;
573 ps->align = 0;
574 /* client challenge is _not_ aligned after the unicode strings */
575 if(!smb_io_chal("", &q_c->clnt_chal, ps, depth)) {
576 /* client challenge */
577 ps->align = old_align;
578 return False;
580 ps->align = old_align;
582 return True;
585 /*******************************************************************
586 Reads or writes a structure.
587 ********************************************************************/
589 BOOL net_io_r_req_chal(char *desc, NET_R_REQ_CHAL *r_c, prs_struct *ps, int depth)
591 if (r_c == NULL)
592 return False;
594 prs_debug(ps, depth, desc, "net_io_r_req_chal");
595 depth++;
597 if(!prs_align(ps))
598 return False;
600 if(!smb_io_chal("", &r_c->srv_chal, ps, depth)) /* server challenge */
601 return False;
603 if(!prs_ntstatus("status", ps, depth, &r_c->status))
604 return False;
606 return True;
610 /*******************************************************************
611 Reads or writes a structure.
612 ********************************************************************/
614 BOOL net_io_q_auth(char *desc, NET_Q_AUTH *q_a, prs_struct *ps, int depth)
616 int old_align;
617 if (q_a == NULL)
618 return False;
620 prs_debug(ps, depth, desc, "net_io_q_auth");
621 depth++;
623 if(!prs_align(ps))
624 return False;
626 if(!smb_io_log_info ("", &q_a->clnt_id, ps, depth)) /* client identification info */
627 return False;
628 /* client challenge is _not_ aligned */
629 old_align = ps->align;
630 ps->align = 0;
631 if(!smb_io_chal("", &q_a->clnt_chal, ps, depth)) {
632 /* client-calculated credentials */
633 ps->align = old_align;
634 return False;
636 ps->align = old_align;
638 return True;
641 /*******************************************************************
642 Reads or writes a structure.
643 ********************************************************************/
645 BOOL net_io_r_auth(char *desc, NET_R_AUTH *r_a, prs_struct *ps, int depth)
647 if (r_a == NULL)
648 return False;
650 prs_debug(ps, depth, desc, "net_io_r_auth");
651 depth++;
653 if(!prs_align(ps))
654 return False;
656 if(!smb_io_chal("", &r_a->srv_chal, ps, depth)) /* server challenge */
657 return False;
659 if(!prs_ntstatus("status", ps, depth, &r_a->status))
660 return False;
662 return True;
665 /*******************************************************************
666 Inits a NET_Q_AUTH_2 struct.
667 ********************************************************************/
669 void init_q_auth_2(NET_Q_AUTH_2 *q_a,
670 char *logon_srv, char *acct_name, uint16 sec_chan, char *comp_name,
671 DOM_CHAL *clnt_chal, uint32 clnt_flgs)
673 DEBUG(5,("init_q_auth_2: %d\n", __LINE__));
675 init_log_info(&q_a->clnt_id, logon_srv, acct_name, sec_chan, comp_name);
676 memcpy(q_a->clnt_chal.data, clnt_chal->data, sizeof(clnt_chal->data));
677 q_a->clnt_flgs.neg_flags = clnt_flgs;
679 DEBUG(5,("init_q_auth_2: %d\n", __LINE__));
682 /*******************************************************************
683 Reads or writes a structure.
684 ********************************************************************/
686 BOOL net_io_q_auth_2(char *desc, NET_Q_AUTH_2 *q_a, prs_struct *ps, int depth)
688 int old_align;
689 if (q_a == NULL)
690 return False;
692 prs_debug(ps, depth, desc, "net_io_q_auth_2");
693 depth++;
695 if(!prs_align(ps))
696 return False;
698 if(!smb_io_log_info ("", &q_a->clnt_id, ps, depth)) /* client identification info */
699 return False;
700 /* client challenge is _not_ aligned */
701 old_align = ps->align;
702 ps->align = 0;
703 if(!smb_io_chal("", &q_a->clnt_chal, ps, depth)) {
704 /* client-calculated credentials */
705 ps->align = old_align;
706 return False;
708 ps->align = old_align;
709 if(!net_io_neg_flags("", &q_a->clnt_flgs, ps, depth))
710 return False;
712 return True;
715 /*******************************************************************
716 Reads or writes a structure.
717 ********************************************************************/
719 BOOL net_io_r_auth_2(char *desc, NET_R_AUTH_2 *r_a, prs_struct *ps, int depth)
721 if (r_a == NULL)
722 return False;
724 prs_debug(ps, depth, desc, "net_io_r_auth_2");
725 depth++;
727 if(!prs_align(ps))
728 return False;
730 if(!smb_io_chal("", &r_a->srv_chal, ps, depth)) /* server challenge */
731 return False;
732 if(!net_io_neg_flags("", &r_a->srv_flgs, ps, depth))
733 return False;
735 if(!prs_ntstatus("status", ps, depth, &r_a->status))
736 return False;
738 return True;
742 /*******************************************************************
743 Inits a NET_Q_SRV_PWSET.
744 ********************************************************************/
746 void init_q_srv_pwset(NET_Q_SRV_PWSET *q_s, char *logon_srv, char *acct_name,
747 uint16 sec_chan, char *comp_name, DOM_CRED *cred, char nt_cypher[16])
749 DEBUG(5,("init_q_srv_pwset\n"));
751 init_clnt_info(&q_s->clnt_id, logon_srv, acct_name, sec_chan, comp_name, cred);
753 memcpy(q_s->pwd, nt_cypher, sizeof(q_s->pwd));
756 /*******************************************************************
757 Reads or writes a structure.
758 ********************************************************************/
760 BOOL net_io_q_srv_pwset(char *desc, NET_Q_SRV_PWSET *q_s, prs_struct *ps, int depth)
762 if (q_s == NULL)
763 return False;
765 prs_debug(ps, depth, desc, "net_io_q_srv_pwset");
766 depth++;
768 if(!prs_align(ps))
769 return False;
771 if(!smb_io_clnt_info("", &q_s->clnt_id, ps, depth)) /* client identification/authentication info */
772 return False;
773 if(!prs_uint8s (False, "pwd", ps, depth, q_s->pwd, 16)) /* new password - undocumented */
774 return False;
776 return True;
779 /*******************************************************************
780 Reads or writes a structure.
781 ********************************************************************/
783 BOOL net_io_r_srv_pwset(char *desc, NET_R_SRV_PWSET *r_s, prs_struct *ps, int depth)
785 if (r_s == NULL)
786 return False;
788 prs_debug(ps, depth, desc, "net_io_r_srv_pwset");
789 depth++;
791 if(!prs_align(ps))
792 return False;
794 if(!smb_io_cred("", &r_s->srv_cred, ps, depth)) /* server challenge */
795 return False;
797 if(!prs_ntstatus("status", ps, depth, &r_s->status))
798 return False;
800 return True;
803 /*************************************************************************
804 Init DOM_SID2 array from a string containing multiple sids
805 *************************************************************************/
807 static int init_dom_sid2s(TALLOC_CTX *ctx, char *sids_str, DOM_SID2 **ppsids)
809 char *ptr;
810 pstring s2;
811 int count = 0;
813 DEBUG(4,("init_dom_sid2s: %s\n", sids_str ? sids_str:""));
815 *ppsids = NULL;
817 if(sids_str) {
818 int number;
819 DOM_SID2 *sids;
821 /* Count the number of SIDs. */
822 for (count = 0, ptr = sids_str;
823 next_token(&ptr, s2, NULL, sizeof(s2)); count++)
826 /* Now allocate space for them. */
827 *ppsids = (DOM_SID2 *)talloc_zero(ctx, count * sizeof(DOM_SID2));
828 if (*ppsids == NULL)
829 return 0;
831 sids = *ppsids;
833 for (number = 0, ptr = sids_str;
834 next_token(&ptr, s2, NULL, sizeof(s2)); number++) {
835 DOM_SID tmpsid;
836 string_to_sid(&tmpsid, s2);
837 init_dom_sid2(&sids[number], &tmpsid);
841 return count;
844 /*******************************************************************
845 Inits a NET_ID_INFO_1 structure.
846 ********************************************************************/
848 void init_id_info1(NET_ID_INFO_1 *id, char *domain_name,
849 uint32 param_ctrl, uint32 log_id_low, uint32 log_id_high,
850 char *user_name, char *wksta_name,
851 char *sess_key,
852 unsigned char lm_cypher[16], unsigned char nt_cypher[16])
854 int len_domain_name = strlen(domain_name);
855 int len_user_name = strlen(user_name );
856 int len_wksta_name = strlen(wksta_name );
858 unsigned char lm_owf[16];
859 unsigned char nt_owf[16];
861 DEBUG(5,("init_id_info1: %d\n", __LINE__));
863 id->ptr_id_info1 = 1;
865 init_uni_hdr(&id->hdr_domain_name, len_domain_name);
867 id->param_ctrl = param_ctrl;
868 init_logon_id(&id->logon_id, log_id_low, log_id_high);
870 init_uni_hdr(&id->hdr_user_name, len_user_name);
871 init_uni_hdr(&id->hdr_wksta_name, len_wksta_name);
873 if (lm_cypher && nt_cypher) {
874 unsigned char key[16];
875 #ifdef DEBUG_PASSWORD
876 DEBUG(100,("lm cypher:"));
877 dump_data(100, (char *)lm_cypher, 16);
879 DEBUG(100,("nt cypher:"));
880 dump_data(100, (char *)nt_cypher, 16);
881 #endif
883 memset(key, 0, 16);
884 memcpy(key, sess_key, 8);
886 memcpy(lm_owf, lm_cypher, 16);
887 SamOEMhash(lm_owf, key, 16);
888 memcpy(nt_owf, nt_cypher, 16);
889 SamOEMhash(nt_owf, key, 16);
891 #ifdef DEBUG_PASSWORD
892 DEBUG(100,("encrypt of lm owf password:"));
893 dump_data(100, (char *)lm_owf, 16);
895 DEBUG(100,("encrypt of nt owf password:"));
896 dump_data(100, (char *)nt_owf, 16);
897 #endif
898 /* set up pointers to cypher blocks */
899 lm_cypher = lm_owf;
900 nt_cypher = nt_owf;
903 init_owf_info(&id->lm_owf, lm_cypher);
904 init_owf_info(&id->nt_owf, nt_cypher);
906 init_unistr2(&id->uni_domain_name, domain_name, len_domain_name);
907 init_unistr2(&id->uni_user_name, user_name, len_user_name);
908 init_unistr2(&id->uni_wksta_name, wksta_name, len_wksta_name);
911 /*******************************************************************
912 Reads or writes an NET_ID_INFO_1 structure.
913 ********************************************************************/
915 static BOOL net_io_id_info1(char *desc, NET_ID_INFO_1 *id, prs_struct *ps, int depth)
917 if (id == NULL)
918 return False;
920 prs_debug(ps, depth, desc, "net_io_id_info1");
921 depth++;
923 if(!prs_align(ps))
924 return False;
926 if(!prs_uint32("ptr_id_info1", ps, depth, &id->ptr_id_info1))
927 return False;
929 if (id->ptr_id_info1 != 0) {
930 if(!smb_io_unihdr("unihdr", &id->hdr_domain_name, ps, depth))
931 return False;
933 if(!prs_uint32("param_ctrl", ps, depth, &id->param_ctrl))
934 return False;
935 if(!smb_io_logon_id("", &id->logon_id, ps, depth))
936 return False;
938 if(!smb_io_unihdr("unihdr", &id->hdr_user_name, ps, depth))
939 return False;
940 if(!smb_io_unihdr("unihdr", &id->hdr_wksta_name, ps, depth))
941 return False;
943 if(!smb_io_owf_info("", &id->lm_owf, ps, depth))
944 return False;
945 if(!smb_io_owf_info("", &id->nt_owf, ps, depth))
946 return False;
948 if(!smb_io_unistr2("unistr2", &id->uni_domain_name,
949 id->hdr_domain_name.buffer, ps, depth))
950 return False;
951 if(!smb_io_unistr2("unistr2", &id->uni_user_name,
952 id->hdr_user_name.buffer, ps, depth))
953 return False;
954 if(!smb_io_unistr2("unistr2", &id->uni_wksta_name,
955 id->hdr_wksta_name.buffer, ps, depth))
956 return False;
959 return True;
962 /*******************************************************************
963 Inits a NET_ID_INFO_2 structure.
965 This is a network logon packet. The log_id parameters
966 are what an NT server would generate for LUID once the
967 user is logged on. I don't think we care about them.
969 Note that this has no access to the NT and LM hashed passwords,
970 so it forwards the challenge, and the NT and LM responses (24
971 bytes each) over the secure channel to the Domain controller
972 for it to say yea or nay. This is the preferred method of
973 checking for a logon as it doesn't export the password
974 hashes to anyone who has compromised the secure channel. JRA.
975 ********************************************************************/
977 void init_id_info2(NET_ID_INFO_2 * id, const char *domain_name,
978 uint32 param_ctrl,
979 uint32 log_id_low, uint32 log_id_high,
980 const char *user_name, const char *wksta_name,
981 const uchar lm_challenge[8],
982 const uchar * lm_chal_resp, int lm_chal_resp_len,
983 const uchar * nt_chal_resp, int nt_chal_resp_len)
985 int len_domain_name = strlen(domain_name);
986 int len_user_name = strlen(user_name );
987 int len_wksta_name = strlen(wksta_name );
988 unsigned char lm_owf[24];
989 unsigned char nt_owf[128];
991 DEBUG(5,("init_id_info2: %d\n", __LINE__));
993 id->ptr_id_info2 = 1;
995 init_uni_hdr(&id->hdr_domain_name, len_domain_name);
997 id->param_ctrl = param_ctrl;
998 init_logon_id(&id->logon_id, log_id_low, log_id_high);
1000 init_uni_hdr(&id->hdr_user_name, len_user_name);
1001 init_uni_hdr(&id->hdr_wksta_name, len_wksta_name);
1003 if (nt_chal_resp) {
1004 /* oops. can only send what-ever-it-is direct */
1005 memcpy(nt_owf, nt_chal_resp, MIN(sizeof(nt_owf), nt_chal_resp_len));
1006 nt_chal_resp = nt_owf;
1008 if (lm_chal_resp) {
1009 /* oops. can only send what-ever-it-is direct */
1010 memcpy(lm_owf, lm_chal_resp, MIN(sizeof(lm_owf), lm_chal_resp_len));
1011 lm_chal_resp = lm_owf;
1014 memcpy(id->lm_chal, lm_challenge, sizeof(id->lm_chal));
1015 init_str_hdr(&id->hdr_nt_chal_resp, nt_chal_resp_len, nt_chal_resp_len, (nt_chal_resp != NULL) ? 1 : 0);
1016 init_str_hdr(&id->hdr_lm_chal_resp, lm_chal_resp_len, lm_chal_resp_len, (lm_chal_resp != NULL) ? 1 : 0);
1018 init_unistr2(&id->uni_domain_name, domain_name, len_domain_name);
1019 init_unistr2(&id->uni_user_name, user_name, len_user_name);
1020 init_unistr2(&id->uni_wksta_name, wksta_name, len_wksta_name);
1022 init_string2(&id->nt_chal_resp, (const char *)nt_chal_resp, nt_chal_resp_len, nt_chal_resp_len);
1023 init_string2(&id->lm_chal_resp, (const char *)lm_chal_resp, lm_chal_resp_len, lm_chal_resp_len);
1027 /*******************************************************************
1028 Reads or writes an NET_ID_INFO_2 structure.
1029 ********************************************************************/
1031 static BOOL net_io_id_info2(char *desc, NET_ID_INFO_2 *id, prs_struct *ps, int depth)
1033 if (id == NULL)
1034 return False;
1036 prs_debug(ps, depth, desc, "net_io_id_info2");
1037 depth++;
1039 if(!prs_align(ps))
1040 return False;
1042 if(!prs_uint32("ptr_id_info2", ps, depth, &id->ptr_id_info2))
1043 return False;
1045 if (id->ptr_id_info2 != 0) {
1046 if(!smb_io_unihdr("unihdr", &id->hdr_domain_name, ps, depth))
1047 return False;
1049 if(!prs_uint32("param_ctrl", ps, depth, &id->param_ctrl))
1050 return False;
1051 if(!smb_io_logon_id("", &id->logon_id, ps, depth))
1052 return False;
1054 if(!smb_io_unihdr("unihdr", &id->hdr_user_name, ps, depth))
1055 return False;
1056 if(!smb_io_unihdr("unihdr", &id->hdr_wksta_name, ps, depth))
1057 return False;
1059 if(!prs_uint8s (False, "lm_chal", ps, depth, id->lm_chal, 8)) /* lm 8 byte challenge */
1060 return False;
1062 if(!smb_io_strhdr("hdr_nt_chal_resp", &id->hdr_nt_chal_resp, ps, depth))
1063 return False;
1064 if(!smb_io_strhdr("hdr_lm_chal_resp", &id->hdr_lm_chal_resp, ps, depth))
1065 return False;
1067 if(!smb_io_unistr2("uni_domain_name", &id->uni_domain_name,
1068 id->hdr_domain_name.buffer, ps, depth))
1069 return False;
1070 if(!smb_io_unistr2("uni_user_name ", &id->uni_user_name,
1071 id->hdr_user_name.buffer, ps, depth))
1072 return False;
1073 if(!smb_io_unistr2("uni_wksta_name ", &id->uni_wksta_name,
1074 id->hdr_wksta_name.buffer, ps, depth))
1075 return False;
1076 if(!smb_io_string2("nt_chal_resp", &id->nt_chal_resp,
1077 id->hdr_nt_chal_resp.buffer, ps, depth))
1078 return False;
1079 if(!smb_io_string2("lm_chal_resp", &id->lm_chal_resp,
1080 id->hdr_lm_chal_resp.buffer, ps, depth))
1081 return False;
1084 return True;
1088 /*******************************************************************
1089 Inits a DOM_SAM_INFO structure.
1090 ********************************************************************/
1092 void init_sam_info(DOM_SAM_INFO *sam,
1093 char *logon_srv, char *comp_name, DOM_CRED *clnt_cred,
1094 DOM_CRED *rtn_cred, uint16 logon_level,
1095 NET_ID_INFO_CTR *ctr)
1097 DEBUG(5,("init_sam_info: %d\n", __LINE__));
1099 init_clnt_info2(&sam->client, logon_srv, comp_name, clnt_cred);
1101 if (rtn_cred != NULL) {
1102 sam->ptr_rtn_cred = 1;
1103 memcpy(&sam->rtn_cred, rtn_cred, sizeof(sam->rtn_cred));
1104 } else {
1105 sam->ptr_rtn_cred = 0;
1108 sam->logon_level = logon_level;
1109 sam->ctr = ctr;
1112 /*******************************************************************
1113 Reads or writes a DOM_SAM_INFO structure.
1114 ********************************************************************/
1116 static BOOL net_io_id_info_ctr(char *desc, NET_ID_INFO_CTR **pp_ctr, prs_struct *ps, int depth)
1118 NET_ID_INFO_CTR *ctr = *pp_ctr;
1120 prs_debug(ps, depth, desc, "smb_io_sam_info");
1121 depth++;
1123 if (UNMARSHALLING(ps)) {
1124 ctr = *pp_ctr = (NET_ID_INFO_CTR *)prs_alloc_mem(ps, sizeof(NET_ID_INFO_CTR));
1125 if (ctr == NULL)
1126 return False;
1129 if (ctr == NULL)
1130 return False;
1132 /* don't 4-byte align here! */
1134 if(!prs_uint16("switch_value ", ps, depth, &ctr->switch_value))
1135 return False;
1137 switch (ctr->switch_value) {
1138 case 1:
1139 if(!net_io_id_info1("", &ctr->auth.id1, ps, depth))
1140 return False;
1141 break;
1142 case 2:
1143 if(!net_io_id_info2("", &ctr->auth.id2, ps, depth))
1144 return False;
1145 break;
1146 default:
1147 /* PANIC! */
1148 DEBUG(4,("smb_io_sam_info: unknown switch_value!\n"));
1149 break;
1152 return True;
1155 /*******************************************************************
1156 Reads or writes a DOM_SAM_INFO structure.
1157 ********************************************************************/
1159 static BOOL smb_io_sam_info(char *desc, DOM_SAM_INFO *sam, prs_struct *ps, int depth)
1161 if (sam == NULL)
1162 return False;
1164 prs_debug(ps, depth, desc, "smb_io_sam_info");
1165 depth++;
1167 if(!prs_align(ps))
1168 return False;
1170 if(!smb_io_clnt_info2("", &sam->client, ps, depth))
1171 return False;
1173 if(!prs_uint32("ptr_rtn_cred ", ps, depth, &sam->ptr_rtn_cred))
1174 return False;
1175 if(!smb_io_cred("", &sam->rtn_cred, ps, depth))
1176 return False;
1178 if(!prs_uint16("logon_level ", ps, depth, &sam->logon_level))
1179 return False;
1181 if (sam->logon_level != 0) {
1182 if(!net_io_id_info_ctr("logon_info", &sam->ctr, ps, depth))
1183 return False;
1186 return True;
1189 /*************************************************************************
1190 Init
1191 *************************************************************************/
1193 void init_net_user_info3(TALLOC_CTX *ctx, NET_USER_INFO_3 *usr, SAM_ACCOUNT *sampw,
1194 uint16 logon_count, uint16 bad_pw_count,
1195 uint32 num_groups, DOM_GID *gids,
1196 uint32 user_flgs, uchar *sess_key,
1197 char *logon_srv, char *logon_dom,
1198 DOM_SID *dom_sid, char *other_sids)
1200 /* only cope with one "other" sid, right now. */
1201 /* need to count the number of space-delimited sids */
1202 int i;
1203 int num_other_sids = 0;
1205 NTTIME logon_time, logoff_time, kickoff_time,
1206 pass_last_set_time, pass_can_change_time,
1207 pass_must_change_time;
1209 int len_user_name, len_full_name, len_home_dir,
1210 len_dir_drive, len_logon_script, len_profile_path;
1212 const char* user_name = pdb_get_username(sampw);
1213 const char* full_name = pdb_get_fullname(sampw);
1214 const char* home_dir = pdb_get_homedir(sampw);
1215 const char* dir_drive = pdb_get_dirdrive(sampw);
1216 const char* logon_script = pdb_get_logon_script(sampw);
1217 const char* profile_path = pdb_get_profile_path(sampw);
1219 int len_logon_srv = strlen(logon_srv);
1220 int len_logon_dom = strlen(logon_dom);
1222 len_user_name = strlen(user_name );
1223 len_full_name = strlen(full_name );
1224 len_home_dir = strlen(home_dir );
1225 len_dir_drive = strlen(dir_drive );
1226 len_logon_script = strlen(logon_script);
1227 len_profile_path = strlen(profile_path);
1230 ZERO_STRUCTP(usr);
1232 usr->ptr_user_info = 1; /* yes, we're bothering to put USER_INFO data here */
1235 /* Create NTTIME structs */
1236 unix_to_nt_time (&logon_time, pdb_get_logon_time(sampw));
1237 unix_to_nt_time (&logoff_time, TIME_T_MAX);
1238 unix_to_nt_time (&kickoff_time, TIME_T_MAX);
1239 unix_to_nt_time (&pass_last_set_time, pdb_get_pass_last_set_time(sampw));
1240 unix_to_nt_time (&pass_can_change_time, pdb_get_pass_can_change_time(sampw));
1241 unix_to_nt_time (&pass_must_change_time,pdb_get_pass_must_change_time(sampw));
1243 usr->logon_time = logon_time;
1244 usr->logoff_time = logoff_time;
1245 usr->kickoff_time = kickoff_time;
1246 usr->pass_last_set_time = pass_last_set_time;
1247 usr->pass_can_change_time = pass_can_change_time;
1248 usr->pass_must_change_time = pass_must_change_time;
1250 init_uni_hdr(&usr->hdr_user_name, len_user_name);
1251 init_uni_hdr(&usr->hdr_full_name, len_full_name);
1252 init_uni_hdr(&usr->hdr_logon_script, len_logon_script);
1253 init_uni_hdr(&usr->hdr_profile_path, len_profile_path);
1254 init_uni_hdr(&usr->hdr_home_dir, len_home_dir);
1255 init_uni_hdr(&usr->hdr_dir_drive, len_dir_drive);
1257 usr->logon_count = logon_count;
1258 usr->bad_pw_count = bad_pw_count;
1260 usr->user_rid = pdb_get_user_rid(sampw);
1261 usr->group_rid = pdb_get_group_rid(sampw);
1262 usr->num_groups = num_groups+1;
1264 usr->buffer_groups = 1; /* indicates fill in groups, below, even if there are none */
1265 usr->user_flgs = user_flgs;
1267 if (sess_key != NULL)
1268 memcpy(usr->user_sess_key, sess_key, sizeof(usr->user_sess_key));
1269 else
1270 memset((char *)usr->user_sess_key, '\0', sizeof(usr->user_sess_key));
1272 init_uni_hdr(&usr->hdr_logon_srv, len_logon_srv);
1273 init_uni_hdr(&usr->hdr_logon_dom, len_logon_dom);
1275 usr->buffer_dom_id = dom_sid ? 1 : 0; /* yes, we're bothering to put a domain SID in */
1277 memset((char *)usr->padding, '\0', sizeof(usr->padding));
1279 num_other_sids = init_dom_sid2s(ctx, other_sids, &usr->other_sids);
1281 usr->num_other_sids = num_other_sids;
1282 usr->buffer_other_sids = (num_other_sids != 0) ? 1 : 0;
1284 init_unistr2(&usr->uni_user_name, user_name, len_user_name);
1285 init_unistr2(&usr->uni_full_name, full_name, len_full_name);
1286 init_unistr2(&usr->uni_logon_script, logon_script, len_logon_script);
1287 init_unistr2(&usr->uni_profile_path, profile_path, len_profile_path);
1288 init_unistr2(&usr->uni_home_dir, home_dir, len_home_dir);
1289 init_unistr2(&usr->uni_dir_drive, dir_drive, len_dir_drive);
1291 /* always have at least one group == the user's primary group */
1292 usr->num_groups2 = num_groups+1;
1294 usr->gids = (DOM_GID *)talloc_zero(ctx,sizeof(DOM_GID) * (num_groups+1));
1295 if (usr->gids == NULL)
1296 return;
1298 /* primary group **MUST** go first. NT4's winmsd.exe will give
1299 "The Network statistics are currently not available. 9-5"
1300 What the heck is this? -- jerry */
1301 usr->gids[0].g_rid = usr->group_rid;
1302 usr->gids[0].attr = 0x07;
1303 for (i = 0; i < num_groups; i++)
1304 usr->gids[i+1] = gids[i];
1306 init_unistr2(&usr->uni_logon_srv, logon_srv, len_logon_srv);
1307 init_unistr2(&usr->uni_logon_dom, logon_dom, len_logon_dom);
1309 init_dom_sid2(&usr->dom_sid, dom_sid);
1310 /* "other" sids are set up above */
1313 /*******************************************************************
1314 This code has been modified to cope with a NET_USER_INFO_2 - which is
1315 exactly the same as a NET_USER_INFO_3, minus the other sids parameters.
1316 We use validation level to determine if we're marshalling a info 2 or
1317 INFO_3 - be we always return an INFO_3. Based on code donated by Marc
1318 Jacobsen at HP. JRA.
1319 ********************************************************************/
1321 static BOOL net_io_user_info3(char *desc, NET_USER_INFO_3 *usr, prs_struct *ps, int depth, uint16 validation_level)
1323 int i;
1325 if (usr == NULL)
1326 return False;
1328 prs_debug(ps, depth, desc, "lsa_io_lsa_user_info");
1329 depth++;
1331 if (UNMARSHALLING(ps))
1332 ZERO_STRUCTP(usr);
1334 if(!prs_align(ps))
1335 return False;
1337 if(!prs_uint32("ptr_user_info ", ps, depth, &usr->ptr_user_info))
1338 return False;
1340 if (usr->ptr_user_info == 0)
1341 return True;
1343 if(!smb_io_time("logon time", &usr->logon_time, ps, depth)) /* logon time */
1344 return False;
1345 if(!smb_io_time("logoff time", &usr->logoff_time, ps, depth)) /* logoff time */
1346 return False;
1347 if(!smb_io_time("kickoff time", &usr->kickoff_time, ps, depth)) /* kickoff time */
1348 return False;
1349 if(!smb_io_time("last set time", &usr->pass_last_set_time, ps, depth)) /* password last set time */
1350 return False;
1351 if(!smb_io_time("can change time", &usr->pass_can_change_time , ps, depth)) /* password can change time */
1352 return False;
1353 if(!smb_io_time("must change time", &usr->pass_must_change_time, ps, depth)) /* password must change time */
1354 return False;
1356 if(!smb_io_unihdr("unihdr", &usr->hdr_user_name, ps, depth)) /* username unicode string header */
1357 return False;
1358 if(!smb_io_unihdr("unihdr", &usr->hdr_full_name, ps, depth)) /* user's full name unicode string header */
1359 return False;
1360 if(!smb_io_unihdr("unihdr", &usr->hdr_logon_script, ps, depth)) /* logon script unicode string header */
1361 return False;
1362 if(!smb_io_unihdr("unihdr", &usr->hdr_profile_path, ps, depth)) /* profile path unicode string header */
1363 return False;
1364 if(!smb_io_unihdr("unihdr", &usr->hdr_home_dir, ps, depth)) /* home directory unicode string header */
1365 return False;
1366 if(!smb_io_unihdr("unihdr", &usr->hdr_dir_drive, ps, depth)) /* home directory drive unicode string header */
1367 return False;
1369 if(!prs_uint16("logon_count ", ps, depth, &usr->logon_count)) /* logon count */
1370 return False;
1371 if(!prs_uint16("bad_pw_count ", ps, depth, &usr->bad_pw_count)) /* bad password count */
1372 return False;
1374 if(!prs_uint32("user_rid ", ps, depth, &usr->user_rid)) /* User RID */
1375 return False;
1376 if(!prs_uint32("group_rid ", ps, depth, &usr->group_rid)) /* Group RID */
1377 return False;
1378 if(!prs_uint32("num_groups ", ps, depth, &usr->num_groups)) /* num groups */
1379 return False;
1380 if(!prs_uint32("buffer_groups ", ps, depth, &usr->buffer_groups)) /* undocumented buffer pointer to groups. */
1381 return False;
1382 if(!prs_uint32("user_flgs ", ps, depth, &usr->user_flgs)) /* user flags */
1383 return False;
1385 if(!prs_uint8s(False, "user_sess_key", ps, depth, usr->user_sess_key, 16)) /* unused user session key */
1386 return False;
1388 if(!smb_io_unihdr("unihdr", &usr->hdr_logon_srv, ps, depth)) /* logon server unicode string header */
1389 return False;
1390 if(!smb_io_unihdr("unihdr", &usr->hdr_logon_dom, ps, depth)) /* logon domain unicode string header */
1391 return False;
1393 if(!prs_uint32("buffer_dom_id ", ps, depth, &usr->buffer_dom_id)) /* undocumented logon domain id pointer */
1394 return False;
1395 if(!prs_uint8s (False, "padding ", ps, depth, usr->padding, 40)) /* unused padding bytes? */
1396 return False;
1398 if (validation_level == 3) {
1399 if(!prs_uint32("num_other_sids", ps, depth, &usr->num_other_sids)) /* 0 - num_sids */
1400 return False;
1401 if(!prs_uint32("buffer_other_sids", ps, depth, &usr->buffer_other_sids)) /* NULL - undocumented pointer to SIDs. */
1402 return False;
1403 } else {
1404 if (UNMARSHALLING(ps)) {
1405 usr->num_other_sids = 0;
1406 usr->buffer_other_sids = 0;
1410 if(!smb_io_unistr2("unistr2", &usr->uni_user_name, usr->hdr_user_name.buffer, ps, depth)) /* username unicode string */
1411 return False;
1412 if(!smb_io_unistr2("unistr2", &usr->uni_full_name, usr->hdr_full_name.buffer, ps, depth)) /* user's full name unicode string */
1413 return False;
1414 if(!smb_io_unistr2("unistr2", &usr->uni_logon_script, usr->hdr_logon_script.buffer, ps, depth)) /* logon script unicode string */
1415 return False;
1416 if(!smb_io_unistr2("unistr2", &usr->uni_profile_path, usr->hdr_profile_path.buffer, ps, depth)) /* profile path unicode string */
1417 return False;
1418 if(!smb_io_unistr2("unistr2", &usr->uni_home_dir, usr->hdr_home_dir.buffer, ps, depth)) /* home directory unicode string */
1419 return False;
1420 if(!smb_io_unistr2("unistr2", &usr->uni_dir_drive, usr->hdr_dir_drive.buffer, ps, depth)) /* home directory drive unicode string */
1421 return False;
1423 if(!prs_align(ps))
1424 return False;
1425 if(!prs_uint32("num_groups2 ", ps, depth, &usr->num_groups2)) /* num groups */
1426 return False;
1428 if (UNMARSHALLING(ps) && usr->num_groups2 > 0) {
1429 usr->gids = (DOM_GID *)prs_alloc_mem(ps, sizeof(DOM_GID)*usr->num_groups2);
1430 if (usr->gids == NULL)
1431 return False;
1434 for (i = 0; i < usr->num_groups2; i++) {
1435 if(!smb_io_gid("", &usr->gids[i], ps, depth)) /* group info */
1436 return False;
1439 if(!smb_io_unistr2("unistr2", &usr->uni_logon_srv, usr->hdr_logon_srv.buffer, ps, depth)) /* logon server unicode string */
1440 return False;
1441 if(!smb_io_unistr2("unistr2", &usr->uni_logon_dom, usr->hdr_logon_srv.buffer, ps, depth)) /* logon domain unicode string */
1442 return False;
1444 if(!smb_io_dom_sid2("", &usr->dom_sid, ps, depth)) /* domain SID */
1445 return False;
1447 if (usr->num_other_sids) {
1449 if (UNMARSHALLING(ps)) {
1450 usr->other_sids = (DOM_SID2 *)prs_alloc_mem(ps, sizeof(DOM_SID2)*usr->num_other_sids);
1451 if (usr->other_sids == NULL)
1452 return False;
1455 if(!prs_uint32("num_other_groups", ps, depth, &usr->num_other_groups))
1456 return False;
1458 if (UNMARSHALLING(ps) && usr->num_other_groups > 0) {
1459 usr->other_gids = (DOM_GID *)prs_alloc_mem(ps, sizeof(DOM_GID)*usr->num_other_groups);
1460 if (usr->other_gids == NULL)
1461 return False;
1464 for (i = 0; i < usr->num_other_groups; i++) {
1465 if(!smb_io_gid("", &usr->other_gids[i], ps, depth)) /* other GIDs */
1466 return False;
1468 for (i = 0; i < usr->num_other_sids; i++) {
1469 if(!smb_io_dom_sid2("", &usr->other_sids[i], ps, depth)) /* other domain SIDs */
1470 return False;
1474 return True;
1477 /*******************************************************************
1478 Reads or writes a structure.
1479 ********************************************************************/
1481 BOOL net_io_q_sam_logon(char *desc, NET_Q_SAM_LOGON *q_l, prs_struct *ps, int depth)
1483 if (q_l == NULL)
1484 return False;
1486 prs_debug(ps, depth, desc, "net_io_q_sam_logon");
1487 depth++;
1489 if(!prs_align(ps))
1490 return False;
1492 if(!smb_io_sam_info("", &q_l->sam_id, ps, depth))
1493 return False;
1495 if(!prs_uint16("validation_level", ps, depth, &q_l->validation_level))
1496 return False;
1498 return True;
1501 /*******************************************************************
1502 Reads or writes a structure.
1503 ********************************************************************/
1505 BOOL net_io_r_sam_logon(char *desc, NET_R_SAM_LOGON *r_l, prs_struct *ps, int depth)
1507 if (r_l == NULL)
1508 return False;
1510 prs_debug(ps, depth, desc, "net_io_r_sam_logon");
1511 depth++;
1513 if(!prs_uint32("buffer_creds", ps, depth, &r_l->buffer_creds)) /* undocumented buffer pointer */
1514 return False;
1515 if(!smb_io_cred("", &r_l->srv_creds, ps, depth)) /* server credentials. server time stamp appears to be ignored. */
1516 return False;
1518 if(!prs_uint16("switch_value", ps, depth, &r_l->switch_value))
1519 return False;
1520 if(!prs_align(ps))
1521 return False;
1523 #if 1 /* W2k always needs this - even for bad passwd. JRA */
1524 if(!net_io_user_info3("", r_l->user, ps, depth, r_l->switch_value))
1525 return False;
1526 #else
1527 if (r_l->switch_value != 0) {
1528 if(!net_io_user_info3("", r_l->user, ps, depth, r_l->switch_value))
1529 return False;
1531 #endif
1533 if(!prs_uint32("auth_resp ", ps, depth, &r_l->auth_resp)) /* 1 - Authoritative response; 0 - Non-Auth? */
1534 return False;
1536 if(!prs_ntstatus("status ", ps, depth, &r_l->status))
1537 return False;
1539 if(!prs_align(ps))
1540 return False;
1542 return True;
1545 /*******************************************************************
1546 Reads or writes a structure.
1547 ********************************************************************/
1549 BOOL net_io_q_sam_logoff(char *desc, NET_Q_SAM_LOGOFF *q_l, prs_struct *ps, int depth)
1551 if (q_l == NULL)
1552 return False;
1554 prs_debug(ps, depth, desc, "net_io_q_sam_logoff");
1555 depth++;
1557 if(!prs_align(ps))
1558 return False;
1560 if(!smb_io_sam_info("", &q_l->sam_id, ps, depth)) /* domain SID */
1561 return False;
1563 return True;
1566 /*******************************************************************
1567 Reads or writes a structure.
1568 ********************************************************************/
1570 BOOL net_io_r_sam_logoff(char *desc, NET_R_SAM_LOGOFF *r_l, prs_struct *ps, int depth)
1572 if (r_l == NULL)
1573 return False;
1575 prs_debug(ps, depth, desc, "net_io_r_sam_logoff");
1576 depth++;
1578 if(!prs_align(ps))
1579 return False;
1581 if(!prs_uint32("buffer_creds", ps, depth, &r_l->buffer_creds)) /* undocumented buffer pointer */
1582 return False;
1583 if(!smb_io_cred("", &r_l->srv_creds, ps, depth)) /* server credentials. server time stamp appears to be ignored. */
1584 return False;
1586 if(!prs_ntstatus("status ", ps, depth, &r_l->status))
1587 return False;
1589 return True;
1592 /*******************************************************************
1593 makes a NET_Q_SAM_SYNC structure.
1594 ********************************************************************/
1595 BOOL init_net_q_sam_sync(NET_Q_SAM_SYNC * q_s, const char *srv_name,
1596 const char *cli_name, DOM_CRED * cli_creds,
1597 DOM_CRED *ret_creds, uint32 database_id)
1599 DEBUG(5, ("init_q_sam_sync\n"));
1601 init_unistr2(&q_s->uni_srv_name, srv_name, strlen(srv_name) + 1);
1602 init_unistr2(&q_s->uni_cli_name, cli_name, strlen(cli_name) + 1);
1604 if (cli_creds)
1605 memcpy(&q_s->cli_creds, cli_creds, sizeof(q_s->cli_creds));
1607 if (cli_creds)
1608 memcpy(&q_s->ret_creds, ret_creds, sizeof(q_s->ret_creds));
1609 else
1610 memset(&q_s->ret_creds, 0, sizeof(q_s->ret_creds));
1612 q_s->database_id = database_id;
1613 q_s->restart_state = 0;
1614 q_s->sync_context = 0;
1615 q_s->max_size = 0xffff;
1617 return True;
1620 /*******************************************************************
1621 reads or writes a structure.
1622 ********************************************************************/
1623 BOOL net_io_q_sam_sync(char *desc, NET_Q_SAM_SYNC * q_s, prs_struct *ps,
1624 int depth)
1626 prs_debug(ps, depth, desc, "net_io_q_sam_sync");
1627 depth++;
1629 if (!smb_io_unistr2("", &q_s->uni_srv_name, True, ps, depth))
1630 return False;
1631 if (!smb_io_unistr2("", &q_s->uni_cli_name, True, ps, depth))
1632 return False;
1634 if (!smb_io_cred("", &q_s->cli_creds, ps, depth))
1635 return False;
1636 if (!smb_io_cred("", &q_s->ret_creds, ps, depth))
1637 return False;
1639 if (!prs_uint32("database_id ", ps, depth, &q_s->database_id))
1640 return False;
1641 if (!prs_uint32("restart_state", ps, depth, &q_s->restart_state))
1642 return False;
1643 if (!prs_uint32("sync_context ", ps, depth, &q_s->sync_context))
1644 return False;
1646 if (!prs_uint32("max_size", ps, depth, &q_s->max_size))
1647 return False;
1649 return True;
1652 /*******************************************************************
1653 reads or writes a structure.
1654 ********************************************************************/
1655 static BOOL net_io_sam_delta_hdr(char *desc, SAM_DELTA_HDR * delta,
1656 prs_struct *ps, int depth)
1658 prs_debug(ps, depth, desc, "net_io_sam_delta_hdr");
1659 depth++;
1661 if (!prs_uint16("type", ps, depth, &delta->type))
1662 return False;
1663 if (!prs_uint16("type2", ps, depth, &delta->type2))
1664 return False;
1665 if (!prs_uint32("target_rid", ps, depth, &delta->target_rid))
1666 return False;
1668 if (!prs_uint32("type3", ps, depth, &delta->type3))
1669 return False;
1671 /* Not sure why we need this but it seems to be necessary to get
1672 sam deltas working. */
1674 if (delta->type != 0x16) {
1675 if (!prs_uint32("ptr_delta", ps, depth, &delta->ptr_delta))
1676 return False;
1679 return True;
1682 /*******************************************************************
1683 reads or writes a structure.
1684 ********************************************************************/
1685 static BOOL net_io_sam_delta_stamp(char *desc, SAM_DELTA_STAMP *info,
1686 prs_struct *ps, int depth)
1688 prs_debug(ps, depth, desc, "net_io_sam_delta_stamp");
1689 depth++;
1691 if (!prs_uint32("seqnum", ps, depth, &info->seqnum))
1692 return False;
1693 if (!prs_uint32("dom_mod_count_ptr", ps, depth,
1694 &info->dom_mod_count_ptr))
1695 return False;
1697 if (info->dom_mod_count_ptr) {
1698 if (!prs_uint64("dom_mod_count", ps, depth,
1699 &info->dom_mod_count))
1700 return False;
1703 return True;
1706 /*******************************************************************
1707 reads or writes a structure.
1708 ********************************************************************/
1709 static BOOL net_io_sam_domain_info(char *desc, SAM_DOMAIN_INFO * info,
1710 prs_struct *ps, int depth)
1712 prs_debug(ps, depth, desc, "net_io_sam_domain_info");
1713 depth++;
1715 if (!smb_io_unihdr("hdr_dom_name", &info->hdr_dom_name, ps, depth))
1716 return False;
1717 if (!smb_io_unihdr("hdr_oem_info", &info->hdr_oem_info, ps, depth))
1718 return False;
1720 if (!prs_uint64("force_logoff", ps, depth, &info->force_logoff))
1721 return False;
1722 if (!prs_uint16("min_pwd_len", ps, depth, &info->min_pwd_len))
1723 return False;
1724 if (!prs_uint16("pwd_history_len", ps, depth, &info->pwd_history_len))
1725 return False;
1726 if (!prs_uint64("max_pwd_age", ps, depth, &info->max_pwd_age))
1727 return False;
1728 if (!prs_uint64("min_pwd_age", ps, depth, &info->min_pwd_age))
1729 return False;
1730 if (!prs_uint64("dom_mod_count", ps, depth, &info->dom_mod_count))
1731 return False;
1732 if (!smb_io_time("creation_time", &info->creation_time, ps, depth))
1733 return False;
1735 if (!smb_io_bufhdr2("hdr_sec_desc", &info->hdr_sec_desc, ps, depth))
1736 return False;
1737 if (!smb_io_unihdr("hdr_unknown", &info->hdr_unknown, ps, depth))
1738 return False;
1740 if (ps->data_offset + 40 > ps->buffer_size)
1741 return False;
1742 ps->data_offset += 40;
1744 if (!smb_io_unistr2("uni_dom_name", &info->uni_dom_name,
1745 info->hdr_dom_name.buffer, ps, depth))
1746 return False;
1747 if (!smb_io_unistr2("buf_oem_info", &info->buf_oem_info,
1748 info->hdr_oem_info.buffer, ps, depth))
1749 return False;
1751 if (!smb_io_buffer4("buf_sec_desc", &info->buf_sec_desc,
1752 info->hdr_sec_desc.buffer, ps, depth))
1753 return False;
1754 if (!smb_io_unistr2("buf_unknown", &info->buf_unknown,
1755 info->hdr_unknown.buffer, ps, depth))
1756 return False;
1758 return True;
1761 /*******************************************************************
1762 reads or writes a structure.
1763 ********************************************************************/
1764 static BOOL net_io_sam_group_info(char *desc, SAM_GROUP_INFO * info,
1765 prs_struct *ps, int depth)
1767 prs_debug(ps, depth, desc, "net_io_sam_group_info");
1768 depth++;
1770 if (!smb_io_unihdr("hdr_grp_name", &info->hdr_grp_name, ps, depth))
1771 return False;
1772 if (!smb_io_gid("gid", &info->gid, ps, depth))
1773 return False;
1774 if (!smb_io_unihdr("hdr_grp_desc", &info->hdr_grp_desc, ps, depth))
1775 return False;
1776 if (!smb_io_bufhdr2("hdr_sec_desc", &info->hdr_sec_desc, ps, depth))
1777 return False;
1779 if (ps->data_offset + 48 > ps->buffer_size)
1780 return False;
1781 ps->data_offset += 48;
1783 if (!smb_io_unistr2("uni_grp_name", &info->uni_grp_name,
1784 info->hdr_grp_name.buffer, ps, depth))
1785 return False;
1786 if (!smb_io_unistr2("uni_grp_desc", &info->uni_grp_desc,
1787 info->hdr_grp_desc.buffer, ps, depth))
1788 return False;
1789 if (!smb_io_buffer4("buf_sec_desc", &info->buf_sec_desc,
1790 info->hdr_sec_desc.buffer, ps, depth))
1791 return False;
1793 return True;
1796 /*******************************************************************
1797 reads or writes a structure.
1798 ********************************************************************/
1799 static BOOL net_io_sam_passwd_info(char *desc, SAM_PWD * pwd,
1800 prs_struct *ps, int depth)
1802 prs_debug(ps, depth, desc, "net_io_sam_passwd_info");
1803 depth++;
1805 if (!prs_uint32("unk_0 ", ps, depth, &pwd->unk_0))
1806 return False;
1808 if (!smb_io_unihdr("hdr_lm_pwd", &pwd->hdr_lm_pwd, ps, depth))
1809 return False;
1810 if (!prs_uint8s(False, "buf_lm_pwd", ps, depth, pwd->buf_lm_pwd, 16))
1811 return False;
1813 if (!smb_io_unihdr("hdr_nt_pwd", &pwd->hdr_nt_pwd, ps, depth))
1814 return False;
1815 if (!prs_uint8s(False, "buf_nt_pwd", ps, depth, pwd->buf_nt_pwd, 16))
1816 return False;
1818 if (!smb_io_unihdr("", &pwd->hdr_empty_lm, ps, depth))
1819 return False;
1820 if (!smb_io_unihdr("", &pwd->hdr_empty_nt, ps, depth))
1821 return False;
1823 return True;
1826 /*******************************************************************
1827 makes a SAM_ACCOUNT_INFO structure.
1828 ********************************************************************/
1829 BOOL make_sam_account_info(SAM_ACCOUNT_INFO * info,
1830 const UNISTR2 *user_name,
1831 const UNISTR2 *full_name,
1832 uint32 user_rid, uint32 group_rid,
1833 const UNISTR2 *home_dir,
1834 const UNISTR2 *dir_drive,
1835 const UNISTR2 *log_scr,
1836 const UNISTR2 *desc,
1837 uint32 acb_info,
1838 const UNISTR2 *prof_path,
1839 const UNISTR2 *wkstas,
1840 const UNISTR2 *unk_str, const UNISTR2 *mung_dial)
1842 int len_user_name = user_name != NULL ? user_name->uni_str_len : 0;
1843 int len_full_name = full_name != NULL ? full_name->uni_str_len : 0;
1844 int len_home_dir = home_dir != NULL ? home_dir->uni_str_len : 0;
1845 int len_dir_drive = dir_drive != NULL ? dir_drive->uni_str_len : 0;
1846 int len_logon_script = log_scr != NULL ? log_scr->uni_str_len : 0;
1847 int len_profile_path = prof_path != NULL ? prof_path->uni_str_len : 0;
1848 int len_description = desc != NULL ? desc->uni_str_len : 0;
1849 int len_workstations = wkstas != NULL ? wkstas->uni_str_len : 0;
1850 int len_unknown_str = unk_str != NULL ? unk_str->uni_str_len : 0;
1851 int len_munged_dial = mung_dial != NULL ? mung_dial->uni_str_len : 0;
1853 DEBUG(5, ("make_sam_account_info\n"));
1855 make_uni_hdr(&info->hdr_acct_name, len_user_name);
1856 make_uni_hdr(&info->hdr_full_name, len_full_name);
1857 make_uni_hdr(&info->hdr_home_dir, len_home_dir);
1858 make_uni_hdr(&info->hdr_dir_drive, len_dir_drive);
1859 make_uni_hdr(&info->hdr_logon_script, len_logon_script);
1860 make_uni_hdr(&info->hdr_profile, len_profile_path);
1861 make_uni_hdr(&info->hdr_acct_desc, len_description);
1862 make_uni_hdr(&info->hdr_workstations, len_workstations);
1863 make_uni_hdr(&info->hdr_comment, len_unknown_str);
1864 make_uni_hdr(&info->hdr_parameters, len_munged_dial);
1866 /* not present */
1867 make_bufhdr2(&info->hdr_sec_desc, 0, 0, 0);
1869 info->user_rid = user_rid;
1870 info->group_rid = group_rid;
1872 init_nt_time(&info->logon_time);
1873 init_nt_time(&info->logoff_time);
1874 init_nt_time(&info->pwd_last_set_time);
1875 init_nt_time(&info->acct_expiry_time);
1877 info->logon_divs = 0xA8;
1878 info->ptr_logon_hrs = 0; /* Don't care right now */
1880 info->bad_pwd_count = 0;
1881 info->logon_count = 0;
1882 info->acb_info = acb_info;
1883 info->nt_pwd_present = 0;
1884 info->lm_pwd_present = 0;
1885 info->pwd_expired = 0;
1886 info->country = 0;
1887 info->codepage = 0;
1889 info->unknown1 = 0x4EC;
1890 info->unknown2 = 0;
1892 copy_unistr2(&info->uni_acct_name, user_name);
1893 copy_unistr2(&info->uni_full_name, full_name);
1894 copy_unistr2(&info->uni_home_dir, home_dir);
1895 copy_unistr2(&info->uni_dir_drive, dir_drive);
1896 copy_unistr2(&info->uni_logon_script, log_scr);
1897 copy_unistr2(&info->uni_profile, prof_path);
1898 copy_unistr2(&info->uni_acct_desc, desc);
1899 copy_unistr2(&info->uni_workstations, wkstas);
1900 copy_unistr2(&info->uni_comment, unk_str);
1901 copy_unistr2(&info->uni_parameters, mung_dial);
1903 return True;
1906 /*******************************************************************
1907 reads or writes a structure.
1908 ********************************************************************/
1909 static BOOL net_io_sam_account_info(char *desc, uint8 sess_key[16],
1910 SAM_ACCOUNT_INFO * info, prs_struct *ps,
1911 int depth)
1913 BUFHDR2 hdr_priv_data;
1914 uint32 i;
1916 prs_debug(ps, depth, desc, "net_io_sam_account_info");
1917 depth++;
1919 if (!smb_io_unihdr("hdr_acct_name", &info->hdr_acct_name, ps, depth))
1920 return False;
1921 if (!smb_io_unihdr("hdr_full_name", &info->hdr_full_name, ps, depth))
1922 return False;
1924 if (!prs_uint32("user_rid ", ps, depth, &info->user_rid))
1925 return False;
1926 if (!prs_uint32("group_rid", ps, depth, &info->group_rid))
1927 return False;
1929 if (!smb_io_unihdr("hdr_home_dir ", &info->hdr_home_dir, ps, depth))
1930 return False;
1931 if (!smb_io_unihdr("hdr_dir_drive", &info->hdr_dir_drive, ps, depth))
1932 return False;
1933 if (!smb_io_unihdr("hdr_logon_script", &info->hdr_logon_script, ps,
1934 depth))
1935 return False;
1937 if (!smb_io_unihdr("hdr_acct_desc", &info->hdr_acct_desc, ps, depth))
1938 return False;
1939 if (!smb_io_unihdr("hdr_workstations", &info->hdr_workstations, ps,
1940 depth))
1941 return False;
1943 if (!smb_io_time("logon_time", &info->logon_time, ps, depth))
1944 return False;
1945 if (!smb_io_time("logoff_time", &info->logoff_time, ps, depth))
1946 return False;
1948 if (!prs_uint32("logon_divs ", ps, depth, &info->logon_divs))
1949 return False;
1950 if (!prs_uint32("ptr_logon_hrs", ps, depth, &info->ptr_logon_hrs))
1951 return False;
1953 if (!prs_uint16("bad_pwd_count", ps, depth, &info->bad_pwd_count))
1954 return False;
1955 if (!prs_uint16("logon_count", ps, depth, &info->logon_count))
1956 return False;
1957 if (!smb_io_time("pwd_last_set_time", &info->pwd_last_set_time, ps,
1958 depth))
1959 return False;
1960 if (!smb_io_time("acct_expiry_time", &info->acct_expiry_time, ps,
1961 depth))
1962 return False;
1964 if (!prs_uint32("acb_info", ps, depth, &info->acb_info))
1965 return False;
1966 if (!prs_uint8s(False, "nt_pwd", ps, depth, info->nt_pwd, 16))
1967 return False;
1968 if (!prs_uint8s(False, "lm_pwd", ps, depth, info->lm_pwd, 16))
1969 return False;
1970 if (!prs_uint8("lm_pwd_present", ps, depth, &info->lm_pwd_present))
1971 return False;
1972 if (!prs_uint8("nt_pwd_present", ps, depth, &info->nt_pwd_present))
1973 return False;
1974 if (!prs_uint8("pwd_expired", ps, depth, &info->pwd_expired))
1975 return False;
1977 if (!smb_io_unihdr("hdr_comment", &info->hdr_comment, ps, depth))
1978 return False;
1979 if (!smb_io_unihdr("hdr_parameters", &info->hdr_parameters, ps,
1980 depth))
1981 return False;
1982 if (!prs_uint16("country", ps, depth, &info->country))
1983 return False;
1984 if (!prs_uint16("codepage", ps, depth, &info->codepage))
1985 return False;
1987 if (!smb_io_bufhdr2("hdr_priv_data", &hdr_priv_data, ps, depth))
1988 return False;
1989 if (!smb_io_bufhdr2("hdr_sec_desc", &info->hdr_sec_desc, ps, depth))
1990 return False;
1991 if (!smb_io_unihdr("hdr_profile", &info->hdr_profile, ps, depth))
1992 return False;
1994 for (i = 0; i < 3; i++)
1996 if (!smb_io_unihdr("hdr_reserved", &info->hdr_reserved[i],
1997 ps, depth))
1998 return False;
2001 for (i = 0; i < 4; i++)
2003 if (!prs_uint32("dw_reserved", ps, depth,
2004 &info->dw_reserved[i]))
2005 return False;
2008 if (!smb_io_unistr2("uni_acct_name", &info->uni_acct_name,
2009 info->hdr_acct_name.buffer, ps, depth))
2010 return False;
2011 prs_align(ps);
2012 if (!smb_io_unistr2("uni_full_name", &info->uni_full_name,
2013 info->hdr_full_name.buffer, ps, depth))
2014 return False;
2015 prs_align(ps);
2016 if (!smb_io_unistr2("uni_home_dir ", &info->uni_home_dir,
2017 info->hdr_home_dir.buffer, ps, depth))
2018 return False;
2019 prs_align(ps);
2020 if (!smb_io_unistr2("uni_dir_drive", &info->uni_dir_drive,
2021 info->hdr_dir_drive.buffer, ps, depth))
2022 return False;
2023 prs_align(ps);
2024 if (!smb_io_unistr2("uni_logon_script", &info->uni_logon_script,
2025 info->hdr_logon_script.buffer, ps, depth))
2026 return False;
2027 prs_align(ps);
2028 if (!smb_io_unistr2("uni_acct_desc", &info->uni_acct_desc,
2029 info->hdr_acct_desc.buffer, ps, depth))
2030 return False;
2031 prs_align(ps);
2032 if (!smb_io_unistr2("uni_workstations", &info->uni_workstations,
2033 info->hdr_workstations.buffer, ps, depth))
2034 return False;
2035 prs_align(ps);
2037 if (!prs_uint32("unknown1", ps, depth, &info->unknown1))
2038 return False;
2039 if (!prs_uint32("unknown2", ps, depth, &info->unknown2))
2040 return False;
2042 if (!smb_io_buffer4("buf_logon_hrs", &info->buf_logon_hrs,
2043 info->ptr_logon_hrs, ps, depth))
2044 return False;
2045 prs_align(ps);
2046 if (!smb_io_unistr2("uni_comment", &info->uni_comment,
2047 info->hdr_comment.buffer, ps, depth))
2048 return False;
2049 prs_align(ps);
2050 if (!smb_io_unistr2("uni_parameters", &info->uni_parameters,
2051 info->hdr_parameters.buffer, ps, depth))
2052 return False;
2053 prs_align(ps);
2054 if (hdr_priv_data.buffer != 0)
2056 int old_offset = 0;
2057 uint32 len = 0x44;
2058 if (!prs_uint32("pwd_len", ps, depth, &len))
2059 return False;
2060 old_offset = ps->data_offset;
2061 if (len == 0x44)
2063 if (ps->io)
2065 /* reading */
2066 if (!prs_hash1(ps, ps->data_offset, sess_key))
2067 return False;
2069 if (!net_io_sam_passwd_info("pass", &info->pass,
2070 ps, depth))
2071 return False;
2073 if (!ps->io)
2075 /* writing */
2076 if (!prs_hash1(ps, old_offset, sess_key))
2077 return False;
2080 if (old_offset + len > ps->buffer_size)
2081 return False;
2082 ps->data_offset = old_offset + len;
2084 if (!smb_io_buffer4("buf_sec_desc", &info->buf_sec_desc,
2085 info->hdr_sec_desc.buffer, ps, depth))
2086 return False;
2087 prs_align(ps);
2088 if (!smb_io_unistr2("uni_profile", &info->uni_profile,
2089 info->hdr_profile.buffer, ps, depth))
2090 return False;
2092 prs_align(ps);
2094 return True;
2097 /*******************************************************************
2098 reads or writes a structure.
2099 ********************************************************************/
2100 static BOOL net_io_sam_group_mem_info(char *desc, SAM_GROUP_MEM_INFO * info,
2101 prs_struct *ps, int depth)
2103 uint32 i;
2104 fstring tmp;
2106 prs_debug(ps, depth, desc, "net_io_sam_group_mem_info");
2107 depth++;
2109 prs_align(ps);
2110 if (!prs_uint32("ptr_rids ", ps, depth, &info->ptr_rids))
2111 return False;
2112 if (!prs_uint32("ptr_attribs", ps, depth, &info->ptr_attribs))
2113 return False;
2114 if (!prs_uint32("num_members", ps, depth, &info->num_members))
2115 return False;
2117 if (ps->data_offset + 16 > ps->buffer_size)
2118 return False;
2119 ps->data_offset += 16;
2121 if (info->ptr_rids != 0)
2123 if (!prs_uint32("num_members2", ps, depth,
2124 &info->num_members2))
2125 return False;
2127 if (info->num_members2 != info->num_members)
2129 /* RPC fault */
2130 return False;
2133 info->rids = talloc(ps->mem_ctx, sizeof(uint32) *
2134 info->num_members2);
2136 if (info->rids == NULL) {
2137 DEBUG(0, ("out of memory allocating %d rids\n",
2138 info->num_members2));
2139 return False;
2142 for (i = 0; i < info->num_members2; i++)
2144 slprintf(tmp, sizeof(tmp) - 1, "rids[%02d]", i);
2145 if (!prs_uint32(tmp, ps, depth, &info->rids[i]))
2146 return False;
2150 if (info->ptr_attribs != 0)
2152 if (!prs_uint32("num_members3", ps, depth,
2153 &info->num_members3))
2154 return False;
2155 if (info->num_members3 != info->num_members)
2157 /* RPC fault */
2158 return False;
2161 info->attribs = talloc(ps->mem_ctx, sizeof(uint32) *
2162 info->num_members3);
2164 if (info->attribs == NULL) {
2165 DEBUG(0, ("out of memory allocating %d attribs\n",
2166 info->num_members3));
2167 return False;
2170 for (i = 0; i < info->num_members3; i++)
2172 slprintf(tmp, sizeof(tmp) - 1, "attribs[%02d]", i);
2173 if (!prs_uint32(tmp, ps, depth, &info->attribs[i]))
2174 return False;
2178 return True;
2181 /*******************************************************************
2182 reads or writes a structure.
2183 ********************************************************************/
2184 static BOOL net_io_sam_alias_info(char *desc, SAM_ALIAS_INFO * info,
2185 prs_struct *ps, int depth)
2187 prs_debug(ps, depth, desc, "net_io_sam_alias_info");
2188 depth++;
2190 if (!smb_io_unihdr("hdr_als_name", &info->hdr_als_name, ps, depth))
2191 return False;
2192 if (!prs_uint32("als_rid", ps, depth, &info->als_rid))
2193 return False;
2194 if (!smb_io_bufhdr2("hdr_sec_desc", &info->hdr_sec_desc, ps, depth))
2195 return False;
2196 if (!smb_io_unihdr("hdr_als_desc", &info->hdr_als_desc, ps, depth))
2197 return False;
2199 if (ps->data_offset + 40 > ps->buffer_size)
2200 return False;
2201 ps->data_offset += 40;
2203 if (!smb_io_unistr2("uni_als_name", &info->uni_als_name,
2204 info->hdr_als_name.buffer, ps, depth))
2205 return False;
2206 if (!smb_io_buffer4("buf_sec_desc", &info->buf_sec_desc,
2207 info->hdr_sec_desc.buffer, ps, depth))
2208 return False;
2209 if (!smb_io_unistr2("uni_als_desc", &info->uni_als_desc,
2210 info->hdr_als_name.buffer, ps, depth))
2211 return False;
2213 return True;
2216 /*******************************************************************
2217 reads or writes a structure.
2218 ********************************************************************/
2219 static BOOL net_io_sam_alias_mem_info(char *desc, SAM_ALIAS_MEM_INFO * info,
2220 prs_struct *ps, int depth)
2222 uint32 i;
2223 fstring tmp;
2225 prs_debug(ps, depth, desc, "net_io_sam_alias_mem_info");
2226 depth++;
2228 prs_align(ps);
2229 if (!prs_uint32("num_members", ps, depth, &info->num_members))
2230 return False;
2231 if (!prs_uint32("ptr_members", ps, depth, &info->ptr_members))
2232 return False;
2234 if (info->ptr_members != 0)
2236 if (ps->data_offset + 16 > ps->buffer_size)
2237 return False;
2238 ps->data_offset += 16;
2240 if (!prs_uint32("num_sids", ps, depth, &info->num_sids))
2241 return False;
2242 if (info->num_sids != info->num_members)
2244 /* RPC fault */
2245 return False;
2248 info->ptr_sids = talloc(ps->mem_ctx, sizeof(uint32) *
2249 info->num_sids);
2251 if (info->ptr_sids == NULL) {
2252 DEBUG(0, ("out of memory allocating %d ptr_sids\n",
2253 info->num_sids));
2254 return False;
2257 for (i = 0; i < info->num_sids; i++)
2259 slprintf(tmp, sizeof(tmp) - 1, "ptr_sids[%02d]", i);
2260 if (!prs_uint32(tmp, ps, depth, &info->ptr_sids[i]))
2261 return False;
2264 info->sids = talloc(ps->mem_ctx, sizeof(DOM_SID2) *
2265 info->num_sids);
2267 if (info->sids == NULL) {
2268 DEBUG(0, ("error allocating %d sids\n",
2269 info->num_sids));
2270 return False;
2273 for (i = 0; i < info->num_sids; i++)
2275 if (info->ptr_sids[i] != 0)
2277 slprintf(tmp, sizeof(tmp) - 1, "sids[%02d]",
2279 if (!smb_io_dom_sid2(tmp, &info->sids[i],
2280 ps, depth))
2281 return False;
2286 return True;
2289 /*******************************************************************
2290 reads or writes a structure.
2291 ********************************************************************/
2292 static BOOL net_io_sam_delta_ctr(char *desc, uint8 sess_key[16],
2293 SAM_DELTA_CTR * delta, uint16 type,
2294 prs_struct *ps, int depth)
2296 prs_debug(ps, depth, desc, "net_io_sam_delta_ctr");
2297 depth++;
2299 switch (type)
2301 /* Seen in sam deltas */
2303 case SAM_DELTA_SAM_STAMP:
2305 if (!net_io_sam_delta_stamp("", &delta->stamp,
2306 ps, depth))
2307 return False;
2308 break;
2311 case SAM_DELTA_DOMAIN_INFO:
2313 if (!net_io_sam_domain_info("", &delta->domain_info,
2314 ps, depth))
2315 return False;
2316 break;
2318 case SAM_DELTA_GROUP_INFO:
2320 if (!net_io_sam_group_info("", &delta->group_info,
2321 ps, depth))
2322 return False;
2323 break;
2325 case SAM_DELTA_ACCOUNT_INFO:
2327 if (!net_io_sam_account_info("", sess_key,
2328 &delta->account_info,
2329 ps, depth))
2330 return False;
2331 break;
2333 case SAM_DELTA_GROUP_MEM:
2335 if (!net_io_sam_group_mem_info("",
2336 &delta->grp_mem_info,
2337 ps, depth))
2338 return False;
2339 break;
2341 case SAM_DELTA_ALIAS_INFO:
2343 if (!net_io_sam_alias_info("", &delta->alias_info,
2344 ps, depth))
2345 return False;
2346 break;
2348 case SAM_DELTA_ALIAS_MEM:
2350 if (!net_io_sam_alias_mem_info("",
2351 &delta->als_mem_info,
2352 ps, depth))
2353 return False;
2354 break;
2356 default:
2358 DEBUG(0,
2359 ("Replication error: Unknown delta type 0x%x\n",
2360 type));
2361 break;
2365 return True;
2368 /*******************************************************************
2369 reads or writes a structure.
2370 ********************************************************************/
2371 BOOL net_io_r_sam_sync(char *desc, uint8 sess_key[16],
2372 NET_R_SAM_SYNC * r_s, prs_struct *ps, int depth)
2374 uint32 i;
2376 prs_debug(ps, depth, desc, "net_io_r_sam_sync");
2377 depth++;
2379 if (!smb_io_cred("srv_creds", &r_s->srv_creds, ps, depth))
2380 return False;
2381 if (!prs_uint32("sync_context", ps, depth, &r_s->sync_context))
2382 return False;
2384 if (!prs_uint32("ptr_deltas", ps, depth, &r_s->ptr_deltas))
2385 return False;
2386 if (r_s->ptr_deltas != 0)
2388 if (!prs_uint32("num_deltas ", ps, depth, &r_s->num_deltas))
2389 return False;
2390 if (!prs_uint32("ptr_deltas2", ps, depth, &r_s->ptr_deltas2))
2391 return False;
2392 if (r_s->ptr_deltas2 != 0)
2394 if (!prs_uint32("num_deltas2", ps, depth,
2395 &r_s->num_deltas2))
2396 return False;
2398 if (r_s->num_deltas2 != r_s->num_deltas)
2400 /* RPC fault */
2401 return False;
2404 if (r_s->num_deltas2 > 0) {
2405 r_s->hdr_deltas = (SAM_DELTA_HDR *)
2406 talloc(ps->mem_ctx, r_s->num_deltas2 *
2407 sizeof(SAM_DELTA_HDR));
2409 if (r_s->hdr_deltas == NULL) {
2410 DEBUG(0, ("error tallocating memory "
2411 "for %d delta headers\n",
2412 r_s->num_deltas2));
2413 return False;
2417 for (i = 0; i < r_s->num_deltas2; i++)
2419 if (!net_io_sam_delta_hdr("",
2420 &r_s->hdr_deltas[i],
2421 ps, depth))
2422 return False;
2425 if (r_s->num_deltas2 > 0) {
2426 r_s->deltas = (SAM_DELTA_CTR *)
2427 talloc(ps->mem_ctx, r_s->num_deltas2 *
2428 sizeof(SAM_DELTA_CTR));
2430 if (r_s->deltas == NULL) {
2431 DEBUG(0, ("error tallocating memory "
2432 "for %d deltas\n",
2433 r_s->num_deltas2));
2434 return False;
2438 for (i = 0; i < r_s->num_deltas2; i++)
2440 if (!net_io_sam_delta_ctr(
2441 "", sess_key, &r_s->deltas[i],
2442 r_s->hdr_deltas[i].type3,
2443 ps, depth)) {
2444 DEBUG(0, ("hmm, failed on i=%d\n", i));
2445 return False;
2451 prs_align(ps);
2452 if (!prs_ntstatus("status", ps, depth, &(r_s->status)))
2453 return False;
2455 return True;
2458 /*******************************************************************
2459 makes a NET_Q_SAM_DELTAS structure.
2460 ********************************************************************/
2461 BOOL init_net_q_sam_deltas(NET_Q_SAM_DELTAS *q_s, const char *srv_name,
2462 const char *cli_name, DOM_CRED *cli_creds,
2463 uint32 database_id, UINT64_S dom_mod_count)
2465 DEBUG(5, ("init_net_q_sam_deltas\n"));
2467 init_unistr2(&q_s->uni_srv_name, srv_name, strlen(srv_name) + 1);
2468 init_unistr2(&q_s->uni_cli_name, cli_name, strlen(cli_name) + 1);
2470 memcpy(&q_s->cli_creds, cli_creds, sizeof(q_s->cli_creds));
2471 memset(&q_s->ret_creds, 0, sizeof(q_s->ret_creds));
2473 q_s->database_id = database_id;
2474 q_s->dom_mod_count.low = dom_mod_count.low;
2475 q_s->dom_mod_count.high = dom_mod_count.high;
2476 q_s->max_size = 0xffff;
2478 return True;
2481 /*******************************************************************
2482 reads or writes a structure.
2483 ********************************************************************/
2484 BOOL net_io_q_sam_deltas(char *desc, NET_Q_SAM_DELTAS *q_s, prs_struct *ps,
2485 int depth)
2487 prs_debug(ps, depth, desc, "net_io_q_sam_deltas");
2488 depth++;
2490 if (!smb_io_unistr2("", &q_s->uni_srv_name, True, ps, depth))
2491 return False;
2492 if (!smb_io_unistr2("", &q_s->uni_cli_name, True, ps, depth))
2493 return False;
2495 if (!smb_io_cred("", &q_s->cli_creds, ps, depth))
2496 return False;
2497 if (!smb_io_cred("", &q_s->ret_creds, ps, depth))
2498 return False;
2500 if (!prs_uint32("database_id ", ps, depth, &q_s->database_id))
2501 return False;
2502 if (!prs_uint64("dom_mod_count", ps, depth, &q_s->dom_mod_count))
2503 return False;
2504 if (!prs_uint32("max_size", ps, depth, &q_s->max_size))
2505 return False;
2507 return True;
2510 /*******************************************************************
2511 reads or writes a structure.
2512 ********************************************************************/
2513 BOOL net_io_r_sam_deltas(char *desc, uint8 sess_key[16],
2514 NET_R_SAM_DELTAS *r_s, prs_struct *ps, int depth)
2516 int i;
2518 prs_debug(ps, depth, desc, "net_io_r_sam_deltas");
2519 depth++;
2521 if (!smb_io_cred("srv_creds", &r_s->srv_creds, ps, depth))
2522 return False;
2523 if (!prs_uint64("dom_mod_count", ps, depth, &r_s->dom_mod_count))
2524 return False;
2526 if (!prs_uint32("ptr_deltas", ps, depth, &r_s->ptr_deltas))
2527 return False;
2528 if (!prs_uint32("num_deltas", ps, depth, &r_s->num_deltas))
2529 return False;
2530 if (!prs_uint32("ptr_deltas2", ps, depth, &r_s->num_deltas2))
2531 return False;
2533 if (r_s->num_deltas2 != 0)
2535 if (!prs_uint32("num_deltas2 ", ps, depth, &r_s->num_deltas2))
2536 return False;
2538 if (r_s->ptr_deltas != 0)
2540 if (r_s->num_deltas > 0) {
2541 r_s->hdr_deltas = (SAM_DELTA_HDR *)
2542 talloc(ps->mem_ctx, r_s->num_deltas *
2543 sizeof(SAM_DELTA_HDR));
2544 if (r_s->hdr_deltas == NULL) {
2545 DEBUG(0, ("error tallocating memory "
2546 "for %d delta headers\n",
2547 r_s->num_deltas));
2548 return False;
2552 for (i = 0; i < r_s->num_deltas; i++)
2554 net_io_sam_delta_hdr("", &r_s->hdr_deltas[i],
2555 ps, depth);
2558 if (r_s->num_deltas > 0) {
2559 r_s->deltas = (SAM_DELTA_CTR *)
2560 talloc(ps->mem_ctx, r_s->num_deltas *
2561 sizeof(SAM_DELTA_CTR));
2563 if (r_s->deltas == NULL) {
2564 DEBUG(0, ("error tallocating memory "
2565 "for %d deltas\n",
2566 r_s->num_deltas));
2567 return False;
2571 for (i = 0; i < r_s->num_deltas; i++)
2573 if (!net_io_sam_delta_ctr(
2574 "", sess_key,
2575 &r_s->deltas[i],
2576 r_s->hdr_deltas[i].type2,
2577 ps, depth))
2579 return False;
2584 prs_align(ps);
2585 if (!prs_ntstatus("status", ps, depth, &r_s->status))
2586 return False;
2588 return True;