diff -cprN netkit-base-0.16/inetd/Makefile netkit-base/inetd/Makefile *** netkit-base-0.16/inetd/Makefile Mon Aug 23 03:30:24 1999 --- netkit-base/inetd/Makefile Thu May 4 13:31:34 2000 *************** all: inetd *** 3,10 **** include ../MCONFIG include ../MRULES ! inetd: inetd.o servtab.o builtins.o sig.o daemon.o setproctitle.o ! $(CC) $(LDFLAGS) $^ $(LIBS) -o $@ include depend.mk depend: --- 3,10 ---- include ../MCONFIG include ../MRULES ! inetd: inetd.o servtab.o builtins.o sig.o daemon.o setproctitle.o vsd.o ! $(CC) $(LDFLAGS) $^ $(LIBS) -lvsd -o $@ include depend.mk depend: diff -cprN netkit-base-0.16/inetd/inetd.c netkit-base/inetd/inetd.c *** netkit-base-0.16/inetd/inetd.c Tue Nov 23 19:31:53 1999 --- netkit-base/inetd/inetd.c Thu May 4 14:07:45 2000 *************** char rcsid[] = *** 138,143 **** --- 138,145 ---- #include #include + #include + #ifndef __linux__ #ifndef RLIMIT_NOFILE #define RLIMIT_NOFILE RLIMIT_OFILE *************** char rcsid[] = *** 150,155 **** --- 152,158 ---- #include "sig.h" #include "daemon.h" #include "setproctitle.h" + #include "vsd.h" #ifdef RPC /* must come after inetd.h, which defines RPC */ /* work around a compiler warning in rpc.h in libc5 */ *************** exec_child(struct servtab *sep) *** 283,288 **** --- 286,308 ---- */ if (debug) { setsid(); + } + + if (sep->se_virtual) { + /* Find the virtual server that this connection is destined for. */ + struct vsd_vs *vs = find_virtual_server (0); + if (vs) { + char *path = vsd_map_server_root (virtual_servers, vs->name); + if (chroot (path)) { + syslog (LOG_ERR, "chroot to %s failed: %m", path); + return; + } + if (chdir ("/")) { + syslog (LOG_ERR, "chdir failed: %m"); + return; + } + free (path); + } } /* diff -cprN netkit-base-0.16/inetd/servtab.c netkit-base/inetd/servtab.c *** netkit-base-0.16/inetd/servtab.c Fri Dec 3 03:47:56 1999 --- netkit-base/inetd/servtab.c Wed May 17 04:49:22 2000 *************** more: *** 324,330 **** sep->se_max = TOOMANY; } sep->se_wait = strcmp(arg, "wait") == 0; ! sep->se_user = dostrdup(skip(&cp)); sep->se_group = strchr(sep->se_user, '.'); if (sep->se_group) { *sep->se_group++ = '\0'; --- 324,336 ---- sep->se_max = TOOMANY; } sep->se_wait = strcmp(arg, "wait") == 0; ! /* The `virtual' parameter is optional. */ ! arg = skip(&cp); ! sep->se_virtual = strcmp(arg, "virtual") == 0; ! if (sep->se_virtual) ! sep->se_user = dostrdup(skip(&cp)); ! else ! sep->se_user = dostrdup(arg); sep->se_group = strchr(sep->se_user, '.'); if (sep->se_group) { *sep->se_group++ = '\0'; *************** assemble_entry(struct servtab *sep, int *** 499,505 **** sep->se_wait = !strcmp(fields[3], "wait"); free(fields[3]); ! s = strchr(fields[4], '.'); if (s) { *s++ = 0; sep->se_group = s; --- 505,514 ---- sep->se_wait = !strcmp(fields[3], "wait"); free(fields[3]); ! sep->se_virtual = !strcmp(fields[4], "virtual"); ! free(fields[4]); ! ! s = strchr(fields[5], '.'); if (s) { *s++ = 0; sep->se_group = s; *************** assemble_entry(struct servtab *sep, int *** 507,516 **** else { sep->se_group = NULL; } ! sep->se_user = fields[4]; ! sep->se_server = fields[5]; ! if (!strcmp(fields[5], "internal")) { sep->se_bi = find_builtin(sep->se_socktype, sep->se_service); if (sep->se_bi==NULL) { return "Invalid internal service"; --- 516,525 ---- else { sep->se_group = NULL; } ! sep->se_user = fields[5]; ! sep->se_server = fields[6]; ! if (!strcmp(fields[6], "internal")) { sep->se_bi = find_builtin(sep->se_socktype, sep->se_service); if (sep->se_bi==NULL) { return "Invalid internal service"; *************** assemble_entry(struct servtab *sep, int *** 522,529 **** } /* The rest are argv[]. */ ! for (i=6; ise_argv[i-6] = fields[i]; } /* Most programs core if argv[0] is null. */ --- 531,538 ---- } /* The rest are argv[]. */ ! for (i=7; ise_argv[i-7] = fields[i]; } /* Most programs core if argv[0] is null. */ *************** config(int signum) *** 918,923 **** --- 927,935 ---- freeconfig(sep); free((char *)sep); } + /* Read virtual server configuration file. */ + delete_server_map (); + read_server_map (); } /********* SIGALRM handler ******************************/ diff -cprN netkit-base-0.16/inetd/servtab.h netkit-base/inetd/servtab.h *** netkit-base-0.16/inetd/servtab.h Mon Aug 23 08:22:30 1999 --- netkit-base/inetd/servtab.h Thu May 4 13:11:45 2000 *************** struct servtab { *** 19,24 **** --- 19,25 ---- int se_rpcprog; /* rpc program number */ int se_rpcversl; /* rpc program lowest version */ int se_rpcversh; /* rpc program highest version */ + int se_virtual; /* candidate for a virtual server */ short se_wait; /* single threaded server */ short se_checked; /* looked at during merge */ char *se_user; /* user name to run as */ diff -cprN netkit-base-0.16/inetd/vsd.c netkit-base/inetd/vsd.c *** netkit-base-0.16/inetd/vsd.c Thu Jan 1 01:00:00 1970 --- netkit-base/inetd/vsd.c Thu May 4 14:13:21 2000 *************** *** 0 **** --- 1,77 ---- + /* Virtual server extensions to inetd. + Copyright (c) 1999, 2000 Idaya Ltd. + Written by Nick Burrett + + This file is part of the Virtual Server Administrator (FreeVSD) + + FreeVSD is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + FreeVSD is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with FreeVSD; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + + #include + #include + #include + #include + #include + #include "vsd.h" + + struct vsd_vs_map *virtual_servers; + + void read_server_map (void) + { + virtual_servers = vsd_map_read (); + } + + /* Remove the server map from memory. */ + void delete_server_map (void) + { + vsd_map_free (virtual_servers); + } + + /* Map an IP address to a virtual server name. + Return NULL on error and "localhost" if no translation could be found. */ + struct vsd_vs *find_virtual_server (int socket) + { + struct sockaddr_in addr; + struct vsd_vs *vs; + int namelen; + char *ip; + + namelen = sizeof (addr); + if (getsockname (socket, (struct sockaddr *)&addr, &namelen) < 0) + { + syslog (LOG_ERR, "getsockname failed: %m"); + return NULL; + } + + ip = inet_ntoa (addr.sin_addr); + + /* Find virtual server. */ + vs = vsd_getmapent (virtual_servers, NULL, ip); + if (vs != NULL) + { + /* Is the virtual server account disabled ? */ + if (vs->status != 0) + { + syslog (LOG_INFO, "attempted access to disabled account %s", + vs->name); + return NULL; + } + return vs; + } + + /* Address not found. Assume that it is an attempt to access the + hosting server. */ + return NULL; + } diff -cprN netkit-base-0.16/inetd/vsd.h netkit-base/inetd/vsd.h *** netkit-base-0.16/inetd/vsd.h Thu Jan 1 01:00:00 1970 --- netkit-base/inetd/vsd.h Thu May 4 14:13:28 2000 *************** *** 0 **** --- 1,26 ---- + /* Virtual server extensions to inetd. + Copyright (c) 2000 Idaya Ltd. + Written by Nick Burrett + + This file is part of the Virtual Server Administrator (FreeVSD) + + FreeVSD is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + FreeVSD is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with FreeVSD; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + + extern struct vsd_vs_map *virtual_servers; + extern void read_server_map (void); + extern void delete_server_map (void); + extern struct vsd_vs *find_virtual_server (int socket); +