build: commit all the waf build files in the tree
[nivanova/samba-autobuild/.git] / source4 / torture / winbind / struct_based.c
index 51ac0e622a12465a8ea9d2202c5faaed69d0ea43..99b08283197da105c704d3c7e0ba15d9615ee3c4 100644 (file)
 */
 
 #include "includes.h"
-#include "pstring.h"
 #include "torture/torture.h"
-#include "torture/winbind/proto.h"
 #include "nsswitch/winbind_client.h"
 #include "libcli/security/security.h"
 #include "librpc/gen_ndr/netlogon.h"
 #include "param/param.h"
-#include "auth/pam_errors.h"
+#include "auth/ntlm/pam_errors.h"
 
 #define DO_STRUCT_REQ_REP_EXT(op,req,rep,expected,strict,warnaction,cmt) do { \
        NSS_STATUS __got, __expected = (expected); \
@@ -124,8 +122,9 @@ static bool torture_winbind_struct_info(struct torture_context *torture)
        DO_STRUCT_REQ_REP(WINBINDD_INFO, NULL, &rep);
 
        separator = torture_setting_string(torture,
-                                          "winbindd separator",
+                                          "winbindd_separator",
                                           lp_winbind_separator(torture->lp_ctx));
+
        torture_assert_int_equal(torture,
                                 rep.data.info.winbind_separator,
                                 *separator,
@@ -140,8 +139,6 @@ static bool torture_winbind_struct_info(struct torture_context *torture)
 static bool torture_winbind_struct_priv_pipe_dir(struct torture_context *torture)
 {
        struct winbindd_response rep;
-       const char *default_dir;
-       const char *expected_dir;
        const char *got_dir;
 
        ZERO_STRUCT(rep);
@@ -154,15 +151,6 @@ static bool torture_winbind_struct_priv_pipe_dir(struct torture_context *torture
 
        torture_assert(torture, got_dir, "NULL WINBINDD_PRIV_PIPE_DIR\n");
 
-       default_dir = lock_path(torture, torture->lp_ctx, 
-                               WINBINDD_PRIV_SOCKET_SUBDIR);
-       expected_dir = torture_setting_string(torture,
-                                             "winbindd private pipe dir",
-                                             default_dir);
-
-       torture_assert_str_equal(torture, got_dir, expected_dir,
-                                "WINBINDD_PRIV_PIPE_DIR doesn't match");
-
        SAFE_FREE(rep.extra_data.data);
        return true;
 }
@@ -179,10 +167,10 @@ static bool torture_winbind_struct_netbios_name(struct torture_context *torture)
        DO_STRUCT_REQ_REP(WINBINDD_NETBIOS_NAME, NULL, &rep);
 
        expected = torture_setting_string(torture,
-                                         "winbindd netbios name",
+                                         "winbindd_netbios_name",
                                          lp_netbios_name(torture->lp_ctx));
        expected = strupper_talloc(torture, expected);
-       
+
        torture_assert_str_equal(torture,
                                 rep.data.netbios_name, expected,
                                 "winbindd's netbios name doesn't match");
@@ -212,7 +200,7 @@ static bool torture_winbind_struct_domain_name(struct torture_context *torture)
        torture_comment(torture, "Running WINBINDD_DOMAIN_NAME (struct based)\n");
 
        expected = torture_setting_string(torture,
-                                         "winbindd netbios domain",
+                                         "winbindd_netbios_domain",
                                          lp_workgroup(torture->lp_ctx));
 
        get_winbind_domain(torture, &domain);
@@ -262,7 +250,7 @@ static bool torture_winbind_struct_check_machacc(struct torture_context *torture
 
        torture_assert_str_equal(torture,
                                 rep.data.auth.error_string,
-                                nt_errstr(NT_STATUS_OK),
+                                get_friendly_nt_error_msg(NT_STATUS_OK),
                                 "WINBINDD_CHECK_MACHACC ok: error_string");
 
        torture_assert_int_equal(torture,
@@ -286,7 +274,7 @@ static bool get_trusted_domains(struct torture_context *torture,
        struct winbindd_response rep;
        struct torture_trust_domain *d = NULL;
        uint32_t dcount = 0;
-       fstring line;
+       char line[256];
        const char *extra_data;
 
        ZERO_STRUCT(req);
@@ -295,9 +283,13 @@ static bool get_trusted_domains(struct torture_context *torture,
        DO_STRUCT_REQ_REP(WINBINDD_LIST_TRUSTDOM, &req, &rep);
 
        extra_data = (char *)rep.extra_data.data;
+       if (!extra_data) {
+               return true;
+       }
+
        torture_assert(torture, extra_data, "NULL trust list");
 
-       while (next_token(&extra_data, line, "\n", sizeof(fstring))) {
+       while (next_token(&extra_data, line, "\n", sizeof(line))) {
                char *p, *lp;
 
                d = talloc_realloc(torture, d,
@@ -356,7 +348,6 @@ static bool torture_winbind_struct_list_trustdom(struct torture_context *torture
        DO_STRUCT_REQ_REP(WINBINDD_LIST_TRUSTDOM, &req, &rep);
 
        list1 = (char *)rep.extra_data.data;
-       torture_assert(torture, list1, "NULL trust list");
 
        torture_comment(torture, "%s\n", list1);
 
@@ -368,7 +359,6 @@ static bool torture_winbind_struct_list_trustdom(struct torture_context *torture
        DO_STRUCT_REQ_REP(WINBINDD_LIST_TRUSTDOM, &req, &rep);
 
        list2 = (char *)rep.extra_data.data;
-       torture_assert(torture, list2, "NULL trust list");
 
        /*
         * The list_all_domains parameter should be ignored
@@ -381,7 +371,7 @@ static bool torture_winbind_struct_list_trustdom(struct torture_context *torture
        ok = get_trusted_domains(torture, &listd);
        torture_assert(torture, ok, "failed to get trust list");
 
-       for (i=0; listd[i].netbios_name; i++) {
+       for (i=0; listd && listd[i].netbios_name; i++) {
                if (i == 0) {
                        struct dom_sid *builtin_sid;
 
@@ -424,7 +414,7 @@ static bool torture_winbind_struct_domain_info(struct torture_context *torture)
        ok = get_trusted_domains(torture, &listd);
        torture_assert(torture, ok, "failed to get trust list");
 
-       for (i=0; listd[i].netbios_name; i++) {
+       for (i=0; listd && listd[i].netbios_name; i++) {
                struct winbindd_request req;
                struct winbindd_response rep;
                struct dom_sid *sid;
@@ -484,18 +474,28 @@ static bool torture_winbind_struct_getdcname(struct torture_context *torture)
 {
        bool ok;
        bool strict = torture_setting_bool(torture, "strict mode", false);
+       const char *domain_name = torture_setting_string(torture,
+                                       "winbindd_netbios_domain",
+                                       lp_workgroup(torture->lp_ctx));
        struct torture_trust_domain *listd = NULL;
-       uint32_t i;
+       uint32_t i, count = 0;
 
        torture_comment(torture, "Running WINBINDD_GETDCNAME (struct based)\n");
 
        ok = get_trusted_domains(torture, &listd);
        torture_assert(torture, ok, "failed to get trust list");
 
-       for (i=0; listd[i].netbios_name; i++) {
+       for (i=0; listd && listd[i].netbios_name; i++) {
                struct winbindd_request req;
                struct winbindd_response rep;
 
+               /* getdcname is not expected to work on "BUILTIN" or our own
+                * domain */
+               if (strequal(listd[i].netbios_name, "BUILTIN") ||
+                   strequal(listd[i].netbios_name, domain_name)) {
+                       continue;
+               }
+
                ZERO_STRUCT(req);
                ZERO_STRUCT(rep);
 
@@ -512,8 +512,13 @@ static bool torture_winbind_struct_getdcname(struct torture_context *torture)
                /* TODO: check rep.data.dc_name; */
                torture_comment(torture, "DOMAIN '%s' => DCNAME '%s'\n",
                                req.domain_name, rep.data.dc_name);
+               count++;
        }
 
+       if (strict) {
+               torture_assert(torture, count > 0,
+                              "WiNBINDD_GETDCNAME was not tested");
+       }
        return true;
 }
 
@@ -530,7 +535,7 @@ static bool torture_winbind_struct_dsgetdcname(struct torture_context *torture)
        ok = get_trusted_domains(torture, &listd);
        torture_assert(torture, ok, "failed to get trust list");
 
-       for (i=0; listd[i].netbios_name; i++) {
+       for (i=0; listd && listd[i].netbios_name; i++) {
                struct winbindd_request req;
                struct winbindd_response rep;
 
@@ -587,7 +592,7 @@ static bool get_user_list(struct torture_context *torture, char ***users)
        struct winbindd_response rep;
        char **u = NULL;
        uint32_t count;
-       fstring name;
+       char name[256];
        const char *extra_data;
 
        ZERO_STRUCT(req);
@@ -599,7 +604,7 @@ static bool get_user_list(struct torture_context *torture, char ***users)
        torture_assert(torture, extra_data, "NULL extra data");
 
        for(count = 0;
-           next_token(&extra_data, name, ",", sizeof(fstring));
+           next_token(&extra_data, name, ",", sizeof(name));
            count++)
        {
                u = talloc_realloc(torture, u, char *, count + 2);
@@ -622,7 +627,7 @@ static bool torture_winbind_struct_list_users(struct torture_context *torture)
        torture_comment(torture, "Running WINBINDD_LIST_USERS (struct based)\n");
 
        ok = get_user_list(torture, &users);
-       torture_assert(torture, ok, "failed to get group list");
+       torture_assert(torture, ok, "failed to get user list");
 
        for (count = 0; users[count]; count++) { }
 
@@ -631,25 +636,36 @@ static bool torture_winbind_struct_list_users(struct torture_context *torture)
        return true;
 }
 
-static bool get_group_list(struct torture_context *torture, char ***groups)
+static bool get_group_list(struct torture_context *torture,
+                          unsigned int *num_entries,
+                          char ***groups)
 {
        struct winbindd_request req;
        struct winbindd_response rep;
        char **g = NULL;
        uint32_t count;
-       fstring name;
+       char name[256];
        const char *extra_data;
 
        ZERO_STRUCT(req);
        ZERO_STRUCT(rep);
 
        DO_STRUCT_REQ_REP(WINBINDD_LIST_GROUPS, &req, &rep);
-
        extra_data = (char *)rep.extra_data.data;
+
+       *num_entries = rep.data.num_entries;
+
+       if (*num_entries == 0) {
+               torture_assert(torture, extra_data == NULL,
+                              "extra data is null for >0 reported entries\n");
+               *groups = NULL;
+               return true;
+       }
+
        torture_assert(torture, extra_data, "NULL extra data");
 
        for(count = 0;
-           next_token(&extra_data, name, ",", sizeof(fstring));
+           next_token(&extra_data, name, ",", sizeof(name));
            count++)
        {
                g = talloc_realloc(torture, g, char *, count + 2);
@@ -659,6 +675,9 @@ static bool get_group_list(struct torture_context *torture, char ***groups)
 
        SAFE_FREE(rep.extra_data.data);
 
+       torture_assert_int_equal(torture, *num_entries, count,
+                                "Wrong number of group entries reported.");
+
        *groups = g;
        return true;
 }
@@ -671,11 +690,9 @@ static bool torture_winbind_struct_list_groups(struct torture_context *torture)
 
        torture_comment(torture, "Running WINBINDD_LIST_GROUPS (struct based)\n");
 
-       ok = get_group_list(torture, &groups);
+       ok = get_group_list(torture, &count, &groups);
        torture_assert(torture, ok, "failed to get group list");
 
-       for (count = 0; groups[count]; count++) { }
-
        torture_comment(torture, "got %d groups\n", count);
 
        return true;
@@ -692,7 +709,7 @@ static bool get_sequence_numbers(struct torture_context *torture,
        struct winbindd_request req;
        struct winbindd_response rep;
        const char *extra_data;
-       fstring line;
+       char line[256];
        uint32_t count = 0;
        struct torture_domain_sequence *s = NULL;
 
@@ -704,7 +721,7 @@ static bool get_sequence_numbers(struct torture_context *torture,
        extra_data = (char *)rep.extra_data.data;
        torture_assert(torture, extra_data, "NULL sequence list");
 
-       while (next_token(&extra_data, line, "\n", sizeof(fstring))) {
+       while (next_token(&extra_data, line, "\n", sizeof(line))) {
                char *p, *lp;
                uint32_t seq;
 
@@ -833,12 +850,23 @@ static bool torture_winbind_struct_getpwent(struct torture_context *torture)
        ZERO_STRUCT(req);
        ZERO_STRUCT(rep);
        req.data.num_entries = 1;
-       DO_STRUCT_REQ_REP(WINBINDD_GETPWENT, &req, &rep);
+       if (torture_setting_bool(torture, "samba3", false)) {
+               bool __noop = false;
+               DO_STRUCT_REQ_REP_EXT(WINBINDD_GETPWENT, &req, &rep,
+                                     NSS_STATUS_SUCCESS, false, __noop=true,
+                                     NULL);
+       } else {
+               DO_STRUCT_REQ_REP(WINBINDD_GETPWENT, &req, &rep);
+       }
        pwent = (struct winbindd_pw *)rep.extra_data.data;
-       torture_assert(torture, (pwent != NULL), "NULL pwent");
-       torture_comment(torture, "name: %s, uid: %d, gid: %d, shell: %s\n",
-                       pwent->pw_name, pwent->pw_uid, pwent->pw_gid,
-                       pwent->pw_shell);
+       if (!torture_setting_bool(torture, "samba3", false)) {
+               torture_assert(torture, (pwent != NULL), "NULL pwent");
+       }
+       if (pwent) {
+               torture_comment(torture, "name: %s, uid: %d, gid: %d, shell: %s\n",
+                               pwent->pw_name, pwent->pw_uid, pwent->pw_gid,
+                               pwent->pw_shell);
+       }
 
        return true;
 }
@@ -899,6 +927,9 @@ static bool lookup_name_sid_list(struct torture_context *torture, char **list)
                struct winbindd_response rep;
                char *sid;
                char *name;
+               const char *domain_name = torture_setting_string(torture,
+                                               "winbindd_netbios_domain",
+                                               lp_workgroup(torture->lp_ctx));
 
                ZERO_STRUCT(req);
                ZERO_STRUCT(rep);
@@ -917,10 +948,15 @@ static bool lookup_name_sid_list(struct torture_context *torture, char **list)
 
                DO_STRUCT_REQ_REP(WINBINDD_LOOKUPSID, &req, &rep);
 
-               name = talloc_asprintf(torture, "%s%c%s",
-                                      rep.data.name.dom_name,
-                                      winbind_separator(torture),
-                                      rep.data.name.name);
+               if (strequal(rep.data.name.dom_name, domain_name)) {
+                       name = talloc_asprintf(torture, "%s",
+                                              rep.data.name.name);
+               } else {
+                       name = talloc_asprintf(torture, "%s%c%s",
+                                              rep.data.name.dom_name,
+                                              winbind_separator(torture),
+                                              rep.data.name.name);
+               }
 
                torture_assert_casestr_equal(torture, list[count], name,
                                         "LOOKUP_SID after LOOKUP_NAME != id");
@@ -941,7 +977,7 @@ static bool name_is_in_list(const char *name, const char **list)
 {
        uint32_t count;
 
-       for (count = 0; list[count]; count++) {
+       for (count = 0; list && list[count]; count++) {
                if (strequal(name, list[count])) {
                        return true;
                }
@@ -960,7 +996,7 @@ static bool torture_winbind_struct_lookup_name_sid(struct torture_context *tortu
        bool strict = torture_setting_bool(torture, "strict mode", false);
        char **users;
        char **groups;
-       uint32_t count;
+       uint32_t count, num_groups;
        bool ok;
 
        torture_comment(torture, "Running WINBINDD_LOOKUP_NAME_SID (struct based)\n");
@@ -969,9 +1005,11 @@ static bool torture_winbind_struct_lookup_name_sid(struct torture_context *tortu
        torture_assert(torture, ok, "failed to retrieve list of users");
        lookup_name_sid_list(torture, users);
 
-       ok = get_group_list(torture, &groups);
+       ok = get_group_list(torture, &num_groups, &groups);
        torture_assert(torture, ok, "failed to retrieve list of groups");
-       lookup_name_sid_list(torture, groups);
+       if (num_groups > 0) {
+               lookup_name_sid_list(torture, groups);
+       }
 
        ZERO_STRUCT(req);
        ZERO_STRUCT(rep);