1
/* Copyright (c) 1996, 1997, 1998, 1999, 2000, 2003, 2005 Thorsten Kukuk
2
Author: Thorsten Kukuk <kukuk@suse.de>
4
The YP Server is free software; you can redistribute it and/or
5
modify it under the terms of the GNU General Public License as
6
published by the Free Software Foundation; either version 2 of the
7
License, or (at your option) any later version.
9
The YP Server is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
General Public License for more details.
14
You should have received a copy of the GNU General Public
15
License along with the YP Server; see the file COPYING. If
16
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
17
Cambridge, MA 02139, USA. */
28
#include <sys/socket.h>
29
#include <netinet/in.h>
30
#include <arpa/inet.h>
36
#define SECURENETS "securenets"
39
typedef struct securenet
41
struct in_addr netmask;
42
struct in_addr network;
43
struct securenet *next;
47
static securenet_t *securenets = NULL;
50
load_securenets (void)
52
char buf1[128], buf2[128], buf3[128];
54
securenet_t *work, *tmp;
57
/* If securenets isn't NULL, we should reload the securents file. */
58
if (securenets != NULL)
60
log_msg ("Reloading securenets file\n");
61
while (securenets != NULL)
64
securenets = securenets->next;
72
if ((in = fopen (SECURENETS, "r")) == NULL)
74
log_msg ("WARNING: no %s file found!\n", SECURENETS);
82
memset (buf1, 0, sizeof (buf1));
83
memset (buf2, 0, sizeof (buf2));
84
memset (buf3, 0, sizeof (buf3));
85
fgets (buf3, 128, in);
88
if (buf3[0] == '\0' || buf3[0] == '#' || buf3[0] == '\n')
91
if (sscanf (buf3, "%s %s", buf1, buf2) != 2)
93
log_msg ("securenets(%d): malformed line, ignore it\n", line);
97
if ((tmp = malloc (sizeof (securenet_t))) == NULL)
99
log_msg ("ERROR: could not allocate enough memory! [%s|%d]\n",
106
if (strcmp (buf1, "host") == 0)
108
strcpy (buf1, "255.255.255.255");
111
else if (strcmp (buf1, "255.255.255.255") == 0)
114
#if defined(HAVE_INET_ATON)
115
if (!inet_aton (buf1, &tmp->netmask) && !host)
117
if ((tmp->netmask.s_addr = inet_addr (buf1)) == (-1) && !host)
120
log_msg ("securenets(%d): %s is not a correct netmask!\n", line,
126
#if defined(HAVE_INET_ATON)
127
if (!inet_aton (buf2, &tmp->network))
129
if ((tmp->network.s_addr = inet_addr (buf2)) == (-1))
132
log_msg ("securenets(%d): %s is not a correct network address!\n",
156
char *p1 = strdup (inet_ntoa (tmp->netmask));
157
char *p2 = strdup (inet_ntoa (tmp->network));
159
if (p1 != NULL && p2 != NULL)
161
log_msg ("Find securenet: %s %s", p1, p2);
172
securenet_host (const struct in_addr sin_addr)
183
if ((ptr->netmask.s_addr & sin_addr.s_addr) == ptr->network.s_addr)