Commit Diff


commit - 54c227727ee63cc0f86859c76a0003c21ca3563a
commit + d348087d319f40c9237d272e23cd12fdec5bd123
blob - 9cde7b165444414f71261f8f2c60b8e8172cbea5
blob + 8f0796a7d3554adeda23475c3241777041b8fc0b
--- Makefile.am
+++ Makefile.am
@@ -74,6 +74,7 @@ regress-deltify:
 		$(top_srcdir)/lib/sha1.c \
 		$(top_srcdir)/lib/murmurhash2.c \
 		$(top_srcdir)/lib/object_open_privsep.c \
+		$(top_srcdir)/lib/read_gitconfig_privsep.c \
 		-L$(top_builddir)/compat -lopenbsd-compat $(LIBS) && \
 			$(top_builddir)/regress/deltify/deltify_test
 
@@ -101,6 +102,7 @@ regress-fetch:
 		$(top_srcdir)/lib/object_idset.c \
 		$(top_srcdir)/lib/object_create.c \
 		$(top_srcdir)/lib/object_open_privsep.c \
+		$(top_srcdir)/lib/read_gitconfig_privsep.c \
 		$(top_srcdir)/lib/fetch.c \
 		$(top_srcdir)/lib/gotconfig.c \
 		$(top_srcdir)/lib/dial.c \
@@ -122,6 +124,7 @@ regress-idset:
 		$(top_srcdir)/lib/inflate.c \
 		$(top_srcdir)/lib/path.c \
 		$(top_srcdir)/lib/object_parse.c \
+		$(top_srcdir)/lib/read_gitconfig_privsep.c \
 		-L$(top_builddir)/compat -lopenbsd-compat $(LIBS) && \
 			$(top_builddir)/regress/idset/idset_test
 
@@ -133,5 +136,6 @@ regress-path:
 		$(top_srcdir)/lib/sha1.c \
 		$(top_srcdir)/lib/path.c \
 		$(top_srcdir)/lib/object_open_privsep.c \
+		$(top_srcdir)/lib/read_gitconfig_privsep.c \
 		-L$(top_builddir)/compat -lopenbsd-compat $(LIBS) && \
 			$(top_builddir)/regress/path/path_test
blob - d2ed6174b7b559747661a63aa31f4e54628c99d6
blob + 61e1f63cd4e1c9aae84e90515bcdec3b74b8f6af
--- got/Makefile.am
+++ got/Makefile.am
@@ -22,6 +22,7 @@ got_SOURCES = got.c \
 	$(top_srcdir)/lib/pack.c \
 	$(top_srcdir)/lib/privsep.c \
 	$(top_srcdir)/lib/ratelimit.c \
+	$(top_srcdir)/lib/read_gitconfig_privsep.c \
 	$(top_srcdir)/lib/reference.c \
 	$(top_srcdir)/lib/repository.c \
 	$(top_srcdir)/lib/sha1.c \
blob - 4c2e510946744eb3108d37d94116401e7b8f37c1
blob + a8dc8d33c6548605efd6caa2f8c56604a2afc79c
--- gotadmin/Makefile.am
+++ gotadmin/Makefile.am
@@ -23,6 +23,7 @@ gotadmin_SOURCES = gotadmin.c \
        $(top_srcdir)/lib/path.c \
        $(top_srcdir)/lib/privsep.c \
        $(top_srcdir)/lib/ratelimit.c \
+       $(top_srcdir)/lib/read_gitconfig_privsep.c \
        $(top_srcdir)/lib/reference.c \
        $(top_srcdir)/lib/repository.c \
        $(top_srcdir)/lib/repository_admin.c \
blob - dc0086e6c8467903bee24745d317a83ca20c538a
blob + edf3f32d8d65ccd3ea2024776e6ec0a6c8ad3af3
--- gotweb/Makefile
+++ gotweb/Makefile
@@ -15,7 +15,8 @@ SRCS =		gotweb.c parse.y blame.c commit_graph.c delta.
 		diff_main.c diff_atomize_text.c diff_myers.c diff_output.c \
 		diff_output_plain.c diff_output_unidiff.c \
 		diff_output_edscript.c diff_patience.c \
