s4:torture/rpc: make use of dcerpc_binding_set_flags()
[samba.git] / source4 / torture / rpc / bind.c
index 71d3489ca42677b5284d1ff5ceeaa1605c00c99d..f20af4afb10bb7c5ae0f1e6d2ad1870c45edc7ba 100644 (file)
-/* 
+/*
    Unix SMB/CIFS implementation.
+   test suite for rpc bind operations
 
-   dcerpc torture tests
-
-   Copyright (C) Andrew Tridgell 2003
-   Copyright (C) Andrew Bartlett <abartlet@samba.org 2004
+   Copyright (C) Guenther Deschner 2010
 
    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
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
-   
+
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
-   
+
    You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
 
 #include "includes.h"
-#include "torture/torture.h"
-#include "librpc/gen_ndr/ndr_lsa.h"
+#include "torture/rpc/torture_rpc.h"
 #include "librpc/gen_ndr/ndr_lsa_c.h"
 #include "lib/cmdline/popt_common.h"
-#include "librpc/rpc/dcerpc.h"
-#include "torture/rpc/rpc.h"
-#include "libcli/libcli.h"
-#include "libcli/composite/composite.h"
-#include "libcli/smb_composite/smb_composite.h"
 
-/*
-  This test is 'bogus' in that it doesn't actually perform to the
-  spec.  We need to deal with other things inside the DCERPC layer,
-  before we could have multiple binds.
+static bool test_openpolicy(struct torture_context *tctx,
+                           struct dcerpc_pipe *p)
+{
+       struct dcerpc_binding_handle *b = p->binding_handle;
+       struct policy_handle *handle;
 
-  We should never pass this test, until such details are fixed in our
-  client, and it looks like multible binds are never used anyway.
+       torture_assert(tctx,
+               test_lsa_OpenPolicy2(b, tctx, &handle),
+               "failed to open policy");
 
-*/
+       torture_assert(tctx,
+               test_lsa_Close(b, tctx, handle),
+               "failed to close policy");
 
-BOOL torture_multi_bind(struct torture_context *torture) 
+       return true;
+}
+
+static bool test_bind(struct torture_context *tctx,
+                     const void *private_data)
 {
-       struct dcerpc_pipe *p;
        struct dcerpc_binding *binding;
-       const char *binding_string = torture_setting_string(torture, "binding", NULL);
-       TALLOC_CTX *mem_ctx;
+       struct dcerpc_pipe *p;
        NTSTATUS status;
-       BOOL ret;
+       const uint32_t *flags = (const uint32_t *)private_data;
 
-       mem_ctx = talloc_init("torture_multi_bind");
+       torture_assert_ntstatus_ok(tctx,
+               torture_rpc_binding(tctx, &binding),
+               "failed to parse binding string");
 
-       status = dcerpc_parse_binding(mem_ctx, binding_string, &binding);
-       if (!NT_STATUS_IS_OK(status)) {
-               printf("Failed to parse dcerpc binding '%s'\n", binding_string);
-               talloc_free(mem_ctx);
-               return False;
-       }
+       status = dcerpc_binding_set_flags(binding, *flags, DCERPC_AUTH_OPTIONS);
+       torture_assert_ntstatus_ok(tctx, status, "set flags");
 
-       status = torture_rpc_connection(mem_ctx, &p, &ndr_table_lsarpc);
-       
-       if (!NT_STATUS_IS_OK(status)) {
-               talloc_free(mem_ctx);
-               return False;
-       }
+       torture_assert_ntstatus_ok(tctx,
+               dcerpc_pipe_connect_b(tctx, &p, binding,
+                                     &ndr_table_lsarpc,
+                                     cmdline_credentials,
+                                     tctx->ev,
+                                     tctx->lp_ctx),
+               "failed to connect pipe");
 
-       status = dcerpc_pipe_auth(mem_ctx, &p, binding, &ndr_table_lsarpc, cmdline_credentials);
+       torture_assert(tctx,
+               test_openpolicy(tctx, p),
+               "failed to test openpolicy");
 
-       if (NT_STATUS_IS_OK(status)) {
-               printf("(incorrectly) allowed re-bind to uuid %s - %s\n", 
-                       GUID_string(mem_ctx, &ndr_table_lsarpc.syntax_id.uuid), nt_errstr(status));
-               ret = False;
-       } else {
-               printf("\n");
-               ret = True;
-       }
+       talloc_free(p);
+
+       return true;
+}
 
-       talloc_free(mem_ctx);
+static void test_bind_op(struct torture_suite *suite,
+                        const char *name,
+                        uint32_t flags)
+{
+       uint32_t *flags_p = talloc(suite, uint32_t);
+
+       *flags_p = flags;
+
+       torture_suite_add_simple_tcase_const(suite, name, test_bind, flags_p);
+}
+
+
+struct torture_suite *torture_rpc_bind(TALLOC_CTX *mem_ctx)
+{
+       struct torture_suite *suite = torture_suite_create(mem_ctx, "bind");
+       struct {
+               const char *test_name;
+               uint32_t flags;
+       } tests[] = {
+               {
+                       .test_name      = "ntlm,sign",
+                       .flags          = DCERPC_AUTH_NTLM | DCERPC_SIGN
+               },{
+                       .test_name      = "ntlm,sign,seal",
+                       .flags          = DCERPC_AUTH_NTLM | DCERPC_SIGN | DCERPC_SEAL
+               },{
+                       .test_name      = "spnego,sign",
+                       .flags          = DCERPC_AUTH_SPNEGO | DCERPC_SIGN
+               },{
+                       .test_name      = "spnego,sign,seal",
+                       .flags          = DCERPC_AUTH_SPNEGO | DCERPC_SIGN | DCERPC_SEAL
+               }
+       };
+       int i;
+
+       for (i=0; i < ARRAY_SIZE(tests); i++) {
+               test_bind_op(suite, tests[i].test_name, tests[i].flags);
+       }
+       for (i=0; i < ARRAY_SIZE(tests); i++) {
+               test_bind_op(suite, talloc_asprintf(suite, "bigendian,%s", tests[i].test_name), tests[i].flags | DCERPC_PUSH_BIGENDIAN);
+       }
 
-       return ret;
+       return suite;
 }