diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/firejail/firejail.h | 2 | ||||
-rw-r--r-- | src/firejail/fs_home.c | 25 | ||||
-rw-r--r-- | src/firejail/util.c | 6 |
3 files changed, 17 insertions, 16 deletions
diff --git a/src/firejail/firejail.h b/src/firejail/firejail.h index c84965074..e579e061e 100644 --- a/src/firejail/firejail.h +++ b/src/firejail/firejail.h | |||
@@ -508,7 +508,7 @@ void logargs(int argc, char **argv) ; | |||
508 | void logerr(const char *msg); | 508 | void logerr(const char *msg); |
509 | void set_nice(int inc); | 509 | void set_nice(int inc); |
510 | int copy_file(const char *srcname, const char *destname, uid_t uid, gid_t gid, mode_t mode); | 510 | int copy_file(const char *srcname, const char *destname, uid_t uid, gid_t gid, mode_t mode); |
511 | void copy_file_as_user(const char *srcname, const char *destname, uid_t uid, gid_t gid, mode_t mode); | 511 | void copy_file_as_user(const char *srcname, const char *destname, mode_t mode); |
512 | void copy_file_from_user_to_root(const char *srcname, const char *destname, uid_t uid, gid_t gid, mode_t mode); | 512 | void copy_file_from_user_to_root(const char *srcname, const char *destname, uid_t uid, gid_t gid, mode_t mode); |
513 | void touch_file_as_user(const char *fname, mode_t mode); | 513 | void touch_file_as_user(const char *fname, mode_t mode); |
514 | int is_dir(const char *fname); | 514 | int is_dir(const char *fname); |
diff --git a/src/firejail/fs_home.c b/src/firejail/fs_home.c index eab952eb8..04f1a0898 100644 --- a/src/firejail/fs_home.c +++ b/src/firejail/fs_home.c | |||
@@ -34,7 +34,7 @@ | |||
34 | #define O_PATH 010000000 | 34 | #define O_PATH 010000000 |
35 | #endif | 35 | #endif |
36 | 36 | ||
37 | static void skel(const char *homedir, uid_t u, gid_t g) { | 37 | static void skel(const char *homedir) { |
38 | char *fname; | 38 | char *fname; |
39 | 39 | ||
40 | // zsh | 40 | // zsh |
@@ -50,7 +50,7 @@ static void skel(const char *homedir, uid_t u, gid_t g) { | |||
50 | exit(1); | 50 | exit(1); |
51 | } | 51 | } |
52 | if (access("/etc/skel/.zshrc", R_OK) == 0) { | 52 | if (access("/etc/skel/.zshrc", R_OK) == 0) { |
53 | copy_file_as_user("/etc/skel/.zshrc", fname, u, g, 0644); // regular user | 53 | copy_file_as_user("/etc/skel/.zshrc", fname, 0644); // regular user |
54 | fs_logger("clone /etc/skel/.zshrc"); | 54 | fs_logger("clone /etc/skel/.zshrc"); |
55 | fs_logger2("clone", fname); | 55 | fs_logger2("clone", fname); |
56 | } | 56 | } |
@@ -74,7 +74,7 @@ static void skel(const char *homedir, uid_t u, gid_t g) { | |||
74 | exit(1); | 74 | exit(1); |
75 | } | 75 | } |
76 | if (access("/etc/skel/.cshrc", R_OK) == 0) { | 76 | if (access("/etc/skel/.cshrc", R_OK) == 0) { |
77 | copy_file_as_user("/etc/skel/.cshrc", fname, u, g, 0644); // regular user | 77 | copy_file_as_user("/etc/skel/.cshrc", fname, 0644); // regular user |
78 | fs_logger("clone /etc/skel/.cshrc"); | 78 | fs_logger("clone /etc/skel/.cshrc"); |
79 | fs_logger2("clone", fname); | 79 | fs_logger2("clone", fname); |
80 | } | 80 | } |
@@ -98,7 +98,7 @@ static void skel(const char *homedir, uid_t u, gid_t g) { | |||
98 | exit(1); | 98 | exit(1); |
99 | } | 99 | } |
100 | if (access("/etc/skel/.bashrc", R_OK) == 0) { | 100 | if (access("/etc/skel/.bashrc", R_OK) == 0) { |
101 | copy_file_as_user("/etc/skel/.bashrc", fname, u, g, 0644); // regular user | 101 | copy_file_as_user("/etc/skel/.bashrc", fname, 0644); // regular user |
102 | fs_logger("clone /etc/skel/.bashrc"); | 102 | fs_logger("clone /etc/skel/.bashrc"); |
103 | fs_logger2("clone", fname); | 103 | fs_logger2("clone", fname); |
104 | } | 104 | } |
@@ -135,7 +135,7 @@ static int store_xauthority(void) { | |||
135 | else | 135 | else |
136 | errExit("fopen"); | 136 | errExit("fopen"); |
137 | 137 | ||
138 | copy_file_as_user(src, dest, getuid(), getgid(), 0600); // regular user | 138 | copy_file_as_user(src, dest, 0600); // regular user |
139 | fs_logger2("clone", dest); | 139 | fs_logger2("clone", dest); |
140 | selinux_relabel_path(dest, src); | 140 | selinux_relabel_path(dest, src); |
141 | free(src); | 141 | free(src); |
@@ -183,7 +183,7 @@ static int store_asoundrc(void) { | |||
183 | else | 183 | else |
184 | errExit("fopen"); | 184 | errExit("fopen"); |
185 | 185 | ||
186 | copy_file_as_user(src, dest, getuid(), getgid(), 0644); // regular user | 186 | copy_file_as_user(src, dest, 0644); // regular user |
187 | selinux_relabel_path(dest, src); | 187 | selinux_relabel_path(dest, src); |
188 | fs_logger2("clone", dest); | 188 | fs_logger2("clone", dest); |
189 | free(src); | 189 | free(src); |
@@ -207,7 +207,7 @@ static void copy_xauthority(void) { | |||
207 | exit(1); | 207 | exit(1); |
208 | } | 208 | } |
209 | 209 | ||
210 | copy_file_as_user(src, dest, getuid(), getgid(), S_IRUSR | S_IWUSR); // regular user | 210 | copy_file_as_user(src, dest, S_IRUSR | S_IWUSR); // regular user |
211 | selinux_relabel_path(dest, src); | 211 | selinux_relabel_path(dest, src); |
212 | fs_logger2("clone", dest); | 212 | fs_logger2("clone", dest); |
213 | free(dest); | 213 | free(dest); |
@@ -229,7 +229,7 @@ static void copy_asoundrc(void) { | |||
229 | exit(1); | 229 | exit(1); |
230 | } | 230 | } |
231 | 231 | ||
232 | copy_file_as_user(src, dest, getuid(), getgid(), S_IRUSR | S_IWUSR); // regular user | 232 | copy_file_as_user(src, dest, S_IRUSR | S_IWUSR); // regular user |
233 | selinux_relabel_path(dest, src); | 233 | selinux_relabel_path(dest, src); |
234 | fs_logger2("clone", dest); | 234 | fs_logger2("clone", dest); |
235 | free(dest); | 235 | free(dest); |
@@ -253,7 +253,7 @@ void fs_private_homedir(void) { | |||
253 | int aflag = store_asoundrc(); | 253 | int aflag = store_asoundrc(); |
254 | 254 | ||
255 | uid_t u = getuid(); | 255 | uid_t u = getuid(); |
256 | gid_t g = getgid(); | 256 | // gid_t g = getgid(); |
257 | 257 | ||
258 | // mount bind private_homedir on top of homedir | 258 | // mount bind private_homedir on top of homedir |
259 | if (arg_debug) | 259 | if (arg_debug) |
@@ -324,7 +324,7 @@ void fs_private_homedir(void) { | |||
324 | fs_logger("tmpfs /home"); | 324 | fs_logger("tmpfs /home"); |
325 | } | 325 | } |
326 | 326 | ||
327 | skel(homedir, u, g); | 327 | skel(homedir); |
328 | if (xflag) | 328 | if (xflag) |
329 | copy_xauthority(); | 329 | copy_xauthority(); |
330 | if (aflag) | 330 | if (aflag) |
@@ -339,6 +339,7 @@ void fs_private_homedir(void) { | |||
339 | void fs_private(void) { | 339 | void fs_private(void) { |
340 | char *homedir = cfg.homedir; | 340 | char *homedir = cfg.homedir; |
341 | assert(homedir); | 341 | assert(homedir); |
342 | |||
342 | uid_t u = getuid(); | 343 | uid_t u = getuid(); |
343 | gid_t g = getgid(); | 344 | gid_t g = getgid(); |
344 | 345 | ||
@@ -388,7 +389,7 @@ void fs_private(void) { | |||
388 | selinux_relabel_path(homedir, homedir); | 389 | selinux_relabel_path(homedir, homedir); |
389 | } | 390 | } |
390 | 391 | ||
391 | skel(homedir, u, g); | 392 | skel(homedir); |
392 | if (xflag) | 393 | if (xflag) |
393 | copy_xauthority(); | 394 | copy_xauthority(); |
394 | if (aflag) | 395 | if (aflag) |
@@ -619,7 +620,7 @@ void fs_private_home_list(void) { | |||
619 | fs_logger("tmpfs /home"); | 620 | fs_logger("tmpfs /home"); |
620 | } | 621 | } |
621 | 622 | ||
622 | skel(homedir, uid, gid); | 623 | skel(homedir); |
623 | if (xflag) | 624 | if (xflag) |
624 | copy_xauthority(); | 625 | copy_xauthority(); |
625 | if (aflag) | 626 | if (aflag) |
diff --git a/src/firejail/util.c b/src/firejail/util.c index 68b76b8e8..0921736f1 100644 --- a/src/firejail/util.c +++ b/src/firejail/util.c | |||
@@ -370,7 +370,7 @@ int copy_file(const char *srcname, const char *destname, uid_t uid, gid_t gid, m | |||
370 | } | 370 | } |
371 | 371 | ||
372 | // return -1 if error, 0 if no error | 372 | // return -1 if error, 0 if no error |
373 | void copy_file_as_user(const char *srcname, const char *destname, uid_t uid, gid_t gid, mode_t mode) { | 373 | void copy_file_as_user(const char *srcname, const char *destname, mode_t mode) { |
374 | pid_t child = fork(); | 374 | pid_t child = fork(); |
375 | if (child < 0) | 375 | if (child < 0) |
376 | errExit("fork"); | 376 | errExit("fork"); |
@@ -378,8 +378,8 @@ void copy_file_as_user(const char *srcname, const char *destname, uid_t uid, gid | |||
378 | // drop privileges | 378 | // drop privileges |
379 | drop_privs(0); | 379 | drop_privs(0); |
380 | 380 | ||
381 | // copy, set permissions and ownership | 381 | // copy, set permissions |
382 | int rv = copy_file(srcname, destname, uid, gid, mode); // already a regular user | 382 | int rv = copy_file(srcname, destname, -1, -1, mode); // already a regular user |
383 | if (rv) | 383 | if (rv) |
384 | fwarning("cannot copy %s\n", srcname); | 384 | fwarning("cannot copy %s\n", srcname); |
385 | #ifdef HAVE_GCOV | 385 | #ifdef HAVE_GCOV |