/*
* tcpdchk - examine all tcpd access control rules and inetd.conf entries
*
* Usage: tcpdchk [-a] [-d] [-i inet_conf] [-v]
*
* -a: complain about implicit "allow" at end of rule.
*
* -d: rules in current directory.
*
* -i: location of inetd.conf file.
*
* -v: show all rules.
*
* Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
*/
#ifndef lint
#endif
/* System libraries. */
#include <stdio.h>
#include <syslog.h>
#include <setjmp.h>
#include <errno.h>
#include <netdb.h>
#include <string.h>
extern int errno;
extern void exit();
extern int optind;
extern char *optarg;
#ifndef INADDR_NONE
#endif
#ifndef S_ISDIR
#endif
/* Application-specific. */
#include "tcpd.h"
#include "inetcf.h"
#include "scaffold.h"
/*
* Stolen from hosts_access.c...
*/
int resident = 0;
int hosts_access_verbose = 0;
/*
* Local stuff.
*/
static void usage();
static void parse_table();
static void print_list();
static void check_daemon_list();
static void check_client_list();
static void check_daemon();
static void check_user();
static int check_host();
static int reserved_name();
#define DENY 0
#define NO 0
static int defl_verdict;
static char *myname;
static int allow_check;
static char *inetcf;
int argc;
char **argv;
{
int c;
/*
* Parse the JCL.
*/
switch (c) {
case 'a':
allow_check = 1;
break;
case 'd':
hosts_allow_table = "hosts.allow";
hosts_deny_table = "hosts.deny";
break;
case 'i':
break;
case 'v':
break;
default:
usage();
/* NOTREACHED */
}
}
usage();
/*
* When confusion really strikes...
*/
}
/*
* Process the inet configuration file (or its moral equivalent). This
* information is used later to find references in hosts.allow/deny to
* unwrapped services, and other possible problems.
*/
if (hosts_access_verbose)
/*
* These are not run from inetd but may have built-in access control.
*/
/*
* Check accessibility of access control files.
*/
/*
* Fake up an arbitrary service request.
*/
RQ_DAEMON, "daemon_name",
RQ_SERVER_NAME, "server_hostname",
RQ_SERVER_ADDR, "server_addr",
RQ_USER, "user_name",
RQ_CLIENT_NAME, "client_hostname",
RQ_CLIENT_ADDR, "client_addr",
RQ_FILE, 1,
0);
/*
* Examine all access-control rules.
*/
defl_verdict = DENY;
return (0);
}
/* usage - explain */
static void usage()
{
exit(1);
}
/* parse_table - like table_match(), but examines _all_ entries */
char *table;
struct request_info *request;
{
int real_verdict;
int verdict;
tcpd_context.line = 0;
tcpd_warn("missing newline or line too long");
continue;
}
continue;
tcpd_warn("missing \":\" separator");
continue;
}
if (hosts_access_verbose)
printf("\n>>> Rule %s line %d:\n",
if (hosts_access_verbose)
if (hosts_access_verbose)
#ifdef PROCESS_OPTIONS
if (sh_cmd) {
if (verdict != 0) {
} else {
dry_run = 1;
tcpd_warn("implicit \"allow\" at end of rule");
}
} else if (defl_verdict && allow_check) {
tcpd_warn("implicit \"allow\" at end of rule");
}
if (hosts_access_verbose)
#else
if (sh_cmd)
if (hosts_access_verbose)
#endif
}
}
}
/* print_list - pretty-print a list */
char *title;
char *list;
{
char *cp;
char *next;
if (next != 0)
}
}
/* check_daemon_list - criticize daemon list */
char *list;
{
char *cp;
char *host;
int daemons = 0;
daemons = 0;
} else {
daemons++;
tcpd_warn("(consider using an address instead)");
}
}
}
if (daemons == 0)
tcpd_warn("daemon list is empty or ends in EXCEPT");
}
/* check_client_list - criticize client list */
char *list;
{
char *cp;
char *host;
int clients = 0;
clients = 0;
} else {
clients++;
check_user(cp);
} else {
check_host(cp);
}
}
}
if (clients == 0)
tcpd_warn("client list is empty or ends in EXCEPT");
}
/* check_daemon - criticize daemon pattern */
char *pat;
{
if (pat[0] == '@') {
} else if (pat[0] == '.') {
/* void */ ;
tcpd_warn("FAIL is no longer recognized");
tcpd_warn("(use EXCEPT or DENY instead)");
} else if (reserved_name(pat)) {
} else {
case WR_UNKNOWN:
break;
case WR_NOT:
break;
}
}
}
/* check_user - criticize user pattern */
char *pat;
{
} else if (pat[0] == '.') {
/* void */ ;
tcpd_warn("FAIL is no longer recognized");
tcpd_warn("(use EXCEPT or DENY instead)");
} else if (reserved_name(pat)) {
}
}
/* check_host - criticize host pattern */
char *pat;
{
char *mask;
#ifdef NO_NETGRENT
/* SCO has no *netgrent() support */
#else
#ifdef NETGROUP
char *machinep;
char *userp;
char *domainp;
endnetgrent();
#else
tcpd_warn("netgroup support disabled");
#endif
#endif
#ifdef HAVE_IPV6
} else if (pat[0] == '[') {
int err = 0;
*slash = '\0';
}
err = 1;
else {
*cbr = '\0';
}
if (err)
#endif
tcpd_warn("FAIL is no longer recognized");
tcpd_warn("(use EXCEPT or DENY instead)");
/* void */ ;
} else if (pat[0] != '.') {
}
} else { /* numeric form */
/* void */ ;
} else if (pat[0] == '.') {
}
}
return (addr_count);
}
/* reserved_name - determine if name is reserved */
char *pat;
{
}