s4:torture: Migrate smbtorture to new cmdline option parser
[samba.git] / source4 / torture / rpc / dsgetinfo.c
index 7fdbdc470af14d1da572a6d8b2b9f57d12ddfcd0..b47d6ee9e5348bc6ce15b2dc2f37f06bc87ad100 100644 (file)
@@ -20,7 +20,7 @@
 */
 
 #include "includes.h"
-#include "lib/cmdline/popt_common.h"
+#include "lib/cmdline/cmdline.h"
 #include "librpc/gen_ndr/ndr_drsuapi_c.h"
 #include "librpc/gen_ndr/ndr_drsblobs.h"
 #include "libcli/cldap/cldap.h"
@@ -29,9 +29,9 @@
 #include "auth/gensec/gensec.h"
 #include "param/param.h"
 #include "dsdb/samdb/samdb.h"
-#include "lib/ldb_wrap.h"
-#include "torture/rpc/rpc.h"
+#include "torture/rpc/torture_rpc.h"
 #include "torture/drs/proto.h"
+#include "lib/util/util_paths.h"
 
 
 struct DsGetinfoBindInfo {
@@ -68,7 +68,7 @@ struct DsGetinfoTest {
  */
 static const char *torture_get_ldap_base_dn(struct torture_context *tctx, struct dcerpc_pipe *p)
 {
-       const char *hostname = p->binding->host;
+       const char *hostname = dcerpc_binding_get_string_option(p->binding, "host");
        struct ldb_context *ldb;
        const char *ldap_url = talloc_asprintf(p, "ldap://%s", hostname);
        const char *attrs[] = { "defaultNamingContext", NULL };
@@ -88,6 +88,9 @@ static const char *torture_get_ldap_base_dn(struct torture_context *tctx, struct
                return NULL;
        }
 
+       ldb_set_modules_dir(ldb,
+                           modules_path(ldb, "ldb"));
+
        ret = ldb_connect(ldb, ldap_url, 0, NULL);
        if (ret != LDB_SUCCESS) {
                torture_comment(tctx, "Failed to make LDB connection to target");
@@ -125,10 +128,14 @@ static struct DsGetinfoTest *test_create_context(struct torture_context *tctx)
                printf("Bad binding string %s\n", binding);
                return NULL;
        }
-       ctx->drsuapi_binding->flags |= DCERPC_SIGN | DCERPC_SEAL;
+       status = dcerpc_binding_set_flags(ctx->drsuapi_binding, DCERPC_SIGN | DCERPC_SEAL, 0);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("dcerpc_binding_set_flags - %s\n", nt_errstr(status));
+               return NULL;
+       }
 
        /* ctx->admin ...*/
-       ctx->admin.credentials                          = cmdline_credentials;
+       ctx->admin.credentials = samba_cmdline_get_creds();
 
        our_bind_info28                         = &ctx->admin.drsuapi.our_bind_info28;
        our_bind_info28->supported_extensions   = 0xFFFFFFFF;
@@ -170,9 +177,6 @@ static bool _test_DsBind(struct torture_context *tctx,
        status = dcerpc_drsuapi_DsBind_r(b->drs_handle, ctx, &b->req);
        if (!NT_STATUS_IS_OK(status)) {
                const char *errstr = nt_errstr(status);
-               if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
-                       errstr = dcerpc_errstr(ctx, b->drs_pipe->last_fault_code);
-               }
                printf("dcerpc_drsuapi_DsBind failed - %s\n", errstr);
                ret = false;
        } else if (!W_ERROR_IS_OK(b->req.out.result)) {
@@ -192,6 +196,19 @@ static bool _test_DsBind(struct torture_context *tctx,
                        b->peer_bind_info28.repl_epoch          = 0;
                        break;
                }
+               case 28: {
+                       b->peer_bind_info28 = b->req.out.bind_info->info.info28;
+                       break;
+               }
+               case 32: {
+                       struct drsuapi_DsBindInfo32 *info32;
+                       info32 = &b->req.out.bind_info->info.info32;
+                       b->peer_bind_info28.supported_extensions= info32->supported_extensions;
+                       b->peer_bind_info28.site_guid           = info32->site_guid;
+                       b->peer_bind_info28.pid                 = info32->pid;
+                       b->peer_bind_info28.repl_epoch          = info32->repl_epoch;
+                       break;
+               }
                case 48: {
                        struct drsuapi_DsBindInfo48 *info48;
                        info48 = &b->req.out.bind_info->info.info48;
@@ -201,9 +218,15 @@ static bool _test_DsBind(struct torture_context *tctx,
                        b->peer_bind_info28.repl_epoch          = info48->repl_epoch;
                        break;
                }
-               case 28:
-                       b->peer_bind_info28 = b->req.out.bind_info->info.info28;
+               case 52: {
+                       struct drsuapi_DsBindInfo52 *info52;
+                       info52 = &b->req.out.bind_info->info.info52;
+                       b->peer_bind_info28.supported_extensions= info52->supported_extensions;
+                       b->peer_bind_info28.site_guid           = info52->site_guid;
+                       b->peer_bind_info28.pid                 = info52->pid;
+                       b->peer_bind_info28.repl_epoch          = info52->repl_epoch;
                        break;
+               }
                default:
                        printf("DsBind - warning: unknown BindInfo length: %u\n",
                               b->req.out.bind_info->length);
@@ -225,7 +248,7 @@ static bool test_getinfo(struct torture_context *tctx,
        union drsuapi_DsReplicaInfo info;
        enum drsuapi_DsReplicaInfoType info_type;
        int i;
-       int invalid_levels = 0;
+       bool no_invalid_levels = true;
        struct {
                int32_t level;
                int32_t infotype;
@@ -302,7 +325,7 @@ static bool test_getinfo(struct torture_context *tctx,
        for (i=0; i < ARRAY_SIZE(array); i++) {
                const char *object_dn;
 
-               torture_comment(tctx, "testing DsReplicaGetInfo level %d infotype %d\n",
+               torture_comment(tctx, "Testing DsReplicaGetInfo level %d infotype %d\n",
                                array[i].level, array[i].infotype);
 
                if (array[i].obj_dn) {
@@ -345,27 +368,28 @@ static bool test_getinfo(struct torture_context *tctx,
                r.out.info_type         = &info_type;
 
                status = dcerpc_drsuapi_DsReplicaGetInfo_r(b, tctx, &r);
-
+               if (NT_STATUS_EQUAL(status, NT_STATUS_RPC_ENUM_VALUE_OUT_OF_RANGE)) {
+                       torture_comment(tctx,
+                                       "DsReplicaGetInfo level %d and/or infotype %d not supported by server\n",
+                                       array[i].level, array[i].infotype);
+                       continue;
+               }
+               torture_assert_ntstatus_ok(tctx, status, talloc_asprintf(tctx,
+                                       "DsReplicaGetInfo level %d and/or infotype %d failed\n",
+                                       array[i].level, array[i].infotype));
                if (W_ERROR_EQUAL(r.out.result, WERR_INVALID_LEVEL)) {
                        /* this is a not yet supported level */
                        torture_comment(tctx,
                                        "DsReplicaGetInfo level %d and/or infotype %d not yet supported by server\n",
                                        array[i].level, array[i].infotype);
-                       invalid_levels++;
-               } else if (!NT_STATUS_IS_OK(status) && p->last_fault_code == DCERPC_FAULT_INVALID_TAG) {
-                       torture_comment(tctx,
-                                       "DsReplicaGetInfo level %d and/or infotype %d not supported by server\n",
-                                       array[i].level, array[i].infotype);
-               }/* else {
-                       torture_drsuapi_assert_call(tctx, p, status, &r, "dcerpc_drsuapi_DsReplicaGetInfo");
-               }*/
-       }
+                       no_invalid_levels = false;
+                       continue;
+               }
 
-       if (invalid_levels > 0) {
-               return false;
+               torture_drsuapi_assert_call(tctx, p, status, &r, "dcerpc_drsuapi_DsReplicaGetInfo");
        }
 
-       return true;
+       return no_invalid_levels;
 }
 
 /**
@@ -401,7 +425,10 @@ static bool torture_dsgetinfo_tcase_teardown(struct torture_context *tctx, void
 
        /* Unbing admin handle */
        r.in.bind_handle = &ctx->admin.drsuapi.bind_handle;
-       dcerpc_drsuapi_DsUnbind_r(ctx->admin.drsuapi.drs_handle, ctx, &r);
+       if (ctx->admin.drsuapi.drs_handle) {
+               dcerpc_drsuapi_DsUnbind_r(ctx->admin.drsuapi.drs_handle,
+                                         ctx, &r);
+       }
 
        talloc_free(ctx);
 
@@ -414,14 +441,12 @@ static bool torture_dsgetinfo_tcase_teardown(struct torture_context *tctx, void
 void torture_drs_rpc_dsgetinfo_tcase(struct torture_suite *suite)
 {
        typedef bool (*run_func) (struct torture_context *test, void *tcase_data);
-
-       struct torture_test *test;
-       struct torture_tcase *tcase = torture_suite_add_tcase(suite, "DSGETINFO");
+       struct torture_tcase *tcase = torture_suite_add_tcase(suite, "dsgetinfo");
 
        torture_tcase_set_fixture(tcase,
                                  torture_dsgetinfo_tcase_setup,
                                  torture_dsgetinfo_tcase_teardown);
 
-       test = torture_tcase_add_simple_test(tcase, "DsGetReplicaInfo", (run_func)test_getinfo);
+       torture_tcase_add_simple_test(tcase, "DsGetReplicaInfo", (run_func)test_getinfo);
 }