s4:torture/ldap/cldap.c - remove the "test_cldap_netlogon_flag_ds_dns_forest" test
[obnox/samba/samba-obnox.git] / source4 / torture / ldap / cldap.c
index 1ddc628a5c643e6f1de23832fe7808a15a9dc7dd..6de33b8597cf4e63c0afdf815b7ee62edd57ffde 100644 (file)
@@ -4,6 +4,7 @@
    test CLDAP operations
    
    Copyright (C) Andrew Tridgell 2005
+   Copyright (C) Matthias Dieter Wallnöfer 2009
     
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
 
 #include "includes.h"
 #include "libcli/cldap/cldap.h"
-#include "libcli/ldap/ldap.h"
-#include "librpc/gen_ndr/ndr_nbt.h"
+#include "libcli/ldap/ldap_client.h"
 #include "librpc/gen_ndr/netlogon.h"
-#include "torture/torture.h"
-#include "lib/ldb/include/ldb.h"
 #include "param/param.h"
+#include "../lib/tsocket/tsocket.h"
+
+#include "torture/torture.h"
+#include "torture/ldap/proto.h"
 
 #define CHECK_STATUS(status, correct) torture_assert_ntstatus_equal(tctx, status, correct, "incorrect status")
 
@@ -45,12 +47,21 @@ static bool test_cldap_netlogon(struct torture_context *tctx, const char *dest)
        struct netlogon_samlogon_response n1;
        struct GUID guid;
        int i;
+       struct tsocket_address *dest_addr;
+       int ret;
 
-       cldap = cldap_socket_init(tctx, tctx->ev, lp_iconv_convenience(tctx->lp_ctx));
+       ret = tsocket_address_inet_from_strings(tctx, "ip",
+                                               dest,
+                                               lpcfg_cldap_port(tctx->lp_ctx),
+                                               &dest_addr);
+       CHECK_VAL(ret, 0);
+
+       status = cldap_socket_init(tctx, NULL, dest_addr, &cldap);
+       CHECK_STATUS(status, NT_STATUS_OK);
 
        ZERO_STRUCT(search);
-       search.in.dest_address = dest;
-       search.in.dest_port = lp_cldap_port(tctx->lp_ctx);
+       search.in.dest_address = NULL;
+       search.in.dest_port = 0;
        search.in.acct_control = -1;
        search.in.version = NETLOGON_NT_VERSION_5 | NETLOGON_NT_VERSION_5EX;
        search.in.map_response = true;
@@ -85,47 +96,40 @@ static bool test_cldap_netlogon(struct torture_context *tctx, const char *dest)
        }
 
        search.in.version = NETLOGON_NT_VERSION_5|NETLOGON_NT_VERSION_5EX|NETLOGON_NT_VERSION_IP;
-
        status = cldap_netlogon(cldap, tctx, &search);
        CHECK_STATUS(status, NT_STATUS_OK);
 
        printf("Trying with User=NULL\n");
-
        search.in.user = NULL;
        status = cldap_netlogon(cldap, tctx, &search);
        CHECK_STATUS(status, NT_STATUS_OK);
-       CHECK_STRING(search.out.netlogon.data.nt5_ex.user_name, "");
        CHECK_VAL(search.out.netlogon.data.nt5_ex.command, LOGON_SAM_LOGON_RESPONSE_EX);
+       CHECK_STRING(search.out.netlogon.data.nt5_ex.user_name, "");
 
        printf("Trying with User=Administrator\n");
-
        search.in.user = "Administrator";
        status = cldap_netlogon(cldap, tctx, &search);
        CHECK_STATUS(status, NT_STATUS_OK);
-
-       CHECK_STRING(search.out.netlogon.data.nt5_ex.user_name, search.in.user);
        CHECK_VAL(search.out.netlogon.data.nt5_ex.command, LOGON_SAM_LOGON_USER_UNKNOWN_EX);
+       CHECK_STRING(search.out.netlogon.data.nt5_ex.user_name, search.in.user);
 
        search.in.version = NETLOGON_NT_VERSION_5;
        status = cldap_netlogon(cldap, tctx, &search);
        CHECK_STATUS(status, NT_STATUS_OK);
 
        printf("Trying with User=NULL\n");
