diff options
Diffstat (limited to 'src/firejail/main.c')
-rw-r--r-- | src/firejail/main.c | 57 |
1 files changed, 30 insertions, 27 deletions
diff --git a/src/firejail/main.c b/src/firejail/main.c index e0a149085..680ce5800 100644 --- a/src/firejail/main.c +++ b/src/firejail/main.c | |||
@@ -1485,8 +1485,33 @@ int main(int argc, char **argv) { | |||
1485 | if (!ppath) | 1485 | if (!ppath) |
1486 | errExit("strdup"); | 1486 | errExit("strdup"); |
1487 | 1487 | ||
1488 | profile_read(ppath); | 1488 | if (access(ppath, R_OK)) { |
1489 | custom_profile = 1; | 1489 | char *ptr = ppath; |
1490 | while (*ptr != '/' && *ptr != '.' && *ptr != '\0') | ||
1491 | ptr++; | ||
1492 | // profile path contains no / or . chars, | ||
1493 | // assume its a profile name | ||
1494 | if (*ptr != '\0') { | ||
1495 | fprintf(stderr, "Error: inaccessible profile file: %s\n", ppath); | ||
1496 | exit(1); | ||
1497 | } | ||
1498 | |||
1499 | // profile was not read in previously, try to see if | ||
1500 | // we were given a profile name. | ||
1501 | if (!profile_find_firejail(ppath, 1)) { | ||
1502 | // do not fall through to default profile, | ||
1503 | // because the user should be notified that | ||
1504 | // given profile arg could not be used. | ||
1505 | fprintf(stderr, "Error: no profile with name \"%s\" found.\n", ppath); | ||
1506 | exit(1); | ||
1507 | } | ||
1508 | else | ||
1509 | custom_profile = 1; | ||
1510 | } | ||
1511 | else { | ||
1512 | profile_read(ppath); | ||
1513 | custom_profile = 1; | ||
1514 | } | ||
1490 | free(ppath); | 1515 | free(ppath); |
1491 | } | 1516 | } |
1492 | else if (strcmp(argv[i], "--noprofile") == 0) { | 1517 | else if (strcmp(argv[i], "--noprofile") == 0) { |
@@ -2327,21 +2352,8 @@ int main(int argc, char **argv) { | |||
2327 | 2352 | ||
2328 | 2353 | ||
2329 | // load the profile | 2354 | // load the profile |
2330 | if (!arg_noprofile) { | 2355 | if (!arg_noprofile && !custom_profile) { |
2331 | if (!custom_profile) { | 2356 | custom_profile = profile_find_firejail(cfg.command_name, 1); |
2332 | // look for a profile in ~/.config/firejail directory | ||
2333 | char *usercfgdir; | ||
2334 | if (asprintf(&usercfgdir, "%s/.config/firejail", cfg.homedir) == -1) | ||
2335 | errExit("asprintf"); | ||
2336 | int rv = profile_find(cfg.command_name, usercfgdir); | ||
2337 | free(usercfgdir); | ||
2338 | custom_profile = rv; | ||
2339 | } | ||
2340 | if (!custom_profile) { | ||
2341 | // look for a user profile in /etc/firejail directory | ||
2342 | int rv = profile_find(cfg.command_name, SYSCONFDIR); | ||
2343 | custom_profile = rv; | ||
2344 | } | ||
2345 | } | 2357 | } |
2346 | 2358 | ||
2347 | // use default.profile as the default | 2359 | // use default.profile as the default |
@@ -2352,16 +2364,7 @@ int main(int argc, char **argv) { | |||
2352 | if (arg_debug) | 2364 | if (arg_debug) |
2353 | printf("Attempting to find %s.profile...\n", profile_name); | 2365 | printf("Attempting to find %s.profile...\n", profile_name); |
2354 | 2366 | ||
2355 | // look for the profile in ~/.config/firejail directory | 2367 | custom_profile = profile_find_firejail(profile_name, 1); |
2356 | char *usercfgdir; | ||
2357 | if (asprintf(&usercfgdir, "%s/.config/firejail", cfg.homedir) == -1) | ||
2358 | errExit("asprintf"); | ||
2359 | custom_profile = profile_find(profile_name, usercfgdir); | ||
2360 | free(usercfgdir); | ||
2361 | |||
2362 | if (!custom_profile) | ||
2363 | // look for the profile in /etc/firejail directory | ||
2364 | custom_profile = profile_find(profile_name, SYSCONFDIR); | ||
2365 | 2368 | ||
2366 | if (!custom_profile) { | 2369 | if (!custom_profile) { |
2367 | fprintf(stderr, "Error: no default.profile installed\n"); | 2370 | fprintf(stderr, "Error: no default.profile installed\n"); |