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