15ff3afceSSheldon Hearn /* 25ff3afceSSheldon Hearn * Copyright (c) 1983, 1991, 1993, 1994 35ff3afceSSheldon Hearn * The Regents of the University of California. All rights reserved. 45ff3afceSSheldon Hearn * 55ff3afceSSheldon Hearn * Redistribution and use in source and binary forms, with or without 65ff3afceSSheldon Hearn * modification, are permitted provided that the following conditions 75ff3afceSSheldon Hearn * are met: 85ff3afceSSheldon Hearn * 1. Redistributions of source code must retain the above copyright 95ff3afceSSheldon Hearn * notice, this list of conditions and the following disclaimer. 105ff3afceSSheldon Hearn * 2. Redistributions in binary form must reproduce the above copyright 115ff3afceSSheldon Hearn * notice, this list of conditions and the following disclaimer in the 125ff3afceSSheldon Hearn * documentation and/or other materials provided with the distribution. 135ff3afceSSheldon Hearn * 3. All advertising materials mentioning features or use of this software 145ff3afceSSheldon Hearn * must display the following acknowledgement: 155ff3afceSSheldon Hearn * This product includes software developed by the University of 165ff3afceSSheldon Hearn * California, Berkeley and its contributors. 175ff3afceSSheldon Hearn * 4. Neither the name of the University nor the names of its contributors 185ff3afceSSheldon Hearn * may be used to endorse or promote products derived from this software 195ff3afceSSheldon Hearn * without specific prior written permission. 205ff3afceSSheldon Hearn * 215ff3afceSSheldon Hearn * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 225ff3afceSSheldon Hearn * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 235ff3afceSSheldon Hearn * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 245ff3afceSSheldon Hearn * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 255ff3afceSSheldon Hearn * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 265ff3afceSSheldon Hearn * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 275ff3afceSSheldon Hearn * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 285ff3afceSSheldon Hearn * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 295ff3afceSSheldon Hearn * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 305ff3afceSSheldon Hearn * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 315ff3afceSSheldon Hearn * SUCH DAMAGE. 325ff3afceSSheldon Hearn * 3397d92980SPeter Wemm * $FreeBSD$ 345ff3afceSSheldon Hearn */ 355ff3afceSSheldon Hearn 365ff3afceSSheldon Hearn #include <sys/time.h> 375ff3afceSSheldon Hearn #include <sys/socket.h> 381c8d1174SDavid Malone #include <sys/un.h> 3909b1c357SHajimu UMEMOTO #include <sys/queue.h> 405ff3afceSSheldon Hearn 415ff3afceSSheldon Hearn #include <netinet/in.h> 425ff3afceSSheldon Hearn 435ff3afceSSheldon Hearn #include <stdio.h> 445ff3afceSSheldon Hearn 455ff3afceSSheldon Hearn #define BUFSIZE 8192 465ff3afceSSheldon Hearn #define LINESIZ 72 475ff3afceSSheldon Hearn 485ff3afceSSheldon Hearn #define NORM_TYPE 0 495ff3afceSSheldon Hearn #define MUX_TYPE 1 505ff3afceSSheldon Hearn #define MUXPLUS_TYPE 2 515ff3afceSSheldon Hearn #define TTCP_TYPE 3 520cac72f4SYoshinobu Inoue #define FAITH_TYPE 4 535ff3afceSSheldon Hearn #define ISMUX(sep) (((sep)->se_type == MUX_TYPE) || \ 545ff3afceSSheldon Hearn ((sep)->se_type == MUXPLUS_TYPE)) 555ff3afceSSheldon Hearn #define ISMUXPLUS(sep) ((sep)->se_type == MUXPLUS_TYPE) 565ff3afceSSheldon Hearn #define ISTTCP(sep) ((sep)->se_type == TTCP_TYPE) 575ff3afceSSheldon Hearn 5809b1c357SHajimu UMEMOTO struct procinfo { 5909b1c357SHajimu UMEMOTO LIST_ENTRY(procinfo) pr_link; 6009b1c357SHajimu UMEMOTO pid_t pr_pid; /* child pid */ 6109b1c357SHajimu UMEMOTO struct conninfo *pr_conn; 6209b1c357SHajimu UMEMOTO }; 6309b1c357SHajimu UMEMOTO 6409b1c357SHajimu UMEMOTO struct conninfo { 6509b1c357SHajimu UMEMOTO LIST_ENTRY(conninfo) co_link; 6609b1c357SHajimu UMEMOTO struct sockaddr_storage co_addr; /* source address */ 6709b1c357SHajimu UMEMOTO int co_numchild; /* current number of children */ 6809b1c357SHajimu UMEMOTO struct procinfo **co_proc; /* array of child proc entry */ 6909b1c357SHajimu UMEMOTO }; 7009b1c357SHajimu UMEMOTO 7109b1c357SHajimu UMEMOTO #define PERIPSIZE 256 7209b1c357SHajimu UMEMOTO 735ff3afceSSheldon Hearn struct servtab { 745ff3afceSSheldon Hearn char *se_service; /* name of service */ 755ff3afceSSheldon Hearn int se_socktype; /* type of socket to use */ 760cac72f4SYoshinobu Inoue int se_family; /* address family */ 775ff3afceSSheldon Hearn char *se_proto; /* protocol used */ 785ff3afceSSheldon Hearn int se_maxchild; /* max number of children */ 795ff3afceSSheldon Hearn int se_maxcpm; /* max connects per IP per minute */ 805ff3afceSSheldon Hearn int se_numchild; /* current number of children */ 815ff3afceSSheldon Hearn pid_t *se_pids; /* array of child pids */ 825ff3afceSSheldon Hearn char *se_user; /* user name to run as */ 835ff3afceSSheldon Hearn char *se_group; /* group name to run as */ 845ff3afceSSheldon Hearn #ifdef LOGIN_CAP 855ff3afceSSheldon Hearn char *se_class; /* login class name to run with */ 865ff3afceSSheldon Hearn #endif 875ff3afceSSheldon Hearn struct biltin *se_bi; /* if built-in, description */ 885ff3afceSSheldon Hearn char *se_server; /* server program */ 895ff3afceSSheldon Hearn char *se_server_name; /* server program without path */ 905ff3afceSSheldon Hearn #define MAXARGV 20 915ff3afceSSheldon Hearn char *se_argv[MAXARGV+1]; /* program arguments */ 920cac72f4SYoshinobu Inoue #ifdef IPSEC 93caf60155SDavid Malone char *se_policy; /* IPsec policy string */ 940cac72f4SYoshinobu Inoue #endif 955ff3afceSSheldon Hearn int se_fd; /* open descriptor */ 960cac72f4SYoshinobu Inoue union { /* bound address */ 970cac72f4SYoshinobu Inoue struct sockaddr se_un_ctrladdr; 980cac72f4SYoshinobu Inoue struct sockaddr_in se_un_ctrladdr4; 990cac72f4SYoshinobu Inoue struct sockaddr_in6 se_un_ctrladdr6; 1001c8d1174SDavid Malone struct sockaddr_un se_un_ctrladdr_un; 1010cac72f4SYoshinobu Inoue } se_un; 1020cac72f4SYoshinobu Inoue #define se_ctrladdr se_un.se_un_ctrladdr 1030cac72f4SYoshinobu Inoue #define se_ctrladdr4 se_un.se_un_ctrladdr4 1040cac72f4SYoshinobu Inoue #define se_ctrladdr6 se_un.se_un_ctrladdr6 1051c8d1174SDavid Malone #define se_ctrladdr_un se_un.se_un_ctrladdr_un 1061c3b5f22SDavid Malone socklen_t se_ctrladdr_size; 1071c8d1174SDavid Malone uid_t se_sockuid; /* Owner for unix domain socket */ 1081c8d1174SDavid Malone gid_t se_sockgid; /* Group for unix domain socket */ 1091c8d1174SDavid Malone mode_t se_sockmode; /* Mode for unix domain socket */ 1105ff3afceSSheldon Hearn u_char se_type; /* type: normal, mux, or mux+ */ 1115ff3afceSSheldon Hearn u_char se_checked; /* looked at during merge */ 1125ff3afceSSheldon Hearn u_char se_accept; /* i.e., wait/nowait mode */ 1135ff3afceSSheldon Hearn u_char se_rpc; /* ==1 if RPC service */ 1145ff3afceSSheldon Hearn int se_rpc_prog; /* RPC program number */ 1155ff3afceSSheldon Hearn u_int se_rpc_lowvers; /* RPC low version */ 1165ff3afceSSheldon Hearn u_int se_rpc_highvers; /* RPC high version */ 1175ff3afceSSheldon Hearn int se_count; /* number started since se_time */ 1185ff3afceSSheldon Hearn struct timeval se_time; /* start of se_count */ 1195ff3afceSSheldon Hearn struct servtab *se_next; 1200cac72f4SYoshinobu Inoue struct se_flags { 1210cac72f4SYoshinobu Inoue u_int se_nomapped : 1; 1220cac72f4SYoshinobu Inoue u_int se_reset : 1; 1230cac72f4SYoshinobu Inoue } se_flags; 12409b1c357SHajimu UMEMOTO int se_maxperip; /* max number of children per src */ 12509b1c357SHajimu UMEMOTO LIST_HEAD(, conninfo) se_conn[PERIPSIZE]; 1265ff3afceSSheldon Hearn }; 1275ff3afceSSheldon Hearn 1280cac72f4SYoshinobu Inoue #define se_nomapped se_flags.se_nomapped 1290cac72f4SYoshinobu Inoue #define se_reset se_flags.se_reset 1300cac72f4SYoshinobu Inoue 131edb616bbSJuli Mallett int check_loop(const struct sockaddr *, const struct servtab *sep); 132edb616bbSJuli Mallett int getvalue(const char *, int *, const char *); 133edb616bbSJuli Mallett char *newstr(const char *); 134edb616bbSJuli Mallett void inetd_setproctitle(const char *, int); 135edb616bbSJuli Mallett void print_service(const char *, const struct servtab *); 136edb616bbSJuli Mallett char *sskip(char **); 137edb616bbSJuli Mallett char *skip(char **); 138edb616bbSJuli Mallett struct servtab *tcpmux(int); 1395ff3afceSSheldon Hearn 140b585f768SDavid Malone extern int debug; 141b585f768SDavid Malone extern struct servtab *servtab; 142b585f768SDavid Malone 143edb616bbSJuli Mallett typedef void (bi_fn_t)(int, struct servtab *); 1445ff3afceSSheldon Hearn 1455ff3afceSSheldon Hearn struct biltin { 146b585f768SDavid Malone const char *bi_service; /* internally provided service name */ 1475ff3afceSSheldon Hearn int bi_socktype; /* type of socket supported */ 1485ff3afceSSheldon Hearn short bi_fork; /* 1 if should fork before call */ 1495ff3afceSSheldon Hearn int bi_maxchild; /* max number of children, -1=default */ 150b585f768SDavid Malone bi_fn_t *bi_fn; /* function which performs it */ 1515ff3afceSSheldon Hearn }; 152