148981Ssheldonh/* 248981Ssheldonh * Copyright (c) 1983, 1991, 1993, 1994 348981Ssheldonh * The Regents of the University of California. All rights reserved. 448981Ssheldonh * 548981Ssheldonh * Redistribution and use in source and binary forms, with or without 648981Ssheldonh * modification, are permitted provided that the following conditions 748981Ssheldonh * are met: 848981Ssheldonh * 1. Redistributions of source code must retain the above copyright 948981Ssheldonh * notice, this list of conditions and the following disclaimer. 1048981Ssheldonh * 2. Redistributions in binary form must reproduce the above copyright 1148981Ssheldonh * notice, this list of conditions and the following disclaimer in the 1248981Ssheldonh * documentation and/or other materials provided with the distribution. 1348981Ssheldonh * 4. Neither the name of the University nor the names of its contributors 1448981Ssheldonh * may be used to endorse or promote products derived from this software 1548981Ssheldonh * without specific prior written permission. 1648981Ssheldonh * 1748981Ssheldonh * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 1848981Ssheldonh * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1948981Ssheldonh * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2048981Ssheldonh * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2148981Ssheldonh * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2248981Ssheldonh * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2348981Ssheldonh * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2448981Ssheldonh * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2548981Ssheldonh * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2648981Ssheldonh * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2748981Ssheldonh * SUCH DAMAGE. 2848981Ssheldonh * 2950479Speter * $FreeBSD$ 3048981Ssheldonh */ 3148981Ssheldonh 3248981Ssheldonh#include <sys/time.h> 3348981Ssheldonh#include <sys/socket.h> 3478356Sdwmalone#include <sys/un.h> 35101474Sume#include <sys/queue.h> 3648981Ssheldonh 3748981Ssheldonh#include <netinet/in.h> 3848981Ssheldonh 3948981Ssheldonh#include <stdio.h> 4048981Ssheldonh 4148981Ssheldonh#define BUFSIZE 8192 4248981Ssheldonh#define LINESIZ 72 4348981Ssheldonh 4448981Ssheldonh#define NORM_TYPE 0 4548981Ssheldonh#define MUX_TYPE 1 4648981Ssheldonh#define MUXPLUS_TYPE 2 4756590Sshin#define FAITH_TYPE 4 4848981Ssheldonh#define ISMUX(sep) (((sep)->se_type == MUX_TYPE) || \ 4948981Ssheldonh ((sep)->se_type == MUXPLUS_TYPE)) 5048981Ssheldonh#define ISMUXPLUS(sep) ((sep)->se_type == MUXPLUS_TYPE) 5148981Ssheldonh 52101474Sumestruct procinfo { 53101474Sume LIST_ENTRY(procinfo) pr_link; 54101474Sume pid_t pr_pid; /* child pid */ 55101474Sume struct conninfo *pr_conn; 56101474Sume}; 57101474Sume 58101474Sumestruct conninfo { 59101474Sume LIST_ENTRY(conninfo) co_link; 60101474Sume struct sockaddr_storage co_addr; /* source address */ 61101474Sume int co_numchild; /* current number of children */ 62101474Sume struct procinfo **co_proc; /* array of child proc entry */ 63101474Sume}; 64101474Sume 65101474Sume#define PERIPSIZE 256 66101474Sume 6748981Ssheldonhstruct servtab { 6848981Ssheldonh char *se_service; /* name of service */ 6948981Ssheldonh int se_socktype; /* type of socket to use */ 7056590Sshin int se_family; /* address family */ 7148981Ssheldonh char *se_proto; /* protocol used */ 7248981Ssheldonh int se_maxchild; /* max number of children */ 7348981Ssheldonh int se_maxcpm; /* max connects per IP per minute */ 7448981Ssheldonh int se_numchild; /* current number of children */ 7548981Ssheldonh pid_t *se_pids; /* array of child pids */ 7648981Ssheldonh char *se_user; /* user name to run as */ 7748981Ssheldonh char *se_group; /* group name to run as */ 7848981Ssheldonh#ifdef LOGIN_CAP 7948981Ssheldonh char *se_class; /* login class name to run with */ 8048981Ssheldonh#endif 8148981Ssheldonh struct biltin *se_bi; /* if built-in, description */ 8248981Ssheldonh char *se_server; /* server program */ 8348981Ssheldonh char *se_server_name; /* server program without path */ 8448981Ssheldonh#define MAXARGV 20 8548981Ssheldonh char *se_argv[MAXARGV+1]; /* program arguments */ 8656590Sshin#ifdef IPSEC 8767514Sdwmalone char *se_policy; /* IPsec policy string */ 8856590Sshin#endif 8948981Ssheldonh int se_fd; /* open descriptor */ 9056590Sshin union { /* bound address */ 9156590Sshin struct sockaddr se_un_ctrladdr; 9256590Sshin struct sockaddr_in se_un_ctrladdr4; 9356590Sshin struct sockaddr_in6 se_un_ctrladdr6; 9478356Sdwmalone struct sockaddr_un se_un_ctrladdr_un; 9556590Sshin } se_un; 9656590Sshin#define se_ctrladdr se_un.se_un_ctrladdr 9756590Sshin#define se_ctrladdr4 se_un.se_un_ctrladdr4 9856590Sshin#define se_ctrladdr6 se_un.se_un_ctrladdr6 9978356Sdwmalone#define se_ctrladdr_un se_un.se_un_ctrladdr_un 10071399Sdwmalone socklen_t se_ctrladdr_size; 10178356Sdwmalone uid_t se_sockuid; /* Owner for unix domain socket */ 10278356Sdwmalone gid_t se_sockgid; /* Group for unix domain socket */ 10378356Sdwmalone mode_t se_sockmode; /* Mode for unix domain socket */ 10448981Ssheldonh u_char se_type; /* type: normal, mux, or mux+ */ 10548981Ssheldonh u_char se_checked; /* looked at during merge */ 10648981Ssheldonh u_char se_accept; /* i.e., wait/nowait mode */ 10748981Ssheldonh u_char se_rpc; /* ==1 if RPC service */ 10848981Ssheldonh int se_rpc_prog; /* RPC program number */ 10948981Ssheldonh u_int se_rpc_lowvers; /* RPC low version */ 11048981Ssheldonh u_int se_rpc_highvers; /* RPC high version */ 11148981Ssheldonh int se_count; /* number started since se_time */ 112236572Sdelphij struct timespec se_time; /* start of se_count */ 11348981Ssheldonh struct servtab *se_next; 11456590Sshin struct se_flags { 11556590Sshin u_int se_nomapped : 1; 11656590Sshin u_int se_reset : 1; 11756590Sshin } se_flags; 118101474Sume int se_maxperip; /* max number of children per src */ 119101474Sume LIST_HEAD(, conninfo) se_conn[PERIPSIZE]; 12048981Ssheldonh}; 12148981Ssheldonh 12256590Sshin#define se_nomapped se_flags.se_nomapped 12356590Sshin#define se_reset se_flags.se_reset 12456590Sshin 12598562Sjmallettint check_loop(const struct sockaddr *, const struct servtab *sep); 12698562Sjmallettint getvalue(const char *, int *, const char *); 12798562Sjmallettchar *newstr(const char *); 12898562Sjmallettvoid inetd_setproctitle(const char *, int); 12998562Sjmallettvoid print_service(const char *, const struct servtab *); 13098562Sjmallettchar *sskip(char **); 13198562Sjmallettchar *skip(char **); 13298562Sjmallettstruct servtab *tcpmux(int); 13348981Ssheldonh 13478694Sdwmaloneextern int debug; 13578694Sdwmaloneextern struct servtab *servtab; 13648981Ssheldonh 13798562Sjmalletttypedef void (bi_fn_t)(int, struct servtab *); 13878694Sdwmalone 13948981Ssheldonhstruct biltin { 14078694Sdwmalone const char *bi_service; /* internally provided service name */ 14148981Ssheldonh int bi_socktype; /* type of socket supported */ 14248981Ssheldonh short bi_fork; /* 1 if should fork before call */ 14348981Ssheldonh int bi_maxchild; /* max number of children, -1=default */ 14478694Sdwmalone bi_fn_t *bi_fn; /* function which performs it */ 14548981Ssheldonh}; 146