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 char **my_netbios_names;
27 extern fstring global_myworkgroup;
29 extern uint16 samba_nb_type; /* Samba's NetBIOS type. */
31 /****************************************************************************
32 Fail funtion when registering my netbios names.
33 **************************************************************************/
35 static void my_name_register_failed(struct subnet_record *subrec,
36 struct response_record *rrec, struct nmb_name *nmbname)
38 DEBUG(0,("my_name_register_failed: Failed to register my name %s on subnet %s.\n",
39 nmb_namestr(nmbname), subrec->subnet_name));
43 /****************************************************************************
44 Add my workgroup and my given names to one subnet
45 Also add the magic Samba names.
46 **************************************************************************/
47 void register_my_workgroup_one_subnet(struct subnet_record *subrec)
51 struct work_record *work;
53 /* Create the workgroup on the subnet. */
54 if((work = create_workgroup_on_subnet(subrec, global_myworkgroup,
55 PERMANENT_TTL)) == NULL) {
56 DEBUG(0,("register_my_workgroup_and_names: Failed to create my workgroup %s on subnet %s. \
57 Exiting.\n", global_myworkgroup, subrec->subnet_name));
61 /* Each subnet entry, except for the wins_server_subnet has
62 the magic Samba names. */
63 add_samba_names_to_subnet(subrec);
65 /* Register all our names including aliases. */
66 for (i=0; my_netbios_names[i]; i++) {
67 register_name(subrec, my_netbios_names[i],0x20,samba_nb_type,
69 my_name_register_failed, NULL);
70 register_name(subrec, my_netbios_names[i],0x03,samba_nb_type,
72 my_name_register_failed, NULL);
73 register_name(subrec, my_netbios_names[i],0x00,samba_nb_type,
75 my_name_register_failed, NULL);
78 /* Initiate election processing, register the workgroup names etc. */
79 initiate_myworkgroup_startup(subrec, work);
83 /****************************************************************************
84 Add my workgroup and my given names to the subnet lists.
85 Also add the magic Samba names.
86 **************************************************************************/
88 BOOL register_my_workgroup_and_names(void)
90 struct subnet_record *subrec;
93 for(subrec = FIRST_SUBNET;
95 subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec))
97 register_my_workgroup_one_subnet(subrec);
100 /* We still need to add the magic Samba
101 names and the netbios names to the unicast subnet directly. This is
102 to allow unicast node status requests and queries to still work
103 in a broadcast only environment. */
105 add_samba_names_to_subnet(unicast_subnet);
107 for (i=0; my_netbios_names[i]; i++)
109 for(subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec))
112 * Ensure all the IP addresses are added if we are multihomed.
114 struct nmb_name nmbname;
116 make_nmb_name(&nmbname, my_netbios_names[i],0x20);
117 insert_permanent_name_into_unicast(subrec, &nmbname, samba_nb_type);
119 make_nmb_name(&nmbname, my_netbios_names[i],0x3);
120 insert_permanent_name_into_unicast(subrec, &nmbname, samba_nb_type);
122 make_nmb_name(&nmbname, my_netbios_names[i],0x0);
123 insert_permanent_name_into_unicast(subrec, &nmbname, samba_nb_type);
128 * Add the WORKGROUP<0> and WORKGROUP<1e> group names to the unicast subnet
129 * also for the same reasons.
132 for(subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec))
135 * Ensure all the IP addresses are added if we are multihomed.
137 struct nmb_name nmbname;
139 make_nmb_name(&nmbname, global_myworkgroup, 0x0);
140 insert_permanent_name_into_unicast(subrec, &nmbname, samba_nb_type|NB_GROUP);
142 make_nmb_name(&nmbname, global_myworkgroup, 0x1e);
143 insert_permanent_name_into_unicast(subrec, &nmbname, samba_nb_type|NB_GROUP);
147 * We need to add the Samba names to the remote broadcast subnet,
148 * as NT 4.x does directed broadcast requests to the *<0x0> name.
150 add_samba_names_to_subnet(remote_broadcast_subnet);
155 /****************************************************************************
156 Remove all the names we registered.
157 **************************************************************************/
159 void release_my_names(void)
161 #if 0 /*JRR: do WINS server only, otherwise clients ignore us when we come back up*/
162 struct subnet_record *subrec;
164 for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec))
166 struct subnet_record *subrec = unicast_subnet;
169 struct name_record *namerec, *nextnamerec;
171 for (namerec = (struct name_record *)ubi_trFirst( subrec->namelist );
173 namerec = nextnamerec)
175 nextnamerec = (struct name_record *)ubi_trNext( namerec );
176 if( (namerec->data.source == SELF_NAME)
177 && !NAME_IS_DEREGISTERING(namerec) )
178 release_name( subrec, namerec, standard_success_release,
184 /*******************************************************************
185 Refresh our registered names.
186 ******************************************************************/
188 void refresh_my_names(time_t t)
190 struct subnet_record *subrec;
192 for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec))
194 struct name_record *namerec;
196 /* B nodes don't send out name refresh requests, see RFC 1001, 15.5.1 */
197 if (subrec != unicast_subnet)
200 for( namerec = (struct name_record *)ubi_trFirst( subrec->namelist );
202 namerec = (struct name_record *)ubi_trNext( namerec ) )
204 /* Each SELF name has an individual time to be refreshed. */
205 if( (namerec->data.source == SELF_NAME)
206 && (namerec->data.refresh_time < t)
207 && ( namerec->data.death_time != PERMANENT_TTL) )
209 /* We cheat here and pretend the refresh is going to be
210 successful & update the refresh times. This stops
211 multiple refresh calls being done. We actually
212 deal with refresh failure in the fail_fn.
214 if( !is_refresh_already_queued( subrec, namerec) )
215 refresh_name( subrec, namerec, NULL, NULL, NULL );
216 namerec->data.death_time = t + lp_max_ttl();
217 namerec->data.refresh_time = t + MIN(lp_max_ttl(), MAX_REFRESH_TIME);