1997-12-13 17:16:07 +03:00
/*
2002-01-30 09:08:46 +03:00
Unix SMB / CIFS implementation .
1997-12-13 17:16:07 +03:00
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
1998-07-24 23:03:11 +04:00
Copyright ( C ) Christopher R . Hertel 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
2007-07-09 23:25:36 +04:00
the Free Software Foundation ; either version 3 of the License , or
1997-12-13 17:16:07 +03:00
( 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
2007-07-10 04:52:41 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
1997-12-13 17:16:07 +03:00
*/
1998-07-24 23:03:11 +04:00
/* -------------------------------------------------------------------------- **
* Modified July 1998 by CRH .
* I converted this module to use the canned doubly - linked lists . I also
* added comments above the functions where possible .
*/
1997-12-13 17:16:07 +03:00
# include "includes.h"
2010-08-18 17:22:09 +04:00
# include "nmbd/nmbd.h"
1997-12-13 17:16:07 +03:00
1998-07-24 23:03:11 +04:00
/* -------------------------------------------------------------------------- **
* Variables . . .
*
* lmb_browserlist - This is our local master browser list .
*/
2005-12-07 02:06:38 +03:00
struct browse_cache_record * lmb_browserlist ;
1998-07-24 23:03:11 +04:00
/* -------------------------------------------------------------------------- **
* Functions . . .
*/
/* ************************************************************************** **
* Remove and free a browser list entry .
*
* Input : browc - A pointer to the entry to be removed from the list and
* freed .
* Output : none .
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
static void remove_lmb_browser_entry ( struct browse_cache_record * browc )
2003-07-03 23:11:31 +04:00
{
2005-12-07 02:06:38 +03:00
DLIST_REMOVE ( lmb_browserlist , browc ) ;
SAFE_FREE ( browc ) ;
2003-07-03 23:11:31 +04:00
}
1998-07-24 23:03:11 +04:00
/* ************************************************************************** **
* Update a browser death time .
*
* Input : browc - Pointer to the entry to be updated .
* Output : none .
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
void update_browser_death_time ( struct browse_cache_record * browc )
2003-07-03 23:11:31 +04:00
{
/* Allow the new lmb to miss an announce period before we remove it. */
browc - > death_time = time ( NULL ) + ( ( CHECK_TIME_MST_ANNOUNCE + 2 ) * 60 ) ;
}
1998-07-24 23:03:11 +04:00
/* ************************************************************************** **
* Create a browser entry and add it to the local master browser list .
*
* Input : work_name
* browser_name
* ip
*
* Output : Pointer to the new entry , or NULL if malloc ( ) failed .
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
2003-08-23 05:59:14 +04:00
struct browse_cache_record * create_browser_in_lmb_cache ( const char * work_name ,
const char * browser_name ,
1998-07-24 23:03:11 +04:00
struct in_addr ip )
2003-07-03 23:11:31 +04:00
{
struct browse_cache_record * browc ;
time_t now = time ( NULL ) ;
1997-12-13 17:16:07 +03:00
2004-12-07 21:25:53 +03:00
browc = SMB_MALLOC_P ( struct browse_cache_record ) ;
1997-12-13 17:16:07 +03:00
2003-07-03 23:11:31 +04:00
if ( NULL = = browc ) {
DEBUG ( 0 , ( " create_browser_in_lmb_cache: malloc fail ! \n " ) ) ;
return ( NULL ) ;
}
1998-07-24 23:03:11 +04:00
2003-07-03 23:11:31 +04:00
memset ( ( char * ) browc , ' \0 ' , sizeof ( * browc ) ) ;
1997-12-13 17:16:07 +03:00
2003-07-03 23:11:31 +04:00
/* For a new lmb entry we want to sync with it after one minute. This
will allow it time to send out a local announce and build its
browse list .
*/
browc - > sync_time = now + 60 ;
/* Allow the new lmb to miss an announce period before we remove it. */
browc - > death_time = now + ( ( CHECK_TIME_MST_ANNOUNCE + 2 ) * 60 ) ;
2004-03-16 00:45:45 +03:00
unstrcpy ( browc - > lmb_name , browser_name ) ;
unstrcpy ( browc - > work_group , work_name ) ;
2012-08-09 02:35:28 +04:00
if ( ! strupper_m ( browc - > lmb_name ) ) {
SAFE_FREE ( browc ) ;
return NULL ;
}
if ( ! strupper_m ( browc - > work_group ) ) {
SAFE_FREE ( browc ) ;
return NULL ;
}
1997-12-13 17:16:07 +03:00
2003-07-03 23:11:31 +04:00
browc - > ip = ip ;
1997-12-13 17:16:07 +03:00
2016-02-05 13:32:18 +03:00
DLIST_ADD_END ( lmb_browserlist , browc ) ;
2003-07-03 23:11:31 +04:00
2014-07-29 16:11:54 +04:00
DEBUG ( 3 , ( " nmbd_browserdb:create_browser_in_lmb_cache() \n " ) ) ;
DEBUGADD ( 3 , ( " Added lmb cache entry for workgroup %s name %s IP %s "
" ttl %d \n " , browc - > work_group , browc - > lmb_name ,
inet_ntoa ( ip ) , ( int ) browc - > death_time ) ) ;
1998-07-24 23:03:11 +04:00
2003-07-03 23:11:31 +04:00
return ( browc ) ;
}
1998-07-24 23:03:11 +04:00
/* ************************************************************************** **
* Find a browser entry in the local master browser list .
*
* Input : browser_name - The name for which to search .
*
* Output : A pointer to the matching entry , or NULL if no match was found .
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
2003-08-23 05:59:14 +04:00
struct browse_cache_record * find_browser_in_lmb_cache ( const char * browser_name )
2003-07-03 23:11:31 +04:00
{
struct browse_cache_record * browc ;
1997-12-13 17:16:07 +03:00
2005-12-07 02:06:38 +03:00
for ( browc = lmb_browserlist ; browc ; browc = browc - > next ) {
if ( strequal ( browser_name , browc - > lmb_name ) ) {
2003-07-03 23:11:31 +04:00
break ;
2005-12-07 02:06:38 +03:00
}
}
1997-12-13 17:16:07 +03:00
2005-12-07 02:06:38 +03:00
return browc ;
2003-07-03 23:11:31 +04:00
}
1998-07-24 23:03:11 +04:00
/* ************************************************************************** **
* Expire timed out browsers in the browserlist .
*
* Input : t - Expiration time . Entries with death times less than this
* value will be removed from the list .
* Output : none .
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
void expire_lmb_browsers ( time_t t )
2003-07-03 23:11:31 +04:00
{
struct browse_cache_record * browc ;
struct browse_cache_record * nextbrowc ;
2005-12-07 02:06:38 +03:00
for ( browc = lmb_browserlist ; browc ; browc = nextbrowc ) {
nextbrowc = browc - > next ;
2003-07-03 23:11:31 +04:00
if ( browc - > death_time < t ) {
2014-07-29 16:11:54 +04:00
DEBUG ( 3 , ( " nmbd_browserdb:expire_lmb_browsers() \n " ) ) ;
DEBUGADD ( 3 , ( " Removing timed out lmb entry %s \n " ,
browc - > lmb_name ) ) ;
2003-07-03 23:11:31 +04:00
remove_lmb_browser_entry ( browc ) ;
}
}
}