/* * Don't forget to update my definitions of BASE, OWNER_UID, OWNER_GID * and the PATH to "CVS" in the execl() system call to match the * definitions you're using. */ /* * TITLE: run-cvs.c * * Author: Joseph L. Kizzier * * Date: April 04, 2001 * * --------------------------------------------------------------------- * * This program automates the "chroot" of the network CVS server. * * The executable is placed in * * /usr/local/sbin * * and is called from * * /etc/inetd.conf * * with the following entry: * * cvspserver stream tcp nowait root /usr/local/sbin/run-cvs cvs * * --------------------------------------------------------------------- * * Global Constants: MIN, ERROR, ARGLIM, BASE, OWNER_UID, OWNER_GID * * Dependencies: never * * Global Macros: none * * Global Typedefs: none * * --------------------------------------------------------------------- * */ /* $Id: run-cvs.c,v 1.3 2001/04/05 16:06:25 markd Exp $ */ #ifndef __runcvsc__ #define __runcvsc__ #include #include #include #include /* Literal constants */ #define MIN 0 #define ERROR -1 #define ARGLIM 1 /* You'll need to modify these constants to match your configuration */ #define BASE "/home/cvsowner/cvs-server-root/" /* your CVS server root */ #define OWNER_UID 6000 /* your cvsowner UID */ #define OWNER_GID 350 /* your CVS GID */ /* Function prototypes */ extern int chroot_filesys(int, int, char *, char *); extern int usage(char *); #endif int chroot_filesys(res, ret, buffer, progname) int res; int ret; char * buffer; char * progname; { res = chdir(BASE); if (res == ERROR) { sprintf(buffer, "%s: (chdir) %s\n", progname, strerror(errno)); return(ERROR); } res = chroot(BASE); if (res == ERROR) { sprintf(buffer, "%s: (chroot) %s\n", progname, strerror(errno)); return(ERROR); } res = setgid(OWNER_GID); if (res == ERROR) { sprintf(buffer, "%s: (setgid) %s\n", progname, strerror(errno)); return(ERROR); } res = setuid(OWNER_UID); if (res == ERROR) { sprintf(buffer, "%s: (setuid) %s\n", progname, strerror(errno)); return(ERROR); } /* If you have "cvs" in a different location, make the change here. */ /* NOTE: this PATH is relative to $CVSROOT! */ ret = execl("/usr/local/bin/cvs", "cvs", "--allow-root=/cvsweb", "pserver", NULL); if (ret == ERROR) { sprintf(buffer, "%s: (execl) %s\n", progname, strerror(errno)); return(ERROR); } return(MIN); } int usage(progname) char * progname; { fprintf(stderr, "Usage: %s\n", progname); return(ERROR); } int main(argc, argv) int argc; char ** argv; { int res; int ret; int i; char * buffer; char * progname = *argv; if (argc > ARGLIM) { usage(progname); return(ERROR); } if ((i = chroot_filesys(res, ret, buffer, progname)) == ERROR) { fprintf(stderr, "%s\n", buffer); return(ERROR); } return(MIN); }