aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Rees <maxcrees@me.com> 2021-01-03 04:29:12 -0500
committerMax Rees <maxcrees@me.com> 2021-01-03 04:29:12 -0500
commit2cebe1786b82efe42561ac79bc0441efcdbe82ed (patch)
tree067d57b6195b8a17777416fe1d5e95874bc5036a
parenta089c57dc3227cf709a718053e14de5e204d4f45 (diff)
comproot: add -u/--unknown-is-real
Files that haven't been previously touched by comped children will appear to have their real owner/group instead of rewriting them to root. Same as the fakeroot option.
-rw-r--r--src/comproot.c8
-rw-r--r--src/comproot.h2
-rw-r--r--src/file.c4
3 files changed, 11 insertions, 3 deletions
diff --git a/src/comproot.c b/src/comproot.c
index 84284da..7bbe09e 100644
--- a/src/comproot.c
+++ b/src/comproot.c
@@ -18,7 +18,9 @@
#define ADVERTISEMENT "COMPROOT_STAGE2"
struct comproot comproot = {
+ .unknown_is_real = 0,
.verbose = 0,
+
.uid = -1,
.gid = -1,
};
@@ -246,6 +248,7 @@ static int stage1(char *argv[], int arg_offset) {
struct option options[] = {
{"help", no_argument, 0, 'h'},
+ {"unknown-is-real", no_argument, 0, 'u'},
{"verbose", no_argument, 0, 'v'},
{ 0, 0, 0, 0 },
};
@@ -265,11 +268,14 @@ int main(int argc, char *argv[]) {
int opt;
opterr = 0;
optind = 0;
- while ((opt = getopt_long(argc, argv, "+hv", options, 0)) != -1) {
+ while ((opt = getopt_long(argc, argv, "+huv", options, 0)) != -1) {
switch (opt) {
case 'h':
return usage(0);
break;
+ case 'u':
+ comproot.unknown_is_real = 1;
+ break;
case 'v':
comproot.verbose++;
break;
diff --git a/src/comproot.h b/src/comproot.h
index 73e5e5d..27c13fa 100644
--- a/src/comproot.h
+++ b/src/comproot.h
@@ -6,7 +6,9 @@
#include <seccomp.h>
struct comproot {
+ int unknown_is_real;
int verbose;
+
uid_t uid;
gid_t gid;
};
diff --git a/src/file.c b/src/file.c
index b53ff8a..e4c2a3f 100644
--- a/src/file.c
+++ b/src/file.c
@@ -60,9 +60,9 @@ static int upsert_path(struct stat *st, struct file **f, char *path, int follow)
(*f)->st_dev = st->st_dev;
(*f)->st_ino = st->st_ino;
- if (st->st_uid == comproot.uid)
+ if (st->st_uid == comproot.uid && !comproot.unknown_is_real)
st->st_uid = 0;
- if (st->st_gid == comproot.gid)
+ if (st->st_gid == comproot.gid && !comproot.unknown_is_real)
st->st_gid = 0;
(*f)->st_uid = st->st_uid;
(*f)->st_gid = st->st_gid;