/* * setup() * performs all ONE TIME setup for this test */ void setup(void) { struct passwd *passwd_p; tst_require_root(NULL); tst_sig(NOFORK, DEF_HANDLER, cleanup); if ((passwd_p = getpwnam("root")) == NULL) { tst_brkm(TBROK, NULL, "getpwnam() failed for root"); } root = *passwd_p; GID16_CHECK((root_gid = root.pw_gid), "setresgid", cleanup) if ((passwd_p = getpwnam("nobody")) == NULL) { tst_brkm(TBROK, NULL, "nobody user id doesn't exist"); } nobody = *passwd_p; GID16_CHECK((nobody_gid = nobody.pw_gid), "setresgid", cleanup) /* Pause if that option was specified * TEST_PAUSE contains the code to fork the test with the -c option. */ TEST_PAUSE; }
int main(int argc, char *argv[]) { int lc; char *msg; uid_t user_id; gid_t group_id; int i; if ((msg = parse_opts(argc, argv, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); setup(); /* set the expected errnos... */ TEST_EXP_ENOS(exp_enos); user_id = geteuid(); UID16_CHECK(user_id, lchown, cleanup); group_id = getegid(); GID16_CHECK(group_id, lchown, cleanup); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; for (i = 0; test_cases[i].desc != NULL; i++) { char *file_name = test_cases[i].pathname; char *test_desc = test_cases[i].desc; /* * Call lchown(2) to test different test conditions. * verify that it fails with -1 return value and * sets appropriate errno. */ TEST(LCHOWN(cleanup, file_name, user_id, group_id)); /* Check return code from lchown(2) */ if (TEST_RETURN == -1) { TEST_ERROR_LOG(TEST_ERRNO); if (TEST_ERRNO == test_cases[i].exp_errno) { tst_resm(TPASS, "lchown(2) fails, %s, errno:%d", test_desc, TEST_ERRNO); } else { tst_resm(TFAIL, "lchown(2) fails, %s, " "errno:%d, expected errno:%d", test_desc, TEST_ERRNO, test_cases[i].exp_errno); } } else { tst_resm(TFAIL, "lchown(2) returned %ld, " "expected -1, errno:%d", TEST_RETURN, test_cases[i].exp_errno); } } } cleanup(); tst_exit(); }
static void setup(void) { tst_sig(NOFORK, DEF_HANDLER, cleanup); TEST_PAUSE; gid = getgid(); GID16_CHECK(gid, setgid, cleanup); }
static struct group get_group_by_gid(gid_t gid) { struct group *ret = getgrgid(gid); if (ret == NULL) tst_brkm(TBROK|TERRNO, NULL, "getgrgid(\"%d\") failed", gid); GID16_CHECK(ret->gr_gid, setregid, NULL); return *ret; }
static struct group get_group_by_name(const char *name) { struct group *ret = getgrnam(name); if (ret == NULL) tst_brkm(TBROK|TERRNO, NULL, "getgrnam(\"%s\") failed", name); GID16_CHECK(ret->gr_gid, setregid, NULL); return *ret; }
int main(int ac, char **av) { struct stat stat_buf; /* stat(2) struct contents */ int lc; const char *msg; uid_t user_id; /* Owner id of the test file. */ gid_t group_id; /* Group id of the test file. */ if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; UID16_CHECK((user_id = geteuid()), "chown", cleanup) GID16_CHECK((group_id = getegid()), "chown", cleanup) TEST(CHOWN(cleanup, TESTFILE, -1, group_id)); if (TEST_RETURN == -1) { tst_resm(TFAIL | TTERRNO, "chown(%s, ..) failed", TESTFILE); continue; } if (stat(TESTFILE, &stat_buf) == -1) tst_brkm(TFAIL | TERRNO, cleanup, "stat failed"); if (stat_buf.st_uid != user_id || stat_buf.st_gid != group_id) tst_resm(TFAIL, "%s: Incorrect ownership" "set to %d %d, Expected %d %d", TESTFILE, stat_buf.st_uid, stat_buf.st_gid, user_id, group_id); if (stat_buf.st_mode != (NEW_PERMS & ~(S_ISUID | S_ISGID))) tst_resm(TFAIL, "%s: incorrect mode permissions" " %#o, Expected %#o", TESTFILE, stat_buf.st_mode, NEW_PERMS & ~(S_ISUID | S_ISGID)); else tst_resm(TPASS, "chown(%s, ..) was successful", TESTFILE); } cleanup(); tst_exit(); }
int main(int ac, char **av) { struct stat stat_buf; int lc; uid_t user_id; gid_t group_id; tst_parse_opts(ac, av, NULL, NULL); setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; user_id = geteuid(); GID16_CHECK((group_id = getegid()), "fchown", cleanup) TEST(FCHOWN(cleanup, fildes, -1, group_id)); if (TEST_RETURN == -1) { tst_resm(TFAIL, "fchown() on %s Fails, errno=%d", TESTFILE, TEST_ERRNO); continue; } SAFE_FSTAT(cleanup, fildes, &stat_buf); if ((stat_buf.st_uid != user_id) || (stat_buf.st_gid != group_id)) { tst_resm(TFAIL, "%s: Incorrect " "ownership set, Expected %d %d", TESTFILE, user_id, group_id); continue; } if (stat_buf.st_mode != FCHOWN_PERMS) { tst_resm(TFAIL, "%s: Incorrect mode permissions" " %#o, Expected %#o", TESTFILE, stat_buf.st_mode, FCHOWN_PERMS); } else { tst_resm(TPASS, "fchown() on %s succeeds: " "Setuid/gid bits cleared", TESTFILE); } } cleanup(); tst_exit(); }
int main(int ac, char **av) { int lc; const char *msg; uid_t euid; struct passwd *pwent; if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; TEST(GETEGID(cleanup)); if (TEST_RETURN < 0) { tst_brkm(TBROK, cleanup, "This should never happen"); } if (STD_FUNCTIONAL_TEST) { euid = geteuid(); pwent = getpwuid(euid); if (pwent == NULL) tst_brkm(TBROK, cleanup, "geteuid() returned " "unexpected value %d", euid); GID16_CHECK(pwent->pw_gid, getegid, cleanup); if (pwent->pw_gid != TEST_RETURN) { tst_resm(TFAIL, "getegid() return value" " %ld unexpected - expected %d", TEST_RETURN, pwent->pw_gid); } else { tst_resm(TPASS, "effective group id %ld " "is correct", TEST_RETURN); } } else { tst_resm(TPASS, "call succeeded"); } } cleanup(); tst_exit(); }
static void setup(void) { tst_sig(NOFORK, DEF_HANDLER, cleanup); TEST_PAUSE; tst_tmpdir(); UID16_CHECK((uid = geteuid()), "chown", cleanup) GID16_CHECK((gid = getegid()), "chown", cleanup) sprintf(fname, "t_%d", getpid()); SAFE_FILE_PRINTF(cleanup, fname, "davef"); }
int main(int ac, char **av) { int lc; char *msg; gid_t gid; if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; gid = getegid(); GID16_CHECK(gid, setfsgid, cleanup); TEST(SETFSGID(cleanup, gid)); if (TEST_RETURN == -1) { tst_resm(TFAIL | TTERRNO, "setfsgid() failed unexpectedly"); continue; } if (!STD_FUNCTIONAL_TEST) { tst_resm(TPASS, "setfsgid() succeeded"); continue; } if (TEST_RETURN != gid) { tst_resm(TFAIL, "setfsgid() returned %ld, expected %d", TEST_RETURN, gid); } else { tst_resm(TPASS, "setfsgid() returned expected value : %ld", TEST_RETURN); } } cleanup(); tst_exit(); }
int main(int ac, char **av) { struct passwd *getpwnam(), *rootpwent; int lc; const char *msg; if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); setup(); TEST_EXP_ENOS(exp_enos); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; if ((rootpwent = getpwnam(root)) == NULL) { tst_brkm(TBROK, cleanup, "getpwnam failed for user id " "%s", root); } GID16_CHECK(rootpwent->pw_gid, setgid, cleanup); TEST(SETGID(cleanup, rootpwent->pw_gid)); if (TEST_RETURN != -1) { tst_resm(TFAIL, "call succeeded unexpectedly"); continue; } TEST_ERROR_LOG(TEST_ERRNO); if (TEST_ERRNO != EPERM) { tst_resm(TFAIL, "setgid set invalid errno, expected: " "EPERM, got: %d\n", TEST_ERRNO); } else { tst_resm(TPASS, "setgid returned EPERM"); } } cleanup(); tst_exit(); }
int main(int ac, char **av) { int lc; const char *msg; uid_t uid; struct passwd *pwent; if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; TEST(GETGID(cleanup)); if (TEST_RETURN < 0) { tst_brkm(TBROK, cleanup, "This should never happen"); } uid = getuid(); pwent = getpwuid(uid); if (pwent == NULL) tst_brkm(TBROK, cleanup, "getuid() returned " "unexpected value %d", uid); GID16_CHECK(pwent->pw_gid, getgid, cleanup); if (pwent->pw_gid != TEST_RETURN) { tst_resm(TFAIL, "getgid() return value " "%ld unexpected - expected %d", TEST_RETURN, pwent->pw_gid); } else { tst_resm(TPASS, "values from getuid " "and getpwuid match"); } } cleanup(); tst_exit(); }
int main(int ac, char **av) { int lc; gid_t gid; tst_parse_opts(ac, av, NULL, NULL); setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; gid = 1; while (!getgrgid(gid)) gid++; GID16_CHECK(gid, setfsgid, cleanup); TEST(SETFSGID(cleanup, gid)); if (TEST_RETURN == -1) { tst_resm(TFAIL | TTERRNO, "setfsgid() failed unexpectedly"); continue; } if (TEST_RETURN == gid) { tst_resm(TFAIL, "setfsgid() returned %ld, expected anything but %d", TEST_RETURN, gid); } else { tst_resm(TPASS, "setfsgid() returned expected value : " "%ld", TEST_RETURN); } } cleanup(); tst_exit(); }
int main(int ac, char **av) { int lc; tst_parse_opts(ac, av, NULL, NULL); setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; /* * TEST CASE: * Dont change either real or effective gid */ gid = getgid(); GID16_CHECK(gid, setregid, NULL); egid = getegid(); GID16_CHECK(egid, setregid, NULL); TEST(SETREGID(NULL, -1, -1)); if (TEST_RETURN == -1) { tst_resm(TFAIL, "setregid - Dont change either real or effective gid failed, errno=%d : %s", TEST_ERRNO, strerror(TEST_ERRNO)); } else { tst_resm(TPASS, "setregid - Dont change either real or effective gid returned %ld", TEST_RETURN); } /* * TEST CASE: * change effective to effective gid */ TEST(SETREGID(NULL, -1, egid)); if (TEST_RETURN == -1) { tst_resm(TFAIL, "setregid - change effective to effective gid failed, errno=%d : %s", TEST_ERRNO, strerror(TEST_ERRNO)); } else { tst_resm(TPASS, "setregid - change effective to effective gid returned %ld", TEST_RETURN); } /* * TEST CASE: * change real to real gid */ TEST(SETREGID(NULL, gid, -1)); if (TEST_RETURN == -1) { tst_resm(TFAIL, "setregid - change real to real gid failed, errno=%d : %s", TEST_ERRNO, strerror(TEST_ERRNO)); } else { tst_resm(TPASS, "setregid - change real to real gid returned %ld", TEST_RETURN); } /* * TEST CASE: * change effective to real gid */ TEST(SETREGID(NULL, -1, gid)); if (TEST_RETURN == -1) { tst_resm(TFAIL, "setregid - change effective to real gid failed, errno=%d : %s", TEST_ERRNO, strerror(TEST_ERRNO)); } else { tst_resm(TPASS, "setregid - change effective to real gid returned %ld", TEST_RETURN); } /* * TEST CASE: * try to change real to current real */ TEST(SETREGID(NULL, gid, gid)); if (TEST_RETURN == -1) { tst_resm(TFAIL | TTERRNO, "setregid failed"); } else { tst_resm(TPASS, "setregid return %ld", TEST_RETURN); } } tst_exit(); }
int main(int ac, char **av) { int lc; const char *msg; if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; /* * TEST CASE: * Dont change either real or effective gid */ gid = getgid(); GID16_CHECK(gid, setregid, cleanup); egid = getegid(); GID16_CHECK(egid, setregid, cleanup); TEST(SETREGID(cleanup, -1, -1)); if (TEST_RETURN == -1) { TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TFAIL, "setregid - Dont change either real or effective gid failed, errno=%d : %s", TEST_ERRNO, strerror(TEST_ERRNO)); } else { if (STD_FUNCTIONAL_TEST) { tst_resm(TPASS, "setregid - Dont change either real or effective gid returned %ld", TEST_RETURN); } } /* * TEST CASE: * change effective to effective gid */ TEST(SETREGID(cleanup, -1, egid)); if (TEST_RETURN == -1) { TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TFAIL, "setregid - change effective to effective gid failed, errno=%d : %s", TEST_ERRNO, strerror(TEST_ERRNO)); } else { if (STD_FUNCTIONAL_TEST) { tst_resm(TPASS, "setregid - change effective to effective gid returned %ld", TEST_RETURN); } } /* * TEST CASE: * change real to real gid */ TEST(SETREGID(cleanup, gid, -1)); if (TEST_RETURN == -1) { TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TFAIL, "setregid - change real to real gid failed, errno=%d : %s", TEST_ERRNO, strerror(TEST_ERRNO)); } else { if (STD_FUNCTIONAL_TEST) { tst_resm(TPASS, "setregid - change real to real gid returned %ld", TEST_RETURN); } } /* * TEST CASE: * change effective to real gid */ TEST(SETREGID(cleanup, -1, gid)); if (TEST_RETURN == -1) { TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TFAIL, "setregid - change effective to real gid failed, errno=%d : %s", TEST_ERRNO, strerror(TEST_ERRNO)); } else { if (STD_FUNCTIONAL_TEST) { tst_resm(TPASS, "setregid - change effective to real gid returned %ld", TEST_RETURN); } } /* * TEST CASE: * try to change real to current real */ TEST(SETREGID(cleanup, gid, gid)); if (TEST_RETURN == -1) { TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TFAIL | TTERRNO, "setregid failed"); } else { if (STD_FUNCTIONAL_TEST) { tst_resm(TPASS, "setregid return %ld", TEST_RETURN); } } } cleanup(); tst_exit(); }