aboutsummaryrefslogtreecommitdiffstats
path: root/src/firecfg/main.c
diff options
context:
space:
mode:
authorLibravatar smitsohu <smitsohu@gmail.com>2018-11-27 17:41:35 +0100
committerLibravatar smitsohu <smitsohu@gmail.com>2018-11-27 17:41:35 +0100
commit1738719c3ef519821f020dfe0e0bbbcd2baf9e8c (patch)
tree85716565a35bd90a6bbdc6cabdf13b4a2847f4ec /src/firecfg/main.c
parentman page typo (diff)
downloadfirejail-1738719c3ef519821f020dfe0e0bbbcd2baf9e8c.tar.gz
firejail-1738719c3ef519821f020dfe0e0bbbcd2baf9e8c.tar.zst
firejail-1738719c3ef519821f020dfe0e0bbbcd2baf9e8c.zip
firecfg: small tweaks, fixes, man page update
Diffstat (limited to 'src/firecfg/main.c')
-rw-r--r--src/firecfg/main.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/firecfg/main.c b/src/firecfg/main.c
index 84f6a5f77..96ae37bd0 100644
--- a/src/firecfg/main.c
+++ b/src/firecfg/main.c
@@ -66,6 +66,7 @@ static void usage(void) {
66static void list(void) { 66static void list(void) {
67 DIR *dir = opendir(arg_bindir); 67 DIR *dir = opendir(arg_bindir);
68 if (!dir) { 68 if (!dir) {
69 perror("opendir");
69 fprintf(stderr, "Error: cannot open %s directory\n", arg_bindir); 70 fprintf(stderr, "Error: cannot open %s directory\n", arg_bindir);
70 exit(1); 71 exit(1);
71 } 72 }
@@ -103,6 +104,7 @@ static void clean(void) {
103 104
104 DIR *dir = opendir(arg_bindir); 105 DIR *dir = opendir(arg_bindir);
105 if (!dir) { 106 if (!dir) {
107 perror("opendir");
106 fprintf(stderr, "Error: cannot open %s directory\n", arg_bindir); 108 fprintf(stderr, "Error: cannot open %s directory\n", arg_bindir);
107 exit(1); 109 exit(1);
108 } 110 }
@@ -182,6 +184,7 @@ static void set_links_firecfg(void) {
182 // parse /usr/lib/firejail/firecfg.cfg file 184 // parse /usr/lib/firejail/firecfg.cfg file
183 FILE *fp = fopen(cfgfile, "r"); 185 FILE *fp = fopen(cfgfile, "r");
184 if (!fp) { 186 if (!fp) {
187 perror("fopen");
185 fprintf(stderr, "Error: cannot open %s\n", cfgfile); 188 fprintf(stderr, "Error: cannot open %s\n", cfgfile);
186 exit(1); 189 exit(1);
187 } 190 }
@@ -247,7 +250,8 @@ static void set_links_homedir(const char *homedir) {
247 250
248 DIR *dir = opendir(dirname); 251 DIR *dir = opendir(dirname);
249 if (!dir) { 252 if (!dir) {
250 fprintf(stderr, "Error: cannot open ~/.config/firejail directory\n"); 253 perror("opendir");
254 fprintf(stderr, "Error: cannot open %s directory\n", dirname);
251 free(dirname); 255 free(dirname);
252 return; 256 return;
253 } 257 }
@@ -337,7 +341,12 @@ int main(int argc, char **argv) {
337 341
338 // exit if the directory does not exist, or if we don't have access to it 342 // exit if the directory does not exist, or if we don't have access to it
339 if (access(arg_bindir, R_OK | W_OK | X_OK)) { 343 if (access(arg_bindir, R_OK | W_OK | X_OK)) {
340 fprintf(stderr, "Error: directory %s not found\n", arg_bindir); 344 if (errno == EACCES)
345 fprintf(stderr, "Error: cannot access directory %s: full permissions required\n", arg_bindir);
346 else {
347 perror("access");
348 fprintf(stderr, "Error: cannot access directory %s\n", arg_bindir);
349 }
341 exit(1); 350 exit(1);
342 } 351 }
343 } 352 }
@@ -407,6 +416,7 @@ int main(int argc, char **argv) {
407 } 416 }
408 else if (bindir_set == 0) { 417 else if (bindir_set == 0) {
409 // create /usr/local directory if it doesn't exist (Solus distro) 418 // create /usr/local directory if it doesn't exist (Solus distro)
419 mode_t orig_umask = umask(022); // temporarily set the umask
410 struct stat s; 420 struct stat s;
411 if (stat("/usr/local", &s) != 0) { 421 if (stat("/usr/local", &s) != 0) {
412 printf("Creating /usr/local directory\n"); 422 printf("Creating /usr/local directory\n");
@@ -417,13 +427,14 @@ int main(int argc, char **argv) {
417 } 427 }
418 } 428 }
419 if (stat(arg_bindir, &s) != 0) { 429 if (stat(arg_bindir, &s) != 0) {
420 printf("Creating /usr/local directory\n"); 430 printf("Creating %s directory\n", arg_bindir);
421 int rv = mkdir(arg_bindir, 0755); 431 int rv = mkdir(arg_bindir, 0755);
422 if (rv != 0) { 432 if (rv != 0) {
423 fprintf(stderr, "Error: cannot create %s directory\n", arg_bindir); 433 fprintf(stderr, "Error: cannot create %s directory\n", arg_bindir);
424 return 1; 434 return 1;
425 } 435 }
426 } 436 }
437 umask(orig_umask);
427 } 438 }
428 439
429 // clear all symlinks 440 // clear all symlinks