1998-07-15 11:31:55 +04:00
|
|
|
/* $NetBSD: config.c,v 1.5 1998/07/15 07:31:56 msaitoh Exp $ */
|
1997-10-08 11:07:40 +04:00
|
|
|
|
1994-02-05 00:41:32 +03:00
|
|
|
/*
|
|
|
|
** config.c This file handles the config file
|
|
|
|
**
|
|
|
|
** This program is in the public domain and may be used freely by anyone
|
|
|
|
** who wants to.
|
|
|
|
**
|
|
|
|
** Last update: 6 Dec 1992
|
|
|
|
**
|
|
|
|
** Please send bug fixes/bug reports to: Peter Eriksson <pen@lysator.liu.se>
|
|
|
|
*/
|
|
|
|
|
1997-10-08 11:07:40 +04:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netinet/in.h>
|
1998-07-15 11:31:55 +04:00
|
|
|
#include <arpa/inet.h>
|
1997-10-08 11:07:40 +04:00
|
|
|
|
1994-02-05 00:41:32 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
1998-07-15 11:31:55 +04:00
|
|
|
#include <string.h>
|
1994-02-05 00:41:32 +03:00
|
|
|
|
|
|
|
#include "error.h"
|
|
|
|
#include "identd.h"
|
|
|
|
#include "paths.h"
|
|
|
|
|
1998-07-15 11:31:55 +04:00
|
|
|
#define MAXLINE 1024
|
|
|
|
#define MAXNETS 1024
|
|
|
|
|
|
|
|
u_long localnet[MAXNETS], localmask[MAXNETS];
|
|
|
|
int netcnt;
|
1994-02-05 00:41:32 +03:00
|
|
|
|
|
|
|
int parse_config(path, silent_flag)
|
|
|
|
char *path;
|
|
|
|
int silent_flag;
|
|
|
|
{
|
|
|
|
FILE *fp;
|
1998-07-15 11:31:55 +04:00
|
|
|
char *start, buf[MAXLINE];
|
1994-02-05 00:41:32 +03:00
|
|
|
|
|
|
|
if (!path)
|
|
|
|
path = PATH_CONFIG;
|
|
|
|
|
|
|
|
fp = fopen(path, "r");
|
|
|
|
if (!fp)
|
|
|
|
{
|
|
|
|
if (silent_flag)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
ERROR1("error opening %s", path);
|
|
|
|
}
|
|
|
|
|
1998-07-15 11:31:55 +04:00
|
|
|
netcnt = 0;
|
|
|
|
while ((start = fgets(buf, sizeof buf, fp)) != NULL) {
|
|
|
|
char *net, *mask;
|
|
|
|
char *cmd = strtok(buf, " \t");
|
|
|
|
if (cmd) {
|
|
|
|
if (!strcmp("trusted-net:", cmd)) {
|
|
|
|
if (netcnt >= MAXNETS) {
|
|
|
|
if (!silent_flag)
|
|
|
|
ERROR1("too many networks defined in %s", path);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
net = strtok(NULL, " \t");
|
|
|
|
if (net) {
|
|
|
|
localnet[netcnt] = inet_network(net);
|
|
|
|
mask = strtok(NULL, " \t");
|
|
|
|
if (mask) {
|
|
|
|
localmask[netcnt] = inet_network(mask);
|
|
|
|
} else {
|
|
|
|
localmask[netcnt] = 0xFFFFFFFFL;
|
|
|
|
}
|
|
|
|
if ((localnet[netcnt] & localmask[netcnt]) == localnet[netcnt]) {
|
|
|
|
netcnt++;
|
|
|
|
} else if (!silent_flag) {
|
|
|
|
ERROR1("netmask does not match network %s", net);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!silent_flag)
|
|
|
|
ERROR2("format error in %s cmd %s", path, cmd);
|
|
|
|
}
|
|
|
|
} else if (*cmd != '#') {
|
|
|
|
ERROR2("unknown config statement %s in file %s", cmd, path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1994-02-05 00:41:32 +03:00
|
|
|
fclose(fp);
|
|
|
|
return 0;
|
|
|
|
}
|