Skip to content

Commit

Permalink
copy_file_as_user function: drop not needed arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
smitsohu committed Jun 23, 2021
1 parent eb87b41 commit 8754896
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/firejail/firejail.h
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ void logargs(int argc, char **argv) ;
void logerr(const char *msg);
void set_nice(int inc);
int copy_file(const char *srcname, const char *destname, uid_t uid, gid_t gid, mode_t mode);
void copy_file_as_user(const char *srcname, const char *destname, uid_t uid, gid_t gid, mode_t mode);
void copy_file_as_user(const char *srcname, const char *destname, mode_t mode);
void copy_file_from_user_to_root(const char *srcname, const char *destname, uid_t uid, gid_t gid, mode_t mode);
void touch_file_as_user(const char *fname, mode_t mode);
int is_dir(const char *fname);
Expand Down
25 changes: 13 additions & 12 deletions src/firejail/fs_home.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#define O_PATH 010000000
#endif

static void skel(const char *homedir, uid_t u, gid_t g) {
static void skel(const char *homedir) {
char *fname;

// zsh
Expand All @@ -50,7 +50,7 @@ static void skel(const char *homedir, uid_t u, gid_t g) {
exit(1);
}
if (access("/etc/skel/.zshrc", R_OK) == 0) {
copy_file_as_user("/etc/skel/.zshrc", fname, u, g, 0644); // regular user
copy_file_as_user("/etc/skel/.zshrc", fname, 0644); // regular user
fs_logger("clone /etc/skel/.zshrc");
fs_logger2("clone", fname);
}
Expand All @@ -74,7 +74,7 @@ static void skel(const char *homedir, uid_t u, gid_t g) {
exit(1);
}
if (access("/etc/skel/.cshrc", R_OK) == 0) {
copy_file_as_user("/etc/skel/.cshrc", fname, u, g, 0644); // regular user
copy_file_as_user("/etc/skel/.cshrc", fname, 0644); // regular user
fs_logger("clone /etc/skel/.cshrc");
fs_logger2("clone", fname);
}
Expand All @@ -98,7 +98,7 @@ static void skel(const char *homedir, uid_t u, gid_t g) {
exit(1);
}
if (access("/etc/skel/.bashrc", R_OK) == 0) {
copy_file_as_user("/etc/skel/.bashrc", fname, u, g, 0644); // regular user
copy_file_as_user("/etc/skel/.bashrc", fname, 0644); // regular user
fs_logger("clone /etc/skel/.bashrc");
fs_logger2("clone", fname);
}
Expand Down Expand Up @@ -135,7 +135,7 @@ static int store_xauthority(void) {
else
errExit("fopen");

copy_file_as_user(src, dest, getuid(), getgid(), 0600); // regular user
copy_file_as_user(src, dest, 0600); // regular user
fs_logger2("clone", dest);
selinux_relabel_path(dest, src);
free(src);
Expand Down Expand Up @@ -183,7 +183,7 @@ static int store_asoundrc(void) {
else
errExit("fopen");

copy_file_as_user(src, dest, getuid(), getgid(), 0644); // regular user
copy_file_as_user(src, dest, 0644); // regular user
selinux_relabel_path(dest, src);
fs_logger2("clone", dest);
free(src);
Expand All @@ -207,7 +207,7 @@ static void copy_xauthority(void) {
exit(1);
}

copy_file_as_user(src, dest, getuid(), getgid(), S_IRUSR | S_IWUSR); // regular user
copy_file_as_user(src, dest, S_IRUSR | S_IWUSR); // regular user
selinux_relabel_path(dest, src);
fs_logger2("clone", dest);
free(dest);
Expand All @@ -229,7 +229,7 @@ static void copy_asoundrc(void) {
exit(1);
}

copy_file_as_user(src, dest, getuid(), getgid(), S_IRUSR | S_IWUSR); // regular user
copy_file_as_user(src, dest, S_IRUSR | S_IWUSR); // regular user
selinux_relabel_path(dest, src);
fs_logger2("clone", dest);
free(dest);
Expand All @@ -253,7 +253,7 @@ void fs_private_homedir(void) {
int aflag = store_asoundrc();

uid_t u = getuid();
gid_t g = getgid();
// gid_t g = getgid();

// mount bind private_homedir on top of homedir
if (arg_debug)
Expand Down Expand Up @@ -324,7 +324,7 @@ void fs_private_homedir(void) {
fs_logger("tmpfs /home");
}

skel(homedir, u, g);
skel(homedir);
if (xflag)
copy_xauthority();
if (aflag)
Expand All @@ -339,6 +339,7 @@ void fs_private_homedir(void) {
void fs_private(void) {
char *homedir = cfg.homedir;
assert(homedir);

uid_t u = getuid();
gid_t g = getgid();

Expand Down Expand Up @@ -388,7 +389,7 @@ void fs_private(void) {
selinux_relabel_path(homedir, homedir);
}

skel(homedir, u, g);
skel(homedir);
if (xflag)
copy_xauthority();
if (aflag)
Expand Down Expand Up @@ -619,7 +620,7 @@ void fs_private_home_list(void) {
fs_logger("tmpfs /home");
}

skel(homedir, uid, gid);
skel(homedir);
if (xflag)
copy_xauthority();
if (aflag)
Expand Down
6 changes: 3 additions & 3 deletions src/firejail/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,16 +370,16 @@ int copy_file(const char *srcname, const char *destname, uid_t uid, gid_t gid, m
}

// return -1 if error, 0 if no error
void copy_file_as_user(const char *srcname, const char *destname, uid_t uid, gid_t gid, mode_t mode) {
void copy_file_as_user(const char *srcname, const char *destname, mode_t mode) {
pid_t child = fork();
if (child < 0)
errExit("fork");
if (child == 0) {
// drop privileges
drop_privs(0);

// copy, set permissions and ownership
int rv = copy_file(srcname, destname, uid, gid, mode); // already a regular user
// copy, set permissions
int rv = copy_file(srcname, destname, -1, -1, mode); // already a regular user
if (rv)
fwarning("cannot copy %s\n", srcname);
#ifdef HAVE_GCOV
Expand Down

0 comments on commit 8754896

Please sign in to comment.