Blob
- Date:
- Message:
- introduce gotd(8), a Git repository server reachable via ssh(1) This is an initial barebones implementation which provides the absolute minimum of functionality required to serve got(1) and git(1) clients. Basic fetch/send functionality has been tested and seems to work here, but this server is not yet expected to be stable. More testing is welcome. See the man pages for setup instructions. The current design uses one reader and one writer process per repository, which will have to be extended to N readers and N writers in the future. At startup, each process will chroot(2) into its assigned repository. This works because gotd(8) can only be started as root, and will then fork+exec, chroot, and privdrop. At present the parent process runs with the following pledge(2) promises: "stdio rpath wpath cpath proc getpw sendfd recvfd fattr flock unix unveil" The parent is the only process able to modify the repository in a way that becomes visible to Git clients. The parent uses unveil(2) to restrict its view of the filesystem to /tmp and the repositories listed in the configuration file gotd.conf(5). Per-repository chroot(2) processes use "stdio rpath sendfd recvfd". The writer defers to the parent for modifying references in the repository to point at newly uploaded commits. The reader is fine without such help, because Git repositories can be read without having to create any lock-files. gotd(8) requires a dedicated user ID, which should own repositories on the filesystem, and a separate secondary group, which should not have filesystem-level repository access, and must be allowed access to the gotd(8) socket. To obtain Git repository access, users must be members of this secondary group, and must have their login shell set to gotsh(1). gotsh(1) connects to the gotd(8) socket and speaks Git-protocol towards the client on the other end of the SSH connection. gotsh(1) is not an interactive command shell. At present, authenticated clients are granted read/write access to all repositories and all references (except for the "refs/got/" and the "refs/remotes/" namespaces, which are already being protected from modification). While complicated access control mechanism are not a design goal, making it possible to safely offer anonymous Git repository access over ssh(1) is on the road map.
- Actions:
- History | Blame | Raw File
1 /*2 * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>3 *4 * Permission to use, copy, modify, and distribute this software for any5 * purpose with or without fee is hereby granted, provided that the above6 * copyright notice and this permission notice appear in all copies.7 *8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.15 */17 #include <stdio.h>18 #include <stdlib.h>19 #include <stdarg.h>20 #include <string.h>21 #include <syslog.h>22 #include <errno.h>23 #include <time.h>25 #include "log.h"27 static int debug;28 static int verbose;29 const char *log_procname;31 void32 log_init(int n_debug, int facility)33 {34 debug = n_debug;35 verbose = n_debug;36 log_procinit(getprogname());38 if (!debug)39 openlog(getprogname(), LOG_PID | LOG_NDELAY, facility);41 tzset();42 }44 void45 log_procinit(const char *procname)46 {47 if (procname != NULL)48 log_procname = procname;49 }51 void52 log_setverbose(int v)53 {54 verbose = v;55 }57 int58 log_getverbose(void)59 {60 return (verbose);61 }63 void64 logit(int pri, const char *fmt, ...)65 {66 va_list ap;68 va_start(ap, fmt);69 vlog(pri, fmt, ap);70 va_end(ap);71 }73 void74 vlog(int pri, const char *fmt, va_list ap)75 {76 char *nfmt;77 int saved_errno = errno;79 if (debug) {80 /* best effort in out of mem situations */81 if (asprintf(&nfmt, "%s\n", fmt) == -1) {82 vfprintf(stderr, fmt, ap);83 fprintf(stderr, "\n");84 } else {85 vfprintf(stderr, nfmt, ap);86 free(nfmt);87 }88 fflush(stderr);89 } else90 vsyslog(pri, fmt, ap);92 errno = saved_errno;93 }95 void96 log_warn(const char *emsg, ...)97 {98 char *nfmt;99 va_list ap;100 int saved_errno = errno;102 /* best effort to even work in out of memory situations */103 if (emsg == NULL)104 logit(LOG_CRIT, "%s", strerror(saved_errno));105 else {106 va_start(ap, emsg);108 if (asprintf(&nfmt, "%s: %s", emsg,109 strerror(saved_errno)) == -1) {110 /* we tried it... */111 vlog(LOG_CRIT, emsg, ap);112 logit(LOG_CRIT, "%s", strerror(saved_errno));113 } else {114 vlog(LOG_CRIT, nfmt, ap);115 free(nfmt);116 }117 va_end(ap);118 }120 errno = saved_errno;121 }123 void124 log_warnx(const char *emsg, ...)125 {126 va_list ap;128 va_start(ap, emsg);129 vlog(LOG_CRIT, emsg, ap);130 va_end(ap);131 }133 void134 log_info(const char *emsg, ...)135 {136 va_list ap;138 va_start(ap, emsg);139 vlog(LOG_INFO, emsg, ap);140 va_end(ap);141 }143 void144 log_debug(const char *emsg, ...)145 {146 va_list ap;148 if (verbose) {149 va_start(ap, emsg);150 vlog(LOG_DEBUG, emsg, ap);151 va_end(ap);152 }153 }155 static void156 vfatalc(int code, const char *emsg, va_list ap)157 {158 static char s[BUFSIZ];159 const char *sep;161 if (emsg != NULL) {162 (void)vsnprintf(s, sizeof(s), emsg, ap);163 sep = ": ";164 } else {165 s[0] = '\0';166 sep = "";167 }168 if (code)169 logit(LOG_CRIT, "%s: %s%s%s",170 log_procname, s, sep, strerror(code));171 else172 logit(LOG_CRIT, "%s%s%s", log_procname, sep, s);173 }175 void176 fatal(const char *emsg, ...)177 {178 va_list ap;180 va_start(ap, emsg);181 vfatalc(errno, emsg, ap);182 va_end(ap);183 exit(1);184 }186 void187 fatalx(const char *emsg, ...)188 {189 va_list ap;191 va_start(ap, emsg);192 vfatalc(0, emsg, ap);193 va_end(ap);194 exit(1);195 }