diff options
Diffstat (limited to 'source3')
-rw-r--r-- | source3/include/proto.h | 3 | ||||
-rw-r--r-- | source3/nmbd/nmbd_elections.c | 2 | ||||
-rw-r--r-- | source3/nmbd/nmbd_incomingdgrams.c | 139 | ||||
-rw-r--r-- | source3/nmbd/nmbd_serverlistdb.c | 18 | ||||
-rw-r--r-- | source3/nmbd/nmbd_workgroupdb.c | 13 |
5 files changed, 118 insertions, 57 deletions
diff --git a/source3/include/proto.h b/source3/include/proto.h index df9c146cd9..7c2966b64f 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -724,6 +724,7 @@ void browse_sync_remote(time_t t); void remove_all_servers(struct work_record *work); struct server_record *find_server_in_workgroup(struct work_record *work, char *name); +void remove_server_from_workgroup(struct work_record *work, struct server_record *servrec); struct server_record *create_server_on_workgroup(struct work_record *work, char *name,int servertype, int ttl,char *comment); @@ -770,7 +771,7 @@ struct work_record *create_workgroup_on_subnet(struct subnet_record *subrec, fstring name, int ttl); void update_workgroup_ttl(struct work_record *work, int ttl); void initiate_myworkgroup_startup(struct subnet_record *subrec, struct work_record *work); -void dump_workgroups(void); +void dump_workgroups(BOOL force_write); void expire_workgroups_and_servers(time_t t); /*The following definitions come from nmblib.c */ diff --git a/source3/nmbd/nmbd_elections.c b/source3/nmbd/nmbd_elections.c index 5c3c4c7a01..8081de8382 100644 --- a/source3/nmbd/nmbd_elections.c +++ b/source3/nmbd/nmbd_elections.c @@ -141,7 +141,7 @@ void check_master_browser_exists(time_t t) lastrun = t; - dump_workgroups(); + dump_workgroups(False); for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) { diff --git a/source3/nmbd/nmbd_incomingdgrams.c b/source3/nmbd/nmbd_incomingdgrams.c index 7133d5ebfb..2396c847a3 100644 --- a/source3/nmbd/nmbd_incomingdgrams.c +++ b/source3/nmbd/nmbd_incomingdgrams.c @@ -153,28 +153,45 @@ void process_host_announce(struct subnet_record *subrec, struct packet_struct *p * announce instead ? JRA. */ - if ((work = find_workgroup_on_subnet(subrec, work_name))==NULL) + work = find_workgroup_on_subnet(subrec, work_name); + + if(servertype != 0) { - /* We have no record of this workgroup. Add it. */ - if((work = create_workgroup_on_subnet(subrec, work_name, ttl))==NULL) - return; - } + if (work ==NULL ) + { + /* We have no record of this workgroup. Add it. */ + if((work = create_workgroup_on_subnet(subrec, work_name, ttl))==NULL) + return; + } - if((servrec = find_server_in_workgroup( work, announce_name))==NULL) - { - /* If this server is not already in the workgroup, add it. */ - create_server_on_workgroup(work, announce_name, - servertype|SV_TYPE_LOCAL_LIST_ONLY, - ttl, comment); + if((servrec = find_server_in_workgroup( work, announce_name))==NULL) + { + /* If this server is not already in the workgroup, add it. */ + create_server_on_workgroup(work, announce_name, + servertype|SV_TYPE_LOCAL_LIST_ONLY, + ttl, comment); + } + else + { + /* Update the record. */ + servrec->serv.type = servertype|SV_TYPE_LOCAL_LIST_ONLY; + update_server_ttl( servrec, ttl); + StrnCpy(servrec->serv.comment,comment,sizeof(servrec->serv.comment)-1); + } } else { - /* Update the record. */ - servrec->serv.type = servertype|SV_TYPE_LOCAL_LIST_ONLY; - update_server_ttl( servrec, ttl); - StrnCpy(servrec->serv.comment,comment,sizeof(servrec->serv.comment)-1); + /* + * This server is announcing it is going down. Remove it from the + * workgroup. + */ + if(!is_myname(announce_name) && (work != NULL) && + ((servrec = find_server_in_workgroup( work, announce_name))!=NULL) + ) + { + remove_server_from_workgroup( work, servrec); + } } - subrec->work_changed = True; } @@ -272,6 +289,10 @@ void process_local_master_announce(struct subnet_record *subrec, struct packet_s if ((work = find_workgroup_on_subnet(subrec, work_name))==NULL) { + /* Don't bother adding if it's a local master release announce. */ + if(servertype == 0) + return; + /* We have no record of this workgroup. Add it. */ if((work = create_workgroup_on_subnet(subrec, work_name, ttl))==NULL) return; @@ -308,23 +329,39 @@ a local master browser for workgroup %s and we think we are master. Forcing elec /* Find the server record on this workgroup. If it doesn't exist, add it. */ - if((servrec = find_server_in_workgroup( work, server_name))==NULL) + if(servertype != 0) { - /* If this server is not already in the workgroup, add it. */ - create_server_on_workgroup(work, server_name, - servertype|SV_TYPE_LOCAL_LIST_ONLY, - ttl, comment); + if((servrec = find_server_in_workgroup( work, server_name))==NULL) + { + /* If this server is not already in the workgroup, add it. */ + create_server_on_workgroup(work, server_name, + servertype|SV_TYPE_LOCAL_LIST_ONLY, + ttl, comment); + } + else + { + /* Update the record. */ + servrec->serv.type = servertype|SV_TYPE_LOCAL_LIST_ONLY; + update_server_ttl(servrec, ttl); + StrnCpy(servrec->serv.comment,comment,sizeof(servrec->serv.comment)-1); + } + + set_workgroup_local_master_browser_name( work, server_name ); } else { - /* Update the record. */ - servrec->serv.type = servertype|SV_TYPE_LOCAL_LIST_ONLY; - update_server_ttl(servrec, ttl); - StrnCpy(servrec->serv.comment,comment,sizeof(servrec->serv.comment)-1); + /* + * This server is announcing it is going down. Remove it from the + * workgroup. + */ + if(!is_myname(server_name) && (work != NULL) && + ((servrec = find_server_in_workgroup( work, server_name))!=NULL) + ) + { + remove_server_from_workgroup( work, servrec); + } } - set_workgroup_local_master_browser_name( work, server_name ); - subrec->work_changed = True; } @@ -454,26 +491,44 @@ void process_lm_host_announce(struct subnet_record *subrec, struct packet_struct * announce instead ? JRA. */ - if ((work = find_workgroup_on_subnet(subrec, work_name))==NULL) - { - /* We have no record of this workgroup. Add it. */ - if((work = create_workgroup_on_subnet(subrec, work_name, ttl))==NULL) - return; - } + work = find_workgroup_on_subnet(subrec, work_name); - if((servrec = find_server_in_workgroup( work, announce_name))==NULL) + if(servertype != 0) { - /* If this server is not already in the workgroup, add it. */ - create_server_on_workgroup(work, announce_name, - servertype|SV_TYPE_LOCAL_LIST_ONLY, - ttl, comment); + if (work == NULL) + { + /* We have no record of this workgroup. Add it. */ + if((work = create_workgroup_on_subnet(subrec, work_name, ttl))==NULL) + return; + } + + if((servrec = find_server_in_workgroup( work, announce_name))==NULL) + { + /* If this server is not already in the workgroup, add it. */ + create_server_on_workgroup(work, announce_name, + servertype|SV_TYPE_LOCAL_LIST_ONLY, + ttl, comment); + } + else + { + /* Update the record. */ + servrec->serv.type = servertype|SV_TYPE_LOCAL_LIST_ONLY; + update_server_ttl( servrec, ttl); + StrnCpy(servrec->serv.comment,comment,sizeof(servrec->serv.comment)-1); + } } else { - /* Update the record. */ - servrec->serv.type = servertype|SV_TYPE_LOCAL_LIST_ONLY; - update_server_ttl( servrec, ttl); - StrnCpy(servrec->serv.comment,comment,sizeof(servrec->serv.comment)-1); + /* + * This server is announcing it is going down. Remove it from the + * workgroup. + */ + if(!is_myname(announce_name) && (work != NULL) && + ((servrec = find_server_in_workgroup( work, announce_name))!=NULL) + ) + { + remove_server_from_workgroup( work, servrec); + } } subrec->work_changed = True; diff --git a/source3/nmbd/nmbd_serverlistdb.c b/source3/nmbd/nmbd_serverlistdb.c index b3dca36c84..6a6998f81d 100644 --- a/source3/nmbd/nmbd_serverlistdb.c +++ b/source3/nmbd/nmbd_serverlistdb.c @@ -111,7 +111,7 @@ struct server_record *find_server_in_workgroup(struct work_record *work, char *n Remove a server entry from this workgroup. ****************************************************************************/ -static void remove_server_from_workgroup(struct work_record *work, struct server_record *servrec) +void remove_server_from_workgroup(struct work_record *work, struct server_record *servrec) { if (servrec->prev) servrec->prev->next = servrec->next; @@ -311,11 +311,17 @@ void write_browse_list(time_t t, BOOL force_write) BOOL list_changed = force_write; static time_t lasttime = 0; - if (!lasttime) - lasttime = t; - if (t - lasttime < 5) - return; + /* Always dump if we're being told to by a signal. */ + if(force_write == False) + { + if (!lasttime) + lasttime = t; + if (t - lasttime < 5) + return; + } + dump_workgroups(force_write); + for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) { if(subrec->work_changed) @@ -331,8 +337,6 @@ void write_browse_list(time_t t, BOOL force_write) lasttime = t; updatecount++; - dump_workgroups(); - pstrcpy(fname,lp_lockdir()); trim_string(fname,NULL,"/"); strcat(fname,"/"); diff --git a/source3/nmbd/nmbd_workgroupdb.c b/source3/nmbd/nmbd_workgroupdb.c index 828e29a024..1b97b92721 100644 --- a/source3/nmbd/nmbd_workgroupdb.c +++ b/source3/nmbd/nmbd_workgroupdb.c @@ -293,22 +293,23 @@ on subnet %s\n", name, subrec->subnet_name)); Dump a copy of the workgroup database into the log file. **************************************************************************/ -void dump_workgroups(void) +void dump_workgroups(BOOL force_write) { struct subnet_record *subrec; - + int debuglevel = force_write ? 0 : 4; + for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) { if (subrec->workgrouplist) { struct work_record *work; - DEBUG(4,("dump_workgroups: dump workgroup on subnet %15s: ", subrec->subnet_name)); - DEBUG(4,(" netmask=%15s:\n", inet_ntoa(subrec->mask_ip))); + DEBUG(debuglevel,("dump_workgroups: dump workgroup on subnet %15s: ", subrec->subnet_name)); + DEBUG(debuglevel,(" netmask=%15s:\n", inet_ntoa(subrec->mask_ip))); for (work = subrec->workgrouplist; work; work = work->next) { - DEBUG(4,("\t%s(%d) current master browser = %s\n", work->work_group, + DEBUG(debuglevel,("\t%s(%d) current master browser = %s\n", work->work_group, work->token, *work->local_master_browser_name ? work->local_master_browser_name : "UNKNOWN" )); if (work->serverlist) @@ -316,7 +317,7 @@ void dump_workgroups(void) struct server_record *servrec; for (servrec = work->serverlist; servrec; servrec = servrec->next) { - DEBUG(4,("\t\t%s %8x (%s)\n", + DEBUG(debuglevel,("\t\t%s %8x (%s)\n", servrec->serv.name, servrec->serv.type, servrec->serv.comment)); } } |