tcpd.h revision 56977
144743Smarkm /* 244743Smarkm * @(#) tcpd.h 1.5 96/03/19 16:22:24 344743Smarkm * 444743Smarkm * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands. 556977Sshin * 656977Sshin * $FreeBSD: head/contrib/tcp_wrappers/tcpd.h 56977 2000-02-03 10:27:03Z shin $ 744743Smarkm */ 844743Smarkm 944743Smarkm/* Structure to describe one communications endpoint. */ 1044743Smarkm 1144743Smarkm#define STRING_LENGTH 128 /* hosts, users, processes */ 1244743Smarkm 1344743Smarkmstruct host_info { 1444743Smarkm char name[STRING_LENGTH]; /* access via eval_hostname(host) */ 1544743Smarkm char addr[STRING_LENGTH]; /* access via eval_hostaddr(host) */ 1656977Sshin#ifdef INET6 1756977Sshin struct sockaddr *sin; /* socket address or 0 */ 1856977Sshin#else 1944743Smarkm struct sockaddr_in *sin; /* socket address or 0 */ 2056977Sshin#endif 2144743Smarkm struct t_unitdata *unit; /* TLI transport address or 0 */ 2244743Smarkm struct request_info *request; /* for shared information */ 2344743Smarkm}; 2444743Smarkm 2544743Smarkm/* Structure to describe what we know about a service request. */ 2644743Smarkm 2744743Smarkmstruct request_info { 2844743Smarkm int fd; /* socket handle */ 2944743Smarkm char user[STRING_LENGTH]; /* access via eval_user(request) */ 3044743Smarkm char daemon[STRING_LENGTH]; /* access via eval_daemon(request) */ 3144743Smarkm char pid[10]; /* access via eval_pid(request) */ 3244743Smarkm struct host_info client[1]; /* client endpoint info */ 3344743Smarkm struct host_info server[1]; /* server endpoint info */ 3444743Smarkm void (*sink) (); /* datagram sink function or 0 */ 3544743Smarkm void (*hostname) (); /* address to printable hostname */ 3644743Smarkm void (*hostaddr) (); /* address to printable address */ 3744743Smarkm void (*cleanup) (); /* cleanup function or 0 */ 3844743Smarkm struct netconfig *config; /* netdir handle */ 3944743Smarkm}; 4044743Smarkm 4144743Smarkm/* Common string operations. Less clutter should be more readable. */ 4244743Smarkm 4344743Smarkm#define STRN_CPY(d,s,l) { strncpy((d),(s),(l)); (d)[(l)-1] = 0; } 4444743Smarkm 4544743Smarkm#define STRN_EQ(x,y,l) (strncasecmp((x),(y),(l)) == 0) 4644743Smarkm#define STRN_NE(x,y,l) (strncasecmp((x),(y),(l)) != 0) 4744743Smarkm#define STR_EQ(x,y) (strcasecmp((x),(y)) == 0) 4844743Smarkm#define STR_NE(x,y) (strcasecmp((x),(y)) != 0) 4944743Smarkm 5044743Smarkm /* 5144743Smarkm * Initially, all above strings have the empty value. Information that 5244743Smarkm * cannot be determined at runtime is set to "unknown", so that we can 5344743Smarkm * distinguish between `unavailable' and `not yet looked up'. A hostname 5444743Smarkm * that we do not believe in is set to "paranoid". 5544743Smarkm */ 5644743Smarkm 5744743Smarkm#define STRING_UNKNOWN "unknown" /* lookup failed */ 5844743Smarkm#define STRING_PARANOID "paranoid" /* hostname conflict */ 5944743Smarkm 6044743Smarkmextern char unknown[]; 6144743Smarkmextern char paranoid[]; 6244743Smarkm 6344743Smarkm#define HOSTNAME_KNOWN(s) (STR_NE((s),unknown) && STR_NE((s),paranoid)) 6444743Smarkm 6544743Smarkm#define NOT_INADDR(s) (s[strspn(s,"01234567890./")] != 0) 6644743Smarkm 6744743Smarkm/* Global functions. */ 6844743Smarkm 6944743Smarkm#if defined(TLI) || defined(PTX) || defined(TLI_SEQUENT) 7044743Smarkmextern void fromhost(); /* get/validate client host info */ 7144743Smarkm#else 7244743Smarkm#define fromhost sock_host /* no TLI support needed */ 7344743Smarkm#endif 7444743Smarkm 7544743Smarkmextern int hosts_access(); /* access control */ 7644743Smarkmextern void shell_cmd(); /* execute shell command */ 7744743Smarkmextern char *percent_x(); /* do %<char> expansion */ 7844743Smarkmextern void rfc931(); /* client name from RFC 931 daemon */ 7944743Smarkmextern void clean_exit(); /* clean up and exit */ 8044743Smarkmextern void refuse(); /* clean up and exit */ 8144743Smarkmextern char *xgets(); /* fgets() on steroids */ 8244743Smarkmextern char *split_at(); /* strchr() and split */ 8344743Smarkmextern unsigned long dot_quad_addr(); /* restricted inet_addr() */ 8444743Smarkm 8544743Smarkm/* Global variables. */ 8644743Smarkm 8744743Smarkmextern int allow_severity; /* for connection logging */ 8844743Smarkmextern int deny_severity; /* for connection logging */ 8944743Smarkmextern char *hosts_allow_table; /* for verification mode redirection */ 9044743Smarkmextern char *hosts_deny_table; /* for verification mode redirection */ 9144743Smarkmextern int hosts_access_verbose; /* for verbose matching mode */ 9244743Smarkmextern int rfc931_timeout; /* user lookup timeout */ 9344743Smarkmextern int resident; /* > 0 if resident process */ 9444743Smarkm 9544743Smarkm /* 9644743Smarkm * Routines for controlled initialization and update of request structure 9744743Smarkm * attributes. Each attribute has its own key. 9844743Smarkm */ 9944743Smarkm 10044743Smarkm#ifdef __STDC__ 10144743Smarkmextern struct request_info *request_init(struct request_info *,...); 10244743Smarkmextern struct request_info *request_set(struct request_info *,...); 10344743Smarkm#else 10444743Smarkmextern struct request_info *request_init(); /* initialize request */ 10544743Smarkmextern struct request_info *request_set(); /* update request structure */ 10644743Smarkm#endif 10744743Smarkm 10844743Smarkm#define RQ_FILE 1 /* file descriptor */ 10944743Smarkm#define RQ_DAEMON 2 /* server process (argv[0]) */ 11044743Smarkm#define RQ_USER 3 /* client user name */ 11144743Smarkm#define RQ_CLIENT_NAME 4 /* client host name */ 11244743Smarkm#define RQ_CLIENT_ADDR 5 /* client host address */ 11344743Smarkm#define RQ_CLIENT_SIN 6 /* client endpoint (internal) */ 11444743Smarkm#define RQ_SERVER_NAME 7 /* server host name */ 11544743Smarkm#define RQ_SERVER_ADDR 8 /* server host address */ 11644743Smarkm#define RQ_SERVER_SIN 9 /* server endpoint (internal) */ 11744743Smarkm 11844743Smarkm /* 11944743Smarkm * Routines for delayed evaluation of request attributes. Each attribute 12044743Smarkm * type has its own access method. The trivial ones are implemented by 12144743Smarkm * macros. The other ones are wrappers around the transport-specific host 12244743Smarkm * name, address, and client user lookup methods. The request_info and 12344743Smarkm * host_info structures serve as caches for the lookup results. 12444743Smarkm */ 12544743Smarkm 12644743Smarkmextern char *eval_user(); /* client user */ 12744743Smarkmextern char *eval_hostname(); /* printable hostname */ 12844743Smarkmextern char *eval_hostaddr(); /* printable host address */ 12944743Smarkmextern char *eval_hostinfo(); /* host name or address */ 13044743Smarkmextern char *eval_client(); /* whatever is available */ 13144743Smarkmextern char *eval_server(); /* whatever is available */ 13244743Smarkm#define eval_daemon(r) ((r)->daemon) /* daemon process name */ 13344743Smarkm#define eval_pid(r) ((r)->pid) /* process id */ 13444743Smarkm 13544743Smarkm/* Socket-specific methods, including DNS hostname lookups. */ 13644743Smarkm 13744743Smarkmextern void sock_host(); /* look up endpoint addresses */ 13844743Smarkmextern void sock_hostname(); /* translate address to hostname */ 13944743Smarkmextern void sock_hostaddr(); /* address to printable address */ 14044743Smarkm#define sock_methods(r) \ 14144743Smarkm { (r)->hostname = sock_hostname; (r)->hostaddr = sock_hostaddr; } 14244743Smarkm 14344743Smarkm/* The System V Transport-Level Interface (TLI) interface. */ 14444743Smarkm 14544743Smarkm#if defined(TLI) || defined(PTX) || defined(TLI_SEQUENT) 14644743Smarkmextern void tli_host(); /* look up endpoint addresses etc. */ 14744743Smarkm#endif 14844743Smarkm 14944743Smarkm /* 15044743Smarkm * Problem reporting interface. Additional file/line context is reported 15144743Smarkm * when available. The jump buffer (tcpd_buf) is not declared here, or 15244743Smarkm * everyone would have to include <setjmp.h>. 15344743Smarkm */ 15444743Smarkm 15544743Smarkm#ifdef __STDC__ 15644743Smarkmextern void tcpd_warn(char *, ...); /* report problem and proceed */ 15744743Smarkmextern void tcpd_jump(char *, ...); /* report problem and jump */ 15844743Smarkm#else 15944743Smarkmextern void tcpd_warn(); 16044743Smarkmextern void tcpd_jump(); 16144743Smarkm#endif 16244743Smarkm 16344743Smarkmstruct tcpd_context { 16444743Smarkm char *file; /* current file */ 16544743Smarkm int line; /* current line */ 16644743Smarkm}; 16744743Smarkmextern struct tcpd_context tcpd_context; 16844743Smarkm 16944743Smarkm /* 17044743Smarkm * While processing access control rules, error conditions are handled by 17144743Smarkm * jumping back into the hosts_access() routine. This is cleaner than 17244743Smarkm * checking the return value of each and every silly little function. The 17344743Smarkm * (-1) returns are here because zero is already taken by longjmp(). 17444743Smarkm */ 17544743Smarkm 17644743Smarkm#define AC_PERMIT 1 /* permit access */ 17744743Smarkm#define AC_DENY (-1) /* deny_access */ 17844743Smarkm#define AC_ERROR AC_DENY /* XXX */ 17944743Smarkm 18044743Smarkm /* 18144743Smarkm * In verification mode an option function should just say what it would do, 18244743Smarkm * instead of really doing it. An option function that would not return 18344743Smarkm * should clear the dry_run flag to inform the caller of this unusual 18444743Smarkm * behavior. 18544743Smarkm */ 18644743Smarkm 18744743Smarkmextern void process_options(); /* execute options */ 18844743Smarkmextern int dry_run; /* verification flag */ 18944743Smarkm 19044743Smarkm/* Bug workarounds. */ 19144743Smarkm 19244743Smarkm#ifdef INET_ADDR_BUG /* inet_addr() returns struct */ 19344743Smarkm#define inet_addr fix_inet_addr 19444743Smarkmextern long fix_inet_addr(); 19544743Smarkm#endif 19644743Smarkm 19744743Smarkm#ifdef BROKEN_FGETS /* partial reads from sockets */ 19844743Smarkm#define fgets fix_fgets 19944743Smarkmextern char *fix_fgets(); 20044743Smarkm#endif 20144743Smarkm 20244743Smarkm#ifdef RECVFROM_BUG /* no address family info */ 20344743Smarkm#define recvfrom fix_recvfrom 20444743Smarkmextern int fix_recvfrom(); 20544743Smarkm#endif 20644743Smarkm 20744743Smarkm#ifdef GETPEERNAME_BUG /* claims success with UDP */ 20844743Smarkm#define getpeername fix_getpeername 20944743Smarkmextern int fix_getpeername(); 21044743Smarkm#endif 21144743Smarkm 21244743Smarkm#ifdef SOLARIS_24_GETHOSTBYNAME_BUG /* lists addresses as aliases */ 21344743Smarkm#define gethostbyname fix_gethostbyname 21444743Smarkmextern struct hostent *fix_gethostbyname(); 21544743Smarkm#endif 21644743Smarkm 21744743Smarkm#ifdef USE_STRSEP /* libc calls strtok() */ 21844743Smarkm#define strtok fix_strtok 21944743Smarkmextern char *fix_strtok(); 22044743Smarkm#endif 22144743Smarkm 22244743Smarkm#ifdef LIBC_CALLS_STRTOK /* libc calls strtok() */ 22344743Smarkm#define strtok my_strtok 22444743Smarkmextern char *my_strtok(); 22544743Smarkm#endif 226