-
        search.in.user = NULL;
        status = cldap_netlogon(cldap, tctx, &search);
        CHECK_STATUS(status, NT_STATUS_OK);
-       CHECK_STRING(search.out.netlogon.data.nt5_ex.user_name, "");
        CHECK_VAL(search.out.netlogon.data.nt5_ex.command, LOGON_SAM_LOGON_RESPONSE);
+       CHECK_STRING(search.out.netlogon.data.nt5_ex.user_name, "");
 
        printf("Trying with User=Administrator\n");
-
        search.in.user = "Administrator";
        status = cldap_netlogon(cldap, tctx, &search);
        CHECK_STATUS(status, NT_STATUS_OK);
-
-       CHECK_STRING(search.out.netlogon.data.nt5_ex.user_name, search.in.user);
        CHECK_VAL(search.out.netlogon.data.nt5_ex.command, LOGON_SAM_LOGON_USER_UNKNOWN);
+       CHECK_STRING(search.out.netlogon.data.nt5_ex.user_name, search.in.user);
 
        search.in.version = NETLOGON_NT_VERSION_5 | NETLOGON_NT_VERSION_5EX;
 
@@ -183,16 +187,26 @@ static bool test_cldap_netlogon(struct torture_context *tctx, const char *dest)
        search.in.user = "Administrator";
        status = cldap_netlogon(cldap, tctx, &search);
        CHECK_STATUS(status, NT_STATUS_OK);
+       CHECK_STRING(search.out.netlogon.data.nt5_ex.forest, n1.data.nt5_ex.dns_domain);
        CHECK_STRING(search.out.netlogon.data.nt5_ex.dns_domain, n1.data.nt5_ex.dns_domain);
+       CHECK_STRING(search.out.netlogon.data.nt5_ex.domain_name, n1.data.nt5_ex.domain_name);
+       CHECK_STRING(search.out.netlogon.data.nt5_ex.pdc_name, n1.data.nt5_ex.pdc_name);
        CHECK_STRING(search.out.netlogon.data.nt5_ex.user_name, search.in.user);
+       CHECK_STRING(search.out.netlogon.data.nt5_ex.server_site, n1.data.nt5_ex.server_site);
+       CHECK_STRING(search.out.netlogon.data.nt5_ex.client_site, n1.data.nt5_ex.client_site);
 
        printf("Trying with just a bad username\n");
        search.in.user = "___no_such_user___";
        status = cldap_netlogon(cldap, tctx, &search);
        CHECK_STATUS(status, NT_STATUS_OK);
-       CHECK_STRING(search.out.netlogon.data.nt5_ex.user_name, search.in.user);
-       CHECK_STRING(search.out.netlogon.data.nt5_ex.dns_domain, n1.data.nt5_ex.dns_domain);
        CHECK_VAL(search.out.netlogon.data.nt5_ex.command, LOGON_SAM_LOGON_USER_UNKNOWN_EX);
+       CHECK_STRING(search.out.netlogon.data.nt5_ex.forest, n1.data.nt5_ex.dns_domain);
+       CHECK_STRING(search.out.netlogon.data.nt5_ex.dns_domain, n1.data.nt5_ex.dns_domain);
+       CHECK_STRING(search.out.netlogon.data.nt5_ex.domain_name, n1.data.nt5_ex.domain_name);
+       CHECK_STRING(search.out.netlogon.data.nt5_ex.pdc_name, n1.data.nt5_ex.pdc_name);
+       CHECK_STRING(search.out.netlogon.data.nt5_ex.user_name, search.in.user);
+       CHECK_STRING(search.out.netlogon.data.nt5_ex.server_site, n1.data.nt5_ex.server_site);
+       CHECK_STRING(search.out.netlogon.data.nt5_ex.client_site, n1.data.nt5_ex.client_site);
 
        printf("Trying with just a bad domain\n");
        search = empty_search;
