1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00

- added the "remote announce" option

- made the lp_string() code able to handle any length string
- got rid of the obsolete lmhosts code, instead users should use
"interfaces" and "remote announce". lmhosts now is just used as a IP
to netbios name map
- cleanup the inet_address() code
This commit is contained in:
Andrew Tridgell 0001-01-01 00:00:00 +00:00
parent b2ca1f0c61
commit be2b679403
6 changed files with 151 additions and 79 deletions

View File

@ -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

View File

@ -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 */

View File

@ -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;

View File

@ -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);
}
}

View File

@ -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;

View File

@ -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)