summaryrefslogtreecommitdiffstats
path: root/src/tests/check_and_open-tests.c
diff options
context:
space:
mode:
authorSimo Sorce <simo@redhat.com>2014-04-19 16:11:47 -0400
committerJakub Hrozek <jhrozek@redhat.com>2014-04-28 21:57:01 +0200
commit9a592ee3fc195f20732c6b1f90894a0be25ccc19 (patch)
tree320d37f03789f3d938a51dae0aaec82c9ad5f9a4 /src/tests/check_and_open-tests.c
parent8e09148b68a3fd8b06fcb746054f3cfa250b40f8 (diff)
downloadsssd-9a592ee3fc195f20732c6b1f90894a0be25ccc19.tar.gz
sssd-9a592ee3fc195f20732c6b1f90894a0be25ccc19.tar.xz
sssd-9a592ee3fc195f20732c6b1f90894a0be25ccc19.zip
util: Change file check fns to use a mode mask
Instead of using a custom way to chck file type, use the system provided macros and a mode mask to decide when we want to check. Additionally a mask also allows us to selectively check permissions. Related: https://bugzilla.redhat.com/1089098 Resolves: https://fedorahosted.org/sssd/ticket/2321 Signed-off-by: Simo Sorce <simo@redhat.com> Reviewed-by: Pavel Reichl <preichl@redhat.com>
Diffstat (limited to 'src/tests/check_and_open-tests.c')
-rw-r--r--src/tests/check_and_open-tests.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/src/tests/check_and_open-tests.c b/src/tests/check_and_open-tests.c
index 6ff40d0fa..8837acc29 100644
--- a/src/tests/check_and_open-tests.c
+++ b/src/tests/check_and_open-tests.c
@@ -79,7 +79,8 @@ START_TEST(test_wrong_filename)
{
int ret;
- ret = check_and_open_readonly("/bla/bla/bla", &fd, uid, gid, mode, CHECK_REG);
+ ret = check_and_open_readonly("/bla/bla/bla", &fd,
+ uid, gid, S_IFREG|mode, 0);
fail_unless(ret == ENOENT,
"check_and_open_readonly succeeded on non-existing file");
fail_unless(fd == -1, "check_and_open_readonly file descriptor not -1");
@@ -104,7 +105,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, false);
+ ret = check_file(newpath, uid, gid, S_IFREG|mode, 0, NULL, false);
unlink(newpath);
fail_unless(ret == EINVAL,
@@ -130,7 +131,7 @@ START_TEST(test_follow_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, true);
+ ret = check_file(newpath, uid, gid, S_IFREG|mode, 0, NULL, true);
unlink(newpath);
fail_unless(ret == EOK,
@@ -142,7 +143,7 @@ START_TEST(test_not_regular_file)
{
int ret;
- ret = check_and_open_readonly("/dev/null", &fd, uid, gid, mode, CHECK_REG);
+ ret = check_and_open_readonly("/dev/null", &fd, uid, gid, S_IFREG|mode, 0);
fail_unless(ret == EINVAL,
"check_and_open_readonly succeeded on non-regular file");
fail_unless(fd == -1, "check_and_open_readonly file descriptor not -1");
@@ -153,7 +154,7 @@ START_TEST(test_wrong_uid)
{
int ret;
- ret = check_and_open_readonly(filename, &fd, uid+1, gid, mode, CHECK_REG);
+ ret = check_and_open_readonly(filename, &fd, uid+1, gid, S_IFREG|mode, 0);
fail_unless(ret == EINVAL,
"check_and_open_readonly succeeded with wrong uid");
fail_unless(fd == -1, "check_and_open_readonly file descriptor not -1");
@@ -164,7 +165,7 @@ START_TEST(test_wrong_gid)
{
int ret;
- ret = check_and_open_readonly(filename, &fd, uid, gid+1, mode, CHECK_REG);
+ ret = check_and_open_readonly(filename, &fd, uid, gid+1, S_IFREG|mode, 0);
fail_unless(ret == EINVAL,
"check_and_open_readonly succeeded with wrong gid");
fail_unless(fd == -1, "check_and_open_readonly file descriptor not -1");
@@ -175,8 +176,8 @@ START_TEST(test_wrong_permission)
{
int ret;
- ret = check_and_open_readonly(filename, &fd, uid, gid, (mode|S_IWOTH),
- CHECK_REG);
+ ret = check_and_open_readonly(filename, &fd,
+ uid, gid, S_IFREG|mode|S_IWOTH, 0);
fail_unless(ret == EINVAL,
"check_and_open_readonly succeeded with wrong mode");
fail_unless(fd == -1, "check_and_open_readonly file descriptor not -1");
@@ -187,7 +188,7 @@ START_TEST(test_ok)
{
int ret;
- ret = check_and_open_readonly(filename, &fd, uid, gid, mode, CHECK_REG);
+ ret = check_and_open_readonly(filename, &fd, uid, gid, S_IFREG|mode, 0);
fail_unless(ret == EOK,
"check_and_open_readonly failed");
fail_unless(fd >= 0,
@@ -201,7 +202,7 @@ START_TEST(test_write)
ssize_t size;
errno_t my_errno;
- ret = check_and_open_readonly(filename, &fd, uid, gid, mode, CHECK_REG);
+ ret = check_and_open_readonly(filename, &fd, uid, gid, S_IFREG|mode, 0);
fail_unless(ret == EOK,
"check_and_open_readonly failed");
fail_unless(fd >= 0,