@@ -204,26 +218,53 @@ static bool test_cldap_netlogon(struct torture_context *tctx, const char *dest)
        search.in.domain_guid = GUID_string(tctx, &n1.data.nt5_ex.domain_uuid);
        status = cldap_netlogon(cldap, tctx, &search);
        CHECK_STATUS(status, NT_STATUS_OK);
+       CHECK_VAL(search.out.netlogon.data.nt5_ex.command, LOGON_SAM_LOGON_RESPONSE_EX);
+       CHECK_STRING(search.out.netlogon.data.nt5_ex.forest, n1.data.nt5_ex.dns_domain);
        CHECK_STRING(search.out.netlogon.data.nt5_ex.dns_domain, n1.data.nt5_ex.dns_domain);
+       CHECK_STRING(search.out.netlogon.data.nt5_ex.domain_name, n1.data.nt5_ex.domain_name);
+       CHECK_STRING(search.out.netlogon.data.nt5_ex.pdc_name, n1.data.nt5_ex.pdc_name);
        CHECK_STRING(search.out.netlogon.data.nt5_ex.user_name, "");
-       CHECK_VAL(search.out.netlogon.data.nt5_ex.command, LOGON_SAM_LOGON_RESPONSE_EX);
+       CHECK_STRING(search.out.netlogon.data.nt5_ex.server_site, n1.data.nt5_ex.server_site);
+       CHECK_STRING(search.out.netlogon.data.nt5_ex.client_site, n1.data.nt5_ex.client_site);
 
        printf("Trying with a incorrect domain and incorrect guid\n");
        search.in.domain_guid = GUID_string(tctx, &guid);
        status = cldap_netlogon(cldap, tctx, &search);
        CHECK_STATUS(status, NT_STATUS_NOT_FOUND);
+       CHECK_VAL(search.out.netlogon.data.nt5_ex.command, LOGON_SAM_LOGON_RESPONSE_EX);
+       CHECK_STRING(search.out.netlogon.data.nt5_ex.forest, n1.data.nt5_ex.dns_domain);
        CHECK_STRING(search.out.netlogon.data.nt5_ex.dns_domain, n1.data.nt5_ex.dns_domain);
+       CHECK_STRING(search.out.netlogon.data.nt5_ex.domain_name, n1.data.nt5_ex.domain_name);
+       CHECK_STRING(search.out.netlogon.data.nt5_ex.pdc_name, n1.data.nt5_ex.pdc_name);
        CHECK_STRING(search.out.netlogon.data.nt5_ex.user_name, "");
-       CHECK_VAL(search.out.netlogon.data.nt5_ex.command, LOGON_SAM_LOGON_RESPONSE_EX);
+       CHECK_STRING(search.out.netlogon.data.nt5_ex.server_site, n1.data.nt5_ex.server_site);
+       CHECK_STRING(search.out.netlogon.data.nt5_ex.client_site, n1.data.nt5_ex.client_site);
 
        printf("Trying with a incorrect GUID and correct domain\n");
        search.in.domain_guid = GUID_string(tctx, &guid);
        search.in.realm = n1.data.nt5_ex.dns_domain;
        status = cldap_netlogon(cldap, tctx, &search);
        CHECK_STATUS(status, NT_STATUS_OK);
+       CHECK_VAL(search.out.netlogon.data.nt5_ex.command, LOGON_SAM_LOGON_RESPONSE_EX);
+       CHECK_STRING(search.out.netlogon.data.nt5_ex.forest, n1.data.nt5_ex.dns_domain);
        CHECK_STRING(search.out.netlogon.data.nt5_ex.dns_domain, n1.data.nt5_ex.dns_domain);
+       CHECK_STRING(search.out.netlogon.data.nt5_ex.domain_name, n1.data.nt5_ex.domain_name);
+       CHECK_STRING(search.out.netlogon.data.nt5_ex.pdc_name, n1.data.nt5_ex.pdc_name);
        CHECK_STRING(search.out.netlogon.data.nt5_ex.user_name, "");
