diff options
Diffstat (limited to 'src/firejail/fs_home.c')
-rw-r--r-- | src/firejail/fs_home.c | 25 |
1 files changed, 8 insertions, 17 deletions
diff --git a/src/firejail/fs_home.c b/src/firejail/fs_home.c index d328d5f1c..75d69e021 100644 --- a/src/firejail/fs_home.c +++ b/src/firejail/fs_home.c | |||
@@ -43,9 +43,7 @@ static void skel(const char *homedir, uid_t u, gid_t g) { | |||
43 | if (stat(fname, &s) == 0) | 43 | if (stat(fname, &s) == 0) |
44 | return; | 44 | return; |
45 | if (stat("/etc/skel/.zshrc", &s) == 0) { | 45 | if (stat("/etc/skel/.zshrc", &s) == 0) { |
46 | if (copy_file("/etc/skel/.zshrc", fname) == 0) { | 46 | if (copy_file("/etc/skel/.zshrc", fname, u, g, 0644) == 0) { |
47 | if (chown(fname, u, g) == -1) | ||
48 | errExit("chown"); | ||
49 | fs_logger("clone /etc/skel/.zshrc"); | 47 | fs_logger("clone /etc/skel/.zshrc"); |
50 | } | 48 | } |
51 | } | 49 | } |
@@ -73,9 +71,7 @@ static void skel(const char *homedir, uid_t u, gid_t g) { | |||
73 | if (stat(fname, &s) == 0) | 71 | if (stat(fname, &s) == 0) |
74 | return; | 72 | return; |
75 | if (stat("/etc/skel/.cshrc", &s) == 0) { | 73 | if (stat("/etc/skel/.cshrc", &s) == 0) { |
76 | if (copy_file("/etc/skel/.cshrc", fname) == 0) { | 74 | if (copy_file("/etc/skel/.cshrc", fname, u, g, 0644) == 0) { |
77 | if (chown(fname, u, g) == -1) | ||
78 | errExit("chown"); | ||
79 | fs_logger("clone /etc/skel/.cshrc"); | 75 | fs_logger("clone /etc/skel/.cshrc"); |
80 | } | 76 | } |
81 | } | 77 | } |
@@ -104,10 +100,7 @@ static void skel(const char *homedir, uid_t u, gid_t g) { | |||
104 | if (stat(fname, &s) == 0) | 100 | if (stat(fname, &s) == 0) |
105 | return; | 101 | return; |
106 | if (stat("/etc/skel/.bashrc", &s) == 0) { | 102 | if (stat("/etc/skel/.bashrc", &s) == 0) { |
107 | if (copy_file("/etc/skel/.bashrc", fname) == 0) { | 103 | if (copy_file("/etc/skel/.bashrc", fname, u, g, 0644) == 0) { |
108 | /* coverity[toctou] */ | ||
109 | if (chown(fname, u, g) == -1) | ||
110 | errExit("chown"); | ||
111 | fs_logger("clone /etc/skel/.bashrc"); | 104 | fs_logger("clone /etc/skel/.bashrc"); |
112 | } | 105 | } |
113 | } | 106 | } |
@@ -131,7 +124,7 @@ static int store_xauthority(void) { | |||
131 | exit(1); | 124 | exit(1); |
132 | } | 125 | } |
133 | 126 | ||
134 | int rv = copy_file(src, dest); | 127 | int rv = copy_file(src, dest, -1, -1, 0600); |
135 | if (rv) { | 128 | if (rv) { |
136 | fprintf(stderr, "Warning: cannot transfer .Xauthority in private home directory\n"); | 129 | fprintf(stderr, "Warning: cannot transfer .Xauthority in private home directory\n"); |
137 | return 0; | 130 | return 0; |
@@ -167,7 +160,7 @@ static int store_asoundrc(void) { | |||
167 | free(rp); | 160 | free(rp); |
168 | } | 161 | } |
169 | 162 | ||
170 | int rv = copy_file(src, dest); | 163 | int rv = copy_file(src, dest, -1, -1, -0644); |
171 | if (rv) { | 164 | if (rv) { |
172 | fprintf(stderr, "Warning: cannot transfer .asoundrc in private home directory\n"); | 165 | fprintf(stderr, "Warning: cannot transfer .asoundrc in private home directory\n"); |
173 | return 0; | 166 | return 0; |
@@ -184,7 +177,7 @@ static void copy_xauthority(void) { | |||
184 | char *dest; | 177 | char *dest; |
185 | if (asprintf(&dest, "%s/.Xauthority", cfg.homedir) == -1) | 178 | if (asprintf(&dest, "%s/.Xauthority", cfg.homedir) == -1) |
186 | errExit("asprintf"); | 179 | errExit("asprintf"); |
187 | int rv = copy_file(src, dest); | 180 | int rv = copy_file(src, dest, -1, -1, 0600); |
188 | if (rv) | 181 | if (rv) |
189 | fprintf(stderr, "Warning: cannot transfer .Xauthority in private home directory\n"); | 182 | fprintf(stderr, "Warning: cannot transfer .Xauthority in private home directory\n"); |
190 | else { | 183 | else { |
@@ -207,7 +200,7 @@ static void copy_asoundrc(void) { | |||
207 | char *dest; | 200 | char *dest; |
208 | if (asprintf(&dest, "%s/.asoundrc", cfg.homedir) == -1) | 201 | if (asprintf(&dest, "%s/.asoundrc", cfg.homedir) == -1) |
209 | errExit("asprintf"); | 202 | errExit("asprintf"); |
210 | int rv = copy_file(src, dest); | 203 | int rv = copy_file(src, dest, -1 , -1, 0644); |
211 | if (rv) | 204 | if (rv) |
212 | fprintf(stderr, "Warning: cannot transfer .asoundrc in private home directory\n"); | 205 | fprintf(stderr, "Warning: cannot transfer .asoundrc in private home directory\n"); |
213 | else { | 206 | else { |
@@ -360,11 +353,9 @@ int fs_copydir(const char *path, const struct stat *st, int ftype, struct FTW *s | |||
360 | return(0); | 353 | return(0); |
361 | if (stat(path, &s) == 0) { | 354 | if (stat(path, &s) == 0) { |
362 | if(ftype == FTW_F) { | 355 | if(ftype == FTW_F) { |
363 | if (copy_file(path, dest) == 0) { | 356 | if (copy_file(path, dest, u, g, 0644) == 0) { |
364 | if (arg_debug) | 357 | if (arg_debug) |
365 | printf("copy from %s to %s\n", path, dest); | 358 | printf("copy from %s to %s\n", path, dest); |
366 | if (chown(dest, u, g) == -1) | ||
367 | errExit("chown"); | ||
368 | fs_logger2("clone", path); | 359 | fs_logger2("clone", path); |
369 | } | 360 | } |
370 | } | 361 | } |