2 Unix SMB/Netbios implementation.
4 NBT netbios routines and daemon - version 2
5 Copyright (C) Andrew Tridgell 1994-1998
6 Copyright (C) Luke Kenneth Casson Leighton 1994-1998
7 Copyright (C) Jeremy Allison 1994-1998
8 Copyright (C) Christopher R. Hertel 1998
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 /* -------------------------------------------------------------------------- **
26 * Modified July 1998 by CRH.
27 * I converted this module to use the canned doubly-linked lists. I also
28 * added comments above the functions where possible.
33 /* -------------------------------------------------------------------------- **
36 * lmb_browserlist - This is our local master browser list.
39 ubi_dlNewList( lmb_browserlist
);
42 /* -------------------------------------------------------------------------- **
46 /* ************************************************************************** **
47 * Remove and free a browser list entry.
49 * Input: browc - A pointer to the entry to be removed from the list and
53 * ************************************************************************** **
55 static void remove_lmb_browser_entry( struct browse_cache_record
*browc
)
57 safe_free( (char *)ubi_dlRemThis( lmb_browserlist
, browc
) );
58 } /* remove_lmb_browser_entry */
60 /* ************************************************************************** **
61 * Update a browser death time.
63 * Input: browc - Pointer to the entry to be updated.
66 * ************************************************************************** **
68 void update_browser_death_time( struct browse_cache_record
*browc
)
70 /* Allow the new lmb to miss an announce period before we remove it. */
71 browc
->death_time
= time(NULL
) + ( (CHECK_TIME_MST_ANNOUNCE
+ 2) * 60 );
72 } /* update_browser_death_time */
74 /* ************************************************************************** **
75 * Create a browser entry and add it to the local master browser list.
81 * Output: Pointer to the new entry, or NULL if malloc() failed.
83 * ************************************************************************** **
85 struct browse_cache_record
*create_browser_in_lmb_cache( char *work_name
,
89 struct browse_cache_record
*browc
;
90 time_t now
= time( NULL
);
92 browc
= (struct browse_cache_record
*)malloc( sizeof( *browc
) );
96 DEBUG( 0, ("create_browser_in_lmb_cache: malloc fail !\n") );
100 memset( (char *)browc
, '\0', sizeof( *browc
) );
102 /* For a new lmb entry we want to sync with it after one minute. This
103 will allow it time to send out a local announce and build its
106 browc
->sync_time
= now
+ 60;
108 /* Allow the new lmb to miss an announce period before we remove it. */
109 browc
->death_time
= now
+ ( (CHECK_TIME_MST_ANNOUNCE
+ 2) * 60 );
111 StrnCpy( browc
->lmb_name
, browser_name
, sizeof(browc
->lmb_name
)-1 );
112 StrnCpy( browc
->work_group
, work_name
, sizeof(browc
->work_group
)-1 );
113 strupper( browc
->lmb_name
);
114 strupper( browc
->work_group
);
118 (void)ubi_dlAddTail( lmb_browserlist
, browc
);
122 Debug1( "nmbd_browserdb:create_browser_in_lmb_cache()\n" );
123 Debug1( " Added lmb cache entry for workgroup %s ", browc
->work_group
);
124 Debug1( "name %s IP %s ", browc
->lmb_name
, inet_ntoa(ip
) );
125 Debug1( "ttl %d\n", (int)browc
->death_time
);
129 } /* create_browser_in_lmb_cache */
131 /* ************************************************************************** **
132 * Find a browser entry in the local master browser list.
134 * Input: browser_name - The name for which to search.
136 * Output: A pointer to the matching entry, or NULL if no match was found.
138 * ************************************************************************** **
140 struct browse_cache_record
*find_browser_in_lmb_cache( char *browser_name
)
142 struct browse_cache_record
*browc
;
144 for( browc
= (struct browse_cache_record
*)ubi_dlFirst( lmb_browserlist
);
146 browc
= (struct browse_cache_record
*)ubi_dlNext( browc
) )
147 if( strequal( browser_name
, browc
->lmb_name
) )
151 } /* find_browser_in_lmb_cache */
153 /* ************************************************************************** **
154 * Expire timed out browsers in the browserlist.
156 * Input: t - Expiration time. Entries with death times less than this
157 * value will be removed from the list.
160 * ************************************************************************** **
162 void expire_lmb_browsers( time_t t
)
164 struct browse_cache_record
*browc
;
165 struct browse_cache_record
*nextbrowc
;
167 for( browc
= (struct browse_cache_record
*)ubi_dlFirst( lmb_browserlist
);
171 nextbrowc
= (struct browse_cache_record
*)ubi_dlNext( browc
);
173 if( browc
->death_time
< t
)
177 Debug1( "nmbd_browserdb:expire_lmb_browsers()\n" );
178 Debug1( " Removing timed out lmb entry %s\n", browc
->lmb_name
);
180 remove_lmb_browser_entry( browc
);
183 } /* expire_lmb_browsers */