2 Unix SMB/Netbios implementation.
4 NBT netbios routines and daemon - version 2
5 Copyright (C) Andrew Tridgell 1994-1997
6 Copyright (C) Luke Kenneth Casson Leighton 1994-1997
7 Copyright (C) Jeremy Allison 1994-1997
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 extern int DEBUGLEVEL;
30 /* This is our local master browser list database. */
31 struct browse_cache_record *lmb_browserlist = NULL;
33 /***************************************************************************
34 Add a browser into the lmb list.
35 **************************************************************************/
37 static void add_to_lmb_browse_cache(struct browse_cache_record *browc)
39 struct browse_cache_record *browc2;
41 if (lmb_browserlist == NULL)
43 lmb_browserlist = browc;
49 for (browc2 = lmb_browserlist; browc2->next; browc2 = browc2->next)
57 /*******************************************************************
58 Remove a lmb browser entry.
59 ******************************************************************/
61 void remove_lmb_browser_entry(struct browse_cache_record *browc)
64 browc->prev->next = browc->next;
66 browc->next->prev = browc->prev;
68 if (lmb_browserlist == browc)
69 lmb_browserlist = browc->next;
74 /****************************************************************************
75 Update a browser death time.
76 ****************************************************************************/
78 void update_browser_death_time(struct browse_cache_record *browc)
80 /* Allow the new lmb to miss an announce period before we remove it. */
81 browc->death_time = time(NULL) + (CHECK_TIME_MST_ANNOUNCE + 2)*60;
84 /****************************************************************************
85 Create a browser entry.
86 ****************************************************************************/
88 struct browse_cache_record *create_browser_in_lmb_cache(char *work_name, char *browser_name,
91 struct browse_cache_record *browc;
92 time_t now = time(NULL);
94 browc = (struct browse_cache_record *)malloc(sizeof(*browc));
98 DEBUG(0,("create_browser_in_lmb_cache: malloc fail !\n"));
102 bzero((char *)browc,sizeof(*browc));
104 /* For a new lmb entry we want to sync with it after one minute. This
105 will allow it time to send out a local announce and build its
108 browc->sync_time = now + 60;
110 /* Allow the new lmb to miss an announce period before we remove it. */
111 browc->death_time = now + (CHECK_TIME_MST_ANNOUNCE + 2)*60;
113 StrnCpy(browc->lmb_name, browser_name,sizeof(browc->lmb_name)-1);
114 StrnCpy(browc->work_group,work_name,sizeof(browc->work_group)-1);
115 strupper(browc->lmb_name);
116 strupper(browc->work_group);
120 add_to_lmb_browse_cache(browc);
122 DEBUG(3,("create_browser_in_lmb_cache: Added lmb cache entry for workgroup %s name %s IP %s ttl %d\n",
123 browc->work_group, browc->lmb_name, inet_ntoa(ip), browc->death_time));
128 /****************************************************************************
129 Find a browser entry.
130 ****************************************************************************/
132 struct browse_cache_record *find_browser_in_lmb_cache( char *browser_name )
134 struct browse_cache_record *browc = NULL;
136 for( browc = lmb_browserlist; browc; browc = browc->next)
137 if(strequal( browser_name, browc->lmb_name))
143 /*******************************************************************
144 Expire timed out browsers in the browserlist.
145 ******************************************************************/
147 void expire_lmb_browsers(time_t t)
149 struct browse_cache_record *browc;
150 struct browse_cache_record *nextbrowc;
152 for (browc = lmb_browserlist; browc; browc = nextbrowc)
154 nextbrowc = browc->next;
156 if (browc->death_time < t)
158 DEBUG(3,("expire_lmb_browsers: Removing timed out lmb entry %s\n",browc->lmb_name));
159 remove_lmb_browser_entry(browc);
164 /*******************************************************************
165 Remove browsers from a named workgroup in the browserlist.
166 ******************************************************************/
168 void remove_workgroup_lmb_browsers(char *work_group)
170 struct browse_cache_record *browc;
171 struct browse_cache_record *nextbrowc;
173 for (browc = lmb_browserlist; browc; browc = nextbrowc)
175 nextbrowc = browc->next;
177 if (strequal(work_group, browc->work_group))
179 DEBUG(3,("remove_workgroup_browsers: Removing lmb entry %s\n",browc->lmb_name));
180 remove_lmb_browser_entry(browc);