diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-11-07 16:56:55 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-11-07 16:56:55 +0000 |
commit | fc8e308ea06aff671dc1d21e99e8b42bf5c2fda1 (patch) | |
tree | d85027a39b401f7e1cd766a3f8d9f992393d0517 | |
parent | ad47a1f332a5aa12d7b56e2b552fcdad65a90bbf (diff) | |
download | gnunet-fc8e308ea06aff671dc1d21e99e8b42bf5c2fda1.tar.gz gnunet-fc8e308ea06aff671dc1d21e99e8b42bf5c2fda1.zip |
Parameterized directory listing permission check
-rw-r--r-- | src/chat/chat.c | 2 | ||||
-rw-r--r-- | src/fs/fs_api.c | 8 | ||||
-rw-r--r-- | src/fs/gnunet-auto-share.c | 2 | ||||
-rw-r--r-- | src/include/gnunet_disk_lib.h | 15 | ||||
-rw-r--r-- | src/mesh/gnunet-regex-profiler.c | 2 | ||||
-rw-r--r-- | src/regex/gnunet-regex-simulation-profiler.c | 2 | ||||
-rw-r--r-- | src/util/disk.c | 28 | ||||
-rw-r--r-- | src/util/test_disk.c | 2 |
8 files changed, 34 insertions, 27 deletions
diff --git a/src/chat/chat.c b/src/chat/chat.c index 26f8f2e38..b2078e563 100644 --- a/src/chat/chat.c +++ b/src/chat/chat.c | |||
@@ -473,7 +473,7 @@ init_private_key (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
473 | return NULL; | 473 | return NULL; |
474 | } | 474 | } |
475 | GNUNET_DISK_directory_create (home); | 475 | GNUNET_DISK_directory_create (home); |
476 | if (GNUNET_OK != GNUNET_DISK_directory_test (home)) | 476 | if (GNUNET_OK != GNUNET_DISK_directory_test (home, GNUNET_YES)) |
477 | { | 477 | { |
478 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 478 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
479 | _("Failed to access chat home directory `%s'\n"), home); | 479 | _("Failed to access chat home directory `%s'\n"), home); |
diff --git a/src/fs/fs_api.c b/src/fs/fs_api.c index 059c70ba6..f03cdb8e4 100644 --- a/src/fs/fs_api.c +++ b/src/fs/fs_api.c | |||
@@ -738,7 +738,7 @@ GNUNET_FS_remove_sync_dir_ (struct GNUNET_FS_Handle *h, const char *ext, | |||
738 | dn = get_serialization_file_name_in_dir (h, ext, uni, ""); | 738 | dn = get_serialization_file_name_in_dir (h, ext, uni, ""); |
739 | if (NULL == dn) | 739 | if (NULL == dn) |
740 | return; | 740 | return; |
741 | if ((GNUNET_OK == GNUNET_DISK_directory_test (dn)) && | 741 | if ((GNUNET_YES == GNUNET_DISK_directory_test (dn, GNUNET_YES)) && |
742 | (GNUNET_OK != GNUNET_DISK_directory_remove (dn))) | 742 | (GNUNET_OK != GNUNET_DISK_directory_remove (dn))) |
743 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "rmdir", dn); | 743 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "rmdir", dn); |
744 | GNUNET_free (dn); | 744 | GNUNET_free (dn); |
@@ -2700,7 +2700,7 @@ deserialize_download (struct GNUNET_FS_Handle *h, | |||
2700 | dn = get_download_sync_filename (dc, dc->serialization, ".dir"); | 2700 | dn = get_download_sync_filename (dc, dc->serialization, ".dir"); |
2701 | if (NULL != dn) | 2701 | if (NULL != dn) |
2702 | { | 2702 | { |
2703 | if (GNUNET_YES == GNUNET_DISK_directory_test (dn)) | 2703 | if (GNUNET_YES == GNUNET_DISK_directory_test (dn, GNUNET_YES)) |
2704 | GNUNET_DISK_directory_scan (dn, &deserialize_subdownload, dc); | 2704 | GNUNET_DISK_directory_scan (dn, &deserialize_subdownload, dc); |
2705 | GNUNET_free (dn); | 2705 | GNUNET_free (dn); |
2706 | } | 2706 | } |
@@ -2813,7 +2813,7 @@ deserialize_search (struct GNUNET_FS_Handle *h, | |||
2813 | sc->serialization, ""); | 2813 | sc->serialization, ""); |
2814 | if (NULL != dn) | 2814 | if (NULL != dn) |
2815 | { | 2815 | { |
2816 | if (GNUNET_YES == GNUNET_DISK_directory_test (dn)) | 2816 | if (GNUNET_YES == GNUNET_DISK_directory_test (dn, GNUNET_YES)) |
2817 | GNUNET_DISK_directory_scan (dn, &deserialize_search_result, sc); | 2817 | GNUNET_DISK_directory_scan (dn, &deserialize_search_result, sc); |
2818 | GNUNET_free (dn); | 2818 | GNUNET_free (dn); |
2819 | } | 2819 | } |
@@ -2940,7 +2940,7 @@ deserialization_master (const char *master_path, GNUNET_FileNameCallback proc, | |||
2940 | dn = get_serialization_file_name (h, master_path, ""); | 2940 | dn = get_serialization_file_name (h, master_path, ""); |
2941 | if (NULL == dn) | 2941 | if (NULL == dn) |
2942 | return; | 2942 | return; |
2943 | if (GNUNET_YES == GNUNET_DISK_directory_test (dn)) | 2943 | if (GNUNET_YES == GNUNET_DISK_directory_test (dn, GNUNET_YES)) |
2944 | GNUNET_DISK_directory_scan (dn, proc, h); | 2944 | GNUNET_DISK_directory_scan (dn, proc, h); |
2945 | GNUNET_free (dn); | 2945 | GNUNET_free (dn); |
2946 | } | 2946 | } |
diff --git a/src/fs/gnunet-auto-share.c b/src/fs/gnunet-auto-share.c index e0514bc8f..86cab5593 100644 --- a/src/fs/gnunet-auto-share.c +++ b/src/fs/gnunet-auto-share.c | |||
@@ -681,7 +681,7 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
681 | { | 681 | { |
682 | /* check arguments */ | 682 | /* check arguments */ |
683 | if ((args[0] == NULL) || (args[1] != NULL) || | 683 | if ((args[0] == NULL) || (args[1] != NULL) || |
684 | (GNUNET_YES != GNUNET_DISK_directory_test (args[0]))) | 684 | (GNUNET_YES != GNUNET_DISK_directory_test (args[0], GNUNET_YES))) |
685 | { | 685 | { |
686 | printf (_("You must specify one and only one directory name for automatic publication.\n")); | 686 | printf (_("You must specify one and only one directory name for automatic publication.\n")); |
687 | ret = -1; | 687 | ret = -1; |
diff --git a/src/include/gnunet_disk_lib.h b/src/include/gnunet_disk_lib.h index 91cc1587a..73736be31 100644 --- a/src/include/gnunet_disk_lib.h +++ b/src/include/gnunet_disk_lib.h | |||
@@ -663,17 +663,18 @@ GNUNET_DISK_directory_create_for_file (const char *filename); | |||
663 | 663 | ||
664 | 664 | ||
665 | /** | 665 | /** |
666 | * Test if "fil" is a directory that can be accessed. | 666 | * Test if "fil" is a directory and readable. Also check if the directory is |
667 | * Will not print an error message if the directory | 667 | * listable. Will not print an error message if the directory does not exist. |
668 | * does not exist. Will log errors if GNUNET_SYSERR is | 668 | * Will log errors if GNUNET_SYSERR is returned (i.e., a file exists with the |
669 | * returned. | 669 | * same name). |
670 | * | 670 | * |
671 | * @param fil filename to test | 671 | * @param fil filename to test |
672 | * @return GNUNET_YES if yes, GNUNET_NO if does not exist, GNUNET_SYSERR | 672 | * @param is_listable GNUNET_YES to additionally check if "fil" is listable |
673 | * on any error and if exists but not directory | 673 | * @return GNUNET_YES if yes, GNUNET_NO if not, GNUNET_SYSERR if it |
674 | * does not exist | ||
674 | */ | 675 | */ |
675 | int | 676 | int |
676 | GNUNET_DISK_directory_test (const char *fil); | 677 | GNUNET_DISK_directory_test (const char *fil, int is_listable); |
677 | 678 | ||
678 | 679 | ||
679 | /** | 680 | /** |
diff --git a/src/mesh/gnunet-regex-profiler.c b/src/mesh/gnunet-regex-profiler.c index 6b3566823..9e4f1b2f8 100644 --- a/src/mesh/gnunet-regex-profiler.c +++ b/src/mesh/gnunet-regex-profiler.c | |||
@@ -1711,7 +1711,7 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
1711 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, | 1711 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, |
1712 | "open", | 1712 | "open", |
1713 | data_filename); | 1713 | data_filename); |
1714 | if (GNUNET_YES != GNUNET_DISK_directory_test (args[1])) | 1714 | if (GNUNET_YES != GNUNET_DISK_directory_test (args[1], GNUNET_YES)) |
1715 | { | 1715 | { |
1716 | fprintf (stderr, _("Specified policies directory does not exist. Exiting.\n")); | 1716 | fprintf (stderr, _("Specified policies directory does not exist. Exiting.\n")); |
1717 | shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | 1717 | shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); |
diff --git a/src/regex/gnunet-regex-simulation-profiler.c b/src/regex/gnunet-regex-simulation-profiler.c index 74e88ea9f..4bb033ea6 100644 --- a/src/regex/gnunet-regex-simulation-profiler.c +++ b/src/regex/gnunet-regex-simulation-profiler.c | |||
@@ -499,7 +499,7 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
499 | result = GNUNET_SYSERR; | 499 | result = GNUNET_SYSERR; |
500 | return; | 500 | return; |
501 | } | 501 | } |
502 | if (GNUNET_YES != GNUNET_DISK_directory_test (args[0])) | 502 | if (GNUNET_YES != GNUNET_DISK_directory_test (args[0], GNUNET_YES)) |
503 | { | 503 | { |
504 | fprintf (stderr, _("Specified policies directory does not exist. Exiting.\n")); | 504 | fprintf (stderr, _("Specified policies directory does not exist. Exiting.\n")); |
505 | result = GNUNET_SYSERR; | 505 | result = GNUNET_SYSERR; |
diff --git a/src/util/disk.c b/src/util/disk.c index 82cc9ddab..ae9135b0c 100644 --- a/src/util/disk.c +++ b/src/util/disk.c | |||
@@ -584,17 +584,19 @@ GNUNET_DISK_get_blocks_available (const char *part) | |||
584 | 584 | ||
585 | 585 | ||
586 | /** | 586 | /** |
587 | * Test if "fil" is a directory. | 587 | * Test if "fil" is a directory and readable. Also check if the directory is |
588 | * Will not print an error message if the directory | 588 | * listable. Will not print an error message if the directory does not exist. |
589 | * does not exist. Will log errors if GNUNET_SYSERR is | 589 | * Will log errors if GNUNET_SYSERR is returned (i.e., a file exists with the |
590 | * returned (i.e., a file exists with the same name). | 590 | * same name). |
591 | * | 591 | * |
592 | * @param fil filename to test | 592 | * @param fil filename to test |
593 | * @return GNUNET_YES if yes, GNUNET_NO if not, GNUNET_SYSERR if it | 593 | * @param is_listable GNUNET_YES to additionally check if "fil" is listable; |
594 | * does not exist | 594 | * GNUNET_NO to disable this check |
595 | * @return GNUNET_YES if yes, GNUNET_NO if not; GNUNET_SYSERR if it | ||
596 | * does not exist | ||
595 | */ | 597 | */ |
596 | int | 598 | int |
597 | GNUNET_DISK_directory_test (const char *fil) | 599 | GNUNET_DISK_directory_test (const char *fil, int is_listable) |
598 | { | 600 | { |
599 | struct stat filestat; | 601 | struct stat filestat; |
600 | int ret; | 602 | int ret; |
@@ -611,7 +613,11 @@ GNUNET_DISK_directory_test (const char *fil) | |||
611 | } | 613 | } |
612 | if (!S_ISDIR (filestat.st_mode)) | 614 | if (!S_ISDIR (filestat.st_mode)) |
613 | return GNUNET_NO; | 615 | return GNUNET_NO; |
614 | if (ACCESS (fil, R_OK | X_OK) < 0) | 616 | if (GNUNET_YES == is_listable) |
617 | ret = ACCESS (fil, R_OK | X_OK); | ||
618 | else | ||
619 | ret = ACCESS (fil, R_OK); | ||
620 | if (ret < 0) | ||
615 | { | 621 | { |
616 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "access", fil); | 622 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "access", fil); |
617 | return GNUNET_SYSERR; | 623 | return GNUNET_SYSERR; |
@@ -716,7 +722,7 @@ GNUNET_DISK_directory_create (const char *dir) | |||
716 | if (DIR_SEPARATOR == rdir[pos2]) | 722 | if (DIR_SEPARATOR == rdir[pos2]) |
717 | { | 723 | { |
718 | rdir[pos2] = '\0'; | 724 | rdir[pos2] = '\0'; |
719 | ret = GNUNET_DISK_directory_test (rdir); | 725 | ret = GNUNET_DISK_directory_test (rdir, GNUNET_YES); |
720 | if (GNUNET_SYSERR == ret) | 726 | if (GNUNET_SYSERR == ret) |
721 | { | 727 | { |
722 | GNUNET_free (rdir); | 728 | GNUNET_free (rdir); |
@@ -740,7 +746,7 @@ GNUNET_DISK_directory_create (const char *dir) | |||
740 | if ((rdir[pos] == DIR_SEPARATOR) || (pos == len)) | 746 | if ((rdir[pos] == DIR_SEPARATOR) || (pos == len)) |
741 | { | 747 | { |
742 | rdir[pos] = '\0'; | 748 | rdir[pos] = '\0'; |
743 | ret = GNUNET_DISK_directory_test (rdir); | 749 | ret = GNUNET_DISK_directory_test (rdir, GNUNET_YES); |
744 | if (ret == GNUNET_SYSERR) | 750 | if (ret == GNUNET_SYSERR) |
745 | { | 751 | { |
746 | GNUNET_free (rdir); | 752 | GNUNET_free (rdir); |
@@ -1393,7 +1399,7 @@ GNUNET_DISK_directory_remove (const char *filename) | |||
1393 | /* EISDIR is not sufficient in all cases, e.g. | 1399 | /* EISDIR is not sufficient in all cases, e.g. |
1394 | * sticky /tmp directory may result in EPERM on BSD. | 1400 | * sticky /tmp directory may result in EPERM on BSD. |
1395 | * So we also explicitly check "isDirectory" */ | 1401 | * So we also explicitly check "isDirectory" */ |
1396 | (GNUNET_YES != GNUNET_DISK_directory_test (filename))) | 1402 | (GNUNET_YES != GNUNET_DISK_directory_test (filename, GNUNET_YES))) |
1397 | { | 1403 | { |
1398 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "rmdir", filename); | 1404 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "rmdir", filename); |
1399 | return GNUNET_SYSERR; | 1405 | return GNUNET_SYSERR; |
diff --git a/src/util/test_disk.c b/src/util/test_disk.c index 149cec0b2..804a870e5 100644 --- a/src/util/test_disk.c +++ b/src/util/test_disk.c | |||
@@ -250,7 +250,7 @@ testDirMani () | |||
250 | return 1; | 250 | return 1; |
251 | if (GNUNET_OK != GNUNET_DISK_directory_create ("test")) | 251 | if (GNUNET_OK != GNUNET_DISK_directory_create ("test")) |
252 | return 1; | 252 | return 1; |
253 | if (GNUNET_YES != GNUNET_DISK_directory_test ("test")) | 253 | if (GNUNET_YES != GNUNET_DISK_directory_test ("test", GNUNET_YES)) |
254 | return 1; | 254 | return 1; |
255 | if (GNUNET_OK != GNUNET_DISK_directory_remove ("test")) | 255 | if (GNUNET_OK != GNUNET_DISK_directory_remove ("test")) |
256 | return 1; | 256 | return 1; |