fixed error check which caused domain logons to fail
[Samba.git] / source / nmbd / nmbd_browserdb.c
blob5b08207556a18e76803e24288e1de9419c90d3ed
1 /*
2 Unix SMB/Netbios implementation.
3 Version 1.9.
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.
31 #include "includes.h"
33 /* -------------------------------------------------------------------------- **
34 * Variables...
36 * lmb_browserlist - This is our local master browser list.
39 ubi_dlNewList( lmb_browserlist );
42 /* -------------------------------------------------------------------------- **
43 * Functions...
46 /* ************************************************************************** **
47 * Remove and free a browser list entry.
49 * Input: browc - A pointer to the entry to be removed from the list and
50 * freed.
51 * Output: none.
53 * ************************************************************************** **
55 static void remove_lmb_browser_entry( struct browse_cache_record *browc )
57 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.
64 * Output: none.
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.
77 * Input: work_name
78 * browser_name
79 * ip
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,
86 char *browser_name,
87 struct in_addr ip )
89 struct browse_cache_record *browc;
90 time_t now = time( NULL );
92 browc = (struct browse_cache_record *)malloc( sizeof( *browc ) );
94 if( NULL == browc )
96 DEBUG( 0, ("create_browser_in_lmb_cache: malloc fail !\n") );
97 return( NULL );
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
104 browse list.
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 );
116 browc->ip = ip;
118 (void)ubi_dlAddTail( lmb_browserlist, browc );
120 if( DEBUGLVL( 3 ) )
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 );
128 return( browc );
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 );
145 browc;
146 browc = (struct browse_cache_record *)ubi_dlNext( browc ) )
147 if( strequal( browser_name, browc->lmb_name ) )
148 break;
150 return( browc );
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.
158 * Output: none.
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 );
168 browc;
169 browc = nextbrowc )
171 nextbrowc = (struct browse_cache_record *)ubi_dlNext( browc );
173 if( browc->death_time < t )
175 if( DEBUGLVL( 3 ) )
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 */