Added nodelist override settings

This commit is contained in:
Michiel Broek
2002-07-13 12:58:35 +00:00
parent 4982b8bd2b
commit e9562655ae
8 changed files with 839 additions and 721 deletions

View File

@@ -172,278 +172,324 @@ int comp_node(struct _nlidx fap1, struct _ixentry fap2)
node *getnlent(faddr *addr)
{
FILE *fp;
static node nodebuf;
static char buf[256], *p, *q;
struct _ixentry xaddr;
int i, j, Found = FALSE;
int ixflag, stdflag;
char *mydomain, *path;
struct _nlfil fdx;
struct _nlidx ndx;
long lowest, highest, current;
FILE *fp;
static node nodebuf;
static char buf[256], *p, *q;
struct _ixentry xaddr;
int i, j, Found = FALSE, ixflag, stdflag, ndrecord = FALSE;
char *mydomain, *path;
struct _nlfil fdx;
struct _nlidx ndx;
long lowest, highest, current;
struct _nodeshdr ndhdr;
static struct _nodes nd;
mydomain = xstrcpy(CFG.aka[0].domain);
if (mydomain == NULL)
mydomain = (char *)NULLDOMAIN;
mydomain = xstrcpy(CFG.aka[0].domain);
if (mydomain == NULL)
mydomain = (char *)NULLDOMAIN;
nodebuf.addr.domain = NULL;
nodebuf.addr.zone = 0;
nodebuf.addr.net = 0;
nodebuf.addr.node = 0;
nodebuf.addr.point = 0;
nodebuf.addr.name = NULL;
nodebuf.upnet = 0;
nodebuf.upnode = 0;
nodebuf.region = 0;
nodebuf.type = 0;
nodebuf.pflag = 0;
nodebuf.name = NULL;
nodebuf.location = NULL;
nodebuf.sysop = NULL;
nodebuf.phone = NULL;
nodebuf.speed = 0;
nodebuf.mflags = 0L;
nodebuf.oflags = 0L;
nodebuf.xflags = 0L;
nodebuf.iflags = 0L;
nodebuf.dflags = 0L;
nodebuf.uflags[0] = NULL;
nodebuf.t1 = '\0';
nodebuf.t2 = '\0';
nodebuf.addr.domain = NULL;
nodebuf.addr.zone = 0;
nodebuf.addr.net = 0;
nodebuf.addr.node = 0;
nodebuf.addr.point = 0;
nodebuf.addr.name = NULL;
nodebuf.upnet = 0;
nodebuf.upnode = 0;
nodebuf.region = 0;
nodebuf.type = 0;
nodebuf.pflag = 0;
nodebuf.name = NULL;
nodebuf.location = NULL;
nodebuf.sysop = NULL;
nodebuf.phone = NULL;
nodebuf.speed = 0;
nodebuf.mflags = 0L;
nodebuf.oflags = 0L;
nodebuf.xflags = 0L;
nodebuf.iflags = 0L;
nodebuf.dflags = 0L;
nodebuf.uflags[0] = NULL;
nodebuf.t1 = '\0';
nodebuf.t2 = '\0';
if (addr == NULL)
goto retdummy;
if (addr == NULL)
goto retdummy;
if (addr->zone == 0)
addr->zone = CFG.aka[0].zone;
xaddr.zone = addr->zone;
nodebuf.addr.zone = addr->zone;
xaddr.net = addr->net;
nodebuf.addr.net = addr->net;
xaddr.node = addr->node;
nodebuf.addr.node = addr->node;
xaddr.point = addr->point;
nodebuf.addr.point = addr->point;
if (addr->zone == 0)
addr->zone = CFG.aka[0].zone;
xaddr.zone = addr->zone;
nodebuf.addr.zone = addr->zone;
xaddr.net = addr->net;
nodebuf.addr.net = addr->net;
xaddr.node = addr->node;
nodebuf.addr.node = addr->node;
xaddr.point = addr->point;
nodebuf.addr.point = addr->point;
if (initnl())
goto retdummy;
if (initnl())
goto retdummy;
/*
* First, lookup node in index. NOTE -- NOT 5D YET
*/
path = calloc(128, sizeof(char));
sprintf(path, "%s/%s", CFG.nodelists, "node.index");
if ((fp = fopen(path, "r")) == NULL) {
tasklog('?', "$Can't open %s", path);
free(path);
goto retdummy;
}
fseek(fp, 0, SEEK_END);
highest = ftell(fp) / sizeof(ndx);
lowest = 0;
while (TRUE) {
current = ((highest - lowest) / 2) + lowest;
fseek(fp, current * sizeof(ndx), SEEK_SET);
if (fread(&ndx, sizeof(ndx), 1, fp) != 1)
break;
if (comp_node(ndx, xaddr) == 0) {
Found = TRUE;
break;
}
if (comp_node(ndx, xaddr) < 0)
lowest = current;
else
highest = current;
if ((highest - lowest) <= 1)
break;
}
fclose(fp);
if (!Found) {
free(path);
goto retdummy;
}
sprintf(path, "%s/%s", CFG.nodelists, "node.files");
if ((fp = fopen(path, "r")) == NULL) {
tasklog('?', "$Can't open %s", path);
free(path);
goto retdummy;
}
/*
* Get filename from node.files
*/
for (i = 0; i < (ndx.fileno +1); i++)
fread(&fdx, sizeof(fdx), 1, fp);
fclose(fp);
/* CHECK DOMAIN HERE */
/*
* Open and read in real nodelist
*/
sprintf(path, "%s/%s", CFG.nodelists, fdx.filename);
if ((fp = fopen(path, "r")) == NULL) {
tasklog('?', "$Can't open %s", path);
free(path);
goto retdummy;
}
/*
* First, lookup node in index. NOTE -- NOT 5D YET
*/
path = calloc(128, sizeof(char));
sprintf(path, "%s/%s", CFG.nodelists, "node.index");
if ((fp = fopen(path, "r")) == NULL) {
tasklog('?', "$Can't open %s", path);
free(path);
goto retdummy;
}
if (fseek(fp, ndx.offset, SEEK_SET) != 0) {
tasklog('?', "$Seek failed for nodelist entry");
fclose(fp);
goto retdummy;
fseek(fp, 0, SEEK_END);
highest = ftell(fp) / sizeof(ndx);
lowest = 0;
while (TRUE) {
current = ((highest - lowest) / 2) + lowest;
fseek(fp, current * sizeof(ndx), SEEK_SET);
if (fread(&ndx, sizeof(ndx), 1, fp) != 1)
break;
if (comp_node(ndx, xaddr) == 0) {
Found = TRUE;
break;
}
if (fgets(buf, sizeof(buf)-1, fp) == NULL) {
tasklog('?', "$fgets failed for nodelist entry");
fclose(fp);
goto retdummy;
}
fclose(fp);
nodebuf.type = ndx.type;
nodebuf.pflag = ndx.pflag;
if (*(p = buf + strlen(buf) -1) == '\n')
*p = '\0';
if (*(p = buf + strlen(buf) -1) == '\r')
*p = '\0';
for (p = buf; *p; p++)
if (*p == '_')
*p = ' ';
p = buf;
if ((q = strchr(p,',')))
*q++ = '\0';
p = q;
if (p == NULL)
goto badsyntax;
if ((q=strchr(p,',')))
*q++ = '\0';
p = q;
if (p == NULL)
goto badsyntax;
if ((q=strchr(p,',')))
*q++ = '\0';
nodebuf.name = p;
p = q;
if (p == NULL)
goto badsyntax;
if ((q=strchr(p,',')))
*q++ = '\0';
nodebuf.location = p;
p = q;
if (p == NULL)
goto badsyntax;
if ((q=strchr(p,',')))
*q++ = '\0';
nodebuf.sysop = p;
p = q;
if (p == NULL)
goto badsyntax;
if ((q=strchr(p,',')))
*q++ = '\0';
if (strcasecmp(p, "-Unpublished-") == 0)
nodebuf.phone = NULL;
if (comp_node(ndx, xaddr) < 0)
lowest = current;
else
nodebuf.phone = p;
p = q;
if (p == NULL)
goto badsyntax;
highest = current;
if ((highest - lowest) <= 1)
break;
}
if ((q=strchr(p,',')))
*q++ = '\0';
nodebuf.speed = atoi(p);
fclose(fp);
/*
* Process the nodelist flags.
*/
ixflag = 0;
stdflag = TRUE;
for (p = q; p; p = q) {
if ((q = strchr(p, ',')))
*q++ = '\0';
if ((strncasecmp(p, "U", 1) == 0) && (strlen(p) == 1)) {
stdflag = FALSE;
} else {
/*
* Experimental: process authorized flags and
* User flags both as authorized.
*/
for (j = 0; fkey[j].key; j++)
if (strcasecmp(p, fkey[j].key) == 0)
nodebuf.mflags |= fkey[j].flag;
for (j = 0; okey[j].key; j++)
if (strcasecmp(p, okey[j].key) == 0)
nodebuf.oflags |= okey[j].flag;
for (j = 0; dkey[j].key; j++)
if (strcasecmp(p, dkey[j].key) == 0)
nodebuf.dflags |= dkey[j].flag;
for (j = 0; ikey[j].key; j++)
if (strncasecmp(p, ikey[j].key, strlen(ikey[j].key)) == 0)
nodebuf.iflags |= ikey[j].flag;
for (j = 0; xkey[j].key; j++)
if (strcasecmp(p, xkey[j].key) == 0)
nodebuf.xflags |= xkey[j].flag;
if ((p[0] == 'T') && (strlen(p) == 3)) {
/*
* System open hours flag
*/
nodebuf.t1 = p[1];
nodebuf.t2 = p[2];
}
if (!stdflag) {
if (ixflag < MAXUFLAGS) {
nodebuf.uflags[ixflag++] = p;
if (ixflag < MAXUFLAGS)
nodebuf.uflags[ixflag] = NULL;
}
}
if (!Found) {
free(path);
goto retdummy;
}
sprintf(path, "%s/%s", CFG.nodelists, "node.files");
if ((fp = fopen(path, "r")) == NULL) {
tasklog('?', "$Can't open %s", path);
free(path);
goto retdummy;
}
/*
* Get filename from node.files
*/
for (i = 0; i < (ndx.fileno +1); i++)
fread(&fdx, sizeof(fdx), 1, fp);
fclose(fp);
/* CHECK DOMAIN HERE */
/*
* Open and read in real nodelist
*/
sprintf(path, "%s/%s", CFG.nodelists, fdx.filename);
if ((fp = fopen(path, "r")) == NULL) {
tasklog('?', "$Can't open %s", path);
free(path);
goto retdummy;
}
if (fseek(fp, ndx.offset, SEEK_SET) != 0) {
tasklog('?', "$Seek failed for nodelist entry");
fclose(fp);
goto retdummy;
}
if (fgets(buf, sizeof(buf)-1, fp) == NULL) {
tasklog('?', "$fgets failed for nodelist entry");
fclose(fp);
goto retdummy;
}
fclose(fp);
/*
* Load noderecord if this node has one, if there is one then
* nodelist overrides in this record will be used instead of
* the nodelist entries.
*/
sprintf(path, "%s/etc/nodes.data", getenv("MBSE_ROOT"));
if ((fp = fopen(path, "r")) != NULL) {
fread(&ndhdr, sizeof(ndhdr), 1, fp);
while (fread(&nd, ndhdr.recsize, 1, fp) == 1) {
fseek(fp, ndhdr.filegrp + ndhdr.mailgrp, SEEK_CUR);
for (i = 0; i < 20; i++) {
if ((addr->zone == nd.Aka[i].zone) && (addr->net == nd.Aka[i].net) &&
(addr->node == nd.Aka[i].node) && (addr->point == nd.Aka[i].point)) {
ndrecord = TRUE;
break;
}
}
if (ndrecord)
break;
}
nodebuf.addr.name = nodebuf.sysop;
nodebuf.addr.domain = xstrcpy(fdx.domain);
nodebuf.upnet = ndx.upnet;
nodebuf.upnode = ndx.upnode;
nodebuf.region = ndx.region;
if (addr->domain == NULL)
addr->domain = xstrcpy(nodebuf.addr.domain);
fclose(fp);
}
free(path);
free(mydomain);
return &nodebuf;
nodebuf.type = ndx.type;
nodebuf.pflag = ndx.pflag;
if (*(p = buf + strlen(buf) -1) == '\n')
*p = '\0';
if (*(p = buf + strlen(buf) -1) == '\r')
*p = '\0';
for (p = buf; *p; p++)
if (*p == '_')
*p = ' ';
p = buf;
if ((q = strchr(p,',')))
*q++ = '\0';
p = q;
if (p == NULL)
goto badsyntax;
if ((q=strchr(p,',')))
*q++ = '\0';
p = q;
if (p == NULL)
goto badsyntax;
/*
* Get system name
*/
if ((q=strchr(p,',')))
*q++ = '\0';
if (ndrecord && strlen(nd.Nl_hostname))
nodebuf.name = nd.Nl_hostname;
else
nodebuf.name = p;
p = q;
if (p == NULL)
goto badsyntax;
/*
* Get location
*/
if ((q=strchr(p,',')))
*q++ = '\0';
nodebuf.location = p;
p = q;
if (p == NULL)
goto badsyntax;
/*
* Get sysop name
*/
if ((q=strchr(p,',')))
*q++ = '\0';
nodebuf.sysop = p;
p = q;
if (p == NULL)
goto badsyntax;
/*
* Get phone number
*/
if ((q=strchr(p,',')))
*q++ = '\0';
if (strcasecmp(p, "-Unpublished-") == 0)
nodebuf.phone = NULL;
else
nodebuf.phone = p;
p = q;
if (p == NULL)
goto badsyntax;
/*
* Get modem speed
*/
if ((q=strchr(p,',')))
*q++ = '\0';
nodebuf.speed = atoi(p);
/*
* Process the nodelist flags, get them from the node override
* field if this is present, else use the nodelist.
*/
if (ndrecord && strlen(nd.Nl_flags))
q = nd.Nl_flags;
ixflag = 0;
stdflag = TRUE;
for (p = q; p; p = q) {
if ((q = strchr(p, ',')))
*q++ = '\0';
if ((strncasecmp(p, "U", 1) == 0) && (strlen(p) == 1)) {
stdflag = FALSE;
} else {
/*
* Experimental: process authorized flags and
* User flags both as authorized.
*/
for (j = 0; fkey[j].key; j++)
if (strcasecmp(p, fkey[j].key) == 0)
nodebuf.mflags |= fkey[j].flag;
for (j = 0; okey[j].key; j++)
if (strcasecmp(p, okey[j].key) == 0)
nodebuf.oflags |= okey[j].flag;
for (j = 0; dkey[j].key; j++)
if (strcasecmp(p, dkey[j].key) == 0)
nodebuf.dflags |= dkey[j].flag;
for (j = 0; ikey[j].key; j++)
if (strncasecmp(p, ikey[j].key, strlen(ikey[j].key)) == 0)
nodebuf.iflags |= ikey[j].flag;
for (j = 0; xkey[j].key; j++)
if (strcasecmp(p, xkey[j].key) == 0)
nodebuf.xflags |= xkey[j].flag;
if ((p[0] == 'T') && (strlen(p) == 3)) {
/*
* System open hours flag
*/
nodebuf.t1 = p[1];
nodebuf.t2 = p[2];
}
if (!stdflag) {
if (ixflag < MAXUFLAGS) {
nodebuf.uflags[ixflag++] = p;
if (ixflag < MAXUFLAGS)
nodebuf.uflags[ixflag] = NULL;
}
}
}
}
nodebuf.addr.name = nodebuf.sysop;
nodebuf.addr.domain = xstrcpy(fdx.domain);
nodebuf.upnet = ndx.upnet;
nodebuf.upnode = ndx.upnode;
nodebuf.region = ndx.region;
if (addr->domain == NULL)
addr->domain = xstrcpy(nodebuf.addr.domain);
free(mydomain);
return &nodebuf;
badsyntax:
tasklog('?', "nodelist %d offset +%lu: bad syntax in line \"%s\"",
ndx.fileno, (unsigned long)ndx.offset, buf);
/* fallthrough */
tasklog('?', "nodelist %d offset +%lu: bad syntax in line \"%s\"", ndx.fileno, (unsigned long)ndx.offset, buf);
/* fallthrough */
retdummy:
memset(&nodebuf, 0, sizeof(nodebuf));
nodebuf.pflag = NL_DUMMY;
nodebuf.name = (char *)"Unknown";
nodebuf.location = (char *)"Nowhere";
nodebuf.sysop = (char *)"Sysop";
nodebuf.phone = NULL;
nodebuf.speed = 2400;
free(mydomain);
memset(&nodebuf, 0, sizeof(nodebuf));
nodebuf.pflag = NL_DUMMY;
nodebuf.name = (char *)"Unknown";
nodebuf.location = (char *)"Nowhere";
nodebuf.sysop = (char *)"Sysop";
nodebuf.phone = NULL;
nodebuf.speed = 2400;
free(mydomain);
return &nodebuf;
return &nodebuf;
}