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 "lib/replace/system/passwd.h"
31 static bool copy_passwd(struct torture_context
*tctx
,
32 const struct passwd
*pwd
,
35 p
->pw_name
= talloc_strdup(tctx
, pwd
->pw_name
);
36 p
->pw_passwd
= talloc_strdup(tctx
, pwd
->pw_passwd
);
37 p
->pw_uid
= pwd
->pw_uid
;
38 p
->pw_gid
= pwd
->pw_gid
;
39 p
->pw_gecos
= talloc_strdup(tctx
, pwd
->pw_gecos
);
40 p
->pw_dir
= talloc_strdup(tctx
, pwd
->pw_dir
);
41 p
->pw_shell
= talloc_strdup(tctx
, pwd
->pw_shell
);
46 static void print_passwd(struct passwd
*pwd
)
48 printf("%s:%s:%lu:%lu:%s:%s:%s\n",
51 (unsigned long)pwd
->pw_uid
,
52 (unsigned long)pwd
->pw_gid
,
59 static bool test_nwrap_getpwnam(struct torture_context
*tctx
,
65 torture_comment(tctx
, "Testing getpwnam: %s\n", name
);
73 copy_passwd(tctx
, pwd
, pwd_p
);
76 return pwd
? true : false;
79 static bool test_nwrap_getpwnam_r(struct torture_context
*tctx
,
83 struct passwd pwd
, *pwdp
;
87 torture_comment(tctx
, "Testing getpwnam_r: %s\n", name
);
89 ret
= getpwnam_r(name
, &pwd
, buffer
, sizeof(buffer
), &pwdp
);
92 torture_comment(tctx
, "got %d return code\n", ret
);
100 copy_passwd(tctx
, &pwd
, pwd_p
);
106 static bool test_nwrap_getpwuid(struct torture_context
*tctx
,
108 struct passwd
*pwd_p
)
112 torture_comment(tctx
, "Testing getpwuid: %lu\n", (unsigned long)uid
);
120 copy_passwd(tctx
, pwd
, pwd_p
);
123 return pwd
? true : false;
126 static bool test_nwrap_getpwuid_r(struct torture_context
*tctx
,
128 struct passwd
*pwd_p
)
130 struct passwd pwd
, *pwdp
;
134 torture_comment(tctx
, "Testing getpwuid_r: %lu\n", (unsigned long)uid
);
136 ret
= getpwuid_r(uid
, &pwd
, buffer
, sizeof(buffer
), &pwdp
);
139 torture_comment(tctx
, "got %d return code\n", ret
);
147 copy_passwd(tctx
, &pwd
, pwd_p
);
154 static bool copy_group(struct torture_context
*tctx
,
155 const struct group
*grp
,
160 g
->gr_name
= talloc_strdup(tctx
, grp
->gr_name
);
161 g
->gr_passwd
= talloc_strdup(tctx
, grp
->gr_passwd
);
162 g
->gr_gid
= grp
->gr_gid
;
165 for (i
=0; grp
->gr_mem
&& grp
->gr_mem
[i
]; i
++) {
166 g
->gr_mem
= talloc_realloc(tctx
, g
->gr_mem
, char *, i
+ 2);
167 g
->gr_mem
[i
] = talloc_strdup(g
->gr_mem
, grp
->gr_mem
[i
]);
168 g
->gr_mem
[i
+1] = NULL
;
174 static void print_group(struct group
*grp
)
180 (unsigned long)grp
->gr_gid
);
182 if ((grp
->gr_mem
== NULL
) || !grp
->gr_mem
[0]) {
187 for (i
=0; grp
->gr_mem
[i
+1]; i
++) {
188 printf("%s,", grp
->gr_mem
[i
]);
190 printf("%s\n", grp
->gr_mem
[i
]);
193 static bool test_nwrap_getgrnam(struct torture_context
*tctx
,
199 torture_comment(tctx
, "Testing getgrnam: %s\n", name
);
201 grp
= getgrnam(name
);
207 copy_group(tctx
, grp
, grp_p
);
210 return grp
? true : false;
213 static bool test_nwrap_getgrnam_r(struct torture_context
*tctx
,
217 struct group grp
, *grpp
;
221 torture_comment(tctx
, "Testing getgrnam_r: %s\n", name
);
223 ret
= getgrnam_r(name
, &grp
, buffer
, sizeof(buffer
), &grpp
);
226 torture_comment(tctx
, "got %d return code\n", ret
);
234 copy_group(tctx
, &grp
, grp_p
);
241 static bool test_nwrap_getgrgid(struct torture_context
*tctx
,
247 torture_comment(tctx
, "Testing getgrgid: %lu\n", (unsigned long)gid
);
255 copy_group(tctx
, grp
, grp_p
);
258 return grp
? true : false;
261 static bool test_nwrap_getgrgid_r(struct torture_context
*tctx
,
265 struct group grp
, *grpp
;
269 torture_comment(tctx
, "Testing getgrgid_r: %lu\n", (unsigned long)gid
);
271 ret
= getgrgid_r(gid
, &grp
, buffer
, sizeof(buffer
), &grpp
);
274 torture_comment(tctx
, "got %d return code\n", ret
);
282 copy_group(tctx
, &grp
, grp_p
);
288 static bool test_nwrap_enum_passwd(struct torture_context
*tctx
,
289 struct passwd
**pwd_array_p
,
293 struct passwd
*pwd_array
= NULL
;
296 torture_comment(tctx
, "Testing setpwent\n");
299 while ((pwd
= getpwent()) != NULL
) {
300 torture_comment(tctx
, "Testing getpwent\n");
303 if (pwd_array_p
&& num_pwd_p
) {
304 pwd_array
= talloc_realloc(tctx
, pwd_array
, struct passwd
, num_pwd
+1);
305 torture_assert(tctx
, pwd_array
, "out of memory");
306 copy_passwd(tctx
, pwd
, &pwd_array
[num_pwd
]);
311 torture_comment(tctx
, "Testing endpwent\n");
315 *pwd_array_p
= pwd_array
;
318 *num_pwd_p
= num_pwd
;
324 static bool test_nwrap_enum_r_passwd(struct torture_context
*tctx
,
325 struct passwd
**pwd_array_p
,
328 struct passwd pwd
, *pwdp
;
329 struct passwd
*pwd_array
= NULL
;
334 torture_comment(tctx
, "Testing setpwent\n");
338 torture_comment(tctx
, "Testing getpwent_r\n");
340 ret
= getpwent_r(&pwd
, buffer
, sizeof(buffer
), &pwdp
);
343 torture_comment(tctx
, "got %d return code\n", ret
);
348 if (pwd_array_p
&& num_pwd_p
) {
349 pwd_array
= talloc_realloc(tctx
, pwd_array
, struct passwd
, num_pwd
+1);
350 torture_assert(tctx
, pwd_array
, "out of memory");
351 copy_passwd(tctx
, &pwd
, &pwd_array
[num_pwd
]);
356 torture_comment(tctx
, "Testing endpwent\n");
360 *pwd_array_p
= pwd_array
;
363 *num_pwd_p
= num_pwd
;
369 static bool torture_assert_passwd_equal(struct torture_context
*tctx
,
370 const struct passwd
*p1
,
371 const struct passwd
*p2
,
374 torture_assert_str_equal(tctx
, p1
->pw_name
, p2
->pw_name
, comment
);
375 torture_assert_str_equal(tctx
, p1
->pw_passwd
, p2
->pw_passwd
, comment
);
376 torture_assert_int_equal(tctx
, p1
->pw_uid
, p2
->pw_uid
, comment
);
377 torture_assert_int_equal(tctx
, p1
->pw_gid
, p2
->pw_gid
, comment
);
378 torture_assert_str_equal(tctx
, p1
->pw_gecos
, p2
->pw_gecos
, comment
);
379 torture_assert_str_equal(tctx
, p1
->pw_dir
, p2
->pw_dir
, comment
);
380 torture_assert_str_equal(tctx
, p1
->pw_shell
, p2
->pw_shell
, comment
);
385 static bool test_nwrap_passwd(struct torture_context
*tctx
)
388 struct passwd
*pwd
, pwd1
, pwd2
;
391 torture_assert(tctx
, test_nwrap_enum_passwd(tctx
, &pwd
, &num_pwd
),
392 "failed to enumerate passwd");
394 for (i
=0; i
< num_pwd
; i
++) {
395 torture_assert(tctx
, test_nwrap_getpwnam(tctx
, pwd
[i
].pw_name
, &pwd1
),
396 "failed to call getpwnam for enumerated user");
397 torture_assert_passwd_equal(tctx
, &pwd
[i
], &pwd1
,
398 "getpwent and getpwnam gave different results");
399 torture_assert(tctx
, test_nwrap_getpwuid(tctx
, pwd
[i
].pw_uid
, &pwd2
),
400 "failed to call getpwuid for enumerated user");
401 torture_assert_passwd_equal(tctx
, &pwd
[i
], &pwd2
,
402 "getpwent and getpwuid gave different results");
403 torture_assert_passwd_equal(tctx
, &pwd1
, &pwd2
,
404 "getpwnam and getpwuid gave different results");
410 static bool test_nwrap_passwd_r(struct torture_context
*tctx
)
413 struct passwd
*pwd
, pwd1
, pwd2
;
416 torture_assert(tctx
, test_nwrap_enum_r_passwd(tctx
, &pwd
, &num_pwd
),
417 "failed to enumerate passwd");
419 for (i
=0; i
< num_pwd
; i
++) {
420 torture_assert(tctx
, test_nwrap_getpwnam_r(tctx
, pwd
[i
].pw_name
, &pwd1
),
421 "failed to call getpwnam_r for enumerated user");
422 torture_assert_passwd_equal(tctx
, &pwd
[i
], &pwd1
,
423 "getpwent_r and getpwnam_r gave different results");
424 torture_assert(tctx
, test_nwrap_getpwuid_r(tctx
, pwd
[i
].pw_uid
, &pwd2
),
425 "failed to call getpwuid_r for enumerated user");
426 torture_assert_passwd_equal(tctx
, &pwd
[i
], &pwd2
,
427 "getpwent_r and getpwuid_r gave different results");
428 torture_assert_passwd_equal(tctx
, &pwd1
, &pwd2
,
429 "getpwnam_r and getpwuid_r gave different results");
435 static bool test_nwrap_passwd_r_cross(struct torture_context
*tctx
)
438 struct passwd
*pwd
, pwd1
, pwd2
, pwd3
, pwd4
;
441 torture_assert(tctx
, test_nwrap_enum_r_passwd(tctx
, &pwd
, &num_pwd
),
442 "failed to enumerate passwd");
444 for (i
=0; i
< num_pwd
; i
++) {
445 torture_assert(tctx
, test_nwrap_getpwnam_r(tctx
, pwd
[i
].pw_name
, &pwd1
),
446 "failed to call getpwnam_r for enumerated user");
447 torture_assert_passwd_equal(tctx
, &pwd
[i
], &pwd1
,
448 "getpwent_r and getpwnam_r gave different results");
449 torture_assert(tctx
, test_nwrap_getpwuid_r(tctx
, pwd
[i
].pw_uid
, &pwd2
),
450 "failed to call getpwuid_r for enumerated user");
451 torture_assert_passwd_equal(tctx
, &pwd
[i
], &pwd2
,
452 "getpwent_r and getpwuid_r gave different results");
453 torture_assert_passwd_equal(tctx
, &pwd1
, &pwd2
,
454 "getpwnam_r and getpwuid_r gave different results");
455 torture_assert(tctx
, test_nwrap_getpwnam(tctx
, pwd
[i
].pw_name
, &pwd3
),
456 "failed to call getpwnam for enumerated user");
457 torture_assert_passwd_equal(tctx
, &pwd
[i
], &pwd3
,
458 "getpwent_r and getpwnam gave different results");
459 torture_assert(tctx
, test_nwrap_getpwuid(tctx
, pwd
[i
].pw_uid
, &pwd4
),
460 "failed to call getpwuid for enumerated user");
461 torture_assert_passwd_equal(tctx
, &pwd
[i
], &pwd4
,
462 "getpwent_r and getpwuid gave different results");
463 torture_assert_passwd_equal(tctx
, &pwd3
, &pwd4
,
464 "getpwnam and getpwuid gave different results");
470 static bool test_nwrap_enum_group(struct torture_context
*tctx
,
471 struct group
**grp_array_p
,
475 struct group
*grp_array
= NULL
;
478 torture_comment(tctx
, "Testing setgrent\n");
481 while ((grp
= getgrent()) != NULL
) {
482 torture_comment(tctx
, "Testing getgrent\n");
485 if (grp_array_p
&& num_grp_p
) {
486 grp_array
= talloc_realloc(tctx
, grp_array
, struct group
, num_grp
+1);
487 torture_assert(tctx
, grp_array
, "out of memory");
488 copy_group(tctx
, grp
, &grp_array
[num_grp
]);
493 torture_comment(tctx
, "Testing endgrent\n");
497 *grp_array_p
= grp_array
;
500 *num_grp_p
= num_grp
;
506 static bool test_nwrap_enum_r_group(struct torture_context
*tctx
,
507 struct group
**grp_array_p
,
510 struct group grp
, *grpp
;
511 struct group
*grp_array
= NULL
;
516 torture_comment(tctx
, "Testing setgrent\n");
520 torture_comment(tctx
, "Testing getgrent_r\n");
522 ret
= getgrent_r(&grp
, buffer
, sizeof(buffer
), &grpp
);
525 torture_comment(tctx
, "got %d return code\n", ret
);
530 if (grp_array_p
&& num_grp_p
) {
531 grp_array
= talloc_realloc(tctx
, grp_array
, struct group
, num_grp
+1);
532 torture_assert(tctx
, grp_array
, "out of memory");
533 copy_group(tctx
, &grp
, &grp_array
[num_grp
]);
538 torture_comment(tctx
, "Testing endgrent\n");
542 *grp_array_p
= grp_array
;
545 *num_grp_p
= num_grp
;
551 static bool torture_assert_group_equal(struct torture_context
*tctx
,
552 const struct group
*g1
,
553 const struct group
*g2
,
557 torture_assert_str_equal(tctx
, g1
->gr_name
, g2
->gr_name
, comment
);
558 torture_assert_str_equal(tctx
, g1
->gr_passwd
, g2
->gr_passwd
, comment
);
559 torture_assert_int_equal(tctx
, g1
->gr_gid
, g2
->gr_gid
, comment
);
560 if (g1
->gr_mem
&& !g2
->gr_mem
) {
563 if (!g1
->gr_mem
&& g2
->gr_mem
) {
566 if (!g1
->gr_mem
&& !g2
->gr_mem
) {
569 for (i
=0; g1
->gr_mem
[i
] && g2
->gr_mem
[i
]; i
++) {
570 torture_assert_str_equal(tctx
, g1
->gr_mem
[i
], g2
->gr_mem
[i
], comment
);
576 static bool test_nwrap_group(struct torture_context
*tctx
)
579 struct group
*grp
, grp1
, grp2
;
582 torture_assert(tctx
, test_nwrap_enum_group(tctx
, &grp
, &num_grp
),
583 "failed to enumerate group");
585 for (i
=0; i
< num_grp
; i
++) {
586 torture_assert(tctx
, test_nwrap_getgrnam(tctx
, grp
[i
].gr_name
, &grp1
),
587 "failed to call getgrnam for enumerated user");
588 torture_assert_group_equal(tctx
, &grp
[i
], &grp1
,
589 "getgrent and getgrnam gave different results");
590 torture_assert(tctx
, test_nwrap_getgrgid(tctx
, grp
[i
].gr_gid
, &grp2
),
591 "failed to call getgrgid for enumerated user");
592 torture_assert_group_equal(tctx
, &grp
[i
], &grp2
,
593 "getgrent and getgrgid gave different results");
594 torture_assert_group_equal(tctx
, &grp1
, &grp2
,
595 "getgrnam and getgrgid gave different results");
601 static bool test_nwrap_group_r(struct torture_context
*tctx
)
604 struct group
*grp
, grp1
, grp2
;
607 torture_assert(tctx
, test_nwrap_enum_r_group(tctx
, &grp
, &num_grp
),
608 "failed to enumerate group");
610 for (i
=0; i
< num_grp
; i
++) {
611 torture_assert(tctx
, test_nwrap_getgrnam_r(tctx
, grp
[i
].gr_name
, &grp1
),
612 "failed to call getgrnam_r for enumerated user");
613 torture_assert_group_equal(tctx
, &grp
[i
], &grp1
,
614 "getgrent_r and getgrnam_r gave different results");
615 torture_assert(tctx
, test_nwrap_getgrgid_r(tctx
, grp
[i
].gr_gid
, &grp2
),
616 "failed to call getgrgid_r for enumerated user");
617 torture_assert_group_equal(tctx
, &grp
[i
], &grp2
,
618 "getgrent_r and getgrgid_r gave different results");
619 torture_assert_group_equal(tctx
, &grp1
, &grp2
,
620 "getgrnam_r and getgrgid_r gave different results");
626 static bool test_nwrap_group_r_cross(struct torture_context
*tctx
)
629 struct group
*grp
, grp1
, grp2
, grp3
, grp4
;
632 torture_assert(tctx
, test_nwrap_enum_r_group(tctx
, &grp
, &num_grp
),
633 "failed to enumerate group");
635 for (i
=0; i
< num_grp
; i
++) {
636 torture_assert(tctx
, test_nwrap_getgrnam_r(tctx
, grp
[i
].gr_name
, &grp1
),
637 "failed to call getgrnam_r for enumerated user");
638 torture_assert_group_equal(tctx
, &grp
[i
], &grp1
,
639 "getgrent_r and getgrnam_r gave different results");
640 torture_assert(tctx
, test_nwrap_getgrgid_r(tctx
, grp
[i
].gr_gid
, &grp2
),
641 "failed to call getgrgid_r for enumerated user");
642 torture_assert_group_equal(tctx
, &grp
[i
], &grp2
,
643 "getgrent_r and getgrgid_r gave different results");
644 torture_assert_group_equal(tctx
, &grp1
, &grp2
,
645 "getgrnam_r and getgrgid_r gave different results");
646 torture_assert(tctx
, test_nwrap_getgrnam(tctx
, grp
[i
].gr_name
, &grp3
),
647 "failed to call getgrnam for enumerated user");
648 torture_assert_group_equal(tctx
, &grp
[i
], &grp3
,
649 "getgrent_r and getgrnam gave different results");
650 torture_assert(tctx
, test_nwrap_getgrgid(tctx
, grp
[i
].gr_gid
, &grp4
),
651 "failed to call getgrgid for enumerated user");
652 torture_assert_group_equal(tctx
, &grp
[i
], &grp4
,
653 "getgrent_r and getgrgid gave different results");
654 torture_assert_group_equal(tctx
, &grp3
, &grp4
,
655 "getgrnam and getgrgid gave different results");
661 static bool test_nwrap_getgrouplist(struct torture_context
*tctx
,
669 gid_t
*groups
= NULL
;
671 torture_comment(tctx
, "Testing getgrouplist: %s\n", user
);
673 ret
= getgrouplist(user
, gid
, NULL
, &num_groups
);
674 if (ret
== -1 || num_groups
!= 0) {
676 groups
= talloc_array(tctx
, gid_t
, num_groups
);
677 torture_assert(tctx
, groups
, "out of memory\n");
679 ret
= getgrouplist(user
, gid
, groups
, &num_groups
);
682 torture_assert(tctx
, (ret
!= -1), "failed to call getgrouplist");
684 torture_comment(tctx
, "%s is member in %d groups\n", user
, num_groups
);
690 *num_gids_p
= num_groups
;
696 static bool test_nwrap_user_in_group(struct torture_context
*tctx
,
697 const struct passwd
*pwd
,
698 const struct group
*grp
)
702 for (i
=0; grp
->gr_mem
&& grp
->gr_mem
[i
] != NULL
; i
++) {
703 if (strequal(grp
->gr_mem
[i
], pwd
->pw_name
)) {
711 static bool test_nwrap_membership_user(struct torture_context
*tctx
,
712 const struct passwd
*pwd
,
713 struct group
*grp_array
,
716 int num_user_groups
= 0;
717 int num_user_groups_from_enum
= 0;
718 gid_t
*user_groups
= NULL
;
720 bool primary_group_had_user_member
= false;
722 torture_assert(tctx
, test_nwrap_getgrouplist(tctx
,
727 "failed to test getgrouplist");
729 for (g
=0; g
< num_user_groups
; g
++) {
730 torture_assert(tctx
, test_nwrap_getgrgid(tctx
, user_groups
[g
], NULL
),
731 "failed to find the group the user is a member of");
735 for (i
=0; i
< num_grp
; i
++) {
737 struct group grp
= grp_array
[i
];
739 if (test_nwrap_user_in_group(tctx
, pwd
, &grp
)) {
741 struct group current_grp
;
742 num_user_groups_from_enum
++;
744 torture_assert(tctx
, test_nwrap_getgrnam(tctx
, grp
.gr_name
, ¤t_grp
),
745 "failed to find the group the user is a member of");
747 if (current_grp
.gr_gid
== pwd
->pw_gid
) {
748 torture_comment(tctx
, "primary group %s of user %s lists user as member\n",
751 primary_group_had_user_member
= true;
758 if (!primary_group_had_user_member
) {
759 num_user_groups_from_enum
++;
762 torture_assert_int_equal(tctx
, num_user_groups
, num_user_groups_from_enum
,
763 "getgrouplist and real inspection of grouplist gave different results\n");
768 static bool test_nwrap_membership(struct torture_context
*tctx
)
770 const char *old_pwd
= getenv("NSS_WRAPPER_PASSWD");
771 const char *old_group
= getenv("NSS_WRAPPER_GROUP");
778 if (!old_pwd
|| !old_group
) {
779 torture_comment(tctx
, "ENV NSS_WRAPPER_PASSWD or NSS_WRAPPER_GROUP not set\n");
780 torture_skip(tctx
, "nothing to test\n");
783 torture_assert(tctx
, test_nwrap_enum_passwd(tctx
, &pwd
, &num_pwd
),
784 "failed to enumerate passwd");
785 torture_assert(tctx
, test_nwrap_enum_group(tctx
, &grp
, &num_grp
),
786 "failed to enumerate group");
788 for (i
=0; i
< num_pwd
; i
++) {
790 torture_assert(tctx
, test_nwrap_membership_user(tctx
, &pwd
[i
], grp
, num_grp
),
791 "failed to test membership for user");
798 static bool test_nwrap_enumeration(struct torture_context
*tctx
)
800 const char *old_pwd
= getenv("NSS_WRAPPER_PASSWD");
801 const char *old_group
= getenv("NSS_WRAPPER_GROUP");
803 if (!old_pwd
|| !old_group
) {
804 torture_comment(tctx
, "ENV NSS_WRAPPER_PASSWD or NSS_WRAPPER_GROUP not set\n");
805 torture_skip(tctx
, "nothing to test\n");
808 torture_assert(tctx
, test_nwrap_passwd(tctx
),
809 "failed to test users");
810 torture_assert(tctx
, test_nwrap_group(tctx
),
811 "failed to test groups");
816 static bool test_nwrap_reentrant_enumeration(struct torture_context
*tctx
)
818 const char *old_pwd
= getenv("NSS_WRAPPER_PASSWD");
819 const char *old_group
= getenv("NSS_WRAPPER_GROUP");
821 if (!old_pwd
|| !old_group
) {
822 torture_comment(tctx
, "ENV NSS_WRAPPER_PASSWD or NSS_WRAPPER_GROUP not set\n");
823 torture_skip(tctx
, "nothing to test\n");
826 torture_comment(tctx
, "Testing re-entrant calls\n");
828 torture_assert(tctx
, test_nwrap_passwd_r(tctx
),
829 "failed to test users");
830 torture_assert(tctx
, test_nwrap_group_r(tctx
),
831 "failed to test groups");
836 static bool test_nwrap_reentrant_enumeration_crosschecks(struct torture_context
*tctx
)
838 const char *old_pwd
= getenv("NSS_WRAPPER_PASSWD");
839 const char *old_group
= getenv("NSS_WRAPPER_GROUP");
841 if (!old_pwd
|| !old_group
) {
842 torture_comment(tctx
, "ENV NSS_WRAPPER_PASSWD or NSS_WRAPPER_GROUP not set\n");
843 torture_skip(tctx
, "nothing to test\n");
846 torture_comment(tctx
, "Testing re-entrant calls with cross checks\n");
848 torture_assert(tctx
, test_nwrap_passwd_r_cross(tctx
),
849 "failed to test users");
850 torture_assert(tctx
, test_nwrap_group_r_cross(tctx
),
851 "failed to test groups");
856 static bool test_nwrap_passwd_duplicates(struct torture_context
*tctx
)
863 torture_assert(tctx
, test_nwrap_enum_passwd(tctx
, &pwd
, &num_pwd
),
864 "failed to enumerate passwd");
866 for (i
=0; i
< num_pwd
; i
++) {
867 const char *current_name
= pwd
[i
].pw_name
;
868 for (d
=0; d
< num_pwd
; d
++) {
869 const char *dup_name
= pwd
[d
].pw_name
;
873 if (!strequal(current_name
, dup_name
)) {
877 torture_warning(tctx
, "found duplicate names:");
878 print_passwd(&pwd
[d
]);
879 print_passwd(&pwd
[i
]);
885 torture_fail(tctx
, talloc_asprintf(tctx
, "found %d duplicate names", duplicates
));
891 static bool test_nwrap_group_duplicates(struct torture_context
*tctx
)
898 torture_assert(tctx
, test_nwrap_enum_group(tctx
, &grp
, &num_grp
),
899 "failed to enumerate group");
901 for (i
=0; i
< num_grp
; i
++) {
902 const char *current_name
= grp
[i
].gr_name
;
903 for (d
=0; d
< num_grp
; d
++) {
904 const char *dup_name
= grp
[d
].gr_name
;
908 if (!strequal(current_name
, dup_name
)) {
912 torture_warning(tctx
, "found duplicate names:");
913 print_group(&grp
[d
]);
914 print_group(&grp
[i
]);
920 torture_fail(tctx
, talloc_asprintf(tctx
, "found %d duplicate names", duplicates
));
927 static bool test_nwrap_duplicates(struct torture_context
*tctx
)
929 const char *old_pwd
= getenv("NSS_WRAPPER_PASSWD");
930 const char *old_group
= getenv("NSS_WRAPPER_GROUP");
932 if (!old_pwd
|| !old_group
) {
933 torture_comment(tctx
, "ENV NSS_WRAPPER_PASSWD or NSS_WRAPPER_GROUP not set\n");
934 torture_skip(tctx
, "nothing to test\n");
937 torture_assert(tctx
, test_nwrap_passwd_duplicates(tctx
),
938 "failed to test users");
939 torture_assert(tctx
, test_nwrap_group_duplicates(tctx
),
940 "failed to test groups");
946 struct torture_suite
*torture_local_nss_wrapper(TALLOC_CTX
*mem_ctx
)
948 struct torture_suite
*suite
= torture_suite_create(mem_ctx
, "nss-wrapper");
950 torture_suite_add_simple_test(suite
, "enumeration", test_nwrap_enumeration
);
951 torture_suite_add_simple_test(suite
, "reentrant enumeration", test_nwrap_reentrant_enumeration
);
952 torture_suite_add_simple_test(suite
, "reentrant enumeration crosschecks", test_nwrap_reentrant_enumeration_crosschecks
);
953 torture_suite_add_simple_test(suite
, "membership", test_nwrap_membership
);
954 torture_suite_add_simple_test(suite
, "duplicates", test_nwrap_duplicates
);