diff options
author | Joris Vink <joris@cvs.openbsd.org> | 2005-04-06 22:08:54 +0000 |
---|---|---|
committer | Joris Vink <joris@cvs.openbsd.org> | 2005-04-06 22:08:54 +0000 |
commit | 8e741e645c9f8d11570278f27a4d5e7923cc3193 (patch) | |
tree | 94bc8c744fa6b17d717439d076b6d1eeaf970e87 /usr.bin/cvs | |
parent | 59bc97435b0c2d5cb4d4fd4783349b74428e2f09 (diff) |
remove dead and unused code
ok jfb@
Diffstat (limited to 'usr.bin/cvs')
-rw-r--r-- | usr.bin/cvs/Makefile | 4 | ||||
-rw-r--r-- | usr.bin/cvs/child.c | 243 | ||||
-rw-r--r-- | usr.bin/cvs/cvsd-child/Makefile | 19 | ||||
-rw-r--r-- | usr.bin/cvs/cvsd.8 | 137 | ||||
-rw-r--r-- | usr.bin/cvs/cvsd.c | 733 | ||||
-rw-r--r-- | usr.bin/cvs/cvsd.conf | 30 | ||||
-rw-r--r-- | usr.bin/cvs/cvsd.conf.5 | 166 | ||||
-rw-r--r-- | usr.bin/cvs/cvsd.h | 169 | ||||
-rw-r--r-- | usr.bin/cvs/cvsd/Makefile | 19 | ||||
-rw-r--r-- | usr.bin/cvs/session.c | 98 | ||||
-rw-r--r-- | usr.bin/cvs/sock.c | 213 | ||||
-rw-r--r-- | usr.bin/cvs/sock.h | 62 |
12 files changed, 2 insertions, 1891 deletions
diff --git a/usr.bin/cvs/Makefile b/usr.bin/cvs/Makefile index 5936319b0c1..95f24627f71 100644 --- a/usr.bin/cvs/Makefile +++ b/usr.bin/cvs/Makefile @@ -1,7 +1,7 @@ -# $OpenBSD: Makefile,v 1.3 2005/03/09 15:42:30 xsa Exp $ +# $OpenBSD: Makefile,v 1.4 2005/04/06 22:08:53 joris Exp $ .include <bsd.own.mk> -SUBDIR= cvs cvsd rcs +SUBDIR= cvs rcs .include <bsd.subdir.mk> diff --git a/usr.bin/cvs/child.c b/usr.bin/cvs/child.c deleted file mode 100644 index 18a4208a4f5..00000000000 --- a/usr.bin/cvs/child.c +++ /dev/null @@ -1,243 +0,0 @@ -/* $OpenBSD: child.c,v 1.3 2005/04/03 17:32:50 xsa Exp $ */ -/* - * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -/* - * cvsd-child - * ---------- - * - * This is the process taking care of cvs(1) repository requests - * This program is not meant to be run standalone and should only be started - * by the cvsd(8) process. - * - */ - -#include <sys/param.h> -#include <sys/stat.h> -#include <sys/wait.h> -#include <sys/uio.h> - -#include <err.h> -#include <pwd.h> -#include <grp.h> -#include <poll.h> -#include <fcntl.h> -#include <dirent.h> -#include <stdlib.h> -#include <stdio.h> -#include <unistd.h> -#include <signal.h> -#include <errno.h> -#include <string.h> -#include <sysexits.h> - -#include "log.h" -#include "cvs.h" -#include "cvsd.h" - - - -extern char *__progname; - - -int cvsd_fg = 0; - -volatile sig_atomic_t cvsd_running = 1; - -static int cvsd_privfd = -1; -static char cvsd_root[MAXPATHLEN]; -static uid_t cvsd_uid = 0; -static gid_t cvsd_gid = 0; - - -/* session info */ -static uid_t cvsd_sess_ruid = 0; /* UID of the cvs issuing requests */ -static gid_t cvsd_sess_rgid = 0; /* UID of the cvs issuing requests */ -static int cvsd_sess_fd = -1; - - -void usage (void); -void cvsd_sighdlr (int); -int cvsd_child_getreq (struct cvsd_req *); - - -/* - * cvsd_sighdlr() - * - * Generic signal handler. - */ -void -cvsd_sighdlr(int signo) -{ - switch (signo) { - case SIGINT: - case SIGTERM: - case SIGQUIT: - cvsd_running = 0; - break; - } -} - - -/* - * usage() - * - * Display program usage. - */ -void -usage(void) -{ - fprintf(stderr, - "Usage: %s [-dfhv] [-g group] " - "[-u user]\n" - "\t-d\t\tStart the server in debugging mode (very verbose)\n" - "\t-u user\t\tUse user <user> for privilege revocation\n" - "\t-v\t\tBe verbose\n", - __progname); -} - - -int -main(int argc, char **argv) -{ - int ret; - struct cvsd_req req; - - if (cvs_log_init(LD_STD|LD_SYSLOG, LF_PID) < 0) - err(1, "failed to initialize logging mechanism"); - - cvsd_sess_fd = CVSD_CHILD_SOCKFD; - if (getpeereid(cvsd_sess_fd, &cvsd_sess_ruid, &cvsd_sess_rgid) == -1) { - cvs_log(LP_ERRNO, "failed to get remote credentials"); - exit(1); - } - - while ((ret = getopt(argc, argv, "dfg:hr:u:v")) != -1) { - switch (ret) { - case 'd': - cvs_log_filter(LP_FILTER_UNSET, LP_DEBUG); - cvs_log_filter(LP_FILTER_UNSET, LP_INFO); - break; - case 'f': - cvsd_fg = 1; - break; - case 'g': - cvsd_gid = atoi(optarg); - break; - case 'h': - usage(); - exit(0); - /* NOTREACHED */ - break; - case 'r': - strlcpy(cvsd_root, optarg, sizeof(cvsd_root)); - break; - case 'u': - cvsd_uid = atoi(optarg); - break; - case 'v': - cvs_log_filter(LP_FILTER_UNSET, LP_INFO); - break; - default: - usage(); - exit(EX_USAGE); - } - } - - argc -= optind; - argv += optind; - if (argc > 0) - errx(EX_USAGE, "unrecognized trailing arguments"); - - /* Before getting any further, chroot to the CVS repository's root - * directory and drop all privileges to the appropriate user and - * group so we can't cause damage outside of the CVS data. - */ - if (chroot(cvsd_root) == -1) { - cvs_log(LP_ERRNO, "failed to chroot to %s", cvsd_root); - exit(1); - } - (void)chdir("/"); - cvs_log(LP_INFO, "dropping privileges to %d:%d", cvsd_uid, cvsd_gid); - if (setgid(cvsd_gid) == -1) { - cvs_log(LP_ERRNO, "failed to drop group privileges to %s", - CVSD_GROUP); - return (-1); - } - - if (setuid(cvsd_uid) == -1) { - cvs_log(LP_ERRNO, "failed to drop user privileges to %s", - CVSD_USER); - return (-1); - } - - signal(SIGINT, cvsd_sighdlr); - signal(SIGQUIT, cvsd_sighdlr); - signal(SIGTERM, cvsd_sighdlr); - signal(SIGPIPE, SIG_IGN); - - setproctitle("%s [child %d]", __progname, getpid()); - - for (;;) { - ret = cvsd_child_getreq(&req); - if (ret <= 0) - break; - - switch (req.cr_op) { - case CVS_OP_DIFF: - case CVS_OP_UPDATE: - default: - } - printf("request ID: %d, nfiles = %d\n", req.cr_op, - req.cr_nfiles); - } - - close(cvsd_sess_fd); - - cvs_log_cleanup(); - - return (0); -} - - -/* - * cvsd_child_getreq() - * - * Read the next request available on the session socket. - * Returns 1 if a request was received, 0 if there are no more requests to - * serve, and -1 in case of failure. - */ -int -cvsd_child_getreq(struct cvsd_req *reqp) -{ - ssize_t ret; - if ((ret = read(cvsd_sess_fd, reqp, sizeof(*reqp))) == -1) { - cvs_log(LP_ERRNO, "failed to read request"); - } else if (ret > 0) { - printf("reqlen = %d\n", ret); - ret = 1; - } - - return ((int)ret); -} diff --git a/usr.bin/cvs/cvsd-child/Makefile b/usr.bin/cvs/cvsd-child/Makefile deleted file mode 100644 index dbe956d324a..00000000000 --- a/usr.bin/cvs/cvsd-child/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -# $Id: Makefile,v 1.1 2005/02/22 22:33:01 jfb Exp $ - -.PATH: ${.CURDIR}/.. - -PROG=cvsd-child -SRCS= child.c buf.c log.c msg.c rcs.c rcsnum.c - -BINDIR=/usr/sbin -MAN= - -CFLAGS+= -Wall -I${.CURDIR}/.. -CFLAGS+= -Wstrict-prototypes -Wmissing-prototypes -CFLAGS+= -Wmissing-declarations -CFLAGS+= -Wshadow -Wpointer-arith -Wcast-qual -CFLAGS+= -Wsign-compare -CFLAGS+= -DCVSD -YFLAGS= - -.include <bsd.prog.mk> diff --git a/usr.bin/cvs/cvsd.8 b/usr.bin/cvs/cvsd.8 deleted file mode 100644 index cbdabe395a7..00000000000 --- a/usr.bin/cvs/cvsd.8 +++ /dev/null @@ -1,137 +0,0 @@ -.\" $OpenBSD: cvsd.8,v 1.5 2005/01/28 23:43:09 jmc Exp $ -.\" -.\" Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. The name of the author may not be used to endorse or promote products -.\" derived from this software without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR -.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, -.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -.\" -.Dd May 16, 2004 -.Dt CVSD 8 -.Os -.Sh NAME -.Nm cvsd -.Nd Concurrent Versions System daemon -.Sh SYNOPSIS -.Nm cvsd -.Op Fl dfhpv -.Op Fl c Ar config -.Op Fl g Ar group -.Op Fl r Ar cvsroot -.Op Fl s Ar sockpath -.Op Fl u Ar user -.Sh DESCRIPTION -The -.Nm -daemon manages access to a CVS repository. -It provides a much more secure alternative to the traditional client-server -model commonly used by -.Xr cvs 1 -through various mechanisms described below. -For a general introduction to CVS, see -.Xr cvsintro 7 . -.Pp -On startup, -.Nm -spawns a child process that chroots to the CVS repository's root directory. -Both processes then drop privileges to user and group -.Ic _cvsd . -Once this is done, the child process loads the list of ACLs and opens a local -socket on which it listens for requests. -The parent process' only purpose is to answer requests for things outside of -the child's jail. -.Pp -.Nm -provides a way to apply Access Control Lists on the modules based on -operation, path, tags, and users. -In order to enforce ACLs and prevent users from modifying the files in the -repository directly, all of the files within the repository should be owned -by the user and group -.Ic _cvsd -and should only be writable by the user. -.Pp -The options are as follows: -.Bl -tag -width "-s sockpath" -.It Fl c Ar config -Use -.Ar config -as the startup configuration file instead of the default one. -.It Fl d -Start the server with debugging enabled. -This option overrides the -.Fl v -option. -.It Fl f -Stay in foreground instead of performing the usual operations to become -a daemon. -This causes all log messages to be printed on standard input or standard -error, depending on the priority of each message. -.It Fl g Ar group -Drop group privileges to the group name or GID specified by -.Ar group -instead of the default group. -.It Fl h -Print information about the server's usage and exit. -.It Fl p -On startup, perform a check on the whole contents of the CVS repository to -check file permissions and ownership, and print warnings for any files or -directories that do not match the expected permission masks. -When running with this option, -.Nm -will exit with an error message if any of the files have permissions that are -too open. -.It Fl r Ar cvsroot -Use -.Ar cvsroot -as the CVS repository's root directory. -.It Fl s Ar sockpath -Use the path specified by -.Ar sockpath -as the file to bind to for the local socket. -.It Fl u Ar user -Drop user privileges to the username or UID specified by -.Ar user -instead of the default user. -.It Fl v -Be verbose. -.El -.Sh FILES -.Bl -tag -width /var/run/cvsd.sock -compact -.It Pa /etc/cvsd.conf -Standard configuration file for the server. -.It Pa /var/run/cvsd.pid -Process ID of the currently running -.Nm . -.It Pa /var/run/cvsd.sock -Default listening socket for incoming cvs requests. -.El -.Sh SEE ALSO -.Xr cvs 1 , -.Xr rcs 1 , -.Xr cvsd.conf 5 , -.Xr rcsfile 5 , -.Xr cvsintro 7 -.Sh HISTORY -The -.Nm -server first appeared as part of the OpenCVS project. -.Sh AUTHORS -.An Jean-Francois Brousseau diff --git a/usr.bin/cvs/cvsd.c b/usr.bin/cvs/cvsd.c deleted file mode 100644 index 9f47f2e5d04..00000000000 --- a/usr.bin/cvs/cvsd.c +++ /dev/null @@ -1,733 +0,0 @@ -/* $OpenBSD: cvsd.c,v 1.19 2005/04/03 17:32:50 xsa Exp $ */ -/* - * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include <sys/param.h> -#include <sys/stat.h> -#include <sys/wait.h> -#include <sys/uio.h> - -#include <err.h> -#include <pwd.h> -#include <grp.h> -#include <poll.h> -#include <fcntl.h> -#include <dirent.h> -#include <stdlib.h> -#include <stdio.h> -#include <unistd.h> -#include <signal.h> -#include <errno.h> -#include <string.h> -#include <sysexits.h> - -#include "log.h" -#include "sock.h" -#include "cvs.h" -#include "repo.h" -#include "cvsd.h" - - -static void cvsd_parent_loop (void); -static void cvsd_report (void); - - -extern char *__progname; - - -int cvsd_fg = 0; -uid_t cvsd_uid = 0; -gid_t cvsd_gid = 0; - -volatile sig_atomic_t cvsd_running = 1; -volatile sig_atomic_t cvsd_restart = 0; - -static char *cvsd_user = NULL; -static char *cvsd_group = NULL; -static char *cvsd_root = NULL; -static char *cvsd_conffile = CVSD_PATH_CONF; -static char *cvsd_moddir = NULL; -static int cvsd_privfd = -1; - -static CVSREPO *cvsd_repo; - - -static TAILQ_HEAD(,cvsd_child) cvsd_children; -static volatile sig_atomic_t cvsd_chnum = 0; -static volatile sig_atomic_t cvsd_chmax = CVSD_CHILD_DEFMAX; -static volatile sig_atomic_t cvsd_sigchld = 0; -static volatile sig_atomic_t cvsd_siginfo = 0; - - -void usage (void); -void cvsd_sighdlr (int); -int cvsd_msghdlr (struct cvsd_child *, int); - - -/* - * cvsd_sighdlr() - * - * Generic signal handler. - */ -void -cvsd_sighdlr(int signo) -{ - switch (signo) { - case SIGHUP: - cvsd_restart = 1; - break; - case SIGCHLD: - cvsd_sigchld = 1; - break; - case SIGINT: - case SIGTERM: - case SIGQUIT: - cvsd_running = 0; - break; - case SIGINFO: - cvsd_siginfo = 1; - break; - } -} - - -/* - * usage() - * - * Display program usage. - */ -void -usage(void) -{ - fprintf(stderr, - "Usage: %s [-dfhpv] [-c config] [-g group] [-r root] " - "[-s path] [-u user]\n" - "\t-c config\tUse <config> as the configuration file\n" - "\t-d\t\tStart the server in debugging mode (very verbose)\n" - "\t-f\t\tStay in foreground instead of becoming a daemon\n" - "\t-g group\tUse group <group> for privilege revocation\n" - "\t-h\t\tPrint the usage and exit\n" - "\t-p\t\tPerform repository sanity check on startup\n" - "\t-r root\t\tUse <root> as the root directory of the repository\n" - "\t-s path\t\tUse <path> as the path for the CVS server socket\n" - "\t-u user\t\tUse user <user> for privilege revocation\n" - "\t-v\t\tBe verbose\n", - __progname); -} - - -int -main(int argc, char **argv) -{ - int ret, repo_flags; - struct passwd *pwd; - struct group *grp; - - repo_flags = 0; - cvsd_set(CVSD_SET_SOCK, CVSD_SOCK_PATH); - cvsd_set(CVSD_SET_USER, CVSD_USER); - cvsd_set(CVSD_SET_GROUP, CVSD_GROUP); - - if (cvs_log_init(LD_STD|LD_SYSLOG, LF_PID) < 0) - err(1, "failed to initialize logging mechanism"); - - while ((ret = getopt(argc, argv, "c:dfg:hpr:s:u:v")) != -1) { - switch (ret) { - case 'c': - cvsd_conffile = optarg; - break; - case 'd': - cvs_log_filter(LP_FILTER_UNSET, LP_DEBUG); - cvs_log_filter(LP_FILTER_UNSET, LP_INFO); - break; - case 'f': - cvsd_fg = 1; - break; - case 'g': - cvsd_set(CVSD_SET_GROUP, optarg); - break; - case 'h': - usage(); - exit(0); - /* NOTREACHED */ - break; - case 'p': - repo_flags |= CVS_REPO_CHKPERM; - break; - case 'r': - cvsd_set(CVSD_SET_ROOT, optarg); - break; - case 's': - cvsd_set(CVSD_SET_SOCK, optarg); - break; - case 'u': - cvsd_set(CVSD_SET_USER, optarg); - break; - case 'v': - cvs_log_filter(LP_FILTER_UNSET, LP_INFO); - break; - default: - usage(); - exit(EX_USAGE); - } - } - - argc -= optind; - argv += optind; - - if (cvs_conf_read(cvsd_conffile) < 0) - errx(1, "error parsing configuration file `%s'", cvsd_conffile); - - if (cvsd_root == NULL) - errx(1, "no CVS root directory specified"); - - if (argc > 0) - errx(EX_USAGE, "unrecognized trailing arguments"); - - TAILQ_INIT(&cvsd_children); - - pwd = getpwnam(cvsd_user); - if (pwd == NULL) - err(1, "failed to get user `%s'", cvsd_user); - - grp = getgrnam(cvsd_group); - if (grp == NULL) - err(1, "failed to get group `%s'", cvsd_group); - - endpwent(); - endgrent(); - - cvsd_uid = pwd->pw_uid; - cvsd_gid = grp->gr_gid; - - signal(SIGHUP, cvsd_sighdlr); - signal(SIGINT, cvsd_sighdlr); - signal(SIGQUIT, cvsd_sighdlr); - signal(SIGTERM, cvsd_sighdlr); - signal(SIGCHLD, cvsd_sighdlr); - signal(SIGPIPE, SIG_IGN); - - if (!cvsd_fg && daemon(0, 0) == -1) { - cvs_log(LP_ERRNO, "failed to become a daemon"); - exit(1); - } - - if ((cvsd_repo = cvs_repo_load(cvsd_root, repo_flags)) == NULL) { - cvs_log(LP_ERR, "failed to load repository"); - exit(1); - }; - - if (cvsd_sock_open() < 0) { - exit(1); - } - - if (setegid(cvsd_gid) == -1) { - cvs_log(LP_ERRNO, "failed to drop group privileges"); - exit(1); - } - if (seteuid(cvsd_uid) == -1) { - cvs_log(LP_ERRNO, "failed to drop user privileges"); - exit(1); - } - - signal(SIGINFO, cvsd_sighdlr); - cvsd_parent_loop(); - - cvsd_sock_close(); - - cvs_repo_free(cvsd_repo); - - cvs_log(LP_NOTICE, "shutting down"); - cvs_log_cleanup(); - return (0); -} - - -/* - * cvsd_child_fork() - * - * Fork a child process which chroots to the CVS repository's root directory, - * drops all privileges, and then executes the cvsd-child process, which will - * handle the incoming CVS requests. - * On success, returns a pointer to the new child structure, - * or NULL on failure. - */ -struct cvsd_child* -cvsd_child_fork(int sock) -{ - int argc, svec[2]; - pid_t pid; - char *argv[16], ubuf[8], gbuf[8]; - struct cvsd_child *chp; - - if (cvsd_chnum == cvsd_chmax) { - cvs_log(LP_WARN, "child pool reached limit of processes"); - return (NULL); - } - - if (socketpair(AF_LOCAL, SOCK_STREAM, PF_UNSPEC, svec) == -1) { - cvs_log(LP_ERRNO, "failed to create socket pair"); - return (NULL); - } - - /* - * We need to temporarily regain original privileges in order for the - * child to chroot(). - */ - if (seteuid(0) == -1) { - cvs_log(LP_ERRNO, "failed to regain privileges"); - return (NULL); - } - - pid = fork(); - if (pid == -1) { - cvs_log(LP_ERRNO, "failed to fork child"); - (void)close(svec[0]); - (void)close(svec[1]); - return (NULL); - } - - if (pid == 0) { - cvsd_privfd = svec[1]; - (void)close(svec[0]); - - /* - * Move the accepted socket to descriptor 3, where the child - * expects it to be. This could become troublesome if the - * descriptor is already taken, but then again, the child - * shouldn't have access to other descriptors except the - * connection and its side of the socket pair it shares with - * the parent. - */ - if (dup2(sock, CVSD_CHILD_SOCKFD) == -1) { - cvs_log(LP_ERRNO, "failed to dup child socket"); - exit(1); - } - (void)close(sock); - - argc = 0; - argv[argc++] = CVSD_PATH_CHILD; - argv[argc++] = "-r"; - argv[argc++] = cvsd_root; - if (cvsd_uid != 0) { - snprintf(ubuf, sizeof(ubuf), "%d", cvsd_uid); - argv[argc++] = "-u"; - argv[argc++] = ubuf; - } - if (cvsd_gid != 0) { - snprintf(gbuf, sizeof(gbuf), "%d", cvsd_gid); - argv[argc++] = "-g"; - argv[argc++] = gbuf; - } - argv[argc] = NULL; - - execv(CVSD_PATH_CHILD, argv); - err(1, "FUCK"); - exit(1); - } - - cvs_log(LP_INFO, "spawning child %d", pid); - - (void)close(svec[1]); - - if (seteuid(cvsd_uid) == -1) - cvs_log(LP_ERRNO, "failed to redrop privs"); - - chp = (struct cvsd_child *)malloc(sizeof(*chp)); - if (chp == NULL) { - /* XXX kill child */ - cvs_log(LP_ERRNO, "failed to allocate child data"); - return (NULL); - } - - chp->ch_pid = pid; - chp->ch_sock = svec[0]; - chp->ch_state = CVSD_ST_IDLE; - - TAILQ_INSERT_TAIL(&cvsd_children, chp, ch_list); - cvsd_chnum++; - - return (chp); -} - - -/* - * cvsd_child_reap() - * - * Wait for a child's status and perform the proper actions depending on it. - * If the child has exited or has been terminated by a signal, it will be - * removed from the list. - * Returns 0 on success, or -1 on failure. - */ -int -cvsd_child_reap(void) -{ - pid_t pid; - int status; - struct cvsd_child *ch; - - pid = wait(&status); - if (pid == -1) { - cvs_log(LP_ERRNO, "failed to wait for child"); - return (-1); - } - - TAILQ_FOREACH(ch, &cvsd_children, ch_list) { - if (ch->ch_pid == pid) { - if (WIFEXITED(status)) { - cvs_log(LP_WARN, - "child %d exited with status %d", - pid, WEXITSTATUS(status)); - } else if (WIFSIGNALED(status)) { - cvs_log(LP_WARN, - "child %d terminated with signal %d", - pid, WTERMSIG(status)); - } else { - cvs_log(LP_ERR, "HOLY SHIT!"); - } - - signal(SIGCHLD, SIG_IGN); - TAILQ_REMOVE(&cvsd_children, ch, ch_list); - cvsd_chnum--; - signal(SIGCHLD, cvsd_sighdlr); - - break; - } - } - - return (0); -} - - -/* - * cvsd_parent_loop() - * - * Main loop of the parent cvsd process, which listens on its end of the - * local socket for requests from the cvs(1) program and on any outstanding - * messages from the children. - */ -static void -cvsd_parent_loop(void) -{ - int cfd, timeout, ret; - nfds_t nfds, i; - struct pollfd *pfd; - struct cvsd_child *chp; - - nfds = 0; - timeout = INFTIM; - pfd = NULL; - - for (;;) { - if (!cvsd_running) - break; - - if (cvsd_restart) { - /* restart server */ - } - - if (cvsd_sigchld) { - cvsd_sigchld = 0; - cvsd_child_reap(); - } - if (cvsd_siginfo) { - cvsd_siginfo = 0; - cvsd_report(); - } - - nfds = cvsd_chnum + 1; - pfd = (struct pollfd *)realloc(pfd, - nfds * sizeof(struct pollfd)); - if (pfd == NULL) { - cvs_log(LP_ERRNO, "failed to reallocate polling data"); - return; - } - - pfd[0].fd = cvsd_sock; - pfd[0].events = POLLIN; - pfd[0].revents = 0; - i = 1; - TAILQ_FOREACH(chp, &cvsd_children, ch_list) { - pfd[i].fd = chp->ch_sock; - pfd[i].events = POLLIN; - pfd[i].revents = 0; - i++; - - if (i == nfds) /* just a precaution */ - break; - } - - ret = poll(pfd, nfds, timeout); - if (ret == -1) { - if (errno == EINTR) - continue; - cvs_log(LP_ERRNO, "poll error"); - break; - } - - if (pfd[0].revents & (POLLERR|POLLNVAL)) { - cvs_log(LP_ERR, "poll error on request socket"); - } else if (pfd[0].revents & POLLIN) { - uid_t uid; - gid_t gid; - - if ((cfd = cvsd_sock_accept(pfd[0].fd)) == -1) - continue; - - if ((chp = cvsd_child_fork(cfd)) == NULL) { - cvs_log(LP_ALERT, - "request queue not implemented"); - break; - } - - if (getpeereid(cfd, &uid, &gid) < 0) - err(1, "failed to get UID"); - if (cvsd_sendmsg(chp->ch_sock, CVSD_MSG_PASSFD, - &cfd, sizeof(cfd)) < 0) - break; - - /* mark the child as busy */ - chp->ch_state = CVSD_ST_BUSY; - } - - chp = TAILQ_FIRST(&cvsd_children); - for (i = 1; i < nfds; i++) { - if (pfd[i].revents & (POLLERR|POLLNVAL)) { - cvs_log(LP_ERR, - "poll error on child socket (PID %d)", - chp->ch_pid); - } else if (pfd[i].revents & POLLIN) - cvsd_msghdlr(chp, pfd[i].fd); - - chp = TAILQ_NEXT(chp, ch_list); - } - - } - - /* broadcast a shutdown message to children */ - TAILQ_FOREACH(chp, &cvsd_children, ch_list) { - (void)cvsd_sendmsg(chp->ch_sock, CVSD_MSG_SHUTDOWN, NULL, 0); - } -} - - -/* - * cvsd_msghdlr() - * - * Handler for messages received from child processes. - * Returns 0 on success, or -1 on failure. - */ -int -cvsd_msghdlr(struct cvsd_child *child, int fd) -{ - uid_t uid; - ssize_t ret; - char rbuf[CVSD_MSG_MAXLEN]; - struct group *gr; - struct passwd *pw; - struct iovec iov[2]; - struct cvsd_msg msg; - - ret = read(fd, &msg, sizeof(msg)); - if (ret == -1) { - cvs_log(LP_ERRNO, "failed to read CVS message"); - return (-1); - } else if (ret == 0) { - cvs_log(LP_WARN, "child closed socket pair"); - return (0); - } - - if (msg.cm_len > 0) { - ret = read(fd, rbuf, msg.cm_len); - if (ret != (ssize_t)msg.cm_len) { - cvs_log(LP_ERR, "failed to read entire msg"); - return (-1); - } - } - - /* setup the I/O vector for the reply */ - iov[0].iov_base = &msg; - iov[0].iov_len = sizeof(msg); - - msg.cm_type = CVSD_MSG_ERROR; - msg.cm_len = 0; - - switch (msg.cm_type) { - case CVSD_MSG_GETUID: - rbuf[ret] = '\0'; - cvs_log(LP_INFO, "getting UID for `%s'", rbuf); - - pw = getpwnam(rbuf); - if (pw != NULL) { - msg.cm_type = CVSD_MSG_UID; - msg.cm_len = sizeof(uid_t); - iov[1].iov_len = msg.cm_len; - iov[1].iov_base = &(pw->pw_uid); - } - break; - case CVSD_MSG_GETUNAME: - memcpy(&uid, rbuf, sizeof(uid)); - cvs_log(LP_INFO, "getting username for UID %u", uid); - pw = getpwuid(uid); - if (pw != NULL) { - msg.cm_type = CVSD_MSG_UNAME; - msg.cm_len = strlen(pw->pw_name); - iov[1].iov_len = msg.cm_len; - iov[1].iov_base = pw->pw_name; - } - break; - case CVSD_MSG_GETGID: - rbuf[ret] = '\0'; - cvs_log(LP_INFO, "getting GID for `%s'", rbuf); - - gr = getgrnam(rbuf); - if (gr != NULL) { - msg.cm_type = CVSD_MSG_GID; - msg.cm_len = sizeof(gid_t); - iov[1].iov_len = msg.cm_len; - iov[1].iov_base = &(gr->gr_gid); - } - break; - case CVSD_MSG_SETIDLE: - child->ch_state = CVSD_ST_IDLE; - break; - default: - cvs_log(LP_ERR, "unknown command type %u", msg.cm_type); - return (-1); - } - - ret = writev(fd, iov, 2); - - return (ret); -} - - -/* - * cvsd_set() - * - * Generic interface to set some of the parameters of the cvs server. - * When a string is set using cvsd_set(), the original string is copied into - * a new buffer. - * Returns 0 on success, or -1 on failure. - */ -int -cvsd_set(int what, ...) -{ - char *str; - int error = 0; - va_list vap; - - str = NULL; - - va_start(vap, what); - - if ((what == CVSD_SET_ROOT) || (what == CVSD_SET_SOCK) || - (what == CVSD_SET_USER) || (what == CVSD_SET_GROUP) || - (what == CVSD_SET_MODDIR)) { - str = strdup(va_arg(vap, char *)); - if (str == NULL) { - cvs_log(LP_ERRNO, "failed to set string"); - va_end(vap); - return (-1); - } - } - - switch (what) { - case CVSD_SET_ROOT: - if (cvsd_root != NULL) - free(cvsd_root); - cvsd_root = str; - break; - case CVSD_SET_SOCK: - if (cvsd_sock_path != NULL) - free(cvsd_sock_path); - cvsd_sock_path = str; - break; - case CVSD_SET_USER: - if (cvsd_user != NULL) - free(cvsd_user); - cvsd_user = str; - break; - case CVSD_SET_GROUP: - if (cvsd_group != NULL) - free(cvsd_group); - cvsd_group = str; - break; - case CVSD_SET_MODDIR: - if (cvsd_moddir != NULL) - free(cvsd_moddir); - cvsd_moddir = str; - break; - case CVSD_SET_CHMAX: - cvsd_chmax = va_arg(vap, int); - /* we should decrease the number of children accordingly */ - break; - case CVSD_SET_ADDR: - /* this is more like an add than a set */ - break; - default: - cvs_log(LP_ERR, "invalid field to set"); - error = -1; - break; - } - - va_end(vap); - - return (error); -} - - -/* - * cvsd_report() - * - * Report about the current state of child processes on the repository. - */ -static void -cvsd_report(void) -{ - u_int nb_idle, nb_busy, nb_unknown; - struct cvsd_child *ch; - - nb_idle = 0; - nb_busy = 0; - nb_unknown = 0; - - signal(SIGCHLD, SIG_IGN); - TAILQ_FOREACH(ch, &cvsd_children, ch_list) { - if (ch->ch_state == CVSD_ST_IDLE) - nb_idle++; - else if (ch->ch_state == CVSD_ST_BUSY) - nb_busy++; - else if (ch->ch_state == CVSD_ST_UNKNOWN) - nb_unknown++; - } - - cvs_log(LP_WARN, "%u children, %u idle, %u busy, %u unknown", - cvsd_chnum, nb_idle, nb_busy, nb_unknown); - - TAILQ_FOREACH(ch, &cvsd_children, ch_list) - cvs_log(LP_WARN, ""); - signal(SIGCHLD, cvsd_sighdlr); -} diff --git a/usr.bin/cvs/cvsd.conf b/usr.bin/cvs/cvsd.conf deleted file mode 100644 index 79d2deeb981..00000000000 --- a/usr.bin/cvs/cvsd.conf +++ /dev/null @@ -1,30 +0,0 @@ -# $OpenBSD: cvsd.conf,v 1.4 2005/02/22 21:51:12 jfb Exp $ -# -# Sample cvsd configuration file -# see cvsd.conf(5) -# -# Directive lines that are commented out show the default value. You should -# only uncomment them if you want to change those values. - - -# Set this to the root directory of your CVS repository -cvsroot /cvs - -# Minimum children processes to keep in pool at any given time -#minchild 3 - -# Maximum children processes to keep in pool at any given time -#maxchild 5 - -# User and group that child processes should drop privileges to upon startup -#user _cvsd -#group _cvsd - -# Socket on which the server will be listening for client requests -reqsock /var/run/cvsd.sock - - - -# Access Control Lists -# -#allow any diff --git a/usr.bin/cvs/cvsd.conf.5 b/usr.bin/cvs/cvsd.conf.5 deleted file mode 100644 index 703e1e0d05f..00000000000 --- a/usr.bin/cvs/cvsd.conf.5 +++ /dev/null @@ -1,166 +0,0 @@ -.\" $OpenBSD: cvsd.conf.5,v 1.4 2004/12/22 00:38:25 david Exp $ -.\" -.\" Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. The name of the author may not be used to endorse or promote products -.\" derived from this software without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR -.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, -.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -.\" -.Dd July 20, 2004 -.Dt CVSD.CONF 5 -.Os -.Sh NAME -.Nm cvsd.conf -.Nd CVS daemon configuration file format -.Sh DESCRIPTION -The -.Nm -configuration file format is used by the -.Xr cvsd 8 -server. -The server's configuration file is read upon startup and reparsed on every -server restart. -.Pp -It is a human-readable text file consisting of one-line directives that -the server handles to modify its configuration and Access Control List rules -to control operations on the repository. -Comments can be inserted anywhere in the file by putting a -.Sq # -character before them and span to the end of the line. -.Sh MACROS -To simplify maintenance of the configuration, the format allows for the -definition of variables that can later be used for interpolation throughout -the configuration file by preceding them with the -.Sq $ -character. -These variables are referred to as macros throughout the rest of the document. -A macro name must start with a letter and can be composed of letters, digits, -and underscores. -.Pp -Here is an example of macro usage: -.Bd -literal -offset indent -rootdir = /usr/local/cvs - -cvsroot $rootdir - -reqsock $rootdir/CVSROOT/cvsd.sock -.Ed -.Pp -To assign a value containing spaces to a macro, the whole value string must -be quoted using double quotes. -.Sh DIRECTIVES -The following directives are supported by the server: -.Bl -tag -width xxxxx -.It Sy cvsroot Ar path -Set the server's CVS root directory to -.Ar path . -.It Sy listen Ar addr -Add the address -.Ar addr -to the list of addresses on which the server will listen for incoming -connections. -This is currently parsed but ignored, as the CVS daemon doesn't support -direct TCP connections yet. -.It Sy maxchild Ar num -Set the server's maximum number of child processes to -.Ar num . -.It Sy minchild Ar num -Set the server's minimum number of child processes to -.Ar num . -.It Sy reqsock Ar path -Set the server's local socket path to -.Ar path . -In order for this to work, the -.Xr cvs 1 -client must be aware of the socket's path. -.El -.Sh ACL GRAMMAR -The Access Control Lists grammar is expressed in BNF (Backus-Naur Form) -notation. -In this representation, terminals are displayed as normal text and nonterminals -are in bold. -.Po -.Ql [ -and -.Ql \&] -.Pc -is optional. -The pipe character -.Pq Ql \&| -is used to separate multiple choices. -.Pp -Here is the BNF syntax for -.Nm -rules: -.Bl -tag -width "this is a test" -.It Ic action -::= allow | deny -.It Ic line -::= -.It Ic op -::= add | commit | tag | update -.It Ic option -::= quick | log -.It Ic optlist -::= -.Ic option -| -.Ic optlist , -.Ic option -.It Ic rule -::= -.Ic action -.Bo -.Ic optlist -.Bc -.Ic op -[ branch -.Ic branch -] -.Pp -[ from -.Ic userlist -] -.It Ic userlist -::= -.El -.Sh EXAMPLES -The following rule denies all operations: -.Bd -literal -offset indent -deny quick any -.Ed -.Sh FILES -.Bl -tag -width /etc/cvsd.conf -compact -.It Pa /etc/cvsd.conf -Default configuration file for -.Xr cvsd 8 . -.El -.Sh SEE ALSO -.Xr cvs 1 , -.Xr rcsfile 5 , -.Xr cvsd 8 -.Sh HISTORY -The -.Nm -file format was introduced along with the CVS daemon as part of the -OpenCVS project. -.Sh AUTHORS -.An Jean-Francois Brousseau diff --git a/usr.bin/cvs/cvsd.h b/usr.bin/cvs/cvsd.h deleted file mode 100644 index bd4ff0549c4..00000000000 --- a/usr.bin/cvs/cvsd.h +++ /dev/null @@ -1,169 +0,0 @@ -/* $OpenBSD: cvsd.h,v 1.8 2005/02/22 22:33:01 jfb Exp $ */ -/* - * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef CVSD_H -#define CVSD_H - -#include <sys/types.h> -#include <sys/queue.h> -#include <sys/stat.h> -#include <sys/socket.h> - -#include <netinet/in.h> - -#include <pwd.h> -#include <grp.h> -#include <signal.h> - -#include "cvs.h" - -#define CVSD_USER "_cvsd" -#define CVSD_GROUP "_cvsd" - -#define CVSD_PATH_CONF "/etc/cvsd.conf" -#define CVSD_PATH_CHILD "/usr/sbin/cvsd-child" - -#define CVSD_CHILD_DEFMAX 5 -#define CVSD_CHILD_SOCKFD 3 - - -#define CVSD_FPERM (S_IRUSR | S_IWUSR) -#define CVSD_DPERM (S_IRWXU) - - -/* requests */ -#define CVSD_MSG_GETUID 1 -#define CVSD_MSG_GETUNAME 2 -#define CVSD_MSG_GETGID 3 -#define CVSD_MSG_GETGNAME 4 -#define CVSD_MSG_PASSFD 5 /* server passes client file descriptor */ -#define CVSD_MSG_SETIDLE 6 /* client has no further processing to do */ - -/* replies */ -#define CVSD_MSG_UID 128 -#define CVSD_MSG_UNAME 129 -#define CVSD_MSG_GID 130 -#define CVSD_MSG_GNAME 131 - -#define CVSD_MSG_SHUTDOWN 253 -#define CVSD_MSG_OK 254 -#define CVSD_MSG_ERROR 255 - -#define CVSD_MSG_MAXLEN 256 - - -#define CVSD_SET_ROOT 1 -#define CVSD_SET_CHMIN 2 -#define CVSD_SET_CHMAX 3 -#define CVSD_SET_ADDR 4 -#define CVSD_SET_SOCK 5 -#define CVSD_SET_USER 6 -#define CVSD_SET_GROUP 7 -#define CVSD_SET_MODDIR 8 - - -#define CVSD_ST_UNKNOWN 0 -#define CVSD_ST_IDLE 1 -#define CVSD_ST_BUSY 2 -#define CVSD_ST_DEAD 3 -#define CVSD_ST_STOPPED 4 - - -/* message structure to pass data between the parent and the chrooted child */ -struct cvsd_msg { - u_int8_t cm_type; - u_int8_t cm_len; /* length of message data in bytes */ -}; - - -struct cvsd_addr { - sa_family_t ca_fam; - union { - struct sockaddr_in sin; - struct sockaddr_in6 sin6; - } ca_addr; -}; - - -struct cvsd_child { - pid_t ch_pid; - int ch_sock; - u_int ch_state; - - TAILQ_ENTRY(cvsd_child) ch_list; -}; - - -/* - * The following structures are used to vehicle information to and from the - * cvsd-child process handling the cvs session. - */ - -struct cvsd_req { - int cr_op; /* operation (see CVS_OP_* in cvs.h) */ - int cr_nfiles; -}; - -struct cvsd_resp { - int cr_code; -}; - - -/* cvsd-child response codes */ -#define CVSD_RESP_OK 0 -#define CVSD_RESP_INVREQ 1 /* invalid request */ -#define CVSD_RESP_DENIED 2 /* access denied */ -#define CVSD_RESP_SYSERR 3 /* system error */ -#define CVSD_RESP_RDONLY 4 /* repository is read-only */ -#define CVSD_RESP_INVFILE 5 /* one or more files are unknown */ -#define CVSD_RESP_INVMOD 6 - - -extern uid_t cvsd_uid; -extern gid_t cvsd_gid; - - -int cvsd_set (int, ...); -struct cvsd_child* cvsd_child_fork (int); -int cvsd_child_reap (void); - - -/* from conf.y */ -int cvs_conf_read (const char *); -u_int cvs_acl_eval (struct cvs_op *); - -/* from msg.c */ -int cvsd_sendmsg (int, u_int, const void *, size_t); -int cvsd_recvmsg (int, u_int *, void *, size_t *); -int cvsd_sendfd (int, int); -int cvsd_recvfd (int); - - -struct cvsd_sess* cvsd_sess_alloc (int); -void cvsd_sess_free (struct cvsd_sess *); - - -#endif /* CVSD_H */ diff --git a/usr.bin/cvs/cvsd/Makefile b/usr.bin/cvs/cvsd/Makefile deleted file mode 100644 index 19964eb6e84..00000000000 --- a/usr.bin/cvs/cvsd/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -# $OpenBSD: Makefile,v 1.10 2005/03/10 15:37:08 jfb Exp $ - -.PATH: ${.CURDIR}/.. - -PROG= cvsd -SRCS= cvsd.c buf.c conf.y log.c msg.c repo.c sock.c - -BINDIR= /usr/sbin -MAN= cvsd.8 cvsd.conf.5 - -CFLAGS+= -Wall -I${.CURDIR}/.. -CFLAGS+= -Wstrict-prototypes -Wmissing-prototypes -CFLAGS+= -Wmissing-declarations -CFLAGS+= -Wshadow -Wpointer-arith -Wcast-qual -CFLAGS+= -Wsign-compare -CFLAGS+= -DCVSD -YFLAGS= - -.include <bsd.prog.mk> diff --git a/usr.bin/cvs/session.c b/usr.bin/cvs/session.c deleted file mode 100644 index b5586a0d282..00000000000 --- a/usr.bin/cvs/session.c +++ /dev/null @@ -1,98 +0,0 @@ -/* $OpenBSD: session.c,v 1.2 2004/12/07 17:10:56 tedu Exp $ */ -/* - * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include <sys/param.h> -#include <sys/stat.h> -#include <sys/wait.h> -#include <sys/time.h> -#include <sys/uio.h> - -#include <err.h> -#include <pwd.h> -#include <grp.h> -#include <poll.h> -#include <fcntl.h> -#include <dirent.h> -#include <stdlib.h> -#include <stdio.h> -#include <unistd.h> -#include <signal.h> -#include <errno.h> -#include <string.h> -#include <sysexits.h> - -#include "log.h" -#include "sock.h" -#include "cvs.h" -#include "cvsd.h" - - -/* - * cvsd_sess_alloc() - * - * Allocate a new session. - */ -struct cvsd_sess* -cvsd_sess_alloc(int fd) -{ - gid_t gid; - struct cvsd_sess *sp; - - sp = (struct cvsd_sess *)malloc(sizeof(*sp)); - if (sp == NULL) { - cvs_log(LP_ERRNO, "failed to allocate session"); - return (NULL); - } - - sp->cs_fd = fd; - /* only local sessions are currently supported */ - sp->cs_type = CVSD_SESS_LOCAL; - - if (sp->cs_type == CVSD_SESS_LOCAL) { - if (getpeereid(fd, &(sp->cs_uid), &gid) == -1) { - cvs_log(LP_ERRNO, "failed to get remote effective ID"); - free(sp); - return (NULL); - } - } - - cvs_log(LP_INFO, "session opened for user %u", sp->cs_uid); - - return (sp); -} - - -/* - * cvsd_sess_free() - * - */ -void -cvsd_sess_free(struct cvsd_sess *sessp) -{ - - if (sessp != NULL) - free(sessp); -} diff --git a/usr.bin/cvs/sock.c b/usr.bin/cvs/sock.c deleted file mode 100644 index 44ee30c0140..00000000000 --- a/usr.bin/cvs/sock.c +++ /dev/null @@ -1,213 +0,0 @@ -/* $OpenBSD: sock.c,v 1.15 2005/03/10 22:40:04 deraadt Exp $ */ -/* - * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include <sys/types.h> -#include <sys/socket.h> -#include <sys/un.h> - -#include <poll.h> -#include <errno.h> -#include <stdio.h> -#include <fcntl.h> -#include <unistd.h> -#include <string.h> -#include <stdlib.h> - -#include "log.h" -#include "sock.h" -#include "cvsd.h" - - -char *cvsd_sock_path; - -/* daemon API */ -#ifdef CVSD -int cvsd_sock = -1; -static struct sockaddr_un cvsd_sun; -#endif - -/* for client API */ -#ifdef CVS -static int cvs_sock = -1; -static struct sockaddr_un cvs_sun; -#endif - - -#ifdef CVSD -/* - * cvsd_sock_open() - * - * Open the daemon's local socket. If the server socket is already opened, - * we close it before reopening it. - * Returns 0 on success, -1 on failure. - */ -int -cvsd_sock_open(void) -{ - mode_t old_umask; - - if (cvsd_sock >= 0) - cvsd_sock_close(); - - cvsd_sun.sun_family = AF_LOCAL; - strlcpy(cvsd_sun.sun_path, cvsd_sock_path, sizeof(cvsd_sun.sun_path)); - - cvsd_sock = socket(AF_LOCAL, SOCK_STREAM, 0); - if (cvsd_sock == -1) { - cvs_log(LP_ERRNO, "failed to open socket"); - return (-1); - } - - old_umask = umask(S_IRWXO); - if (bind(cvsd_sock, (struct sockaddr *)&cvsd_sun, - SUN_LEN(&cvsd_sun)) == -1) { - cvs_log(LP_ERRNO, "failed to bind local socket to `%s'", - cvsd_sock_path); - (void)close(cvsd_sock); - umask(old_umask); - return (-1); - } - umask(old_umask); - - (void)listen(cvsd_sock, 10); - - if (chown(cvsd_sock_path, getuid(), cvsd_gid) == -1) { - cvs_log(LP_ERRNO, "failed to change owner of `%s'", - cvsd_sock_path); - (void)close(cvsd_sock); - (void)unlink(cvsd_sock_path); - return (-1); - } - - if (chmod(cvsd_sock_path, CVSD_SOCK_PERMS) == -1) { - cvs_log(LP_ERRNO, "failed to change mode of `%s'", - cvsd_sock_path); - (void)close(cvsd_sock); - (void)unlink(cvsd_sock_path); - return (-1); - } - - /* close on exec so children can't muck around with this */ - (void)fcntl(cvsd_sock, F_SETFD, FD_CLOEXEC); - - cvs_log(LP_DEBUG, "opened local socket `%s'", cvsd_sock_path); - - return (0); -} - - -/* - * cvsd_sock_close() - * - * Close the local socket. - */ -void -cvsd_sock_close(void) -{ - cvs_log(LP_DEBUG, "closing local socket `%s'", CVSD_SOCK_PATH); - if (close(cvsd_sock) == -1) { - cvs_log(LP_ERRNO, "failed to close local socket"); - } - if (seteuid(0) == -1) - cvs_log(LP_ERRNO, "failed to regain privileges"); - else if (unlink(cvsd_sock_path) == -1) - cvs_log(LP_ERRNO, "failed to unlink local socket `%s'", - cvsd_sock_path); -} - - -/* - * cvsd_sock_accept() - * - * Handler for connections made on the server's local domain socket. - * It accepts connections and looks for a child process that is currently - * idle to which it can dispatch the connection's descriptor. If there are - * no available child processes, a new one will be created unless the number - * of children has attained the maximum. - */ -int -cvsd_sock_accept(int fd) -{ - int cfd; - socklen_t slen; - struct sockaddr_un sun; - - slen = sizeof(sun); - cfd = accept(fd, (struct sockaddr *)&sun, &slen); - if (cfd == -1) { - cvs_log(LP_ERRNO, "failed to accept client connection"); - return (-1); - } - - return (cfd); -} -#endif - -#ifdef CVS -/* - * cvs_sock_connect() - * - * Open a connection to the CVS server's local socket. - */ -int -cvs_sock_connect(const char *path) -{ - cvs_sun.sun_family = AF_LOCAL; - strlcpy(cvs_sun.sun_path, path, sizeof(cvs_sun.sun_path)); - - cvs_log(LP_INFO, "connecting to CVS server socket `%s'", - cvs_sun.sun_path); - - cvs_sock = socket(AF_LOCAL, SOCK_STREAM, 0); - if (cvs_sock == -1) { - cvs_log(LP_ERRNO, "failed to open local socket"); - return (-1); - } - - if (connect(cvs_sock, (struct sockaddr *)&cvs_sun, - SUN_LEN(&cvs_sun)) == -1) { - cvs_log(LP_ERRNO, "failed to connect to server socket `%s'", - cvs_sun.sun_path); - (void)close(cvs_sock); - return (-1); - } - - return (0); -} - - -/* - * cvs_sock_disconnect() - * - * Disconnect from the open socket to the CVS server. - */ -void -cvs_sock_disconnect(void) -{ - if (close(cvs_sock) == -1) - cvs_log(LP_ERRNO, "failed to close local socket"); -} -#endif diff --git a/usr.bin/cvs/sock.h b/usr.bin/cvs/sock.h deleted file mode 100644 index 9cdff5114c2..00000000000 --- a/usr.bin/cvs/sock.h +++ /dev/null @@ -1,62 +0,0 @@ -/* $OpenBSD: sock.h,v 1.3 2004/12/07 17:10:56 tedu Exp $ */ -/* - * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef SOCK_H -#define SOCK_H - -#include <sys/types.h> -#include <sys/stat.h> -#include <sys/socket.h> - -#include <err.h> -#include <errno.h> -#include <stdio.h> -#include <stdlib.h> -#include <signal.h> -#include <unistd.h> -#include <string.h> - -#include "cvs.h" - - -#define CVSD_SOCK_PATH "/var/run/cvsd.sock" - -#define CVSD_SOCK_PERMS (S_IRWXU | S_IRWXG) - - -extern char *cvsd_sock_path; -extern int cvsd_sock; - -/* daemon api */ -int cvsd_sock_open (void); -void cvsd_sock_close (void); -int cvsd_sock_accept (int); - -/* client api */ -int cvs_sock_connect (const char *); -void cvs_sock_disconnect (void); - -#endif /* SOCK_H */ |