sync'ing up for 3.0alpha20 release
[Samba.git] / source / rpc_parse / parse_net.c
blobe0f710b2d75362857ba11630185f0beb396c86e7
1 /*
2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines
4 * Copyright (C) Andrew Tridgell 1992-1997,
5 * Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
6 * Copyright (C) Paul Ashton 1997.
7 * Copyright (C) Jean François Micouleau 2002.
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 #undef DBGC_CLASS
27 #define DBGC_CLASS DBGC_RPC_PARSE
29 /*******************************************************************
30 Reads or writes a structure.
31 ********************************************************************/
33 static BOOL net_io_neg_flags(char *desc, NEG_FLAGS *neg, prs_struct *ps, int depth)
35 if (neg == NULL)
36 return False;
38 prs_debug(ps, depth, desc, "net_io_neg_flags");
39 depth++;
41 if(!prs_align(ps))
42 return False;
44 if(!prs_uint32("neg_flags", ps, depth, &neg->neg_flags))
45 return False;
47 return True;
50 /*******************************************************************
51 Inits a NETLOGON_INFO_3 structure.
52 ********************************************************************/
54 static void init_netinfo_3(NETLOGON_INFO_3 *info, uint32 flags, uint32 logon_attempts)
56 info->flags = flags;
57 info->logon_attempts = logon_attempts;
58 info->reserved_1 = 0x0;
59 info->reserved_2 = 0x0;
60 info->reserved_3 = 0x0;
61 info->reserved_4 = 0x0;
62 info->reserved_5 = 0x0;
65 /*******************************************************************
66 Reads or writes a NETLOGON_INFO_3 structure.
67 ********************************************************************/
69 static BOOL net_io_netinfo_3(char *desc, NETLOGON_INFO_3 *info, prs_struct *ps, int depth)
71 if (info == NULL)
72 return False;
74 prs_debug(ps, depth, desc, "net_io_netinfo_3");
75 depth++;
77 if(!prs_align(ps))
78 return False;
80 if(!prs_uint32("flags ", ps, depth, &info->flags))
81 return False;
82 if(!prs_uint32("logon_attempts", ps, depth, &info->logon_attempts))
83 return False;
84 if(!prs_uint32("reserved_1 ", ps, depth, &info->reserved_1))
85 return False;
86 if(!prs_uint32("reserved_2 ", ps, depth, &info->reserved_2))
87 return False;
88 if(!prs_uint32("reserved_3 ", ps, depth, &info->reserved_3))
89 return False;
90 if(!prs_uint32("reserved_4 ", ps, depth, &info->reserved_4))
91 return False;
92 if(!prs_uint32("reserved_5 ", ps, depth, &info->reserved_5))
93 return False;
95 return True;
99 /*******************************************************************
100 Inits a NETLOGON_INFO_1 structure.
101 ********************************************************************/
103 static void init_netinfo_1(NETLOGON_INFO_1 *info, uint32 flags, uint32 pdc_status)
105 info->flags = flags;
106 info->pdc_status = pdc_status;
109 /*******************************************************************
110 Reads or writes a NETLOGON_INFO_1 structure.
111 ********************************************************************/
113 static BOOL net_io_netinfo_1(char *desc, NETLOGON_INFO_1 *info, prs_struct *ps, int depth)
115 if (info == NULL)
116 return False;
118 prs_debug(ps, depth, desc, "net_io_netinfo_1");
119 depth++;
121 if(!prs_align(ps))
122 return False;
124 if(!prs_uint32("flags ", ps, depth, &info->flags))
125 return False;
126 if(!prs_uint32("pdc_status", ps, depth, &info->pdc_status))
127 return False;
129 return True;
132 /*******************************************************************
133 Inits a NETLOGON_INFO_2 structure.
134 ********************************************************************/
136 static void init_netinfo_2(NETLOGON_INFO_2 *info, uint32 flags, uint32 pdc_status,
137 uint32 tc_status, char *trusted_dc_name)
139 int len_dc_name = strlen(trusted_dc_name);
140 info->flags = flags;
141 info->pdc_status = pdc_status;
142 info->ptr_trusted_dc_name = 1;
143 info->tc_status = tc_status;
145 if (trusted_dc_name != NULL)
146 init_unistr2(&info->uni_trusted_dc_name, trusted_dc_name, len_dc_name+1);
147 else
148 init_unistr2(&info->uni_trusted_dc_name, "", 1);
151 /*******************************************************************
152 Reads or writes a NETLOGON_INFO_2 structure.
153 ********************************************************************/
155 static BOOL net_io_netinfo_2(char *desc, NETLOGON_INFO_2 *info, prs_struct *ps, int depth)
157 if (info == NULL)
158 return False;
160 prs_debug(ps, depth, desc, "net_io_netinfo_2");
161 depth++;
163 if(!prs_align(ps))
164 return False;
166 if(!prs_uint32("flags ", ps, depth, &info->flags))
167 return False;
168 if(!prs_uint32("pdc_status ", ps, depth, &info->pdc_status))
169 return False;
170 if(!prs_uint32("ptr_trusted_dc_name", ps, depth, &info->ptr_trusted_dc_name))
171 return False;
172 if(!prs_uint32("tc_status ", ps, depth, &info->tc_status))
173 return False;
175 if (info->ptr_trusted_dc_name != 0) {
176 if(!smb_io_unistr2("unistr2", &info->uni_trusted_dc_name, info->ptr_trusted_dc_name, ps, depth))
177 return False;
180 if(!prs_align(ps))
181 return False;
183 return True;
186 /*******************************************************************
187 Reads or writes an NET_Q_LOGON_CTRL2 structure.
188 ********************************************************************/
190 BOOL net_io_q_logon_ctrl2(char *desc, NET_Q_LOGON_CTRL2 *q_l, prs_struct *ps, int depth)
192 if (q_l == NULL)
193 return False;
195 prs_debug(ps, depth, desc, "net_io_q_logon_ctrl2");
196 depth++;
198 if(!prs_align(ps))
199 return False;
201 if(!prs_uint32("ptr ", ps, depth, &q_l->ptr))
202 return False;
204 if(!smb_io_unistr2 ("", &q_l->uni_server_name, q_l->ptr, ps, depth))
205 return False;
207 if(!prs_align(ps))
208 return False;
210 if(!prs_uint32("function_code", ps, depth, &q_l->function_code))
211 return False;
212 if(!prs_uint32("query_level ", ps, depth, &q_l->query_level))
213 return False;
214 if(!prs_uint32("switch_value ", ps, depth, &q_l->switch_value))
215 return False;
217 return True;
220 /*******************************************************************
221 Inits an NET_Q_LOGON_CTRL2 structure.
222 ********************************************************************/
224 void init_net_q_logon_ctrl2(NET_Q_LOGON_CTRL2 *q_l, char *srv_name,
225 uint32 query_level)
227 DEBUG(5,("init_q_logon_ctrl2\n"));
229 q_l->function_code = 0x01;
230 q_l->query_level = query_level;
231 q_l->switch_value = 0x01;
233 init_unistr2(&q_l->uni_server_name, srv_name, strlen(srv_name) + 1);
236 /*******************************************************************
237 Inits an NET_R_LOGON_CTRL2 structure.
238 ********************************************************************/
240 void init_net_r_logon_ctrl2(NET_R_LOGON_CTRL2 *r_l, uint32 query_level,
241 uint32 flags, uint32 pdc_status,
242 uint32 logon_attempts, uint32 tc_status,
243 char *trusted_domain_name)
245 DEBUG(5,("init_r_logon_ctrl2\n"));
247 r_l->switch_value = query_level; /* should only be 0x1 */
249 switch (query_level) {
250 case 1:
251 r_l->ptr = 1; /* undocumented pointer */
252 init_netinfo_1(&r_l->logon.info1, flags, pdc_status);
253 r_l->status = NT_STATUS_OK;
254 break;
255 case 2:
256 r_l->ptr = 1; /* undocumented pointer */
257 init_netinfo_2(&r_l->logon.info2, flags, pdc_status,
258 tc_status, trusted_domain_name);
259 r_l->status = NT_STATUS_OK;
260 break;
261 case 3:
262 r_l->ptr = 1; /* undocumented pointer */
263 init_netinfo_3(&r_l->logon.info3, flags, logon_attempts);
264 r_l->status = NT_STATUS_OK;
265 break;
266 default:
267 DEBUG(2,("init_r_logon_ctrl2: unsupported switch value %d\n",
268 r_l->switch_value));
269 r_l->ptr = 0; /* undocumented pointer */
271 /* take a guess at an error code... */
272 r_l->status = NT_STATUS_INVALID_INFO_CLASS;
273 break;
277 /*******************************************************************
278 Reads or writes an NET_R_LOGON_CTRL2 structure.
279 ********************************************************************/
281 BOOL net_io_r_logon_ctrl2(char *desc, NET_R_LOGON_CTRL2 *r_l, prs_struct *ps, int depth)
283 if (r_l == NULL)
284 return False;
286 prs_debug(ps, depth, desc, "net_io_r_logon_ctrl2");
287 depth++;
289 if(!prs_uint32("switch_value ", ps, depth, &r_l->switch_value))
290 return False;
291 if(!prs_uint32("ptr ", ps, depth, &r_l->ptr))
292 return False;
294 if (r_l->ptr != 0) {
295 switch (r_l->switch_value) {
296 case 1:
297 if(!net_io_netinfo_1("", &r_l->logon.info1, ps, depth))
298 return False;
299 break;
300 case 2:
301 if(!net_io_netinfo_2("", &r_l->logon.info2, ps, depth))
302 return False;
303 break;
304 case 3:
305 if(!net_io_netinfo_3("", &r_l->logon.info3, ps, depth))
306 return False;
307 break;
308 default:
309 DEBUG(2,("net_io_r_logon_ctrl2: unsupported switch value %d\n",
310 r_l->switch_value));
311 break;
315 if(!prs_ntstatus("status ", ps, depth, &r_l->status))
316 return False;
318 return True;
321 /*******************************************************************
322 Reads or writes an NET_Q_LOGON_CTRL structure.
323 ********************************************************************/
325 BOOL net_io_q_logon_ctrl(char *desc, NET_Q_LOGON_CTRL *q_l, prs_struct *ps,
326 int depth)
328 prs_debug(ps, depth, desc, "net_io_q_logon_ctrl");
329 depth++;
331 if(!prs_align(ps))
332 return False;
334 if(!prs_uint32("ptr ", ps, depth, &q_l->ptr))
335 return False;
337 if(!smb_io_unistr2 ("", &q_l->uni_server_name, q_l->ptr, ps, depth))
338 return False;
340 if(!prs_align(ps))
341 return False;
343 if(!prs_uint32("function_code", ps, depth, &q_l->function_code))
344 return False;
345 if(!prs_uint32("query_level ", ps, depth, &q_l->query_level))
346 return False;
348 return True;
351 /*******************************************************************
352 Inits an NET_Q_LOGON_CTRL structure.
353 ********************************************************************/
355 void init_net_q_logon_ctrl(NET_Q_LOGON_CTRL *q_l, char *srv_name,
356 uint32 query_level)
358 DEBUG(5,("init_q_logon_ctrl\n"));
360 q_l->function_code = 0x01; /* ??? */
361 q_l->query_level = query_level;
363 init_unistr2(&q_l->uni_server_name, srv_name, strlen(srv_name) + 1);
366 /*******************************************************************
367 Inits an NET_R_LOGON_CTRL structure.
368 ********************************************************************/
370 void init_net_r_logon_ctrl(NET_R_LOGON_CTRL *r_l, uint32 query_level,
371 uint32 flags, uint32 pdc_status)
373 DEBUG(5,("init_r_logon_ctrl\n"));
375 r_l->switch_value = query_level; /* should only be 0x1 */
377 switch (query_level) {
378 case 1:
379 r_l->ptr = 1; /* undocumented pointer */
380 init_netinfo_1(&r_l->logon.info1, flags, pdc_status);
381 r_l->status = NT_STATUS_OK;
382 break;
383 default:
384 DEBUG(2,("init_r_logon_ctrl: unsupported switch value %d\n",
385 r_l->switch_value));
386 r_l->ptr = 0; /* undocumented pointer */
388 /* take a guess at an error code... */
389 r_l->status = NT_STATUS_INVALID_INFO_CLASS;
390 break;
394 /*******************************************************************
395 Reads or writes an NET_R_LOGON_CTRL structure.
396 ********************************************************************/
398 BOOL net_io_r_logon_ctrl(char *desc, NET_R_LOGON_CTRL *r_l, prs_struct *ps,
399 int depth)
401 prs_debug(ps, depth, desc, "net_io_r_logon_ctrl");
402 depth++;
404 if(!prs_uint32("switch_value ", ps, depth, &r_l->switch_value))
405 return False;
406 if(!prs_uint32("ptr ", ps, depth, &r_l->ptr))
407 return False;
409 if (r_l->ptr != 0) {
410 switch (r_l->switch_value) {
411 case 1:
412 if(!net_io_netinfo_1("", &r_l->logon.info1, ps, depth))
413 return False;
414 break;
415 default:
416 DEBUG(2,("net_io_r_logon_ctrl: unsupported switch value %d\n",
417 r_l->switch_value));
418 break;
422 if(!prs_ntstatus("status ", ps, depth, &r_l->status))
423 return False;
425 return True;
428 /*******************************************************************
429 Inits an NET_R_TRUST_DOM_LIST structure.
430 ********************************************************************/
432 void init_r_trust_dom(NET_R_TRUST_DOM_LIST *r_t,
433 uint32 num_doms, char *dom_name)
435 int i = 0;
437 DEBUG(5,("init_r_trust_dom\n"));
439 for (i = 0; i < MAX_TRUST_DOMS; i++) {
440 r_t->uni_trust_dom_name[i].uni_str_len = 0;
441 r_t->uni_trust_dom_name[i].uni_max_len = 0;
443 if (num_doms > MAX_TRUST_DOMS)
444 num_doms = MAX_TRUST_DOMS;
446 for (i = 0; i < num_doms; i++) {
447 fstring domain_name;
448 fstrcpy(domain_name, dom_name);
449 strupper(domain_name);
450 init_unistr2(&r_t->uni_trust_dom_name[i], domain_name, strlen(domain_name)+1);
451 /* the use of UNISTR2 here is non-standard. */
452 r_t->uni_trust_dom_name[i].undoc = 0x1;
455 r_t->status = NT_STATUS_OK;
458 /*******************************************************************
459 Reads or writes an NET_R_TRUST_DOM_LIST structure.
460 ********************************************************************/
462 BOOL net_io_r_trust_dom(char *desc, NET_R_TRUST_DOM_LIST *r_t, prs_struct *ps, int depth)
464 uint32 value;
466 if (r_t == NULL)
467 return False;
469 prs_debug(ps, depth, desc, "net_io_r_trust_dom");
470 depth++;
472 /* temporary code to give a valid response */
473 value=2;
474 if(!prs_uint32("status", ps, depth, &value))
475 return False;
477 value=1;
478 if(!prs_uint32("status", ps, depth, &value))
479 return False;
480 value=2;
481 if(!prs_uint32("status", ps, depth, &value))
482 return False;
484 value=0;
485 if(!prs_uint32("status", ps, depth, &value))
486 return False;
488 value=0;
489 if(!prs_uint32("status", ps, depth, &value))
490 return False;
492 /* old non working code */
493 #if 0
494 int i;
496 for (i = 0; i < MAX_TRUST_DOMS; i++) {
497 if (r_t->uni_trust_dom_name[i].uni_str_len == 0)
498 break;
499 if(!smb_io_unistr2("", &r_t->uni_trust_dom_name[i], True, ps, depth))
500 return False;
503 if(!prs_ntstatus("status", ps, depth, &r_t->status))
504 return False;
505 #endif
506 return True;
510 /*******************************************************************
511 Reads or writes an NET_Q_TRUST_DOM_LIST structure.
512 ********************************************************************/
514 BOOL net_io_q_trust_dom(char *desc, NET_Q_TRUST_DOM_LIST *q_l, prs_struct *ps, int depth)
516 if (q_l == NULL)
517 return False;
519 prs_debug(ps, depth, desc, "net_io_q_trust_dom");
520 depth++;
522 if(!prs_uint32("ptr ", ps, depth, &q_l->ptr))
523 return False;
524 if(!smb_io_unistr2 ("", &q_l->uni_server_name, q_l->ptr, ps, depth))
525 return False;
527 return True;
530 /*******************************************************************
531 Inits an NET_Q_REQ_CHAL structure.
532 ********************************************************************/
534 void init_q_req_chal(NET_Q_REQ_CHAL *q_c,
535 const char *logon_srv, const char *logon_clnt,
536 DOM_CHAL *clnt_chal)
538 DEBUG(5,("init_q_req_chal: %d\n", __LINE__));
540 q_c->undoc_buffer = 1; /* don't know what this buffer is */
542 init_unistr2(&q_c->uni_logon_srv, logon_srv , strlen(logon_srv )+1);
543 init_unistr2(&q_c->uni_logon_clnt, logon_clnt, strlen(logon_clnt)+1);
545 memcpy(q_c->clnt_chal.data, clnt_chal->data, sizeof(clnt_chal->data));
547 DEBUG(5,("init_q_req_chal: %d\n", __LINE__));
550 /*******************************************************************
551 Reads or writes an NET_Q_REQ_CHAL structure.
552 ********************************************************************/
554 BOOL net_io_q_req_chal(char *desc, NET_Q_REQ_CHAL *q_c, prs_struct *ps, int depth)
556 if (q_c == NULL)
557 return False;
559 prs_debug(ps, depth, desc, "net_io_q_req_chal");
560 depth++;
562 if(!prs_align(ps))
563 return False;
565 if(!prs_uint32("undoc_buffer", ps, depth, &q_c->undoc_buffer))
566 return False;
568 if(!smb_io_unistr2("", &q_c->uni_logon_srv, True, ps, depth)) /* logon server unicode string */
569 return False;
570 if(!smb_io_unistr2("", &q_c->uni_logon_clnt, True, ps, depth)) /* logon client unicode string */
571 return False;
573 if(!smb_io_chal("", &q_c->clnt_chal, ps, depth))
574 return False;
576 return True;
579 /*******************************************************************
580 Reads or writes a structure.
581 ********************************************************************/
583 BOOL net_io_r_req_chal(char *desc, NET_R_REQ_CHAL *r_c, prs_struct *ps, int depth)
585 if (r_c == NULL)
586 return False;
588 prs_debug(ps, depth, desc, "net_io_r_req_chal");
589 depth++;
591 if(!prs_align(ps))
592 return False;
594 if(!smb_io_chal("", &r_c->srv_chal, ps, depth)) /* server challenge */
595 return False;
597 if(!prs_ntstatus("status", ps, depth, &r_c->status))
598 return False;
600 return True;
604 /*******************************************************************
605 Reads or writes a structure.
606 ********************************************************************/
608 BOOL net_io_q_auth(char *desc, NET_Q_AUTH *q_a, prs_struct *ps, int depth)
610 if (q_a == NULL)
611 return False;
613 prs_debug(ps, depth, desc, "net_io_q_auth");
614 depth++;
616 if(!prs_align(ps))
617 return False;
619 if(!smb_io_log_info ("", &q_a->clnt_id, ps, depth)) /* client identification info */
620 return False;
621 if(!smb_io_chal("", &q_a->clnt_chal, ps, depth))
622 return False;
624 return True;
627 /*******************************************************************
628 Reads or writes a structure.
629 ********************************************************************/
631 BOOL net_io_r_auth(char *desc, NET_R_AUTH *r_a, prs_struct *ps, int depth)
633 if (r_a == NULL)
634 return False;
636 prs_debug(ps, depth, desc, "net_io_r_auth");
637 depth++;
639 if(!prs_align(ps))
640 return False;
642 if(!smb_io_chal("", &r_a->srv_chal, ps, depth)) /* server challenge */
643 return False;
645 if(!prs_ntstatus("status", ps, depth, &r_a->status))
646 return False;
648 return True;
651 /*******************************************************************
652 Inits a NET_Q_AUTH_2 struct.
653 ********************************************************************/
655 void init_q_auth_2(NET_Q_AUTH_2 *q_a,
656 const char *logon_srv, const char *acct_name, uint16 sec_chan, const char *comp_name,
657 DOM_CHAL *clnt_chal, uint32 clnt_flgs)
659 DEBUG(5,("init_q_auth_2: %d\n", __LINE__));
661 init_log_info(&q_a->clnt_id, logon_srv, acct_name, sec_chan, comp_name);
662 memcpy(q_a->clnt_chal.data, clnt_chal->data, sizeof(clnt_chal->data));
663 q_a->clnt_flgs.neg_flags = clnt_flgs;
665 DEBUG(5,("init_q_auth_2: %d\n", __LINE__));
668 /*******************************************************************
669 Reads or writes a structure.
670 ********************************************************************/
672 BOOL net_io_q_auth_2(char *desc, NET_Q_AUTH_2 *q_a, prs_struct *ps, int depth)
674 if (q_a == NULL)
675 return False;
677 prs_debug(ps, depth, desc, "net_io_q_auth_2");
678 depth++;
680 if(!prs_align(ps))
681 return False;
683 if(!smb_io_log_info ("", &q_a->clnt_id, ps, depth)) /* client identification info */
684 return False;
685 if(!smb_io_chal("", &q_a->clnt_chal, ps, depth))
686 return False;
687 if(!net_io_neg_flags("", &q_a->clnt_flgs, ps, depth))
688 return False;
690 return True;
693 /*******************************************************************
694 Reads or writes a structure.
695 ********************************************************************/
697 BOOL net_io_r_auth_2(char *desc, NET_R_AUTH_2 *r_a, prs_struct *ps, int depth)
699 if (r_a == NULL)
700 return False;
702 prs_debug(ps, depth, desc, "net_io_r_auth_2");
703 depth++;
705 if(!prs_align(ps))
706 return False;
708 if(!smb_io_chal("", &r_a->srv_chal, ps, depth)) /* server challenge */
709 return False;
710 if(!net_io_neg_flags("", &r_a->srv_flgs, ps, depth))
711 return False;
713 if(!prs_ntstatus("status", ps, depth, &r_a->status))
714 return False;
716 return True;
719 /*******************************************************************
720 Inits a NET_Q_AUTH_3 struct.
721 ********************************************************************/
723 void init_q_auth_3(NET_Q_AUTH_3 *q_a,
724 const char *logon_srv, const char *acct_name, uint16 sec_chan, const char *comp_name,
725 DOM_CHAL *clnt_chal, uint32 clnt_flgs)
727 DEBUG(5,("init_q_auth_3: %d\n", __LINE__));
729 init_log_info(&q_a->clnt_id, logon_srv, acct_name, sec_chan, comp_name);
730 memcpy(q_a->clnt_chal.data, clnt_chal->data, sizeof(clnt_chal->data));
731 q_a->clnt_flgs.neg_flags = clnt_flgs;
733 DEBUG(5,("init_q_auth_3: %d\n", __LINE__));
736 /*******************************************************************
737 Reads or writes a structure.
738 ********************************************************************/
740 BOOL net_io_q_auth_3(char *desc, NET_Q_AUTH_3 *q_a, prs_struct *ps, int depth)
742 if (q_a == NULL)
743 return False;
745 prs_debug(ps, depth, desc, "net_io_q_auth_3");
746 depth++;
748 if(!prs_align(ps))
749 return False;
751 if(!smb_io_log_info ("", &q_a->clnt_id, ps, depth)) /* client identification info */
752 return False;
753 if(!smb_io_chal("", &q_a->clnt_chal, ps, depth))
754 return False;
755 if(!net_io_neg_flags("", &q_a->clnt_flgs, ps, depth))
756 return False;
758 return True;
761 /*******************************************************************
762 Reads or writes a structure.
763 ********************************************************************/
765 BOOL net_io_r_auth_3(char *desc, NET_R_AUTH_3 *r_a, prs_struct *ps, int depth)
767 if (r_a == NULL)
768 return False;
770 prs_debug(ps, depth, desc, "net_io_r_auth_3");
771 depth++;
773 if(!prs_align(ps))
774 return False;
776 if(!smb_io_chal("srv_chal", &r_a->srv_chal, ps, depth)) /* server challenge */
777 return False;
778 if(!net_io_neg_flags("srv_flgs", &r_a->srv_flgs, ps, depth))
779 return False;
780 if (!prs_uint32("unknown", ps, depth, &r_a->unknown))
781 return False;
783 if(!prs_ntstatus("status", ps, depth, &r_a->status))
784 return False;
786 return True;
790 /*******************************************************************
791 Inits a NET_Q_SRV_PWSET.
792 ********************************************************************/
794 void init_q_srv_pwset(NET_Q_SRV_PWSET *q_s, char *logon_srv, char *sess_key, char *acct_name,
795 uint16 sec_chan, char *comp_name, DOM_CRED *cred, uchar hashed_mach_pwd[16])
797 unsigned char nt_cypher[16];
799 DEBUG(5,("init_q_srv_pwset\n"));
801 /* Process the new password. */
802 cred_hash3( nt_cypher, hashed_mach_pwd, sess_key, 1);
804 init_clnt_info(&q_s->clnt_id, logon_srv, acct_name, sec_chan, comp_name, cred);
806 memcpy(q_s->pwd, nt_cypher, sizeof(q_s->pwd));
809 /*******************************************************************
810 Reads or writes a structure.
811 ********************************************************************/
813 BOOL net_io_q_srv_pwset(char *desc, NET_Q_SRV_PWSET *q_s, prs_struct *ps, int depth)
815 if (q_s == NULL)
816 return False;
818 prs_debug(ps, depth, desc, "net_io_q_srv_pwset");
819 depth++;
821 if(!prs_align(ps))
822 return False;
824 if(!smb_io_clnt_info("", &q_s->clnt_id, ps, depth)) /* client identification/authentication info */
825 return False;
826 if(!prs_uint8s (False, "pwd", ps, depth, q_s->pwd, 16)) /* new password - undocumented */
827 return False;
829 return True;
832 /*******************************************************************
833 Reads or writes a structure.
834 ********************************************************************/
836 BOOL net_io_r_srv_pwset(char *desc, NET_R_SRV_PWSET *r_s, prs_struct *ps, int depth)
838 if (r_s == NULL)
839 return False;
841 prs_debug(ps, depth, desc, "net_io_r_srv_pwset");
842 depth++;
844 if(!prs_align(ps))
845 return False;
847 if(!smb_io_cred("", &r_s->srv_cred, ps, depth)) /* server challenge */
848 return False;
850 if(!prs_ntstatus("status", ps, depth, &r_s->status))
851 return False;
853 return True;
856 /*************************************************************************
857 Init DOM_SID2 array from a string containing multiple sids
858 *************************************************************************/
860 static int init_dom_sid2s(TALLOC_CTX *ctx, char *sids_str, DOM_SID2 **ppsids)
862 char *ptr;
863 pstring s2;
864 int count = 0;
866 DEBUG(4,("init_dom_sid2s: %s\n", sids_str ? sids_str:""));
868 *ppsids = NULL;
870 if(sids_str) {
871 int number;
872 DOM_SID2 *sids;
874 /* Count the number of SIDs. */
875 for (count = 0, ptr = sids_str;
876 next_token(&ptr, s2, NULL, sizeof(s2)); count++)
879 /* Now allocate space for them. */
880 *ppsids = (DOM_SID2 *)talloc_zero(ctx, count * sizeof(DOM_SID2));
881 if (*ppsids == NULL)
882 return 0;
884 sids = *ppsids;
886 for (number = 0, ptr = sids_str;
887 next_token(&ptr, s2, NULL, sizeof(s2)); number++) {
888 DOM_SID tmpsid;
889 string_to_sid(&tmpsid, s2);
890 init_dom_sid2(&sids[number], &tmpsid);
894 return count;
897 /*******************************************************************
898 Inits a NET_ID_INFO_1 structure.
899 ********************************************************************/
901 void init_id_info1(NET_ID_INFO_1 *id, char *domain_name,
902 uint32 param_ctrl, uint32 log_id_low, uint32 log_id_high,
903 char *user_name, char *wksta_name,
904 char *sess_key,
905 unsigned char lm_cypher[16], unsigned char nt_cypher[16])
907 int len_domain_name = strlen(domain_name);
908 int len_user_name = strlen(user_name );
909 int len_wksta_name = strlen(wksta_name );
911 unsigned char lm_owf[16];
912 unsigned char nt_owf[16];
914 DEBUG(5,("init_id_info1: %d\n", __LINE__));
916 id->ptr_id_info1 = 1;
918 init_uni_hdr(&id->hdr_domain_name, len_domain_name);
920 id->param_ctrl = param_ctrl;
921 init_logon_id(&id->logon_id, log_id_low, log_id_high);
923 init_uni_hdr(&id->hdr_user_name, len_user_name);
924 init_uni_hdr(&id->hdr_wksta_name, len_wksta_name);
926 if (lm_cypher && nt_cypher) {
927 unsigned char key[16];
928 #ifdef DEBUG_PASSWORD
929 DEBUG(100,("lm cypher:"));
930 dump_data(100, (char *)lm_cypher, 16);
932 DEBUG(100,("nt cypher:"));
933 dump_data(100, (char *)nt_cypher, 16);
934 #endif
936 memset(key, 0, 16);
937 memcpy(key, sess_key, 8);
939 memcpy(lm_owf, lm_cypher, 16);
940 SamOEMhash(lm_owf, key, 16);
941 memcpy(nt_owf, nt_cypher, 16);
942 SamOEMhash(nt_owf, key, 16);
944 #ifdef DEBUG_PASSWORD
945 DEBUG(100,("encrypt of lm owf password:"));
946 dump_data(100, (char *)lm_owf, 16);
948 DEBUG(100,("encrypt of nt owf password:"));
949 dump_data(100, (char *)nt_owf, 16);
950 #endif
951 /* set up pointers to cypher blocks */
952 lm_cypher = lm_owf;
953 nt_cypher = nt_owf;
956 init_owf_info(&id->lm_owf, lm_cypher);
957 init_owf_info(&id->nt_owf, nt_cypher);
959 init_unistr2(&id->uni_domain_name, domain_name, len_domain_name);
960 init_unistr2(&id->uni_user_name, user_name, len_user_name);
961 init_unistr2(&id->uni_wksta_name, wksta_name, len_wksta_name);
964 /*******************************************************************
965 Reads or writes an NET_ID_INFO_1 structure.
966 ********************************************************************/
968 static BOOL net_io_id_info1(char *desc, NET_ID_INFO_1 *id, prs_struct *ps, int depth)
970 if (id == NULL)
971 return False;
973 prs_debug(ps, depth, desc, "net_io_id_info1");
974 depth++;
976 if(!prs_align(ps))
977 return False;
979 if(!prs_uint32("ptr_id_info1", ps, depth, &id->ptr_id_info1))
980 return False;
982 if (id->ptr_id_info1 != 0) {
983 if(!smb_io_unihdr("unihdr", &id->hdr_domain_name, ps, depth))
984 return False;
986 if(!prs_uint32("param_ctrl", ps, depth, &id->param_ctrl))
987 return False;
988 if(!smb_io_logon_id("", &id->logon_id, ps, depth))
989 return False;
991 if(!smb_io_unihdr("unihdr", &id->hdr_user_name, ps, depth))
992 return False;
993 if(!smb_io_unihdr("unihdr", &id->hdr_wksta_name, ps, depth))
994 return False;
996 if(!smb_io_owf_info("", &id->lm_owf, ps, depth))
997 return False;
998 if(!smb_io_owf_info("", &id->nt_owf, ps, depth))
999 return False;
1001 if(!smb_io_unistr2("unistr2", &id->uni_domain_name,
1002 id->hdr_domain_name.buffer, ps, depth))
1003 return False;
1004 if(!smb_io_unistr2("unistr2", &id->uni_user_name,
1005 id->hdr_user_name.buffer, ps, depth))
1006 return False;
1007 if(!smb_io_unistr2("unistr2", &id->uni_wksta_name,
1008 id->hdr_wksta_name.buffer, ps, depth))
1009 return False;
1012 return True;
1015 /*******************************************************************
1016 Inits a NET_ID_INFO_2 structure.
1018 This is a network logon packet. The log_id parameters
1019 are what an NT server would generate for LUID once the
1020 user is logged on. I don't think we care about them.
1022 Note that this has no access to the NT and LM hashed passwords,
1023 so it forwards the challenge, and the NT and LM responses (24
1024 bytes each) over the secure channel to the Domain controller
1025 for it to say yea or nay. This is the preferred method of
1026 checking for a logon as it doesn't export the password
1027 hashes to anyone who has compromised the secure channel. JRA.
1028 ********************************************************************/
1030 void init_id_info2(NET_ID_INFO_2 * id, const char *domain_name,
1031 uint32 param_ctrl,
1032 uint32 log_id_low, uint32 log_id_high,
1033 const char *user_name, const char *wksta_name,
1034 const uchar lm_challenge[8],
1035 const uchar * lm_chal_resp, int lm_chal_resp_len,
1036 const uchar * nt_chal_resp, int nt_chal_resp_len)
1038 int len_domain_name = strlen(domain_name);
1039 int len_user_name = strlen(user_name );
1040 int len_wksta_name = strlen(wksta_name );
1041 unsigned char lm_owf[24];
1042 unsigned char nt_owf[128];
1044 DEBUG(5,("init_id_info2: %d\n", __LINE__));
1046 id->ptr_id_info2 = 1;
1048 init_uni_hdr(&id->hdr_domain_name, len_domain_name);
1050 id->param_ctrl = param_ctrl;
1051 init_logon_id(&id->logon_id, log_id_low, log_id_high);
1053 init_uni_hdr(&id->hdr_user_name, len_user_name);
1054 init_uni_hdr(&id->hdr_wksta_name, len_wksta_name);
1056 if (nt_chal_resp) {
1057 /* oops. can only send what-ever-it-is direct */
1058 memcpy(nt_owf, nt_chal_resp, MIN(sizeof(nt_owf), nt_chal_resp_len));
1059 nt_chal_resp = nt_owf;
1061 if (lm_chal_resp) {
1062 /* oops. can only send what-ever-it-is direct */
1063 memcpy(lm_owf, lm_chal_resp, MIN(sizeof(lm_owf), lm_chal_resp_len));
1064 lm_chal_resp = lm_owf;
1067 memcpy(id->lm_chal, lm_challenge, sizeof(id->lm_chal));
1068 init_str_hdr(&id->hdr_nt_chal_resp, nt_chal_resp_len, nt_chal_resp_len, (nt_chal_resp != NULL) ? 1 : 0);
1069 init_str_hdr(&id->hdr_lm_chal_resp, lm_chal_resp_len, lm_chal_resp_len, (lm_chal_resp != NULL) ? 1 : 0);
1071 init_unistr2(&id->uni_domain_name, domain_name, len_domain_name);
1072 init_unistr2(&id->uni_user_name, user_name, len_user_name);
1073 init_unistr2(&id->uni_wksta_name, wksta_name, len_wksta_name);
1075 init_string2(&id->nt_chal_resp, (const char *)nt_chal_resp, nt_chal_resp_len, nt_chal_resp_len);
1076 init_string2(&id->lm_chal_resp, (const char *)lm_chal_resp, lm_chal_resp_len, lm_chal_resp_len);
1080 /*******************************************************************
1081 Reads or writes an NET_ID_INFO_2 structure.
1082 ********************************************************************/
1084 static BOOL net_io_id_info2(char *desc, NET_ID_INFO_2 *id, prs_struct *ps, int depth)
1086 if (id == NULL)
1087 return False;
1089 prs_debug(ps, depth, desc, "net_io_id_info2");
1090 depth++;
1092 if(!prs_align(ps))
1093 return False;
1095 if(!prs_uint32("ptr_id_info2", ps, depth, &id->ptr_id_info2))
1096 return False;
1098 if (id->ptr_id_info2 != 0) {
1099 if(!smb_io_unihdr("unihdr", &id->hdr_domain_name, ps, depth))
1100 return False;
1102 if(!prs_uint32("param_ctrl", ps, depth, &id->param_ctrl))
1103 return False;
1104 if(!smb_io_logon_id("", &id->logon_id, ps, depth))
1105 return False;
1107 if(!smb_io_unihdr("unihdr", &id->hdr_user_name, ps, depth))
1108 return False;
1109 if(!smb_io_unihdr("unihdr", &id->hdr_wksta_name, ps, depth))
1110 return False;
1112 if(!prs_uint8s (False, "lm_chal", ps, depth, id->lm_chal, 8)) /* lm 8 byte challenge */
1113 return False;
1115 if(!smb_io_strhdr("hdr_nt_chal_resp", &id->hdr_nt_chal_resp, ps, depth))
1116 return False;
1117 if(!smb_io_strhdr("hdr_lm_chal_resp", &id->hdr_lm_chal_resp, ps, depth))
1118 return False;
1120 if(!smb_io_unistr2("uni_domain_name", &id->uni_domain_name,
1121 id->hdr_domain_name.buffer, ps, depth))
1122 return False;
1123 if(!smb_io_unistr2("uni_user_name ", &id->uni_user_name,
1124 id->hdr_user_name.buffer, ps, depth))
1125 return False;
1126 if(!smb_io_unistr2("uni_wksta_name ", &id->uni_wksta_name,
1127 id->hdr_wksta_name.buffer, ps, depth))
1128 return False;
1129 if(!smb_io_string2("nt_chal_resp", &id->nt_chal_resp,
1130 id->hdr_nt_chal_resp.buffer, ps, depth))
1131 return False;
1132 if(!smb_io_string2("lm_chal_resp", &id->lm_chal_resp,
1133 id->hdr_lm_chal_resp.buffer, ps, depth))
1134 return False;
1137 return True;
1141 /*******************************************************************
1142 Inits a DOM_SAM_INFO structure.
1143 ********************************************************************/
1145 void init_sam_info(DOM_SAM_INFO *sam,
1146 char *logon_srv, char *comp_name, DOM_CRED *clnt_cred,
1147 DOM_CRED *rtn_cred, uint16 logon_level,
1148 NET_ID_INFO_CTR *ctr)
1150 DEBUG(5,("init_sam_info: %d\n", __LINE__));
1152 init_clnt_info2(&sam->client, logon_srv, comp_name, clnt_cred);
1154 if (rtn_cred != NULL) {
1155 sam->ptr_rtn_cred = 1;
1156 memcpy(&sam->rtn_cred, rtn_cred, sizeof(sam->rtn_cred));
1157 } else {
1158 sam->ptr_rtn_cred = 0;
1161 sam->logon_level = logon_level;
1162 sam->ctr = ctr;
1165 /*******************************************************************
1166 Reads or writes a DOM_SAM_INFO structure.
1167 ********************************************************************/
1169 static BOOL net_io_id_info_ctr(char *desc, NET_ID_INFO_CTR **pp_ctr, prs_struct *ps, int depth)
1171 NET_ID_INFO_CTR *ctr = *pp_ctr;
1173 prs_debug(ps, depth, desc, "smb_io_sam_info");
1174 depth++;
1176 if (UNMARSHALLING(ps)) {
1177 ctr = *pp_ctr = (NET_ID_INFO_CTR *)prs_alloc_mem(ps, sizeof(NET_ID_INFO_CTR));
1178 if (ctr == NULL)
1179 return False;
1182 if (ctr == NULL)
1183 return False;
1185 /* don't 4-byte align here! */
1187 if(!prs_uint16("switch_value ", ps, depth, &ctr->switch_value))
1188 return False;
1190 switch (ctr->switch_value) {
1191 case 1:
1192 if(!net_io_id_info1("", &ctr->auth.id1, ps, depth))
1193 return False;
1194 break;
1195 case 2:
1196 if(!net_io_id_info2("", &ctr->auth.id2, ps, depth))
1197 return False;
1198 break;
1199 default:
1200 /* PANIC! */
1201 DEBUG(4,("smb_io_sam_info: unknown switch_value!\n"));
1202 break;
1205 return True;
1208 /*******************************************************************
1209 Reads or writes a DOM_SAM_INFO structure.
1210 ********************************************************************/
1212 static BOOL smb_io_sam_info(char *desc, DOM_SAM_INFO *sam, prs_struct *ps, int depth)
1214 if (sam == NULL)
1215 return False;
1217 prs_debug(ps, depth, desc, "smb_io_sam_info");
1218 depth++;
1220 if(!prs_align(ps))
1221 return False;
1223 if(!smb_io_clnt_info2("", &sam->client, ps, depth))
1224 return False;
1226 if(!prs_uint32("ptr_rtn_cred ", ps, depth, &sam->ptr_rtn_cred))
1227 return False;
1228 if(!smb_io_cred("", &sam->rtn_cred, ps, depth))
1229 return False;
1231 if(!prs_uint16("logon_level ", ps, depth, &sam->logon_level))
1232 return False;
1234 if (sam->logon_level != 0) {
1235 if(!net_io_id_info_ctr("logon_info", &sam->ctr, ps, depth))
1236 return False;
1239 return True;
1242 /*************************************************************************
1243 Inits a NET_USER_INFO_3 structure.
1245 This is a network logon reply packet, and contains much information about
1246 the user. This information is passed as a (very long) paramater list
1247 to avoid having to link in the PASSDB code to every program that deals
1248 with this file.
1249 *************************************************************************/
1251 void init_net_user_info3(TALLOC_CTX *ctx, NET_USER_INFO_3 *usr,
1252 uint32 user_rid,
1253 uint32 group_rid,
1255 const char* user_name,
1256 const char* full_name,
1257 const char* home_dir,
1258 const char* dir_drive,
1259 const char* logon_script,
1260 const char* profile_path,
1262 time_t unix_logon_time,
1263 time_t unix_logoff_time,
1264 time_t unix_kickoff_time,
1265 time_t unix_pass_last_set_time,
1266 time_t unix_pass_can_change_time,
1267 time_t unix_pass_must_change_time,
1269 uint16 logon_count, uint16 bad_pw_count,
1270 uint32 num_groups, const DOM_GID *gids,
1271 uint32 user_flgs, uchar *sess_key,
1272 const char *logon_srv, const char *logon_dom,
1273 const DOM_SID *dom_sid, char *other_sids)
1275 /* only cope with one "other" sid, right now. */
1276 /* need to count the number of space-delimited sids */
1277 int i;
1278 int num_other_sids = 0;
1280 NTTIME logon_time, logoff_time, kickoff_time,
1281 pass_last_set_time, pass_can_change_time,
1282 pass_must_change_time;
1284 int len_user_name, len_full_name, len_home_dir,
1285 len_dir_drive, len_logon_script, len_profile_path;
1287 int len_logon_srv = strlen(logon_srv);
1288 int len_logon_dom = strlen(logon_dom);
1290 len_user_name = strlen(user_name );
1291 len_full_name = strlen(full_name );
1292 len_home_dir = strlen(home_dir );
1293 len_dir_drive = strlen(dir_drive );
1294 len_logon_script = strlen(logon_script);
1295 len_profile_path = strlen(profile_path);
1298 ZERO_STRUCTP(usr);
1300 usr->ptr_user_info = 1; /* yes, we're bothering to put USER_INFO data here */
1303 /* Create NTTIME structs */
1304 unix_to_nt_time (&logon_time, unix_logon_time);
1305 unix_to_nt_time (&logoff_time, unix_logoff_time);
1306 unix_to_nt_time (&kickoff_time, unix_kickoff_time);
1307 unix_to_nt_time (&pass_last_set_time, unix_pass_last_set_time);
1308 unix_to_nt_time (&pass_can_change_time, unix_pass_can_change_time);
1309 unix_to_nt_time (&pass_must_change_time, unix_pass_must_change_time);
1311 usr->logon_time = logon_time;
1312 usr->logoff_time = logoff_time;
1313 usr->kickoff_time = kickoff_time;
1314 usr->pass_last_set_time = pass_last_set_time;
1315 usr->pass_can_change_time = pass_can_change_time;
1316 usr->pass_must_change_time = pass_must_change_time;
1318 init_uni_hdr(&usr->hdr_user_name, len_user_name);
1319 init_uni_hdr(&usr->hdr_full_name, len_full_name);
1320 init_uni_hdr(&usr->hdr_logon_script, len_logon_script);
1321 init_uni_hdr(&usr->hdr_profile_path, len_profile_path);
1322 init_uni_hdr(&usr->hdr_home_dir, len_home_dir);
1323 init_uni_hdr(&usr->hdr_dir_drive, len_dir_drive);
1325 usr->logon_count = logon_count;
1326 usr->bad_pw_count = bad_pw_count;
1328 usr->user_rid = user_rid;
1329 usr->group_rid = group_rid;
1330 usr->num_groups = num_groups;
1332 usr->buffer_groups = 1; /* indicates fill in groups, below, even if there are none */
1333 usr->user_flgs = user_flgs;
1335 if (sess_key != NULL)
1336 memcpy(usr->user_sess_key, sess_key, sizeof(usr->user_sess_key));
1337 else
1338 memset((char *)usr->user_sess_key, '\0', sizeof(usr->user_sess_key));
1340 init_uni_hdr(&usr->hdr_logon_srv, len_logon_srv);
1341 init_uni_hdr(&usr->hdr_logon_dom, len_logon_dom);
1343 usr->buffer_dom_id = dom_sid ? 1 : 0; /* yes, we're bothering to put a domain SID in */
1345 memset((char *)usr->padding, '\0', sizeof(usr->padding));
1347 num_other_sids = init_dom_sid2s(ctx, other_sids, &usr->other_sids);
1349 usr->num_other_sids = num_other_sids;
1350 usr->buffer_other_sids = (num_other_sids != 0) ? 1 : 0;
1352 init_unistr2(&usr->uni_user_name, user_name, len_user_name);
1353 init_unistr2(&usr->uni_full_name, full_name, len_full_name);
1354 init_unistr2(&usr->uni_logon_script, logon_script, len_logon_script);
1355 init_unistr2(&usr->uni_profile_path, profile_path, len_profile_path);
1356 init_unistr2(&usr->uni_home_dir, home_dir, len_home_dir);
1357 init_unistr2(&usr->uni_dir_drive, dir_drive, len_dir_drive);
1359 usr->num_groups2 = num_groups;
1361 usr->gids = (DOM_GID *)talloc_zero(ctx,sizeof(DOM_GID) * (num_groups));
1362 if (usr->gids == NULL && num_groups>0)
1363 return;
1365 for (i = 0; i < num_groups; i++)
1366 usr->gids[i] = gids[i];
1368 init_unistr2(&usr->uni_logon_srv, logon_srv, len_logon_srv);
1369 init_unistr2(&usr->uni_logon_dom, logon_dom, len_logon_dom);
1371 init_dom_sid2(&usr->dom_sid, dom_sid);
1372 /* "other" sids are set up above */
1375 /*******************************************************************
1376 This code has been modified to cope with a NET_USER_INFO_2 - which is
1377 exactly the same as a NET_USER_INFO_3, minus the other sids parameters.
1378 We use validation level to determine if we're marshalling a info 2 or
1379 INFO_3 - be we always return an INFO_3. Based on code donated by Marc
1380 Jacobsen at HP. JRA.
1381 ********************************************************************/
1383 BOOL net_io_user_info3(const char *desc, NET_USER_INFO_3 *usr, prs_struct *ps,
1384 int depth, uint16 validation_level)
1386 int i;
1388 if (usr == NULL)
1389 return False;
1391 prs_debug(ps, depth, desc, "net_io_user_info3");
1392 depth++;
1394 if (UNMARSHALLING(ps))
1395 ZERO_STRUCTP(usr);
1397 if(!prs_align(ps))
1398 return False;
1400 if(!prs_uint32("ptr_user_info ", ps, depth, &usr->ptr_user_info))
1401 return False;
1403 if (usr->ptr_user_info == 0)
1404 return True;
1406 if(!smb_io_time("logon time", &usr->logon_time, ps, depth)) /* logon time */
1407 return False;
1408 if(!smb_io_time("logoff time", &usr->logoff_time, ps, depth)) /* logoff time */
1409 return False;
1410 if(!smb_io_time("kickoff time", &usr->kickoff_time, ps, depth)) /* kickoff time */
1411 return False;
1412 if(!smb_io_time("last set time", &usr->pass_last_set_time, ps, depth)) /* password last set time */
1413 return False;
1414 if(!smb_io_time("can change time", &usr->pass_can_change_time , ps, depth)) /* password can change time */
1415 return False;
1416 if(!smb_io_time("must change time", &usr->pass_must_change_time, ps, depth)) /* password must change time */
1417 return False;
1419 if(!smb_io_unihdr("hdr_user_name", &usr->hdr_user_name, ps, depth)) /* username unicode string header */
1420 return False;
1421 if(!smb_io_unihdr("hdr_full_name", &usr->hdr_full_name, ps, depth)) /* user's full name unicode string header */
1422 return False;
1423 if(!smb_io_unihdr("hdr_logon_script", &usr->hdr_logon_script, ps, depth)) /* logon script unicode string header */
1424 return False;
1425 if(!smb_io_unihdr("hdr_profile_path", &usr->hdr_profile_path, ps, depth)) /* profile path unicode string header */
1426 return False;
1427 if(!smb_io_unihdr("hdr_home_dir", &usr->hdr_home_dir, ps, depth)) /* home directory unicode string header */
1428 return False;
1429 if(!smb_io_unihdr("hdr_dir_drive", &usr->hdr_dir_drive, ps, depth)) /* home directory drive unicode string header */
1430 return False;
1432 if(!prs_uint16("logon_count ", ps, depth, &usr->logon_count)) /* logon count */
1433 return False;
1434 if(!prs_uint16("bad_pw_count ", ps, depth, &usr->bad_pw_count)) /* bad password count */
1435 return False;
1437 if(!prs_uint32("user_rid ", ps, depth, &usr->user_rid)) /* User RID */
1438 return False;
1439 if(!prs_uint32("group_rid ", ps, depth, &usr->group_rid)) /* Group RID */
1440 return False;
1441 if(!prs_uint32("num_groups ", ps, depth, &usr->num_groups)) /* num groups */
1442 return False;
1443 if(!prs_uint32("buffer_groups ", ps, depth, &usr->buffer_groups)) /* undocumented buffer pointer to groups. */
1444 return False;
1445 if(!prs_uint32("user_flgs ", ps, depth, &usr->user_flgs)) /* user flags */
1446 return False;
1448 if(!prs_uint8s(False, "user_sess_key", ps, depth, usr->user_sess_key, 16)) /* unused user session key */
1449 return False;
1451 if(!smb_io_unihdr("hdr_logon_srv", &usr->hdr_logon_srv, ps, depth)) /* logon server unicode string header */
1452 return False;
1453 if(!smb_io_unihdr("hdr_logon_dom", &usr->hdr_logon_dom, ps, depth)) /* logon domain unicode string header */
1454 return False;
1456 if(!prs_uint32("buffer_dom_id ", ps, depth, &usr->buffer_dom_id)) /* undocumented logon domain id pointer */
1457 return False;
1458 if(!prs_uint8s (False, "padding ", ps, depth, usr->padding, 40)) /* unused padding bytes? */
1459 return False;
1461 if (validation_level == 3) {
1462 if(!prs_uint32("num_other_sids", ps, depth, &usr->num_other_sids)) /* 0 - num_sids */
1463 return False;
1464 if(!prs_uint32("buffer_other_sids", ps, depth, &usr->buffer_other_sids)) /* NULL - undocumented pointer to SIDs. */
1465 return False;
1466 } else {
1467 if (UNMARSHALLING(ps)) {
1468 usr->num_other_sids = 0;
1469 usr->buffer_other_sids = 0;
1473 if(!smb_io_unistr2("uni_user_name", &usr->uni_user_name, usr->hdr_user_name.buffer, ps, depth)) /* username unicode string */
1474 return False;
1475 if(!smb_io_unistr2("uni_full_name", &usr->uni_full_name, usr->hdr_full_name.buffer, ps, depth)) /* user's full name unicode string */
1476 return False;
1477 if(!smb_io_unistr2("uni_logon_script", &usr->uni_logon_script, usr->hdr_logon_script.buffer, ps, depth)) /* logon script unicode string */
1478 return False;
1479 if(!smb_io_unistr2("uni_profile_path", &usr->uni_profile_path, usr->hdr_profile_path.buffer, ps, depth)) /* profile path unicode string */
1480 return False;
1481 if(!smb_io_unistr2("uni_home_dir", &usr->uni_home_dir, usr->hdr_home_dir.buffer, ps, depth)) /* home directory unicode string */
1482 return False;
1483 if(!smb_io_unistr2("uni_dir_drive", &usr->uni_dir_drive, usr->hdr_dir_drive.buffer, ps, depth)) /* home directory drive unicode string */
1484 return False;
1486 if(!prs_align(ps))
1487 return False;
1488 if(!prs_uint32("num_groups2 ", ps, depth, &usr->num_groups2)) /* num groups */
1489 return False;
1491 if (UNMARSHALLING(ps) && usr->num_groups2 > 0) {
1492 usr->gids = (DOM_GID *)prs_alloc_mem(ps, sizeof(DOM_GID)*usr->num_groups2);
1493 if (usr->gids == NULL)
1494 return False;
1497 for (i = 0; i < usr->num_groups2; i++) {
1498 if(!smb_io_gid("", &usr->gids[i], ps, depth)) /* group info */
1499 return False;
1502 if(!smb_io_unistr2("uni_logon_srv", &usr->uni_logon_srv, usr->hdr_logon_srv.buffer, ps, depth)) /* logon server unicode string */
1503 return False;
1504 if(!smb_io_unistr2("uni_logon_dom", &usr->uni_logon_dom, usr->hdr_logon_srv.buffer, ps, depth)) /* logon domain unicode string */
1505 return False;
1507 if(!smb_io_dom_sid2("", &usr->dom_sid, ps, depth)) /* domain SID */
1508 return False;
1510 if (usr->num_other_sids) {
1512 if (UNMARSHALLING(ps)) {
1513 usr->other_sids = (DOM_SID2 *)prs_alloc_mem(ps, sizeof(DOM_SID2)*usr->num_other_sids);
1514 if (usr->other_sids == NULL)
1515 return False;
1518 if(!prs_uint32("num_other_groups", ps, depth, &usr->num_other_groups))
1519 return False;
1521 if (UNMARSHALLING(ps) && usr->num_other_groups > 0) {
1522 usr->other_gids = (DOM_GID *)prs_alloc_mem(ps, sizeof(DOM_GID)*usr->num_other_groups);
1523 if (usr->other_gids == NULL)
1524 return False;
1527 for (i = 0; i < usr->num_other_groups; i++) {
1528 if(!smb_io_gid("", &usr->other_gids[i], ps, depth)) /* other GIDs */
1529 return False;
1531 for (i = 0; i < usr->num_other_sids; i++) {
1532 if(!smb_io_dom_sid2("", &usr->other_sids[i], ps, depth)) /* other domain SIDs */
1533 return False;
1537 return True;
1540 /*******************************************************************
1541 Reads or writes a structure.
1542 ********************************************************************/
1544 BOOL net_io_q_sam_logon(char *desc, NET_Q_SAM_LOGON *q_l, prs_struct *ps, int depth)
1546 if (q_l == NULL)
1547 return False;
1549 prs_debug(ps, depth, desc, "net_io_q_sam_logon");
1550 depth++;
1552 if(!prs_align(ps))
1553 return False;
1555 if(!smb_io_sam_info("", &q_l->sam_id, ps, depth))
1556 return False;
1558 if(!prs_uint16("validation_level", ps, depth, &q_l->validation_level))
1559 return False;
1561 return True;
1564 /*******************************************************************
1565 Reads or writes a structure.
1566 ********************************************************************/
1568 BOOL net_io_r_sam_logon(char *desc, NET_R_SAM_LOGON *r_l, prs_struct *ps, int depth)
1570 if (r_l == NULL)
1571 return False;
1573 prs_debug(ps, depth, desc, "net_io_r_sam_logon");
1574 depth++;
1576 if(!prs_uint32("buffer_creds", ps, depth, &r_l->buffer_creds)) /* undocumented buffer pointer */
1577 return False;
1578 if(!smb_io_cred("", &r_l->srv_creds, ps, depth)) /* server credentials. server time stamp appears to be ignored. */
1579 return False;
1581 if(!prs_uint16("switch_value", ps, depth, &r_l->switch_value))
1582 return False;
1583 if(!prs_align(ps))
1584 return False;
1586 #if 1 /* W2k always needs this - even for bad passwd. JRA */
1587 if(!net_io_user_info3("", r_l->user, ps, depth, r_l->switch_value))
1588 return False;
1589 #else
1590 if (r_l->switch_value != 0) {
1591 if(!net_io_user_info3("", r_l->user, ps, depth, r_l->switch_value))
1592 return False;
1594 #endif
1596 if(!prs_uint32("auth_resp ", ps, depth, &r_l->auth_resp)) /* 1 - Authoritative response; 0 - Non-Auth? */
1597 return False;
1599 if(!prs_ntstatus("status ", ps, depth, &r_l->status))
1600 return False;
1602 if(!prs_align(ps))
1603 return False;
1605 return True;
1608 /*******************************************************************
1609 Reads or writes a structure.
1610 ********************************************************************/
1612 BOOL net_io_q_sam_logoff(char *desc, NET_Q_SAM_LOGOFF *q_l, prs_struct *ps, int depth)
1614 if (q_l == NULL)
1615 return False;
1617 prs_debug(ps, depth, desc, "net_io_q_sam_logoff");
1618 depth++;
1620 if(!prs_align(ps))
1621 return False;
1623 if(!smb_io_sam_info("", &q_l->sam_id, ps, depth)) /* domain SID */
1624 return False;
1626 return True;
1629 /*******************************************************************
1630 Reads or writes a structure.
1631 ********************************************************************/
1633 BOOL net_io_r_sam_logoff(char *desc, NET_R_SAM_LOGOFF *r_l, prs_struct *ps, int depth)
1635 if (r_l == NULL)
1636 return False;
1638 prs_debug(ps, depth, desc, "net_io_r_sam_logoff");
1639 depth++;
1641 if(!prs_align(ps))
1642 return False;
1644 if(!prs_uint32("buffer_creds", ps, depth, &r_l->buffer_creds)) /* undocumented buffer pointer */
1645 return False;
1646 if(!smb_io_cred("", &r_l->srv_creds, ps, depth)) /* server credentials. server time stamp appears to be ignored. */
1647 return False;
1649 if(!prs_ntstatus("status ", ps, depth, &r_l->status))
1650 return False;
1652 return True;
1655 /*******************************************************************
1656 makes a NET_Q_SAM_SYNC structure.
1657 ********************************************************************/
1658 BOOL init_net_q_sam_sync(NET_Q_SAM_SYNC * q_s, const char *srv_name,
1659 const char *cli_name, DOM_CRED *cli_creds,
1660 DOM_CRED *ret_creds, uint32 database_id,
1661 uint32 next_rid)
1663 DEBUG(5, ("init_q_sam_sync\n"));
1665 init_unistr2(&q_s->uni_srv_name, srv_name, strlen(srv_name) + 1);
1666 init_unistr2(&q_s->uni_cli_name, cli_name, strlen(cli_name) + 1);
1668 if (cli_creds)
1669 memcpy(&q_s->cli_creds, cli_creds, sizeof(q_s->cli_creds));
1671 if (cli_creds)
1672 memcpy(&q_s->ret_creds, ret_creds, sizeof(q_s->ret_creds));
1673 else
1674 memset(&q_s->ret_creds, 0, sizeof(q_s->ret_creds));
1676 q_s->database_id = database_id;
1677 q_s->restart_state = 0;
1678 q_s->sync_context = next_rid;
1679 q_s->max_size = 0xffff;
1681 return True;
1684 /*******************************************************************
1685 reads or writes a structure.
1686 ********************************************************************/
1687 BOOL net_io_q_sam_sync(char *desc, NET_Q_SAM_SYNC * q_s, prs_struct *ps,
1688 int depth)
1690 prs_debug(ps, depth, desc, "net_io_q_sam_sync");
1691 depth++;
1693 if (!smb_io_unistr2("", &q_s->uni_srv_name, True, ps, depth))
1694 return False;
1695 if (!smb_io_unistr2("", &q_s->uni_cli_name, True, ps, depth))
1696 return False;
1698 if (!smb_io_cred("", &q_s->cli_creds, ps, depth))
1699 return False;
1700 if (!smb_io_cred("", &q_s->ret_creds, ps, depth))
1701 return False;
1703 if (!prs_uint32("database_id ", ps, depth, &q_s->database_id))
1704 return False;
1705 if (!prs_uint32("restart_state", ps, depth, &q_s->restart_state))
1706 return False;
1707 if (!prs_uint32("sync_context ", ps, depth, &q_s->sync_context))
1708 return False;
1710 if (!prs_uint32("max_size", ps, depth, &q_s->max_size))
1711 return False;
1713 return True;
1716 /*******************************************************************
1717 reads or writes a structure.
1718 ********************************************************************/
1719 static BOOL net_io_sam_delta_hdr(char *desc, SAM_DELTA_HDR * delta,
1720 prs_struct *ps, int depth)
1722 prs_debug(ps, depth, desc, "net_io_sam_delta_hdr");
1723 depth++;
1725 if (!prs_uint16("type", ps, depth, &delta->type))
1726 return False;
1727 if (!prs_uint16("type2", ps, depth, &delta->type2))
1728 return False;
1729 if (!prs_uint32("target_rid", ps, depth, &delta->target_rid))
1730 return False;
1732 if (!prs_uint32("type3", ps, depth, &delta->type3))
1733 return False;
1735 /* Not sure why we need this but it seems to be necessary to get
1736 sam deltas working. */
1738 if (delta->type != 0x16) {
1739 if (!prs_uint32("ptr_delta", ps, depth, &delta->ptr_delta))
1740 return False;
1743 return True;
1746 /*******************************************************************
1747 reads or writes a structure.
1748 ********************************************************************/
1749 static BOOL net_io_sam_delta_mod_count(char *desc, SAM_DELTA_MOD_COUNT *info,
1750 prs_struct *ps, int depth)
1752 prs_debug(ps, depth, desc, "net_io_sam_delta_stamp");
1753 depth++;
1755 if (!prs_uint32("seqnum", ps, depth, &info->seqnum))
1756 return False;
1757 if (!prs_uint32("dom_mod_count_ptr", ps, depth,
1758 &info->dom_mod_count_ptr))
1759 return False;
1761 if (info->dom_mod_count_ptr) {
1762 if (!prs_uint64("dom_mod_count", ps, depth,
1763 &info->dom_mod_count))
1764 return False;
1767 return True;
1770 /*******************************************************************
1771 reads or writes a structure.
1772 ********************************************************************/
1773 static BOOL net_io_sam_domain_info(char *desc, SAM_DOMAIN_INFO * info,
1774 prs_struct *ps, int depth)
1776 prs_debug(ps, depth, desc, "net_io_sam_domain_info");
1777 depth++;
1779 if (!smb_io_unihdr("hdr_dom_name", &info->hdr_dom_name, ps, depth))
1780 return False;
1781 if (!smb_io_unihdr("hdr_oem_info", &info->hdr_oem_info, ps, depth))
1782 return False;
1784 if (!prs_uint64("force_logoff", ps, depth, &info->force_logoff))
1785 return False;
1786 if (!prs_uint16("min_pwd_len", ps, depth, &info->min_pwd_len))
1787 return False;
1788 if (!prs_uint16("pwd_history_len", ps, depth, &info->pwd_history_len))
1789 return False;
1790 if (!prs_uint64("max_pwd_age", ps, depth, &info->max_pwd_age))
1791 return False;
1792 if (!prs_uint64("min_pwd_age", ps, depth, &info->min_pwd_age))
1793 return False;
1794 if (!prs_uint64("dom_mod_count", ps, depth, &info->dom_mod_count))
1795 return False;
1796 if (!smb_io_time("creation_time", &info->creation_time, ps, depth))
1797 return False;
1799 if (!smb_io_bufhdr2("hdr_sec_desc", &info->hdr_sec_desc, ps, depth))
1800 return False;
1801 if (!smb_io_unihdr("hdr_unknown", &info->hdr_unknown, ps, depth))
1802 return False;
1804 if (ps->data_offset + 40 > ps->buffer_size)
1805 return False;
1806 ps->data_offset += 40;
1808 if (!smb_io_unistr2("uni_dom_name", &info->uni_dom_name,
1809 info->hdr_dom_name.buffer, ps, depth))
1810 return False;
1811 if (!smb_io_unistr2("buf_oem_info", &info->buf_oem_info,
1812 info->hdr_oem_info.buffer, ps, depth))
1813 return False;
1815 if (!smb_io_buffer4("buf_sec_desc", &info->buf_sec_desc,
1816 info->hdr_sec_desc.buffer, ps, depth))
1817 return False;
1818 if (!smb_io_unistr2("buf_unknown", &info->buf_unknown,
1819 info->hdr_unknown.buffer, ps, depth))
1820 return False;
1822 return True;
1825 /*******************************************************************
1826 reads or writes a structure.
1827 ********************************************************************/
1828 static BOOL net_io_sam_group_info(char *desc, SAM_GROUP_INFO * info,
1829 prs_struct *ps, int depth)
1831 prs_debug(ps, depth, desc, "net_io_sam_group_info");
1832 depth++;
1834 if (!smb_io_unihdr("hdr_grp_name", &info->hdr_grp_name, ps, depth))
1835 return False;
1836 if (!smb_io_gid("gid", &info->gid, ps, depth))
1837 return False;
1838 if (!smb_io_unihdr("hdr_grp_desc", &info->hdr_grp_desc, ps, depth))
1839 return False;
1840 if (!smb_io_bufhdr2("hdr_sec_desc", &info->hdr_sec_desc, ps, depth))
1841 return False;
1843 if (ps->data_offset + 48 > ps->buffer_size)
1844 return False;
1845 ps->data_offset += 48;
1847 if (!smb_io_unistr2("uni_grp_name", &info->uni_grp_name,
1848 info->hdr_grp_name.buffer, ps, depth))
1849 return False;
1850 if (!smb_io_unistr2("uni_grp_desc", &info->uni_grp_desc,
1851 info->hdr_grp_desc.buffer, ps, depth))
1852 return False;
1853 if (!smb_io_buffer4("buf_sec_desc", &info->buf_sec_desc,
1854 info->hdr_sec_desc.buffer, ps, depth))
1855 return False;
1857 return True;
1860 /*******************************************************************
1861 reads or writes a structure.
1862 ********************************************************************/
1863 static BOOL net_io_sam_passwd_info(char *desc, SAM_PWD * pwd,
1864 prs_struct *ps, int depth)
1866 prs_debug(ps, depth, desc, "net_io_sam_passwd_info");
1867 depth++;
1869 if (!prs_uint32("unk_0 ", ps, depth, &pwd->unk_0))
1870 return False;
1872 if (!smb_io_unihdr("hdr_lm_pwd", &pwd->hdr_lm_pwd, ps, depth))
1873 return False;
1874 if (!prs_uint8s(False, "buf_lm_pwd", ps, depth, pwd->buf_lm_pwd, 16))
1875 return False;
1877 if (!smb_io_unihdr("hdr_nt_pwd", &pwd->hdr_nt_pwd, ps, depth))
1878 return False;
1879 if (!prs_uint8s(False, "buf_nt_pwd", ps, depth, pwd->buf_nt_pwd, 16))
1880 return False;
1882 if (!smb_io_unihdr("", &pwd->hdr_empty_lm, ps, depth))
1883 return False;
1884 if (!smb_io_unihdr("", &pwd->hdr_empty_nt, ps, depth))
1885 return False;
1887 return True;
1890 /*******************************************************************
1891 makes a SAM_ACCOUNT_INFO structure.
1892 ********************************************************************/
1893 BOOL make_sam_account_info(SAM_ACCOUNT_INFO * info,
1894 const UNISTR2 *user_name,
1895 const UNISTR2 *full_name,
1896 uint32 user_rid, uint32 group_rid,
1897 const UNISTR2 *home_dir,
1898 const UNISTR2 *dir_drive,
1899 const UNISTR2 *log_scr,
1900 const UNISTR2 *desc,
1901 uint32 acb_info,
1902 const UNISTR2 *prof_path,
1903 const UNISTR2 *wkstas,
1904 const UNISTR2 *unk_str, const UNISTR2 *mung_dial)
1906 int len_user_name = user_name != NULL ? user_name->uni_str_len : 0;
1907 int len_full_name = full_name != NULL ? full_name->uni_str_len : 0;
1908 int len_home_dir = home_dir != NULL ? home_dir->uni_str_len : 0;
1909 int len_dir_drive = dir_drive != NULL ? dir_drive->uni_str_len : 0;
1910 int len_logon_script = log_scr != NULL ? log_scr->uni_str_len : 0;
1911 int len_profile_path = prof_path != NULL ? prof_path->uni_str_len : 0;
1912 int len_description = desc != NULL ? desc->uni_str_len : 0;
1913 int len_workstations = wkstas != NULL ? wkstas->uni_str_len : 0;
1914 int len_unknown_str = unk_str != NULL ? unk_str->uni_str_len : 0;
1915 int len_munged_dial = mung_dial != NULL ? mung_dial->uni_str_len : 0;
1917 DEBUG(5, ("make_sam_account_info\n"));
1919 make_uni_hdr(&info->hdr_acct_name, len_user_name);
1920 make_uni_hdr(&info->hdr_full_name, len_full_name);
1921 make_uni_hdr(&info->hdr_home_dir, len_home_dir);
1922 make_uni_hdr(&info->hdr_dir_drive, len_dir_drive);
1923 make_uni_hdr(&info->hdr_logon_script, len_logon_script);
1924 make_uni_hdr(&info->hdr_profile, len_profile_path);
1925 make_uni_hdr(&info->hdr_acct_desc, len_description);
1926 make_uni_hdr(&info->hdr_workstations, len_workstations);
1927 make_uni_hdr(&info->hdr_comment, len_unknown_str);
1928 make_uni_hdr(&info->hdr_parameters, len_munged_dial);
1930 /* not present */
1931 make_bufhdr2(&info->hdr_sec_desc, 0, 0, 0);
1933 info->user_rid = user_rid;
1934 info->group_rid = group_rid;
1936 init_nt_time(&info->logon_time);
1937 init_nt_time(&info->logoff_time);
1938 init_nt_time(&info->pwd_last_set_time);
1939 init_nt_time(&info->acct_expiry_time);
1941 info->logon_divs = 0xA8;
1942 info->ptr_logon_hrs = 0; /* Don't care right now */
1944 info->bad_pwd_count = 0;
1945 info->logon_count = 0;
1946 info->acb_info = acb_info;
1947 info->nt_pwd_present = 0;
1948 info->lm_pwd_present = 0;
1949 info->pwd_expired = 0;
1950 info->country = 0;
1951 info->codepage = 0;
1953 info->unknown1 = 0x4EC;
1954 info->unknown2 = 0;
1956 copy_unistr2(&info->uni_acct_name, user_name);
1957 copy_unistr2(&info->uni_full_name, full_name);
1958 copy_unistr2(&info->uni_home_dir, home_dir);
1959 copy_unistr2(&info->uni_dir_drive, dir_drive);
1960 copy_unistr2(&info->uni_logon_script, log_scr);
1961 copy_unistr2(&info->uni_profile, prof_path);
1962 copy_unistr2(&info->uni_acct_desc, desc);
1963 copy_unistr2(&info->uni_workstations, wkstas);
1964 copy_unistr2(&info->uni_comment, unk_str);
1965 copy_unistr2(&info->uni_parameters, mung_dial);
1967 return True;
1970 /*******************************************************************
1971 reads or writes a structure.
1972 ********************************************************************/
1973 static BOOL net_io_sam_account_info(char *desc, uint8 sess_key[16],
1974 SAM_ACCOUNT_INFO * info, prs_struct *ps,
1975 int depth)
1977 BUFHDR2 hdr_priv_data;
1978 uint32 i;
1980 prs_debug(ps, depth, desc, "net_io_sam_account_info");
1981 depth++;
1983 if (!smb_io_unihdr("hdr_acct_name", &info->hdr_acct_name, ps, depth))
1984 return False;
1985 if (!smb_io_unihdr("hdr_full_name", &info->hdr_full_name, ps, depth))
1986 return False;
1988 if (!prs_uint32("user_rid ", ps, depth, &info->user_rid))
1989 return False;
1990 if (!prs_uint32("group_rid", ps, depth, &info->group_rid))
1991 return False;
1993 if (!smb_io_unihdr("hdr_home_dir ", &info->hdr_home_dir, ps, depth))
1994 return False;
1995 if (!smb_io_unihdr("hdr_dir_drive", &info->hdr_dir_drive, ps, depth))
1996 return False;
1997 if (!smb_io_unihdr("hdr_logon_script", &info->hdr_logon_script, ps,
1998 depth))
1999 return False;
2001 if (!smb_io_unihdr("hdr_acct_desc", &info->hdr_acct_desc, ps, depth))
2002 return False;
2003 if (!smb_io_unihdr("hdr_workstations", &info->hdr_workstations, ps,
2004 depth))
2005 return False;
2007 if (!smb_io_time("logon_time", &info->logon_time, ps, depth))
2008 return False;
2009 if (!smb_io_time("logoff_time", &info->logoff_time, ps, depth))
2010 return False;
2012 if (!prs_uint32("logon_divs ", ps, depth, &info->logon_divs))
2013 return False;
2014 if (!prs_uint32("ptr_logon_hrs", ps, depth, &info->ptr_logon_hrs))
2015 return False;
2017 if (!prs_uint16("bad_pwd_count", ps, depth, &info->bad_pwd_count))
2018 return False;
2019 if (!prs_uint16("logon_count", ps, depth, &info->logon_count))
2020 return False;
2021 if (!smb_io_time("pwd_last_set_time", &info->pwd_last_set_time, ps,
2022 depth))
2023 return False;
2024 if (!smb_io_time("acct_expiry_time", &info->acct_expiry_time, ps,
2025 depth))
2026 return False;
2028 if (!prs_uint32("acb_info", ps, depth, &info->acb_info))
2029 return False;
2030 if (!prs_uint8s(False, "nt_pwd", ps, depth, info->nt_pwd, 16))
2031 return False;
2032 if (!prs_uint8s(False, "lm_pwd", ps, depth, info->lm_pwd, 16))
2033 return False;
2034 if (!prs_uint8("lm_pwd_present", ps, depth, &info->lm_pwd_present))
2035 return False;
2036 if (!prs_uint8("nt_pwd_present", ps, depth, &info->nt_pwd_present))
2037 return False;
2038 if (!prs_uint8("pwd_expired", ps, depth, &info->pwd_expired))
2039 return False;
2041 if (!smb_io_unihdr("hdr_comment", &info->hdr_comment, ps, depth))
2042 return False;
2043 if (!smb_io_unihdr("hdr_parameters", &info->hdr_parameters, ps,
2044 depth))
2045 return False;
2046 if (!prs_uint16("country", ps, depth, &info->country))
2047 return False;
2048 if (!prs_uint16("codepage", ps, depth, &info->codepage))
2049 return False;
2051 if (!smb_io_bufhdr2("hdr_priv_data", &hdr_priv_data, ps, depth))
2052 return False;
2053 if (!smb_io_bufhdr2("hdr_sec_desc", &info->hdr_sec_desc, ps, depth))
2054 return False;
2055 if (!smb_io_unihdr("hdr_profile", &info->hdr_profile, ps, depth))
2056 return False;
2058 for (i = 0; i < 3; i++)
2060 if (!smb_io_unihdr("hdr_reserved", &info->hdr_reserved[i],
2061 ps, depth))
2062 return False;
2065 for (i = 0; i < 4; i++)
2067 if (!prs_uint32("dw_reserved", ps, depth,
2068 &info->dw_reserved[i]))
2069 return False;
2072 if (!smb_io_unistr2("uni_acct_name", &info->uni_acct_name,
2073 info->hdr_acct_name.buffer, ps, depth))
2074 return False;
2075 prs_align(ps);
2076 if (!smb_io_unistr2("uni_full_name", &info->uni_full_name,
2077 info->hdr_full_name.buffer, ps, depth))
2078 return False;
2079 prs_align(ps);
2080 if (!smb_io_unistr2("uni_home_dir ", &info->uni_home_dir,
2081 info->hdr_home_dir.buffer, ps, depth))
2082 return False;
2083 prs_align(ps);
2084 if (!smb_io_unistr2("uni_dir_drive", &info->uni_dir_drive,
2085 info->hdr_dir_drive.buffer, ps, depth))
2086 return False;
2087 prs_align(ps);
2088 if (!smb_io_unistr2("uni_logon_script", &info->uni_logon_script,
2089 info->hdr_logon_script.buffer, ps, depth))
2090 return False;
2091 prs_align(ps);
2092 if (!smb_io_unistr2("uni_acct_desc", &info->uni_acct_desc,
2093 info->hdr_acct_desc.buffer, ps, depth))
2094 return False;
2095 prs_align(ps);
2096 if (!smb_io_unistr2("uni_workstations", &info->uni_workstations,
2097 info->hdr_workstations.buffer, ps, depth))
2098 return False;
2099 prs_align(ps);
2101 if (!prs_uint32("unknown1", ps, depth, &info->unknown1))
2102 return False;
2103 if (!prs_uint32("unknown2", ps, depth, &info->unknown2))
2104 return False;
2106 if (!smb_io_buffer4("buf_logon_hrs", &info->buf_logon_hrs,
2107 info->ptr_logon_hrs, ps, depth))
2108 return False;
2109 prs_align(ps);
2110 if (!smb_io_unistr2("uni_comment", &info->uni_comment,
2111 info->hdr_comment.buffer, ps, depth))
2112 return False;
2113 prs_align(ps);
2114 if (!smb_io_unistr2("uni_parameters", &info->uni_parameters,
2115 info->hdr_parameters.buffer, ps, depth))
2116 return False;
2117 prs_align(ps);
2118 if (hdr_priv_data.buffer != 0)
2120 int old_offset = 0;
2121 uint32 len = 0x44;
2122 if (!prs_uint32("pwd_len", ps, depth, &len))
2123 return False;
2124 old_offset = ps->data_offset;
2125 if (len == 0x44)
2127 if (ps->io)
2129 /* reading */
2130 if (!prs_hash1(ps, ps->data_offset, sess_key))
2131 return False;
2133 if (!net_io_sam_passwd_info("pass", &info->pass,
2134 ps, depth))
2135 return False;
2137 if (!ps->io)
2139 /* writing */
2140 if (!prs_hash1(ps, old_offset, sess_key))
2141 return False;
2144 if (old_offset + len > ps->buffer_size)
2145 return False;
2146 ps->data_offset = old_offset + len;
2148 if (!smb_io_buffer4("buf_sec_desc", &info->buf_sec_desc,
2149 info->hdr_sec_desc.buffer, ps, depth))
2150 return False;
2151 prs_align(ps);
2152 if (!smb_io_unistr2("uni_profile", &info->uni_profile,
2153 info->hdr_profile.buffer, ps, depth))
2154 return False;
2156 prs_align(ps);
2158 return True;
2161 /*******************************************************************
2162 reads or writes a structure.
2163 ********************************************************************/
2164 static BOOL net_io_sam_group_mem_info(char *desc, SAM_GROUP_MEM_INFO * info,
2165 prs_struct *ps, int depth)
2167 uint32 i;
2168 fstring tmp;
2170 prs_debug(ps, depth, desc, "net_io_sam_group_mem_info");
2171 depth++;
2173 prs_align(ps);
2174 if (!prs_uint32("ptr_rids ", ps, depth, &info->ptr_rids))
2175 return False;
2176 if (!prs_uint32("ptr_attribs", ps, depth, &info->ptr_attribs))
2177 return False;
2178 if (!prs_uint32("num_members", ps, depth, &info->num_members))
2179 return False;
2181 if (ps->data_offset + 16 > ps->buffer_size)
2182 return False;
2183 ps->data_offset += 16;
2185 if (info->ptr_rids != 0)
2187 if (!prs_uint32("num_members2", ps, depth,
2188 &info->num_members2))
2189 return False;
2191 if (info->num_members2 != info->num_members)
2193 /* RPC fault */
2194 return False;
2197 info->rids = talloc(ps->mem_ctx, sizeof(uint32) *
2198 info->num_members2);
2200 if (info->rids == NULL) {
2201 DEBUG(0, ("out of memory allocating %d rids\n",
2202 info->num_members2));
2203 return False;
2206 for (i = 0; i < info->num_members2; i++)
2208 slprintf(tmp, sizeof(tmp) - 1, "rids[%02d]", i);
2209 if (!prs_uint32(tmp, ps, depth, &info->rids[i]))
2210 return False;
2214 if (info->ptr_attribs != 0)
2216 if (!prs_uint32("num_members3", ps, depth,
2217 &info->num_members3))
2218 return False;
2219 if (info->num_members3 != info->num_members)
2221 /* RPC fault */
2222 return False;
2225 info->attribs = talloc(ps->mem_ctx, sizeof(uint32) *
2226 info->num_members3);
2228 if (info->attribs == NULL) {
2229 DEBUG(0, ("out of memory allocating %d attribs\n",
2230 info->num_members3));
2231 return False;
2234 for (i = 0; i < info->num_members3; i++)
2236 slprintf(tmp, sizeof(tmp) - 1, "attribs[%02d]", i);
2237 if (!prs_uint32(tmp, ps, depth, &info->attribs[i]))
2238 return False;
2242 return True;
2245 /*******************************************************************
2246 reads or writes a structure.
2247 ********************************************************************/
2248 static BOOL net_io_sam_alias_info(char *desc, SAM_ALIAS_INFO * info,
2249 prs_struct *ps, int depth)
2251 prs_debug(ps, depth, desc, "net_io_sam_alias_info");
2252 depth++;
2254 if (!smb_io_unihdr("hdr_als_name", &info->hdr_als_name, ps, depth))
2255 return False;
2256 if (!prs_uint32("als_rid", ps, depth, &info->als_rid))
2257 return False;
2258 if (!smb_io_bufhdr2("hdr_sec_desc", &info->hdr_sec_desc, ps, depth))
2259 return False;
2260 if (!smb_io_unihdr("hdr_als_desc", &info->hdr_als_desc, ps, depth))
2261 return False;
2263 if (ps->data_offset + 40 > ps->buffer_size)
2264 return False;
2265 ps->data_offset += 40;
2267 if (!smb_io_unistr2("uni_als_name", &info->uni_als_name,
2268 info->hdr_als_name.buffer, ps, depth))
2269 return False;
2270 if (!smb_io_buffer4("buf_sec_desc", &info->buf_sec_desc,
2271 info->hdr_sec_desc.buffer, ps, depth))
2272 return False;
2273 if (!smb_io_unistr2("uni_als_desc", &info->uni_als_desc,
2274 info->hdr_als_name.buffer, ps, depth))
2275 return False;
2277 return True;
2280 /*******************************************************************
2281 reads or writes a structure.
2282 ********************************************************************/
2283 static BOOL net_io_sam_alias_mem_info(char *desc, SAM_ALIAS_MEM_INFO * info,
2284 prs_struct *ps, int depth)
2286 uint32 i;
2287 fstring tmp;
2289 prs_debug(ps, depth, desc, "net_io_sam_alias_mem_info");
2290 depth++;
2292 prs_align(ps);
2293 if (!prs_uint32("num_members", ps, depth, &info->num_members))
2294 return False;
2295 if (!prs_uint32("ptr_members", ps, depth, &info->ptr_members))
2296 return False;
2298 if (info->ptr_members != 0)
2300 if (ps->data_offset + 16 > ps->buffer_size)
2301 return False;
2302 ps->data_offset += 16;
2304 if (!prs_uint32("num_sids", ps, depth, &info->num_sids))
2305 return False;
2306 if (info->num_sids != info->num_members)
2308 /* RPC fault */
2309 return False;
2312 info->ptr_sids = talloc(ps->mem_ctx, sizeof(uint32) *
2313 info->num_sids);
2315 if (info->ptr_sids == NULL) {
2316 DEBUG(0, ("out of memory allocating %d ptr_sids\n",
2317 info->num_sids));
2318 return False;
2321 for (i = 0; i < info->num_sids; i++)
2323 slprintf(tmp, sizeof(tmp) - 1, "ptr_sids[%02d]", i);
2324 if (!prs_uint32(tmp, ps, depth, &info->ptr_sids[i]))
2325 return False;
2328 info->sids = talloc(ps->mem_ctx, sizeof(DOM_SID2) *
2329 info->num_sids);
2331 if (info->sids == NULL) {
2332 DEBUG(0, ("error allocating %d sids\n",
2333 info->num_sids));
2334 return False;
2337 for (i = 0; i < info->num_sids; i++)
2339 if (info->ptr_sids[i] != 0)
2341 slprintf(tmp, sizeof(tmp) - 1, "sids[%02d]",
2343 if (!smb_io_dom_sid2(tmp, &info->sids[i],
2344 ps, depth))
2345 return False;
2350 return True;
2353 /*******************************************************************
2354 reads or writes a structure.
2355 ********************************************************************/
2356 static BOOL net_io_sam_policy_info(char *desc, SAM_DELTA_POLICY *info,
2357 prs_struct *ps, int depth)
2359 int i;
2360 prs_debug(ps, depth, desc, "net_io_sam_policy_info");
2361 depth++;
2363 if(!prs_align(ps))
2364 return False;
2366 if (!prs_uint32("max_log_size", ps, depth, &info->max_log_size))
2367 return False;
2368 if (!prs_uint64("audit_retention_period", ps, depth,
2369 &info->audit_retention_period))
2370 return False;
2371 if (!prs_uint32("auditing_mode", ps, depth, &info->auditing_mode))
2372 return False;
2373 if (!prs_uint32("num_events", ps, depth, &info->num_events))
2374 return False;
2375 if (!prs_uint32("ptr_events", ps, depth, &info->ptr_events))
2376 return False;
2378 if (!smb_io_unihdr("hdr_dom_name", &info->hdr_dom_name, ps, depth))
2379 return False;
2381 if (!prs_uint32("sid_ptr", ps, depth, &info->sid_ptr))
2382 return False;
2384 if (!prs_uint32("paged_pool_limit", ps, depth, &info->paged_pool_limit))
2385 return False;
2386 if (!prs_uint32("non_paged_pool_limit", ps, depth,
2387 &info->non_paged_pool_limit))
2388 return False;
2389 if (!prs_uint32("min_workset_size", ps, depth, &info->min_workset_size))
2390 return False;
2391 if (!prs_uint32("max_workset_size", ps, depth, &info->max_workset_size))
2392 return False;
2393 if (!prs_uint32("page_file_limit", ps, depth, &info->page_file_limit))
2394 return False;
2395 if (!prs_uint64("time_limit", ps, depth, &info->time_limit))
2396 return False;
2397 if (!smb_io_time("modify_time", &info->modify_time, ps, depth))
2398 return False;
2399 if (!smb_io_time("create_time", &info->create_time, ps, depth))
2400 return False;
2401 if (!smb_io_bufhdr2("hdr_sec_desc", &info->hdr_sec_desc, ps, depth))
2402 return False;
2404 for (i=0; i<4; i++) {
2405 UNIHDR dummy;
2406 if (!smb_io_unihdr("dummy", &dummy, ps, depth))
2407 return False;
2410 for (i=0; i<4; i++) {
2411 uint32 reserved;
2412 if (!prs_uint32("reserved", ps, depth, &reserved))
2413 return False;
2416 if (!prs_uint32("num_event_audit_options", ps, depth,
2417 &info->num_event_audit_options))
2418 return False;
2420 for (i=0; i<info->num_event_audit_options; i++)
2421 if (!prs_uint32("event_audit_option", ps, depth,
2422 &info->event_audit_option))
2423 return False;
2425 if (!smb_io_unistr2("domain_name", &info->domain_name, True, ps, depth))
2426 return False;
2428 if(!smb_io_dom_sid2("domain_sid", &info->domain_sid, ps, depth))
2429 return False;
2431 if (!smb_io_buffer4("buf_sec_desc", &info->buf_sec_desc,
2432 info->hdr_sec_desc.buffer, ps, depth))
2434 return False;
2436 return True;
2439 /*******************************************************************
2440 reads or writes a structure.
2441 ********************************************************************/
2442 static BOOL net_io_sam_trustdoms_info(char *desc, SAM_DELTA_TRUSTDOMS *info,
2443 prs_struct *ps, int depth)
2445 int i;
2447 prs_debug(ps, depth, desc, "net_io_sam_trustdoms_info");
2448 depth++;
2450 if(!prs_align(ps))
2451 return False;
2453 if(!prs_uint32("buf_size", ps, depth, &info->buf_size))
2454 return False;
2456 if(!sec_io_desc("sec_desc", &info->sec_desc, ps, depth))
2457 return False;
2459 if(!smb_io_dom_sid2("sid", &info->sid, ps, depth))
2460 return False;
2462 if(!smb_io_unihdr("hdr_domain", &info->hdr_domain, ps, depth))
2463 return False;
2465 if(!prs_uint32("unknown0", ps, depth, &info->unknown0))
2466 return False;
2467 if(!prs_uint32("unknown1", ps, depth, &info->unknown1))
2468 return False;
2469 if(!prs_uint32("unknown2", ps, depth, &info->unknown2))
2470 return False;
2472 if(!prs_uint32("buf_size2", ps, depth, &info->buf_size2))
2473 return False;
2474 if(!prs_uint32("ptr", ps, depth, &info->ptr))
2475 return False;
2477 for (i=0; i<12; i++)
2478 if(!prs_uint32("unknown3", ps, depth, &info->unknown3))
2479 return False;
2481 if (!smb_io_unistr2("domain", &info->domain, True, ps, depth))
2482 return False;
2484 return True;
2487 /*******************************************************************
2488 reads or writes a structure.
2489 ********************************************************************/
2490 static BOOL net_io_sam_secret_info(char *desc, SAM_DELTA_SECRET *info,
2491 prs_struct *ps, int depth)
2493 int i;
2495 prs_debug(ps, depth, desc, "net_io_sam_secret_info");
2496 depth++;
2498 if(!prs_align(ps))
2499 return False;
2501 if(!prs_uint32("buf_size", ps, depth, &info->buf_size))
2502 return False;
2504 if(!sec_io_desc("sec_desc", &info->sec_desc, ps, depth))
2505 return False;
2507 if (!smb_io_unistr2("secret", &info->secret, True, ps, depth))
2508 return False;
2510 if(!prs_align(ps))
2511 return False;
2513 if(!prs_uint32("count1", ps, depth, &info->count1))
2514 return False;
2515 if(!prs_uint32("count2", ps, depth, &info->count2))
2516 return False;
2517 if(!prs_uint32("ptr", ps, depth, &info->ptr))
2518 return False;
2521 if(!smb_io_time("time1", &info->time1, ps, depth)) /* logon time */
2522 return False;
2523 if(!prs_uint32("count3", ps, depth, &info->count3))
2524 return False;
2525 if(!prs_uint32("count4", ps, depth, &info->count4))
2526 return False;
2527 if(!prs_uint32("ptr2", ps, depth, &info->ptr2))
2528 return False;
2529 if(!smb_io_time("time2", &info->time2, ps, depth)) /* logon time */
2530 return False;
2531 if(!prs_uint32("unknow1", ps, depth, &info->unknow1))
2532 return False;
2535 if(!prs_uint32("buf_size2", ps, depth, &info->buf_size2))
2536 return False;
2537 if(!prs_uint32("ptr3", ps, depth, &info->ptr3))
2538 return False;
2539 for(i=0; i<12; i++)
2540 if(!prs_uint32("unknow2", ps, depth, &info->unknow2))
2541 return False;
2543 if(!prs_uint32("chal_len", ps, depth, &info->chal_len))
2544 return False;
2545 if(!prs_uint32("reserved1", ps, depth, &info->reserved1))
2546 return False;
2547 if(!prs_uint32("chal_len2", ps, depth, &info->chal_len2))
2548 return False;
2550 if(!prs_uint8s (False, "chal", ps, depth, info->chal, info->chal_len2))
2551 return False;
2553 if(!prs_uint32("key_len", ps, depth, &info->key_len))
2554 return False;
2555 if(!prs_uint32("reserved2", ps, depth, &info->reserved2))
2556 return False;
2557 if(!prs_uint32("key_len2", ps, depth, &info->key_len2))
2558 return False;
2560 if(!prs_uint8s (False, "key", ps, depth, info->key, info->key_len2))
2561 return False;
2564 if(!prs_uint32("buf_size3", ps, depth, &info->buf_size3))
2565 return False;
2567 if(!sec_io_desc("sec_desc2", &info->sec_desc2, ps, depth))
2568 return False;
2571 return True;
2574 /*******************************************************************
2575 reads or writes a structure.
2576 ********************************************************************/
2577 static BOOL net_io_sam_privs_info(char *desc, SAM_DELTA_PRIVS *info,
2578 prs_struct *ps, int depth)
2580 int i;
2582 prs_debug(ps, depth, desc, "net_io_sam_privs_info");
2583 depth++;
2585 if(!prs_align(ps))
2586 return False;
2588 if(!smb_io_dom_sid2("sid", &info->sid, ps, depth))
2589 return False;
2591 if(!prs_uint32("priv_count", ps, depth, &info->priv_count))
2592 return False;
2593 if(!prs_uint32("priv_control", ps, depth, &info->priv_control))
2594 return False;
2596 if(!prs_uint32("priv_attr_ptr", ps, depth, &info->priv_attr_ptr))
2597 return False;
2598 if(!prs_uint32("priv_name_ptr", ps, depth, &info->priv_name_ptr))
2599 return False;
2601 if (!prs_uint32("paged_pool_limit", ps, depth, &info->paged_pool_limit))
2602 return False;
2603 if (!prs_uint32("non_paged_pool_limit", ps, depth,
2604 &info->non_paged_pool_limit))
2605 return False;
2606 if (!prs_uint32("min_workset_size", ps, depth, &info->min_workset_size))
2607 return False;
2608 if (!prs_uint32("max_workset_size", ps, depth, &info->max_workset_size))
2609 return False;
2610 if (!prs_uint32("page_file_limit", ps, depth, &info->page_file_limit))
2611 return False;
2612 if (!prs_uint64("time_limit", ps, depth, &info->time_limit))
2613 return False;
2614 if (!prs_uint32("system_flags", ps, depth, &info->system_flags))
2615 return False;
2616 if (!smb_io_bufhdr2("hdr_sec_desc", &info->hdr_sec_desc, ps, depth))
2617 return False;
2619 for (i=0; i<4; i++) {
2620 UNIHDR dummy;
2621 if (!smb_io_unihdr("dummy", &dummy, ps, depth))
2622 return False;
2625 for (i=0; i<4; i++) {
2626 uint32 reserved;
2627 if (!prs_uint32("reserved", ps, depth, &reserved))
2628 return False;
2631 if(!prs_uint32("attribute_count", ps, depth, &info->attribute_count))
2632 return False;
2634 info->attributes = talloc(ps->mem_ctx, sizeof(uint32) * info->attribute_count);
2636 for (i=0; i<info->attribute_count; i++)
2637 if(!prs_uint32("attributes", ps, depth, &info->attributes[i]))
2638 return False;
2640 if(!prs_uint32("privlist_count", ps, depth, &info->privlist_count))
2641 return False;
2643 info->hdr_privslist = talloc(ps->mem_ctx, sizeof(UNIHDR) * info->privlist_count);
2644 info->uni_privslist = talloc(ps->mem_ctx, sizeof(UNISTR2) * info->privlist_count);
2646 for (i=0; i<info->privlist_count; i++)
2647 if(!smb_io_unihdr("hdr_privslist", &info->hdr_privslist[i], ps, depth))
2648 return False;
2650 for (i=0; i<info->privlist_count; i++)
2651 if (!smb_io_unistr2("uni_privslist", &info->uni_privslist[i], True, ps, depth))
2652 return False;
2654 if (!smb_io_buffer4("buf_sec_desc", &info->buf_sec_desc,
2655 info->hdr_sec_desc.buffer, ps, depth))
2656 return False;
2658 return True;
2661 /*******************************************************************
2662 reads or writes a structure.
2663 ********************************************************************/
2664 static BOOL net_io_sam_delta_ctr(char *desc, uint8 sess_key[16],
2665 SAM_DELTA_CTR * delta, uint16 type,
2666 prs_struct *ps, int depth)
2668 prs_debug(ps, depth, desc, "net_io_sam_delta_ctr");
2669 depth++;
2671 switch (type) {
2672 /* Seen in sam deltas */
2673 case SAM_DELTA_MODIFIED_COUNT:
2674 if (!net_io_sam_delta_mod_count("", &delta->mod_count, ps, depth))
2675 return False;
2676 break;
2678 case SAM_DELTA_DOMAIN_INFO:
2679 if (!net_io_sam_domain_info("", &delta->domain_info, ps, depth))
2680 return False;
2681 break;
2683 case SAM_DELTA_GROUP_INFO:
2684 if (!net_io_sam_group_info("", &delta->group_info, ps, depth))
2685 return False;
2686 break;
2688 case SAM_DELTA_ACCOUNT_INFO:
2689 if (!net_io_sam_account_info("", sess_key, &delta->account_info, ps, depth))
2690 return False;
2691 break;
2693 case SAM_DELTA_GROUP_MEM:
2694 if (!net_io_sam_group_mem_info("", &delta->grp_mem_info, ps, depth))
2695 return False;
2696 break;
2698 case SAM_DELTA_ALIAS_INFO:
2699 if (!net_io_sam_alias_info("", &delta->alias_info, ps, depth))
2700 return False;
2701 break;
2703 case SAM_DELTA_POLICY_INFO:
2704 if (!net_io_sam_policy_info("", &delta->policy_info, ps, depth))
2705 return False;
2706 break;
2708 case SAM_DELTA_ALIAS_MEM:
2709 if (!net_io_sam_alias_mem_info("", &delta->als_mem_info, ps, depth))
2710 return False;
2711 break;
2713 case SAM_DELTA_PRIVS_INFO:
2714 if (!net_io_sam_privs_info("", &delta->privs_info, ps, depth))
2715 return False;
2716 break;
2718 case SAM_DELTA_TRUST_DOMS:
2719 if (!net_io_sam_trustdoms_info("", &delta->trustdoms_info, ps, depth))
2720 return False;
2721 break;
2723 case SAM_DELTA_SECRET_INFO:
2724 if (!net_io_sam_secret_info("", &delta->secret_info, ps, depth))
2725 return False;
2726 break;
2728 /* These guys are not implemented yet */
2730 case SAM_DELTA_RENAME_GROUP:
2731 case SAM_DELTA_RENAME_USER:
2732 case SAM_DELTA_RENAME_ALIAS:
2733 case SAM_DELTA_DELETE_GROUP:
2734 case SAM_DELTA_DELETE_USER:
2735 default:
2736 DEBUG(0, ("Replication error: Unknown delta type 0x%x\n", type));
2737 break;
2740 return True;
2743 /*******************************************************************
2744 reads or writes a structure.
2745 ********************************************************************/
2746 BOOL net_io_r_sam_sync(char *desc, uint8 sess_key[16],
2747 NET_R_SAM_SYNC * r_s, prs_struct *ps, int depth)
2749 uint32 i;
2751 prs_debug(ps, depth, desc, "net_io_r_sam_sync");
2752 depth++;
2754 if (!smb_io_cred("srv_creds", &r_s->srv_creds, ps, depth))
2755 return False;
2756 if (!prs_uint32("sync_context", ps, depth, &r_s->sync_context))
2757 return False;
2759 if (!prs_uint32("ptr_deltas", ps, depth, &r_s->ptr_deltas))
2760 return False;
2761 if (r_s->ptr_deltas != 0)
2763 if (!prs_uint32("num_deltas ", ps, depth, &r_s->num_deltas))
2764 return False;
2765 if (!prs_uint32("ptr_deltas2", ps, depth, &r_s->ptr_deltas2))
2766 return False;
2767 if (r_s->ptr_deltas2 != 0)
2769 if (!prs_uint32("num_deltas2", ps, depth,
2770 &r_s->num_deltas2))
2771 return False;
2773 if (r_s->num_deltas2 != r_s->num_deltas)
2775 /* RPC fault */
2776 return False;
2779 if (r_s->num_deltas2 > 0) {
2780 r_s->hdr_deltas = (SAM_DELTA_HDR *)
2781 talloc(ps->mem_ctx, r_s->num_deltas2 *
2782 sizeof(SAM_DELTA_HDR));
2784 if (r_s->hdr_deltas == NULL) {
2785 DEBUG(0, ("error tallocating memory "
2786 "for %d delta headers\n",
2787 r_s->num_deltas2));
2788 return False;
2792 for (i = 0; i < r_s->num_deltas2; i++)
2794 if (!net_io_sam_delta_hdr("",
2795 &r_s->hdr_deltas[i],
2796 ps, depth))
2797 return False;
2800 if (r_s->num_deltas2 > 0) {
2801 r_s->deltas = (SAM_DELTA_CTR *)
2802 talloc(ps->mem_ctx, r_s->num_deltas2 *
2803 sizeof(SAM_DELTA_CTR));
2805 if (r_s->deltas == NULL) {
2806 DEBUG(0, ("error tallocating memory "
2807 "for %d deltas\n",
2808 r_s->num_deltas2));
2809 return False;
2813 for (i = 0; i < r_s->num_deltas2; i++)
2815 if (!net_io_sam_delta_ctr(
2816 "", sess_key, &r_s->deltas[i],
2817 r_s->hdr_deltas[i].type3,
2818 ps, depth)) {
2819 DEBUG(0, ("hmm, failed on i=%d\n", i));
2820 return False;
2826 prs_align(ps);
2827 if (!prs_ntstatus("status", ps, depth, &(r_s->status)))
2828 return False;
2830 return True;
2833 /*******************************************************************
2834 makes a NET_Q_SAM_DELTAS structure.
2835 ********************************************************************/
2836 BOOL init_net_q_sam_deltas(NET_Q_SAM_DELTAS *q_s, const char *srv_name,
2837 const char *cli_name, DOM_CRED *cli_creds,
2838 uint32 database_id, UINT64_S dom_mod_count)
2840 DEBUG(5, ("init_net_q_sam_deltas\n"));
2842 init_unistr2(&q_s->uni_srv_name, srv_name, strlen(srv_name) + 1);
2843 init_unistr2(&q_s->uni_cli_name, cli_name, strlen(cli_name) + 1);
2845 memcpy(&q_s->cli_creds, cli_creds, sizeof(q_s->cli_creds));
2846 memset(&q_s->ret_creds, 0, sizeof(q_s->ret_creds));
2848 q_s->database_id = database_id;
2849 q_s->dom_mod_count.low = dom_mod_count.low;
2850 q_s->dom_mod_count.high = dom_mod_count.high;
2851 q_s->max_size = 0xffff;
2853 return True;
2856 /*******************************************************************
2857 reads or writes a structure.
2858 ********************************************************************/
2859 BOOL net_io_q_sam_deltas(char *desc, NET_Q_SAM_DELTAS *q_s, prs_struct *ps,
2860 int depth)
2862 prs_debug(ps, depth, desc, "net_io_q_sam_deltas");
2863 depth++;
2865 if (!smb_io_unistr2("", &q_s->uni_srv_name, True, ps, depth))
2866 return False;
2867 if (!smb_io_unistr2("", &q_s->uni_cli_name, True, ps, depth))
2868 return False;
2870 if (!smb_io_cred("", &q_s->cli_creds, ps, depth))
2871 return False;
2872 if (!smb_io_cred("", &q_s->ret_creds, ps, depth))
2873 return False;
2875 if (!prs_uint32("database_id ", ps, depth, &q_s->database_id))
2876 return False;
2877 if (!prs_uint64("dom_mod_count", ps, depth, &q_s->dom_mod_count))
2878 return False;
2879 if (!prs_uint32("max_size", ps, depth, &q_s->max_size))
2880 return False;
2882 return True;
2885 /*******************************************************************
2886 reads or writes a structure.
2887 ********************************************************************/
2888 BOOL net_io_r_sam_deltas(char *desc, uint8 sess_key[16],
2889 NET_R_SAM_DELTAS *r_s, prs_struct *ps, int depth)
2891 int i;
2893 prs_debug(ps, depth, desc, "net_io_r_sam_deltas");
2894 depth++;
2896 if (!smb_io_cred("srv_creds", &r_s->srv_creds, ps, depth))
2897 return False;
2898 if (!prs_uint64("dom_mod_count", ps, depth, &r_s->dom_mod_count))
2899 return False;
2901 if (!prs_uint32("ptr_deltas", ps, depth, &r_s->ptr_deltas))
2902 return False;
2903 if (!prs_uint32("num_deltas", ps, depth, &r_s->num_deltas))
2904 return False;
2905 if (!prs_uint32("ptr_deltas2", ps, depth, &r_s->num_deltas2))
2906 return False;
2908 if (r_s->num_deltas2 != 0)
2910 if (!prs_uint32("num_deltas2 ", ps, depth, &r_s->num_deltas2))
2911 return False;
2913 if (r_s->ptr_deltas != 0)
2915 if (r_s->num_deltas > 0) {
2916 r_s->hdr_deltas = (SAM_DELTA_HDR *)
2917 talloc(ps->mem_ctx, r_s->num_deltas *
2918 sizeof(SAM_DELTA_HDR));
2919 if (r_s->hdr_deltas == NULL) {
2920 DEBUG(0, ("error tallocating memory "
2921 "for %d delta headers\n",
2922 r_s->num_deltas));
2923 return False;
2927 for (i = 0; i < r_s->num_deltas; i++)
2929 net_io_sam_delta_hdr("", &r_s->hdr_deltas[i],
2930 ps, depth);
2933 if (r_s->num_deltas > 0) {
2934 r_s->deltas = (SAM_DELTA_CTR *)
2935 talloc(ps->mem_ctx, r_s->num_deltas *
2936 sizeof(SAM_DELTA_CTR));
2938 if (r_s->deltas == NULL) {
2939 DEBUG(0, ("error tallocating memory "
2940 "for %d deltas\n",
2941 r_s->num_deltas));
2942 return False;
2946 for (i = 0; i < r_s->num_deltas; i++)
2948 if (!net_io_sam_delta_ctr(
2949 "", sess_key,
2950 &r_s->deltas[i],
2951 r_s->hdr_deltas[i].type2,
2952 ps, depth))
2954 return False;
2959 prs_align(ps);
2960 if (!prs_ntstatus("status", ps, depth, &r_s->status))
2961 return False;
2963 return True;