-       CHECK_VAL(search.out.netlogon.data.nt5_ex.command, LOGON_SAM_LOGON_RESPONSE_EX);
+       CHECK_STRING(search.out.netlogon.data.nt5_ex.server_site, n1.data.nt5_ex.server_site);
+       CHECK_STRING(search.out.netlogon.data.nt5_ex.client_site, n1.data.nt5_ex.client_site);
+
+       printf("Proof other results\n");
+       search.in.user = "Administrator";
+       status = cldap_netlogon(cldap, tctx, &search);
+       CHECK_STATUS(status, NT_STATUS_OK);
+       CHECK_STRING(search.out.netlogon.data.nt5_ex.forest, n1.data.nt5_ex.dns_domain);
+       CHECK_STRING(search.out.netlogon.data.nt5_ex.dns_domain, n1.data.nt5_ex.dns_domain);
+       CHECK_STRING(search.out.netlogon.data.nt5_ex.domain_name, n1.data.nt5_ex.domain_name);
+       CHECK_STRING(search.out.netlogon.data.nt5_ex.pdc_name, n1.data.nt5_ex.pdc_name);
+       CHECK_STRING(search.out.netlogon.data.nt5_ex.user_name, search.in.user);
+       CHECK_STRING(search.out.netlogon.data.nt5_ex.server_site, n1.data.nt5_ex.server_site);
+       CHECK_STRING(search.out.netlogon.data.nt5_ex.client_site, n1.data.nt5_ex.client_site);
 
        return true;
 }
