r26682: Move CLDAP to the modern torture system, and add value checking.
[samba.git] / source / torture / ldap / cldap.c
index ddb966683f1afd80b15e5952a8fafb0df6e45e44..bea4b08c8baee87c63db22a33356181bd094800f 100644 (file)
 #include "lib/ldb/include/ldb.h"
 #include "param/param.h"
 
-#define CHECK_STATUS(status, correct) do { \
-       if (!NT_STATUS_EQUAL(status, correct)) { \
-               printf("(%s) Incorrect status %s - should be %s\n", \
-                      __location__, nt_errstr(status), nt_errstr(correct)); \
-               ret = false; \
-               goto done; \
-       } \
-} while (0)
+#define CHECK_STATUS(status, correct) torture_assert_ntstatus_equal(tctx, status, correct, "incorrect status")
 
+#define CHECK_VAL(v, correct) torture_assert_int_equal(tctx, (v), (correct), "incorrect value");
+
+#define CHECK_STRING(v, correct) torture_assert_str_equal(tctx, v, correct, "incorrect value");
 /*
   test netlogon operations
 */
-static bool test_cldap_netlogon(TALLOC_CTX *mem_ctx, const char *dest)
+static bool test_cldap_netlogon(struct torture_context *tctx, const char *dest)
 {
-       struct cldap_socket *cldap = cldap_socket_init(mem_ctx, NULL);
+       struct cldap_socket *cldap = cldap_socket_init(tctx, NULL);
        NTSTATUS status;
        struct cldap_netlogon search, empty_search;
        union nbt_cldap_netlogon n1;
        struct GUID guid;
        int i;
-       bool ret = true;
 
        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 = 6;
 
@@ -59,7 +55,7 @@ static bool test_cldap_netlogon(TALLOC_CTX *mem_ctx, const char *dest)
 
        printf("Trying without any attributes\n");
        search = empty_search;
-       status = cldap_netlogon(cldap, mem_ctx, &search);
+       status = cldap_netlogon(cldap, tctx, &search);
        CHECK_STATUS(status, NT_STATUS_OK);
 
        n1 = search.out.netlogon;
@@ -72,7 +68,7 @@ static bool test_cldap_netlogon(TALLOC_CTX *mem_ctx, const char *dest)
        for (i=0;i<256;i++) {
                search.in.version = i;
                printf("Trying netlogon level %d\n", i);
-               status = cldap_netlogon(cldap, mem_ctx, &search);
+               status = cldap_netlogon(cldap, tctx, &search);
                CHECK_STATUS(status, NT_STATUS_OK);
        }
 
@@ -80,86 +76,107 @@ static bool test_cldap_netlogon(TALLOC_CTX *mem_ctx, const char *dest)
        for (i=0;i<31;i++) {
                search.in.version = (1<<i);
                printf("Trying netlogon level 0x%x\n", i);
-               status = cldap_netlogon(cldap, mem_ctx, &search);
+               status = cldap_netlogon(cldap, tctx, &search);
                CHECK_STATUS(status, NT_STATUS_OK);
        }
 
        search.in.version = 6;
-       status = cldap_netlogon(cldap, mem_ctx, &search);
+       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, mem_ctx, &search);
+       status = cldap_netlogon(cldap, tctx, &search);
        CHECK_STATUS(status, NT_STATUS_OK);
+       CHECK_STRING(search.out.netlogon.logon5.user_name, "");
+       CHECK_VAL(search.out.netlogon.logon5.type, NETLOGON_RESPONSE_FROM_PDC2);
 
        printf("Trying with User=Administrator\n");
 
        search.in.user = "Administrator";
-       status = cldap_netlogon(cldap, mem_ctx, &search);
+       status = cldap_netlogon(cldap, tctx, &search);
        CHECK_STATUS(status, NT_STATUS_OK);
 
+       CHECK_STRING(search.out.netlogon.logon5.user_name, search.in.user);
+       CHECK_VAL(search.out.netlogon.logon5.type, NETLOGON_RESPONSE_FROM_PDC_USER);
+
        printf("Trying with a GUID\n");
        search.in.realm       = NULL;
-       search.in.domain_guid = GUID_string(mem_ctx, &n1.logon5.domain_uuid);
-       status = cldap_netlogon(cldap, mem_ctx, &search);
+       search.in.domain_guid = GUID_string(tctx, &n1.logon5.domain_uuid);
+       status = cldap_netlogon(cldap, tctx, &search);
        CHECK_STATUS(status, NT_STATUS_OK);
+       CHECK_VAL(search.out.netlogon.logon5.type, NETLOGON_RESPONSE_FROM_PDC_USER);
+       CHECK_STRING(GUID_string(tctx, &search.out.netlogon.logon5.domain_uuid), search.in.domain_guid);
 
        printf("Trying with a incorrect GUID\n");
        guid = GUID_random();
        search.in.user        = NULL;
-       search.in.domain_guid = GUID_string(mem_ctx, &guid);
-       status = cldap_netlogon(cldap, mem_ctx, &search);
+       search.in.domain_guid = GUID_string(tctx, &guid);
+       status = cldap_netlogon(cldap, tctx, &search);
        CHECK_STATUS(status, NT_STATUS_NOT_FOUND);
 
        printf("Trying with a AAC\n");
        search.in.acct_control = 0x180;
        search.in.realm = n1.logon5.dns_domain;
