sync with the sec_desc parsing fix from APP_HEAD. I will probably need
[Samba.git] / source / nmbd / nmbd_browserdb.c
bloba4ef98e265e1bb2c36227e404c96e35782a40f16
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
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.
24 /* -------------------------------------------------------------------------- **
25 * Modified July 1998 by CRH.
26 * I converted this module to use the canned doubly-linked lists. I also
27 * added comments above the functions where possible.
30 #include "includes.h"
32 /* -------------------------------------------------------------------------- **
33 * Variables...
35 * lmb_browserlist - This is our local master browser list.
38 ubi_dlNewList( lmb_browserlist );
41 /* -------------------------------------------------------------------------- **
42 * Functions...
45 /* ************************************************************************** **
46 * Remove and free a browser list entry.
48 * Input: browc - A pointer to the entry to be removed from the list and
49 * freed.
50 * Output: none.
52 * ************************************************************************** **
54 static void remove_lmb_browser_entry( struct browse_cache_record *browc )
56 safe_free( ubi_dlRemThis( lmb_browserlist, browc ) );
57 } /* remove_lmb_browser_entry */
59 /* ************************************************************************** **
60 * Update a browser death time.
62 * Input: browc - Pointer to the entry to be updated.
63 * Output: none.
65 * ************************************************************************** **
67 void update_browser_death_time( struct browse_cache_record *browc )
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 } /* update_browser_death_time */
73 /* ************************************************************************** **
74 * Create a browser entry and add it to the local master browser list.
76 * Input: work_name
77 * browser_name
78 * ip
80 * Output: Pointer to the new entry, or NULL if malloc() failed.
82 * ************************************************************************** **
84 struct browse_cache_record *create_browser_in_lmb_cache( char *work_name,
85 char *browser_name,
86 struct in_addr ip )
88 struct browse_cache_record *browc;
89 time_t now = time( NULL );
91 browc = (struct browse_cache_record *)malloc( sizeof( *browc ) );
93 if( NULL == browc )
95 DEBUG( 0, ("create_browser_in_lmb_cache: malloc fail !\n") );
96 return( NULL );
99 memset( (char *)browc, '\0', sizeof( *browc ) );
101 /* For a new lmb entry we want to sync with it after one minute. This
102 will allow it time to send out a local announce and build its
103 browse list.
105 browc->sync_time = now + 60;
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 );
110 StrnCpy( browc->lmb_name, browser_name, sizeof(browc->lmb_name)-1 );
111 StrnCpy( browc->work_group, work_name, sizeof(browc->work_group)-1 );
112 strupper( browc->lmb_name );
113 strupper( browc->work_group );
115 browc->ip = ip;
117 (void)ubi_dlAddTail( lmb_browserlist, browc );
119 if( DEBUGLVL( 3 ) )
121 Debug1( "nmbd_browserdb:create_browser_in_lmb_cache()\n" );
122 Debug1( " Added lmb cache entry for workgroup %s ", browc->work_group );
123 Debug1( "name %s IP %s ", browc->lmb_name, inet_ntoa(ip) );
124 Debug1( "ttl %d\n", (int)browc->death_time );
127 return( browc );
128 } /* create_browser_in_lmb_cache */
130 /* ************************************************************************** **
131 * Find a browser entry in the local master browser list.
133 * Input: browser_name - The name for which to search.
135 * Output: A pointer to the matching entry, or NULL if no match was found.
137 * ************************************************************************** **
139 struct browse_cache_record *find_browser_in_lmb_cache( char *browser_name )
141 struct browse_cache_record *browc;
143 for( browc = (struct browse_cache_record *)ubi_dlFirst( lmb_browserlist );
144 browc;
145 browc = (struct browse_cache_record *)ubi_dlNext( browc ) )
146 if( strequal( browser_name, browc->lmb_name ) )
147 break;
149 return( browc );
150 } /* find_browser_in_lmb_cache */
152 /* ************************************************************************** **
153 * Expire timed out browsers in the browserlist.
155 * Input: t - Expiration time. Entries with death times less than this
156 * value will be removed from the list.
157 * Output: none.
159 * ************************************************************************** **
161 void expire_lmb_browsers( time_t t )
163 struct browse_cache_record *browc;
164 struct browse_cache_record *nextbrowc;
166 for( browc = (struct browse_cache_record *)ubi_dlFirst( lmb_browserlist );
167 browc;
168 browc = nextbrowc )
170 nextbrowc = (struct browse_cache_record *)ubi_dlNext( browc );
172 if( browc->death_time < t )
174 if( DEBUGLVL( 3 ) )
176 Debug1( "nmbd_browserdb:expire_lmb_browsers()\n" );
177 Debug1( " Removing timed out lmb entry %s\n", browc->lmb_name );
179 remove_lmb_browser_entry( browc );
182 } /* expire_lmb_browsers */