r25290: remove wrong comment
[kai/samba.git] / source / torture / winbind / struct_based.c
index b6686e8a04d85ec22511d2d47c76f516e2bf0094..51269b9d95f7441e54b363e4195af158e1470d76 100644 (file)
 #include "libcli/security/security.h"
 #include "param/param.h"
 
+#define DO_STRUCT_REQ_REP_EXT(op,req,rep,expected,strict,warnaction,cmt) do { \
+       NSS_STATUS __got, __expected = (expected); \
+       __got = winbindd_request_response(op, req, rep); \
+       if (__got != __expected) { \
+               const char *__cmt = (cmt); \
+               if (strict) { \
+                       torture_result(torture, TORTURE_FAIL, \
+                               __location__ ": " __STRING(op) \
+                               " returned %d, expected %d%s%s", \
+                               __got, __expected, \
+                               (__cmt) ? ": " : "", \
+                               (__cmt) ? (__cmt) : ""); \
+                       return false; \
+               } else { \
+                       torture_warning(torture, \
+                               __location__ ": " __STRING(op) \
+                               " returned %d, expected %d%s%s", \
+                               __got, __expected, \
+                               (__cmt) ? ": " : "", \
+                               (__cmt) ? (__cmt) : ""); \
+                       warnaction; \
+               } \
+       } \
+} while(0)
+
 #define DO_STRUCT_REQ_REP(op,req,rep) do { \
-       NSS_STATUS _result; \
-       _result = winbindd_request_response(op, req, rep); \
-       torture_assert_int_equal(torture, _result, NSS_STATUS_SUCCESS, \
-                                __STRING(op) "(struct based)"); \
+       bool __noop = false; \
+       DO_STRUCT_REQ_REP_EXT(op,req,rep,NSS_STATUS_SUCCESS,true,__noop=true,NULL); \
 } while (0)
 
+static bool torture_winbind_struct_interface_version(struct torture_context *torture)
+{
+       struct winbindd_request req;
+       struct winbindd_response rep;
+
+       ZERO_STRUCT(req);
+       ZERO_STRUCT(rep);
+
+       torture_comment(torture, "Running WINBINDD_INTERFACE_VERSION (struct based)\n");
+
+       DO_STRUCT_REQ_REP(WINBINDD_INTERFACE_VERSION, &req, &rep);
+
+       torture_assert_int_equal(torture,
+                                rep.data.interface_version,
+                                WINBIND_INTERFACE_VERSION,
+                                "winbind server and client doesn't match");
+
+       return true;
+}
+
 static bool torture_winbind_struct_ping(struct torture_context *torture)
 {
        struct timeval tv = timeval_current();
@@ -54,6 +97,79 @@ static bool torture_winbind_struct_ping(struct torture_context *torture)
        return true;
 }
 
+static bool torture_winbind_struct_info(struct torture_context *torture)
+{
+       struct winbindd_response rep;
+       const char *separator;
+
+       ZERO_STRUCT(rep);
+
+       torture_comment(torture, "Running WINBINDD_INFO (struct based)\n");
+
+       DO_STRUCT_REQ_REP(WINBINDD_INFO, NULL, &rep);
+
+       separator = torture_setting_string(torture,
+                                          "winbindd separator",
+                                          lp_winbind_separator());
+       torture_assert_int_equal(torture,
+                                rep.data.info.winbind_separator,
+                                *separator,
+                                "winbind separator doesn't match");
+
+       torture_comment(torture, "Samba Version '%s'\n",
+                       rep.data.info.samba_version);
+
+       return true;
+}
+
+static bool torture_winbind_struct_netbios_name(struct torture_context *torture)
+{
+       struct winbindd_request req;
+       struct winbindd_response rep;
+       const char *expected;
+
+       ZERO_STRUCT(req);
+       ZERO_STRUCT(rep);
+
+       torture_comment(torture, "Running WINBINDD_NETBIOS_NAME (struct based)\n");
+
+       DO_STRUCT_REQ_REP(WINBINDD_NETBIOS_NAME, &req, &rep);
+
+       expected = torture_setting_string(torture,
+                                         "winbindd netbios name",
+                                         lp_netbios_name());
+
+       torture_assert_str_equal(torture,
+                                rep.data.netbios_name, expected,
+                                "winbindd's netbios name doesn't match");
+
+       return true;
+}
+
+static bool torture_winbind_struct_domain_name(struct torture_context *torture)
+{
+       struct winbindd_request req;
+       struct winbindd_response rep;
+       const char *expected;
+
+       ZERO_STRUCT(req);
+       ZERO_STRUCT(rep);
+
+       torture_comment(torture, "Running WINBINDD_DOMAIN_NAME (struct based)\n");
+
+       DO_STRUCT_REQ_REP(WINBINDD_DOMAIN_NAME, &req, &rep);
+
+       expected = torture_setting_string(torture,
+                                         "winbindd netbios domain",
+                                         lp_workgroup());
+
+       torture_assert_str_equal(torture,
+                                rep.data.domain_name, expected,
+                                "winbindd's netbios domain doesn't match");
+
+       return true;
+}
+
 struct torture_trust_domain {
        const char *netbios_name;
        const char *dns_name;
@@ -108,8 +224,11 @@ static bool get_trusted_domains(struct torture_context *torture,
 
                dcount++;
        }
-
        SAFE_FREE(rep.extra_data.data);
+
+       torture_assert(torture, dcount >= 2,
+                      "The list of trusted domain should contain 2 entries");
+
        *_d = d;
        return true;
 }
