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.
12 * $Id: sconf.h,v 1.10 2005/10/05 17:15:33 bbraun Exp $
18 #include <sys/types.h>
19 #include <netinet/in.h>
20 #include <sys/socket.h>
23 #ifdef HAVE_SYS_RESOURCE_H
24 #include <sys/resource.h>
26 #include "libportable.h"
45 #define ST_TCPMUXPLUS 7
50 #define SF_INTERCEPT 1
54 #define SF_NAMEINARGS 5
56 #define SF_KEEPALIVE 7
57 #define SF_NOLIBWRAP 8
63 * Values for log options
75 unsigned long rd_min_version ;
76 unsigned long rd_max_version ;
77 unsigned long rd_program_number ;
80 #define RD_MINVERS( rdp ) (rdp)->rd_min_version
81 #define RD_MAXVERS( rdp ) (rdp)->rd_max_version
82 #define RD_PROGNUM( rdp ) (rdp)->rd_program_number
84 typedef enum { NO_ENV = 0, STD_ENV, DEF_ENV, CUSTOM_ENV } environ_e ;
93 * NOTE: Clearing the structure will give all its fields their default values
97 mask_t sc_specified_attributes; /* specified attributes */
98 mask_t sc_attributes_present; /* includes those from defaults*/
99 mask_t sc_type; /* RPC, UNLISTED etc */
100 mask_t sc_xflags ; /* INTERCEPT etc */
101 char *sc_name; /* e g "echo" */
102 char *sc_id ; /* e.g. "echo-stream" */
103 uint16_t sc_port ; /* in host byte order */
104 int sc_socket_type ; /* e.g. SOCK_DGRAM */
105 struct protocol_name_value sc_protocol ; /* e.g. "TCP", IPPROTO_TCP */
108 gid_t sc_user_gid ; /* gid corresponding to uid */
109 gid_t sc_gid ; /* gid corresponding to group */
111 char **sc_server_argv ;
113 int sc_nice ; /* argument for nice(3) */
114 pset_h sc_env_var_defs ; /* list of env strings */
115 pset_h sc_pass_env_vars ; /* env vars to pass to server */
116 pset_h sc_access_times ;
117 pset_h sc_only_from ;
118 pset_h sc_no_access ;
119 mask_t sc_log_on_success ;
120 mask_t sc_log_on_failure ;
122 struct rpc_data sc_rd ;
123 pset_h sc_disabled ; /* used only by the default entry */
124 pset_h sc_enabled ; /* used only by the default entry */
125 struct environment sc_environment ;
126 const builtin_s *sc_builtin ;
127 union xsockaddr *sc_redir_addr ;
128 char *sc_orig_bind_addr ; /* used only when dual stack */
129 union xsockaddr *sc_bind_addr ;
133 boolean_e sc_groups ;
134 char *sc_banner_success ;
135 char *sc_banner_fail ;
137 time_t sc_time_limit ;
138 time_t sc_time_conn ;
139 time_t sc_time_conn_max ;
140 time_t sc_time_wait ;
141 time_t sc_time_reenable ;
146 rlim_t sc_rlim_stack;
148 int sc_deny_time; /* Sensor deny access time:
162 #define SCP( p ) ((struct service_config *)(p))
165 * Field access macros
167 #define SC_LOG( scp ) (&(scp)->sc_log)
168 #define SC_RPCDATA( scp ) (&(scp)->sc_rd)
169 #define SC_ENV( scp ) (&(scp)->sc_environment)
170 #define SC_ENV_VAR_DEFS( scp ) (scp)->sc_env_var_defs
171 #define SC_PORT( scp ) (scp)->sc_port
172 #define SC_NICE( scp ) (scp)->sc_nice
173 #define SC_SOCKET_TYPE( scp ) (scp)->sc_socket_type
174 #define SC_ID( scp ) (scp)->sc_id
175 #define SC_NAME( scp ) (scp)->sc_name
176 #define SC_PROTOVAL( scp ) (scp)->sc_protocol.value
177 #define SC_PROTONAME( scp ) (scp)->sc_protocol.name
178 #define SC_INSTANCES( scp ) (scp)->sc_instances
179 #define SC_UID( scp ) (scp)->sc_uid
180 #define SC_GID( scp ) (scp)->sc_gid
181 #define SC_USER_GID( scp ) (scp)->sc_user_gid
182 #define SC_SERVER( scp ) (scp)->sc_server
183 #define SC_SERVER_ARGV( scp ) (scp)->sc_server_argv
184 #define SC_ONLY_FROM( scp ) (scp)->sc_only_from
185 #define SC_NO_ACCESS( scp ) (scp)->sc_no_access
186 #define SC_ACCESS_TIMES( scp ) (scp)->sc_access_times
187 #define SC_LOG_ON_SUCCESS( scp ) (scp)->sc_log_on_success
188 #define SC_LOG_ON_FAILURE( scp ) (scp)->sc_log_on_failure
189 #define SC_PASS_ENV_VARS( scp ) (scp)->sc_pass_env_vars
190 #define SC_RLIM_AS( scp ) (scp)->sc_rlim_as
191 #define SC_RLIM_CPU( scp ) (scp)->sc_rlim_cpu
192 #define SC_RLIM_DATA( scp ) (scp)->sc_rlim_data
193 #define SC_RLIM_RSS( scp ) (scp)->sc_rlim_rss
194 #define SC_RLIM_STACK( scp ) (scp)->sc_rlim_stack
195 #define SC_TYPE( scp ) (scp)->sc_type
196 #define SC_WAIT( scp ) (scp)->sc_wait
197 #define SC_XFLAGS( scp ) (scp)->sc_xflags
198 #define SC_V6ONLY( scp ) (scp)->sc_v6only
199 #define SC_ENABLED( scp ) (scp)->sc_enabled
200 #define SC_DISABLED( scp ) (scp)->sc_disabled
201 #define SC_BUILTIN( scp ) (scp)->sc_builtin
202 #define SC_REDIR_ADDR( scp ) (scp)->sc_redir_addr
203 #define SC_ORIG_BIND_ADDR( scp ) (scp)->sc_orig_bind_addr
204 #define SC_BIND_ADDR( scp ) (scp)->sc_bind_addr
205 #define SC_BANNER( scp ) (scp)->sc_banner
206 #define SC_BANNER_SUCCESS( scp ) (scp)->sc_banner_success
207 #define SC_BANNER_FAIL( scp ) (scp)->sc_banner_fail
208 #define SC_GROUPS( scp ) (scp)->sc_groups
209 #define SC_MAX_LOAD( scp ) (scp)->sc_max_load
210 #define SC_TIME_LIMIT( scp ) (scp)->sc_time_limit
211 #define SC_TIME_CONN( scp ) (scp)->sc_time_conn
212 #define SC_TIME_CONN_MAX( scp ) (scp)->sc_time_conn_max
213 #define SC_TIME_WAIT( scp ) (scp)->sc_time_wait
214 #define SC_TIME_REENABLE( scp ) (scp)->sc_time_reenable
215 #define SC_UMASK( scp ) (scp)->sc_umask
216 #define SC_DENY_TIME( scp ) (scp)->sc_deny_time
217 #define SC_MDNS_NAME( scp ) (scp)->sc_mdns_name
218 #define SC_MDNS( scp ) (scp)->sc_mdns
219 #define SC_PER_SOURCE( scp ) (scp)->sc_per_source
220 #define SC_LIBWRAP( scp ) (scp)->sc_libwrap
224 #define SC_SET_PORT( scp, port ) (scp)->sc_port = (port)
227 * Predicate checking macros
229 #define SC_FORKS( scp ) ( ! SC_IS_INTERNAL( scp ) || \
230 BUILTIN_FORKS( (scp)->sc_builtin ) )
231 #define SC_WAITS( scp ) ( (scp)->sc_wait == YES )
232 #define SC_RETRY( scp ) ( M_IS_CLEAR( (scp)->sc_xflags, SF_NORETRY ) )
233 #define SC_MUST_IDENTIFY( scp ) M_IS_SET( (scp)->sc_xflags, SF_IDONLY )
234 #define SC_NAMEINARGS( scp ) M_IS_SET( (scp)->sc_xflags, SF_NAMEINARGS )
235 #define SC_NODELAY( scp ) M_IS_SET( (scp)->sc_xflags, SF_NODELAY )
236 #define SC_KEEPALIVE( scp ) M_IS_SET( (scp)->sc_xflags, SF_KEEPALIVE )
237 #define SC_NOLIBWRAP( scp ) M_IS_SET( (scp)->sc_xflags, SF_NOLIBWRAP )
238 #define SC_IS_INTERCEPTED( scp ) ( M_IS_SET( (scp)->sc_xflags, SF_INTERCEPT ) )
239 #define SC_SENSOR( scp ) M_IS_SET( (scp)->sc_xflags, SF_SENSOR )
240 #define SC_IPV4( scp ) M_IS_SET( (scp)->sc_xflags, SF_IPV4 )
241 #define SC_IPV6( scp ) M_IS_SET( (scp)->sc_xflags, SF_IPV6 )
243 #define SC_IS_RPC( scp ) ( M_IS_SET( (scp)->sc_type, ST_RPC ) )
244 #define SC_IS_INTERNAL( scp ) ( M_IS_SET( (scp)->sc_type, ST_INTERNAL ) )
245 #define SC_IS_SPECIAL( scp ) ( M_IS_SET( (scp)->sc_type, ST_SPECIAL ) )
246 #define SC_IS_UNLISTED( scp ) ( M_IS_SET( (scp)->sc_type, ST_UNLISTED ) )
247 #define SC_IS_DISABLED( scp ) ( M_IS_SET( (scp)->sc_type, ST_DISABLED ) )
248 #define SC_DISABLE(scp) ( M_SET( (scp)->sc_type, ST_DISABLED ) )
249 #define SC_ENABLE(scp) ( M_CLEAR( (scp)->sc_type, ST_DISABLED ) )
250 #define SC_IS_MUXCLIENT( scp ) ( M_IS_SET( (scp)->sc_type, ST_TCPMUX ) || \
251 M_IS_SET( (scp)->sc_type, ST_TCPMUXPLUS ) )
252 #define SC_IS_MUXPLUSCLIENT(scp) ( M_IS_SET( (scp)->sc_type, ST_TCPMUXPLUS ) )
253 #define SC_IS_TCPMUX( scp ) ( (scp)->sc_builtin && \
254 (BUILTIN_HANDLER( (scp)->sc_builtin ) == \
255 (void *)tcpmux_handler ) )
257 #define LOGS_USERID( scp, flags ) \
258 ( M_IS_SET( (scp)->flags, LO_USERID ) && SC_ACCEPTS_CONNECTIONS( scp ) )
260 #define LOGS_ANY( scp, flags ) ( ! M_ARE_ALL_CLEAR( (scp)->flags ) )
262 #define SC_LOGS_ON_SUCCESS( scp ) LOGS_ANY( scp, sc_log_on_success )
263 #define SC_LOGS_ON_FAILURE( scp ) LOGS_ANY( scp, sc_log_on_failure )
264 #define SC_LOGS_USERID_ON_FAILURE( scp ) LOGS_USERID( scp, sc_log_on_failure )
265 #define SC_LOGS_USERID_ON_SUCCESS( scp ) LOGS_USERID( scp, sc_log_on_success )
266 #define SC_LOGS_ON_EXIT( scp ) \
267 ( M_IS_SET( (scp)->sc_log_on_success, LO_DURATION ) || \
268 M_IS_SET( (scp)->sc_log_on_success, LO_EXIT ) )
269 #define SC_LOGS_PID( scp ) M_IS_SET( (scp)->sc_log_on_success, LO_PID )
270 #define SC_LOGS_EXITS( scp ) M_IS_SET( (scp)->sc_log_on_success, LO_EXIT )
271 #define SC_LOGS_DURATION( scp ) \
272 M_IS_SET( (scp)->sc_log_on_success, LO_DURATION )
275 #define SC_MUST_LISTEN( scp ) ( (scp)->sc_socket_type == SOCK_STREAM )
277 #define SC_ACCEPTS_CONNECTIONS( scp ) \
278 ( (scp)->sc_wait == NO && (scp)->sc_socket_type == SOCK_STREAM )
280 #define SC_SPECIFIED( scp, attr ) \
281 M_IS_SET( (scp)->sc_specified_attributes, (attr) )
282 #define SC_SPECIFY( scp, attr ) \
284 M_SET( (scp)->sc_specified_attributes, (attr) ) ; \
285 SC_PRESENT( (scp), (attr) ) ; \
288 #define SC_IS_PRESENT( scp, attr ) \
289 M_IS_SET( (scp)->sc_attributes_present, (attr) )
290 #define SC_PRESENT( scp, attr ) \
291 M_SET( (scp)->sc_attributes_present, (attr) )
293 #define SC_GETGID( scp ) ( SC_SPECIFIED( scp, A_GROUP ) \
294 ? (scp)->sc_gid : (scp)->sc_user_gid )
295 #define SC_INTERNAL( scp, serp ) BUILTIN_INVOKE( (scp)->sc_builtin, serp )
296 #define SC_MAKE_EXTERNAL( scp ) M_CLEAR( (scp)->sc_type, ST_INTERNAL )
298 struct service_config *sc_alloc(const char *name);
299 void sc_free(struct service_config *scp);
300 struct service_config *sc_make_special(const char *service_name,const builtin_s *bp,int instances);
301 void sc_dump(struct service_config *scp,int fd,int tab_level,bool_int is_defaults);
302 bool_int sc_different_confs(struct service_config *scp1,struct service_config *scp2);