-		bloom.c murmurhash2.c sigs.c date.c object_open_privsep.c
+		bloom.c murmurhash2.c sigs.c date.c object_open_privsep.c \
+		read_gitconfig_privsep.c
 MAN =		${PROG}.conf.5 ${PROG}.8
 
 CPPFLAGS +=	-I${.CURDIR}/../include -I${.CURDIR}/../lib -I${.CURDIR} \
blob - 0815870f33f1ad8613553f86364320c7053fb0f0
blob + 49bb8f917bc5e567a5e86c195646db00e0fcdbf6
--- gotwebd/Makefile.am
+++ gotwebd/Makefile.am
@@ -48,6 +48,7 @@ gotwebd_SOURCES = config.c \
 		  $(top_srcdir)/lib/path.c \
 		  $(top_srcdir)/lib/privsep.c \
 		  $(top_srcdir)/lib/rcsutil.c \
+		  $(top_srcdir)/lib/read_gitconfig_privsep.c \
 		  $(top_srcdir)/lib/reference.c \
 		  $(top_srcdir)/lib/repository.c \
 		  $(top_srcdir)/lib/sha1.c \
blob - fadbfad45e1c86893452d04c192e3bf35883bebf
blob + 4015e1cdcca8f6de5990a90e32e88c4004495348
--- lib/got_lib_repository.h
+++ lib/got_lib_repository.h
@@ -152,3 +152,6 @@ const struct got_error *got_repo_pin_pack(struct got_r
 struct got_pack *got_repo_get_pinned_pack(struct got_repository *);
 void got_repo_unpin_pack(struct got_repository *);
 
+const struct got_error *got_repo_read_gitconfig(int *, char **, char **,
+    struct got_remote_repo **, int *, char **, char ***, int *,
+    const char *);
blob - /dev/null
blob + 0f29cc09331dd7d207bd1ec47e0b2310708660ee (mode 644)
--- /dev/null
+++ lib/read_gitconfig_privsep.c
@@ -0,0 +1,196 @@
+/*
+ * Copyright (c) 2019, 2022 Stefan Sperling <stsp@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/types.h>
+#include <sys/tree.h>
+#include <sys/socket.h>
+#include <sys/queue.h>
+#include <sys/uio.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <sha1.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <imsg.h>
+#include <unistd.h>
+
+#include "got_error.h"
+#include "got_object.h"
+#include "got_repository.h"
+#include "got_path.h"
+
+#include "got_lib_delta.h"
+#include "got_lib_object.h"
+#include "got_lib_object_cache.h"
+#include "got_lib_privsep.h"
+#include "got_lib_pack.h"
+#include "got_lib_repository.h"
+
+const struct got_error *
+got_repo_read_gitconfig(int *gitconfig_repository_format_version,
+    char **gitconfig_author_name, char **gitconfig_author_email,
+    struct got_remote_repo **remotes, int *nremotes,
+    char **gitconfig_owner, char ***extensions, int *nextensions,
+    const char *gitconfig_path)
+{
+	const struct got_error *err = NULL, *child_err = NULL;
+	int fd = -1;
+	int imsg_fds[2] = { -1, -1 };
+	pid_t pid;
+	struct imsgbuf *ibuf;
+
+	*gitconfig_repository_format_version = 0;
+	if (extensions)
+		*extensions = NULL;
+	if (nextensions)
+		*nextensions = 0;
+	*gitconfig_author_name = NULL;
+	*gitconfig_author_email = NULL;
+	if (remotes)
+		*remotes = NULL;
+	if (nremotes)
+		*nremotes = 0;
+	if (gitconfig_owner)
+		*gitconfig_owner = NULL;
+
+	fd = open(gitconfig_path, O_RDONLY | O_CLOEXEC);
+	if (fd == -1) {
+		if (errno == ENOENT)
+			return NULL;
+		return got_error_from_errno2("open", gitconfig_path);
+	}
+
+	ibuf = calloc(1, sizeof(*ibuf));
+	if (ibuf == NULL) {
+		err = got_error_from_errno("calloc");
+		goto done;
+	}
+
+	if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, imsg_fds) == -1) {
+		err = got_error_from_errno("socketpair");
+		goto done;
+	}
+
+	pid = fork();
+	if (pid == -1) {
+		err = got_error_from_errno("fork");
+		goto done;
+	} else if (pid == 0) {
+		got_privsep_exec_child(imsg_fds, GOT_PATH_PROG_READ_GITCONFIG,
+		    gitconfig_path);
+		/* not reached */
+	}
+
+	if (close(imsg_fds[1]) == -1) {
+		err = got_error_from_errno("close");
+		goto done;
+	}
+	imsg_fds[1] = -1;
+	imsg_init(ibuf, imsg_fds[0]);
+
+	err = got_privsep_send_gitconfig_parse_req(ibuf, fd);
+	if (err)
+		goto done;
+	fd = -1;
+
+	err = got_privsep_send_gitconfig_repository_format_version_req(ibuf);
+	if (err)
+		goto done;
+
+	err = got_privsep_recv_gitconfig_int(
+	    gitconfig_repository_format_version, ibuf);
+	if (err)
+		goto done;
+
+	if (extensions && nextensions) {
+		err = got_privsep_send_gitconfig_repository_extensions_req(
+		    ibuf);
+		if (err)
+			goto done;
+		err = got_privsep_recv_gitconfig_int(nextensions, ibuf);
+		if (err)
+			goto done;
+		if (*nextensions > 0) {
+			int i;
+			*extensions = calloc(*nextensions, sizeof(char *));
+			if (*extensions == NULL) {
+				err = got_error_from_errno("calloc");
+				goto done;
+			}
+			for (i = 0; i < *nextensions; i++) {
+				char *ext;
+				err = got_privsep_recv_gitconfig_str(&ext,
+				    ibuf);
+				if (err)
+					goto done;
+				(*extensions)[i] = ext;
+			}
+		}
+	}
+
+	err = got_privsep_send_gitconfig_author_name_req(ibuf);
+	if (err)
+		goto done;
+
+	err = got_privsep_recv_gitconfig_str(gitconfig_author_name, ibuf);
+	if (err)
+		goto done;
+
+	err = got_privsep_send_gitconfig_author_email_req(ibuf);
+	if (err)
+		goto done;
+
+	err = got_privsep_recv_gitconfig_str(gitconfig_author_email, ibuf);
+	if (err)
+		goto done;
+
+	if (remotes && nremotes) {
+		err = got_privsep_send_gitconfig_remotes_req(ibuf);
+		if (err)
+			goto done;
+
+		err = got_privsep_recv_gitconfig_remotes(remotes,
+		    nremotes, ibuf);
+		if (err)
+			goto done;
+	}
+
+	if (gitconfig_owner) {
+		err = got_privsep_send_gitconfig_owner_req(ibuf);
+		if (err)
+			goto done;
+		err = got_privsep_recv_gitconfig_str(gitconfig_owner, ibuf);
+		if (err)
+			goto done;
+	}
+
+	err = got_privsep_send_stop(imsg_fds[0]);
+	child_err = got_privsep_wait_for_child(pid);
+	if (child_err && err == NULL)
+		err = child_err;
+done:
+	if (imsg_fds[0] != -1 && close(imsg_fds[0]) == -1 && err == NULL)
+		err = got_error_from_errno("close");
+	if (imsg_fds[1] != -1 && close(imsg_fds[1]) == -1 && err == NULL)
+		err = got_error_from_errno("close");
+	if (fd != -1 && close(fd) == -1 && err == NULL)
+		err = got_error_from_errno2("close", gitconfig_path);
+	free(ibuf);
+	return err;
+}
blob - c2d947195b439b1a091c0e087b34fdadb14a3d58
blob + 2dde8c00b8802b9a1853350993d47c812cd657e0
--- lib/repository.c
+++ lib/repository.c
@@ -482,161 +482,8 @@ done:
 		if (repo->gitdir_fd != -1)
 			close(repo->gitdir_fd);
 		repo->gitdir_fd = -1;
