2 Unix SMB/CIFS implementation.
3 NBT netbios routines and daemon - version 2
4 Copyright (C) Andrew Tridgell 1994-1998
5 Copyright (C) Luke Kenneth Casson Leighton 1994-1998
6 Copyright (C) Jeremy Allison 1994-2003
7 Copyright (C) Jim McDonough <jmcd@us.ibm.com> 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 3 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, see <http://www.gnu.org/licenses/>.
27 #include "../libcli/netlogon.h"
28 #include "../libcli/cldap/cldap.h"
29 #include "../lib/tsocket/tsocket.h"
30 #include "../libcli/security/dom_sid.h"
32 struct sam_database_info
{
34 uint32 serial_lo
, serial_hi
;
35 uint32 date_lo
, date_hi
;
39 * check whether the client belongs to the hosts
40 * for which initial logon should be delayed...
42 static bool delay_logon(const char *peer_name
, const char *peer_addr
)
44 const char **delay_list
= lp_init_logon_delayed_hosts();
47 if (delay_list
== NULL
) {
54 return list_match(delay_list
, (const char *)peer
, client_match
);
57 static void delayed_init_logon_handler(struct event_context
*event_ctx
,
58 struct timed_event
*te
,
62 struct packet_struct
*p
= (struct packet_struct
*)private_data
;
64 DEBUG(10, ("delayed_init_logon_handler (%lx): re-queuing packet.\n",
72 struct nmbd_proxy_logon_context
{
73 struct cldap_socket
*cldap_sock
;
76 static struct nmbd_proxy_logon_context
*global_nmbd_proxy_logon
;
78 bool initialize_nmbd_proxy_logon(void)
80 const char *cldap_server
= lp_parm_const_string(-1, "nmbd_proxy_logon",
81 "cldap_server", NULL
);
82 struct nmbd_proxy_logon_context
*ctx
;
85 char addrstr
[INET_ADDRSTRLEN
];
86 const char *server_str
;
88 struct tsocket_address
*server_addr
;
94 addr
= interpret_addr2(cldap_server
);
95 server_str
= inet_ntop(AF_INET
, &addr
,
96 addrstr
, sizeof(addrstr
));
97 if (!server_str
|| strcmp("0.0.0.0", server_str
) == 0) {
98 DEBUG(0,("Failed to resolve[%s] for nmbd_proxy_logon\n",
103 ctx
= talloc_zero(nmbd_event_context(),
104 struct nmbd_proxy_logon_context
);
109 ret
= tsocket_address_inet_from_strings(ctx
, "ipv4",
110 server_str
, LDAP_PORT
,
114 status
= map_nt_error_from_unix(errno
);
115 DEBUG(0,("Failed to create cldap tsocket_address for %s - %s\n",
116 server_str
, nt_errstr(status
)));
120 /* we create a connected udp socket */
121 status
= cldap_socket_init(ctx
, nmbd_event_context(), NULL
,
122 server_addr
, &ctx
->cldap_sock
);
123 TALLOC_FREE(server_addr
);
124 if (!NT_STATUS_IS_OK(status
)) {
126 DEBUG(0,("failed to create cldap socket for %s: %s\n",
127 server_str
, nt_errstr(status
)));
131 global_nmbd_proxy_logon
= ctx
;
135 struct nmbd_proxy_logon_state
{
136 struct in_addr local_ip
;
137 struct packet_struct
*p
;
138 const char *remote_name
;
139 uint8_t remote_name_type
;
140 const char *remote_mailslot
;
141 struct nbt_netlogon_packet req
;
142 struct nbt_netlogon_response resp
;
143 struct cldap_netlogon io
;
146 static int nmbd_proxy_logon_state_destructor(struct nmbd_proxy_logon_state
*s
)
148 s
->p
->locked
= false;
153 static void nmbd_proxy_logon_done(struct tevent_req
*subreq
);
155 static void nmbd_proxy_logon(struct nmbd_proxy_logon_context
*ctx
,
156 struct in_addr local_ip
,
157 struct packet_struct
*p
,
161 struct nmbd_proxy_logon_state
*state
;
162 enum ndr_err_code ndr_err
;
163 DATA_BLOB blob
= data_blob_const(buf
, len
);
164 const char *computer_name
= NULL
;
165 const char *mailslot_name
= NULL
;
166 const char *user_name
= NULL
;
167 const char *domain_sid
= NULL
;
168 uint32_t acct_control
= 0;
169 uint32_t nt_version
= 0;
170 struct tevent_req
*subreq
;
172 struct dgram_packet
*dgram
= &p
->packet
.dgram
;
174 state
= TALLOC_ZERO_P(ctx
, struct nmbd_proxy_logon_state
);
176 DEBUG(0,("failed to allocate nmbd_proxy_logon_state\n"));
180 pull_ascii_nstring(source_name
, sizeof(source_name
), dgram
->source_name
.name
);
181 state
->remote_name
= talloc_strdup(state
, source_name
);
182 state
->remote_name_type
= dgram
->source_name
.name_type
,
183 state
->local_ip
= local_ip
;
186 ndr_err
= ndr_pull_struct_blob(
187 &blob
, state
, &state
->req
,
188 (ndr_pull_flags_fn_t
)ndr_pull_nbt_netlogon_packet
);
189 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
190 NTSTATUS status
= ndr_map_error2ntstatus(ndr_err
);
191 DEBUG(0,("failed parse nbt_netlogon_packet: %s\n",
197 if (DEBUGLEVEL
>= 10) {
198 DEBUG(10, ("nmbd_proxy_logon:\n"));
199 NDR_PRINT_DEBUG(nbt_netlogon_packet
, &state
->req
);
202 switch (state
->req
.command
) {
203 case LOGON_SAM_LOGON_REQUEST
:
204 computer_name
= state
->req
.req
.logon
.computer_name
;
205 user_name
= state
->req
.req
.logon
.user_name
;
206 mailslot_name
= state
->req
.req
.logon
.mailslot_name
;
207 acct_control
= state
->req
.req
.logon
.acct_control
;
208 if (state
->req
.req
.logon
.sid_size
> 0) {
209 domain_sid
= dom_sid_string(state
,
210 &state
->req
.req
.logon
.sid
);
212 DEBUG(0,("failed to get a string for sid\n"));
217 nt_version
= state
->req
.req
.logon
.nt_version
;
221 /* this can't happen as the caller already checks the command */
225 state
->remote_mailslot
= mailslot_name
;
227 if (user_name
&& strlen(user_name
) == 0) {
231 if (computer_name
&& strlen(computer_name
) == 0) {
232 computer_name
= NULL
;
236 * as the socket is connected,
237 * we don't need to specify the destination
239 state
->io
.in
.dest_address
= NULL
;
240 state
->io
.in
.dest_port
= 0;
241 state
->io
.in
.realm
= NULL
;
242 state
->io
.in
.host
= computer_name
;
243 state
->io
.in
.user
= user_name
;
244 state
->io
.in
.domain_guid
= NULL
;
245 state
->io
.in
.domain_sid
= domain_sid
;
246 state
->io
.in
.acct_control
= acct_control
;
247 state
->io
.in
.version
= nt_version
;
248 state
->io
.in
.map_response
= false;
250 subreq
= cldap_netlogon_send(state
,
254 DEBUG(0,("failed to send cldap netlogon call\n"));
258 tevent_req_set_callback(subreq
, nmbd_proxy_logon_done
, state
);
261 state
->p
->locked
= true;
262 talloc_set_destructor(state
, nmbd_proxy_logon_state_destructor
);
265 static void nmbd_proxy_logon_done(struct tevent_req
*subreq
)
267 struct nmbd_proxy_logon_state
*state
=
268 tevent_req_callback_data(subreq
,
269 struct nmbd_proxy_logon_state
);
271 DATA_BLOB response
= data_blob_null
;
273 status
= cldap_netlogon_recv(subreq
, state
, &state
->io
);
274 if (!NT_STATUS_IS_OK(status
)) {
275 DEBUG(0,("failed to recv cldap netlogon call: %s\n",
281 status
= push_netlogon_samlogon_response(&response
, state
,
282 &state
->io
.out
.netlogon
);
283 if (!NT_STATUS_IS_OK(status
)) {
284 DEBUG(0,("failed to push netlogon_samlogon_response: %s\n",
290 send_mailslot(true, state
->remote_mailslot
,
291 (char *)response
.data
, response
.length
,
292 global_myname(), 0x0,
294 state
->remote_name_type
,
301 /****************************************************************************
302 Process a domain logon packet
303 **************************************************************************/
305 void process_logon_packet(struct packet_struct
*p
, char *buf
,int len
,
306 const char *mailslot
)
308 struct dgram_packet
*dgram
= &p
->packet
.dgram
;
314 uint32 ntversion
= 0;
315 uint16 lmnttoken
= 0;
316 uint16 lm20token
= 0;
317 uint32 domainsidsize
;
318 bool short_request
= False
;
320 char *uniuser
; /* Unicode user name. */
322 char *unicomp
; /* Unicode computer name. */
324 struct sockaddr_storage ss
;
325 const struct sockaddr_storage
*pss
;
328 in_addr_to_sockaddr_storage(&ss
, p
->ip
);
329 pss
= iface_ip((struct sockaddr
*)&ss
);
331 DEBUG(5,("process_logon_packet:can't find outgoing interface "
332 "for packet from IP %s\n",
336 ip
= ((struct sockaddr_in
*)pss
)->sin_addr
;
338 memset(outbuf
, 0, sizeof(outbuf
));
340 if (!lp_domain_logons()) {
341 DEBUG(5,("process_logon_packet: Logon packet received from IP %s and domain \
342 logons are not enabled.\n", inet_ntoa(p
->ip
) ));
346 fstrcpy(my_name
, global_myname());
348 code
= get_safe_SVAL(buf
,len
,buf
,0,-1);
349 DEBUG(4,("process_logon_packet: Logon from %s: code = 0x%x\n", inet_ntoa(p
->ip
), code
));
354 fstring mach_str
, user_str
, getdc_str
;
357 char *user
= skip_string(buf
,len
,machine
);
359 if (!user
|| PTR_DIFF(user
, buf
) >= len
) {
360 DEBUG(0,("process_logon_packet: bad packet\n"));
363 getdc
= skip_string(buf
,len
,user
);
365 if (!getdc
|| PTR_DIFF(getdc
, buf
) >= len
) {
366 DEBUG(0,("process_logon_packet: bad packet\n"));
369 q
= skip_string(buf
,len
,getdc
);
371 if (!q
|| PTR_DIFF(q
+ 5, buf
) > len
) {
372 DEBUG(0,("process_logon_packet: bad packet\n"));
377 fstrcpy(reply_name
,my_name
);
379 pull_ascii_fstring(mach_str
, machine
);
380 pull_ascii_fstring(user_str
, user
);
381 pull_ascii_fstring(getdc_str
, getdc
);
383 DEBUG(5,("process_logon_packet: Domain login request from %s at IP %s user=%s token=%x\n",
384 mach_str
,inet_ntoa(p
->ip
),user_str
,token
));
390 fstrcpy(reply_name
, "\\\\");
391 fstrcat(reply_name
, my_name
);
392 size
= push_ascii(q
,reply_name
,
393 sizeof(outbuf
)-PTR_DIFF(q
, outbuf
),
395 if (size
== (size_t)-1) {
398 q
= skip_string(outbuf
,sizeof(outbuf
),q
); /* PDC name */
403 dump_data(4, (uint8
*)outbuf
, PTR_DIFF(q
, outbuf
));
405 send_mailslot(True
, getdc_str
,
406 outbuf
,PTR_DIFF(q
,outbuf
),
407 global_myname(), 0x0,
409 dgram
->source_name
.name_type
,
414 case LOGON_PRIMARY_QUERY
:
416 fstring mach_str
, getdc_str
;
421 if (!lp_domain_master()) {
422 /* We're not Primary Domain Controller -- ignore this */
426 getdc
= skip_string(buf
,len
,machine
);
428 if (!getdc
|| PTR_DIFF(getdc
, buf
) >= len
) {
429 DEBUG(0,("process_logon_packet: bad packet\n"));
432 q
= skip_string(buf
,len
,getdc
);
434 if (!q
|| PTR_DIFF(q
, buf
) >= len
) {
435 DEBUG(0,("process_logon_packet: bad packet\n"));
440 /* At this point we can work out if this is a W9X or NT style
441 request. Experiments show that the difference is wether the
442 packet ends here. For a W9X request we now end with a pair of
443 bytes (usually 0xFE 0xFF) whereas with NT we have two further
444 strings - the following is a simple way of detecting this */
446 if (len
- PTR_DIFF(q
, buf
) <= 3) {
447 short_request
= True
;
451 if (PTR_DIFF(q
, buf
) >= len
) {
452 DEBUG(0,("process_logon_packet: bad packet\n"));
456 /* A full length (NT style) request */
457 q
= skip_unibuf(unicomp
, PTR_DIFF(buf
+ len
, unicomp
));
459 if (PTR_DIFF(q
, buf
) >= len
) {
460 DEBUG(0,("process_logon_packet: bad packet\n"));
464 if (len
- PTR_DIFF(q
, buf
) > 8) {
465 /* with NT5 clients we can sometimes
466 get additional data - a length specificed string
467 containing the domain name, then 16 bytes of
468 data (no idea what it is) */
469 int dom_len
= CVAL(q
, 0);
477 if (PTR_DIFF(q
+ 8, buf
) > len
) {
478 DEBUG(0,("process_logon_packet: bad packet\n"));
482 ntversion
= IVAL(q
, 0);
483 lmnttoken
= SVAL(q
, 4);
484 lm20token
= SVAL(q
, 6);
487 /* Construct reply. */
489 SSVAL(q
, 0, NETLOGON_RESPONSE_FROM_PDC
);
492 fstrcpy(reply_name
,my_name
);
493 size
= push_ascii(q
, reply_name
,
494 sizeof(outbuf
)-PTR_DIFF(q
, outbuf
),
496 if (size
== (size_t)-1) {
499 q
= skip_string(outbuf
,sizeof(outbuf
),q
); /* PDC name */
501 /* PDC and domain name */
502 if (!short_request
) {
503 /* Make a full reply */
504 q
= ALIGN2(q
, outbuf
);
506 q
+= dos_PutUniCode(q
, my_name
,
507 sizeof(outbuf
) - PTR_DIFF(q
, outbuf
),
508 True
); /* PDC name */
509 q
+= dos_PutUniCode(q
, lp_workgroup(),
510 sizeof(outbuf
) - PTR_DIFF(q
, outbuf
),
511 True
); /* Domain name*/
512 if (sizeof(outbuf
) - PTR_DIFF(q
, outbuf
) < 8) {
515 SIVAL(q
, 0, 1); /* our nt version */
516 SSVAL(q
, 4, 0xffff); /* our lmnttoken */
517 SSVAL(q
, 6, 0xffff); /* our lm20token */
521 /* RJS, 21-Feb-2000, we send a short reply if the request was short */
523 pull_ascii_fstring(mach_str
, machine
);
525 DEBUG(5,("process_logon_packet: GETDC request from %s at IP %s, \
526 reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n",
527 mach_str
,inet_ntoa(p
->ip
), reply_name
, lp_workgroup(),
528 NETLOGON_RESPONSE_FROM_PDC
, (uint32
)ntversion
, (uint32
)lmnttoken
,
529 (uint32
)lm20token
));
531 dump_data(4, (uint8
*)outbuf
, PTR_DIFF(q
, outbuf
));
533 pull_ascii_fstring(getdc_str
, getdc
);
534 pull_ascii_nstring(source_name
, sizeof(source_name
), dgram
->source_name
.name
);
536 send_mailslot(True
, getdc_str
,
537 outbuf
,PTR_DIFF(q
,outbuf
),
538 global_myname(), 0x0,
540 dgram
->source_name
.name_type
,
545 case LOGON_SAM_LOGON_REQUEST
:
554 if (global_nmbd_proxy_logon
) {
555 nmbd_proxy_logon(global_nmbd_proxy_logon
,
556 ip
, p
, (uint8_t *)buf
, len
);
562 if (PTR_DIFF(q
, buf
) >= len
) {
563 DEBUG(0,("process_logon_packet: bad packet\n"));
568 uniuser
= skip_unibuf(unicomp
, PTR_DIFF(buf
+len
, unicomp
));
570 if (PTR_DIFF(uniuser
, buf
) >= len
) {
571 DEBUG(0,("process_logon_packet: bad packet\n"));
575 getdc
= skip_unibuf(uniuser
,PTR_DIFF(buf
+len
, uniuser
));
577 if (PTR_DIFF(getdc
, buf
) >= len
) {
578 DEBUG(0,("process_logon_packet: bad packet\n"));
582 q
= skip_string(buf
,len
,getdc
);
584 if (!q
|| PTR_DIFF(q
+ 8, buf
) >= len
) {
585 DEBUG(0,("process_logon_packet: bad packet\n"));
589 q
+= 4; /* Account Control Bits - indicating username type */
590 domainsidsize
= IVAL(q
, 0);
593 DEBUG(5,("process_logon_packet: LOGON_SAM_LOGON_REQUEST sidsize %d, len = %d\n", domainsidsize
, len
));
595 if (domainsidsize
< (len
- PTR_DIFF(q
, buf
)) && (domainsidsize
!= 0)) {
600 DEBUG(5,("process_logon_packet: len = %d PTR_DIFF(q, buf) = %ld\n", len
, (unsigned long)PTR_DIFF(q
, buf
) ));
602 if (len
- PTR_DIFF(q
, buf
) > 8) {
603 /* with NT5 clients we can sometimes
604 get additional data - a length specificed string
605 containing the domain name, then 16 bytes of
606 data (no idea what it is) */
607 int dom_len
= CVAL(q
, 0);
609 if (dom_len
< (len
- PTR_DIFF(q
, buf
)) && (dom_len
!= 0)) {
615 if (PTR_DIFF(q
+ 8, buf
) > len
) {
616 DEBUG(0,("process_logon_packet: bad packet\n"));
620 ntversion
= IVAL(q
, 0);
621 lmnttoken
= SVAL(q
, 4);
622 lm20token
= SVAL(q
, 6);
625 DEBUG(3,("process_logon_packet: LOGON_SAM_LOGON_REQUEST sidsize %d ntv %d\n", domainsidsize
, ntversion
));
628 * we respond regadless of whether the machine is in our password
629 * database. If it isn't then we let smbd send an appropriate error.
630 * Let's ignore the SID.
632 pull_ucs2_fstring(ascuser
, uniuser
);
633 pull_ucs2_fstring(asccomp
, unicomp
);
634 DEBUG(5,("process_logon_packet: LOGON_SAM_LOGON_REQUEST user %s\n", ascuser
));
636 fstrcpy(reply_name
, "\\\\"); /* Here it wants \\LOGONSERVER. */
637 fstrcat(reply_name
, my_name
);
639 DEBUG(5,("process_logon_packet: LOGON_SAM_LOGON_REQUEST request from %s(%s) for %s, returning logon svr %s domain %s code %x token=%x\n",
640 asccomp
,inet_ntoa(p
->ip
), ascuser
, reply_name
, lp_workgroup(),
641 LOGON_SAM_LOGON_RESPONSE
,lmnttoken
));
643 /* Construct reply. */
646 /* we want the simple version unless we are an ADS PDC..which means */
647 /* never, at least for now */
648 if ((ntversion
< 11) || (SEC_ADS
!= lp_security()) || (ROLE_DOMAIN_PDC
!= lp_server_role())) {
649 if (SVAL(uniuser
, 0) == 0) {
650 SSVAL(q
, 0, LOGON_SAM_LOGON_USER_UNKNOWN
); /* user unknown */
652 SSVAL(q
, 0, LOGON_SAM_LOGON_RESPONSE
);
657 q
+= dos_PutUniCode(q
, reply_name
,
658 sizeof(outbuf
) - PTR_DIFF(q
, outbuf
),
660 q
+= dos_PutUniCode(q
, ascuser
,
661 sizeof(outbuf
) - PTR_DIFF(q
, outbuf
),
663 q
+= dos_PutUniCode(q
, lp_workgroup(),
664 sizeof(outbuf
) - PTR_DIFF(q
, outbuf
),
669 struct GUID domain_guid
;
673 char *component
, *dc
, *q1
;
676 char *saveptr
= NULL
;
678 domain
= get_mydnsdomname(talloc_tos());
681 ("get_mydnsdomname failed.\n"));
684 hostname
= get_myname(talloc_tos());
687 ("get_myname failed.\n"));
691 if (sizeof(outbuf
) - PTR_DIFF(q
, outbuf
) < 8) {
694 if (SVAL(uniuser
, 0) == 0) {
695 SIVAL(q
, 0, LOGON_SAM_LOGON_USER_UNKNOWN_EX
); /* user unknown */
697 SIVAL(q
, 0, LOGON_SAM_LOGON_RESPONSE_EX
);
701 SIVAL(q
, 0, NBT_SERVER_PDC
|NBT_SERVER_GC
|NBT_SERVER_LDAP
|NBT_SERVER_DS
|
702 NBT_SERVER_KDC
|NBT_SERVER_TIMESERV
|NBT_SERVER_CLOSEST
|NBT_SERVER_WRITABLE
);
705 /* Push Domain GUID */
706 if (sizeof(outbuf
) - PTR_DIFF(q
, outbuf
) < UUID_FLAT_SIZE
) {
709 if (False
== secrets_fetch_domain_guid(domain
, &domain_guid
)) {
710 DEBUG(2, ("Could not fetch DomainGUID for %s\n", domain
));
714 smb_uuid_pack(domain_guid
, &flat_guid
);
715 memcpy(q
, &flat_guid
.info
, UUID_FLAT_SIZE
);
719 str_offset
= q
- q_orig
;
722 while ((component
= strtok_r(dc
, ".", &saveptr
)) != NULL
) {
724 if (sizeof(outbuf
) - PTR_DIFF(q
, outbuf
) < 1) {
727 size
= push_ascii(&q
[1], component
,
728 sizeof(outbuf
) - PTR_DIFF(q
+1, outbuf
),
730 if (size
== (size_t)-1 || size
> 0xff) {
738 if (sizeof(outbuf
) - PTR_DIFF(q
, outbuf
) < 4) {
745 SCVAL(q
, 0, 0xc0 | ((str_offset
>> 8) & 0x3F));
746 SCVAL(q
, 1, str_offset
& 0xFF);
750 size
= push_ascii(&q
[1], hostname
,
751 sizeof(outbuf
) - PTR_DIFF(q
+1, outbuf
),
753 if (size
== (size_t)-1 || size
> 0xff) {
759 if (sizeof(outbuf
) - PTR_DIFF(q
, outbuf
) < 3) {
763 SCVAL(q
, 0, 0xc0 | ((str_offset
>> 8) & 0x3F));
764 SCVAL(q
, 1, str_offset
& 0xFF);
767 /* NETBIOS of domain */
768 size
= push_ascii(&q
[1], lp_workgroup(),
769 sizeof(outbuf
) - PTR_DIFF(q
+1, outbuf
),
771 if (size
== (size_t)-1 || size
> 0xff) {
778 if (sizeof(outbuf
) - PTR_DIFF(q
, outbuf
) < 2) {
785 /* NETBIOS of hostname */
786 size
= push_ascii(&q
[1], my_name
,
787 sizeof(outbuf
) - PTR_DIFF(q
+1, outbuf
),
789 if (size
== (size_t)-1 || size
> 0xff) {
796 if (sizeof(outbuf
) - PTR_DIFF(q
, outbuf
) < 4) {
804 if (SVAL(uniuser
, 0) != 0) {
805 size
= push_ascii(&q
[1], ascuser
,
806 sizeof(outbuf
) - PTR_DIFF(q
+1, outbuf
),
808 if (size
== (size_t)-1 || size
> 0xff) {
817 if (sizeof(outbuf
) - PTR_DIFF(q
, outbuf
) < 1) {
820 size
= push_ascii(&q
[1], "Default-First-Site-Name",
821 sizeof(outbuf
) - PTR_DIFF(q
+1, outbuf
),
823 if (size
== (size_t)-1 || size
> 0xff) {
829 if (sizeof(outbuf
) - PTR_DIFF(q
, outbuf
) < 18) {
834 str_offset
= q
- q_orig
;
835 SCVAL(q
, 0, 0xc0 | ((str_offset
>> 8) & 0x3F));
836 SCVAL(q
, 1, str_offset
& 0xFF);
839 SCVAL(q
, 0, PTR_DIFF(q
,q1
));
840 SCVAL(q
, 1, 0x10); /* unknown */
842 SIVAL(q
, 0, 0x00000002);
843 q
+= 4; /* unknown */
844 SIVAL(q
, 0, ntohl(ip
.s_addr
));
846 SIVAL(q
, 0, 0x00000000);
847 q
+= 4; /* unknown */
848 SIVAL(q
, 0, 0x00000000);
849 q
+= 4; /* unknown */
853 if (sizeof(outbuf
) - PTR_DIFF(q
, outbuf
) < 8) {
857 /* tell the client what version we are */
858 SIVAL(q
, 0, ((ntversion
< 11) || (SEC_ADS
!= lp_security())) ? 1 : 13);
860 SSVAL(q
, 4, 0xffff); /* our lmnttoken */
861 SSVAL(q
, 6, 0xffff); /* our lm20token */
864 dump_data(4, (uint8
*)outbuf
, PTR_DIFF(q
, outbuf
));
866 pull_ascii_fstring(getdc_str
, getdc
);
867 pull_ascii_nstring(source_name
, sizeof(source_name
), dgram
->source_name
.name
);
868 source_addr
= SMB_STRDUP(inet_ntoa(dgram
->header
.source_ip
));
869 if (source_addr
== NULL
) {
870 DEBUG(3, ("out of memory copying client"
871 " address string\n"));
877 * packets requeued after delay are marked as
880 if ((p
->locked
== False
) &&
881 (strlen(ascuser
) == 0) &&
882 delay_logon(source_name
, source_addr
))
886 DEBUG(3, ("process_logon_packet: "
887 "delaying initial logon "
888 "reply for client %s(%s) for "
890 source_name
, source_addr
,
891 lp_init_logon_delay()));
893 when
= timeval_current_ofs(0,
894 lp_init_logon_delay() * 1000);
896 event_add_timed(nmbd_event_context(),
899 delayed_init_logon_handler
,
902 DEBUG(3, ("process_logon_packet: "
903 "processing delayed initial "
904 "logon reply for client "
906 source_name
, source_addr
));
909 send_mailslot(true, getdc
,
910 outbuf
,PTR_DIFF(q
,outbuf
),
911 global_myname(), 0x0,
913 dgram
->source_name
.name_type
,
917 SAFE_FREE(source_addr
);
922 /* Announce change to UAS or SAM. Send by the domain controller when a
923 replication event is required. */
925 case NETLOGON_ANNOUNCE_UAS
:
926 DEBUG(5, ("Got NETLOGON_ANNOUNCE_UAS\n"));
930 DEBUG(3,("process_logon_packet: Unknown domain request %d\n",code
));