2 Unix SMB/Netbios implementation.
4 NBT netbios routines and daemon - version 2
5 Copyright (C) Andrew Tridgell 1994-1996
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 14 jan 96: lkcl@pires.co.uk
24 added multiple workgroup domain master support
26 04 jul 96: lkcl@pires.co.uk
27 created module namedbserver containing server database functions
35 extern int ClientDGRAM
;
37 extern int DEBUGLEVEL
;
39 extern pstring myname
;
41 /* this is our domain/workgroup/server database */
42 extern struct subnet_record
*subnetlist
;
44 extern BOOL updatedlists
;
47 /*******************************************************************
48 expire old servers in the serverlist
49 time of -1 indicates everybody dies except those with time of 0
50 remove_all_servers indicates everybody dies.
51 ******************************************************************/
52 void remove_old_servers(struct work_record
*work
, time_t t
,
55 struct server_record
*s
;
56 struct server_record
*nexts
;
58 /* expire old entries in the serverlist */
59 for (s
= work
->serverlist
; s
; s
= nexts
)
61 if (remove_all
|| (s
->death_time
&& (t
== -1 || s
->death_time
< t
)))
63 DEBUG(3,("Removing dead server %s\n",s
->serv
.name
));
67 if (s
->prev
) s
->prev
->next
= s
->next
;
68 if (s
->next
) s
->next
->prev
= s
->prev
;
70 if (work
->serverlist
== s
)
71 work
->serverlist
= s
->next
;
83 /***************************************************************************
84 add a server into the list
85 **************************************************************************/
86 static void add_server(struct work_record
*work
,struct server_record
*s
)
88 struct server_record
*s2
;
90 if (!work
->serverlist
) {
97 for (s2
= work
->serverlist
; s2
->next
; s2
= s2
->next
) ;
105 /****************************************************************************
107 ****************************************************************************/
108 struct server_record
*add_server_entry(struct subnet_record
*d
,
109 struct work_record
*work
,
110 char *name
,int servertype
,
111 int ttl
,char *comment
,
115 struct server_record
*s
;
122 for (s
= work
->serverlist
; s
; s
= s
->next
)
124 if (strequal(name
,s
->serv
.name
)) break;
129 DEBUG(4,("Not replacing %s\n",name
));
133 if (!s
|| s
->serv
.type
!= servertype
|| !strequal(s
->serv
.comment
, comment
))
139 s
= (struct server_record
*)malloc(sizeof(*s
));
141 if (!s
) return(NULL
);
143 bzero((char *)s
,sizeof(*s
));
147 if (d
->my_interface
&& strequal(lp_workgroup(),work
->work_group
))
150 servertype
|= SV_TYPE_LOCAL_LIST_ONLY
;
154 servertype
&= ~SV_TYPE_LOCAL_LIST_ONLY
;
157 /* update the entry */
158 StrnCpy(s
->serv
.name
,name
,sizeof(s
->serv
.name
)-1);
159 StrnCpy(s
->serv
.comment
,comment
,sizeof(s
->serv
.comment
)-1);
160 strupper(s
->serv
.name
);
161 s
->serv
.type
= servertype
;
162 s
->death_time
= servertype
? (ttl
?time(NULL
)+ttl
*3:0) : (time(NULL
)-1);
164 /* for a domain entry, the comment field refers to the server name */
166 if (s
->serv
.type
& SV_TYPE_DOMAIN_ENUM
) strupper(s
->serv
.comment
);
176 DEBUG(3,("Updated "));
179 DEBUG(3,("server entry %s of type %x (%s) to %s %s\n",
180 name
,servertype
,comment
,
181 work
->work_group
,inet_ntoa(d
->bcast_ip
)));
187 /*******************************************************************
188 expire old servers in the serverlist
189 ******************************************************************/
190 void expire_servers(time_t t
)
192 struct subnet_record
*d
;
194 for (d
= subnetlist
; d
; d
= d
->next
)
196 struct work_record
*work
;
198 for (work
= d
->workgrouplist
; work
; work
= work
->next
)
200 remove_old_servers(work
, t
, False
);