test_main: Add assertChown
This commit is contained in:
1 parent
d4d61f1694
commit
0de2f8ee8d
3 files changed
+22
-2
No files matched your search
@@ -142,7 +142,7 @@ DEFINE_TEST(test_write_disk_perms)
|
||||
* and we're on a system where group ownership is inherited.
|
||||
* (Because we're not allowed to SGID files with defaultgid().)
|
||||
*/
|
||||
assertEqualInt(0, chown(".", getuid(), getgid()));
|
||||
assertChown(".", getuid(), getgid());
|
||||
|
||||
/* Create an archive_write_disk object. */
|
||||
assert((a = archive_write_disk_new()) != NULL);
|
||||
@@ -208,7 +208,7 @@ DEFINE_TEST(test_write_disk_perms)
|
||||
if (getuid() == 0) {
|
||||
original_uid = getuid() + 1;
|
||||
try_to_change_uid = getuid();
|
||||
assertEqualInt(0, chown("dir_owner", original_uid, getgid()));
|
||||
assertChown("dir_owner", original_uid, getgid());
|
||||
} else {
|
||||
original_uid = getuid();
|
||||
try_to_change_uid = getuid() + 1;
|
||||
|
||||
@@ -163,6 +163,9 @@
|
||||
/* change file/directory permissions and errors if it fails */
|
||||
#define assertChmod(pathname, mode) \
|
||||
assertion_chmod(__FILE__, __LINE__, pathname, mode)
|
||||
/* change file/directory ownership and errors if it fails */
|
||||
#define assertChown(pathname, user, group) \
|
||||
assertion_chown(__FILE__, __LINE__, pathname, user, group)
|
||||
/* Assert two files have the same file flags */
|
||||
#define assertEqualFflags(patha, pathb) \
|
||||
assertion_compare_fflags(__FILE__, __LINE__, patha, pathb, 0)
|
||||
@@ -279,6 +282,7 @@ void failure(const char *fmt, ...) __LA_PRINTFLIKE(1, 2);
|
||||
int assertion_assert(const char *, int, int, const char *, void *);
|
||||
int assertion_chdir(const char *, int, const char *);
|
||||
int assertion_chmod(const char *, int, const char *, int);
|
||||
int assertion_chown(const char *, int, const char *, int, int);
|
||||
int assertion_compare_fflags(const char *, int, const char *, const char *,
|
||||
int);
|
||||
int assertion_empty_file(const char *, int, const char *);
|
||||
|
||||
@@ -632,6 +632,22 @@ assertion_chmod(const char *file, int line, const char *pathname, int mode)
|
||||
|
||||
}
|
||||
|
||||
/* change file/directory ownership and errors if it fails */
|
||||
int
|
||||
assertion_chown(const char *file, int line, const char *pathname, int user,
|
||||
int group)
|
||||
{
|
||||
assertion_count(file, line);
|
||||
#ifdef HAVE_CHOWN
|
||||
if (chown(pathname, (uid_t)user, (gid_t)group) == 0)
|
||||
return (1);
|
||||
#endif
|
||||
failure_start(file, line, "chown(\"%s\", %d, %d)", pathname,
|
||||
user, group);
|
||||
failure_finish(NULL);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Verify two integers are equal. */
|
||||
int
|
||||
assertion_equal_int(const char *file, int line,
|
||||
|
||||
Reference in new issue
Block a user