-       status = cldap_netlogon(cldap, mem_ctx, &search);
+       status = cldap_netlogon(cldap, tctx, &search);
        CHECK_STATUS(status, NT_STATUS_OK);
+       CHECK_VAL(search.out.netlogon.logon5.type, NETLOGON_RESPONSE_FROM_PDC2);
+       CHECK_STRING(search.out.netlogon.logon5.user_name, "");
 
        printf("Trying with a bad AAC\n");
        search.in.acct_control = 0xFF00FF00;
        search.in.realm = n1.logon5.dns_domain;
-       status = cldap_netlogon(cldap, mem_ctx, &search);
+       status = cldap_netlogon(cldap, tctx, &search);
        CHECK_STATUS(status, NT_STATUS_OK);
 
        printf("Trying with a user only\n");
        search = empty_search;
        search.in.user = "Administrator";
-       status = cldap_netlogon(cldap, mem_ctx, &search);
+       status = cldap_netlogon(cldap, tctx, &search);
        CHECK_STATUS(status, NT_STATUS_OK);
+       CHECK_STRING(search.out.netlogon.logon5.dns_domain, n1.logon5.dns_domain);
+       CHECK_STRING(search.out.netlogon.logon5.user_name, search.in.user);
 
        printf("Trying with just a bad username\n");
        search.in.user = "___no_such_user___";
-       status = cldap_netlogon(cldap, mem_ctx, &search);
+       status = cldap_netlogon(cldap, tctx, &search);
        CHECK_STATUS(status, NT_STATUS_OK);
+       CHECK_STRING(search.out.netlogon.logon5.user_name, search.in.user);
+       CHECK_STRING(search.out.netlogon.logon5.dns_domain, n1.logon5.dns_domain);
 
        printf("Trying with just a bad domain\n");
        search = empty_search;
        search.in.realm = "___no_such_domain___";
-       status = cldap_netlogon(cldap, mem_ctx, &search);
+       status = cldap_netlogon(cldap, tctx, &search);
        CHECK_STATUS(status, NT_STATUS_NOT_FOUND);
 
        printf("Trying with a incorrect domain and correct guid\n");
-       search.in.domain_guid = GUID_string(mem_ctx, &n1.logon5.domain_uuid);
-       status = cldap_netlogon(cldap, mem_ctx, &search);
+       search.in.domain_guid = GUID_string(tctx, &n1.logon5.domain_uuid);
+       status = cldap_netlogon(cldap, tctx, &search);
        CHECK_STATUS(status, NT_STATUS_OK);
+       CHECK_STRING(search.out.netlogon.logon5.dns_domain, n1.logon5.dns_domain);
+       CHECK_STRING(search.out.netlogon.logon5.user_name, "");
+       CHECK_VAL(search.out.netlogon.logon5.type, NETLOGON_RESPONSE_FROM_PDC2);
 
        printf("Trying with a incorrect domain and incorrect guid\n");
-       search.in.domain_guid = GUID_string(mem_ctx, &guid);
-       status = cldap_netlogon(cldap, mem_ctx, &search);
+       search.in.domain_guid = GUID_string(tctx, &guid);
+       status = cldap_netlogon(cldap, tctx, &search);
        CHECK_STATUS(status, NT_STATUS_NOT_FOUND);
+       CHECK_STRING(search.out.netlogon.logon5.dns_domain, n1.logon5.dns_domain);
+       CHECK_STRING(search.out.netlogon.logon5.user_name, "");
+       CHECK_VAL(search.out.netlogon.logon5.type, NETLOGON_RESPONSE_FROM_PDC2);
 
        printf("Trying with a incorrect GUID and correct domain\n");
-       search.in.domain_guid = GUID_string(mem_ctx, &guid);
+       search.in.domain_guid = GUID_string(tctx, &guid);
        search.in.realm = n1.logon5.dns_domain;
-       status = cldap_netlogon(cldap, mem_ctx, &search);
+       status = cldap_netlogon(cldap, tctx, &search);
        CHECK_STATUS(status, NT_STATUS_OK);
+       CHECK_STRING(search.out.netlogon.logon5.dns_domain, n1.logon5.dns_domain);
+       CHECK_STRING(search.out.netlogon.logon5.user_name, "");
+       CHECK_VAL(search.out.netlogon.logon5.type, NETLOGON_RESPONSE_FROM_PDC2);
 
-done:
-       return ret;     
+       return true;
 }
 
 /*
@@ -209,7 +226,6 @@ static bool test_cldap_generic(struct torture_context *tctx, const char *dest)
        struct cldap_socket *cldap = cldap_socket_init(tctx, NULL);
        NTSTATUS status;
        struct cldap_search search;
-       bool ret = true;
        const char *attrs1[] = { "currentTime", "highestCommittedUSN", NULL };
        const char *attrs2[] = { "currentTime", "highestCommittedUSN", "netlogon", NULL };
        const char *attrs3[] = { "netlogon", NULL };
@@ -268,8 +284,7 @@ static bool test_cldap_generic(struct torture_context *tctx, const char *dest)
 
        if (DEBUGLVL(3)) cldap_dump_results(&search);   
 
-done:
-       return ret;     
+       return true;    
 }
 
 bool torture_cldap(struct torture_context *torture)