-
-	}
-	return err;
-}
-
-static const struct got_error *
-parse_gitconfig_file(int *gitconfig_repository_format_version,
-    char **gitconfig_author_name, char **gitconfig_author_email,
-    struct got_remote_repo **remotes, int *nremotes,
-    char **gitconfig_owner, char ***extensions, int *nextensions,
-    const char *gitconfig_path)
-{
-	const struct got_error *err = NULL, *child_err = NULL;
-	int fd = -1;
-	int imsg_fds[2] = { -1, -1 };
-	pid_t pid;
-	struct imsgbuf *ibuf;
-
-	*gitconfig_repository_format_version = 0;
-	if (extensions)
-		*extensions = NULL;
-	if (nextensions)
-		*nextensions = 0;
-	*gitconfig_author_name = NULL;
-	*gitconfig_author_email = NULL;
-	if (remotes)
-		*remotes = NULL;
-	if (nremotes)
-		*nremotes = 0;
-	if (gitconfig_owner)
-		*gitconfig_owner = NULL;
-
-	fd = open(gitconfig_path, O_RDONLY | O_CLOEXEC);
-	if (fd == -1) {
-		if (errno == ENOENT)
-			return NULL;
-		return got_error_from_errno2("open", gitconfig_path);
-	}
-
-	ibuf = calloc(1, sizeof(*ibuf));
-	if (ibuf == NULL) {
-		err = got_error_from_errno("calloc");
-		goto done;
-	}
-
-	if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, imsg_fds) == -1) {
-		err = got_error_from_errno("socketpair");
-		goto done;
-	}
-
-	pid = fork();
-	if (pid == -1) {
-		err = got_error_from_errno("fork");
-		goto done;
-	} else if (pid == 0) {
-		got_privsep_exec_child(imsg_fds, GOT_PATH_PROG_READ_GITCONFIG,
-		    gitconfig_path);
-		/* not reached */
-	}
-
-	if (close(imsg_fds[1]) == -1) {
-		err = got_error_from_errno("close");
-		goto done;
-	}
-	imsg_fds[1] = -1;
-	imsg_init(ibuf, imsg_fds[0]);
-
-	err = got_privsep_send_gitconfig_parse_req(ibuf, fd);
-	if (err)
-		goto done;
-	fd = -1;
-
-	err = got_privsep_send_gitconfig_repository_format_version_req(ibuf);
-	if (err)
-		goto done;
-
-	err = got_privsep_recv_gitconfig_int(
-	    gitconfig_repository_format_version, ibuf);
-	if (err)
-		goto done;
-
-	if (extensions && nextensions) {
-		err = got_privsep_send_gitconfig_repository_extensions_req(
-		    ibuf);
-		if (err)
-			goto done;
-		err = got_privsep_recv_gitconfig_int(nextensions, ibuf);
-		if (err)
-			goto done;
-		if (*nextensions > 0) {
-			int i;
-			*extensions = calloc(*nextensions, sizeof(char *));
-			if (*extensions == NULL) {
-				err = got_error_from_errno("calloc");
-				goto done;
-			}
-			for (i = 0; i < *nextensions; i++) {
-				char *ext;
-				err = got_privsep_recv_gitconfig_str(&ext,
-				    ibuf);
-				if (err)
-					goto done;
-				(*extensions)[i] = ext;
-			}
-		}
-	}
-
-	err = got_privsep_send_gitconfig_author_name_req(ibuf);
-	if (err)
-		goto done;
-
-	err = got_privsep_recv_gitconfig_str(gitconfig_author_name, ibuf);
-	if (err)
-		goto done;
-
-	err = got_privsep_send_gitconfig_author_email_req(ibuf);
-	if (err)
-		goto done;
-
-	err = got_privsep_recv_gitconfig_str(gitconfig_author_email, ibuf);
-	if (err)
-		goto done;
 
