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);
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);
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 */
pstring sesssetup_user="";
pstring myname = "";
fstring myworkgroup = "";
+char **my_netbios_names;
int smb_read_error = 0;
/*******************************************************************
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);
/*******************************************************************
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);
#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);
+}
extern pstring myname;
extern fstring myworkgroup;
+extern char **my_netbios_names;
extern int ClientDGRAM;
extern int ClientNMB;
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);
}
}
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));
{
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
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)
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;
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);
+ }
}
}
extern pstring myname;
extern fstring myworkgroup;
+extern char **my_netbios_names;
BOOL updatedlists = True;
int updatecount = 0;
*/
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)));
+ }
}
}
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;
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 */
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++;
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);
}
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
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;
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);
}
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;
}
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);
char *szSocketAddress;
char *szNISHomeMapName;
char *szAnnounceVersion; /* This is initialised in init_globals */
+ char *szNetbiosAliases;
int max_log_size;
int mangled_stack;
int max_xmit;
{"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},
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)