summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source3/include/nameserv.h19
-rw-r--r--source3/include/proto.h12
-rw-r--r--source3/nmbd/nmbd_browserdb.c281
-rw-r--r--source3/nmbd/nmbd_browsesync.c4
4 files changed, 175 insertions, 141 deletions
diff --git a/source3/include/nameserv.h b/source3/include/nameserv.h
index 0ba7acda18..80d9667d1c 100644
--- a/source3/include/nameserv.h
+++ b/source3/include/nameserv.h
@@ -189,11 +189,10 @@ struct nmb_data
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
{
ubi_trNode node[1];
-
struct subnet_record *subnet;
struct nmb_name name; /* The netbios name. */
struct nmb_data data; /* The netbios data. */
@@ -201,16 +200,14 @@ struct name_record
/* Browser cache for synchronising browse lists. */
struct browse_cache_record
-{
- struct browse_cache_record *next;
- struct browse_cache_record *prev;
-
- pstring lmb_name;
- pstring work_group;
+ {
+ ubi_dlNode node[1];
+ pstring lmb_name;
+ pstring work_group;
struct in_addr ip;
- time_t sync_time;
- time_t death_time; /* The time the record must be removed. */
-};
+ time_t sync_time;
+ 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
contained within lists of domains. */
diff --git a/source3/include/proto.h b/source3/include/proto.h
index 5819d1aadc..8adfb70d38 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -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 */
-void remove_lmb_browser_entry(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, char *browser_name,
- struct in_addr ip);
+void update_browser_death_time( struct browse_cache_record *browc );
+struct browse_cache_record *create_browser_in_lmb_cache( char *work_name,
+ char *browser_name,
+ struct in_addr ip );
struct browse_cache_record *find_browser_in_lmb_cache( char *browser_name );
-void expire_lmb_browsers(time_t t);
-void remove_workgroup_lmb_browsers(char *work_group);
+void expire_lmb_browsers( time_t t );
+void remove_workgroup_lmb_browsers( char *work_group );
/*The following definitions come from nmbd_browsesync.c */
diff --git a/source3/nmbd/nmbd_browserdb.c b/source3/nmbd/nmbd_browserdb.c
index ee3e4e4bde..293a129d42 100644
--- a/source3/nmbd/nmbd_browserdb.c
+++ b/source3/nmbd/nmbd_browserdb.c
@@ -5,6 +5,7 @@
Copyright (C) Andrew Tridgell 1994-1998
Copyright (C) Luke Kenneth Casson Leighton 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
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.
*/
+/* -------------------------------------------------------------------------- **
+ * 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 "smb.h"
extern int DEBUGLEVEL;
-/* This is our local master browser list database. */
-struct browse_cache_record *lmb_browserlist = NULL;
-
-/***************************************************************************
-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)
+/* -------------------------------------------------------------------------- **
+ * Variables...
+ *
+ * lmb_browserlist - This is our local master browser list.
+ */
+
+ubi_dlNewList( lmb_browserlist );
+
+
+/* -------------------------------------------------------------------------- **
+ * 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 )
+ {
+ free( (char *)ubi_dlRemThis( lmb_browserlist, browc ) );
+ } /* remove_lmb_browser_entry */
+
+/* ************************************************************************** **
+ * 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 )
{
- lmb_browserlist = browc;
- browc->prev = NULL;
- browc->next = NULL;
- return;
- }
-
- for (browc2 = lmb_browserlist; browc2->next; browc2 = browc2->next)
- ;
-
- browc2->next = browc;
- browc->next = NULL;
- browc->prev = browc2;
-}
-
-/*******************************************************************
-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. */
- browc->death_time = time(NULL) + (CHECK_TIME_MST_ANNOUNCE + 2)*60;
-}
-
-/****************************************************************************
-Create a browser entry.
-****************************************************************************/
-
-struct browse_cache_record *create_browser_in_lmb_cache(char *work_name, char *browser_name,
- struct in_addr ip)
-{
+ browc->death_time = time(NULL) + ( (CHECK_TIME_MST_ANNOUNCE + 2) * 60 );
+ } /* update_browser_death_time */
+
+/* ************************************************************************** **
+ * 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.
+ *
+ * ************************************************************************** **
+ */
+struct browse_cache_record *create_browser_in_lmb_cache( char *work_name,
+ char *browser_name,
+ struct in_addr ip )
+ {
struct browse_cache_record *browc;
- time_t now = time(NULL);
+ time_t now = time( NULL );
- browc = (struct browse_cache_record *)malloc(sizeof(*browc));
-
- if (browc == NULL)
- {
- DEBUG(0,("create_browser_in_lmb_cache: malloc fail !\n"));
- return(NULL);
- }
+ browc = (struct browse_cache_record *)malloc( sizeof( *browc ) );
- bzero((char *)browc,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
will allow it time to send out a local announce and build its
- browse list. */
-
+ 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;
+ browc->death_time = now + ( (CHECK_TIME_MST_ANNOUNCE + 2) * 60 );
- StrnCpy(browc->lmb_name, browser_name,sizeof(browc->lmb_name)-1);
- StrnCpy(browc->work_group,work_name,sizeof(browc->work_group)-1);
- strupper(browc->lmb_name);
- strupper(browc->work_group);
+ StrnCpy( browc->lmb_name, browser_name, sizeof(browc->lmb_name)-1 );
+ StrnCpy( browc->work_group, work_name, sizeof(browc->work_group)-1 );
+ strupper( browc->lmb_name );
+ strupper( browc->work_group );
browc->ip = ip;
- add_to_lmb_browse_cache(browc);
-
- DEBUG(3,("create_browser_in_lmb_cache: Added lmb cache entry for workgroup %s name %s IP %s ttl %d\n",
- browc->work_group, browc->lmb_name, inet_ntoa(ip), browc->death_time));
-
- return(browc);
-}
-
-/****************************************************************************
-Find a browser entry.
-****************************************************************************/
+ (void)ubi_dlAddTail( lmb_browserlist, browc );
+ if( DEBUGLVL( 3 ) )
+ {
+ 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 );
+ } /* create_browser_in_lmb_cache */
+
+/* ************************************************************************** **
+ * 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 *browc = NULL;
+ {
+ struct browse_cache_record *browc;
- for( browc = lmb_browserlist; browc; browc = browc->next)
- if(strequal( browser_name, browc->lmb_name))
+ for( browc = (struct browse_cache_record *)ubi_dlFirst( lmb_browserlist );
+ browc;
+ browc = (struct browse_cache_record *)ubi_dlNext( browc ) )
+ if( strequal( browser_name, browc->lmb_name ) )
break;
- return browc;
-}
-
-/*******************************************************************
- Expire timed out browsers in the browserlist.
-******************************************************************/
-
-void expire_lmb_browsers(time_t t)
-{
+ return( browc );
+ } /* find_browser_in_lmb_cache */
+
+/* ************************************************************************** **
+ * 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;
- for (browc = lmb_browserlist; browc; browc = nextbrowc)
- {
- nextbrowc = browc->next;
-
- if (browc->death_time < t)
+ for( browc = (struct browse_cache_record *)ubi_dlFirst( lmb_browserlist );
+ browc;
+ browc = nextbrowc )
{
- DEBUG(3,("expire_lmb_browsers: Removing timed out lmb entry %s\n",browc->lmb_name));
- remove_lmb_browser_entry(browc);
+ 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 );
+ }
}
- }
-}
-
-/*******************************************************************
- Remove browsers from a named workgroup in the browserlist.
-******************************************************************/
-
-void remove_workgroup_lmb_browsers(char *work_group)
+ } /* 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 *nextbrowc;
- for (browc = lmb_browserlist; browc; browc = nextbrowc)
- {
- nextbrowc = browc->next;
-
- if (strequal(work_group, browc->work_group))
+ for( browc = (struct browse_cache_record *)ubi_dlFirst( lmb_browserlist );
+ browc;
+ browc = nextbrowc )
{
- DEBUG(3,("remove_workgroup_browsers: Removing 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_workgroup_lmb_browsers */
+/* ========================================================================== */
diff --git a/source3/nmbd/nmbd_browsesync.c b/source3/nmbd/nmbd_browsesync.c
index c1f6aa5a6c..dd4a82d7f6 100644
--- a/source3/nmbd/nmbd_browsesync.c
+++ b/source3/nmbd/nmbd_browsesync.c
@@ -215,7 +215,9 @@ void dmb_expire_and_sync_browser_lists(time_t 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)
sync_with_lmb(browc);