diff options
-rw-r--r-- | lib/nss_wrapper/testsuite.c | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/lib/nss_wrapper/testsuite.c b/lib/nss_wrapper/testsuite.c index ea109ebcda..e4047cfd38 100644 --- a/lib/nss_wrapper/testsuite.c +++ b/lib/nss_wrapper/testsuite.c @@ -428,6 +428,41 @@ static bool test_nwrap_passwd_r(struct torture_context *tctx) return true; } +static bool test_nwrap_passwd_r_cross(struct torture_context *tctx) +{ + int i; + struct passwd *pwd, pwd1, pwd2, pwd3, pwd4; + size_t num_pwd; + + torture_assert(tctx, test_nwrap_enum_r_passwd(tctx, &pwd, &num_pwd), + "failed to enumerate passwd"); + + for (i=0; i < num_pwd; i++) { + torture_assert(tctx, test_nwrap_getpwnam_r(tctx, pwd[i].pw_name, &pwd1), + "failed to call getpwnam_r for enumerated user"); + torture_assert_passwd_equal(tctx, &pwd[i], &pwd1, + "getpwent_r and getpwnam_r gave different results"); + torture_assert(tctx, test_nwrap_getpwuid_r(tctx, pwd[i].pw_uid, &pwd2), + "failed to call getpwuid_r for enumerated user"); + torture_assert_passwd_equal(tctx, &pwd[i], &pwd2, + "getpwent_r and getpwuid_r gave different results"); + torture_assert_passwd_equal(tctx, &pwd1, &pwd2, + "getpwnam_r and getpwuid_r gave different results"); + torture_assert(tctx, test_nwrap_getpwnam(tctx, pwd[i].pw_name, &pwd3), + "failed to call getpwnam for enumerated user"); + torture_assert_passwd_equal(tctx, &pwd[i], &pwd3, + "getpwent_r and getpwnam gave different results"); + torture_assert(tctx, test_nwrap_getpwuid(tctx, pwd[i].pw_uid, &pwd4), + "failed to call getpwuid for enumerated user"); + torture_assert_passwd_equal(tctx, &pwd[i], &pwd4, + "getpwent_r and getpwuid gave different results"); + torture_assert_passwd_equal(tctx, &pwd3, &pwd4, + "getpwnam and getpwuid gave different results"); + } + + return true; +} + static bool test_nwrap_enum_group(struct torture_context *tctx, struct group **grp_array_p, size_t *num_grp_p) @@ -584,6 +619,41 @@ static bool test_nwrap_group_r(struct torture_context *tctx) return true; } +static bool test_nwrap_group_r_cross(struct torture_context *tctx) +{ + int i; + struct group *grp, grp1, grp2, grp3, grp4; + size_t num_grp; + + torture_assert(tctx, test_nwrap_enum_r_group(tctx, &grp, &num_grp), + "failed to enumerate group"); + + for (i=0; i < num_grp; i++) { + torture_assert(tctx, test_nwrap_getgrnam_r(tctx, grp[i].gr_name, &grp1), + "failed to call getgrnam_r for enumerated user"); + torture_assert_group_equal(tctx, &grp[i], &grp1, + "getgrent_r and getgrnam_r gave different results"); + torture_assert(tctx, test_nwrap_getgrgid_r(tctx, grp[i].gr_gid, &grp2), + "failed to call getgrgid_r for enumerated user"); + torture_assert_group_equal(tctx, &grp[i], &grp2, + "getgrent_r and getgrgid_r gave different results"); + torture_assert_group_equal(tctx, &grp1, &grp2, + "getgrnam_r and getgrgid_r gave different results"); + torture_assert(tctx, test_nwrap_getgrnam(tctx, grp[i].gr_name, &grp3), + "failed to call getgrnam for enumerated user"); + torture_assert_group_equal(tctx, &grp[i], &grp3, + "getgrent_r and getgrnam gave different results"); + torture_assert(tctx, test_nwrap_getgrgid(tctx, grp[i].gr_gid, &grp4), + "failed to call getgrgid for enumerated user"); + torture_assert_group_equal(tctx, &grp[i], &grp4, + "getgrent_r and getgrgid gave different results"); + torture_assert_group_equal(tctx, &grp3, &grp4, + "getgrnam and getgrgid gave different results"); + } + + return true; +} + static bool test_nwrap_getgrouplist(struct torture_context *tctx, const char *user, gid_t gid, @@ -759,6 +829,25 @@ static bool test_nwrap_reentrant_enumeration(struct torture_context *tctx) return true; } +static bool test_nwrap_reentrant_enumeration_crosschecks(struct torture_context *tctx) +{ + const char *old_pwd = getenv("NSS_WRAPPER_PASSWD"); + const char *old_group = getenv("NSS_WRAPPER_GROUP"); + + if (!old_pwd || !old_group) { + torture_skip(tctx, "nothing to test\n"); + return true; + } + + torture_comment(tctx, "Testing re-entrant calls with cross checks\n"); + + torture_assert(tctx, test_nwrap_passwd_r_cross(tctx), + "failed to test users"); + torture_assert(tctx, test_nwrap_group_r_cross(tctx), + "failed to test groups"); + + return true; +} struct torture_suite *torture_local_nss_wrapper(TALLOC_CTX *mem_ctx) { @@ -766,6 +855,7 @@ struct torture_suite *torture_local_nss_wrapper(TALLOC_CTX *mem_ctx) torture_suite_add_simple_test(suite, "enumeration", test_nwrap_enumeration); torture_suite_add_simple_test(suite, "reentrant enumeration", test_nwrap_reentrant_enumeration); + torture_suite_add_simple_test(suite, "reentrant enumeration crosschecks", test_nwrap_reentrant_enumeration_crosschecks); torture_suite_add_simple_test(suite, "membership", test_nwrap_membership); return suite; |