summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source3/include/nameserv.h2
-rw-r--r--source3/include/proto.h2
-rw-r--r--source3/lib/util.c11
-rw-r--r--source3/nameannounce.c51
-rw-r--r--source3/nmbd/nmbd.c120
-rw-r--r--source3/param/loadparm.c44
6 files changed, 151 insertions, 79 deletions
diff --git a/source3/include/nameserv.h b/source3/include/nameserv.h
index 582378e183..5162ebe2d7 100644
--- a/source3/include/nameserv.h
+++ b/source3/include/nameserv.h
@@ -373,3 +373,5 @@ struct packet_struct
/* announce as master to WINS server and any Primary Domain Controllers */
#define CHECK_TIME_MST_ANNOUNCE 15
+/* do all remote announcements this often */
+#define REMOTE_ANNOUNCE_INTERVAL 180
diff --git a/source3/include/proto.h b/source3/include/proto.h
index 04f5ef158d..d3e9f42ae8 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -140,6 +140,7 @@ char *lp_domain_controller(void);
char *lp_username_map(void);
char *lp_character_set(void);
char *lp_logon_script(void);
+char *lp_remote_announce(void);
char *lp_wins_server(void);
char *lp_interfaces(void);
BOOL lp_wins_support(void);
@@ -308,6 +309,7 @@ void announce_server(struct subnet_record *d, struct work_record *work,
char *name, char *comment, time_t ttl, int server_type);
void announce_host(void);
void announce_master(void);
+void announce_remote(void);
/*The following definitions come from namebrowse.c */
diff --git a/source3/lib/util.c b/source3/lib/util.c
index 5b765e0ac6..aeaac29ae1 100644
--- a/source3/lib/util.c
+++ b/source3/lib/util.c
@@ -2889,15 +2889,22 @@ uint32 interpret_addr(char *str)
{
struct hostent *hp;
uint32 res;
+ int i;
+ BOOL pure_address = True;
if (strcmp(str,"0.0.0.0") == 0) return(0);
if (strcmp(str,"255.255.255.255") == 0) return(0xFFFFFFFF);
+ for (i=0; pure_address && str[i]; i++)
+ if (!(isdigit(str[i]) || str[i] == '.'))
+ pure_address = False;
+
/* if it's in the form of an IP address then get the lib to interpret it */
- if (isdigit(str[0])) {
+ if (pure_address) {
res = inet_addr(str);
} else {
- /* otherwise assume it's a network name of some sort and use Get_Hostbyname */
+ /* otherwise assume it's a network name of some sort and use
+ Get_Hostbyname */
if ((hp = Get_Hostbyname(str)) == 0) {
DEBUG(3,("Get_Hostbyname: Unknown host. %s\n",str));
return 0;
diff --git a/source3/nameannounce.c b/source3/nameannounce.c
index 4c1ef78f9e..0127ae03e3 100644
--- a/source3/nameannounce.c
+++ b/source3/nameannounce.c
@@ -50,6 +50,8 @@ extern int workgroup_count;
extern struct in_addr ipgrp;
+
+
/****************************************************************************
send a announce request to the local net
**************************************************************************/
@@ -578,3 +580,52 @@ void announce_master(void)
}
}
}
+
+
+
+/****************************************************************************
+ 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 browse master at the other end.
+ **************************************************************************/
+void announce_remote(void)
+{
+ char *s,*ptr;
+ static time_t last_time = 0;
+ time_t t = time(NULL);
+ pstring s2;
+ struct in_addr addr;
+ char *comment,*workgroup;
+ int stype = SV_TYPE_WORKSTATION | SV_TYPE_SERVER | SV_TYPE_PRINTQ_SERVER |
+ SV_TYPE_SERVER_UNIX;
+
+ if (last_time && t < last_time + REMOTE_ANNOUNCE_INTERVAL)
+ return;
+
+ last_time = t;
+
+ s = lp_remote_announce();
+ if (!*s) return;
+
+ comment = lp_serverstring();
+ workgroup = lp_workgroup();
+
+ 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;
+
+ wgroup = strchr(s2,'/');
+ if (wgroup) *wgroup++ = 0;
+ if (!wgroup || !*wgroup)
+ wgroup = workgroup;
+
+ addr = *interpret_addr2(s2);
+
+ do_announce_host(ANN_HostAnnouncement,myname,0x20,*iface_ip(addr),
+ wgroup,0x1e,addr,
+ REMOTE_ANNOUNCE_INTERVAL,
+ myname,stype,comment);
+ }
+
+}
diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c
index 04751f6f56..1ee11edbcf 100644
--- a/source3/nmbd/nmbd.c
+++ b/source3/nmbd/nmbd.c
@@ -229,80 +229,60 @@ static void load_hosts_file(char *fname)
while (!feof(f))
{
+ pstring ip,name,flags,extra;
+ struct subnet_record *d;
+ char *ptr;
+ int count = 0;
+ struct in_addr ipaddr;
+ enum name_source source = LMHOSTS;
+
if (!fgets_slash(line,sizeof(pstring),f)) continue;
if (*line == '#') continue;
- {
- BOOL group=False;
-
- pstring ip,name,mask,flags,extra;
-
- char *ptr;
- int count = 0;
- struct in_addr ipaddr;
- struct in_addr ipmask;
- enum name_source source = LMHOSTS;
-
- strcpy(ip,"");
- strcpy(name,"");
- strcpy(mask,"");
- strcpy(flags,"");
- strcpy(extra,"");
-
- ptr = line;
-
- if (next_token(&ptr,ip ,NULL)) ++count;
- if (next_token(&ptr,name ,NULL)) ++count;
- if (next_token(&ptr,mask ,NULL)) ++count;
- if (next_token(&ptr,flags,NULL)) ++count;
- if (next_token(&ptr,extra,NULL)) ++count;
-
- if (count <= 0) continue;
-
- if (count > 0 && count < 2) {
- DEBUG(0,("Ill formed hosts line [%s]\n",line));
- continue;
- }
-
- /* work out if we need to shuffle the tokens along due to the
- optional subnet mask argument */
-
- if (strchr(mask, 'G') || strchr(mask, 'S') || strchr(mask, 'M')) {
- strcpy(flags, mask );
- /* default action for no subnet mask */
- strcpy(mask, "");
- }
-
- DEBUG(4, ("lmhost entry: %s %s %s %s\n", ip, name, mask, flags));
-
- if (strchr(flags,'G') || strchr(flags,'S'))
- group = True;
-
- if (strchr(flags,'M') && !group) {
- source = SELF;
- strcpy(myname,name);
- }
-
- ipaddr = *interpret_addr2(ip);
- if (*mask)
- ipmask = *interpret_addr2(mask);
- else
- ipmask = *iface_nmask(ipaddr);
-
- if (group) {
- add_subnet_entry(ipaddr, ipmask, name, True, True);
- } else {
- struct subnet_record *d = find_subnet(ipaddr);
- if (d)
- {
- add_netbios_entry(d,name,0x00,NB_ACTIVE,0,source,ipaddr,True,True);
- add_netbios_entry(d,name,0x20,NB_ACTIVE,0,source,ipaddr,True,True);
+ strcpy(ip,"");
+ strcpy(name,"");
+ strcpy(flags,"");
+
+ ptr = line;
+
+ if (next_token(&ptr,ip ,NULL)) ++count;
+ if (next_token(&ptr,name ,NULL)) ++count;
+ if (next_token(&ptr,flags,NULL)) ++count;
+ if (next_token(&ptr,extra,NULL)) ++count;
+
+ if (count <= 0) continue;
+
+ if (count > 0 && count < 2) {
+ DEBUG(0,("Ill formed hosts line [%s]\n",line));
+ continue;
}
- }
+
+ if (count >= 4) {
+ DEBUG(0,("too many columns in %s (obsolete syntax)\n",fname));
+ continue;
+ }
+
+ DEBUG(4, ("lmhost entry: %s %s %s\n", ip, name, flags));
+
+ if (strchr(flags,'G') || strchr(flags,'S')) {
+ DEBUG(0,("group flag in %s ignored (obsolete)\n",fname));
+ continue;
}
+
+ if (strchr(flags,'M')) {
+ source = SELF;
+ strcpy(myname,name);
+ }
+
+ ipaddr = *interpret_addr2(ip);
+ d = find_subnet(ipaddr);
+ if (d) {
+ add_netbios_entry(d,name,0x00,NB_ACTIVE,0,source,ipaddr,True,True);
+ add_netbios_entry(d,name,0x20,NB_ACTIVE,0,source,ipaddr,True,True);
+ }
}
-
+
fclose(f);
}
@@ -325,7 +305,7 @@ static void process(void)
announce_host();
-#if 1
+#if 0
/* XXXX what was this stuff supposed to do? It sent
ANN_GetBackupListReq packets which I think should only be
sent when trying to find out who to browse with */
@@ -335,6 +315,8 @@ static void process(void)
announce_master();
+ announce_remote();
+
query_refresh_names();
expire_names_and_servers();
@@ -468,7 +450,7 @@ static void usage(char *pname)
{
case 's':
strcpy(servicesf,optarg);
- break;
+ break;
case 'C':
strcpy(ServerComment,optarg);
break;
diff --git a/source3/param/loadparm.c b/source3/param/loadparm.c
index 7877f2eb99..d0df198a67 100644
--- a/source3/param/loadparm.c
+++ b/source3/param/loadparm.c
@@ -129,6 +129,7 @@ typedef struct
char *szSmbrun;
char *szWINSserver;
char *szInterfaces;
+ char *szRemoteAnnounce;
int max_log_size;
int mangled_stack;
int max_xmit;
@@ -397,6 +398,7 @@ struct parm_struct
{"username map", P_STRING, P_GLOBAL, &Globals.szUsernameMap, NULL},
{"character set", P_STRING, P_GLOBAL, &Globals.szCharacterSet, handle_character_set},
{"logon script", P_STRING, P_GLOBAL, &Globals.szLogonScript, NULL},
+ {"remote announce", P_STRING, P_GLOBAL, &Globals.szRemoteAnnounce, NULL},
{"max log size", P_INTEGER, P_GLOBAL, &Globals.max_log_size, NULL},
{"mangled stack", P_INTEGER, P_GLOBAL, &Globals.mangled_stack, NULL},
{"max mux", P_INTEGER, P_GLOBAL, &Globals.max_mux, NULL},
@@ -637,24 +639,49 @@ static void init_locals(void)
}
-/*******************************************************************
-a convenience rooutine to grab string parameters into a rotating
-static buffer, and run standard_sub_basic on them. The buffers
-can be written to by callers
+/******************************************************************* a
+convenience routine to grab string parameters into a rotating buffer,
+and run standard_sub_basic on them. The buffers can be written to by
+callers without affecting the source string.
********************************************************************/
char *lp_string(char *s)
{
- static pstring bufs[10];
- static int next=0;
+ static char *bufs[10];
+ static int buflen[10];
+ static int next = -1;
char *ret;
-
+ int i;
+ int len = s?strlen(s):0;
+
+ if (next == -1) {
+ /* initialisation */
+ for (i=0;i<10;i++) {
+ bufs[i] = NULL;
+ buflen[i] = 0;
+ }
+ next = 0;
+ }
+
+ len = MAX(len+100,sizeof(pstring)); /* the +100 is for some
+ substitution room */
+
+ if (buflen[next] != len) {
+ buflen[next] = len;
+ if (bufs[next]) free(bufs[next]);
+ bufs[next] = (char *)malloc(len);
+ if (!bufs[next]) {
+ DEBUG(0,("out of memory in lp_string()"));
+ exit(1);
+ }
+ }
+
ret = &bufs[next][0];
next = (next+1)%10;
if (!s)
*ret = 0;
else
- StrnCpy(ret,s,sizeof(pstring)-1);
+ StrCpy(ret,s);
standard_sub_basic(ret);
return(ret);
@@ -705,6 +732,7 @@ FN_GLOBAL_STRING(lp_domain_controller,&Globals.szDomainController)
FN_GLOBAL_STRING(lp_username_map,&Globals.szUsernameMap)
FN_GLOBAL_STRING(lp_character_set,&Globals.szCharacterSet)
FN_GLOBAL_STRING(lp_logon_script,&Globals.szLogonScript)
+FN_GLOBAL_STRING(lp_remote_announce,&Globals.szRemoteAnnounce)
FN_GLOBAL_STRING(lp_wins_server,&Globals.szWINSserver)
FN_GLOBAL_STRING(lp_interfaces,&Globals.szInterfaces)