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"
33 struct sam_database_info
{
35 uint32 serial_lo
, serial_hi
;
36 uint32 date_lo
, date_hi
;
40 * check whether the client belongs to the hosts
41 * for which initial logon should be delayed...
43 static bool delay_logon(const char *peer_name
, const char *peer_addr
)
45 const char **delay_list
= lp_init_logon_delayed_hosts();
48 if (delay_list
== NULL
) {
55 return list_match(delay_list
, (const char *)peer
, client_match
);
58 static void delayed_init_logon_handler(struct event_context
*event_ctx
,
59 struct timed_event
*te
,
63 struct packet_struct
*p
= (struct packet_struct
*)private_data
;
65 DEBUG(10, ("delayed_init_logon_handler (%lx): re-queuing packet.\n",
73 struct nmbd_proxy_logon_context
{
74 struct cldap_socket
*cldap_sock
;
77 static struct nmbd_proxy_logon_context
*global_nmbd_proxy_logon
;
79 bool initialize_nmbd_proxy_logon(void)
81 const char *cldap_server
= lp_parm_const_string(-1, "nmbd_proxy_logon",
82 "cldap_server", NULL
);
83 struct nmbd_proxy_logon_context
*ctx
;
86 char addrstr
[INET_ADDRSTRLEN
];
87 const char *server_str
;
89 struct tsocket_address
*server_addr
;
95 addr
= interpret_addr2(cldap_server
);
96 server_str
= inet_ntop(AF_INET
, &addr
,
97 addrstr
, sizeof(addrstr
));
98 if (!server_str
|| strcmp("0.0.0.0", server_str
) == 0) {
99 DEBUG(0,("Failed to resolve[%s] for nmbd_proxy_logon\n",
104 ctx
= talloc_zero(nmbd_event_context(),
105 struct nmbd_proxy_logon_context
);
110 ret
= tsocket_address_inet_from_strings(ctx
, "ipv4",
111 server_str
, LDAP_PORT
,
115 status
= map_nt_error_from_unix(errno
);
116 DEBUG(0,("Failed to create cldap tsocket_address for %s - %s\n",
117 server_str
, nt_errstr(status
)));
121 /* we create a connected udp socket */
122 status
= cldap_socket_init(ctx
, nmbd_event_context(), NULL
,
123 server_addr
, &ctx
->cldap_sock
);
124 TALLOC_FREE(server_addr
);
125 if (!NT_STATUS_IS_OK(status
)) {
127 DEBUG(0,("failed to create cldap socket for %s: %s\n",
128 server_str
, nt_errstr(status
)));
132 global_nmbd_proxy_logon
= ctx
;
136 struct nmbd_proxy_logon_state
{
137 struct in_addr local_ip
;
138 struct packet_struct
*p
;
139 const char *remote_name
;
140 uint8_t remote_name_type
;
141 const char *remote_mailslot
;
142 struct nbt_netlogon_packet req
;
143 struct nbt_netlogon_response resp
;
144 struct cldap_netlogon io
;
147 static int nmbd_proxy_logon_state_destructor(struct nmbd_proxy_logon_state
*s
)
149 s
->p
->locked
= false;
154 static void nmbd_proxy_logon_done(struct tevent_req
*subreq
);
156 static void nmbd_proxy_logon(struct nmbd_proxy_logon_context
*ctx
,
157 struct in_addr local_ip
,
158 struct packet_struct
*p
,
162 struct nmbd_proxy_logon_state
*state
;
163 enum ndr_err_code ndr_err
;
164 DATA_BLOB blob
= data_blob_const(buf
, len
);
165 const char *computer_name
= NULL
;
166 const char *mailslot_name
= NULL
;
167 const char *user_name
= NULL
;
168 const char *domain_sid
= NULL
;
169 uint32_t acct_control
= 0;
170 uint32_t nt_version
= 0;
171 struct tevent_req
*subreq
;
173 struct dgram_packet
*dgram
= &p
->packet
.dgram
;
175 state
= TALLOC_ZERO_P(ctx
, struct nmbd_proxy_logon_state
);
177 DEBUG(0,("failed to allocate nmbd_proxy_logon_state\n"));
181 pull_ascii_nstring(source_name
, sizeof(source_name
), dgram
->source_name
.name
);
182 state
->remote_name
= talloc_strdup(state
, source_name
);
183 state
->remote_name_type
= dgram
->source_name
.name_type
,
184 state
->local_ip
= local_ip
;
187 ndr_err
= ndr_pull_struct_blob(
188 &blob
, state
, &state
->req
,
189 (ndr_pull_flags_fn_t
)ndr_pull_nbt_netlogon_packet
);
190 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
191 NTSTATUS status
= ndr_map_error2ntstatus(ndr_err
);
192 DEBUG(0,("failed parse nbt_netlogon_packet: %s\n",
198 if (DEBUGLEVEL
>= 10) {
199 DEBUG(10, ("nmbd_proxy_logon:\n"));
200 NDR_PRINT_DEBUG(nbt_netlogon_packet
, &state
->req
);
203 switch (state
->req
.command
) {
204 case LOGON_SAM_LOGON_REQUEST
:
205 computer_name
= state
->req
.req
.logon
.computer_name
;
206 user_name
= state
->req
.req
.logon
.user_name
;
207 mailslot_name
= state
->req
.req
.logon
.mailslot_name
;
208 acct_control
= state
->req
.req
.logon
.acct_control
;
209 if (state
->req
.req
.logon
.sid_size
> 0) {
210 domain_sid
= dom_sid_string(state
,
211 &state
->req
.req
.logon
.sid
);
213 DEBUG(0,("failed to get a string for sid\n"));
218 nt_version
= state
->req
.req
.logon
.nt_version
;
222 /* this can't happen as the caller already checks the command */
226 state
->remote_mailslot
= mailslot_name
;
228 if (user_name
&& strlen(user_name
) == 0) {
232 if (computer_name
&& strlen(computer_name
) == 0) {
233 computer_name
= NULL
;
237 * as the socket is connected,
238 * we don't need to specify the destination
240 state
->io
.in
.dest_address
= NULL
;
241 state
->io
.in
.dest_port
= 0;
242 state
->io
.in
.realm
= NULL
;
243 state
->io
.in
.host
= computer_name
;
244 state
->io
.in
.user
= user_name
;
245 state
->io
.in
.domain_guid
= NULL
;
246 state
->io
.in
.domain_sid
= domain_sid
;
247 state
->io
.in
.acct_control
= acct_control
;
248 state
->io
.in
.version
= nt_version
;
249 state
->io
.in
.map_response
= false;
251 subreq
= cldap_netlogon_send(state
,
255 DEBUG(0,("failed to send cldap netlogon call\n"));
259 tevent_req_set_callback(subreq
, nmbd_proxy_logon_done
, state
);
262 state
->p
->locked
= true;
263 talloc_set_destructor(state
, nmbd_proxy_logon_state_destructor
);
266 static void nmbd_proxy_logon_done(struct tevent_req
*subreq
)
268 struct nmbd_proxy_logon_state
*state
=
269 tevent_req_callback_data(subreq
,
270 struct nmbd_proxy_logon_state
);
272 DATA_BLOB response
= data_blob_null
;
274 status
= cldap_netlogon_recv(subreq
, state
, &state
->io
);
275 if (!NT_STATUS_IS_OK(status
)) {
276 DEBUG(0,("failed to recv cldap netlogon call: %s\n",
282 status
= push_netlogon_samlogon_response(&response
, state
,
283 &state
->io
.out
.netlogon
);
284 if (!NT_STATUS_IS_OK(status
)) {
285 DEBUG(0,("failed to push netlogon_samlogon_response: %s\n",
291 send_mailslot(true, state
->remote_mailslot
,
292 (char *)response
.data
, response
.length
,
293 global_myname(), 0x0,
295 state
->remote_name_type
,
302 /****************************************************************************
303 Process a domain logon packet
304 **************************************************************************/
306 void process_logon_packet(struct packet_struct
*p
, char *buf
,int len
,
307 const char *mailslot
)
309 struct dgram_packet
*dgram
= &p
->packet
.dgram
;
315 uint32 ntversion
= 0;
316 uint16 lmnttoken
= 0;
317 uint16 lm20token
= 0;
318 uint32 domainsidsize
;
319 bool short_request
= False
;
321 char *uniuser
; /* Unicode user name. */
323 char *unicomp
; /* Unicode computer name. */
325 struct sockaddr_storage ss
;
326 const struct sockaddr_storage
*pss
;
329 in_addr_to_sockaddr_storage(&ss
, p
->ip
);
330 pss
= iface_ip((struct sockaddr
*)&ss
);
332 DEBUG(5,("process_logon_packet:can't find outgoing interface "
333 "for packet from IP %s\n",
337 ip
= ((struct sockaddr_in
*)pss
)->sin_addr
;
339 memset(outbuf
, 0, sizeof(outbuf
));
341 if (!lp_domain_logons()) {
342 DEBUG(5,("process_logon_packet: Logon packet received from IP %s and domain \
343 logons are not enabled.\n", inet_ntoa(p
->ip
) ));
347 fstrcpy(my_name
, global_myname());
349 code
= get_safe_SVAL(buf
,len
,buf
,0,-1);
350 DEBUG(4,("process_logon_packet: Logon from %s: code = 0x%x\n", inet_ntoa(p
->ip
), code
));
355 fstring mach_str
, user_str
, getdc_str
;
358 char *user
= skip_string(buf
,len
,machine
);
360 if (!user
|| PTR_DIFF(user
, buf
) >= len
) {
361 DEBUG(0,("process_logon_packet: bad packet\n"));
364 getdc
= skip_string(buf
,len
,user
);
366 if (!getdc
|| PTR_DIFF(getdc
, buf
) >= len
) {
367 DEBUG(0,("process_logon_packet: bad packet\n"));
370 q
= skip_string(buf
,len
,getdc
);
372 if (!q
|| PTR_DIFF(q
+ 5, buf
) > len
) {
373 DEBUG(0,("process_logon_packet: bad packet\n"));
378 fstrcpy(reply_name
,my_name
);
380 pull_ascii_fstring(mach_str
, machine
);
381 pull_ascii_fstring(user_str
, user
);
382 pull_ascii_fstring(getdc_str
, getdc
);
384 DEBUG(5,("process_logon_packet: Domain login request from %s at IP %s user=%s token=%x\n",
385 mach_str
,inet_ntoa(p
->ip
),user_str
,token
));
391 fstrcpy(reply_name
, "\\\\");
392 fstrcat(reply_name
, my_name
);
393 size
= push_ascii(q
,reply_name
,
394 sizeof(outbuf
)-PTR_DIFF(q
, outbuf
),
396 if (size
== (size_t)-1) {
399 q
= skip_string(outbuf
,sizeof(outbuf
),q
); /* PDC name */
404 dump_data(4, (uint8
*)outbuf
, PTR_DIFF(q
, outbuf
));
406 send_mailslot(True
, getdc_str
,
407 outbuf
,PTR_DIFF(q
,outbuf
),
408 global_myname(), 0x0,
410 dgram
->source_name
.name_type
,
415 case LOGON_PRIMARY_QUERY
:
417 fstring mach_str
, getdc_str
;
422 if (!lp_domain_master()) {
423 /* We're not Primary Domain Controller -- ignore this */
427 getdc
= skip_string(buf
,len
,machine
);
429 if (!getdc
|| PTR_DIFF(getdc
, buf
) >= len
) {
430 DEBUG(0,("process_logon_packet: bad packet\n"));
433 q
= skip_string(buf
,len
,getdc
);
435 if (!q
|| PTR_DIFF(q
, buf
) >= len
) {
436 DEBUG(0,("process_logon_packet: bad packet\n"));
441 /* At this point we can work out if this is a W9X or NT style
442 request. Experiments show that the difference is wether the
443 packet ends here. For a W9X request we now end with a pair of
444 bytes (usually 0xFE 0xFF) whereas with NT we have two further
445 strings - the following is a simple way of detecting this */
447 if (len
- PTR_DIFF(q
, buf
) <= 3) {
448 short_request
= True
;
452 if (PTR_DIFF(q
, buf
) >= len
) {
453 DEBUG(0,("process_logon_packet: bad packet\n"));
457 /* A full length (NT style) request */
458 q
= skip_unibuf(unicomp
, PTR_DIFF(buf
+ len
, unicomp
));
460 if (PTR_DIFF(q
, buf
) >= len
) {
461 DEBUG(0,("process_logon_packet: bad packet\n"));
465 if (len
- PTR_DIFF(q
, buf
) > 8) {
466 /* with NT5 clients we can sometimes
467 get additional data - a length specificed string
468 containing the domain name, then 16 bytes of
469 data (no idea what it is) */
470 int dom_len
= CVAL(q
, 0);
478 if (PTR_DIFF(q
+ 8, buf
) > len
) {
479 DEBUG(0,("process_logon_packet: bad packet\n"));
483 ntversion
= IVAL(q
, 0);
484 lmnttoken
= SVAL(q
, 4);
485 lm20token
= SVAL(q
, 6);
488 /* Construct reply. */
490 SSVAL(q
, 0, NETLOGON_RESPONSE_FROM_PDC
);
493 fstrcpy(reply_name
,my_name
);
494 size
= push_ascii(q
, reply_name
,
495 sizeof(outbuf
)-PTR_DIFF(q
, outbuf
),
497 if (size
== (size_t)-1) {
500 q
= skip_string(outbuf
,sizeof(outbuf
),q
); /* PDC name */
502 /* PDC and domain name */
503 if (!short_request
) {
504 /* Make a full reply */
505 q
= ALIGN2(q
, outbuf
);
507 q
+= dos_PutUniCode(q
, my_name
,
508 sizeof(outbuf
) - PTR_DIFF(q
, outbuf
),
509 True
); /* PDC name */
510 q
+= dos_PutUniCode(q
, lp_workgroup(),
511 sizeof(outbuf
) - PTR_DIFF(q
, outbuf
),
512 True
); /* Domain name*/
513 if (sizeof(outbuf
) - PTR_DIFF(q
, outbuf
) < 8) {
516 SIVAL(q
, 0, 1); /* our nt version */
517 SSVAL(q
, 4, 0xffff); /* our lmnttoken */
518 SSVAL(q
, 6, 0xffff); /* our lm20token */
522 /* RJS, 21-Feb-2000, we send a short reply if the request was short */
524 pull_ascii_fstring(mach_str
, machine
);
526 DEBUG(5,("process_logon_packet: GETDC request from %s at IP %s, \
527 reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n",
528 mach_str
,inet_ntoa(p
->ip
), reply_name
, lp_workgroup(),
529 NETLOGON_RESPONSE_FROM_PDC
, (uint32
)ntversion
, (uint32
)lmnttoken
,
530 (uint32
)lm20token
));
532 dump_data(4, (uint8
*)outbuf
, PTR_DIFF(q
, outbuf
));
534 pull_ascii_fstring(getdc_str
, getdc
);
535 pull_ascii_nstring(source_name
, sizeof(source_name
), dgram
->source_name
.name
);
537 send_mailslot(True
, getdc_str
,
538 outbuf
,PTR_DIFF(q
,outbuf
),
539 global_myname(), 0x0,
541 dgram
->source_name
.name_type
,
546 case LOGON_SAM_LOGON_REQUEST
:
555 if (global_nmbd_proxy_logon
) {
556 nmbd_proxy_logon(global_nmbd_proxy_logon
,
557 ip
, p
, (uint8_t *)buf
, len
);
563 if (PTR_DIFF(q
, buf
) >= len
) {
564 DEBUG(0,("process_logon_packet: bad packet\n"));
569 uniuser
= skip_unibuf(unicomp
, PTR_DIFF(buf
+len
, unicomp
));
571 if (PTR_DIFF(uniuser
, buf
) >= len
) {
572 DEBUG(0,("process_logon_packet: bad packet\n"));
576 getdc
= skip_unibuf(uniuser
,PTR_DIFF(buf
+len
, uniuser
));
578 if (PTR_DIFF(getdc
, buf
) >= len
) {
579 DEBUG(0,("process_logon_packet: bad packet\n"));
583 q
= skip_string(buf
,len
,getdc
);
585 if (!q
|| PTR_DIFF(q
+ 8, buf
) >= len
) {
586 DEBUG(0,("process_logon_packet: bad packet\n"));
590 q
+= 4; /* Account Control Bits - indicating username type */
591 domainsidsize
= IVAL(q
, 0);
594 DEBUG(5,("process_logon_packet: LOGON_SAM_LOGON_REQUEST sidsize %d, len = %d\n", domainsidsize
, len
));
596 if (domainsidsize
< (len
- PTR_DIFF(q
, buf
)) && (domainsidsize
!= 0)) {
601 DEBUG(5,("process_logon_packet: len = %d PTR_DIFF(q, buf) = %ld\n", len
, (unsigned long)PTR_DIFF(q
, buf
) ));
603 if (len
- PTR_DIFF(q
, buf
) > 8) {
604 /* with NT5 clients we can sometimes
605 get additional data - a length specificed string
606 containing the domain name, then 16 bytes of
607 data (no idea what it is) */
608 int dom_len
= CVAL(q
, 0);
610 if (dom_len
< (len
- PTR_DIFF(q
, buf
)) && (dom_len
!= 0)) {
616 if (PTR_DIFF(q
+ 8, buf
) > len
) {
617 DEBUG(0,("process_logon_packet: bad packet\n"));
621 ntversion
= IVAL(q
, 0);
622 lmnttoken
= SVAL(q
, 4);
623 lm20token
= SVAL(q
, 6);
626 DEBUG(3,("process_logon_packet: LOGON_SAM_LOGON_REQUEST sidsize %d ntv %d\n", domainsidsize
, ntversion
));
629 * we respond regadless of whether the machine is in our password
630 * database. If it isn't then we let smbd send an appropriate error.
631 * Let's ignore the SID.
633 pull_ucs2_fstring(ascuser
, uniuser
);
634 pull_ucs2_fstring(asccomp
, unicomp
);
635 DEBUG(5,("process_logon_packet: LOGON_SAM_LOGON_REQUEST user %s\n", ascuser
));
637 fstrcpy(reply_name
, "\\\\"); /* Here it wants \\LOGONSERVER. */
638 fstrcat(reply_name
, my_name
);
640 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",
641 asccomp
,inet_ntoa(p
->ip
), ascuser
, reply_name
, lp_workgroup(),
642 LOGON_SAM_LOGON_RESPONSE
,lmnttoken
));
644 /* Construct reply. */
647 /* we want the simple version unless we are an ADS PDC..which means */
648 /* never, at least for now */
649 if ((ntversion
< 11) || (SEC_ADS
!= lp_security()) || (ROLE_DOMAIN_PDC
!= lp_server_role())) {
650 if (SVAL(uniuser
, 0) == 0) {
651 SSVAL(q
, 0, LOGON_SAM_LOGON_USER_UNKNOWN
); /* user unknown */
653 SSVAL(q
, 0, LOGON_SAM_LOGON_RESPONSE
);
658 q
+= dos_PutUniCode(q
, reply_name
,
659 sizeof(outbuf
) - PTR_DIFF(q
, outbuf
),
661 q
+= dos_PutUniCode(q
, ascuser
,
662 sizeof(outbuf
) - PTR_DIFF(q
, outbuf
),
664 q
+= dos_PutUniCode(q
, lp_workgroup(),
665 sizeof(outbuf
) - PTR_DIFF(q
, outbuf
),
670 struct GUID domain_guid
;
674 char *component
, *dc
, *q1
;
677 char *saveptr
= NULL
;
679 domain
= get_mydnsdomname(talloc_tos());
682 ("get_mydnsdomname failed.\n"));
685 hostname
= get_myname(talloc_tos());
688 ("get_myname failed.\n"));
692 if (sizeof(outbuf
) - PTR_DIFF(q
, outbuf
) < 8) {
695 if (SVAL(uniuser
, 0) == 0) {
696 SIVAL(q
, 0, LOGON_SAM_LOGON_USER_UNKNOWN_EX
); /* user unknown */
698 SIVAL(q
, 0, LOGON_SAM_LOGON_RESPONSE_EX
);
702 SIVAL(q
, 0, NBT_SERVER_PDC
|NBT_SERVER_GC
|NBT_SERVER_LDAP
|NBT_SERVER_DS
|
703 NBT_SERVER_KDC
|NBT_SERVER_TIMESERV
|NBT_SERVER_CLOSEST
|NBT_SERVER_WRITABLE
);
706 /* Push Domain GUID */
707 if (sizeof(outbuf
) - PTR_DIFF(q
, outbuf
) < UUID_FLAT_SIZE
) {
710 if (False
== secrets_fetch_domain_guid(domain
, &domain_guid
)) {
711 DEBUG(2, ("Could not fetch DomainGUID for %s\n", domain
));
715 smb_uuid_pack(domain_guid
, &flat_guid
);
716 memcpy(q
, &flat_guid
.info
, UUID_FLAT_SIZE
);
720 str_offset
= q
- q_orig
;
723 while ((component
= strtok_r(dc
, ".", &saveptr
)) != NULL
) {
725 if (sizeof(outbuf
) - PTR_DIFF(q
, outbuf
) < 1) {
728 size
= push_ascii(&q
[1], component
,
729 sizeof(outbuf
) - PTR_DIFF(q
+1, outbuf
),
731 if (size
== (size_t)-1 || size
> 0xff) {
739 if (sizeof(outbuf
) - PTR_DIFF(q
, outbuf
) < 4) {
746 SCVAL(q
, 0, 0xc0 | ((str_offset
>> 8) & 0x3F));
747 SCVAL(q
, 1, str_offset
& 0xFF);
751 size
= push_ascii(&q
[1], hostname
,
752 sizeof(outbuf
) - PTR_DIFF(q
+1, outbuf
),
754 if (size
== (size_t)-1 || size
> 0xff) {
760 if (sizeof(outbuf
) - PTR_DIFF(q
, outbuf
) < 3) {
764 SCVAL(q
, 0, 0xc0 | ((str_offset
>> 8) & 0x3F));
765 SCVAL(q
, 1, str_offset
& 0xFF);
768 /* NETBIOS of domain */
769 size
= push_ascii(&q
[1], lp_workgroup(),
770 sizeof(outbuf
) - PTR_DIFF(q
+1, outbuf
),
772 if (size
== (size_t)-1 || size
> 0xff) {
779 if (sizeof(outbuf
) - PTR_DIFF(q
, outbuf
) < 2) {
786 /* NETBIOS of hostname */
787 size
= push_ascii(&q
[1], my_name
,
788 sizeof(outbuf
) - PTR_DIFF(q
+1, outbuf
),
790 if (size
== (size_t)-1 || size
> 0xff) {
797 if (sizeof(outbuf
) - PTR_DIFF(q
, outbuf
) < 4) {
805 if (SVAL(uniuser
, 0) != 0) {
806 size
= push_ascii(&q
[1], ascuser
,
807 sizeof(outbuf
) - PTR_DIFF(q
+1, outbuf
),
809 if (size
== (size_t)-1 || size
> 0xff) {
818 if (sizeof(outbuf
) - PTR_DIFF(q
, outbuf
) < 1) {
821 size
= push_ascii(&q
[1], "Default-First-Site-Name",
822 sizeof(outbuf
) - PTR_DIFF(q
+1, outbuf
),
824 if (size
== (size_t)-1 || size
> 0xff) {
830 if (sizeof(outbuf
) - PTR_DIFF(q
, outbuf
) < 18) {
835 str_offset
= q
- q_orig
;
836 SCVAL(q
, 0, 0xc0 | ((str_offset
>> 8) & 0x3F));
837 SCVAL(q
, 1, str_offset
& 0xFF);
840 SCVAL(q
, 0, PTR_DIFF(q
,q1
));
841 SCVAL(q
, 1, 0x10); /* unknown */
843 SIVAL(q
, 0, 0x00000002);
844 q
+= 4; /* unknown */
845 SIVAL(q
, 0, ntohl(ip
.s_addr
));
847 SIVAL(q
, 0, 0x00000000);
848 q
+= 4; /* unknown */
849 SIVAL(q
, 0, 0x00000000);
850 q
+= 4; /* unknown */
854 if (sizeof(outbuf
) - PTR_DIFF(q
, outbuf
) < 8) {
858 /* tell the client what version we are */
859 SIVAL(q
, 0, ((ntversion
< 11) || (SEC_ADS
!= lp_security())) ? 1 : 13);
861 SSVAL(q
, 4, 0xffff); /* our lmnttoken */
862 SSVAL(q
, 6, 0xffff); /* our lm20token */
865 dump_data(4, (uint8
*)outbuf
, PTR_DIFF(q
, outbuf
));
867 pull_ascii_fstring(getdc_str
, getdc
);
868 pull_ascii_nstring(source_name
, sizeof(source_name
), dgram
->source_name
.name
);
869 source_addr
= SMB_STRDUP(inet_ntoa(dgram
->header
.source_ip
));
870 if (source_addr
== NULL
) {
871 DEBUG(3, ("out of memory copying client"
872 " address string\n"));
878 * packets requeued after delay are marked as
881 if ((p
->locked
== False
) &&
882 (strlen(ascuser
) == 0) &&
883 delay_logon(source_name
, source_addr
))
887 DEBUG(3, ("process_logon_packet: "
888 "delaying initial logon "
889 "reply for client %s(%s) for "
891 source_name
, source_addr
,
892 lp_init_logon_delay()));
894 when
= timeval_current_ofs(0,
895 lp_init_logon_delay() * 1000);
897 event_add_timed(nmbd_event_context(),
900 delayed_init_logon_handler
,
903 DEBUG(3, ("process_logon_packet: "
904 "processing delayed initial "
905 "logon reply for client "
907 source_name
, source_addr
));
910 send_mailslot(true, getdc
,
911 outbuf
,PTR_DIFF(q
,outbuf
),
912 global_myname(), 0x0,
914 dgram
->source_name
.name_type
,
918 SAFE_FREE(source_addr
);
923 /* Announce change to UAS or SAM. Send by the domain controller when a
924 replication event is required. */
926 case NETLOGON_ANNOUNCE_UAS
:
927 DEBUG(5, ("Got NETLOGON_ANNOUNCE_UAS\n"));
931 DEBUG(3,("process_logon_packet: Unknown domain request %d\n",code
));