Skip to content

Commit

Permalink
Let caller of fileop_chown check for !slave_unprivileged
Browse files Browse the repository at this point in the history
  • Loading branch information
donald committed Sep 10, 2022
1 parent f5664d0 commit 7532145
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions cmirror.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,6 @@ static void fileop_mknod(char *path, char type, dev_t rdev) {
}

static void fileop_chown(uid_t uid, gid_t gid, char *path) {
if (slave_unprivileged)
return;
if (fileop_debug)
warn("fileop: chown %d:%d %s\n", uid, gid, path);
if (fileop_noop)
Expand Down Expand Up @@ -465,8 +463,8 @@ static void fileop_ln_or_cp(char *from, char *to) {
}

static void check_perm(FileInfo *is, FileInfo *want) {
if (is->uid != want->uid || is->gid != want ->gid ){
if (!quiet && !slave_unprivileged)
if (!slave_unprivileged && (is->uid != want->uid || is->gid != want->gid) ) {
if (!quiet)
warn("chown %d:%d %s\n", want->uid, want->gid, is->name);
fileop_chown(want->uid, want->gid, is->name);
}
Expand All @@ -481,7 +479,8 @@ static void make_dir(char *path, mode_t perm, uid_t uid, gid_t gid) {
if (!quiet)
warn("mkdir %s owner %d:%d mode 0%03o\n", path, uid, gid, perm);
fileop_mkdir(path);
fileop_chown(uid, gid, path);
if (!slave_unprivileged)
fileop_chown(uid, gid, path);
fileop_chmod(perm, path);
}

Expand Down Expand Up @@ -868,7 +867,8 @@ static void slave(char *slave_path) {
if (!quiet)
warn("mknod %s P\n", filename);
fileop_mknod(filename, fi_want->type, 0);
fileop_chown(fi_want->uid, fi_want->gid, filename);
if (!slave_unprivileged)
fileop_chown(fi_want->uid, fi_want->gid, filename);
fileop_chmod(fi_want->perm, filename);
}
} else if (fi_want->type== 'S') {
Expand All @@ -880,7 +880,8 @@ static void slave(char *slave_path) {
if (!quiet)
warn("mknod %s %c\n", filename, fi_want->type);
fileop_mknod(filename, fi_want->type, fi_want->rdev);
fileop_chown(fi_want->uid, fi_want->gid, filename);
if (!slave_unprivileged)
fileop_chown(fi_want->uid, fi_want->gid, filename);
fileop_chmod(fi_want->perm, filename);
} else {
check_perm(fi_is, fi_want);
Expand Down

0 comments on commit 7532145

Please sign in to comment.