commit 96fd6df18fbd10f0beed6fcc138d336bbb536a3e from: Stefan Sperling date: Thu Oct 13 12:28:04 2022 UTC move got_gotconfig_read() into new file read_gotconfig_privsep.c commit - affc4eed0efab2d385406813ccf33ac850b09c5c commit + 96fd6df18fbd10f0beed6fcc138d336bbb536a3e blob - b53f5b76596fb58a4657764378bdb954da8fea1c blob + 2491213e9e4a591c7ea3ebd247528bf036f39e53 --- got/Makefile +++ got/Makefile @@ -14,7 +14,8 @@ 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 read_gitconfig_privsep.c + object_open_privsep.c read_gitconfig_privsep.c \ + read_gotconfig_privsep.c MAN = ${PROG}.1 got-worktree.5 git-repository.5 got.conf.5 blob - 7d972eb72bddec7a120c810ebda2c2aafd2639ea blob + 6ffb2c64697c223811c72f8cf386b645cb1bc757 --- gotadmin/Makefile +++ gotadmin/Makefile @@ -10,7 +10,7 @@ SRCS= gotadmin.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 \ - read_gitconfig_privsep.c + read_gitconfig_privsep.c read_gotconfig_privsep.c MAN = ${PROG}.1 CPPFLAGS = -I${.CURDIR}/../include -I${.CURDIR}/../lib 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 - f87f1141ff7e1d618580dcb8a396545fb5c95e39 blob + 8f99e7a2489fce25802d4360c54fd0110b3b6827 --- gotwebd/Makefile +++ gotwebd/Makefile @@ -18,7 +18,8 @@ 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 read_gitconfig_privsep.c + object_open_privsep.c read_gitconfig_privsep.c \ + read_gotconfig_privsep.c MAN = ${PROG}.conf.5 ${PROG}.8 blob - 8abcb57e5150fe88df32e79806a1dca197c5948f blob + 44fc554ac408696a7dbb4c8acb50d2c24dce89a0 --- 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 - dbee17e98fc0c86d1952ac091c986b8438e0fa28 blob + 77026c9204de82a647b51112fe7f475d83c9e480 --- tog/Makefile +++ tog/Makefile @@ -13,7 +13,8 @@ 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 read_gitconfig_privsep.c + object_open_privsep.c read_gitconfig_privsep.c \ + read_gotconfig_privsep.c MAN = ${PROG}.1 CPPFLAGS = -I${.CURDIR}/../include -I${.CURDIR}/../lib