Add support for DownloadUser with XferCommand

Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
Remi Gacogne 2022-11-09 11:17:36 +10:00 committed by Allan McRae
parent 93a796aa27
commit cf359b0da4
2 changed files with 11 additions and 3 deletions

View file

@ -1029,7 +1029,7 @@ static int curl_download_internal_sandboxed(alpm_handle_t *handle,
_alpm_log(handle, ALPM_LOG_ERROR, _("could not chdir to download directory %s\n"), localpath);
ret = -1;
} else {
ret = alpm_sandbox_child(handle->sandboxuser);
ret = alpm_sandbox_setup_child(handle->sandboxuser);
if (ret != 0) {
_alpm_log(handle, ALPM_LOG_ERROR, _("switching to sandbox user '%s' failed!\n"), handle->sandboxuser);
_Exit(2);

View file

@ -218,7 +218,7 @@ static char *get_tempfile(const char *path, const char *filename)
* - not thread-safe
* - errno may be set by fork(), pipe(), or execvp()
*/
static int systemvp(const char *file, char *const argv[])
static int systemvp(const char *file, char *const argv[], const char *sandboxuser)
{
int pid, err = 0, ret = -1, err_fd[2];
sigset_t oldblock;
@ -245,6 +245,14 @@ static int systemvp(const char *file, char *const argv[])
sigaction(SIGQUIT, &oldquit, NULL);
sigprocmask(SIG_SETMASK, &oldblock, NULL);
if (sandboxuser) {
ret = alpm_sandbox_setup_child(sandboxuser);
if (ret != 0) {
pm_printf(ALPM_LOG_ERROR, _("switching to sandbox user '%s' failed!\n"), sandboxuser);
_Exit(ret);
}
}
execvp(file, argv);
/* execvp failed, pass the error back to the parent */
@ -355,7 +363,7 @@ static int download_with_xfercommand(void *ctx, const char *url,
free(cmd);
}
}
retval = systemvp(argv[0], (char**)argv);
retval = systemvp(argv[0], (char**)argv, config->sandboxuser);
if(retval == -1) {
pm_printf(ALPM_LOG_WARNING, _("running XferCommand: fork failed!\n"));