-	if (remotes && nremotes) {
-		err = got_privsep_send_gitconfig_remotes_req(ibuf);
-		if (err)
-			goto done;
-
-		err = got_privsep_recv_gitconfig_remotes(remotes,
-		    nremotes, ibuf);
-		if (err)
-			goto done;
-	}
-
-	if (gitconfig_owner) {
-		err = got_privsep_send_gitconfig_owner_req(ibuf);
-		if (err)
-			goto done;
-		err = got_privsep_recv_gitconfig_str(gitconfig_owner, ibuf);
-		if (err)
-			goto done;
 	}
-
-	err = got_privsep_send_stop(imsg_fds[0]);
-	child_err = got_privsep_wait_for_child(pid);
-	if (child_err && err == NULL)
-		err = child_err;
-done:
-	if (imsg_fds[0] != -1 && close(imsg_fds[0]) == -1 && err == NULL)
-		err = got_error_from_errno("close");
-	if (imsg_fds[1] != -1 && close(imsg_fds[1]) == -1 && err == NULL)
-		err = got_error_from_errno("close");
-	if (fd != -1 && close(fd) == -1 && err == NULL)
-		err = got_error_from_errno2("close", gitconfig_path);
-	free(ibuf);
 	return err;
 }
 
@@ -649,7 +496,7 @@ read_gitconfig(struct got_repository *repo, const char
 	if (global_gitconfig_path) {
 		/* Read settings from ~/.gitconfig. */
 		int dummy_repo_version;
-		err = parse_gitconfig_file(&dummy_repo_version,
+		err = got_repo_read_gitconfig(&dummy_repo_version,
 		    &repo->global_gitconfig_author_name,
 		    &repo->global_gitconfig_author_email,
 		    NULL, NULL, NULL, NULL, NULL, global_gitconfig_path);
@@ -662,7 +509,8 @@ read_gitconfig(struct got_repository *repo, const char
 	if (repo_gitconfig_path == NULL)
 		return got_error_from_errno("got_repo_get_path_gitconfig");
 
-	err = parse_gitconfig_file(&repo->gitconfig_repository_format_version,
+	err = got_repo_read_gitconfig(
+	    &repo->gitconfig_repository_format_version,
 	    &repo->gitconfig_author_name, &repo->gitconfig_author_email,
 	    &repo->gitconfig_remotes, &repo->ngitconfig_remotes,
 	    &repo->gitconfig_owner, &repo->extensions, &repo->nextensions,
blob - 010d5c58dd7c45337472d5f5bb7045b080150f3d
blob + cd7a2983233d7fa5ed552f34a67f1d07d5c81e1f
--- regress/fetch/Makefile
+++ regress/fetch/Makefile
@@ -5,7 +5,7 @@ SRCS = error.c privsep.c reference.c sha1.c object.c o
 	opentemp.c repository.c lockfile.c object_cache.c pack.c inflate.c \
 	deflate.c delta.c delta_cache.c object_idset.c object_create.c \
 	fetch.c gotconfig.c dial.c fetch_test.c bloom.c murmurhash2.c sigs.c \
-	buf.c date.c object_open_privsep.c
+	buf.c date.c object_open_privsep.c read_gitconfig_privsep.c
 
 CPPFLAGS = -I${.CURDIR}/../../include -I${.CURDIR}/../../lib
 LDADD = -lutil -lz -lm
blob - d29f3726176bcecc862c887cc1f0264ad91a958f
blob + c9630157cd33572cfbca1730950640a66247abe4
--- tog/Makefile.am
+++ tog/Makefile.am
@@ -47,6 +47,7 @@ tog_SOURCES = tog.c \
 	$(top_srcdir)/lib/bloom.c \
 	$(top_srcdir)/lib/murmurhash2.c \
 	$(top_srcdir)/lib/date.c \
+	$(top_srcdir)/lib/read_gitconfig_privsep.c \
 	$(top_srcdir)/lib/sigs.c
 
 tog_DEPENDENCIES = $(top_builddir)/compat/libopenbsd-compat.a