@@ -239,14 +280,24 @@ static bool test_cldap_netlogon_flags(struct torture_context *tctx,
        struct cldap_netlogon search;
        struct netlogon_samlogon_response n1;
        uint32_t server_type;
+       struct tsocket_address *dest_addr;
+       int ret;
 
-       cldap = cldap_socket_init(tctx, tctx->ev, lp_iconv_convenience(tctx->lp_ctx));
+       ret = tsocket_address_inet_from_strings(tctx, "ip",
+                                               dest,
+                                               lpcfg_cldap_port(tctx->lp_ctx),
+                                               &dest_addr);
+       CHECK_VAL(ret, 0);
+
+       /* cldap_socket_init should now know about the dest. address */
+       status = cldap_socket_init(tctx, NULL, dest_addr, &cldap);
+       CHECK_STATUS(status, NT_STATUS_OK);
 
-       printf("Printing out netlogon server type flags:\n");
+       printf("Printing out netlogon server type flags: %s\n", dest);
 
        ZERO_STRUCT(search);
-       search.in.dest_address = dest;
-       search.in.dest_port = lp_cldap_port(tctx->lp_ctx);
+       search.in.dest_address = NULL;
+       search.in.dest_port = 0;
        search.in.acct_control = -1;
        search.in.version = NETLOGON_NT_VERSION_5 | NETLOGON_NT_VERSION_5EX;
        search.in.map_response = true;
@@ -289,8 +340,8 @@ static bool test_cldap_netlogon_flags(struct torture_context *tctx,
                printf("DS_DNS_CONTROLLER ");
        if (server_type & DS_DNS_DOMAIN)
                printf("DS_DNS_DOMAIN ");
-       if (server_type & DS_DNS_FOREST)
-               printf("DS_DNS_FOREST ");
+       if (server_type & DS_DNS_FOREST_ROOT)
+               printf("DS_DNS_FOREST_ROOT ");
 
        printf("\n");
 
@@ -336,81 +387,6 @@ static void cldap_dump_results(struct cldap_search *search)
        talloc_free(ldb);
 }
 
-
-/*
-  test cldap netlogon server type flag "NBT_SERVER_DS_DNS_FOREST"
-*/
-static bool test_cldap_netlogon_flag_ds_dns_forest(struct torture_context *tctx,
-       const char *dest)
-{
-       struct cldap_socket *cldap;
-       NTSTATUS status;
-       struct cldap_netlogon search;
-       uint32_t server_type;
-       struct netlogon_samlogon_response n1;
-
-       bool result = true;
-
-       cldap = cldap_socket_init(tctx, tctx->ev, lp_iconv_convenience(tctx->lp_ctx));
-
-       printf("Testing netlogon server type flag NBT_SERVER_DS_DNS_FOREST: ");
-
-       ZERO_STRUCT(search);
-       search.in.dest_address = dest;
-       search.in.dest_port = lp_cldap_port(tctx->lp_ctx);
-       search.in.acct_control = -1;
-       search.in.version = NETLOGON_NT_VERSION_5 | NETLOGON_NT_VERSION_5EX;
-       search.in.map_response = true;
-
-       status = cldap_netlogon(cldap, tctx, &search);
-       CHECK_STATUS(status, NT_STATUS_OK);
-
-       n1 = search.out.netlogon;
-       if (n1.ntver == NETLOGON_NT_VERSION_5)
-               server_type = n1.data.nt5.server_type;
-       else if (n1.ntver == NETLOGON_NT_VERSION_5EX)
-               server_type = n1.data.nt5_ex.server_type;
-
-       if (server_type & DS_DNS_FOREST) {
-               struct cldap_search search2;
-               const char *attrs[] = { "defaultNamingContext", "rootDomainNamingContext", 
-                       NULL };
-               struct ldb_context *ldb;
-               struct ldb_message *msg;
-
-               /* Trying to fetch the attributes "defaultNamingContext" and
-                  "rootDomainNamingContext" */
-               ZERO_STRUCT(search2);
-               search2.in.dest_address = dest;
-               search2.in.dest_port = lp_cldap_port(tctx->lp_ctx);
-               search2.in.timeout = 10;
-               search2.in.retries = 3;
-               search2.in.filter = "(objectclass=*)";
-               search2.in.attributes = attrs;
-
-               status = cldap_search(cldap, tctx, &search2);
-               CHECK_STATUS(status, NT_STATUS_OK);
-
-               ldb = ldb_init(NULL, NULL);
-
-               msg = ldap_msg_to_ldb(ldb, ldb, search2.out.response);
-
-               /* Try to compare the two attributes */
-               if (ldb_msg_element_compare(ldb_msg_find_element(msg, attrs[0]),
-                       ldb_msg_find_element(msg, attrs[1])))
-                       result = false;
-
-               talloc_free(ldb);
-       }
-
-       if (result)
-               printf("passed\n");
-       else
-               printf("failed\n");
-
-       return result;
-}
-
 /*
   test generic cldap operations
 */
@@ -422,12 +398,22 @@ static bool test_cldap_generic(struct torture_context *tctx, const char *dest)
        const char *attrs1[] = { "currentTime", "highestCommittedUSN", NULL };
        const char *attrs2[] = { "currentTime", "highestCommittedUSN", "netlogon", NULL };
        const char *attrs3[] = { "netlogon", NULL };
+       struct tsocket_address *dest_addr;
+       int ret;
 
-       cldap = cldap_socket_init(tctx, tctx->ev, lp_iconv_convenience(tctx->lp_ctx));
+       ret = tsocket_address_inet_from_strings(tctx, "ip",
+                                               dest,
+                                               lpcfg_cldap_port(tctx->lp_ctx),
+                                               &dest_addr);
+       CHECK_VAL(ret, 0);
+
+       /* cldap_socket_init should now know about the dest. address */
+       status = cldap_socket_init(tctx, NULL, dest_addr, &cldap);
+       CHECK_STATUS(status, NT_STATUS_OK);
 
        ZERO_STRUCT(search);
-       search.in.dest_address = dest;
-       search.in.dest_port = lp_cldap_port(tctx->lp_ctx);
+       search.in.dest_address = NULL;
+       search.in.dest_port = 0;
        search.in.timeout = 10;
        search.in.retries = 3;
 
@@ -489,7 +475,6 @@ bool torture_cldap(struct torture_context *torture)
 
        ret &= test_cldap_netlogon(torture, host);
        ret &= test_cldap_netlogon_flags(torture, host);
-       ret &= test_cldap_netlogon_flag_ds_dns_forest(torture, host);
        ret &= test_cldap_generic(torture, host);
 
        return ret;