inetd.h revision 1.2 1 1.2 rillig /* $NetBSD: inetd.h,v 1.2 2021/08/30 17:32:23 rillig Exp $ */
2 1.1 christos
3 1.1 christos /*-
4 1.1 christos * Copyright (c) 1998, 2003 The NetBSD Foundation, Inc.
5 1.1 christos * All rights reserved.
6 1.1 christos *
7 1.1 christos * This code is derived from software contributed to The NetBSD Foundation
8 1.1 christos * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 1.1 christos * NASA Ames Research Center and by Matthias Scheler.
10 1.1 christos *
11 1.1 christos * Redistribution and use in source and binary forms, with or without
12 1.1 christos * modification, are permitted provided that the following conditions
13 1.1 christos * are met:
14 1.1 christos * 1. Redistributions of source code must retain the above copyright
15 1.1 christos * notice, this list of conditions and the following disclaimer.
16 1.1 christos * 2. Redistributions in binary form must reproduce the above copyright
17 1.1 christos * notice, this list of conditions and the following disclaimer in the
18 1.1 christos * documentation and/or other materials provided with the distribution.
19 1.1 christos *
20 1.1 christos * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 1.1 christos * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 1.1 christos * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 1.1 christos * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 1.1 christos * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 1.1 christos * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 1.1 christos * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 1.1 christos * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 1.1 christos * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 1.1 christos * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 1.1 christos * POSSIBILITY OF SUCH DAMAGE.
31 1.1 christos */
32 1.1 christos
33 1.1 christos /*
34 1.1 christos * Copyright (c) 1983, 1991, 1993, 1994
35 1.1 christos * The Regents of the University of California. All rights reserved.
36 1.1 christos *
37 1.1 christos * Redistribution and use in source and binary forms, with or without
38 1.1 christos * modification, are permitted provided that the following conditions
39 1.1 christos * are met:
40 1.1 christos * 1. Redistributions of source code must retain the above copyright
41 1.1 christos * notice, this list of conditions and the following disclaimer.
42 1.1 christos * 2. Redistributions in binary form must reproduce the above copyright
43 1.1 christos * notice, this list of conditions and the following disclaimer in the
44 1.1 christos * documentation and/or other materials provided with the distribution.
45 1.1 christos * 3. Neither the name of the University nor the names of its contributors
46 1.1 christos * may be used to endorse or promote products derived from this software
47 1.1 christos * without specific prior written permission.
48 1.1 christos *
49 1.1 christos * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
50 1.1 christos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
51 1.1 christos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
52 1.1 christos * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
53 1.1 christos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
54 1.1 christos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
55 1.1 christos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56 1.1 christos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57 1.1 christos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
58 1.1 christos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59 1.1 christos * SUCH DAMAGE.
60 1.1 christos */
61 1.1 christos
62 1.1 christos #ifndef _INETD_H
63 1.1 christos #define _INETD_H
64 1.1 christos
65 1.1 christos #include <netinet/in.h>
66 1.1 christos #include <sys/socket.h>
67 1.1 christos #include <sys/time.h>
68 1.1 christos #include <sys/un.h>
69 1.1 christos
70 1.1 christos #include <arpa/inet.h>
71 1.1 christos
72 1.1 christos #include <netdb.h>
73 1.1 christos
74 1.1 christos #include "pathnames.h"
75 1.1 christos
76 1.1 christos #ifdef IPSEC
77 1.1 christos #include <netipsec/ipsec.h>
78 1.1 christos #ifndef IPSEC_POLICY_IPSEC /* no ipsec support on old ipsec */
79 1.1 christos #undef IPSEC
80 1.1 christos #endif
81 1.1 christos #include "ipsec.h"
82 1.1 christos #endif
83 1.1 christos
84 1.1 christos typedef enum service_type {
85 1.2 rillig NORM_TYPE = 0,
86 1.2 rillig MUX_TYPE = 1,
87 1.2 rillig MUXPLUS_TYPE = 2,
88 1.1 christos FAITH_TYPE = 3
89 1.1 christos } service_type;
90 1.1 christos
91 1.1 christos #define ISMUXPLUS(sep) ((sep)->se_type == MUXPLUS_TYPE)
92 1.1 christos #define ISMUX(sep) (((sep)->se_type == MUX_TYPE) || ISMUXPLUS(sep))
93 1.1 christos
94 1.1 christos #define TOOMANY 40 /* don't start more than TOOMANY */
95 1.1 christos
96 1.1 christos #define CONF_ERROR_FMT "%s line %zu: "
97 1.1 christos
98 1.1 christos /* Log warning/error with 0 or variadic args with line number and file name */
99 1.1 christos
100 1.1 christos #define ILV(prio, msg, ...) syslog(prio, CONF_ERROR_FMT msg ".", \
101 1.1 christos CONFIG, line_number __VA_OPT__(,) __VA_ARGS__)
102 1.1 christos
103 1.1 christos #define WRN(msg, ...) ILV(LOG_WARNING, msg __VA_OPT__(,) __VA_ARGS__)
104 1.1 christos #define ERR(msg, ...) ILV(LOG_ERR, msg __VA_OPT__(,) __VA_ARGS__)
105 1.1 christos
106 1.1 christos /* Debug logging */
107 1.1 christos #ifdef DEBUG_ENABLE
108 1.1 christos #define DPRINTF(fmt, ...) do {\
109 1.1 christos if (debug) {\
110 1.1 christos fprintf(stderr, fmt "\n" __VA_OPT__(,) __VA_ARGS__);\
111 1.1 christos }\
112 1.1 christos } while (0)
113 1.1 christos #else
114 1.1 christos #define DPRINTF(fmt, ...) __nothing
115 1.1 christos #endif
116 1.1 christos
117 1.1 christos #define DPRINTCONF(fmt, ...) DPRINTF(CONF_ERROR_FMT fmt,\
118 1.1 christos CONFIG, line_number __VA_OPT__(,) __VA_ARGS__)
119 1.1 christos
120 1.1 christos #define STRINGIFY(x) #x
121 1.1 christos #define TOSTRING(x) STRINGIFY(x)
122 1.1 christos
123 1.1 christos struct servtab {
124 1.1 christos char *se_hostaddr; /* host address to listen on */
125 1.1 christos char *se_service; /* name of service */
126 1.1 christos int se_socktype; /* type of socket to use */
127 1.1 christos sa_family_t se_family; /* address family */
128 1.1 christos char *se_proto; /* protocol used */
129 1.1 christos int se_sndbuf; /* sndbuf size */
130 1.1 christos int se_rcvbuf; /* rcvbuf size */
131 1.1 christos int se_rpcprog; /* rpc program number */
132 1.1 christos int se_rpcversl; /* rpc program lowest version */
133 1.1 christos int se_rpcversh; /* rpc program highest version */
134 1.1 christos #define isrpcservice(sep) ((sep)->se_rpcversl != 0)
135 1.1 christos pid_t se_wait; /* single threaded server */
136 1.1 christos short se_checked; /* looked at during merge */
137 1.1 christos char *se_user; /* user name to run as */
138 1.1 christos char *se_group; /* group name to run as */
139 1.1 christos struct biltin *se_bi; /* if built-in, description */
140 1.1 christos char *se_server; /* server program */
141 1.1 christos #define MAXARGV 64
142 1.1 christos char *se_argv[MAXARGV+1]; /* program arguments */
143 1.1 christos #ifdef IPSEC
144 1.1 christos char *se_policy; /* IPsec poilcy string */
145 1.1 christos #endif
146 1.1 christos struct accept_filter_arg se_accf; /* accept filter for stream service */
147 1.1 christos int se_fd; /* open descriptor */
148 1.1 christos service_type se_type; /* type */
149 1.1 christos union {
150 1.1 christos struct sockaddr_storage se_ctrladdr_storage; /* ensure correctness of C struct initializer */
151 1.1 christos struct sockaddr se_ctrladdr;
152 1.1 christos struct sockaddr_in se_ctrladdr_in;
153 1.1 christos struct sockaddr_in6 se_ctrladdr_in6; /* in6 is used by bind()/getaddrinfo */
154 1.1 christos struct sockaddr_un se_ctrladdr_un;
155 1.1 christos }; /* bound address */
156 1.1 christos socklen_t se_ctrladdr_size;
157 1.1 christos size_t se_service_max; /* max # of instances of this service */
158 1.1 christos size_t se_count; /* number of instances of this service started since se_time */
159 1.1 christos size_t se_ip_max; /* max # of instances of this service per ip per minute */
160 1.1 christos struct se_ip_list_node {
161 1.1 christos struct se_ip_list_node *next;
162 1.2 rillig size_t count; /*
163 1.1 christos * number of instances of this service started from
164 1.2 rillig * this ip address since se_time (includes
165 1.1 christos * attempted starts if greater than se_ip_max)
166 1.1 christos */
167 1.1 christos char address[NI_MAXHOST];
168 1.1 christos } *se_ip_list_head; /* linked list of number of requests per ip */
169 1.1 christos time_t se_time; /* start of se_count and ip_max counts, in seconds from arbitrary point */
170 1.1 christos struct servtab *se_next;
171 1.1 christos };
172 1.1 christos
173 1.1 christos /* From inetd.c */
174 1.1 christos int parse_protocol(struct servtab *);
175 1.1 christos int parse_wait(struct servtab *, int);
176 1.1 christos int parse_server(struct servtab *, const char *);
177 1.1 christos void parse_socktype(char *, struct servtab *);
178 1.1 christos void parse_accept_filter(char *, struct servtab *);
179 1.1 christos char *nextline(FILE *);
180 1.1 christos char *newstr(const char *);
181 1.1 christos void freeconfig(struct servtab *);
182 1.1 christos
183 1.1 christos /* Global debug mode boolean, enabled with -d */
184 1.1 christos extern int debug;
185 1.1 christos
186 1.1 christos /* Current config file path */
187 1.1 christos extern const char *CONFIG;
188 1.1 christos
189 1.1 christos /* Open config file */
190 1.1 christos extern FILE *fconfig;
191 1.1 christos
192 1.1 christos /* Current line number in current config file */
193 1.1 christos extern size_t line_number;
194 1.1 christos
195 1.1 christos /* Default listening hostname/IP for current config file */
196 1.1 christos extern char *defhost;
197 1.1 christos
198 1.1 christos /* Default IPsec policy for current config file */
199 1.1 christos extern char *policy;
200 1.1 christos
201 1.1 christos /* From parse_v2.c */
202 1.1 christos
203 1.1 christos typedef enum parse_v2_result {V2_SUCCESS, V2_SKIP, V2_ERROR} parse_v2_result;
204 1.1 christos
205 1.2 rillig /*
206 1.1 christos * Parse a key-values service definition, starting at the token after
207 1.1 christos * on/off (i.e. parse a series of key-values pairs terminated by a semicolon).
208 1.1 christos * Fills the provided servtab structure. Does not call freeconfig on error.
209 1.1 christos */
210 1.1 christos parse_v2_result parse_syntax_v2(struct servtab *, char **);
211 1.1 christos
212 1.1 christos /* "Unspecified" indicator value for servtabs (mainly used by v2 syntax) */
213 1.1 christos #define SERVTAB_UNSPEC_VAL -1
214 1.1 christos
215 1.1 christos #define SERVTAB_UNSPEC_SIZE_T SIZE_MAX
216 1.1 christos
217 1.1 christos #define SERVTAB_COUNT_MAX (SIZE_MAX - (size_t)1)
218 1.1 christos
219 1.1 christos /* Standard logging and debug print format for a servtab */
220 1.1 christos #define SERV_FMT "%s/%s"
221 1.1 christos #define SERV_PARAMS(sep) sep->se_service,sep->se_proto
222 1.1 christos
223 1.1 christos #endif
224