Ignore:
Timestamp:
Nov 27, 2012, 4:43:17 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: updated trunk to 3.6.0

Location:
trunk/server
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/server

  • trunk/server/lib/nss_wrapper/testsuite.c

    r414 r745  
    44   local testing of the nss wrapper
    55
    6    Copyright (C) Guenther Deschner 2009
     6   Copyright (C) Guenther Deschner 2009-2010
    77
    88   This program is free software; you can redistribute it and/or modify
     
    2121
    2222#include "includes.h"
     23
     24#ifndef NSS_WRAPPER
     25#define NSS_WRAPPER
     26#endif
     27
    2328#include "torture/torture.h"
    2429#include "lib/replace/system/passwd.h"
    25 #include "lib/nss_wrapper/nss_wrapper.h"
    2630
    2731static bool copy_passwd(struct torture_context *tctx,
     
    176180               (unsigned long)grp->gr_gid);
    177181
    178         if (!grp->gr_mem[0]) {
     182        if ((grp->gr_mem == NULL) || !grp->gr_mem[0]) {
    179183                printf("\n");
    180184                return;
     
    773777
    774778        if (!old_pwd || !old_group) {
     779                torture_comment(tctx, "ENV NSS_WRAPPER_PASSWD or NSS_WRAPPER_GROUP not set\n");
    775780                torture_skip(tctx, "nothing to test\n");
    776                 return true;
    777781        }
    778782
     
    798802
    799803        if (!old_pwd || !old_group) {
     804                torture_comment(tctx, "ENV NSS_WRAPPER_PASSWD or NSS_WRAPPER_GROUP not set\n");
    800805                torture_skip(tctx, "nothing to test\n");
    801                 return true;
    802806        }
    803807
     
    816820
    817821        if (!old_pwd || !old_group) {
     822                torture_comment(tctx, "ENV NSS_WRAPPER_PASSWD or NSS_WRAPPER_GROUP not set\n");
    818823                torture_skip(tctx, "nothing to test\n");
    819                 return true;
    820824        }
    821825
     
    836840
    837841        if (!old_pwd || !old_group) {
     842                torture_comment(tctx, "ENV NSS_WRAPPER_PASSWD or NSS_WRAPPER_GROUP not set\n");
    838843                torture_skip(tctx, "nothing to test\n");
    839                 return true;
    840844        }
    841845
     
    850854}
    851855
     856static bool test_nwrap_passwd_duplicates(struct torture_context *tctx)
     857{
     858        int i, d;
     859        struct passwd *pwd;
     860        size_t num_pwd;
     861        int duplicates = 0;
     862
     863        torture_assert(tctx, test_nwrap_enum_passwd(tctx, &pwd, &num_pwd),
     864            "failed to enumerate passwd");
     865
     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;
     870                        if (d == i) {
     871                                continue;
     872                        }
     873                        if (!strequal(current_name, dup_name)) {
     874                                continue;
     875                        }
     876
     877                        torture_warning(tctx, "found duplicate names:");
     878                        print_passwd(&pwd[d]);
     879                        print_passwd(&pwd[i]);
     880                        duplicates++;
     881                }
     882        }
     883
     884        if (duplicates) {
     885                torture_fail(tctx, talloc_asprintf(tctx, "found %d duplicate names", duplicates));
     886        }
     887
     888        return true;
     889}
     890
     891static bool test_nwrap_group_duplicates(struct torture_context *tctx)
     892{
     893        int i, d;
     894        struct group *grp;
     895        size_t num_grp;
     896        int duplicates = 0;
     897
     898        torture_assert(tctx, test_nwrap_enum_group(tctx, &grp, &num_grp),
     899                "failed to enumerate group");
     900
     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;
     905                        if (d == i) {
     906                                continue;
     907                        }
     908                        if (!strequal(current_name, dup_name)) {
     909                                continue;
     910                        }
     911
     912                        torture_warning(tctx, "found duplicate names:");
     913                        print_group(&grp[d]);
     914                        print_group(&grp[i]);
     915                        duplicates++;
     916                }
     917        }
     918
     919        if (duplicates) {
     920                torture_fail(tctx, talloc_asprintf(tctx, "found %d duplicate names", duplicates));
     921        }
     922
     923        return true;
     924}
     925
     926
     927static bool test_nwrap_duplicates(struct torture_context *tctx)
     928{
     929        const char *old_pwd = getenv("NSS_WRAPPER_PASSWD");
     930        const char *old_group = getenv("NSS_WRAPPER_GROUP");
     931
     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");
     935        }
     936
     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");
     941
     942        return true;
     943}
     944
     945
    852946struct torture_suite *torture_local_nss_wrapper(TALLOC_CTX *mem_ctx)
    853947{
    854         struct torture_suite *suite = torture_suite_create(mem_ctx, "NSS-WRAPPER");
     948        struct torture_suite *suite = torture_suite_create(mem_ctx, "nss-wrapper");
    855949
    856950        torture_suite_add_simple_test(suite, "enumeration", test_nwrap_enumeration);
     
    858952        torture_suite_add_simple_test(suite, "reentrant enumeration crosschecks", test_nwrap_reentrant_enumeration_crosschecks);
    859953        torture_suite_add_simple_test(suite, "membership", test_nwrap_membership);
     954        torture_suite_add_simple_test(suite, "duplicates", test_nwrap_duplicates);
    860955
    861956        return suite;
Note: See TracChangeset for help on using the changeset viewer.