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> 395ff3afceSSheldon Hearn 405ff3afceSSheldon Hearn #include <netinet/in.h> 415ff3afceSSheldon Hearn 425ff3afceSSheldon Hearn #include <stdio.h> 435ff3afceSSheldon Hearn 445ff3afceSSheldon Hearn #define BUFSIZE 8192 455ff3afceSSheldon Hearn #define LINESIZ 72 465ff3afceSSheldon Hearn 475ff3afceSSheldon Hearn #define NORM_TYPE 0 485ff3afceSSheldon Hearn #define MUX_TYPE 1 495ff3afceSSheldon Hearn #define MUXPLUS_TYPE 2 505ff3afceSSheldon Hearn #define TTCP_TYPE 3 510cac72f4SYoshinobu Inoue #define FAITH_TYPE 4 525ff3afceSSheldon Hearn #define ISMUX(sep) (((sep)->se_type == MUX_TYPE) || \ 535ff3afceSSheldon Hearn ((sep)->se_type == MUXPLUS_TYPE)) 545ff3afceSSheldon Hearn #define ISMUXPLUS(sep) ((sep)->se_type == MUXPLUS_TYPE) 555ff3afceSSheldon Hearn #define ISTTCP(sep) ((sep)->se_type == TTCP_TYPE) 565ff3afceSSheldon Hearn 575ff3afceSSheldon Hearn struct servtab { 585ff3afceSSheldon Hearn char *se_service; /* name of service */ 595ff3afceSSheldon Hearn int se_socktype; /* type of socket to use */ 600cac72f4SYoshinobu Inoue int se_family; /* address family */ 615ff3afceSSheldon Hearn char *se_proto; /* protocol used */ 625ff3afceSSheldon Hearn int se_maxchild; /* max number of children */ 635ff3afceSSheldon Hearn int se_maxcpm; /* max connects per IP per minute */ 645ff3afceSSheldon Hearn int se_numchild; /* current number of children */ 655ff3afceSSheldon Hearn pid_t *se_pids; /* array of child pids */ 665ff3afceSSheldon Hearn char *se_user; /* user name to run as */ 675ff3afceSSheldon Hearn char *se_group; /* group name to run as */ 685ff3afceSSheldon Hearn #ifdef LOGIN_CAP 695ff3afceSSheldon Hearn char *se_class; /* login class name to run with */ 705ff3afceSSheldon Hearn #endif 715ff3afceSSheldon Hearn struct biltin *se_bi; /* if built-in, description */ 725ff3afceSSheldon Hearn char *se_server; /* server program */ 735ff3afceSSheldon Hearn char *se_server_name; /* server program without path */ 745ff3afceSSheldon Hearn #define MAXARGV 20 755ff3afceSSheldon Hearn char *se_argv[MAXARGV+1]; /* program arguments */ 760cac72f4SYoshinobu Inoue #ifdef IPSEC 77caf60155SDavid Malone char *se_policy; /* IPsec policy string */ 780cac72f4SYoshinobu Inoue #endif 795ff3afceSSheldon Hearn int se_fd; /* open descriptor */ 800cac72f4SYoshinobu Inoue union { /* bound address */ 810cac72f4SYoshinobu Inoue struct sockaddr se_un_ctrladdr; 820cac72f4SYoshinobu Inoue struct sockaddr_in se_un_ctrladdr4; 830cac72f4SYoshinobu Inoue struct sockaddr_in6 se_un_ctrladdr6; 841c8d1174SDavid Malone struct sockaddr_un se_un_ctrladdr_un; 850cac72f4SYoshinobu Inoue } se_un; 860cac72f4SYoshinobu Inoue #define se_ctrladdr se_un.se_un_ctrladdr 870cac72f4SYoshinobu Inoue #define se_ctrladdr4 se_un.se_un_ctrladdr4 880cac72f4SYoshinobu Inoue #define se_ctrladdr6 se_un.se_un_ctrladdr6 891c8d1174SDavid Malone #define se_ctrladdr_un se_un.se_un_ctrladdr_un 901c3b5f22SDavid Malone socklen_t se_ctrladdr_size; 911c8d1174SDavid Malone uid_t se_sockuid; /* Owner for unix domain socket */ 921c8d1174SDavid Malone gid_t se_sockgid; /* Group for unix domain socket */ 931c8d1174SDavid Malone mode_t se_sockmode; /* Mode for unix domain socket */ 945ff3afceSSheldon Hearn u_char se_type; /* type: normal, mux, or mux+ */ 955ff3afceSSheldon Hearn u_char se_checked; /* looked at during merge */ 965ff3afceSSheldon Hearn u_char se_accept; /* i.e., wait/nowait mode */ 975ff3afceSSheldon Hearn u_char se_rpc; /* ==1 if RPC service */ 985ff3afceSSheldon Hearn int se_rpc_prog; /* RPC program number */ 995ff3afceSSheldon Hearn u_int se_rpc_lowvers; /* RPC low version */ 1005ff3afceSSheldon Hearn u_int se_rpc_highvers; /* RPC high version */ 1015ff3afceSSheldon Hearn int se_count; /* number started since se_time */ 1025ff3afceSSheldon Hearn struct timeval se_time; /* start of se_count */ 1035ff3afceSSheldon Hearn struct servtab *se_next; 1040cac72f4SYoshinobu Inoue struct se_flags { 1050cac72f4SYoshinobu Inoue u_int se_nomapped : 1; 1060cac72f4SYoshinobu Inoue u_int se_reset : 1; 1070cac72f4SYoshinobu Inoue } se_flags; 1085ff3afceSSheldon Hearn }; 1095ff3afceSSheldon Hearn 1100cac72f4SYoshinobu Inoue #define se_nomapped se_flags.se_nomapped 1110cac72f4SYoshinobu Inoue #define se_reset se_flags.se_reset 1120cac72f4SYoshinobu Inoue 1135ff3afceSSheldon Hearn void chargen_dg __P((int, struct servtab *)); 1145ff3afceSSheldon Hearn void chargen_stream __P((int, struct servtab *)); 1155ff3afceSSheldon Hearn void close_sep __P((struct servtab *)); 11613f1579aSDavid Malone void flag_signal __P((int)); 1175ff3afceSSheldon Hearn void flag_config __P((int)); 1185ff3afceSSheldon Hearn void config __P((void)); 1195ff3afceSSheldon Hearn void daytime_dg __P((int, struct servtab *)); 1205ff3afceSSheldon Hearn void daytime_stream __P((int, struct servtab *)); 1215ff3afceSSheldon Hearn void discard_dg __P((int, struct servtab *)); 1225ff3afceSSheldon Hearn void discard_stream __P((int, struct servtab *)); 1235ff3afceSSheldon Hearn void echo_dg __P((int, struct servtab *)); 1245ff3afceSSheldon Hearn void echo_stream __P((int, struct servtab *)); 1255ff3afceSSheldon Hearn void endconfig __P((void)); 1265ff3afceSSheldon Hearn struct servtab *enter __P((struct servtab *)); 1275ff3afceSSheldon Hearn void freeconfig __P((struct servtab *)); 1285ff3afceSSheldon Hearn struct servtab *getconfigent __P((void)); 1299a0b3389SDavid Malone void iderror __P((int, int, int, char *)); 1305ff3afceSSheldon Hearn void ident_stream __P((int, struct servtab *)); 1315ff3afceSSheldon Hearn void machtime_dg __P((int, struct servtab *)); 1325ff3afceSSheldon Hearn void machtime_stream __P((int, struct servtab *)); 1335ff3afceSSheldon Hearn int matchservent __P((char *, char *, char *)); 1345ff3afceSSheldon Hearn char *newstr __P((char *)); 1355ff3afceSSheldon Hearn char *nextline __P((FILE *)); 1365ff3afceSSheldon Hearn void print_service __P((char *, struct servtab *)); 1375ff3afceSSheldon Hearn void addchild __P((struct servtab *, int)); 1385ff3afceSSheldon Hearn void flag_reapchild __P((int)); 1395ff3afceSSheldon Hearn void reapchild __P((void)); 1405ff3afceSSheldon Hearn void enable __P((struct servtab *)); 1415ff3afceSSheldon Hearn void disable __P((struct servtab *)); 1425ff3afceSSheldon Hearn void flag_retry __P((int)); 1435ff3afceSSheldon Hearn void retry __P((void)); 1445ff3afceSSheldon Hearn int setconfig __P((void)); 1455ff3afceSSheldon Hearn void setup __P((struct servtab *)); 1460cac72f4SYoshinobu Inoue #ifdef IPSEC 1470cac72f4SYoshinobu Inoue void ipsecsetup __P((struct servtab *)); 1480cac72f4SYoshinobu Inoue #endif 1495ff3afceSSheldon Hearn char *sskip __P((char **)); 1505ff3afceSSheldon Hearn char *skip __P((char **)); 1515ff3afceSSheldon Hearn struct servtab *tcpmux __P((int)); 1525ff3afceSSheldon Hearn int cpmip __P((struct servtab *, int)); 1535ff3afceSSheldon Hearn void inetd_setproctitle __P((char *, int)); 15413f1579aSDavid Malone int check_loop __P((struct sockaddr *, struct servtab *sep)); 1555ff3afceSSheldon Hearn 1565ff3afceSSheldon Hearn void unregisterrpc __P((register struct servtab *sep)); 1575ff3afceSSheldon Hearn 1585ff3afceSSheldon Hearn struct biltin { 1595ff3afceSSheldon Hearn char *bi_service; /* internally provided service name */ 1605ff3afceSSheldon Hearn int bi_socktype; /* type of socket supported */ 1615ff3afceSSheldon Hearn short bi_fork; /* 1 if should fork before call */ 1625ff3afceSSheldon Hearn int bi_maxchild; /* max number of children, -1=default */ 1635ff3afceSSheldon Hearn void (*bi_fn)(); /* function which performs it */ 1645ff3afceSSheldon Hearn }; 165