1997-12-13 17:16:07 +03:00
/*
Unix SMB / Netbios implementation .
Version 1.9 .
NBT netbios routines and daemon - version 2
1998-01-22 16:27:43 +03:00
Copyright ( C ) Andrew Tridgell 1994 - 1998
Copyright ( C ) Luke Kenneth Casson Leighton 1994 - 1998
Copyright ( C ) Jeremy Allison 1994 - 1998
1997-12-13 17:16:07 +03:00
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation ; either version 2 of the License , or
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program ; if not , write to the Free Software
Foundation , Inc . , 675 Mass Ave , Cambridge , MA 0213 9 , USA .
*/
# include "includes.h"
extern int DEBUGLEVEL ;
extern char * * my_netbios_names ;
1998-04-25 05:12:08 +04:00
extern fstring global_myworkgroup ;
1998-02-24 23:05:39 +03:00
extern pstring scope ;
1997-12-13 17:16:07 +03:00
extern uint16 samba_nb_type ; /* Samba's NetBIOS type. */
/****************************************************************************
Fail funtion when registering my netbios names .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static void my_name_register_failed ( struct subnet_record * subrec ,
struct response_record * rrec , struct nmb_name * nmbname )
{
DEBUG ( 0 , ( " my_name_register_failed: Failed to register my name %s on subnet %s. \n " ,
namestr ( nmbname ) , subrec - > subnet_name ) ) ;
}
/****************************************************************************
Add my workgroup and my given names to the subnet lists .
Also add the magic Samba names .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1998-04-13 23:24:06 +04:00
BOOL register_my_workgroup_and_names ( void )
1997-12-13 17:16:07 +03:00
{
struct subnet_record * subrec ;
struct work_record * work ;
int i ;
for ( subrec = FIRST_SUBNET ; subrec ; subrec = NEXT_SUBNET_INCLUDING_UNICAST ( subrec ) )
{
/* Create the workgroup on the subnet. */
1998-04-25 05:12:08 +04:00
if ( ( work = create_workgroup_on_subnet ( subrec , global_myworkgroup , PERMANENT_TTL ) ) = = NULL )
1997-12-13 17:16:07 +03:00
{
DEBUG ( 0 , ( " register_my_workgroup_and_names: Failed to create my workgroup %s on subnet %s. \
1998-04-25 05:12:08 +04:00
Exiting . \ n " , global_myworkgroup, subrec->subnet_name));
1997-12-13 17:16:07 +03:00
return False ;
}
1998-06-08 23:09:47 +04:00
/* Each subnet entry, except for the wins_server_subnet has the magic Samba names. */
1997-12-13 17:16:07 +03:00
add_samba_names_to_subnet ( subrec ) ;
/* Register all our names including aliases. */
for ( i = 0 ; my_netbios_names [ i ] ; i + + )
{
register_name ( subrec , my_netbios_names [ i ] , 0x20 , samba_nb_type ,
NULL ,
my_name_register_failed , NULL ) ;
register_name ( subrec , my_netbios_names [ i ] , 0x03 , samba_nb_type ,
NULL ,
my_name_register_failed , NULL ) ;
register_name ( subrec , my_netbios_names [ i ] , 0x00 , samba_nb_type ,
NULL ,
my_name_register_failed , NULL ) ;
}
/* Initiate election processing, register the workgroup names etc. */
initiate_myworkgroup_startup ( subrec , work ) ;
}
/* If we are not a WINS client, we still need to add the magic Samba
names and the netbios names to the unicast subnet directly . This is
to allow unicast node status requests and queries to still work
in a broadcast only environment . */
if ( we_are_a_wins_client ( ) = = False )
{
add_samba_names_to_subnet ( unicast_subnet ) ;
for ( i = 0 ; my_netbios_names [ i ] ; i + + )
{
1998-02-24 23:05:39 +03:00
for ( subrec = FIRST_SUBNET ; subrec ; subrec = NEXT_SUBNET_EXCLUDING_UNICAST ( subrec ) )
{
/*
* Ensure all the IP addresses are added if we are multihomed .
*/
struct nmb_name nmbname ;
make_nmb_name ( & nmbname , my_netbios_names [ i ] , 0x20 , scope ) ;
insert_permanent_name_into_unicast ( subrec , & nmbname , samba_nb_type ) ;
make_nmb_name ( & nmbname , my_netbios_names [ i ] , 0x3 , scope ) ;
insert_permanent_name_into_unicast ( subrec , & nmbname , samba_nb_type ) ;
make_nmb_name ( & nmbname , my_netbios_names [ i ] , 0x0 , scope ) ;
insert_permanent_name_into_unicast ( subrec , & nmbname , samba_nb_type ) ;
}
}
/*
* Add the WORKGROUP < 0 > and WORKGROUP < 1 e > group names to the unicast subnet
* also for the same reasons .
*/
for ( subrec = FIRST_SUBNET ; subrec ; subrec = NEXT_SUBNET_EXCLUDING_UNICAST ( subrec ) )
{
/*
* Ensure all the IP addresses are added if we are multihomed .
*/
struct nmb_name nmbname ;
1997-12-13 17:16:07 +03:00
1998-04-25 05:12:08 +04:00
make_nmb_name ( & nmbname , global_myworkgroup , 0x0 , scope ) ;
1998-02-24 23:05:39 +03:00
insert_permanent_name_into_unicast ( subrec , & nmbname , samba_nb_type | NB_GROUP ) ;
1997-12-13 17:16:07 +03:00
1998-04-25 05:12:08 +04:00
make_nmb_name ( & nmbname , global_myworkgroup , 0x1e , scope ) ;
1998-02-24 23:05:39 +03:00
insert_permanent_name_into_unicast ( subrec , & nmbname , samba_nb_type | NB_GROUP ) ;
1997-12-13 17:16:07 +03:00
}
}
1998-06-08 23:09:47 +04:00
/*
* We need to add the Samba names to the remote broadcast subnet ,
* as NT 4. x does directed broadcast requests to the * < 0x0 > name .
*/
add_samba_names_to_subnet ( remote_broadcast_subnet ) ;
1997-12-13 17:16:07 +03:00
return True ;
}
/****************************************************************************
Remove all the names we registered .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1998-04-13 23:24:06 +04:00
void release_my_names ( void )
1997-12-13 17:16:07 +03:00
{
struct subnet_record * subrec ;
for ( subrec = FIRST_SUBNET ; subrec ; subrec = NEXT_SUBNET_INCLUDING_UNICAST ( subrec ) )
{
struct name_record * namerec , * nextnamerec ;
1998-06-10 23:51:58 +04:00
for ( namerec = ( struct name_record * ) ubi_trFirst ( subrec - > namelist ) ;
namerec ;
namerec = nextnamerec )
1997-12-13 17:16:07 +03:00
{
1998-06-10 23:51:58 +04:00
nextnamerec = ( struct name_record * ) ubi_trNext ( namerec ) ;
1998-06-09 05:56:18 +04:00
if ( ( namerec - > data . source = = SELF_NAME )
& & ! NAME_IS_DEREGISTERING ( namerec ) )
1998-06-10 23:51:58 +04:00
release_name ( subrec , namerec , standard_success_release ,
NULL , NULL ) ;
1997-12-13 17:16:07 +03:00
}
}
}
/*******************************************************************
Refresh our registered names .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void refresh_my_names ( time_t t )
{
struct subnet_record * subrec ;
for ( subrec = FIRST_SUBNET ; subrec ; subrec = NEXT_SUBNET_INCLUDING_UNICAST ( subrec ) )
{
struct name_record * namerec ;
1998-06-10 23:51:58 +04:00
for ( namerec = ( struct name_record * ) ubi_trFirst ( subrec - > namelist ) ;
namerec ;
namerec = ( struct name_record * ) ubi_trNext ( namerec ) )
1997-12-13 17:16:07 +03:00
{
/* Each SELF name has an individual time to be refreshed. */
1998-06-09 05:56:18 +04:00
if ( ( namerec - > data . source = = SELF_NAME )
& & ( namerec - > data . refresh_time < t )
& & ( namerec - > data . death_time ! = PERMANENT_TTL ) )
1997-12-13 17:16:07 +03:00
{
/* We cheat here and pretend the refresh is going to be
successful & update the refresh times . This stops
multiple refresh calls being done . We actually
deal with refresh failure in the fail_fn .
*/
1998-06-09 05:56:18 +04:00
if ( ! is_refresh_already_queued ( subrec , namerec ) )
refresh_name ( subrec , namerec , NULL , NULL , NULL ) ;
namerec - > data . death_time + = lp_max_ttl ( ) ;
namerec - > data . refresh_time + = lp_max_ttl ( ) ;
1997-12-13 17:16:07 +03:00
}
}
}
}