source: vendor/current/source3/nmbd/nmbd_browserdb.c

Last change on this file was 988, checked in by Silvan Scherrer, 9 years ago

Samba Server: update vendor to version 4.4.3

File size: 5.6 KB
Line 
1/*
2 Unix SMB/CIFS implementation.
3 NBT netbios routines and daemon - version 2
4 Copyright (C) Andrew Tridgell 1994-1998
5 Copyright (C) Luke Kenneth Casson Leighton 1994-1998
6 Copyright (C) Jeremy Allison 1994-1998
7 Copyright (C) Christopher R. Hertel 1998
8
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 3 of the License, or
12 (at your option) any later version.
13
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.
18
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
21
22*/
23/* -------------------------------------------------------------------------- **
24 * Modified July 1998 by CRH.
25 * I converted this module to use the canned doubly-linked lists. I also
26 * added comments above the functions where possible.
27 */
28
29#include "includes.h"
30#include "nmbd/nmbd.h"
31
32/* -------------------------------------------------------------------------- **
33 * Variables...
34 *
35 * lmb_browserlist - This is our local master browser list.
36 */
37
38struct browse_cache_record *lmb_browserlist;
39
40/* -------------------------------------------------------------------------- **
41 * Functions...
42 */
43
44/* ************************************************************************** **
45 * Remove and free a browser list entry.
46 *
47 * Input: browc - A pointer to the entry to be removed from the list and
48 * freed.
49 * Output: none.
50 *
51 * ************************************************************************** **
52 */
53static void remove_lmb_browser_entry( struct browse_cache_record *browc )
54{
55 DLIST_REMOVE(lmb_browserlist, browc);
56 SAFE_FREE(browc);
57}
58
59/* ************************************************************************** **
60 * Update a browser death time.
61 *
62 * Input: browc - Pointer to the entry to be updated.
63 * Output: none.
64 *
65 * ************************************************************************** **
66 */
67void update_browser_death_time( struct browse_cache_record *browc )
68{
69 /* Allow the new lmb to miss an announce period before we remove it. */
70 browc->death_time = time(NULL) + ( (CHECK_TIME_MST_ANNOUNCE + 2) * 60 );
71}
72
73/* ************************************************************************** **
74 * Create a browser entry and add it to the local master browser list.
75 *
76 * Input: work_name
77 * browser_name
78 * ip
79 *
80 * Output: Pointer to the new entry, or NULL if malloc() failed.
81 *
82 * ************************************************************************** **
83 */
84struct browse_cache_record *create_browser_in_lmb_cache( const char *work_name,
85 const char *browser_name,
86 struct in_addr ip )
87{
88 struct browse_cache_record *browc;
89 time_t now = time( NULL );
90
91 browc = SMB_MALLOC_P(struct browse_cache_record);
92
93 if( NULL == browc ) {
94 DEBUG( 0, ("create_browser_in_lmb_cache: malloc fail !\n") );
95 return( NULL );
96 }
97
98 memset( (char *)browc, '\0', sizeof( *browc ) );
99
100 /* For a new lmb entry we want to sync with it after one minute. This
101 will allow it time to send out a local announce and build its
102 browse list.
103 */
104
105 browc->sync_time = now + 60;
106
107 /* Allow the new lmb to miss an announce period before we remove it. */
108 browc->death_time = now + ( (CHECK_TIME_MST_ANNOUNCE + 2) * 60 );
109
110 unstrcpy( browc->lmb_name, browser_name);
111 unstrcpy( browc->work_group, work_name);
112 if (!strupper_m( browc->lmb_name )) {
113 SAFE_FREE(browc);
114 return NULL;
115 }
116 if (!strupper_m( browc->work_group )) {
117 SAFE_FREE(browc);
118 return NULL;
119 }
120
121 browc->ip = ip;
122
123 DLIST_ADD_END(lmb_browserlist, browc);
124
125 DEBUG(3, ("nmbd_browserdb:create_browser_in_lmb_cache()\n"));
126 DEBUGADD(3, (" Added lmb cache entry for workgroup %s name %s IP %s "
127 "ttl %d\n", browc->work_group, browc->lmb_name,
128 inet_ntoa(ip), (int)browc->death_time));
129
130 return( browc );
131}
132
133/* ************************************************************************** **
134 * Find a browser entry in the local master browser list.
135 *
136 * Input: browser_name - The name for which to search.
137 *
138 * Output: A pointer to the matching entry, or NULL if no match was found.
139 *
140 * ************************************************************************** **
141 */
142struct browse_cache_record *find_browser_in_lmb_cache( const char *browser_name )
143{
144 struct browse_cache_record *browc;
145
146 for( browc = lmb_browserlist; browc; browc = browc->next ) {
147 if( strequal( browser_name, browc->lmb_name ) ) {
148 break;
149 }
150 }
151
152 return browc;
153}
154
155/* ************************************************************************** **
156 * Expire timed out browsers in the browserlist.
157 *
158 * Input: t - Expiration time. Entries with death times less than this
159 * value will be removed from the list.
160 * Output: none.
161 *
162 * ************************************************************************** **
163 */
164void expire_lmb_browsers( time_t t )
165{
166 struct browse_cache_record *browc;
167 struct browse_cache_record *nextbrowc;
168
169 for( browc = lmb_browserlist; browc; browc = nextbrowc) {
170 nextbrowc = browc->next;
171
172 if( browc->death_time < t ) {
173 DEBUG(3, ("nmbd_browserdb:expire_lmb_browsers()\n"));
174 DEBUGADD(3, (" Removing timed out lmb entry %s\n",
175 browc->lmb_name));
176 remove_lmb_browser_entry( browc );
177 }
178 }
179}
Note: See TracBrowser for help on using the repository browser.