aboutsummaryrefslogtreecommitdiffstats
path: root/src/firejail/fs_etc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/firejail/fs_etc.c')
-rw-r--r--src/firejail/fs_etc.c60
1 files changed, 32 insertions, 28 deletions
diff --git a/src/firejail/fs_etc.c b/src/firejail/fs_etc.c
index 1a44b1305..2ff36f5d2 100644
--- a/src/firejail/fs_etc.c
+++ b/src/firejail/fs_etc.c
@@ -129,40 +129,44 @@ void fs_private_etc_list(void) {
129 errExit("chmod"); 129 errExit("chmod");
130 fs_logger("tmpfs /etc"); 130 fs_logger("tmpfs /etc");
131 131
132 // copy the list of files in the new etc directory
133 // using a new child process without root privileges
134 fs_logger_print(); // save the current log 132 fs_logger_print(); // save the current log
135 pid_t child = fork();
136 if (child < 0)
137 errExit("fork");
138 if (child == 0) {
139 if (arg_debug)
140 printf("Copying files in the new etc directory:\n");
141 133
142 // elevate privileges - files in the new /etc directory belong to root
143 if (setreuid(0, 0) < 0)
144 errExit("setreuid");
145 if (setregid(0, 0) < 0)
146 errExit("setregid");
147
148 // copy the list of files in the new home directory
149 char *dlist = strdup(private_list);
150 if (!dlist)
151 errExit("strdup");
152
153 134
154 char *ptr = strtok(dlist, ","); 135 // copy the list of files in the new etc directory
155 duplicate(ptr); 136 // using a new child process without root privileges
137 if (*private_list != '\0') {
138 pid_t child = fork();
139 if (child < 0)
140 errExit("fork");
141 if (child == 0) {
142 if (arg_debug)
143 printf("Copying files in the new etc directory:\n");
156 144
157 while ((ptr = strtok(NULL, ",")) != NULL) 145 // elevate privileges - files in the new /etc directory belong to root
146 if (setreuid(0, 0) < 0)
147 errExit("setreuid");
148 if (setregid(0, 0) < 0)
149 errExit("setregid");
150
151 // copy the list of files in the new home directory
152 char *dlist = strdup(private_list);
153 if (!dlist)
154 errExit("strdup");
155
156
157 char *ptr = strtok(dlist, ",");
158 duplicate(ptr); 158 duplicate(ptr);
159 free(dlist); 159
160 fs_logger_print(); 160 while ((ptr = strtok(NULL, ",")) != NULL)
161 exit(0); 161 duplicate(ptr);
162 free(dlist);
163 fs_logger_print();
164 exit(0);
165 }
166 // wait for the child to finish
167 waitpid(child, NULL, 0);
162 } 168 }
163 // wait for the child to finish 169
164 waitpid(child, NULL, 0);
165
166 if (arg_debug) 170 if (arg_debug)
167 printf("Mount-bind %s on top of /etc\n", RUN_ETC_DIR); 171 printf("Mount-bind %s on top of /etc\n", RUN_ETC_DIR);
168 if (mount(RUN_ETC_DIR, "/etc", NULL, MS_BIND|MS_REC, NULL) < 0) 172 if (mount(RUN_ETC_DIR, "/etc", NULL, MS_BIND|MS_REC, NULL) < 0)