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-1998
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 extern struct in_addr allones_ip;
28 extern uint16 samba_nb_type; /* Samba's NetBIOS type. */
30 /****************************************************************************
31 Fail to become a Logon server on a subnet.
32 ****************************************************************************/
33 static void become_logon_server_fail(struct subnet_record *subrec,
34 struct response_record *rrec,
35 struct nmb_name *fail_name)
37 struct work_record *work = find_workgroup_on_subnet(subrec, fail_name->name);
38 struct server_record *servrec;
42 DEBUG(0,("become_logon_server_fail: Error - cannot find \
43 workgroup %s on subnet %s\n", fail_name->name, subrec->subnet_name));
47 if((servrec = find_server_in_workgroup( work, lp_netbios_name())) == NULL)
49 DEBUG(0,("become_logon_server_fail: Error - cannot find server %s \
50 in workgroup %s on subnet %s\n",
51 lp_netbios_name(), fail_name->name, subrec->subnet_name));
52 work->log_state = LOGON_NONE;
56 /* Set the state back to LOGON_NONE. */
57 work->log_state = LOGON_NONE;
59 servrec->serv.type &= ~SV_TYPE_DOMAIN_CTRL;
61 DEBUG(0,("become_logon_server_fail: Failed to become a domain master for \
62 workgroup %s on subnet %s. Couldn't register name %s.\n",
63 work->work_group, subrec->subnet_name, nmb_namestr(fail_name)));
67 /****************************************************************************
68 Become a Logon server on a subnet.
69 ****************************************************************************/
71 static void become_logon_server_success(struct subnet_record *subrec,
72 struct userdata_struct *userdata,
73 struct nmb_name *registered_name,
75 int ttl, struct in_addr registered_ip)
77 struct work_record *work = find_workgroup_on_subnet( subrec, registered_name->name);
78 struct server_record *servrec;
82 DEBUG(0,("become_logon_server_success: Error - cannot find \
83 workgroup %s on subnet %s\n", registered_name->name, subrec->subnet_name));
87 if((servrec = find_server_in_workgroup( work, lp_netbios_name())) == NULL)
89 DEBUG(0,("become_logon_server_success: Error - cannot find server %s \
90 in workgroup %s on subnet %s\n",
91 lp_netbios_name(), registered_name->name, subrec->subnet_name));
92 work->log_state = LOGON_NONE;
96 /* Set the state in the workgroup structure. */
97 work->log_state = LOGON_SRV; /* Become domain master. */
99 /* Update our server status. */
100 servrec->serv.type |= (SV_TYPE_NT|SV_TYPE_DOMAIN_MEMBER);
101 /* To allow Win95 policies to load we need to set type domain
104 servrec->serv.type |= SV_TYPE_DOMAIN_CTRL;
106 /* Tell the namelist writer to write out a change. */
107 subrec->work_changed = True;
110 * Add the WORKGROUP<1C> name to the UNICAST subnet with the IP address
111 * for this subnet so we will respond to queries on this name.
114 struct nmb_name nmbname;
115 make_nmb_name(&nmbname,lp_workgroup(),0x1c);
116 insert_permanent_name_into_unicast(subrec, &nmbname, 0x1c);
119 DEBUG(0,("become_logon_server_success: Samba is now a logon server \
120 for workgroup %s on subnet %s\n", work->work_group, subrec->subnet_name));
123 /*******************************************************************
124 Become a logon server by attempting to register the WORKGROUP<1c>
126 ******************************************************************/
128 static void become_logon_server(struct subnet_record *subrec,
129 struct work_record *work)
131 DEBUG(2,("become_logon_server: Atempting to become logon server for workgroup %s \
132 on subnet %s\n", work->work_group,subrec->subnet_name));
134 DEBUG(3,("become_logon_server: go to first stage: register %s<1c> name\n",
136 work->log_state = LOGON_WAIT;
138 register_name(subrec, work->work_group,0x1c,samba_nb_type|NB_GROUP,
139 become_logon_server_success,
140 become_logon_server_fail, NULL);
143 /*****************************************************************************
144 Add the internet group <1c> logon names by unicast and broadcast.
145 ****************************************************************************/
146 void add_logon_names(void)
148 struct subnet_record *subrec;
150 for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec))
152 struct work_record *work = find_workgroup_on_subnet(subrec, lp_workgroup());
154 if (work && (work->log_state == LOGON_NONE))
156 struct nmb_name nmbname;
157 make_nmb_name(&nmbname,lp_workgroup(),0x1c);
159 if (find_name_on_subnet(subrec, &nmbname, FIND_SELF_NAME) == NULL)
163 dbgtext( "add_domain_logon_names:\n" );
164 dbgtext( "Attempting to become logon server " );
165 dbgtext( "for workgroup %s ", lp_workgroup() );
166 dbgtext( "on subnet %s\n", subrec->subnet_name );
168 become_logon_server(subrec, work);