xref: /freebsd/usr.sbin/inetd/inetd.h (revision b3e76948)
18a16b7a1SPedro F. Giffuni /*-
28a16b7a1SPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
38a16b7a1SPedro F. Giffuni  *
45ff3afceSSheldon Hearn  * Copyright (c) 1983, 1991, 1993, 1994
55ff3afceSSheldon Hearn  *	The Regents of the University of California.  All rights reserved.
65ff3afceSSheldon Hearn  *
75ff3afceSSheldon Hearn  * Redistribution and use in source and binary forms, with or without
85ff3afceSSheldon Hearn  * modification, are permitted provided that the following conditions
95ff3afceSSheldon Hearn  * are met:
105ff3afceSSheldon Hearn  * 1. Redistributions of source code must retain the above copyright
115ff3afceSSheldon Hearn  *    notice, this list of conditions and the following disclaimer.
125ff3afceSSheldon Hearn  * 2. Redistributions in binary form must reproduce the above copyright
135ff3afceSSheldon Hearn  *    notice, this list of conditions and the following disclaimer in the
145ff3afceSSheldon Hearn  *    documentation and/or other materials provided with the distribution.
15fbbd9655SWarner Losh  * 3. Neither the name of the University nor the names of its contributors
165ff3afceSSheldon Hearn  *    may be used to endorse or promote products derived from this software
175ff3afceSSheldon Hearn  *    without specific prior written permission.
185ff3afceSSheldon Hearn  *
195ff3afceSSheldon Hearn  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
205ff3afceSSheldon Hearn  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
215ff3afceSSheldon Hearn  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
225ff3afceSSheldon Hearn  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
235ff3afceSSheldon Hearn  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
245ff3afceSSheldon Hearn  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
255ff3afceSSheldon Hearn  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
265ff3afceSSheldon Hearn  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
275ff3afceSSheldon Hearn  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
285ff3afceSSheldon Hearn  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
295ff3afceSSheldon Hearn  * SUCH DAMAGE.
305ff3afceSSheldon Hearn  */
315ff3afceSSheldon Hearn 
325ff3afceSSheldon Hearn #include <sys/time.h>
335ff3afceSSheldon Hearn #include <sys/socket.h>
341c8d1174SDavid Malone #include <sys/un.h>
3509b1c357SHajimu UMEMOTO #include <sys/queue.h>
365ff3afceSSheldon Hearn 
375ff3afceSSheldon Hearn #include <netinet/in.h>
385ff3afceSSheldon Hearn 
395ff3afceSSheldon Hearn #include <stdio.h>
405ff3afceSSheldon Hearn 
415ff3afceSSheldon Hearn #define BUFSIZE 8192
425ff3afceSSheldon Hearn #define LINESIZ 72
435ff3afceSSheldon Hearn 
445ff3afceSSheldon Hearn #define NORM_TYPE	0
455ff3afceSSheldon Hearn #define MUX_TYPE	1
465ff3afceSSheldon Hearn #define MUXPLUS_TYPE	2
470cac72f4SYoshinobu Inoue #define FAITH_TYPE	4
485ff3afceSSheldon Hearn #define ISMUX(sep)	(((sep)->se_type == MUX_TYPE) || \
495ff3afceSSheldon Hearn 			 ((sep)->se_type == MUXPLUS_TYPE))
505ff3afceSSheldon Hearn #define ISMUXPLUS(sep)	((sep)->se_type == MUXPLUS_TYPE)
515ff3afceSSheldon Hearn 
5209b1c357SHajimu UMEMOTO struct procinfo {
5309b1c357SHajimu UMEMOTO 	LIST_ENTRY(procinfo) pr_link;
5409b1c357SHajimu UMEMOTO 	pid_t		pr_pid;		/* child pid */
5509b1c357SHajimu UMEMOTO 	struct conninfo	*pr_conn;
5609b1c357SHajimu UMEMOTO };
5709b1c357SHajimu UMEMOTO 
5809b1c357SHajimu UMEMOTO struct conninfo {
5909b1c357SHajimu UMEMOTO 	LIST_ENTRY(conninfo) co_link;
6009b1c357SHajimu UMEMOTO 	struct sockaddr_storage	co_addr;	/* source address */
6109b1c357SHajimu UMEMOTO 	int		co_numchild;	/* current number of children */
6209b1c357SHajimu UMEMOTO 	struct procinfo	**co_proc;	/* array of child proc entry */
6309b1c357SHajimu UMEMOTO };
6409b1c357SHajimu UMEMOTO 
6509b1c357SHajimu UMEMOTO #define PERIPSIZE	256
6609b1c357SHajimu UMEMOTO 
67c53b0f40SKyle Evans struct	stabchild {
68c53b0f40SKyle Evans 	LIST_ENTRY(stabchild)	sc_link;
69c53b0f40SKyle Evans 	pid_t			sc_pid;
70c53b0f40SKyle Evans };
71c53b0f40SKyle Evans 
725ff3afceSSheldon Hearn struct	servtab {
735ff3afceSSheldon Hearn 	char	*se_service;		/* name of service */
745ff3afceSSheldon Hearn 	int	se_socktype;		/* type of socket to use */
750cac72f4SYoshinobu Inoue 	int	se_family;		/* address family */
765ff3afceSSheldon Hearn 	char	*se_proto;		/* protocol used */
775ff3afceSSheldon Hearn 	int	se_maxchild;		/* max number of children */
785ff3afceSSheldon Hearn 	int	se_maxcpm;		/* max connects per IP per minute */
795ff3afceSSheldon Hearn 	int	se_numchild;		/* current number of children */
805ff3afceSSheldon Hearn 	char	*se_user;		/* user name to run as */
815ff3afceSSheldon Hearn 	char    *se_group;              /* group name to run as */
825ff3afceSSheldon Hearn #ifdef  LOGIN_CAP
835ff3afceSSheldon Hearn 	char    *se_class;              /* login class name to run with */
845ff3afceSSheldon Hearn #endif
855ff3afceSSheldon Hearn 	struct	biltin *se_bi;		/* if built-in, description */
865ff3afceSSheldon Hearn 	char	*se_server;		/* server program */
875ff3afceSSheldon Hearn 	char	*se_server_name;	/* server program without path */
885ff3afceSSheldon Hearn #define	MAXARGV 20
895ff3afceSSheldon Hearn 	char	*se_argv[MAXARGV+1];	/* program arguments */
900cac72f4SYoshinobu Inoue #ifdef IPSEC
91caf60155SDavid Malone 	char	*se_policy;		/* IPsec policy string */
920cac72f4SYoshinobu Inoue #endif
935ff3afceSSheldon Hearn 	int	se_fd;			/* open descriptor */
940cac72f4SYoshinobu Inoue 	union {				/* bound address */
950cac72f4SYoshinobu Inoue 		struct	sockaddr se_un_ctrladdr;
960cac72f4SYoshinobu Inoue 		struct	sockaddr_in se_un_ctrladdr4;
970cac72f4SYoshinobu Inoue 		struct	sockaddr_in6 se_un_ctrladdr6;
981c8d1174SDavid Malone 	        struct  sockaddr_un se_un_ctrladdr_un;
990cac72f4SYoshinobu Inoue 	} se_un;
1000cac72f4SYoshinobu Inoue #define se_ctrladdr	se_un.se_un_ctrladdr
1010cac72f4SYoshinobu Inoue #define se_ctrladdr4	se_un.se_un_ctrladdr4
1020cac72f4SYoshinobu Inoue #define se_ctrladdr6	se_un.se_un_ctrladdr6
1031c8d1174SDavid Malone #define se_ctrladdr_un   se_un.se_un_ctrladdr_un
1041c3b5f22SDavid Malone   	socklen_t	se_ctrladdr_size;
1051c8d1174SDavid Malone 	uid_t	se_sockuid;		/* Owner for unix domain socket */
1061c8d1174SDavid Malone 	gid_t	se_sockgid;		/* Group for unix domain socket */
1071c8d1174SDavid Malone 	mode_t	se_sockmode;		/* Mode for unix domain socket */
1085ff3afceSSheldon Hearn 	u_char	se_type;		/* type: normal, mux, or mux+ */
1095ff3afceSSheldon Hearn 	u_char	se_checked;		/* looked at during merge */
1105ff3afceSSheldon Hearn 	u_char	se_accept;		/* i.e., wait/nowait mode */
1115ff3afceSSheldon Hearn 	u_char	se_rpc;			/* ==1 if RPC service */
1125ff3afceSSheldon Hearn 	int	se_rpc_prog;		/* RPC program number */
1135ff3afceSSheldon Hearn 	u_int	se_rpc_lowvers;		/* RPC low version */
1145ff3afceSSheldon Hearn 	u_int	se_rpc_highvers;	/* RPC high version */
1155ff3afceSSheldon Hearn 	int	se_count;		/* number started since se_time */
1164f985ef6SXin LI 	struct	timespec se_time;	/* start of se_count */
1175ff3afceSSheldon Hearn 	struct	servtab *se_next;
1180cac72f4SYoshinobu Inoue 	struct se_flags {
1190cac72f4SYoshinobu Inoue 		u_int se_nomapped : 1;
1200cac72f4SYoshinobu Inoue 		u_int se_reset : 1;
1210cac72f4SYoshinobu Inoue 	} se_flags;
12209b1c357SHajimu UMEMOTO 	int	se_maxperip;		/* max number of children per src */
12309b1c357SHajimu UMEMOTO 	LIST_HEAD(, conninfo) se_conn[PERIPSIZE];
124c53b0f40SKyle Evans 	LIST_HEAD(, stabchild) se_children;
1255ff3afceSSheldon Hearn };
1265ff3afceSSheldon Hearn 
1270cac72f4SYoshinobu Inoue #define	se_nomapped		se_flags.se_nomapped
1280cac72f4SYoshinobu Inoue #define	se_reset		se_flags.se_reset
1290cac72f4SYoshinobu Inoue 
130d6272fceSKyle Evans #define	SERVTAB_AT_LIMIT(sep)		\
131d6272fceSKyle Evans 	((sep)->se_maxchild > 0 && (sep)->se_numchild == (sep)->se_maxchild)
132d6272fceSKyle Evans #define	SERVTAB_EXCEEDS_LIMIT(sep)	\
133d6272fceSKyle Evans 	((sep)->se_maxchild > 0 && (sep)->se_numchild >= (sep)->se_maxchild)
134d6272fceSKyle Evans 
135edb616bbSJuli Mallett int		check_loop(const struct sockaddr *, const struct servtab *sep);
136edb616bbSJuli Mallett void		inetd_setproctitle(const char *, int);
137edb616bbSJuli Mallett struct servtab *tcpmux(int);
1385ff3afceSSheldon Hearn 
139b585f768SDavid Malone extern int	 debug;
140b585f768SDavid Malone extern struct servtab *servtab;
141b585f768SDavid Malone 
142edb616bbSJuli Mallett typedef void (bi_fn_t)(int, struct servtab *);
1435ff3afceSSheldon Hearn 
1445ff3afceSSheldon Hearn struct biltin {
145b585f768SDavid Malone 	const char *bi_service;		/* internally provided service name */
1465ff3afceSSheldon Hearn 	int	bi_socktype;		/* type of socket supported */
1475ff3afceSSheldon Hearn 	short	bi_fork;		/* 1 if should fork before call */
1485ff3afceSSheldon Hearn 	int	bi_maxchild;		/* max number of children, -1=default */
149b585f768SDavid Malone 	bi_fn_t	*bi_fn;			/* function which performs it */
1505ff3afceSSheldon Hearn };
1514909085fSHiroki Sato extern struct biltin biltins[];
152