diff options
Diffstat (limited to 'src/firejail/fs_etc.c')
-rw-r--r-- | src/firejail/fs_etc.c | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/src/firejail/fs_etc.c b/src/firejail/fs_etc.c index 59700dd9b..b0835d50b 100644 --- a/src/firejail/fs_etc.c +++ b/src/firejail/fs_etc.c | |||
@@ -36,20 +36,20 @@ void fs_machineid(void) { | |||
36 | return; | 36 | return; |
37 | if (arg_debug) | 37 | if (arg_debug) |
38 | printf("Generating a new machine-id\n"); | 38 | printf("Generating a new machine-id\n"); |
39 | 39 | ||
40 | // init random number generator | 40 | // init random number generator |
41 | srand(time(NULL)); | 41 | srand(time(NULL)); |
42 | 42 | ||
43 | // generate random id | 43 | // generate random id |
44 | mid.u32[0] = rand(); | 44 | mid.u32[0] = rand(); |
45 | mid.u32[1] = rand(); | 45 | mid.u32[1] = rand(); |
46 | mid.u32[2] = rand(); | 46 | mid.u32[2] = rand(); |
47 | mid.u32[3] = rand(); | 47 | mid.u32[3] = rand(); |
48 | 48 | ||
49 | // UUID version 4 and DCE variant | 49 | // UUID version 4 and DCE variant |
50 | mid.u8[6] = (mid.u8[6] & 0x0F) | 0x40; | 50 | mid.u8[6] = (mid.u8[6] & 0x0F) | 0x40; |
51 | mid.u8[8] = (mid.u8[8] & 0x3F) | 0x80; | 51 | mid.u8[8] = (mid.u8[8] & 0x3F) | 0x80; |
52 | 52 | ||
53 | // write it in a file | 53 | // write it in a file |
54 | FILE *fp = fopen(RUN_MACHINEID, "w"); | 54 | FILE *fp = fopen(RUN_MACHINEID, "w"); |
55 | if (!fp) | 55 | if (!fp) |
@@ -58,7 +58,7 @@ void fs_machineid(void) { | |||
58 | fclose(fp); | 58 | fclose(fp); |
59 | if (set_perms(RUN_MACHINEID, 0, 0, 0444)) | 59 | if (set_perms(RUN_MACHINEID, 0, 0, 0444)) |
60 | errExit("set_perms"); | 60 | errExit("set_perms"); |
61 | 61 | ||
62 | 62 | ||
63 | struct stat s; | 63 | struct stat s; |
64 | if (stat("/etc/machine-id", &s) == 0) { | 64 | if (stat("/etc/machine-id", &s) == 0) { |
@@ -93,7 +93,7 @@ static int check_dir_or_file(const char *fname) { | |||
93 | if (S_ISDIR(s.st_mode) || S_ISREG(s.st_mode) || !is_link(fname)) | 93 | if (S_ISDIR(s.st_mode) || S_ISREG(s.st_mode) || !is_link(fname)) |
94 | return 1; // normal exit | 94 | return 1; // normal exit |
95 | 95 | ||
96 | errexit: | 96 | errexit: |
97 | fprintf(stderr, "Error: invalid file type, %s.\n", fname); | 97 | fprintf(stderr, "Error: invalid file type, %s.\n", fname); |
98 | exit(1); | 98 | exit(1); |
99 | } | 99 | } |
@@ -116,7 +116,7 @@ static void duplicate(const char *fname, const char *private_dir, const char *pr | |||
116 | 116 | ||
117 | if (arg_debug) | 117 | if (arg_debug) |
118 | printf("copying %s to private %s\n", src, private_dir); | 118 | printf("copying %s to private %s\n", src, private_dir); |
119 | 119 | ||
120 | struct stat s; | 120 | struct stat s; |
121 | if (stat(src, &s) == 0 && S_ISDIR(s.st_mode)) { | 121 | if (stat(src, &s) == 0 && S_ISDIR(s.st_mode)) { |
122 | // create the directory in RUN_ETC_DIR | 122 | // create the directory in RUN_ETC_DIR |
@@ -139,11 +139,11 @@ void fs_private_dir_list(const char *private_dir, const char *private_run_dir, c | |||
139 | assert(private_dir); | 139 | assert(private_dir); |
140 | assert(private_run_dir); | 140 | assert(private_run_dir); |
141 | assert(private_list); | 141 | assert(private_list); |
142 | 142 | ||
143 | // create /run/firejail/mnt/etc directory | 143 | // create /run/firejail/mnt/etc directory |
144 | mkdir_attr(private_run_dir, 0755, 0, 0); | 144 | mkdir_attr(private_run_dir, 0755, 0, 0); |
145 | fs_logger2("tmpfs", private_dir); | 145 | fs_logger2("tmpfs", private_dir); |
146 | 146 | ||
147 | fs_logger_print(); // save the current log | 147 | fs_logger_print(); // save the current log |
148 | 148 | ||
149 | 149 | ||
@@ -157,21 +157,20 @@ void fs_private_dir_list(const char *private_dir, const char *private_run_dir, c | |||
157 | char *dlist = strdup(private_list); | 157 | char *dlist = strdup(private_list); |
158 | if (!dlist) | 158 | if (!dlist) |
159 | errExit("strdup"); | 159 | errExit("strdup"); |
160 | 160 | ||
161 | 161 | ||
162 | char *ptr = strtok(dlist, ","); | 162 | char *ptr = strtok(dlist, ","); |
163 | duplicate(ptr, private_dir, private_run_dir); | 163 | duplicate(ptr, private_dir, private_run_dir); |
164 | 164 | ||
165 | while ((ptr = strtok(NULL, ",")) != NULL) | 165 | while ((ptr = strtok(NULL, ",")) != NULL) |
166 | duplicate(ptr, private_dir, private_run_dir); | 166 | duplicate(ptr, private_dir, private_run_dir); |
167 | free(dlist); | 167 | free(dlist); |
168 | fs_logger_print(); | 168 | fs_logger_print(); |
169 | } | 169 | } |
170 | 170 | ||
171 | if (arg_debug) | 171 | if (arg_debug) |
172 | printf("Mount-bind %s on top of %s\n", private_run_dir, private_dir); | 172 | printf("Mount-bind %s on top of %s\n", private_run_dir, private_dir); |
173 | if (mount(private_run_dir, private_dir, NULL, MS_BIND|MS_REC, NULL) < 0) | 173 | if (mount(private_run_dir, private_dir, NULL, MS_BIND|MS_REC, NULL) < 0) |
174 | errExit("mount bind"); | 174 | errExit("mount bind"); |
175 | fs_logger2("mount", private_dir); | 175 | fs_logger2("mount", private_dir); |
176 | } | 176 | } |
177 | |||