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