From 5a2f52b79e28530c454cb488a44588147640f061 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 2 Oct 1996 14:09:22 +0000 Subject: - a huge pile of changes from Luke which implement the browse.conf stuff and also fix a pile of nmbd bugs. Unfortunately I found it very hard to disentangle the new features from the bug fixes so I am putting in the new code. I hope this is the last big pile of changes to the 1.9.16 series! (This used to be commit 20b6203dac4bbb43e4e7bea0b214496d76d679d9) --- source3/namedbwork.c | 133 ++++++++++++++++++++++++++------------------------- 1 file changed, 67 insertions(+), 66 deletions(-) (limited to 'source3/namedbwork.c') diff --git a/source3/namedbwork.c b/source3/namedbwork.c index 04f2103254..dd4bd88175 100644 --- a/source3/namedbwork.c +++ b/source3/namedbwork.c @@ -26,6 +26,9 @@ 04 jul 96: lkcl@pires.co.uk created module namedbwork containing workgroup database functions + 30 July 96: David.Chappell@mail.trincoll.edu + Expanded multiple workgroup domain master browser support. + */ #include "includes.h" @@ -40,9 +43,7 @@ extern struct subnet_record *subnetlist; extern struct in_addr ipgrp; -int workgroup_count = 0; /* unique index key: one for each workgroup */ - - +extern pstring myname; /**************************************************************************** add a workgroup into the domain list @@ -75,11 +76,17 @@ static void add_workgroup(struct work_record *work, struct subnet_record *d) static struct work_record *make_workgroup(char *name) { struct work_record *work; - struct subnet_record *d; int t = -1; if (!name || !name[0]) return NULL; + /* conf_workgroup_name_to_token() gets or creates a unique index for the workgroup name */ + if ((t = conf_workgroup_name_to_token(name, myname)) == -1) + { + DEBUG(3, ("work_record(\"%s\"): conf_workgroup_name_to_token() refuses to allow workgroup\n", name)); + return (struct work_record *)NULL; + } + work = (struct work_record *)malloc(sizeof(*work)); if (!work) return(NULL); @@ -92,34 +99,16 @@ static struct work_record *make_workgroup(char *name) work->needelection = False; work->needannounce = True; work->state = MST_NONE; - - /* make sure all token representations of workgroups are unique */ - - for (d = subnetlist; d && t == -1; d = d->next) - { - struct work_record *w; - for (w = d->workgrouplist; w && t == -1; w = w->next) - { - if (strequal(w->work_group, work->work_group)) t = w->token; - } - } - - if (t == -1) - { - work->token = ++workgroup_count; - } - else - { - work->token = t; - } - + work->token = t; /* WfWg uses 01040b01 */ /* Win95 uses 01041501 */ /* NTAS uses ???????? */ work->ElectionCriterion = (MAINTAIN_LIST<<1)|(ELECTION_VERSION<<8); work->ElectionCriterion |= (lp_os_level() << 24); - if (lp_domain_master()) { + + if (conf_should_domain_master(work->token)) + { work->ElectionCriterion |= 0x80; } @@ -131,8 +120,8 @@ static struct work_record *make_workgroup(char *name) remove workgroups ******************************************************************/ struct work_record *remove_workgroup(struct subnet_record *d, - struct work_record *work, - BOOL remove_all_servers) + struct work_record *work, + BOOL remove_all_servers) { struct work_record *ret_work = NULL; @@ -165,7 +154,7 @@ struct work_record *remove_workgroup(struct subnet_record *d, lmhosts file to be added. **************************************************************************/ struct work_record *find_workgroupstruct(struct subnet_record *d, - fstring name, BOOL add) + fstring name, BOOL add) { struct work_record *ret, *work; @@ -174,39 +163,51 @@ struct work_record *find_workgroupstruct(struct subnet_record *d, DEBUG(4, ("workgroup search for %s: ", name)); if (strequal(name, "*")) - { + { +#if 0 /* XXXX this is being called too many times */ + DEBUG(2,("add any workgroups: initiating browser search on %s\n", - inet_ntoa(d->bcast_ip))); + inet_ntoa(d->bcast_ip))); queue_netbios_pkt_wins(d,ClientNMB,NMB_QUERY, NAME_QUERY_FIND_MST, - MSBROWSE,0x1,0,0,0,NULL,NULL, - True,False, d->bcast_ip, d->bcast_ip); + -1,MSBROWSE,0x1,0,0,0,0,NULL,NULL, + True,False, d->bcast_ip, d->bcast_ip); + +#endif return NULL; - } + } - for (ret = d->workgrouplist; ret; ret = ret->next) { - if (!strcmp(ret->work_group,name)) { + for (ret = d->workgrouplist; ret; ret = ret->next) + { + if (!strcmp(ret->work_group,name)) + { DEBUG(4, ("found\n")); return(ret); } } - if (!add) { + if (!add) + { DEBUG(4, ("not found\n")); return NULL; } DEBUG(4,("not found: creating\n")); - if ((work = make_workgroup(name))) + if ((work = make_workgroup(name)) != NULL) + { + DEBUG(4,("bcast_ip:%s preferred master=%s local_master=%s\n", + inet_ntoa(d->bcast_ip), + BOOLSTR(conf_should_preferred_master(work->token)), + BOOLSTR(conf_should_local_master(work->token)) )); + + if (!ip_equal(d->bcast_ip, ipgrp) && + conf_should_preferred_master(work->token) && + conf_should_local_master (work->token)) { - if (!ip_equal(d->bcast_ip, ipgrp) && - lp_preferred_master() && - strequal(lp_workgroup(), name)) - { - DEBUG(3, ("preferred master startup for %s\n", work->work_group)); - work->needelection = True; - work->ElectionCriterion |= (1<<3); - } + DEBUG(3, ("preferred master startup for %s\n", work->work_group)); + work->needelection = True; + work->ElectionCriterion |= (1<<3); + } add_workgroup(work, d); return(work); } @@ -224,25 +225,25 @@ void dump_workgroups(void) for (d = subnetlist; d; d = d->next) { if (d->workgrouplist) - { - struct work_record *work; - - DEBUG(4,("dump domain bcast=%15s: ", inet_ntoa(d->bcast_ip))); - DEBUG(4,(" netmask=%15s:\n", inet_ntoa(d->mask_ip))); - - for (work = d->workgrouplist; work; work = work->next) - { - DEBUG(4,("\t%s(%d)\n", work->work_group, work->token)); - if (work->serverlist) - { - struct server_record *s; - for (s = work->serverlist; s; s = s->next) - { - DEBUG(4,("\t\t%s %8x (%s)\n", - s->serv.name, s->serv.type, s->serv.comment)); - } - } - } - } + { + struct work_record *work; + + DEBUG(4,("dump domain bcast=%15s: ", inet_ntoa(d->bcast_ip))); + DEBUG(4,(" netmask=%15s:\n", inet_ntoa(d->mask_ip))); + + for (work = d->workgrouplist; work; work = work->next) + { + DEBUG(4,("\t%s(%d)\n", work->work_group, work->token)); + if (work->serverlist) + { + struct server_record *s; + for (s = work->serverlist; s; s = s->next) + { + DEBUG(4,("\t\t%s %8x (%s)\n", + s->serv.name, s->serv.type, s->serv.comment)); + } + } + } + } } } -- cgit