Commit Diff


commit - 1d9e43b0ca10bcb024cf1335f2a1e95647a50e9c
commit + 6a800804535a75203abfb3708e68a661c1c89958
blob - ebdd46b32765e3a469912c789d2e66380474b9bb
blob + b53f5b76596fb58a4657764378bdb954da8fea1c
--- got/Makefile
+++ got/Makefile
@@ -14,7 +14,7 @@ SRCS=		got.c blame.c commit_graph.c delta.c diff.c \
 		diff_output_unidiff.c diff_output_edscript.c \
 		diff_patience.c send.c deltify.c pack_create.c dial.c \
 		bloom.c murmurhash2.c ratelimit.c patch.c sigs.c date.c \
-		object_open_privsep.c
+		object_open_privsep.c read_gitconfig_privsep.c
 
 MAN =		${PROG}.1 got-worktree.5 git-repository.5 got.conf.5
 
blob - 61964eeb24894743d7e03a98d7da55b1ffc4a4af
blob + 7d972eb72bddec7a120c810ebda2c2aafd2639ea
--- gotadmin/Makefile
+++ gotadmin/Makefile
@@ -9,7 +9,8 @@ SRCS=		gotadmin.c \
 		object_idset.c object_parse.c opentemp.c pack.c pack_create.c \
 		path.c privsep.c reference.c repository.c repository_admin.c \
 		worktree_open.c sha1.c bloom.c murmurhash2.c ratelimit.c \
-		sigs.c buf.c date.c object_open_privsep.c
+		sigs.c buf.c date.c object_open_privsep.c \
+		read_gitconfig_privsep.c
 MAN =		${PROG}.1
 
 CPPFLAGS = -I${.CURDIR}/../include -I${.CURDIR}/../lib
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 - de3dcacc20ae8cf7d1e63df9fbfa5430784ab2bb
blob + f87f1141ff7e1d618580dcb8a396545fb5c95e39
--- gotwebd/Makefile
+++ gotwebd/Makefile
@@ -18,7 +18,7 @@ SRCS +=		blame.c commit_graph.c delta.c diff.c \
 		diff_output.c diff_output_plain.c diff_output_unidiff.c \
 		diff_output_edscript.c diff_patience.c bloom.c murmurhash2.c \
 		worktree_open.c patch.c sigs.c date.c sockaddr.c \
-		object_open_privsep.c
+		object_open_privsep.c read_gitconfig_privsep.c
 
 MAN =		${PROG}.conf.5 ${PROG}.8
 
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 - 5b8073b6d323365b34814adee39ff939c26df08e
blob + 4ce6727114c32c4380ae59715312588d87adc91b
--- lib/repository.c
+++ lib/repository.c
@@ -487,161 +487,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;
 }
 
@@ -654,7 +501,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);
@@ -667,7 +514,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 - aa13e23859c0a05101c4f431cd0675719f48a8e2
blob + dbee17e98fc0c86d1952ac091c986b8438e0fa28
--- tog/Makefile
+++ tog/Makefile
@@ -13,7 +13,7 @@ SRCS=		tog.c blame.c commit_graph.c delta.c diff.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
+		object_open_privsep.c read_gitconfig_privsep.c
 MAN =		${PROG}.1
 
 CPPFLAGS = -I${.CURDIR}/../include -I${.CURDIR}/../lib