2 Unix SMB/CIFS implementation.
4 local testing of the nss wrapper
6 Copyright (C) Guenther Deschner 2009-2010
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
28 #include "torture/torture.h"
29 #include "torture/local/proto.h"
30 #include "lib/replace/system/passwd.h"
32 static bool copy_passwd(struct torture_context
*tctx
,
33 const struct passwd
*pwd
,
36 p
->pw_name
= talloc_strdup(tctx
, pwd
->pw_name
);
37 p
->pw_passwd
= talloc_strdup(tctx
, pwd
->pw_passwd
);
38 p
->pw_uid
= pwd
->pw_uid
;
39 p
->pw_gid
= pwd
->pw_gid
;
40 p
->pw_gecos
= talloc_strdup(tctx
, pwd
->pw_gecos
);
41 p
->pw_dir
= talloc_strdup(tctx
, pwd
->pw_dir
);
42 p
->pw_shell
= talloc_strdup(tctx
, pwd
->pw_shell
);
47 static void print_passwd(struct passwd
*pwd
)
49 printf("%s:%s:%lu:%lu:%s:%s:%s\n",
52 (unsigned long)pwd
->pw_uid
,
53 (unsigned long)pwd
->pw_gid
,
60 static bool test_nwrap_getpwnam(struct torture_context
*tctx
,
66 torture_comment(tctx
, "Testing getpwnam: %s\n", name
);
74 copy_passwd(tctx
, pwd
, pwd_p
);
77 return pwd
? true : false;
80 static bool test_nwrap_getpwnam_r(struct torture_context
*tctx
,
84 struct passwd pwd
, *pwdp
;
88 torture_comment(tctx
, "Testing getpwnam_r: %s\n", name
);
90 ret
= getpwnam_r(name
, &pwd
, buffer
, sizeof(buffer
), &pwdp
);
93 torture_comment(tctx
, "got %d return code\n", ret
);
101 copy_passwd(tctx
, &pwd
, pwd_p
);
107 static bool test_nwrap_getpwuid(struct torture_context
*tctx
,
109 struct passwd
*pwd_p
)
113 torture_comment(tctx
, "Testing getpwuid: %lu\n", (unsigned long)uid
);
121 copy_passwd(tctx
, pwd
, pwd_p
);
124 return pwd
? true : false;
127 static bool test_nwrap_getpwuid_r(struct torture_context
*tctx
,
129 struct passwd
*pwd_p
)
131 struct passwd pwd
, *pwdp
;
135 torture_comment(tctx
, "Testing getpwuid_r: %lu\n", (unsigned long)uid
);
137 ret
= getpwuid_r(uid
, &pwd
, buffer
, sizeof(buffer
), &pwdp
);
140 torture_comment(tctx
, "got %d return code\n", ret
);
148 copy_passwd(tctx
, &pwd
, pwd_p
);
155 static bool copy_group(struct torture_context
*tctx
,
156 const struct group
*grp
,
161 g
->gr_name
= talloc_strdup(tctx
, grp
->gr_name
);
162 g
->gr_passwd
= talloc_strdup(tctx
, grp
->gr_passwd
);
163 g
->gr_gid
= grp
->gr_gid
;
166 for (i
=0; grp
->gr_mem
&& grp
->gr_mem
[i
]; i
++) {
167 g
->gr_mem
= talloc_realloc(tctx
, g
->gr_mem
, char *, i
+ 2);
168 g
->gr_mem
[i
] = talloc_strdup(g
->gr_mem
, grp
->gr_mem
[i
]);
169 g
->gr_mem
[i
+1] = NULL
;
175 static void print_group(struct group
*grp
)
181 (unsigned long)grp
->gr_gid
);
183 if ((grp
->gr_mem
== NULL
) || !grp
->gr_mem
[0]) {
188 for (i
=0; grp
->gr_mem
[i
+1]; i
++) {
189 printf("%s,", grp
->gr_mem
[i
]);
191 printf("%s\n", grp
->gr_mem
[i
]);
194 static bool test_nwrap_getgrnam(struct torture_context
*tctx
,
200 torture_comment(tctx
, "Testing getgrnam: %s\n", name
);
202 grp
= getgrnam(name
);
208 copy_group(tctx
, grp
, grp_p
);
211 return grp
? true : false;
214 static bool test_nwrap_getgrnam_r(struct torture_context
*tctx
,
218 struct group grp
, *grpp
;
222 torture_comment(tctx
, "Testing getgrnam_r: %s\n", name
);
224 ret
= getgrnam_r(name
, &grp
, buffer
, sizeof(buffer
), &grpp
);
227 torture_comment(tctx
, "got %d return code\n", ret
);
235 copy_group(tctx
, &grp
, grp_p
);
242 static bool test_nwrap_getgrgid(struct torture_context
*tctx
,
248 torture_comment(tctx
, "Testing getgrgid: %lu\n", (unsigned long)gid
);
256 copy_group(tctx
, grp
, grp_p
);
259 return grp
? true : false;
262 static bool test_nwrap_getgrgid_r(struct torture_context
*tctx
,
266 struct group grp
, *grpp
;
270 torture_comment(tctx
, "Testing getgrgid_r: %lu\n", (unsigned long)gid
);
272 ret
= getgrgid_r(gid
, &grp
, buffer
, sizeof(buffer
), &grpp
);
275 torture_comment(tctx
, "got %d return code\n", ret
);
283 copy_group(tctx
, &grp
, grp_p
);
289 static bool test_nwrap_enum_passwd(struct torture_context
*tctx
,
290 struct passwd
**pwd_array_p
,
294 struct passwd
*pwd_array
= NULL
;
297 torture_comment(tctx
, "Testing setpwent\n");
300 while ((pwd
= getpwent()) != NULL
) {
301 torture_comment(tctx
, "Testing getpwent\n");
304 if (pwd_array_p
&& num_pwd_p
) {
305 pwd_array
= talloc_realloc(tctx
, pwd_array
, struct passwd
, num_pwd
+1);
306 torture_assert(tctx
, pwd_array
, "out of memory");
307 copy_passwd(tctx
, pwd
, &pwd_array
[num_pwd
]);
312 torture_comment(tctx
, "Testing endpwent\n");
316 *pwd_array_p
= pwd_array
;
319 *num_pwd_p
= num_pwd
;
325 static bool test_nwrap_enum_r_passwd(struct torture_context
*tctx
,
326 struct passwd
**pwd_array_p
,
329 struct passwd pwd
, *pwdp
;
330 struct passwd
*pwd_array
= NULL
;
335 torture_comment(tctx
, "Testing setpwent\n");
339 torture_comment(tctx
, "Testing getpwent_r\n");
341 ret
= getpwent_r(&pwd
, buffer
, sizeof(buffer
), &pwdp
);
344 torture_comment(tctx
, "got %d return code\n", ret
);
349 if (pwd_array_p
&& num_pwd_p
) {
350 pwd_array
= talloc_realloc(tctx
, pwd_array
, struct passwd
, num_pwd
+1);
351 torture_assert(tctx
, pwd_array
, "out of memory");
352 copy_passwd(tctx
, &pwd
, &pwd_array
[num_pwd
]);
357 torture_comment(tctx
, "Testing endpwent\n");
361 *pwd_array_p
= pwd_array
;
364 *num_pwd_p
= num_pwd
;
370 static bool torture_assert_passwd_equal(struct torture_context
*tctx
,
371 const struct passwd
*p1
,
372 const struct passwd
*p2
,
375 torture_assert_str_equal(tctx
, p1
->pw_name
, p2
->pw_name
, comment
);
376 torture_assert_str_equal(tctx
, p1
->pw_passwd
, p2
->pw_passwd
, comment
);
377 torture_assert_int_equal(tctx
, p1
->pw_uid
, p2
->pw_uid
, comment
);
378 torture_assert_int_equal(tctx
, p1
->pw_gid
, p2
->pw_gid
, comment
);
379 torture_assert_str_equal(tctx
, p1
->pw_gecos
, p2
->pw_gecos
, comment
);
380 torture_assert_str_equal(tctx
, p1
->pw_dir
, p2
->pw_dir
, comment
);
381 torture_assert_str_equal(tctx
, p1
->pw_shell
, p2
->pw_shell
, comment
);
386 static bool test_nwrap_passwd(struct torture_context
*tctx
)
389 struct passwd
*pwd
, pwd1
, pwd2
;
392 torture_assert(tctx
, test_nwrap_enum_passwd(tctx
, &pwd
, &num_pwd
),
393 "failed to enumerate passwd");
395 for (i
=0; i
< num_pwd
; i
++) {
396 torture_assert(tctx
, test_nwrap_getpwnam(tctx
, pwd
[i
].pw_name
, &pwd1
),
397 "failed to call getpwnam for enumerated user");
398 torture_assert_passwd_equal(tctx
, &pwd
[i
], &pwd1
,
399 "getpwent and getpwnam gave different results");
400 torture_assert(tctx
, test_nwrap_getpwuid(tctx
, pwd
[i
].pw_uid
, &pwd2
),
401 "failed to call getpwuid for enumerated user");
402 torture_assert_passwd_equal(tctx
, &pwd
[i
], &pwd2
,
403 "getpwent and getpwuid gave different results");
404 torture_assert_passwd_equal(tctx
, &pwd1
, &pwd2
,
405 "getpwnam and getpwuid gave different results");
411 static bool test_nwrap_passwd_r(struct torture_context
*tctx
)
414 struct passwd
*pwd
, pwd1
, pwd2
;
417 torture_assert(tctx
, test_nwrap_enum_r_passwd(tctx
, &pwd
, &num_pwd
),
418 "failed to enumerate passwd");
420 for (i
=0; i
< num_pwd
; i
++) {
421 torture_assert(tctx
, test_nwrap_getpwnam_r(tctx
, pwd
[i
].pw_name
, &pwd1
),
422 "failed to call getpwnam_r for enumerated user");
423 torture_assert_passwd_equal(tctx
, &pwd
[i
], &pwd1
,
424 "getpwent_r and getpwnam_r gave different results");
425 torture_assert(tctx
, test_nwrap_getpwuid_r(tctx
, pwd
[i
].pw_uid
, &pwd2
),
426 "failed to call getpwuid_r for enumerated user");
427 torture_assert_passwd_equal(tctx
, &pwd
[i
], &pwd2
,
428 "getpwent_r and getpwuid_r gave different results");
429 torture_assert_passwd_equal(tctx
, &pwd1
, &pwd2
,
430 "getpwnam_r and getpwuid_r gave different results");
436 static bool test_nwrap_passwd_r_cross(struct torture_context
*tctx
)
439 struct passwd
*pwd
, pwd1
, pwd2
, pwd3
, pwd4
;
442 torture_assert(tctx
, test_nwrap_enum_r_passwd(tctx
, &pwd
, &num_pwd
),
443 "failed to enumerate passwd");
445 for (i
=0; i
< num_pwd
; i
++) {
446 torture_assert(tctx
, test_nwrap_getpwnam_r(tctx
, pwd
[i
].pw_name
, &pwd1
),
447 "failed to call getpwnam_r for enumerated user");
448 torture_assert_passwd_equal(tctx
, &pwd
[i
], &pwd1
,
449 "getpwent_r and getpwnam_r gave different results");
450 torture_assert(tctx
, test_nwrap_getpwuid_r(tctx
, pwd
[i
].pw_uid
, &pwd2
),
451 "failed to call getpwuid_r for enumerated user");
452 torture_assert_passwd_equal(tctx
, &pwd
[i
], &pwd2
,
453 "getpwent_r and getpwuid_r gave different results");
454 torture_assert_passwd_equal(tctx
, &pwd1
, &pwd2
,
455 "getpwnam_r and getpwuid_r gave different results");
456 torture_assert(tctx
, test_nwrap_getpwnam(tctx
, pwd
[i
].pw_name
, &pwd3
),
457 "failed to call getpwnam for enumerated user");
458 torture_assert_passwd_equal(tctx
, &pwd
[i
], &pwd3
,
459 "getpwent_r and getpwnam gave different results");
460 torture_assert(tctx
, test_nwrap_getpwuid(tctx
, pwd
[i
].pw_uid
, &pwd4
),
461 "failed to call getpwuid for enumerated user");
462 torture_assert_passwd_equal(tctx
, &pwd
[i
], &pwd4
,
463 "getpwent_r and getpwuid gave different results");
464 torture_assert_passwd_equal(tctx
, &pwd3
, &pwd4
,
465 "getpwnam and getpwuid gave different results");
471 static bool test_nwrap_enum_group(struct torture_context
*tctx
,
472 struct group
**grp_array_p
,
476 struct group
*grp_array
= NULL
;
479 torture_comment(tctx
, "Testing setgrent\n");
482 while ((grp
= getgrent()) != NULL
) {
483 torture_comment(tctx
, "Testing getgrent\n");
486 if (grp_array_p
&& num_grp_p
) {
487 grp_array
= talloc_realloc(tctx
, grp_array
, struct group
, num_grp
+1);
488 torture_assert(tctx
, grp_array
, "out of memory");
489 copy_group(tctx
, grp
, &grp_array
[num_grp
]);
494 torture_comment(tctx
, "Testing endgrent\n");
498 *grp_array_p
= grp_array
;
501 *num_grp_p
= num_grp
;
507 static bool test_nwrap_enum_r_group(struct torture_context
*tctx
,
508 struct group
**grp_array_p
,
511 struct group grp
, *grpp
;
512 struct group
*grp_array
= NULL
;
517 torture_comment(tctx
, "Testing setgrent\n");
521 torture_comment(tctx
, "Testing getgrent_r\n");
523 ret
= getgrent_r(&grp
, buffer
, sizeof(buffer
), &grpp
);
526 torture_comment(tctx
, "got %d return code\n", ret
);
531 if (grp_array_p
&& num_grp_p
) {
532 grp_array
= talloc_realloc(tctx
, grp_array
, struct group
, num_grp
+1);
533 torture_assert(tctx
, grp_array
, "out of memory");
534 copy_group(tctx
, &grp
, &grp_array
[num_grp
]);
539 torture_comment(tctx
, "Testing endgrent\n");
543 *grp_array_p
= grp_array
;
546 *num_grp_p
= num_grp
;
552 static bool torture_assert_group_equal(struct torture_context
*tctx
,
553 const struct group
*g1
,
554 const struct group
*g2
,
558 torture_assert_str_equal(tctx
, g1
->gr_name
, g2
->gr_name
, comment
);
559 torture_assert_str_equal(tctx
, g1
->gr_passwd
, g2
->gr_passwd
, comment
);
560 torture_assert_int_equal(tctx
, g1
->gr_gid
, g2
->gr_gid
, comment
);
561 if (g1
->gr_mem
&& !g2
->gr_mem
) {
564 if (!g1
->gr_mem
&& g2
->gr_mem
) {
567 if (!g1
->gr_mem
&& !g2
->gr_mem
) {
570 for (i
=0; g1
->gr_mem
[i
] && g2
->gr_mem
[i
]; i
++) {
571 torture_assert_str_equal(tctx
, g1
->gr_mem
[i
], g2
->gr_mem
[i
], comment
);
577 static bool test_nwrap_group(struct torture_context
*tctx
)
580 struct group
*grp
, grp1
, grp2
;
583 torture_assert(tctx
, test_nwrap_enum_group(tctx
, &grp
, &num_grp
),
584 "failed to enumerate group");
586 for (i
=0; i
< num_grp
; i
++) {
587 torture_assert(tctx
, test_nwrap_getgrnam(tctx
, grp
[i
].gr_name
, &grp1
),
588 "failed to call getgrnam for enumerated user");
589 torture_assert_group_equal(tctx
, &grp
[i
], &grp1
,
590 "getgrent and getgrnam gave different results");
591 torture_assert(tctx
, test_nwrap_getgrgid(tctx
, grp
[i
].gr_gid
, &grp2
),
592 "failed to call getgrgid for enumerated user");
593 torture_assert_group_equal(tctx
, &grp
[i
], &grp2
,
594 "getgrent and getgrgid gave different results");
595 torture_assert_group_equal(tctx
, &grp1
, &grp2
,
596 "getgrnam and getgrgid gave different results");
602 static bool test_nwrap_group_r(struct torture_context
*tctx
)
605 struct group
*grp
, grp1
, grp2
;
608 torture_assert(tctx
, test_nwrap_enum_r_group(tctx
, &grp
, &num_grp
),
609 "failed to enumerate group");
611 for (i
=0; i
< num_grp
; i
++) {
612 torture_assert(tctx
, test_nwrap_getgrnam_r(tctx
, grp
[i
].gr_name
, &grp1
),
613 "failed to call getgrnam_r for enumerated user");
614 torture_assert_group_equal(tctx
, &grp
[i
], &grp1
,
615 "getgrent_r and getgrnam_r gave different results");
616 torture_assert(tctx
, test_nwrap_getgrgid_r(tctx
, grp
[i
].gr_gid
, &grp2
),
617 "failed to call getgrgid_r for enumerated user");
618 torture_assert_group_equal(tctx
, &grp
[i
], &grp2
,
619 "getgrent_r and getgrgid_r gave different results");
620 torture_assert_group_equal(tctx
, &grp1
, &grp2
,
621 "getgrnam_r and getgrgid_r gave different results");
627 static bool test_nwrap_group_r_cross(struct torture_context
*tctx
)
630 struct group
*grp
, grp1
, grp2
, grp3
, grp4
;
633 torture_assert(tctx
, test_nwrap_enum_r_group(tctx
, &grp
, &num_grp
),
634 "failed to enumerate group");
636 for (i
=0; i
< num_grp
; i
++) {
637 torture_assert(tctx
, test_nwrap_getgrnam_r(tctx
, grp
[i
].gr_name
, &grp1
),
638 "failed to call getgrnam_r for enumerated user");
639 torture_assert_group_equal(tctx
, &grp
[i
], &grp1
,
640 "getgrent_r and getgrnam_r gave different results");
641 torture_assert(tctx
, test_nwrap_getgrgid_r(tctx
, grp
[i
].gr_gid
, &grp2
),
642 "failed to call getgrgid_r for enumerated user");
643 torture_assert_group_equal(tctx
, &grp
[i
], &grp2
,
644 "getgrent_r and getgrgid_r gave different results");
645 torture_assert_group_equal(tctx
, &grp1
, &grp2
,
646 "getgrnam_r and getgrgid_r gave different results");
647 torture_assert(tctx
, test_nwrap_getgrnam(tctx
, grp
[i
].gr_name
, &grp3
),
648 "failed to call getgrnam for enumerated user");
649 torture_assert_group_equal(tctx
, &grp
[i
], &grp3
,
650 "getgrent_r and getgrnam gave different results");
651 torture_assert(tctx
, test_nwrap_getgrgid(tctx
, grp
[i
].gr_gid
, &grp4
),
652 "failed to call getgrgid for enumerated user");
653 torture_assert_group_equal(tctx
, &grp
[i
], &grp4
,
654 "getgrent_r and getgrgid gave different results");
655 torture_assert_group_equal(tctx
, &grp3
, &grp4
,
656 "getgrnam and getgrgid gave different results");
662 static bool test_nwrap_getgrouplist(struct torture_context
*tctx
,
670 gid_t
*groups
= NULL
;
672 torture_comment(tctx
, "Testing getgrouplist: %s\n", user
);
674 ret
= getgrouplist(user
, gid
, NULL
, &num_groups
);
675 if (ret
== -1 || num_groups
!= 0) {
677 groups
= talloc_array(tctx
, gid_t
, num_groups
);
678 torture_assert(tctx
, groups
, "out of memory\n");
680 ret
= getgrouplist(user
, gid
, groups
, &num_groups
);
683 torture_assert(tctx
, (ret
!= -1), "failed to call getgrouplist");
685 torture_comment(tctx
, "%s is member in %d groups\n", user
, num_groups
);
691 *num_gids_p
= num_groups
;
697 static bool test_nwrap_user_in_group(struct torture_context
*tctx
,
698 const struct passwd
*pwd
,
699 const struct group
*grp
)
703 for (i
=0; grp
->gr_mem
&& grp
->gr_mem
[i
] != NULL
; i
++) {
704 if (strequal(grp
->gr_mem
[i
], pwd
->pw_name
)) {
712 static bool test_nwrap_membership_user(struct torture_context
*tctx
,
713 const struct passwd
*pwd
,
714 struct group
*grp_array
,
717 int num_user_groups
= 0;
718 int num_user_groups_from_enum
= 0;
719 gid_t
*user_groups
= NULL
;
721 bool primary_group_had_user_member
= false;
723 torture_assert(tctx
, test_nwrap_getgrouplist(tctx
,
728 "failed to test getgrouplist");
730 for (g
=0; g
< num_user_groups
; g
++) {
731 torture_assert(tctx
, test_nwrap_getgrgid(tctx
, user_groups
[g
], NULL
),
732 "failed to find the group the user is a member of");
736 for (i
=0; i
< num_grp
; i
++) {
738 struct group grp
= grp_array
[i
];
740 if (test_nwrap_user_in_group(tctx
, pwd
, &grp
)) {
742 struct group current_grp
;
743 num_user_groups_from_enum
++;
745 torture_assert(tctx
, test_nwrap_getgrnam(tctx
, grp
.gr_name
, ¤t_grp
),
746 "failed to find the group the user is a member of");
748 if (current_grp
.gr_gid
== pwd
->pw_gid
) {
749 torture_comment(tctx
, "primary group %s of user %s lists user as member\n",
752 primary_group_had_user_member
= true;
759 if (!primary_group_had_user_member
) {
760 num_user_groups_from_enum
++;
763 torture_assert_int_equal(tctx
, num_user_groups
, num_user_groups_from_enum
,
764 "getgrouplist and real inspection of grouplist gave different results\n");
769 static bool test_nwrap_membership(struct torture_context
*tctx
)
771 const char *old_pwd
= getenv("NSS_WRAPPER_PASSWD");
772 const char *old_group
= getenv("NSS_WRAPPER_GROUP");
779 if (!old_pwd
|| !old_group
) {
780 torture_comment(tctx
, "ENV NSS_WRAPPER_PASSWD or NSS_WRAPPER_GROUP not set\n");
781 torture_skip(tctx
, "nothing to test\n");
784 torture_assert(tctx
, test_nwrap_enum_passwd(tctx
, &pwd
, &num_pwd
),
785 "failed to enumerate passwd");
786 torture_assert(tctx
, test_nwrap_enum_group(tctx
, &grp
, &num_grp
),
787 "failed to enumerate group");
789 for (i
=0; i
< num_pwd
; i
++) {
791 torture_assert(tctx
, test_nwrap_membership_user(tctx
, &pwd
[i
], grp
, num_grp
),
792 "failed to test membership for user");
799 static bool test_nwrap_enumeration(struct torture_context
*tctx
)
801 const char *old_pwd
= getenv("NSS_WRAPPER_PASSWD");
802 const char *old_group
= getenv("NSS_WRAPPER_GROUP");
804 if (!old_pwd
|| !old_group
) {
805 torture_comment(tctx
, "ENV NSS_WRAPPER_PASSWD or NSS_WRAPPER_GROUP not set\n");
806 torture_skip(tctx
, "nothing to test\n");
809 torture_assert(tctx
, test_nwrap_passwd(tctx
),
810 "failed to test users");
811 torture_assert(tctx
, test_nwrap_group(tctx
),
812 "failed to test groups");
817 static bool test_nwrap_reentrant_enumeration(struct torture_context
*tctx
)
819 const char *old_pwd
= getenv("NSS_WRAPPER_PASSWD");
820 const char *old_group
= getenv("NSS_WRAPPER_GROUP");
822 if (!old_pwd
|| !old_group
) {
823 torture_comment(tctx
, "ENV NSS_WRAPPER_PASSWD or NSS_WRAPPER_GROUP not set\n");
824 torture_skip(tctx
, "nothing to test\n");
827 torture_comment(tctx
, "Testing re-entrant calls\n");
829 torture_assert(tctx
, test_nwrap_passwd_r(tctx
),
830 "failed to test users");
831 torture_assert(tctx
, test_nwrap_group_r(tctx
),
832 "failed to test groups");
837 static bool test_nwrap_reentrant_enumeration_crosschecks(struct torture_context
*tctx
)
839 const char *old_pwd
= getenv("NSS_WRAPPER_PASSWD");
840 const char *old_group
= getenv("NSS_WRAPPER_GROUP");
842 if (!old_pwd
|| !old_group
) {
843 torture_comment(tctx
, "ENV NSS_WRAPPER_PASSWD or NSS_WRAPPER_GROUP not set\n");
844 torture_skip(tctx
, "nothing to test\n");
847 torture_comment(tctx
, "Testing re-entrant calls with cross checks\n");
849 torture_assert(tctx
, test_nwrap_passwd_r_cross(tctx
),
850 "failed to test users");
851 torture_assert(tctx
, test_nwrap_group_r_cross(tctx
),
852 "failed to test groups");
857 static bool test_nwrap_passwd_duplicates(struct torture_context
*tctx
)
864 torture_assert(tctx
, test_nwrap_enum_passwd(tctx
, &pwd
, &num_pwd
),
865 "failed to enumerate passwd");
867 for (i
=0; i
< num_pwd
; i
++) {
868 const char *current_name
= pwd
[i
].pw_name
;
869 for (d
=0; d
< num_pwd
; d
++) {
870 const char *dup_name
= pwd
[d
].pw_name
;
874 if (!strequal(current_name
, dup_name
)) {
878 torture_warning(tctx
, "found duplicate names:");
879 print_passwd(&pwd
[d
]);
880 print_passwd(&pwd
[i
]);
886 torture_fail(tctx
, talloc_asprintf(tctx
, "found %d duplicate names", duplicates
));
892 static bool test_nwrap_group_duplicates(struct torture_context
*tctx
)
899 torture_assert(tctx
, test_nwrap_enum_group(tctx
, &grp
, &num_grp
),
900 "failed to enumerate group");
902 for (i
=0; i
< num_grp
; i
++) {
903 const char *current_name
= grp
[i
].gr_name
;
904 for (d
=0; d
< num_grp
; d
++) {
905 const char *dup_name
= grp
[d
].gr_name
;
909 if (!strequal(current_name
, dup_name
)) {
913 torture_warning(tctx
, "found duplicate names:");
914 print_group(&grp
[d
]);
915 print_group(&grp
[i
]);
921 torture_fail(tctx
, talloc_asprintf(tctx
, "found %d duplicate names", duplicates
));
928 static bool test_nwrap_duplicates(struct torture_context
*tctx
)
930 const char *old_pwd
= getenv("NSS_WRAPPER_PASSWD");
931 const char *old_group
= getenv("NSS_WRAPPER_GROUP");
933 if (!old_pwd
|| !old_group
) {
934 torture_comment(tctx
, "ENV NSS_WRAPPER_PASSWD or NSS_WRAPPER_GROUP not set\n");
935 torture_skip(tctx
, "nothing to test\n");
938 torture_assert(tctx
, test_nwrap_passwd_duplicates(tctx
),
939 "failed to test users");
940 torture_assert(tctx
, test_nwrap_group_duplicates(tctx
),
941 "failed to test groups");
947 struct torture_suite
*torture_local_nss_wrapper(TALLOC_CTX
*mem_ctx
)
949 struct torture_suite
*suite
= torture_suite_create(mem_ctx
, "nss-wrapper");
951 torture_suite_add_simple_test(suite
, "enumeration", test_nwrap_enumeration
);
952 torture_suite_add_simple_test(suite
, "reentrant enumeration", test_nwrap_reentrant_enumeration
);
953 torture_suite_add_simple_test(suite
, "reentrant enumeration crosschecks", test_nwrap_reentrant_enumeration_crosschecks
);
954 torture_suite_add_simple_test(suite
, "membership", test_nwrap_membership
);
955 torture_suite_add_simple_test(suite
, "duplicates", test_nwrap_duplicates
);