@@ -178,7 +297,7 @@ static bool torture_winbind_struct_list_trustdom(struct torture_context *torture
                        ok = dom_sid_equal(builtin_sid,
                                           listd[i].sid);
                        torture_assert(torture, ok, "BUILTIN domain should have S-1-5-32");
-                                      
+
                        continue;
                }
 
@@ -188,29 +307,109 @@ static bool torture_winbind_struct_list_trustdom(struct torture_context *torture
                 */
        }
 
-       torture_assert(torture, i >= 2,
-                      "The list of trusted domain should contain 2 entries");
+       return true;
+}
+
+static bool torture_winbind_struct_domain_info(struct torture_context *torture)
+{
+       bool ok;
+       struct torture_trust_domain *listd = NULL;
+       uint32_t i;
+
+       torture_comment(torture, "Running WINBINDD_DOMAIN_INFO (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++) {
+               struct winbindd_request req;
+               struct winbindd_response rep;
+               struct dom_sid *sid;
+               char *flagstr = talloc_strdup(torture," ");
+
+               ZERO_STRUCT(req);
+               ZERO_STRUCT(rep);
+
+               fstrcpy(req.domain_name, listd[i].netbios_name);
+
+               DO_STRUCT_REQ_REP(WINBINDD_DOMAIN_INFO, &req, &rep);
+
+               torture_assert_str_equal(torture,
+                                        rep.data.domain_info.name,
+                                        listd[i].netbios_name,
+                                        "Netbios domain name doesn't match");
+
+               torture_assert_str_equal(torture,
+                                        rep.data.domain_info.alt_name,
+                                        listd[i].dns_name,
+                                        "DNS domain name doesn't match");
+
+               sid = dom_sid_parse_talloc(torture, rep.data.domain_info.sid);
+               torture_assert(torture, sid, "Failed to parse SID");
+
+               ok = dom_sid_equal(listd[i].sid, sid);
+               torture_assert(torture, ok, "SID's doesn't match");
+
+               if (rep.data.domain_info.primary) {
+                       flagstr = talloc_strdup_append(flagstr, "PR ");
+               }
+
+               if (rep.data.domain_info.active_directory) {
+                       torture_assert(torture,
+                                      strlen(rep.data.domain_info.alt_name)>0,
+                                      "Active Directory without DNS name");
+                       flagstr = talloc_strdup_append(flagstr, "AD ");
+               }
+
+               if (rep.data.domain_info.native_mode) {
+                       torture_assert(torture,
+                                      rep.data.domain_info.active_directory,
+                                      "Native-Mode, but no Active Directory");
+                       flagstr = talloc_strdup_append(flagstr, "NA ");
+               }
+
+               torture_comment(torture, "DOMAIN '%s' => '%s' [%s]\n",
+                               rep.data.domain_info.name,
+                               rep.data.domain_info.alt_name,
+                               flagstr);
+       }
 
        return true;
 }
 
 static bool torture_winbind_struct_getdcname(struct torture_context *torture)
 {
-       struct winbindd_request req;
-       struct winbindd_response rep;
+       bool ok;
+       bool strict = torture_setting_bool(torture, "strict mode", false);
+       struct torture_trust_domain *listd = NULL;
+       uint32_t i;
 
        torture_comment(torture, "Running WINBINDD_GETDCNAME (struct based)\n");
 
-       ZERO_STRUCT(req);
-       ZERO_STRUCT(rep);
+       ok = get_trusted_domains(torture, &listd);
+       torture_assert(torture, ok, "failed to get trust list");
 
-       fstrcpy(req.domain_name, lp_workgroup());
+       for (i=0; listd[i].netbios_name; i++) {
+               struct winbindd_request req;
+               struct winbindd_response rep;
 
-       DO_STRUCT_REQ_REP(WINBINDD_GETDCNAME, &req, &rep);
+               ZERO_STRUCT(req);
+               ZERO_STRUCT(rep);
 
-       /*
-        * TODO: test all trusted domains
-        */
+               fstrcpy(req.domain_name, listd[i].netbios_name);
+
+               ok = true;
+               DO_STRUCT_REQ_REP_EXT(WINBINDD_GETDCNAME, &req, &rep,
+                                     NSS_STATUS_SUCCESS,
+                                     (i <2 || strict), ok = false,
+                                     talloc_asprintf(torture, "DOMAIN '%s'",
+                                                     req.domain_name));
+               if (!ok) continue;
+
+               /* TODO: check rep.data.dc_name; */
+               torture_comment(torture, "DOMAIN '%s' => DCNAME '%s'\n",
+                               req.domain_name, rep.data.dc_name);
+       }
 
        return true;
 }
@@ -219,9 +418,14 @@ struct torture_suite *torture_winbind_struct_init(void)
 {
        struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "STRUCT");
 
+       torture_suite_add_simple_test(suite, "INTERFACE_VERSION", torture_winbind_struct_interface_version);
        torture_suite_add_simple_test(suite, "PING", torture_winbind_struct_ping);
-       torture_suite_add_simple_test(suite, "GETDCNAME", torture_winbind_struct_getdcname);
+       torture_suite_add_simple_test(suite, "INFO", torture_winbind_struct_info);
+       torture_suite_add_simple_test(suite, "NETBIOS_NAME", torture_winbind_struct_netbios_name);
+       torture_suite_add_simple_test(suite, "DOMAIN_NAME", torture_winbind_struct_domain_name);
        torture_suite_add_simple_test(suite, "LIST_TRUSTDOM", torture_winbind_struct_list_trustdom);
+       torture_suite_add_simple_test(suite, "DOMAIN_INFO", torture_winbind_struct_domain_info);
+       torture_suite_add_simple_test(suite, "GETDCNAME", torture_winbind_struct_getdcname);
 
        suite->description = talloc_strdup(suite, "WINBIND - struct based protocol tests");