1 /*
2  * (c) Copyright 1992 by Panagiotis Tsirigotis
3  * (c) Sections Copyright 1998-2001 by Rob Braun
4  * All rights reserved.  The file named COPYRIGHT specifies the terms
5  * and conditions for redistribution.
6  */
7 
8 #ifndef DEFS_H
9 #define DEFS_H
10 
11 /*
12  * $Id: defs.h,v 1.4 2007-09-20 17:01:52 bbraun Exp $
13  */
14 
15 
16 #include "config.h"
17 #include <memory.h>
18 #include <string.h>
19 #include <stdlib.h>
20 #include <sys/socket.h>
21 #include <netinet/in.h>
22 
23 union xsockaddr {
24    struct sockaddr     sa;
25    struct sockaddr_in  sa_in;
26    struct sockaddr_in6 sa_in6;
27    char                pad[128];
28 };
29 
30 #ifndef FALSE
31 #define FALSE                           0
32 #define TRUE                            1
33 #endif
34 
35 #define NUL                             '\0'
36 
37 #define ES_NOMEM                        "out of memory"
38 
39 #define INT_NULL                        ((int *)0)
40 #define CHAR_NULL                       ((char *)0)
41 #define VOID_NULL                       ((void *)0)
42 #define FD_SET_NULL                     ((fd_set *)0)
43 #define RUSAGE_NULL                     ((struct rusage *)0)
44 #define TIMEVAL_NULL                    ((struct timeval *)0)
45 
46 #define EQ( s1, s2 )          ( strcasecmp( s1, s2 ) == 0 )
47 #define CLEAR( x )            (void) memset( (char *)&(x), 0, sizeof( x ) )
48 /* Apparently, some tcp wrapper header files export an SA definition.
49  * make sure we use ours instead of some other one.
50  */
51 #undef SA
52 
53 #define SA( p )               ( (struct sockaddr *) (p) )
54 #define SAIN( p )             ( (struct sockaddr_in *) (p) )
55 #define SAIN6( p )            ( (struct sockaddr_in6 *) (p) )
56 #define CSA( p )              ( (const struct sockaddr *) (p) )
57 #define CSAIN( p )            ( (const struct sockaddr_in *) (p) )
58 #define CSAIN6( p )           ( (const struct sockaddr_in6 *) (p) )
59 #define NEW( type )           (type *) malloc( sizeof( type ) )
60 #define FREE( p )             (void) free( (char *)(p) )
61 
62 /*
63  * Value for unlimited server instances
64  */
65 #define UNLIMITED                  (-1)
66 
67 /*
68  * We pass to the child the descriptors 0..MAX_PASS_FD
69  */
70 #define MAX_PASS_FD                2
71 
72 /*
73  * Service port for the identification service
74  */
75 #define IDENTITY_SERVICE_PORT      113
76 
77 /*
78  * This is the signal sent to interceptor processes to tell them
79  * to stop intercepting
80  */
81 #define INTERCEPT_SIG              SIGUSR1
82 
83 /*
84  * This is how many descriptors we reserve for ourselves:
85  *
86  *      3    for stdin, stdout, stderr
87  *      1    for syslog/debug
88  *
89  * For the rest we just need to reserve the maximum of each category.
90  *
91  *   1    for doing accepts
92  *   1    for registering rpc services (initialization phase)
93  *   4    for reading the configuration file during reconfiguration
94  *      1 for the configuration file
95  *      1 for /etc/passwd
96  *      1 for /etc/group
97  *      1 for /etc/services, /etc/protocols, /etc/rpc
98  *      NOTE: We need only 1 descriptor for the last 3 files because
99  *         the functions get{serv,proto,rpc}byname close the
100  *         respective files after accessing them.
101  *      1    for dumping the internal state
102  *      1   for talking to the portmapper (reconfiguration phase)
103  *      1   for doing identification
104  *
105  * NOTE: we assume that the socket used for pmap_{set,unset} is closed
106  *      after the operation is completed. If it stays open, then we
107  *      need to increase DESCRIPTORS_RESERVED.
108  */
109 #define DESCRIPTORS_RESERVED         8
110 
111 /*
112  * Used for listen(2)
113  */
114 #define LISTEN_BACKLOG               64
115 
116 /*
117  * When explicit values are given for enum's, that is because the structures
118  * that the enum's are in may be initialized by a memory clear operation.
119  */
120 
121 typedef enum { FAILED = 0, OK } status_e ;
122 typedef enum { NO = 0, YES } boolean_e ;
123 
124 /*
125  * Possible outcomes of an identification attempt
126  */
127 typedef enum
128    {
129       IDR_OK,
130       IDR_NOSERVER,
131       IDR_TIMEDOUT,
132       IDR_RESPERR,
133       IDR_BADRESP,
134       IDR_ERROR
135    } idresult_e ;
136 
137 typedef int bool_int ;
138 
139 typedef void (*voidfunc)() ;
140 typedef status_e (*statfunc)() ;
141 
142 
143 /*
144  * A name-value list is exactly what its name says.
145  * The functions nv_get_name() and nv_get_value() return a pointer to
146  * the entry with the specified value or name respectively.
147  * The list ends when an antry with a NULL name is encountered.
148  * The value field of that entry is treated in a special manner: if it
149  * is non-zero, it is assumed that there exists one more entry whose
150  * name field will be returned by the nv_get_name function if it can't
151  * find an entry whose value field is equal to its 2nd parameter.
152  * If the value field of the NULL entry is 0, then nv_get_name() will
153  * return NULL.
154  */
155 struct name_value
156 {
157    const char   *name ;
158    int          value ;
159 } ;
160 
161 struct protocol_name_value
162 {
163    char   *name ;
164    int    value ;
165 } ;
166 
167 struct debug
168 {
169    bool_int on ;
170    int fd ;
171 } ;
172 
173 /* This is some forward prototypes to work out a couple
174  * circular dependencies in the data structures */
175 struct service;
176 struct server;
177 struct connection;
178 typedef struct connection connection_s ;
179 
180 
181 extern struct debug debug ;
182 
183 #endif   /* DEFS_H */
184