17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * tcpdchk - examine all tcpd access control rules and inetd.conf entries
3*55fea89dSDan Cross *
47c478bd9Sstevel@tonic-gate * Usage: tcpdchk [-a] [-d] [-i inet_conf] [-v]
5*55fea89dSDan Cross *
67c478bd9Sstevel@tonic-gate * -a: complain about implicit "allow" at end of rule.
7*55fea89dSDan Cross *
87c478bd9Sstevel@tonic-gate * -d: rules in current directory.
9*55fea89dSDan Cross *
107c478bd9Sstevel@tonic-gate * -i: location of inetd.conf file.
11*55fea89dSDan Cross *
127c478bd9Sstevel@tonic-gate * -v: show all rules.
13*55fea89dSDan Cross *
147c478bd9Sstevel@tonic-gate * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
157c478bd9Sstevel@tonic-gate */
167c478bd9Sstevel@tonic-gate
177c478bd9Sstevel@tonic-gate #ifndef lint
187c478bd9Sstevel@tonic-gate static char sccsid[] = "@(#) tcpdchk.c 1.8 97/02/12 02:13:25";
197c478bd9Sstevel@tonic-gate #endif
207c478bd9Sstevel@tonic-gate
217c478bd9Sstevel@tonic-gate /* System libraries. */
227c478bd9Sstevel@tonic-gate
237c478bd9Sstevel@tonic-gate #include <sys/types.h>
247c478bd9Sstevel@tonic-gate #include <sys/stat.h>
257c478bd9Sstevel@tonic-gate #include <netinet/in.h>
267c478bd9Sstevel@tonic-gate #include <arpa/inet.h>
277c478bd9Sstevel@tonic-gate #include <stdio.h>
287c478bd9Sstevel@tonic-gate #include <syslog.h>
297c478bd9Sstevel@tonic-gate #include <setjmp.h>
307c478bd9Sstevel@tonic-gate #include <errno.h>
317c478bd9Sstevel@tonic-gate #include <netdb.h>
327c478bd9Sstevel@tonic-gate #include <string.h>
337c478bd9Sstevel@tonic-gate
347c478bd9Sstevel@tonic-gate extern int errno;
357c478bd9Sstevel@tonic-gate extern void exit();
367c478bd9Sstevel@tonic-gate extern int optind;
377c478bd9Sstevel@tonic-gate extern char *optarg;
387c478bd9Sstevel@tonic-gate
397c478bd9Sstevel@tonic-gate #ifndef INADDR_NONE
407c478bd9Sstevel@tonic-gate #define INADDR_NONE (-1) /* XXX should be 0xffffffff */
417c478bd9Sstevel@tonic-gate #endif
427c478bd9Sstevel@tonic-gate
437c478bd9Sstevel@tonic-gate #ifndef S_ISDIR
447c478bd9Sstevel@tonic-gate #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
457c478bd9Sstevel@tonic-gate #endif
467c478bd9Sstevel@tonic-gate
477c478bd9Sstevel@tonic-gate /* Application-specific. */
487c478bd9Sstevel@tonic-gate
497c478bd9Sstevel@tonic-gate #include "tcpd.h"
507c478bd9Sstevel@tonic-gate #include "inetcf.h"
517c478bd9Sstevel@tonic-gate #include "scaffold.h"
527c478bd9Sstevel@tonic-gate
537c478bd9Sstevel@tonic-gate /*
547c478bd9Sstevel@tonic-gate * Stolen from hosts_access.c...
557c478bd9Sstevel@tonic-gate */
567c478bd9Sstevel@tonic-gate static char sep[] = ", \t\n";
577c478bd9Sstevel@tonic-gate
587c478bd9Sstevel@tonic-gate #define BUFLEN 2048
597c478bd9Sstevel@tonic-gate
607c478bd9Sstevel@tonic-gate int resident = 0;
617c478bd9Sstevel@tonic-gate int hosts_access_verbose = 0;
627c478bd9Sstevel@tonic-gate char *hosts_allow_table = HOSTS_ALLOW;
637c478bd9Sstevel@tonic-gate char *hosts_deny_table = HOSTS_DENY;
647c478bd9Sstevel@tonic-gate extern jmp_buf tcpd_buf;
657c478bd9Sstevel@tonic-gate
667c478bd9Sstevel@tonic-gate /*
677c478bd9Sstevel@tonic-gate * Local stuff.
687c478bd9Sstevel@tonic-gate */
697c478bd9Sstevel@tonic-gate static void usage();
707c478bd9Sstevel@tonic-gate static void parse_table();
717c478bd9Sstevel@tonic-gate static void print_list();
727c478bd9Sstevel@tonic-gate static void check_daemon_list();
737c478bd9Sstevel@tonic-gate static void check_client_list();
747c478bd9Sstevel@tonic-gate static void check_daemon();
757c478bd9Sstevel@tonic-gate static void check_user();
767c478bd9Sstevel@tonic-gate static int check_host();
777c478bd9Sstevel@tonic-gate static int reserved_name();
787c478bd9Sstevel@tonic-gate
797c478bd9Sstevel@tonic-gate #define PERMIT 1
807c478bd9Sstevel@tonic-gate #define DENY 0
817c478bd9Sstevel@tonic-gate
827c478bd9Sstevel@tonic-gate #define YES 1
837c478bd9Sstevel@tonic-gate #define NO 0
847c478bd9Sstevel@tonic-gate
857c478bd9Sstevel@tonic-gate static int defl_verdict;
867c478bd9Sstevel@tonic-gate static char *myname;
877c478bd9Sstevel@tonic-gate static int allow_check;
887c478bd9Sstevel@tonic-gate static char *inetcf;
897c478bd9Sstevel@tonic-gate
main(argc,argv)907c478bd9Sstevel@tonic-gate int main(argc, argv)
917c478bd9Sstevel@tonic-gate int argc;
927c478bd9Sstevel@tonic-gate char **argv;
937c478bd9Sstevel@tonic-gate {
947c478bd9Sstevel@tonic-gate struct request_info request;
957c478bd9Sstevel@tonic-gate struct stat st;
967c478bd9Sstevel@tonic-gate int c;
977c478bd9Sstevel@tonic-gate
987c478bd9Sstevel@tonic-gate myname = argv[0];
997c478bd9Sstevel@tonic-gate
1007c478bd9Sstevel@tonic-gate /*
1017c478bd9Sstevel@tonic-gate * Parse the JCL.
1027c478bd9Sstevel@tonic-gate */
1037c478bd9Sstevel@tonic-gate while ((c = getopt(argc, argv, "adi:v")) != EOF) {
1047c478bd9Sstevel@tonic-gate switch (c) {
1057c478bd9Sstevel@tonic-gate case 'a':
1067c478bd9Sstevel@tonic-gate allow_check = 1;
1077c478bd9Sstevel@tonic-gate break;
1087c478bd9Sstevel@tonic-gate case 'd':
1097c478bd9Sstevel@tonic-gate hosts_allow_table = "hosts.allow";
1107c478bd9Sstevel@tonic-gate hosts_deny_table = "hosts.deny";
1117c478bd9Sstevel@tonic-gate break;
1127c478bd9Sstevel@tonic-gate case 'i':
1137c478bd9Sstevel@tonic-gate inetcf = optarg;
1147c478bd9Sstevel@tonic-gate break;
1157c478bd9Sstevel@tonic-gate case 'v':
1167c478bd9Sstevel@tonic-gate hosts_access_verbose++;
1177c478bd9Sstevel@tonic-gate break;
1187c478bd9Sstevel@tonic-gate default:
1197c478bd9Sstevel@tonic-gate usage();
1207c478bd9Sstevel@tonic-gate /* NOTREACHED */
1217c478bd9Sstevel@tonic-gate }
1227c478bd9Sstevel@tonic-gate }
1237c478bd9Sstevel@tonic-gate if (argc != optind)
1247c478bd9Sstevel@tonic-gate usage();
1257c478bd9Sstevel@tonic-gate
1267c478bd9Sstevel@tonic-gate /*
1277c478bd9Sstevel@tonic-gate * When confusion really strikes...
1287c478bd9Sstevel@tonic-gate */
1297c478bd9Sstevel@tonic-gate if (check_path(REAL_DAEMON_DIR, &st) < 0) {
1307c478bd9Sstevel@tonic-gate tcpd_warn("REAL_DAEMON_DIR %s: %m", REAL_DAEMON_DIR);
1317c478bd9Sstevel@tonic-gate } else if (!S_ISDIR(st.st_mode)) {
1327c478bd9Sstevel@tonic-gate tcpd_warn("REAL_DAEMON_DIR %s is not a directory", REAL_DAEMON_DIR);
1337c478bd9Sstevel@tonic-gate }
1347c478bd9Sstevel@tonic-gate
1357c478bd9Sstevel@tonic-gate /*
1367c478bd9Sstevel@tonic-gate * Process the inet configuration file (or its moral equivalent). This
1377c478bd9Sstevel@tonic-gate * information is used later to find references in hosts.allow/deny to
1387c478bd9Sstevel@tonic-gate * unwrapped services, and other possible problems.
1397c478bd9Sstevel@tonic-gate */
1407c478bd9Sstevel@tonic-gate inetcf = inet_cfg(inetcf);
1417c478bd9Sstevel@tonic-gate if (hosts_access_verbose)
1427c478bd9Sstevel@tonic-gate printf("Using network configuration file: %s\n", inetcf);
1437c478bd9Sstevel@tonic-gate
1447c478bd9Sstevel@tonic-gate /*
1457c478bd9Sstevel@tonic-gate * These are not run from inetd but may have built-in access control.
1467c478bd9Sstevel@tonic-gate */
1477c478bd9Sstevel@tonic-gate inet_set("portmap", WR_NOT);
1487c478bd9Sstevel@tonic-gate inet_set("rpcbind", WR_NOT);
1497c478bd9Sstevel@tonic-gate
1507c478bd9Sstevel@tonic-gate /*
1517c478bd9Sstevel@tonic-gate * Check accessibility of access control files.
1527c478bd9Sstevel@tonic-gate */
1537c478bd9Sstevel@tonic-gate (void) check_path(hosts_allow_table, &st);
1547c478bd9Sstevel@tonic-gate (void) check_path(hosts_deny_table, &st);
1557c478bd9Sstevel@tonic-gate
1567c478bd9Sstevel@tonic-gate /*
1577c478bd9Sstevel@tonic-gate * Fake up an arbitrary service request.
1587c478bd9Sstevel@tonic-gate */
1597c478bd9Sstevel@tonic-gate request_init(&request,
1607c478bd9Sstevel@tonic-gate RQ_DAEMON, "daemon_name",
1617c478bd9Sstevel@tonic-gate RQ_SERVER_NAME, "server_hostname",
1627c478bd9Sstevel@tonic-gate RQ_SERVER_ADDR, "server_addr",
1637c478bd9Sstevel@tonic-gate RQ_USER, "user_name",
1647c478bd9Sstevel@tonic-gate RQ_CLIENT_NAME, "client_hostname",
1657c478bd9Sstevel@tonic-gate RQ_CLIENT_ADDR, "client_addr",
1667c478bd9Sstevel@tonic-gate RQ_FILE, 1,
1677c478bd9Sstevel@tonic-gate 0);
1687c478bd9Sstevel@tonic-gate
1697c478bd9Sstevel@tonic-gate /*
1707c478bd9Sstevel@tonic-gate * Examine all access-control rules.
1717c478bd9Sstevel@tonic-gate */
1727c478bd9Sstevel@tonic-gate defl_verdict = PERMIT;
1737c478bd9Sstevel@tonic-gate parse_table(hosts_allow_table, &request);
1747c478bd9Sstevel@tonic-gate defl_verdict = DENY;
1757c478bd9Sstevel@tonic-gate parse_table(hosts_deny_table, &request);
1767c478bd9Sstevel@tonic-gate return (0);
1777c478bd9Sstevel@tonic-gate }
1787c478bd9Sstevel@tonic-gate
1797c478bd9Sstevel@tonic-gate /* usage - explain */
1807c478bd9Sstevel@tonic-gate
usage()1817c478bd9Sstevel@tonic-gate static void usage()
1827c478bd9Sstevel@tonic-gate {
1837c478bd9Sstevel@tonic-gate fprintf(stderr, "usage: %s [-a] [-d] [-i inet_conf] [-v]\n", myname);
1847c478bd9Sstevel@tonic-gate fprintf(stderr, " -a: report rules with implicit \"ALLOW\" at end\n");
1857c478bd9Sstevel@tonic-gate fprintf(stderr, " -d: use allow/deny files in current directory\n");
1867c478bd9Sstevel@tonic-gate fprintf(stderr, " -i: location of inetd.conf file\n");
1877c478bd9Sstevel@tonic-gate fprintf(stderr, " -v: list all rules\n");
1887c478bd9Sstevel@tonic-gate exit(1);
1897c478bd9Sstevel@tonic-gate }
1907c478bd9Sstevel@tonic-gate
1917c478bd9Sstevel@tonic-gate /* parse_table - like table_match(), but examines _all_ entries */
1927c478bd9Sstevel@tonic-gate
parse_table(table,request)1937c478bd9Sstevel@tonic-gate static void parse_table(table, request)
1947c478bd9Sstevel@tonic-gate char *table;
1957c478bd9Sstevel@tonic-gate struct request_info *request;
1967c478bd9Sstevel@tonic-gate {
1977c478bd9Sstevel@tonic-gate FILE *fp;
1987c478bd9Sstevel@tonic-gate int real_verdict;
1997c478bd9Sstevel@tonic-gate char sv_list[BUFLEN]; /* becomes list of daemons */
2007c478bd9Sstevel@tonic-gate char *cl_list; /* becomes list of requests */
2017c478bd9Sstevel@tonic-gate char *sh_cmd; /* becomes optional shell command */
2027c478bd9Sstevel@tonic-gate char buf[BUFSIZ];
2037c478bd9Sstevel@tonic-gate int verdict;
2047c478bd9Sstevel@tonic-gate struct tcpd_context saved_context;
2057c478bd9Sstevel@tonic-gate
2067c478bd9Sstevel@tonic-gate saved_context = tcpd_context; /* stupid compilers */
2077c478bd9Sstevel@tonic-gate
2087c478bd9Sstevel@tonic-gate if (fp = fopen(table, "r")) {
2097c478bd9Sstevel@tonic-gate tcpd_context.file = table;
2107c478bd9Sstevel@tonic-gate tcpd_context.line = 0;
2117c478bd9Sstevel@tonic-gate while (xgets(sv_list, sizeof(sv_list), fp)) {
2127c478bd9Sstevel@tonic-gate if (sv_list[strlen(sv_list) - 1] != '\n') {
2137c478bd9Sstevel@tonic-gate tcpd_warn("missing newline or line too long");
2147c478bd9Sstevel@tonic-gate continue;
2157c478bd9Sstevel@tonic-gate }
2167c478bd9Sstevel@tonic-gate if (sv_list[0] == '#' || sv_list[strspn(sv_list, " \t\r\n")] == 0)
2177c478bd9Sstevel@tonic-gate continue;
2187c478bd9Sstevel@tonic-gate if ((cl_list = split_at(skip_ipv6_addrs(sv_list), ':')) == 0) {
2197c478bd9Sstevel@tonic-gate tcpd_warn("missing \":\" separator");
2207c478bd9Sstevel@tonic-gate continue;
2217c478bd9Sstevel@tonic-gate }
2227c478bd9Sstevel@tonic-gate sh_cmd = split_at(skip_ipv6_addrs(cl_list), ':');
2237c478bd9Sstevel@tonic-gate
2247c478bd9Sstevel@tonic-gate if (hosts_access_verbose)
2257c478bd9Sstevel@tonic-gate printf("\n>>> Rule %s line %d:\n",
2267c478bd9Sstevel@tonic-gate tcpd_context.file, tcpd_context.line);
2277c478bd9Sstevel@tonic-gate
2287c478bd9Sstevel@tonic-gate if (hosts_access_verbose)
2297c478bd9Sstevel@tonic-gate print_list("daemons: ", sv_list);
2307c478bd9Sstevel@tonic-gate check_daemon_list(sv_list);
2317c478bd9Sstevel@tonic-gate
2327c478bd9Sstevel@tonic-gate if (hosts_access_verbose)
2337c478bd9Sstevel@tonic-gate print_list("clients: ", cl_list);
2347c478bd9Sstevel@tonic-gate check_client_list(cl_list);
2357c478bd9Sstevel@tonic-gate
2367c478bd9Sstevel@tonic-gate #ifdef PROCESS_OPTIONS
2377c478bd9Sstevel@tonic-gate real_verdict = defl_verdict;
2387c478bd9Sstevel@tonic-gate if (sh_cmd) {
2397c478bd9Sstevel@tonic-gate verdict = setjmp(tcpd_buf);
2407c478bd9Sstevel@tonic-gate if (verdict != 0) {
2417c478bd9Sstevel@tonic-gate real_verdict = (verdict == AC_PERMIT);
2427c478bd9Sstevel@tonic-gate } else {
2437c478bd9Sstevel@tonic-gate dry_run = 1;
2447c478bd9Sstevel@tonic-gate process_options(sh_cmd, request);
2457c478bd9Sstevel@tonic-gate if (dry_run == 1 && real_verdict && allow_check)
2467c478bd9Sstevel@tonic-gate tcpd_warn("implicit \"allow\" at end of rule");
2477c478bd9Sstevel@tonic-gate }
2487c478bd9Sstevel@tonic-gate } else if (defl_verdict && allow_check) {
2497c478bd9Sstevel@tonic-gate tcpd_warn("implicit \"allow\" at end of rule");
2507c478bd9Sstevel@tonic-gate }
2517c478bd9Sstevel@tonic-gate if (hosts_access_verbose)
2527c478bd9Sstevel@tonic-gate printf("access: %s\n", real_verdict ? "granted" : "denied");
2537c478bd9Sstevel@tonic-gate #else
2547c478bd9Sstevel@tonic-gate if (sh_cmd)
2557c478bd9Sstevel@tonic-gate shell_cmd(percent_x(buf, sizeof(buf), sh_cmd, request));
2567c478bd9Sstevel@tonic-gate if (hosts_access_verbose)
2577c478bd9Sstevel@tonic-gate printf("access: %s\n", defl_verdict ? "granted" : "denied");
2587c478bd9Sstevel@tonic-gate #endif
2597c478bd9Sstevel@tonic-gate }
2607c478bd9Sstevel@tonic-gate (void) fclose(fp);
2617c478bd9Sstevel@tonic-gate } else if (errno != ENOENT) {
2627c478bd9Sstevel@tonic-gate tcpd_warn("cannot open %s: %m", table);
2637c478bd9Sstevel@tonic-gate }
2647c478bd9Sstevel@tonic-gate tcpd_context = saved_context;
2657c478bd9Sstevel@tonic-gate }
2667c478bd9Sstevel@tonic-gate
2677c478bd9Sstevel@tonic-gate /* print_list - pretty-print a list */
2687c478bd9Sstevel@tonic-gate
print_list(title,list)2697c478bd9Sstevel@tonic-gate static void print_list(title, list)
2707c478bd9Sstevel@tonic-gate char *title;
2717c478bd9Sstevel@tonic-gate char *list;
2727c478bd9Sstevel@tonic-gate {
2737c478bd9Sstevel@tonic-gate char buf[BUFLEN];
2747c478bd9Sstevel@tonic-gate char *cp;
2757c478bd9Sstevel@tonic-gate char *next;
2767c478bd9Sstevel@tonic-gate
2777c478bd9Sstevel@tonic-gate fputs(title, stdout);
2787c478bd9Sstevel@tonic-gate strcpy(buf, list);
2797c478bd9Sstevel@tonic-gate
2807c478bd9Sstevel@tonic-gate for (cp = strtok(buf, sep); cp != 0; cp = next) {
2817c478bd9Sstevel@tonic-gate fputs(cp, stdout);
2827c478bd9Sstevel@tonic-gate next = strtok((char *) 0, sep);
2837c478bd9Sstevel@tonic-gate if (next != 0)
2847c478bd9Sstevel@tonic-gate fputs(" ", stdout);
2857c478bd9Sstevel@tonic-gate }
2867c478bd9Sstevel@tonic-gate fputs("\n", stdout);
2877c478bd9Sstevel@tonic-gate }
2887c478bd9Sstevel@tonic-gate
2897c478bd9Sstevel@tonic-gate /* check_daemon_list - criticize daemon list */
2907c478bd9Sstevel@tonic-gate
check_daemon_list(list)2917c478bd9Sstevel@tonic-gate static void check_daemon_list(list)
2927c478bd9Sstevel@tonic-gate char *list;
2937c478bd9Sstevel@tonic-gate {
2947c478bd9Sstevel@tonic-gate char buf[BUFLEN];
2957c478bd9Sstevel@tonic-gate char *cp;
2967c478bd9Sstevel@tonic-gate char *host;
2977c478bd9Sstevel@tonic-gate int daemons = 0;
2987c478bd9Sstevel@tonic-gate
2997c478bd9Sstevel@tonic-gate strcpy(buf, list);
3007c478bd9Sstevel@tonic-gate
3017c478bd9Sstevel@tonic-gate for (cp = strtok(buf, sep); cp != 0; cp = strtok((char *) 0, sep)) {
3027c478bd9Sstevel@tonic-gate if (STR_EQ(cp, "EXCEPT")) {
3037c478bd9Sstevel@tonic-gate daemons = 0;
3047c478bd9Sstevel@tonic-gate } else {
3057c478bd9Sstevel@tonic-gate daemons++;
3067c478bd9Sstevel@tonic-gate if ((host = split_at(cp + 1, '@')) != 0 && check_host(host) > 1) {
3077c478bd9Sstevel@tonic-gate tcpd_warn("host %s has more than one address", host);
3087c478bd9Sstevel@tonic-gate tcpd_warn("(consider using an address instead)");
3097c478bd9Sstevel@tonic-gate }
3107c478bd9Sstevel@tonic-gate check_daemon(cp);
3117c478bd9Sstevel@tonic-gate }
3127c478bd9Sstevel@tonic-gate }
3137c478bd9Sstevel@tonic-gate if (daemons == 0)
3147c478bd9Sstevel@tonic-gate tcpd_warn("daemon list is empty or ends in EXCEPT");
3157c478bd9Sstevel@tonic-gate }
3167c478bd9Sstevel@tonic-gate
3177c478bd9Sstevel@tonic-gate /* check_client_list - criticize client list */
3187c478bd9Sstevel@tonic-gate
check_client_list(list)3197c478bd9Sstevel@tonic-gate static void check_client_list(list)
3207c478bd9Sstevel@tonic-gate char *list;
3217c478bd9Sstevel@tonic-gate {
3227c478bd9Sstevel@tonic-gate char buf[BUFLEN];
3237c478bd9Sstevel@tonic-gate char *cp;
3247c478bd9Sstevel@tonic-gate char *host;
3257c478bd9Sstevel@tonic-gate int clients = 0;
3267c478bd9Sstevel@tonic-gate
3277c478bd9Sstevel@tonic-gate strcpy(buf, list);
3287c478bd9Sstevel@tonic-gate
3297c478bd9Sstevel@tonic-gate for (cp = strtok(buf, sep); cp != 0; cp = strtok((char *) 0, sep)) {
3307c478bd9Sstevel@tonic-gate if (STR_EQ(cp, "EXCEPT")) {
3317c478bd9Sstevel@tonic-gate clients = 0;
3327c478bd9Sstevel@tonic-gate } else {
3337c478bd9Sstevel@tonic-gate clients++;
3347c478bd9Sstevel@tonic-gate if (host = split_at(cp + 1, '@')) { /* user@host */
3357c478bd9Sstevel@tonic-gate check_user(cp);
3367c478bd9Sstevel@tonic-gate check_host(host);
3377c478bd9Sstevel@tonic-gate } else {
3387c478bd9Sstevel@tonic-gate check_host(cp);
3397c478bd9Sstevel@tonic-gate }
3407c478bd9Sstevel@tonic-gate }
3417c478bd9Sstevel@tonic-gate }
3427c478bd9Sstevel@tonic-gate if (clients == 0)
3437c478bd9Sstevel@tonic-gate tcpd_warn("client list is empty or ends in EXCEPT");
3447c478bd9Sstevel@tonic-gate }
3457c478bd9Sstevel@tonic-gate
3467c478bd9Sstevel@tonic-gate /* check_daemon - criticize daemon pattern */
3477c478bd9Sstevel@tonic-gate
check_daemon(pat)3487c478bd9Sstevel@tonic-gate static void check_daemon(pat)
3497c478bd9Sstevel@tonic-gate char *pat;
3507c478bd9Sstevel@tonic-gate {
3517c478bd9Sstevel@tonic-gate if (pat[0] == '@') {
3527c478bd9Sstevel@tonic-gate tcpd_warn("%s: daemon name begins with \"@\"", pat);
3537c478bd9Sstevel@tonic-gate } else if (pat[0] == '.') {
3547c478bd9Sstevel@tonic-gate tcpd_warn("%s: daemon name begins with dot", pat);
3557c478bd9Sstevel@tonic-gate } else if (pat[strlen(pat) - 1] == '.') {
3567c478bd9Sstevel@tonic-gate tcpd_warn("%s: daemon name ends in dot", pat);
3577c478bd9Sstevel@tonic-gate } else if (STR_EQ(pat, "ALL") || STR_EQ(pat, unknown)) {
3587c478bd9Sstevel@tonic-gate /* void */ ;
3597c478bd9Sstevel@tonic-gate } else if (STR_EQ(pat, "FAIL")) { /* obsolete */
3607c478bd9Sstevel@tonic-gate tcpd_warn("FAIL is no longer recognized");
3617c478bd9Sstevel@tonic-gate tcpd_warn("(use EXCEPT or DENY instead)");
3627c478bd9Sstevel@tonic-gate } else if (reserved_name(pat)) {
3637c478bd9Sstevel@tonic-gate tcpd_warn("%s: daemon name may be reserved word", pat);
3647c478bd9Sstevel@tonic-gate } else {
3657c478bd9Sstevel@tonic-gate switch (inet_get(pat)) {
3667c478bd9Sstevel@tonic-gate case WR_UNKNOWN:
3677c478bd9Sstevel@tonic-gate tcpd_warn("%s: no such process name in %s", pat, inetcf);
3687c478bd9Sstevel@tonic-gate inet_set(pat, WR_YES); /* shut up next time */
3697c478bd9Sstevel@tonic-gate break;
3707c478bd9Sstevel@tonic-gate case WR_NOT:
3717c478bd9Sstevel@tonic-gate tcpd_warn("%s: service possibly not wrapped", pat);
3727c478bd9Sstevel@tonic-gate inet_set(pat, WR_YES);
3737c478bd9Sstevel@tonic-gate break;
3747c478bd9Sstevel@tonic-gate }
3757c478bd9Sstevel@tonic-gate }
3767c478bd9Sstevel@tonic-gate }
3777c478bd9Sstevel@tonic-gate
3787c478bd9Sstevel@tonic-gate /* check_user - criticize user pattern */
3797c478bd9Sstevel@tonic-gate
check_user(pat)3807c478bd9Sstevel@tonic-gate static void check_user(pat)
3817c478bd9Sstevel@tonic-gate char *pat;
3827c478bd9Sstevel@tonic-gate {
3837c478bd9Sstevel@tonic-gate if (pat[0] == '@') { /* @netgroup */
3847c478bd9Sstevel@tonic-gate tcpd_warn("%s: user name begins with \"@\"", pat);
3857c478bd9Sstevel@tonic-gate } else if (pat[0] == '.') {
3867c478bd9Sstevel@tonic-gate tcpd_warn("%s: user name begins with dot", pat);
3877c478bd9Sstevel@tonic-gate } else if (pat[strlen(pat) - 1] == '.') {
3887c478bd9Sstevel@tonic-gate tcpd_warn("%s: user name ends in dot", pat);
3897c478bd9Sstevel@tonic-gate } else if (STR_EQ(pat, "ALL") || STR_EQ(pat, unknown)
3907c478bd9Sstevel@tonic-gate || STR_EQ(pat, "KNOWN")) {
3917c478bd9Sstevel@tonic-gate /* void */ ;
3927c478bd9Sstevel@tonic-gate } else if (STR_EQ(pat, "FAIL")) { /* obsolete */
3937c478bd9Sstevel@tonic-gate tcpd_warn("FAIL is no longer recognized");
3947c478bd9Sstevel@tonic-gate tcpd_warn("(use EXCEPT or DENY instead)");
3957c478bd9Sstevel@tonic-gate } else if (reserved_name(pat)) {
3967c478bd9Sstevel@tonic-gate tcpd_warn("%s: user name may be reserved word", pat);
3977c478bd9Sstevel@tonic-gate }
3987c478bd9Sstevel@tonic-gate }
3997c478bd9Sstevel@tonic-gate
4007c478bd9Sstevel@tonic-gate /* check_host - criticize host pattern */
4017c478bd9Sstevel@tonic-gate
check_host(pat)4027c478bd9Sstevel@tonic-gate static int check_host(pat)
4037c478bd9Sstevel@tonic-gate char *pat;
4047c478bd9Sstevel@tonic-gate {
4057c478bd9Sstevel@tonic-gate char *mask;
4067c478bd9Sstevel@tonic-gate int addr_count = 1;
4077c478bd9Sstevel@tonic-gate
4087c478bd9Sstevel@tonic-gate if (pat[0] == '@') { /* @netgroup */
4097c478bd9Sstevel@tonic-gate #ifdef NO_NETGRENT
4107c478bd9Sstevel@tonic-gate /* SCO has no *netgrent() support */
4117c478bd9Sstevel@tonic-gate #else
4127c478bd9Sstevel@tonic-gate #ifdef NETGROUP
4137c478bd9Sstevel@tonic-gate char *machinep;
4147c478bd9Sstevel@tonic-gate char *userp;
4157c478bd9Sstevel@tonic-gate char *domainp;
4167c478bd9Sstevel@tonic-gate
4177c478bd9Sstevel@tonic-gate setnetgrent(pat + 1);
4187c478bd9Sstevel@tonic-gate if (getnetgrent(&machinep, &userp, &domainp) == 0)
4197c478bd9Sstevel@tonic-gate tcpd_warn("%s: unknown or empty netgroup", pat + 1);
4207c478bd9Sstevel@tonic-gate endnetgrent();
4217c478bd9Sstevel@tonic-gate #else
4227c478bd9Sstevel@tonic-gate tcpd_warn("netgroup support disabled");
4237c478bd9Sstevel@tonic-gate #endif
4247c478bd9Sstevel@tonic-gate #endif
4257c478bd9Sstevel@tonic-gate #ifdef HAVE_IPV6
4267c478bd9Sstevel@tonic-gate } else if (pat[0] == '[') {
4277c478bd9Sstevel@tonic-gate struct in6_addr in6;
4287c478bd9Sstevel@tonic-gate char *cbr = strchr(pat, ']');
4297c478bd9Sstevel@tonic-gate char *slash = strchr(pat, '/');
4307c478bd9Sstevel@tonic-gate int err = 0;
4317c478bd9Sstevel@tonic-gate int mask = IPV6_ABITS;
4327c478bd9Sstevel@tonic-gate
4337c478bd9Sstevel@tonic-gate if (slash != NULL) {
4347c478bd9Sstevel@tonic-gate *slash = '\0';
4357c478bd9Sstevel@tonic-gate mask = atoi(slash + 1);
4367c478bd9Sstevel@tonic-gate err = mask < 0 || mask > IPV6_ABITS;
4377c478bd9Sstevel@tonic-gate }
4387c478bd9Sstevel@tonic-gate if (cbr == NULL)
4397c478bd9Sstevel@tonic-gate err = 1;
4407c478bd9Sstevel@tonic-gate else {
4417c478bd9Sstevel@tonic-gate *cbr = '\0';
4427c478bd9Sstevel@tonic-gate err += inet_pton(AF_INET6, pat+1, &in6) != 1;
4437c478bd9Sstevel@tonic-gate }
4447c478bd9Sstevel@tonic-gate if (slash) *slash = '/';
4457c478bd9Sstevel@tonic-gate if (cbr) *cbr = ']';
4467c478bd9Sstevel@tonic-gate if (err)
4477c478bd9Sstevel@tonic-gate tcpd_warn("bad IP6 address specification: %s", pat);
4487c478bd9Sstevel@tonic-gate #endif
4497c478bd9Sstevel@tonic-gate } else if (mask = split_at(pat, '/')) { /* network/netmask */
4507c478bd9Sstevel@tonic-gate if (dot_quad_addr(pat) == INADDR_NONE
4517c478bd9Sstevel@tonic-gate || dot_quad_addr(mask) == INADDR_NONE)
4527c478bd9Sstevel@tonic-gate tcpd_warn("%s/%s: bad net/mask pattern", pat, mask);
4537c478bd9Sstevel@tonic-gate } else if (STR_EQ(pat, "FAIL")) { /* obsolete */
4547c478bd9Sstevel@tonic-gate tcpd_warn("FAIL is no longer recognized");
4557c478bd9Sstevel@tonic-gate tcpd_warn("(use EXCEPT or DENY instead)");
4567c478bd9Sstevel@tonic-gate } else if (reserved_name(pat)) { /* other reserved */
4577c478bd9Sstevel@tonic-gate /* void */ ;
4587c478bd9Sstevel@tonic-gate } else if (NOT_INADDR(pat)) { /* internet name */
4597c478bd9Sstevel@tonic-gate if (pat[strlen(pat) - 1] == '.') {
4607c478bd9Sstevel@tonic-gate tcpd_warn("%s: domain or host name ends in dot", pat);
4617c478bd9Sstevel@tonic-gate } else if (pat[0] != '.') {
4627c478bd9Sstevel@tonic-gate addr_count = check_dns(pat);
4637c478bd9Sstevel@tonic-gate }
4647c478bd9Sstevel@tonic-gate } else { /* numeric form */
4657c478bd9Sstevel@tonic-gate if (STR_EQ(pat, "0.0.0.0") || STR_EQ(pat, "255.255.255.255")) {
4667c478bd9Sstevel@tonic-gate /* void */ ;
4677c478bd9Sstevel@tonic-gate } else if (pat[0] == '.') {
4687c478bd9Sstevel@tonic-gate tcpd_warn("%s: network number begins with dot", pat);
4697c478bd9Sstevel@tonic-gate } else if (pat[strlen(pat) - 1] != '.') {
4707c478bd9Sstevel@tonic-gate check_dns(pat);
4717c478bd9Sstevel@tonic-gate }
4727c478bd9Sstevel@tonic-gate }
4737c478bd9Sstevel@tonic-gate return (addr_count);
4747c478bd9Sstevel@tonic-gate }
4757c478bd9Sstevel@tonic-gate
4767c478bd9Sstevel@tonic-gate /* reserved_name - determine if name is reserved */
4777c478bd9Sstevel@tonic-gate
reserved_name(pat)4787c478bd9Sstevel@tonic-gate static int reserved_name(pat)
4797c478bd9Sstevel@tonic-gate char *pat;
4807c478bd9Sstevel@tonic-gate {
4817c478bd9Sstevel@tonic-gate return (STR_EQ(pat, unknown)
4827c478bd9Sstevel@tonic-gate || STR_EQ(pat, "KNOWN")
4837c478bd9Sstevel@tonic-gate || STR_EQ(pat, paranoid)
4847c478bd9Sstevel@tonic-gate || STR_EQ(pat, "ALL")
4857c478bd9Sstevel@tonic-gate || STR_EQ(pat, "LOCAL"));
4867c478bd9Sstevel@tonic-gate }
487