xref: /freebsd/usr.sbin/inetd/inetd.h (revision cfd6422a5217410fbd66f7a7a8a64d9d85e61229)
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 1983, 1991, 1993, 1994
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. Neither the name of the University nor the names of its contributors
16  *    may be used to endorse or promote products derived from this software
17  *    without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29  * SUCH DAMAGE.
30  *
31  * $FreeBSD$
32  */
33 
34 #include <sys/time.h>
35 #include <sys/socket.h>
36 #include <sys/un.h>
37 #include <sys/queue.h>
38 
39 #include <netinet/in.h>
40 
41 #include <stdio.h>
42 
43 #define BUFSIZE 8192
44 #define LINESIZ 72
45 
46 #define NORM_TYPE	0
47 #define MUX_TYPE	1
48 #define MUXPLUS_TYPE	2
49 #define FAITH_TYPE	4
50 #define ISMUX(sep)	(((sep)->se_type == MUX_TYPE) || \
51 			 ((sep)->se_type == MUXPLUS_TYPE))
52 #define ISMUXPLUS(sep)	((sep)->se_type == MUXPLUS_TYPE)
53 
54 struct procinfo {
55 	LIST_ENTRY(procinfo) pr_link;
56 	pid_t		pr_pid;		/* child pid */
57 	struct conninfo	*pr_conn;
58 };
59 
60 struct conninfo {
61 	LIST_ENTRY(conninfo) co_link;
62 	struct sockaddr_storage	co_addr;	/* source address */
63 	int		co_numchild;	/* current number of children */
64 	struct procinfo	**co_proc;	/* array of child proc entry */
65 };
66 
67 #define PERIPSIZE	256
68 
69 struct	stabchild {
70 	LIST_ENTRY(stabchild)	sc_link;
71 	pid_t			sc_pid;
72 };
73 
74 struct	servtab {
75 	char	*se_service;		/* name of service */
76 	int	se_socktype;		/* type of socket to use */
77 	int	se_family;		/* address family */
78 	char	*se_proto;		/* protocol used */
79 	int	se_maxchild;		/* max number of children */
80 	int	se_maxcpm;		/* max connects per IP per minute */
81 	int	se_numchild;		/* current number of children */
82 	char	*se_user;		/* user name to run as */
83 	char    *se_group;              /* group name to run as */
84 #ifdef  LOGIN_CAP
85 	char    *se_class;              /* login class name to run with */
86 #endif
87 	struct	biltin *se_bi;		/* if built-in, description */
88 	char	*se_server;		/* server program */
89 	char	*se_server_name;	/* server program without path */
90 #define	MAXARGV 20
91 	char	*se_argv[MAXARGV+1];	/* program arguments */
92 #ifdef IPSEC
93 	char	*se_policy;		/* IPsec policy string */
94 #endif
95 	int	se_fd;			/* open descriptor */
96 	union {				/* bound address */
97 		struct	sockaddr se_un_ctrladdr;
98 		struct	sockaddr_in se_un_ctrladdr4;
99 		struct	sockaddr_in6 se_un_ctrladdr6;
100 	        struct  sockaddr_un se_un_ctrladdr_un;
101 	} se_un;
102 #define se_ctrladdr	se_un.se_un_ctrladdr
103 #define se_ctrladdr4	se_un.se_un_ctrladdr4
104 #define se_ctrladdr6	se_un.se_un_ctrladdr6
105 #define se_ctrladdr_un   se_un.se_un_ctrladdr_un
106   	socklen_t	se_ctrladdr_size;
107 	uid_t	se_sockuid;		/* Owner for unix domain socket */
108 	gid_t	se_sockgid;		/* Group for unix domain socket */
109 	mode_t	se_sockmode;		/* Mode for unix domain socket */
110 	u_char	se_type;		/* type: normal, mux, or mux+ */
111 	u_char	se_checked;		/* looked at during merge */
112 	u_char	se_accept;		/* i.e., wait/nowait mode */
113 	u_char	se_rpc;			/* ==1 if RPC service */
114 	int	se_rpc_prog;		/* RPC program number */
115 	u_int	se_rpc_lowvers;		/* RPC low version */
116 	u_int	se_rpc_highvers;	/* RPC high version */
117 	int	se_count;		/* number started since se_time */
118 	struct	timespec se_time;	/* start of se_count */
119 	struct	servtab *se_next;
120 	struct se_flags {
121 		u_int se_nomapped : 1;
122 		u_int se_reset : 1;
123 	} se_flags;
124 	int	se_maxperip;		/* max number of children per src */
125 	LIST_HEAD(, conninfo) se_conn[PERIPSIZE];
126 	LIST_HEAD(, stabchild) se_children;
127 };
128 
129 #define	se_nomapped		se_flags.se_nomapped
130 #define	se_reset		se_flags.se_reset
131 
132 #define	SERVTAB_AT_LIMIT(sep)		\
133 	((sep)->se_maxchild > 0 && (sep)->se_numchild == (sep)->se_maxchild)
134 #define	SERVTAB_EXCEEDS_LIMIT(sep)	\
135 	((sep)->se_maxchild > 0 && (sep)->se_numchild >= (sep)->se_maxchild)
136 
137 int		check_loop(const struct sockaddr *, const struct servtab *sep);
138 void		inetd_setproctitle(const char *, int);
139 struct servtab *tcpmux(int);
140 
141 extern int	 debug;
142 extern struct servtab *servtab;
143 
144 typedef void (bi_fn_t)(int, struct servtab *);
145 
146 struct biltin {
147 	const char *bi_service;		/* internally provided service name */
148 	int	bi_socktype;		/* type of socket supported */
149 	short	bi_fork;		/* 1 if should fork before call */
150 	int	bi_maxchild;		/* max number of children, -1=default */
151 	bi_fn_t	*bi_fn;			/* function which performs it */
152 };
153 extern struct biltin biltins[];
154