mirror of
https://github.com/samba-team/samba.git
synced 2025-12-12 12:23:50 +03:00
Converted the browser database to a ubi_dLinkList. This should reduce code
size, etc. Also did a bit of work to add comments. Chris -)-----
This commit is contained in:
@@ -189,11 +189,10 @@ struct nmb_data
|
|||||||
time_t refresh_time; /* The time the record should be refreshed. */
|
time_t refresh_time; /* The time the record should be refreshed. */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* This is the structure used for the local netbios name list. */
|
/* This structure represents an entry in a local netbios name list. */
|
||||||
struct name_record
|
struct name_record
|
||||||
{
|
{
|
||||||
ubi_trNode node[1];
|
ubi_trNode node[1];
|
||||||
|
|
||||||
struct subnet_record *subnet;
|
struct subnet_record *subnet;
|
||||||
struct nmb_name name; /* The netbios name. */
|
struct nmb_name name; /* The netbios name. */
|
||||||
struct nmb_data data; /* The netbios data. */
|
struct nmb_data data; /* The netbios data. */
|
||||||
@@ -201,16 +200,14 @@ struct name_record
|
|||||||
|
|
||||||
/* Browser cache for synchronising browse lists. */
|
/* Browser cache for synchronising browse lists. */
|
||||||
struct browse_cache_record
|
struct browse_cache_record
|
||||||
{
|
{
|
||||||
struct browse_cache_record *next;
|
ubi_dlNode node[1];
|
||||||
struct browse_cache_record *prev;
|
pstring lmb_name;
|
||||||
|
pstring work_group;
|
||||||
pstring lmb_name;
|
|
||||||
pstring work_group;
|
|
||||||
struct in_addr ip;
|
struct in_addr ip;
|
||||||
time_t sync_time;
|
time_t sync_time;
|
||||||
time_t death_time; /* The time the record must be removed. */
|
time_t death_time; /* The time the record must be removed. */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* This is used to hold the list of servers in my domain, and is
|
/* This is used to hold the list of servers in my domain, and is
|
||||||
contained within lists of domains. */
|
contained within lists of domains. */
|
||||||
|
|||||||
@@ -1270,13 +1270,13 @@ void set_workgroup_local_master_browser_name( struct work_record *work, char *ne
|
|||||||
|
|
||||||
/*The following definitions come from nmbd_browserdb.c */
|
/*The following definitions come from nmbd_browserdb.c */
|
||||||
|
|
||||||
void remove_lmb_browser_entry(struct browse_cache_record *browc);
|
void update_browser_death_time( struct browse_cache_record *browc );
|
||||||
void update_browser_death_time(struct browse_cache_record *browc);
|
struct browse_cache_record *create_browser_in_lmb_cache( char *work_name,
|
||||||
struct browse_cache_record *create_browser_in_lmb_cache(char *work_name, char *browser_name,
|
char *browser_name,
|
||||||
struct in_addr ip);
|
struct in_addr ip );
|
||||||
struct browse_cache_record *find_browser_in_lmb_cache( char *browser_name );
|
struct browse_cache_record *find_browser_in_lmb_cache( char *browser_name );
|
||||||
void expire_lmb_browsers(time_t t);
|
void expire_lmb_browsers( time_t t );
|
||||||
void remove_workgroup_lmb_browsers(char *work_group);
|
void remove_workgroup_lmb_browsers( char *work_group );
|
||||||
|
|
||||||
/*The following definitions come from nmbd_browsesync.c */
|
/*The following definitions come from nmbd_browsesync.c */
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
Copyright (C) Andrew Tridgell 1994-1998
|
Copyright (C) Andrew Tridgell 1994-1998
|
||||||
Copyright (C) Luke Kenneth Casson Leighton 1994-1998
|
Copyright (C) Luke Kenneth Casson Leighton 1994-1998
|
||||||
Copyright (C) Jeremy Allison 1994-1998
|
Copyright (C) Jeremy Allison 1994-1998
|
||||||
|
Copyright (C) Christopher R. Hertel 1998
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -21,164 +22,198 @@
|
|||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
/* -------------------------------------------------------------------------- **
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
#include "includes.h"
|
#include "includes.h"
|
||||||
#include "smb.h"
|
|
||||||
|
|
||||||
extern int DEBUGLEVEL;
|
extern int DEBUGLEVEL;
|
||||||
|
|
||||||
/* This is our local master browser list database. */
|
/* -------------------------------------------------------------------------- **
|
||||||
struct browse_cache_record *lmb_browserlist = NULL;
|
* Variables...
|
||||||
|
*
|
||||||
|
* lmb_browserlist - This is our local master browser list.
|
||||||
|
*/
|
||||||
|
|
||||||
/***************************************************************************
|
ubi_dlNewList( lmb_browserlist );
|
||||||
Add a browser into the lmb list.
|
|
||||||
**************************************************************************/
|
|
||||||
|
|
||||||
static void add_to_lmb_browse_cache(struct browse_cache_record *browc)
|
|
||||||
{
|
|
||||||
struct browse_cache_record *browc2;
|
|
||||||
|
|
||||||
if (lmb_browserlist == NULL)
|
/* -------------------------------------------------------------------------- **
|
||||||
|
* 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 )
|
||||||
{
|
{
|
||||||
lmb_browserlist = browc;
|
free( (char *)ubi_dlRemThis( lmb_browserlist, browc ) );
|
||||||
browc->prev = NULL;
|
} /* remove_lmb_browser_entry */
|
||||||
browc->next = NULL;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (browc2 = lmb_browserlist; browc2->next; browc2 = browc2->next)
|
/* ************************************************************************** **
|
||||||
;
|
* Update a browser death time.
|
||||||
|
*
|
||||||
browc2->next = browc;
|
* Input: browc - Pointer to the entry to be updated.
|
||||||
browc->next = NULL;
|
* Output: none.
|
||||||
browc->prev = browc2;
|
*
|
||||||
}
|
* ************************************************************************** **
|
||||||
|
*/
|
||||||
/*******************************************************************
|
void update_browser_death_time( struct browse_cache_record *browc )
|
||||||
Remove a lmb browser entry.
|
{
|
||||||
******************************************************************/
|
|
||||||
|
|
||||||
void remove_lmb_browser_entry(struct browse_cache_record *browc)
|
|
||||||
{
|
|
||||||
if (browc->prev)
|
|
||||||
browc->prev->next = browc->next;
|
|
||||||
if (browc->next)
|
|
||||||
browc->next->prev = browc->prev;
|
|
||||||
|
|
||||||
if (lmb_browserlist == browc)
|
|
||||||
lmb_browserlist = browc->next;
|
|
||||||
|
|
||||||
free((char *)browc);
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
Update a browser death time.
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
void update_browser_death_time(struct browse_cache_record *browc)
|
|
||||||
{
|
|
||||||
/* Allow the new lmb to miss an announce period before we remove it. */
|
/* Allow the new lmb to miss an announce period before we remove it. */
|
||||||
browc->death_time = time(NULL) + (CHECK_TIME_MST_ANNOUNCE + 2)*60;
|
browc->death_time = time(NULL) + ( (CHECK_TIME_MST_ANNOUNCE + 2) * 60 );
|
||||||
}
|
} /* update_browser_death_time */
|
||||||
|
|
||||||
/****************************************************************************
|
/* ************************************************************************** **
|
||||||
Create a browser entry.
|
* Create a browser entry and add it to the local master browser list.
|
||||||
****************************************************************************/
|
*
|
||||||
|
* Input: work_name
|
||||||
struct browse_cache_record *create_browser_in_lmb_cache(char *work_name, char *browser_name,
|
* browser_name
|
||||||
struct in_addr ip)
|
* ip
|
||||||
{
|
*
|
||||||
struct browse_cache_record *browc;
|
* Output: Pointer to the new entry, or NULL if malloc() failed.
|
||||||
time_t now = time(NULL);
|
*
|
||||||
|
* ************************************************************************** **
|
||||||
browc = (struct browse_cache_record *)malloc(sizeof(*browc));
|
*/
|
||||||
|
struct browse_cache_record *create_browser_in_lmb_cache( char *work_name,
|
||||||
if (browc == NULL)
|
char *browser_name,
|
||||||
|
struct in_addr ip )
|
||||||
{
|
{
|
||||||
DEBUG(0,("create_browser_in_lmb_cache: malloc fail !\n"));
|
struct browse_cache_record *browc;
|
||||||
return(NULL);
|
time_t now = time( NULL );
|
||||||
}
|
|
||||||
|
|
||||||
bzero((char *)browc,sizeof(*browc));
|
browc = (struct browse_cache_record *)malloc( sizeof( *browc ) );
|
||||||
|
|
||||||
|
if( NULL == browc )
|
||||||
|
{
|
||||||
|
DEBUG( 0, ("create_browser_in_lmb_cache: malloc fail !\n") );
|
||||||
|
return( NULL );
|
||||||
|
}
|
||||||
|
|
||||||
|
bzero( (char *)browc, sizeof( *browc ) );
|
||||||
|
|
||||||
/* For a new lmb entry we want to sync with it after one minute. This
|
/* 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
|
will allow it time to send out a local announce and build its
|
||||||
browse list. */
|
browse list.
|
||||||
|
*/
|
||||||
browc->sync_time = now + 60;
|
browc->sync_time = now + 60;
|
||||||
|
|
||||||
/* Allow the new lmb to miss an announce period before we remove it. */
|
/* Allow the new lmb to miss an announce period before we remove it. */
|
||||||
browc->death_time = now + (CHECK_TIME_MST_ANNOUNCE + 2)*60;
|
browc->death_time = now + ( (CHECK_TIME_MST_ANNOUNCE + 2) * 60 );
|
||||||
|
|
||||||
StrnCpy(browc->lmb_name, browser_name,sizeof(browc->lmb_name)-1);
|
StrnCpy( browc->lmb_name, browser_name, sizeof(browc->lmb_name)-1 );
|
||||||
StrnCpy(browc->work_group,work_name,sizeof(browc->work_group)-1);
|
StrnCpy( browc->work_group, work_name, sizeof(browc->work_group)-1 );
|
||||||
strupper(browc->lmb_name);
|
strupper( browc->lmb_name );
|
||||||
strupper(browc->work_group);
|
strupper( browc->work_group );
|
||||||
|
|
||||||
browc->ip = ip;
|
browc->ip = ip;
|
||||||
|
|
||||||
add_to_lmb_browse_cache(browc);
|
(void)ubi_dlAddTail( lmb_browserlist, browc );
|
||||||
|
|
||||||
DEBUG(3,("create_browser_in_lmb_cache: Added lmb cache entry for workgroup %s name %s IP %s ttl %d\n",
|
if( DEBUGLVL( 3 ) )
|
||||||
browc->work_group, browc->lmb_name, inet_ntoa(ip), browc->death_time));
|
{
|
||||||
|
Debug1( "nmbd_browserdb:create_browser_in_lmb_cache()\n" );
|
||||||
|
Debug1( " Added lmb cache entry for workgroup %s ", browc->work_group );
|
||||||
|
Debug1( "name %s IP %s ", browc->lmb_name, inet_ntoa(ip) );
|
||||||
|
Debug1( "ttl %d\n", browc->death_time );
|
||||||
|
}
|
||||||
|
|
||||||
return(browc);
|
return( browc );
|
||||||
}
|
} /* create_browser_in_lmb_cache */
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
Find a browser entry.
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
|
/* ************************************************************************** **
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* ************************************************************************** **
|
||||||
|
*/
|
||||||
struct browse_cache_record *find_browser_in_lmb_cache( char *browser_name )
|
struct browse_cache_record *find_browser_in_lmb_cache( char *browser_name )
|
||||||
{
|
{
|
||||||
struct browse_cache_record *browc = NULL;
|
struct browse_cache_record *browc;
|
||||||
|
|
||||||
for( browc = lmb_browserlist; browc; browc = browc->next)
|
for( browc = (struct browse_cache_record *)ubi_dlFirst( lmb_browserlist );
|
||||||
if(strequal( browser_name, browc->lmb_name))
|
browc;
|
||||||
|
browc = (struct browse_cache_record *)ubi_dlNext( browc ) )
|
||||||
|
if( strequal( browser_name, browc->lmb_name ) )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
return browc;
|
return( browc );
|
||||||
}
|
} /* find_browser_in_lmb_cache */
|
||||||
|
|
||||||
/*******************************************************************
|
/* ************************************************************************** **
|
||||||
Expire timed out browsers in the browserlist.
|
* 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 )
|
||||||
|
{
|
||||||
|
struct browse_cache_record *browc;
|
||||||
|
struct browse_cache_record *nextbrowc;
|
||||||
|
|
||||||
void expire_lmb_browsers(time_t t)
|
for( browc = (struct browse_cache_record *)ubi_dlFirst( lmb_browserlist );
|
||||||
|
browc;
|
||||||
|
browc = nextbrowc )
|
||||||
|
{
|
||||||
|
nextbrowc = (struct browse_cache_record *)ubi_dlNext( browc );
|
||||||
|
|
||||||
|
if( browc->death_time < t )
|
||||||
|
{
|
||||||
|
if( DEBUGLVL( 3 ) )
|
||||||
|
{
|
||||||
|
Debug1( "nmbd_browserdb:expire_lmb_browsers()\n" );
|
||||||
|
Debug1( " Removing timed out lmb entry %s\n", browc->lmb_name );
|
||||||
|
}
|
||||||
|
remove_lmb_browser_entry( browc );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} /* expire_lmb_browsers */
|
||||||
|
|
||||||
|
/* ************************************************************************** **
|
||||||
|
* Remove browsers from a named workgroup in the browserlist.
|
||||||
|
*
|
||||||
|
* Input: work_group - The name of the work group which is to be removed
|
||||||
|
* from the browse list.
|
||||||
|
* Output: none.
|
||||||
|
*
|
||||||
|
* ************************************************************************** **
|
||||||
|
*/
|
||||||
|
void remove_workgroup_lmb_browsers( char *work_group )
|
||||||
{
|
{
|
||||||
struct browse_cache_record *browc;
|
struct browse_cache_record *browc;
|
||||||
struct browse_cache_record *nextbrowc;
|
struct browse_cache_record *nextbrowc;
|
||||||
|
|
||||||
for (browc = lmb_browserlist; browc; browc = nextbrowc)
|
for( browc = (struct browse_cache_record *)ubi_dlFirst( lmb_browserlist );
|
||||||
{
|
browc;
|
||||||
nextbrowc = browc->next;
|
browc = nextbrowc )
|
||||||
|
|
||||||
if (browc->death_time < t)
|
|
||||||
{
|
{
|
||||||
DEBUG(3,("expire_lmb_browsers: Removing timed out lmb entry %s\n",browc->lmb_name));
|
nextbrowc = (struct browse_cache_record *)ubi_dlNext( browc );
|
||||||
|
|
||||||
|
if( strequal( work_group, browc->work_group ) )
|
||||||
|
{
|
||||||
|
if( DEBUGLVL( 3 ) )
|
||||||
|
{
|
||||||
|
Debug1( "nmbd_browserdb:remove_workgroup_browsers()\n" );
|
||||||
|
Debug1( "Removing lmb entry %s\n", browc->lmb_name );
|
||||||
|
}
|
||||||
remove_lmb_browser_entry(browc);
|
remove_lmb_browser_entry(browc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
} /* remove_workgroup_lmb_browsers */
|
||||||
}
|
|
||||||
|
|
||||||
/*******************************************************************
|
|
||||||
Remove browsers from a named workgroup in the browserlist.
|
|
||||||
******************************************************************/
|
|
||||||
|
|
||||||
void remove_workgroup_lmb_browsers(char *work_group)
|
|
||||||
{
|
|
||||||
struct browse_cache_record *browc;
|
|
||||||
struct browse_cache_record *nextbrowc;
|
|
||||||
|
|
||||||
for (browc = lmb_browserlist; browc; browc = nextbrowc)
|
|
||||||
{
|
|
||||||
nextbrowc = browc->next;
|
|
||||||
|
|
||||||
if (strequal(work_group, browc->work_group))
|
|
||||||
{
|
|
||||||
DEBUG(3,("remove_workgroup_browsers: Removing lmb entry %s\n",browc->lmb_name));
|
|
||||||
remove_lmb_browser_entry(browc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/* ========================================================================== */
|
||||||
|
|||||||
@@ -215,7 +215,9 @@ void dmb_expire_and_sync_browser_lists(time_t t)
|
|||||||
|
|
||||||
expire_lmb_browsers(t);
|
expire_lmb_browsers(t);
|
||||||
|
|
||||||
for (browc = lmb_browserlist; browc; browc = browc->next)
|
for( browc = (struct browse_cache_record *)ubi_dlFirst( lmb_browserlist );
|
||||||
|
browc;
|
||||||
|
browc = (struct browse_cache_record *)ubi_dlNext( browc ) )
|
||||||
{
|
{
|
||||||
if (browc->sync_time < t)
|
if (browc->sync_time < t)
|
||||||
sync_with_lmb(browc);
|
sync_with_lmb(browc);
|
||||||
|
|||||||
Reference in New Issue
Block a user