diff options
Diffstat (limited to 'source')
-rw-r--r-- | source/include/proto.h | 6 | ||||
-rw-r--r-- | source/lib/util.c | 22 | ||||
-rw-r--r-- | source/nameannounce.c | 37 | ||||
-rw-r--r-- | source/namedbsubnet.c | 24 | ||||
-rw-r--r-- | source/nameserv.c | 12 | ||||
-rw-r--r-- | source/namework.c | 6 | ||||
-rw-r--r-- | source/nmbd/nmbd.c | 68 | ||||
-rw-r--r-- | source/param/loadparm.c | 3 |
8 files changed, 146 insertions, 32 deletions
diff --git a/source/include/proto.h b/source/include/proto.h index 23f7f191fb8..0fa4251b827 100644 --- a/source/include/proto.h +++ b/source/include/proto.h @@ -146,6 +146,7 @@ char *lp_wins_server(void); char *lp_interfaces(void); char *lp_socket_address(void); char *lp_nis_home_map_name(void); +char *lp_netbios_aliases(void); BOOL lp_dns_proxy(void); BOOL lp_wins_support(void); BOOL lp_wins_proxy(void); @@ -871,8 +872,8 @@ uint32 file_size(char *file_name); char *attrib_string(int mode); int StrCaseCmp(const char *s, const char *t); int StrnCaseCmp(const char *s, const char *t, int n); -BOOL strequal(char *s1,char *s2); -BOOL strnequal(char *s1,char *s2,int n); +BOOL strequal(const char *s1,const char *s2); +BOOL strnequal(const char *s1,const char *s2,int n); BOOL strcsequal(char *s1,char *s2); void strlower(char *s); void strupper(char *s); @@ -965,6 +966,7 @@ void free_namearray(name_compare_entry *name_array); BOOL fcntl_lock(int fd,int op,uint32 offset,uint32 count,int type); int file_lock(char *name,int timeout); void file_unlock(int fd); +BOOL is_myname(const char *s); /*The following definitions come from vt_mode.c */ diff --git a/source/lib/util.c b/source/lib/util.c index 51bb2b4a16a..9982d105adc 100644 --- a/source/lib/util.c +++ b/source/lib/util.c @@ -74,6 +74,7 @@ pstring user_socket_options=""; pstring sesssetup_user=""; pstring myname = ""; fstring myworkgroup = ""; +char **my_netbios_names; int smb_read_error = 0; @@ -834,7 +835,7 @@ int StrnCaseCmp(const char *s, const char *t, int n) /******************************************************************* compare 2 strings ********************************************************************/ -BOOL strequal(char *s1,char *s2) +BOOL strequal(const char *s1, const char *s2) { if (s1 == s2) return(True); if (!s1 || !s2) return(False); @@ -845,7 +846,7 @@ BOOL strequal(char *s1,char *s2) /******************************************************************* compare 2 strings up to and including the nth char. ******************************************************************/ -BOOL strnequal(char *s1,char *s2,int n) +BOOL strnequal(const char *s1,const char *s2,int n) { if (s1 == s2) return(True); if (!s1 || !s2 || !n) return(False); @@ -3741,3 +3742,20 @@ void file_unlock(int fd) #endif close(fd); } + +/******************************************************************* +is the name specified one of my netbios names +returns true is it is equal, false otherwise +********************************************************************/ +BOOL is_myname(const char *s) +{ + int n; + BOOL ret = False; + + for (n=0; my_netbios_names[n]; n++) { + if (strequal(my_netbios_names[n], s)) + ret=True; + } + DEBUG(8, ("is_myname(\"%s\") returns %d\n", s, ret)); + return(ret); +} diff --git a/source/nameannounce.c b/source/nameannounce.c index e92e989c313..2f169e9287c 100644 --- a/source/nameannounce.c +++ b/source/nameannounce.c @@ -39,6 +39,7 @@ extern struct in_addr ipzero; extern pstring myname; extern fstring myworkgroup; +extern char **my_netbios_names; extern int ClientDGRAM; extern int ClientNMB; @@ -202,7 +203,7 @@ void announce_my_servers_removed(void) struct server_record *s; for (s = work->serverlist; s; s = s->next) { - if (!strequal(myname,s->serv.name)) continue; + if (!is_myname(s->serv.name)) continue; announce_server(d, work, s->serv.name, s->serv.comment, 0, 0); } } @@ -230,7 +231,9 @@ interface for workgroup %s, name %s\n", work->work_group, name)); return; } - if (AM_MASTER(work)) + /* Only do domain announcements if we are a master and it's + our name we're being asked to announce. */ + if (AM_MASTER(work) && strequal(myname,name)) { DEBUG(3,("sending local master announce to %s for %s(1e)\n", inet_ntoa(d->bcast_ip),work->work_group)); @@ -289,7 +292,6 @@ void announce_host(time_t t) { uint32 stype = work->ServerType; struct server_record *s; - BOOL announce = False; /* must work on the code that does announcements at up to 30 seconds later if a master browser sends us a request @@ -315,15 +317,15 @@ void announce_host(time_t t) work->lastannounce_time = t; for (s = work->serverlist; s; s = s->next) { - if (strequal(myname, s->serv.name)) { - announce = True; - break; - } - } - - if (announce) { - announce_server(d,work,my_name,comment, + if (is_myname(s->serv.name)) { + /* If we are any kind of browser or logon server, only + announce it for our primary name, not our aliases. */ + if(!strequal(myname, s->serv.name)) + stype &= ~(SV_TYPE_MASTER_BROWSER|SV_TYPE_POTENTIAL_BROWSER| + SV_TYPE_DOMAIN_MASTER|SV_TYPE_DOMAIN_MEMBER); + announce_server(d,work,s->serv.name,comment, work->announce_interval,stype); + } } if (work->needannounce) @@ -498,10 +500,12 @@ void announce_remote(time_t t) comment = lp_serverstring(); workgroup = myworkgroup; - for (ptr=s; next_token(&ptr,s2,NULL); ) { + for (ptr=s; next_token(&ptr,s2,NULL); ) + { /* the entries are of the form a.b.c.d/WORKGROUP with WORKGROUP being optional */ char *wgroup; + int n; wgroup = strchr(s2,'/'); if (wgroup) *wgroup++ = 0; @@ -510,10 +514,15 @@ void announce_remote(time_t t) addr = *interpret_addr2(s2); - do_announce_host(ANN_HostAnnouncement,myname,0x20,*iface_ip(addr), + /* Announce all our names including aliases */ + for (n=0; my_netbios_names[n]; n++) + { + char *name = my_netbios_names[n]; + do_announce_host(ANN_HostAnnouncement,name,0x20,*iface_ip(addr), wgroup,0x1e,addr, REMOTE_ANNOUNCE_INTERVAL, - myname,stype,comment); + name,stype,comment); + } } } diff --git a/source/namedbsubnet.c b/source/namedbsubnet.c index 5ddda0a2827..6364ebba543 100644 --- a/source/namedbsubnet.c +++ b/source/namedbsubnet.c @@ -41,6 +41,7 @@ extern struct in_addr ipzero; extern pstring myname; extern fstring myworkgroup; +extern char **my_netbios_names; BOOL updatedlists = True; int updatecount = 0; @@ -214,13 +215,28 @@ void add_workgroup_to_subnet( struct subnet_record *d, char *group) */ if (strequal(myworkgroup, group)) { + int n; + add_my_name_entry(d,group,0x0 ,nb_type|NB_ACTIVE|NB_GROUP); add_my_name_entry(d,group,0x1e,nb_type|NB_ACTIVE|NB_GROUP); - /* add samba server name to workgroup list. */ - add_server_entry(d,w,myname,w->ServerType|SV_TYPE_LOCAL_LIST_ONLY,0, + + /* Add all our server names to the workgroup list. We remove any + browser or logon server flags from all but the primary name. + */ + for( n = 0; my_netbios_names[n]; n++) + { + char *name = my_netbios_names[n]; + int stype = w->ServerType; + + if(!strequal(myname, name)) + stype &= ~(SV_TYPE_MASTER_BROWSER|SV_TYPE_POTENTIAL_BROWSER| + SV_TYPE_DOMAIN_MASTER|SV_TYPE_DOMAIN_MEMBER); + + add_server_entry(d,w,name,stype|SV_TYPE_LOCAL_LIST_ONLY,0, lp_serverstring(),True); - DEBUG(3,("add_workgroup_to_subnet: Added server name entry %s to subnet %s\n", - myname, inet_ntoa(d->bcast_ip))); + DEBUG(3,("add_workgroup_to_subnet: Added server name entry %s \ +to subnet %s\n", name, inet_ntoa(d->bcast_ip))); + } } } diff --git a/source/nameserv.c b/source/nameserv.c index abad9b28c2a..96bb1c0eac8 100644 --- a/source/nameserv.c +++ b/source/nameserv.c @@ -38,6 +38,7 @@ extern int DEBUGLEVEL; extern pstring scope; extern pstring myname; extern fstring myworkgroup; +extern char **my_netbios_names; extern struct in_addr ipzero; extern struct in_addr wins_ip; @@ -366,11 +367,16 @@ void add_my_names(void) for (d = FIRST_SUBNET; d; d = NEXT_SUBNET_INCLUDING_WINS(d)) { + int n; BOOL wins = (lp_wins_support() && (d == wins_subnet)); - add_my_name_entry(d, myname,0x20,nb_type|NB_ACTIVE); - add_my_name_entry(d, myname,0x03,nb_type|NB_ACTIVE); - add_my_name_entry(d, myname,0x00,nb_type|NB_ACTIVE); + /* Add all our names including aliases. */ + for (n=0; my_netbios_names[n]; n++) + { + add_my_name_entry(d, my_netbios_names[n],0x20,nb_type|NB_ACTIVE); + add_my_name_entry(d, my_netbios_names[n],0x03,nb_type|NB_ACTIVE); + add_my_name_entry(d, my_netbios_names[n],0x00,nb_type|NB_ACTIVE); + } /* these names are added permanently (ttl of zero) and will NOT be refreshed with the WINS server */ diff --git a/source/namework.c b/source/namework.c index 97934412e47..3e1ac220058 100644 --- a/source/namework.c +++ b/source/namework.c @@ -112,7 +112,7 @@ void tell_become_backup(void) num_servers++; - if (strequal(myname, s->serv.name)) continue; + if (is_myname(s->serv.name)) continue; if (s->serv.type & SV_TYPE_BACKUP_BROWSER) { num_backups++; @@ -153,7 +153,7 @@ void tell_become_backup(void) BOOL same_context(struct dgram_packet *dgram) { if (!strequal(dgram->dest_name .scope,scope )) return(True); - if ( strequal(dgram->source_name.name ,myname)) return(True); + if ( is_myname(dgram->source_name.name)) return(True); return(False); } @@ -624,7 +624,7 @@ static void process_announce_request(struct packet_struct *p,char *buf) DEBUG(3,("process_announce_request: Announce request from %s to %s token=0x%X\n", name,namestr(&dgram->dest_name), token)); - if (strequal(dgram->source_name.name,myname)) return; + if (is_myname(dgram->source_name.name)) return; /* XXXX BUG or FEATURE?: need to ensure that we are a member of this workgroup before announcing, particularly as we only diff --git a/source/nmbd/nmbd.c b/source/nmbd/nmbd.c index 10701c24d41..925f975ffef 100644 --- a/source/nmbd/nmbd.c +++ b/source/nmbd/nmbd.c @@ -41,6 +41,7 @@ extern pstring myhostname; static pstring host_file; extern pstring myname; extern fstring myworkgroup; +extern char **my_netbios_names; /* are we running as a daemon ? */ static BOOL is_daemon = False; @@ -363,7 +364,11 @@ static BOOL open_sockets(BOOL isdaemon, int port) static BOOL init_structs() { extern fstring local_machine; - char *p; + char *p, *ptr; + int namecount; + int n; + int nodup; + pstring nbname; if (! *myname) { strcpy(myname,myhostname); @@ -372,12 +377,62 @@ static BOOL init_structs() } strupper(myname); + /* Add any NETBIOS name aliases. Ensure that the first entry + is equal to myname. */ + /* Work out the max number of netbios aliases that we have */ + ptr=lp_netbios_aliases(); + for (namecount=0; next_token(&ptr,nbname,NULL); namecount++) + ; + if (*myname) + namecount++; + + /* Allocate space for the netbios aliases */ + if((my_netbios_names=(char **)malloc(sizeof(char *)*(namecount+1))) == NULL) + { + DEBUG(0,("init_structs: malloc fail.\n")); + return False; + } + + /* Use the myname string first */ + namecount=0; + if (*myname) + my_netbios_names[namecount++] = myname; + + ptr=lp_netbios_aliases(); + while (next_token(&ptr,nbname,NULL)) { + strupper(nbname); + /* Look for duplicates */ + nodup=1; + for(n=0; n<namecount; n++) { + if (strcmp(nbname, my_netbios_names[n])==0) + nodup=0; + } + if (nodup) + my_netbios_names[namecount++]=strdup(nbname); + } + + /* Check the strdups succeeded. */ + for(n = 0; n < namecount; n++) + if(my_netbios_names[n]==NULL) + { + DEBUG(0,("init_structs: malloc fail when allocating names.\n")); + return False; + } + + /* Terminate name list */ + my_netbios_names[namecount++]=NULL; + strcpy(local_machine,myname); trim_string(local_machine," "," "); p = strchr(local_machine,' '); - if (p) *p = 0; + if (p) + *p = 0; strlower(local_machine); + DEBUG(5, ("Netbios name list:-\n")); + for (n=0; my_netbios_names[n]; n++) + DEBUG(5, ("my_netbios_names[%d]=\"%s\"\n", n, my_netbios_names[n])); + return True; } @@ -493,14 +548,19 @@ static void usage(char *pname) DEBUG(1,("%s netbios nameserver version %s started\n",timestring(),VERSION)); DEBUG(1,("Copyright Andrew Tridgell 1994-1997\n")); - get_myname(myhostname,NULL); + if(!get_myname(myhostname,NULL)) + { + DEBUG(0,("Unable to get my hostname - exiting.\n")); + return -1; + } if (!reload_services(False)) return(-1); codepage_initialise(lp_client_code_page()); - init_structs(); + if(!init_structs()) + return -1; reload_services(True); diff --git a/source/param/loadparm.c b/source/param/loadparm.c index df6aff6f9c0..69204cc13fe 100644 --- a/source/param/loadparm.c +++ b/source/param/loadparm.c @@ -136,6 +136,7 @@ typedef struct char *szSocketAddress; char *szNISHomeMapName; char *szAnnounceVersion; /* This is initialised in init_globals */ + char *szNetbiosAliases; int max_log_size; int mangled_stack; int max_xmit; @@ -403,6 +404,7 @@ struct parm_struct {"password server", P_STRING, P_GLOBAL, &Globals.szPasswordServer, NULL}, {"socket options", P_GSTRING, P_GLOBAL, user_socket_options, NULL}, {"netbios name", P_UGSTRING,P_GLOBAL, myname, NULL}, + {"netbios aliases", P_STRING, P_GLOBAL, &Globals.szNetbiosAliases, NULL}, {"smbrun", P_STRING, P_GLOBAL, &Globals.szSmbrun, NULL}, {"log file", P_STRING, P_GLOBAL, &Globals.szLogFile, NULL}, {"config file", P_STRING, P_GLOBAL, &Globals.szConfigFile, NULL}, @@ -831,6 +833,7 @@ FN_GLOBAL_STRING(lp_interfaces,&Globals.szInterfaces) FN_GLOBAL_STRING(lp_socket_address,&Globals.szSocketAddress) FN_GLOBAL_STRING(lp_nis_home_map_name,&Globals.szNISHomeMapName) FN_GLOBAL_STRING(lp_announce_version,&Globals.szAnnounceVersion) +FN_GLOBAL_STRING(lp_netbios_aliases,&Globals.szNetbiosAliases) FN_GLOBAL_BOOL(lp_dns_proxy,&Globals.bDNSproxy) FN_GLOBAL_BOOL(lp_wins_support,&Globals.bWINSsupport) |