diff options
Diffstat (limited to 'source3/namedbwork.c')
-rw-r--r-- | source3/namedbwork.c | 133 |
1 files changed, 66 insertions, 67 deletions
diff --git a/source3/namedbwork.c b/source3/namedbwork.c index dd4bd88175..04f2103254 100644 --- a/source3/namedbwork.c +++ b/source3/namedbwork.c @@ -26,9 +26,6 @@ 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" @@ -43,7 +40,9 @@ extern struct subnet_record *subnetlist; extern struct in_addr ipgrp; -extern pstring myname; +int workgroup_count = 0; /* unique index key: one for each workgroup */ + + /**************************************************************************** add a workgroup into the domain list @@ -76,17 +75,11 @@ 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); @@ -99,16 +92,34 @@ static struct work_record *make_workgroup(char *name) work->needelection = False; work->needannounce = True; work->state = MST_NONE; - work->token = t; + + /* 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; + } + /* WfWg uses 01040b01 */ /* Win95 uses 01041501 */ /* NTAS uses ???????? */ work->ElectionCriterion = (MAINTAIN_LIST<<1)|(ELECTION_VERSION<<8); work->ElectionCriterion |= (lp_os_level() << 24); - - if (conf_should_domain_master(work->token)) - { + if (lp_domain_master()) { work->ElectionCriterion |= 0x80; } @@ -120,8 +131,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; @@ -154,7 +165,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; @@ -163,51 +174,39 @@ 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, - -1,MSBROWSE,0x1,0,0,0,0,NULL,NULL, - True,False, d->bcast_ip, d->bcast_ip); - -#endif + MSBROWSE,0x1,0,0,0,NULL,NULL, + True,False, d->bcast_ip, d->bcast_ip); 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)) != 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 ((work = make_workgroup(name))) { - DEBUG(3, ("preferred master startup for %s\n", work->work_group)); - work->needelection = True; - work->ElectionCriterion |= (1<<3); - } + 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); + } add_workgroup(work, d); return(work); } @@ -225,25 +224,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)); + } + } + } + } } } |