This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
+ the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "includes.h"
-extern int ClientNMB;
-
int updatecount = 0;
/*******************************************************************
for (servrec = work->serverlist; servrec; servrec = nexts) {
DEBUG(7,("remove_all_servers: Removing server %s\n",servrec->serv.name));
nexts = servrec->next;
-
- if (servrec->prev)
- servrec->prev->next = servrec->next;
- if (servrec->next)
- servrec->next->prev = servrec->prev;
-
- if (work->serverlist == servrec)
- work->serverlist = servrec->next;
-
+ DLIST_REMOVE(work->serverlist, servrec);
ZERO_STRUCTP(servrec);
SAFE_FREE(servrec);
}
static void add_server_to_workgroup(struct work_record *work,
struct server_record *servrec)
{
- struct server_record *servrec2;
-
- if (!work->serverlist) {
- work->serverlist = servrec;
- servrec->prev = NULL;
- servrec->next = NULL;
- return;
- }
-
- for (servrec2 = work->serverlist; servrec2->next; servrec2 = servrec2->next)
- ;
-
- servrec2->next = servrec;
- servrec->next = NULL;
- servrec->prev = servrec2;
+ DLIST_ADD_END(work->serverlist, servrec, struct server_record *);
work->subnet->work_changed = True;
}
void remove_server_from_workgroup(struct work_record *work, struct server_record *servrec)
{
- if (servrec->prev)
- servrec->prev->next = servrec->next;
- if (servrec->next)
- servrec->next->prev = servrec->prev;
-
- if (work->serverlist == servrec)
- work->serverlist = servrec->next;
-
+ DLIST_REMOVE(work->serverlist, servrec);
ZERO_STRUCTP(servrec);
SAFE_FREE(servrec);
work->subnet->work_changed = True;
return (NULL);
}
- if((servrec = find_server_in_workgroup(work, name)) != NULL) {
+ if(find_server_in_workgroup(work, name) != NULL) {
DEBUG(0,("create_server_on_workgroup: Server %s already exists on \
workgroup %s. This is a bug.\n", name, work->work_group));
return NULL;
}
- if((servrec = (struct server_record *)malloc(sizeof(*servrec))) == NULL) {
+ if((servrec = SMB_MALLOC_P(struct server_record)) == NULL) {
DEBUG(0,("create_server_entry_on_workgroup: malloc fail !\n"));
return NULL;
}
struct work_record *iwork;
/* Go through all the subnets we have already seen. */
- for (ssub = FIRST_SUBNET; ssub != subrec; ssub = NEXT_SUBNET_INCLUDING_UNICAST(ssub)) {
+ for (ssub = FIRST_SUBNET; ssub && (ssub != subrec); ssub = NEXT_SUBNET_INCLUDING_UNICAST(ssub)) {
for(iwork = ssub->workgrouplist; iwork; iwork = iwork->next) {
if(find_server_in_workgroup( iwork, servrec->serv.name) != NULL) {
/*
x_fprintf(fp, "\"%s\"\n", description);
}
-void write_browse_list(time_t t, BOOL force_write)
-{
+void write_browse_list(time_t t, bool force_write)
+{
struct subnet_record *subrec;
struct work_record *work;
struct server_record *servrec;
- pstring fname,fnamenew;
+ char *fname;
+ char *fnamenew;
uint32 stype;
int i;
XFILE *fp;
- BOOL list_changed = force_write;
+ bool list_changed = force_write;
static time_t lasttime = 0;
-
+ TALLOC_CTX *ctx = talloc_tos();
+
/* Always dump if we're being told to by a signal. */
if(force_write == False) {
if (!lasttime)
lasttime = t;
dump_workgroups(force_write);
-
+
for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) {
if(subrec->work_changed) {
list_changed = True;
return;
updatecount++;
-
- pstrcpy(fname,lp_lockdir());
- trim_string(fname,NULL,"/");
- pstrcat(fname,"/");
- pstrcat(fname,SERVER_LIST);
- pstrcpy(fnamenew,fname);
- pstrcat(fnamenew,".");
-
+
+ fname = cache_path(SERVER_LIST);
+ if (!fname) {
+ return;
+ }
+ fnamenew = talloc_asprintf(ctx, "%s.",
+ fname);
+ if (!fnamenew) {
+ return;
+ }
+
fp = x_fopen(fnamenew,O_WRONLY|O_CREAT|O_TRUNC, 0644);
-
+
if (!fp) {
DEBUG(0,("write_browse_list: Can't open file %s. Error was %s\n",
fnamenew,strerror(errno)));
return;
- }
-
+ }
+
/*
* Write out a record for our workgroup. Use the record from the first
* subnet.
SV_TYPE_DOMAIN_ENUM|SV_TYPE_NT|SV_TYPE_LOCAL_LIST_ONLY,
work->local_master_browser_name, work->work_group);
- /*
+ /*
* We need to do something special for our own names.
* This is due to the fact that we may be a local master browser on
* one of our broadcast subnets, and a domain master on the unicast
write_browse_list_entry(fp, my_netbios_names(i), stype,
string_truncate(lp_serverstring(), MAX_SERVER_STRING_LENGTH), lp_workgroup());
}
-
+
for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) {
subrec->work_changed = False;
/* We have already written our names here. */
if(is_myname(servrec->serv.name))
- continue;
+ continue;
serv_type = write_this_server_name(subrec, work, servrec);
if(serv_type) {
}
}
}
- }
-
+ }
+
x_fclose(fp);
unlink(fname);
chmod(fnamenew,0644);