2 Unix SMB/Netbios implementation.
4 NBT netbios routines and daemon - version 2
5 Copyright (C) Andrew Tridgell 1994-1998
6 Copyright (C) Luke Kenneth Casson Leighton 1994-1998
7 Copyright (C) Jeremy Allison 1994-1998
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.
27 extern pstring global_myname
;
28 extern fstring global_myworkgroup
;
29 extern char **my_netbios_names
;
30 extern struct in_addr allones_ip
;
32 extern uint16 samba_nb_type
; /* Samba's NetBIOS type. */
34 /****************************************************************************
35 Fail to become a Logon server on a subnet.
36 ****************************************************************************/
37 static void become_logon_server_fail(struct subnet_record
*subrec
,
38 struct response_record
*rrec
,
39 struct nmb_name
*fail_name
)
41 struct work_record
*work
= find_workgroup_on_subnet(subrec
, fail_name
->name
);
42 struct server_record
*servrec
;
46 DEBUG(0,("become_logon_server_fail: Error - cannot find \
47 workgroup %s on subnet %s\n", fail_name
->name
, subrec
->subnet_name
));
51 if((servrec
= find_server_in_workgroup( work
, global_myname
)) == NULL
)
53 DEBUG(0,("become_logon_server_fail: Error - cannot find server %s \
54 in workgroup %s on subnet %s\n",
55 global_myname
, fail_name
->name
, subrec
->subnet_name
));
56 work
->log_state
= LOGON_NONE
;
60 /* Set the state back to LOGON_NONE. */
61 work
->log_state
= LOGON_NONE
;
63 servrec
->serv
.type
&= ~SV_TYPE_DOMAIN_CTRL
;
65 DEBUG(0,("become_logon_server_fail: Failed to become a domain master for \
66 workgroup %s on subnet %s. Couldn't register name %s.\n",
67 work
->work_group
, subrec
->subnet_name
, nmb_namestr(fail_name
)));
71 /****************************************************************************
72 Become a Logon server on a subnet.
73 ****************************************************************************/
75 static void become_logon_server_success(struct subnet_record
*subrec
,
76 struct userdata_struct
*userdata
,
77 struct nmb_name
*registered_name
,
79 int ttl
, struct in_addr registered_ip
)
81 struct work_record
*work
= find_workgroup_on_subnet( subrec
, registered_name
->name
);
82 struct server_record
*servrec
;
86 DEBUG(0,("become_logon_server_success: Error - cannot find \
87 workgroup %s on subnet %s\n", registered_name
->name
, subrec
->subnet_name
));
91 if((servrec
= find_server_in_workgroup( work
, global_myname
)) == NULL
)
93 DEBUG(0,("become_logon_server_success: Error - cannot find server %s \
94 in workgroup %s on subnet %s\n",
95 global_myname
, registered_name
->name
, subrec
->subnet_name
));
96 work
->log_state
= LOGON_NONE
;
100 /* Set the state in the workgroup structure. */
101 work
->log_state
= LOGON_SRV
; /* Become domain master. */
103 /* Update our server status. */
104 servrec
->serv
.type
|= (SV_TYPE_NT
|SV_TYPE_DOMAIN_MEMBER
);
105 /* To allow Win95 policies to load we need to set type domain
108 servrec
->serv
.type
|= SV_TYPE_DOMAIN_CTRL
;
110 /* Tell the namelist writer to write out a change. */
111 subrec
->work_changed
= True
;
113 DEBUG(0,("become_logon_server_success: Samba is now a logon server \
114 for workgroup %s on subnet %s\n", work
->work_group
, subrec
->subnet_name
));
117 /*******************************************************************
118 Become a logon server by attempting to register the WORKGROUP<1c>
120 ******************************************************************/
122 static void become_logon_server(struct subnet_record
*subrec
,
123 struct work_record
*work
)
125 DEBUG(2,("become_logon_server: Atempting to become logon server for workgroup %s \
126 on subnet %s\n", work
->work_group
,subrec
->subnet_name
));
128 DEBUG(3,("become_logon_server: go to first stage: register %s<1c> name\n",
130 work
->log_state
= LOGON_WAIT
;
132 register_name(subrec
, work
->work_group
,0x1c,samba_nb_type
|NB_GROUP
,
133 become_logon_server_success
,
134 become_logon_server_fail
, NULL
);
137 /*****************************************************************************
138 Add the internet group <1c> logon names by unicast and broadcast.
139 ****************************************************************************/
140 void add_logon_names(void)
142 struct subnet_record
*subrec
;
144 for (subrec
= FIRST_SUBNET
; subrec
; subrec
= NEXT_SUBNET_INCLUDING_UNICAST(subrec
))
146 struct work_record
*work
= find_workgroup_on_subnet(subrec
, global_myworkgroup
);
148 if (work
&& (work
->log_state
== LOGON_NONE
))
150 struct nmb_name nmbname
;
151 make_nmb_name(&nmbname
,global_myworkgroup
,0x1c);
153 if (find_name_on_subnet(subrec
, &nmbname
, FIND_SELF_NAME
) == NULL
)
157 dbgtext( "add_domain_logon_names:\n" );
158 dbgtext( "Attempting to become logon server " );
159 dbgtext( "for workgroup %s ", global_myworkgroup
);
160 dbgtext( "on subnet %s\n", subrec
->subnet_name
);
162 become_logon_server(subrec
, work
);