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 /src/util/disk.c | |
parent | ad47a1f332a5aa12d7b56e2b552fcdad65a90bbf (diff) | |
download | gnunet-fc8e308ea06aff671dc1d21e99e8b42bf5c2fda1.tar.gz gnunet-fc8e308ea06aff671dc1d21e99e8b42bf5c2fda1.zip |
Parameterized directory listing permission check
Diffstat (limited to 'src/util/disk.c')
-rw-r--r-- | src/util/disk.c | 28 |
1 files changed, 17 insertions, 11 deletions
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; |