commit 400c1baa797ea52d7f44e2d997bbf0341912a6f4 from: Stefan Sperling via: Thomas Adam date: Thu Oct 13 19:41:56 2022 UTC move got_gotconfig_read() into new file read_gotconfig_privsep.c commit - 405ceee385e4537e9878f8e24a6c3be0640bcd5b commit + 400c1baa797ea52d7f44e2d997bbf0341912a6f4 blob - 8f0796a7d3554adeda23475c3241777041b8fc0b blob + 6acb5d4f05e147393331235098ed9b0bf553f881 --- Makefile.am +++ Makefile.am @@ -61,6 +61,7 @@ regress-delta: $(top_srcdir)/lib/sha1.c \ $(top_srcdir)/lib/object_open_privsep.c \ $(top_srcdir)/regress/delta/delta_test.c \ + $(top_srcdir)/lib/read_gotconfig_privsep.c \ -L$(top_builddir)/compat -lopenbsd-compat $(LIBS) && \ $(top_builddir)/regress/delta/delta_test @@ -75,6 +76,7 @@ regress-deltify: $(top_srcdir)/lib/murmurhash2.c \ $(top_srcdir)/lib/object_open_privsep.c \ $(top_srcdir)/lib/read_gitconfig_privsep.c \ + $(top_srcdir)/lib/read_gotconfig_privsep.c \ -L$(top_builddir)/compat -lopenbsd-compat $(LIBS) && \ $(top_builddir)/regress/deltify/deltify_test @@ -103,6 +105,7 @@ regress-fetch: $(top_srcdir)/lib/object_create.c \ $(top_srcdir)/lib/object_open_privsep.c \ $(top_srcdir)/lib/read_gitconfig_privsep.c \ + $(top_srcdir)/lib/read_gotconfig_privsep.c \ $(top_srcdir)/lib/fetch.c \ $(top_srcdir)/lib/gotconfig.c \ $(top_srcdir)/lib/dial.c \ @@ -125,6 +128,7 @@ regress-idset: $(top_srcdir)/lib/path.c \ $(top_srcdir)/lib/object_parse.c \ $(top_srcdir)/lib/read_gitconfig_privsep.c \ + $(top_srcdir)/lib/read_gotconfig_privsep.c \ -L$(top_builddir)/compat -lopenbsd-compat $(LIBS) && \ $(top_builddir)/regress/idset/idset_test @@ -137,5 +141,6 @@ regress-path: $(top_srcdir)/lib/path.c \ $(top_srcdir)/lib/object_open_privsep.c \ $(top_srcdir)/lib/read_gitconfig_privsep.c \ + $(top_srcdir)/lib/read_gotconfig_privsep.c \ -L$(top_builddir)/compat -lopenbsd-compat $(LIBS) && \ $(top_builddir)/regress/path/path_test blob - 61e1f63cd4e1c9aae84e90515bcdec3b74b8f6af blob + 3707b48f8be2502db6068a5e40d5fd91370ce9cf --- got/Makefile.am +++ got/Makefile.am @@ -23,6 +23,7 @@ got_SOURCES = got.c \ $(top_srcdir)/lib/privsep.c \ $(top_srcdir)/lib/ratelimit.c \ $(top_srcdir)/lib/read_gitconfig_privsep.c \ + $(top_srcdir)/lib/read_gotconfig_privsep.c \ $(top_srcdir)/lib/reference.c \ $(top_srcdir)/lib/repository.c \ $(top_srcdir)/lib/sha1.c \ blob - a8dc8d33c6548605efd6caa2f8c56604a2afc79c blob + e455a11a0d0e27c24d7ac0d0ce31628b19289e7e --- gotadmin/Makefile.am +++ gotadmin/Makefile.am @@ -24,6 +24,7 @@ gotadmin_SOURCES = gotadmin.c \ $(top_srcdir)/lib/privsep.c \ $(top_srcdir)/lib/ratelimit.c \ $(top_srcdir)/lib/read_gitconfig_privsep.c \ + $(top_srcdir)/lib/read_gotconfig_privsep.c \ $(top_srcdir)/lib/reference.c \ $(top_srcdir)/lib/repository.c \ $(top_srcdir)/lib/repository_admin.c \ blob - edf3f32d8d65ccd3ea2024776e6ec0a6c8ad3af3 blob + ae74a7f106da33fa511bef27e2ec204cdb107072 --- gotweb/Makefile +++ gotweb/Makefile @@ -16,7 +16,7 @@ SRCS = gotweb.c parse.y blame.c commit_graph.c delta. 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 \ - read_gitconfig_privsep.c + read_gitconfig_privsep.c read_gotconfig_privsep.c MAN = ${PROG}.conf.5 ${PROG}.8 CPPFLAGS += -I${.CURDIR}/../include -I${.CURDIR}/../lib -I${.CURDIR} \ blob - 49bb8f917bc5e567a5e86c195646db00e0fcdbf6 blob + a860b264a5fdafcb3e965a046d484f5f74f029a2 --- gotwebd/Makefile.am +++ gotwebd/Makefile.am @@ -49,6 +49,7 @@ gotwebd_SOURCES = config.c \ $(top_srcdir)/lib/privsep.c \ $(top_srcdir)/lib/rcsutil.c \ $(top_srcdir)/lib/read_gitconfig_privsep.c \ + $(top_srcdir)/lib/read_gotconfig_privsep.c \ $(top_srcdir)/lib/reference.c \ $(top_srcdir)/lib/repository.c \ $(top_srcdir)/lib/sha1.c \ blob - f4b8945c99801ba8be0d56637b26e91ea722d2d5 blob + 3659cf2de9d905cce373d19b59337a6ce0dd904d --- lib/gotconfig.c +++ lib/gotconfig.c @@ -33,128 +33,10 @@ #include "got_object.h" #include "got_repository.h" -#include "got_lib_delta.h" -#include "got_lib_object.h" -#include "got_lib_privsep.h" #include "got_lib_gotconfig.h" #include "got_gotconfig.h" -const struct got_error * -got_gotconfig_read(struct got_gotconfig **conf, const char *gotconfig_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; - - *conf = calloc(1, sizeof(**conf)); - if (*conf == NULL) - return got_error_from_errno("calloc"); - - fd = open(gotconfig_path, O_RDONLY | O_CLOEXEC); - if (fd == -1) { - if (errno == ENOENT) - return NULL; - return got_error_from_errno2("open", gotconfig_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_GOTCONFIG, - gotconfig_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_gotconfig_parse_req(ibuf, fd); - if (err) - goto done; - fd = -1; - - err = got_privsep_send_gotconfig_author_req(ibuf); - if (err) - goto done; - - err = got_privsep_recv_gotconfig_str(&(*conf)->author, ibuf); - if (err) - goto done; - - err = got_privsep_send_gotconfig_allowed_signers_req(ibuf); - if (err) - goto done; - - err = got_privsep_recv_gotconfig_str(&(*conf)->allowed_signers_file, - ibuf); - if (err) - goto done; - - err = got_privsep_send_gotconfig_revoked_signers_req(ibuf); - if (err) - goto done; - - err = got_privsep_recv_gotconfig_str(&(*conf)->revoked_signers_file, - ibuf); - if (err) - goto done; - - err = got_privsep_send_gotconfig_signer_id_req(ibuf); - if (err) - goto done; - - err = got_privsep_recv_gotconfig_str(&(*conf)->signer_id, ibuf); - if (err) - goto done; - - err = got_privsep_send_gotconfig_remotes_req(ibuf); - if (err) - goto done; - - err = got_privsep_recv_gotconfig_remotes(&(*conf)->remotes, - &(*conf)->nremotes, 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", gotconfig_path); - if (err) { - got_gotconfig_free(*conf); - *conf = NULL; - } - free(ibuf); - return err; -} - void got_gotconfig_free(struct got_gotconfig *conf) { blob - /dev/null blob + 00dbdebf54e0335e148296057d897cb9f431e29f (mode 644) --- /dev/null +++ lib/read_gotconfig_privsep.c @@ -0,0 +1,156 @@ +/* + * Copyright (c) 2020 Stefan Sperling + * + * 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 +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "got_error.h" +#include "got_object.h" +#include "got_repository.h" + +#include "got_lib_delta.h" +#include "got_lib_object.h" +#include "got_lib_privsep.h" +#include "got_lib_gotconfig.h" + +#include "got_gotconfig.h" + +const struct got_error * +got_gotconfig_read(struct got_gotconfig **conf, const char *gotconfig_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; + + *conf = calloc(1, sizeof(**conf)); + if (*conf == NULL) + return got_error_from_errno("calloc"); + + fd = open(gotconfig_path, O_RDONLY | O_CLOEXEC); + if (fd == -1) { + if (errno == ENOENT) + return NULL; + return got_error_from_errno2("open", gotconfig_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_GOTCONFIG, + gotconfig_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_gotconfig_parse_req(ibuf, fd); + if (err) + goto done; + fd = -1; + + err = got_privsep_send_gotconfig_author_req(ibuf); + if (err) + goto done; + + err = got_privsep_recv_gotconfig_str(&(*conf)->author, ibuf); + if (err) + goto done; + + err = got_privsep_send_gotconfig_allowed_signers_req(ibuf); + if (err) + goto done; + + err = got_privsep_recv_gotconfig_str(&(*conf)->allowed_signers_file, + ibuf); + if (err) + goto done; + + err = got_privsep_send_gotconfig_revoked_signers_req(ibuf); + if (err) + goto done; + + err = got_privsep_recv_gotconfig_str(&(*conf)->revoked_signers_file, + ibuf); + if (err) + goto done; + + err = got_privsep_send_gotconfig_signer_id_req(ibuf); + if (err) + goto done; + + err = got_privsep_recv_gotconfig_str(&(*conf)->signer_id, ibuf); + if (err) + goto done; + + err = got_privsep_send_gotconfig_remotes_req(ibuf); + if (err) + goto done; + + err = got_privsep_recv_gotconfig_remotes(&(*conf)->remotes, + &(*conf)->nremotes, 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", gotconfig_path); + if (err) { + got_gotconfig_free(*conf); + *conf = NULL; + } + free(ibuf); + return err; +} blob - cd7a2983233d7fa5ed552f34a67f1d07d5c81e1f blob + f52c80673381058fa605428772575e17f2276fd9 --- regress/fetch/Makefile +++ regress/fetch/Makefile @@ -5,7 +5,8 @@ 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 read_gitconfig_privsep.c + buf.c date.c object_open_privsep.c read_gitconfig_privsep.c \ + read_gotconfig_privsep.c CPPFLAGS = -I${.CURDIR}/../../include -I${.CURDIR}/../../lib LDADD = -lutil -lz -lm blob - c9630157cd33572cfbca1730950640a66247abe4 blob + 182343dfed5fc093b43c735e021f77431a0fcc6d --- tog/Makefile.am +++ tog/Makefile.am @@ -48,6 +48,7 @@ tog_SOURCES = tog.c \ $(top_srcdir)/lib/murmurhash2.c \ $(top_srcdir)/lib/date.c \ $(top_srcdir)/lib/read_gitconfig_privsep.c \ + $(top_srcdir)/lib/read_gotconfig_privsep.c \ $(top_srcdir)/lib/sigs.c tog_DEPENDENCIES = $(top_builddir)/compat/libopenbsd-compat.a