home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / tcpd.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-04-30  |  9.3 KB  |  265 lines

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