1 /* $NetBSD: tcpd.h,v 1.11 2001/03/27 22:46:55 kleink Exp $ */ 2 /* 3 * @(#) tcpd.h 1.5 96/03/19 16:22:24 4 * 5 * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands. 6 */ 7 8 #include <sys/cdefs.h> 9 #include <stdio.h> 10 11 /* Structure to describe one communications endpoint. */ 12 13 #define STRING_LENGTH 128 /* hosts, users, processes */ 14 15 struct host_info { 16 char name[STRING_LENGTH]; /* access via eval_hostname(host) */ 17 char addr[STRING_LENGTH]; /* access via eval_hostaddr(host) */ 18 struct sockaddr *sin; /* socket address or 0 */ 19 struct t_unitdata *unit; /* TLI transport address or 0 */ 20 struct request_info *request; /* for shared information */ 21 }; 22 23 /* Structure to describe what we know about a service request. */ 24 25 struct request_info { 26 int fd; /* socket handle */ 27 char user[STRING_LENGTH]; /* access via eval_user(request) */ 28 char daemon[STRING_LENGTH]; /* access via eval_daemon(request) */ 29 char pid[10]; /* access via eval_pid(request) */ 30 struct host_info client[1]; /* client endpoint info */ 31 struct host_info server[1]; /* server endpoint info */ 32 void (*sink) /* datagram sink function or 0 */ 33 __P((int)); 34 void (*hostname) /* address to printable hostname */ 35 __P((struct host_info *)); 36 void (*hostaddr) /* address to printable address */ 37 __P((struct host_info *)); 38 void (*cleanup) /* cleanup function or 0 */ 39 __P((void)); 40 struct netconfig *config; /* netdir handle */ 41 }; 42 43 /* Common string operations. Less clutter should be more readable. */ 44 45 #define STRN_CPY(d,s,l) { strncpy((d),(s),(l)); (d)[(l)-1] = 0; } 46 47 #define STRN_EQ(x,y,l) (strncasecmp((x),(y),(l)) == 0) 48 #define STRN_NE(x,y,l) (strncasecmp((x),(y),(l)) != 0) 49 #define STR_EQ(x,y) (strcasecmp((x),(y)) == 0) 50 #define STR_NE(x,y) (strcasecmp((x),(y)) != 0) 51 52 /* 53 * Initially, all above strings have the empty value. Information that 54 * cannot be determined at runtime is set to "unknown", so that we can 55 * distinguish between `unavailable' and `not yet looked up'. A hostname 56 * that we do not believe in is set to "paranoid". 57 */ 58 59 #define STRING_UNKNOWN "unknown" /* lookup failed */ 60 #define STRING_PARANOID "paranoid" /* hostname conflict */ 61 62 __BEGIN_DECLS 63 extern char unknown[]; 64 extern char paranoid[]; 65 __END_DECLS 66 67 #define HOSTNAME_KNOWN(s) (STR_NE((s),unknown) && STR_NE((s),paranoid)) 68 69 #define NOT_INADDR(s) (s[strspn(s,"01234567890./")] != 0) 70 71 /* Global functions. */ 72 73 __BEGIN_DECLS 74 #if defined(TLI) || defined(PTX) || defined(TLI_SEQUENT) 75 extern void fromhost /* get/validate client host info */ 76 __P((struct request_info *)); 77 #else 78 #define fromhost sock_host /* no TLI support needed */ 79 #endif 80 81 extern int hosts_access /* access control */ 82 __P((struct request_info *)); 83 extern int hosts_ctl /* limited interface to hosts_access */ 84 __P((char *, char *, char *, char *)); 85 extern void shell_cmd /* execute shell command */ 86 __P((char *)); 87 extern char *percent_x /* do %<char> expansion */ 88 __P((char *, int, char *, struct request_info *)); 89 extern void rfc931 /* client name from RFC 931 daemon */ 90 __P((struct sockaddr *, struct sockaddr *, char *)); 91 extern void clean_exit /* clean up and exit */ 92 __P((struct request_info *)); 93 extern void refuse /* clean up and exit */ 94 __P((struct request_info *)); 95 extern char *xgets /* fgets() on steroids */ 96 __P((char *, int, FILE *)); 97 extern char *split_at /* strchr() and split */ 98 __P((char *, int)); 99 extern int dot_quad_addr /* restricted inet_aton() */ 100 __P((char *, unsigned long *)); 101 102 /* Global variables. */ 103 104 extern int allow_severity; /* for connection logging */ 105 extern int deny_severity; /* for connection logging */ 106 extern char *hosts_allow_table; /* for verification mode redirection */ 107 extern char *hosts_deny_table; /* for verification mode redirection */ 108 extern int hosts_access_verbose; /* for verbose matching mode */ 109 extern int rfc931_timeout; /* user lookup timeout */ 110 extern int resident; /* > 0 if resident process */ 111 112 /* 113 * Routines for controlled initialization and update of request structure 114 * attributes. Each attribute has its own key. 115 */ 116 117 extern struct request_info *request_init /* initialize request */ 118 __P((struct request_info *,...)); 119 extern struct request_info *request_set /* update request structure */ 120 __P((struct request_info *,...)); 121 122 #define RQ_FILE 1 /* file descriptor */ 123 #define RQ_DAEMON 2 /* server process (argv[0]) */ 124 #define RQ_USER 3 /* client user name */ 125 #define RQ_CLIENT_NAME 4 /* client host name */ 126 #define RQ_CLIENT_ADDR 5 /* client host address */ 127 #define RQ_CLIENT_SIN 6 /* client endpoint (internal) */ 128 #define RQ_SERVER_NAME 7 /* server host name */ 129 #define RQ_SERVER_ADDR 8 /* server host address */ 130 #define RQ_SERVER_SIN 9 /* server endpoint (internal) */ 131 132 /* 133 * Routines for delayed evaluation of request attributes. Each attribute 134 * type has its own access method. The trivial ones are implemented by 135 * macros. The other ones are wrappers around the transport-specific host 136 * name, address, and client user lookup methods. The request_info and 137 * host_info structures serve as caches for the lookup results. 138 */ 139 140 extern char *eval_user /* client user */ 141 __P((struct request_info *)); 142 extern char *eval_hostname /* printable hostname */ 143 __P((struct host_info *)); 144 extern char *eval_hostaddr /* printable host address */ 145 __P((struct host_info *)); 146 extern char *eval_hostinfo /* host name or address */ 147 __P((struct host_info *)); 148 extern char *eval_client /* whatever is available */ 149 __P((struct request_info *)); 150 extern char *eval_server /* whatever is available */ 151 __P((struct request_info *)); 152 #define eval_daemon(r) ((r)->daemon) /* daemon process name */ 153 #define eval_pid(r) ((r)->pid) /* process id */ 154 155 /* Socket-specific methods, including DNS hostname lookups. */ 156 157 extern void sock_host /* look up endpoint addresses */ 158 __P((struct request_info *)); 159 extern void sock_hostname /* translate address to hostname */ 160 __P((struct host_info *)); 161 extern void sock_hostaddr /* address to printable address */ 162 __P((struct host_info *)); 163 #define sock_methods(r) \ 164 { (r)->hostname = sock_hostname; (r)->hostaddr = sock_hostaddr; } 165 166 /* The System V Transport-Level Interface (TLI) interface. */ 167 168 #if defined(TLI) || defined(PTX) || defined(TLI_SEQUENT) 169 extern void tli_host /* look up endpoint addresses etc. */ 170 __P((struct request_info *)); 171 #endif 172 173 /* 174 * Problem reporting interface. Additional file/line context is reported 175 * when available. The jump buffer (tcpd_buf) is not declared here, or 176 * everyone would have to include <setjmp.h>. 177 */ 178 179 extern void tcpd_warn /* report problem and proceed */ 180 __P((char *, ...)) 181 __attribute__((__format__(__printf__, 1, 2))); 182 extern void tcpd_jump /* report problem and jump */ 183 __P((char *, ...)) 184 __attribute__((__format__(__printf__, 1, 2))); 185 __END_DECLS 186 187 struct tcpd_context { 188 char *file; /* current file */ 189 int line; /* current line */ 190 }; 191 __BEGIN_DECLS 192 extern struct tcpd_context tcpd_context; 193 __END_DECLS 194 195 /* 196 * While processing access control rules, error conditions are handled by 197 * jumping back into the hosts_access() routine. This is cleaner than 198 * checking the return value of each and every silly little function. The 199 * (-1) returns are here because zero is already taken by longjmp(). 200 */ 201 202 #define AC_PERMIT 1 /* permit access */ 203 #define AC_DENY (-1) /* deny_access */ 204 #define AC_ERROR AC_DENY /* XXX */ 205 206 /* 207 * In verification mode an option function should just say what it would do, 208 * instead of really doing it. An option function that would not return 209 * should clear the dry_run flag to inform the caller of this unusual 210 * behavior. 211 */ 212 213 __BEGIN_DECLS 214 extern void process_options /* execute options */ 215 __P((char *, struct request_info *)); 216 extern int dry_run; /* verification flag */ 217 extern void fix_options /* get rid of IP-level socket options */ 218 __P((struct request_info *)); 219 /* Bug workarounds. */ 220 221 #ifdef INET_ADDR_BUG /* inet_addr() returns struct */ 222 #define inet_addr fix_inet_addr 223 extern long fix_inet_addr __P((char *)); 224 #endif 225 226 #ifdef BROKEN_FGETS /* partial reads from sockets */ 227 #define fgets fix_fgets 228 extern char *fix_fgets __P((char *, int, FILE *)); 229 #endif 230 231 #ifdef RECVFROM_BUG /* no address family info */ 232 #define recvfrom fix_recvfrom 233 extern int fix_recvfrom __P((int, char *, int, int, struct sockaddr *, int *)); 234 #endif 235 236 #ifdef GETPEERNAME_BUG /* claims success with UDP */ 237 #include <sys/socket.h> /* XXX serious hack! */ 238 #define getpeername fix_getpeername 239 extern int fix_getpeername __P((int, struct sockaddr *, int *)); 240 #endif 241 242 #ifdef SOLARIS_24_GETHOSTBYNAME_BUG /* lists addresses as aliases */ 243 #define gethostbyname fix_gethostbyname 244 extern struct hostent *fix_gethostbyname __P((char *)); 245 #endif 246 247 #ifdef USE_STRSEP /* libc calls strtok() */ 248 #define strtok fix_strtok 249 extern char *fix_strtok __P((char *, char *)); 250 #endif 251 252 #ifdef LIBC_CALLS_STRTOK /* libc calls strtok() */ 253 #define strtok my_strtok 254 extern char *my_strtok __P((char *, char *)); 255 #endif 256 __END_DECLS 257