📄 nmbd_sendannounce.c
字号:
work->lastannounce_time = t; for (servrec = work->serverlist; servrec; servrec = servrec->next) { if (is_myname(servrec->serv.name)) announce_server(subrec, work, servrec); } } /* if work */ } /* for subrec */}/**************************************************************************** Go through all my registered names on all broadcast subnets and announce them as a LanMan server if the timeout requires it.**************************************************************************/void announce_my_lm_server_names(time_t t){ struct subnet_record *subrec; static time_t last_lm_announce_time=0; int announce_interval = lp_lm_interval(); int lm_announce = lp_lm_announce(); if ((announce_interval <= 0) || (lm_announce <= 0)) { /* user absolutely does not want LM announcements to be sent. */ return; } if ((lm_announce >= 2) && (!found_lm_clients)) { /* has been set to 2 (Auto) but no LM clients detected (yet). */ return; } /* Otherwise: must have been set to 1 (Yes), or LM clients *have* been detected. */ for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) { struct work_record *work = find_workgroup_on_subnet(subrec, lp_workgroup()); if(work) { struct server_record *servrec; if (last_lm_announce_time && ((t - last_lm_announce_time) < announce_interval )) continue; last_lm_announce_time = t; for (servrec = work->serverlist; servrec; servrec = servrec->next) { if (is_myname(servrec->serv.name)) /* skipping equivalent of announce_server() */ send_lm_host_announcement(subrec, work, servrec, announce_interval); } } /* if work */ } /* for subrec */}/* Announce timer. Moved into global static so it can be reset when a machine becomes a local master browser. */static time_t announce_timer_last=0;/**************************************************************************** Reset the announce_timer so that a local master browser announce will be done immediately. ****************************************************************************/void reset_announce_timer(void){ announce_timer_last = time(NULL) - (CHECK_TIME_MST_ANNOUNCE * 60);}/**************************************************************************** Announce myself as a local master browser to a domain master browser. **************************************************************************/void announce_myself_to_domain_master_browser(time_t t){ struct subnet_record *subrec; struct work_record *work; if(!we_are_a_wins_client()) { DEBUG(10,("announce_myself_to_domain_master_browser: no unicast subnet, ignoring.\n")); return; } if (!announce_timer_last) announce_timer_last = t; if ((t-announce_timer_last) < (CHECK_TIME_MST_ANNOUNCE * 60)) { DEBUG(10,("announce_myself_to_domain_master_browser: t (%d) - last(%d) < %d\n", (int)t, (int)announce_timer_last, CHECK_TIME_MST_ANNOUNCE * 60 )); return; } announce_timer_last = t; /* Look over all our broadcast subnets to see if any of them has the state set as local master browser. */ for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) { for (work = subrec->workgrouplist; work; work = work->next) { if (AM_LOCAL_MASTER_BROWSER(work)) { DEBUG(4,( "announce_myself_to_domain_master_browser: I am a local master browser for \workgroup %s on subnet %s\n", work->work_group, subrec->subnet_name)); /* Look in nmbd_browsersync.c for the rest of this code. */ announce_and_sync_with_domain_master_browser(subrec, work); } } }}/****************************************************************************Announce all samba's server entries as 'gone'.This must *only* be called on shutdown.****************************************************************************/void announce_my_servers_removed(void){ int announce_interval = lp_lm_interval(); int lm_announce = lp_lm_announce(); struct subnet_record *subrec; for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) { struct work_record *work; for (work = subrec->workgrouplist; work; work = work->next) { struct server_record *servrec; work->announce_interval = 0; for (servrec = work->serverlist; servrec; servrec = servrec->next) { if (!is_myname(servrec->serv.name)) continue; servrec->serv.type = 0; if(AM_LOCAL_MASTER_BROWSER(work)) send_local_master_announcement(subrec, work, servrec); send_host_announcement(subrec, work, servrec); if ((announce_interval <= 0) || (lm_announce <= 0)) { /* user absolutely does not want LM announcements to be sent. */ continue; } if ((lm_announce >= 2) && (!found_lm_clients)) { /* has been set to 2 (Auto) but no LM clients detected (yet). */ continue; } /* * lm announce was set or we have seen lm announcements, so do * a lm announcement of host removed. */ send_lm_host_announcement(subrec, work, servrec, 0); } } }}/**************************************************************************** Do all the "remote" announcements. These are used to put ourselves on a remote browse list. They are done blind, no checking is done to see if there is actually a local master browser at the other end. **************************************************************************/void announce_remote(time_t t){ char *s; const char *ptr; static time_t last_time = 0; pstring s2; struct in_addr addr; char *comment; int stype = lp_default_server_announce(); if (last_time && (t < (last_time + REMOTE_ANNOUNCE_INTERVAL))) return; last_time = t; s = lp_remote_announce(); if (!*s) return; comment = string_truncate(lp_serverstring(), MAX_SERVER_STRING_LENGTH); for (ptr=s; next_token(&ptr,s2,NULL,sizeof(s2)); ) { /* The entries are of the form a.b.c.d/WORKGROUP with WORKGROUP being optional */ const char *wgroup; char *pwgroup; int i; pwgroup = strchr_m(s2,'/'); if (pwgroup) *pwgroup++ = 0; if (!pwgroup || !*pwgroup) wgroup = lp_workgroup(); else wgroup = pwgroup; addr = *interpret_addr2(s2); /* Announce all our names including aliases */ /* Give the ip address as the address of our first broadcast subnet. */ for(i=0; my_netbios_names(i); i++) { const char *name = my_netbios_names(i); DEBUG(5,("announce_remote: Doing remote announce for server %s to IP %s.\n", name, inet_ntoa(addr) )); send_announcement(FIRST_SUBNET, ANN_HostAnnouncement, name, /* From nbt name. */ wgroup, 0x1d, /* To nbt name. */ addr, /* To ip. */ REMOTE_ANNOUNCE_INTERVAL, /* Time until next announce. */ name, /* Name to announce. */ stype, /* Type field. */ comment); } }}/**************************************************************************** Implement the 'remote browse sync' feature Andrew added. These are used to put our browse lists into remote browse lists.**************************************************************************/void browse_sync_remote(time_t t){ char *s; const char *ptr; static time_t last_time = 0; pstring s2; struct in_addr addr; struct work_record *work; pstring outbuf; char *p; unstring myname; if (last_time && (t < (last_time + REMOTE_ANNOUNCE_INTERVAL))) return; last_time = t; s = lp_remote_browse_sync(); if (!*s) return; /* * We only do this if we are the local master browser * for our workgroup on the firsst subnet. */ if((work = find_workgroup_on_subnet(FIRST_SUBNET, lp_workgroup())) == NULL) { DEBUG(0,("browse_sync_remote: Cannot find workgroup %s on subnet %s\n", lp_workgroup(), FIRST_SUBNET->subnet_name )); return; } if(!AM_LOCAL_MASTER_BROWSER(work)) { DEBUG(5,("browse_sync_remote: We can only do this if we are a local master browser \for workgroup %s on subnet %s.\n", lp_workgroup(), FIRST_SUBNET->subnet_name )); return; } memset(outbuf,'\0',sizeof(outbuf)); p = outbuf; SCVAL(p,0,ANN_MasterAnnouncement); p++; unstrcpy(myname, global_myname()); strupper_m(myname); myname[15]='\0'; push_pstring_base(p, myname, outbuf); p = skip_string(p,1); for (ptr=s; next_token(&ptr,s2,NULL,sizeof(s2)); ) { /* The entries are of the form a.b.c.d */ addr = *interpret_addr2(s2); DEBUG(5,("announce_remote: Doing remote browse sync announce for server %s to IP %s.\n", global_myname(), inet_ntoa(addr) )); send_mailslot(True, BROWSE_MAILSLOT, outbuf,PTR_DIFF(p,outbuf), global_myname(), 0x0, "*", 0x0, addr, FIRST_SUBNET->myip, DGRAM_PORT); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -