diff options
author | Jakub Hrozek <jhrozek@redhat.com> | 2011-10-05 17:52:06 +0200 |
---|---|---|
committer | Stephen Gallagher <sgallagh@redhat.com> | 2011-10-13 13:18:14 -0400 |
commit | fe9cea3352b919f81ead0de5487ed593325b2ef0 (patch) | |
tree | 0dd1028ffe56f5c5b22d63edcaf897a3a200007f /src/tests | |
parent | c2352a73f52f600d95966ebe0b0819649ba923fa (diff) | |
download | sssd-fe9cea3352b919f81ead0de5487ed593325b2ef0.tar.gz sssd-fe9cea3352b919f81ead0de5487ed593325b2ef0.tar.bz2 sssd-fe9cea3352b919f81ead0de5487ed593325b2ef0.zip |
Add option to follow symlinks to check_file()
Diffstat (limited to 'src/tests')
-rw-r--r-- | src/tests/check_and_open-tests.c | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/src/tests/check_and_open-tests.c b/src/tests/check_and_open-tests.c index 59879cc9..8e1bc988 100644 --- a/src/tests/check_and_open-tests.c +++ b/src/tests/check_and_open-tests.c @@ -100,7 +100,7 @@ START_TEST(test_symlink) ret = symlink(filename, newpath); fail_unless(ret == 0, "symlink failed [%d][%s]", ret, strerror(errno)); - ret = check_file(newpath, uid, gid, mode, CHECK_REG, NULL); + ret = check_file(newpath, uid, gid, mode, CHECK_REG, NULL, false); unlink(newpath); fail_unless(ret == EINVAL, @@ -108,6 +108,32 @@ START_TEST(test_symlink) } END_TEST +START_TEST(test_follow_symlink) +{ + int ret; + char *newpath; + size_t newpath_length; + + newpath_length = strlen(filename) + strlen(SUFFIX) + 1; + newpath = malloc((newpath_length) * sizeof(char)); + fail_unless(newpath != NULL, "malloc failed"); + + ret = snprintf(newpath, newpath_length, "%s%s", filename, SUFFIX); + fail_unless(ret == newpath_length - 1, + "snprintf failed: expected [%d] got [%d]", newpath_length -1, + ret); + + ret = symlink(filename, newpath); + fail_unless(ret == 0, "symlink failed [%d][%s]", ret, strerror(errno)); + + ret = check_file(newpath, uid, gid, mode, CHECK_REG, NULL, true); + unlink(newpath); + + fail_unless(ret == EOK, + "check_and_open_readonly failed on symlink with follow=true"); +} +END_TEST + START_TEST(test_not_regular_file) { int ret; @@ -196,6 +222,7 @@ Suite *check_and_open_suite (void) tcase_add_test (tc_check_and_open_readonly, test_wrong_filename); tcase_add_test (tc_check_and_open_readonly, test_not_regular_file); tcase_add_test (tc_check_and_open_readonly, test_symlink); + tcase_add_test (tc_check_and_open_readonly, test_follow_symlink); tcase_add_test (tc_check_and_open_readonly, test_wrong_uid); tcase_add_test (tc_check_and_open_readonly, test_wrong_gid); tcase_add_test (tc_check_and_open_readonly, test_wrong_permission); |