From aa9512d232e611ccbba46b17349168e501e2bd78 Mon Sep 17 00:00:00 2001 From: kit Date: Mon, 18 May 2026 16:11:59 -0400 Subject: [PATCH] initial --- Makefile | 18 ++++++++++++++++++ exec-in-chroot.c | 31 +++++++++++++++++++++++++++++++ exec-in-chroot.conf | 5 +++++ 3 files changed, 54 insertions(+) create mode 100755 Makefile create mode 100644 exec-in-chroot.c create mode 100644 exec-in-chroot.conf diff --git a/Makefile b/Makefile new file mode 100755 index 0000000..46cb9f8 --- /dev/null +++ b/Makefile @@ -0,0 +1,18 @@ +#!/bin/make + +CFLAGS ?= -Ofast -march=native -mtune=native -static -Wall -Wextra -Wpedantic + +./exec-in-chroot: ./exec-in-chroot.c + +.PHONY: install uninstall clean +install: ./exec-in-chroot + cp "$<" "${PREFIX}/bin/exec-in-chroot" + chmod 4555 "${PREFIX}/bin/exec-in-chroot" + cp -n "./exec-in-chroot.conf" "/etc/exec-in-chroot.conf" + +uninstall: + rm "${PREFIX}/bin/exec-in-chroot" + rm "/etc/exec-in-chroot.conf" + +clean: + rm ./exec-in-chroot diff --git a/exec-in-chroot.c b/exec-in-chroot.c new file mode 100644 index 0000000..138977c --- /dev/null +++ b/exec-in-chroot.c @@ -0,0 +1,31 @@ +#include +#include +#include +#include + +const char *chroot_path = "/mnt/nfs/chroots/ff-build"; + +int main (int argc, char **argv) { + uid_t user = getuid (); + char *cwd = getcwd (NULL, 0); + if (chroot (chroot_path) != 0) { + perror ("chroot"); + return errno; + } + + if (seteuid (user) != 0) { + perror ("seteuid"); + return errno; + } + + if (chdir (cwd) != 0) { + perror ("chdir"); + chdir ("/"); + } + + free (cwd); + + execvp (argv [0], &argv [0]); + perror ("execvp"); + return errno; +} diff --git a/exec-in-chroot.conf b/exec-in-chroot.conf new file mode 100644 index 0000000..807c52e --- /dev/null +++ b/exec-in-chroot.conf @@ -0,0 +1,5 @@ +# invoked_name chroot_path binary +inv1 /path/1 bin1 +inv2 /path/2 +inv3 +inv4 /path/3 bin2