s4:torture/rpc: avoid compiler warnings
[garming/samba-autobuild/.git] / source4 / torture / rpc / schannel.c
index 0098dcf648db1134f73e8f81b5797efc56e9b10c..fb8af5fba0fcc4ef4dc5e18fa33d59c61961ab10 100644 (file)
@@ -59,7 +59,7 @@ bool test_netlogon_ex_ops(struct dcerpc_pipe *p, struct torture_context *tctx,
        struct netr_UserSessionKey key;
        struct netr_LMSessionKey LMSessKey;
        uint32_t validation_levels[] = { 2, 3 };
-       struct netr_SamBaseInfo *base;
+       struct netr_SamBaseInfo *base = NULL;
        const char *crypto_alg = "";
        bool can_do_validation_6 = true;
 
@@ -380,8 +380,8 @@ static bool test_schannel(struct torture_context *tctx,
        status = dcerpc_parse_binding(tctx, binding, &b);
        torture_assert_ntstatus_ok(tctx, status, "Bad binding string");
 
-       b->flags &= ~DCERPC_AUTH_OPTIONS;
-       b->flags |= dcerpc_flags;
+       status = dcerpc_binding_set_flags(b, dcerpc_flags, DCERPC_AUTH_OPTIONS);
+       torture_assert_ntstatus_ok(tctx, status, "set flags");
 
        status = dcerpc_pipe_connect_b(tctx, &p, b, &ndr_table_samr,
                                       credentials, tctx->ev, tctx->lp_ctx);
@@ -426,8 +426,9 @@ static bool test_schannel(struct torture_context *tctx,
                "Failed to process schannel secured NETLOGON EX ops");
 
        /* we *MUST* use ncacn_np for openpolicy etc. */
-       transport = b->transport;
-       b->transport = NCACN_NP;
+       transport = dcerpc_binding_get_transport(b);
+       status = dcerpc_binding_set_transport(b, NCACN_NP);
+       torture_assert_ntstatus_ok(tctx, status, "set transport");
 
        /* Swap the binding details from SAMR to LSARPC */
        status = dcerpc_epm_map_binding(tctx, b, &ndr_table_lsarpc, tctx->ev, tctx->lp_ctx);
@@ -444,11 +445,9 @@ static bool test_schannel(struct torture_context *tctx,
        talloc_free(p_lsa);
        p_lsa = NULL;
 
-       b->transport = transport;
-
        /* we *MUST* use ncacn_ip_tcp for lookupsids3/lookupnames4 */
-       transport = b->transport;
-       b->transport = NCACN_IP_TCP;
+       status = dcerpc_binding_set_transport(b, NCACN_IP_TCP);
+       torture_assert_ntstatus_ok(tctx, status, "set transport");
 
        torture_assert_ntstatus_ok(tctx,
                dcerpc_epm_map_binding(tctx, b, &ndr_table_lsarpc, tctx->ev, tctx->lp_ctx),
@@ -463,7 +462,9 @@ static bool test_schannel(struct torture_context *tctx,
                test_many_LookupSids(p_lsa, tctx, NULL),
                "LsaLookupSids3 failed!\n");
 
-       b->transport = transport;
+       status = dcerpc_binding_set_transport(b, transport);
+       torture_assert_ntstatus_ok(tctx, status, "set transport");
+
 
        /* Drop the socket, we want to start from scratch */
        talloc_free(p);
@@ -474,8 +475,8 @@ static bool test_schannel(struct torture_context *tctx,
        status = dcerpc_parse_binding(tctx, binding, &b);
        torture_assert_ntstatus_ok(tctx, status, "Bad binding string");
 
-       b->flags &= ~DCERPC_AUTH_OPTIONS;
-       b->flags |= dcerpc_flags;
+       status = dcerpc_binding_set_flags(b, dcerpc_flags, DCERPC_AUTH_OPTIONS);
+       torture_assert_ntstatus_ok(tctx, status, "set flags");
 
        status = dcerpc_pipe_connect_b(tctx, &p_samr2, b, &ndr_table_samr,
                                       credentials, tctx->ev, tctx->lp_ctx);
@@ -521,7 +522,8 @@ static bool test_schannel(struct torture_context *tctx,
        talloc_free(p_samr2);
 
        /* We don't want schannel for this test */
-       b->flags &= ~DCERPC_AUTH_OPTIONS;
+       status = dcerpc_binding_set_flags(b, 0, DCERPC_AUTH_OPTIONS);
+       torture_assert_ntstatus_ok(tctx, status, "set flags");
 
        status = dcerpc_pipe_connect_b(tctx, &p_netlogon3, b, &ndr_table_netlogon,
                                       credentials, tctx->ev, tctx->lp_ctx);
@@ -541,6 +543,85 @@ static bool test_schannel(struct torture_context *tctx,
        return true;
 }
 
+/*
+ * Purpose of this test is to demonstrate that a netlogon server carefully deals
+ * with anonymous attempts to set passwords, in particular when the server
+ * enforces the use of schannel. This test makes most sense to be run in an
+ * environment where the netlogon server enforces use of schannel.
+ */
+
+static bool test_schannel_anonymous_setPassword(struct torture_context *tctx,
+                                               uint32_t dcerpc_flags,
+                                               bool use2)
+{
+       NTSTATUS status, result;
+       const char *binding = torture_setting_string(tctx, "binding", NULL);
+       struct dcerpc_binding *b;
+       struct dcerpc_pipe *p = NULL;
+       struct cli_credentials *credentials;
+       bool ok = true;
+
+       credentials = cli_credentials_init(NULL);
+       torture_assert(tctx, credentials != NULL, "Bad credentials");
+       cli_credentials_set_anonymous(credentials);
+
+       status = dcerpc_parse_binding(tctx, binding, &b);
+       torture_assert_ntstatus_ok(tctx, status, "Bad binding string");
+
+       status = dcerpc_binding_set_flags(b, dcerpc_flags, DCERPC_AUTH_OPTIONS);
+       torture_assert_ntstatus_ok(tctx, status, "set flags");
+
+       status = dcerpc_pipe_connect_b(tctx,
+                                      &p,
+                                      b,
+                                      &ndr_table_netlogon,
+                                      credentials,
+                                      tctx->ev,
+                                      tctx->lp_ctx);
+       torture_assert_ntstatus_ok(tctx, status, "Failed to connect without schannel");
+
+       if (use2) {
+               struct netr_ServerPasswordSet2 r = {};
+               struct netr_Authenticator credential = {};
+               struct netr_Authenticator return_authenticator = {};
+               struct netr_CryptPassword new_password = {};
+
+               r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
+               r.in.account_name = talloc_asprintf(tctx, "%s$", TEST_MACHINE_NAME);
+               r.in.secure_channel_type = 0;
+               r.in.computer_name = TEST_MACHINE_NAME;
+               r.in.credential = &credential;
+               r.in.new_password = &new_password;
+               r.out.return_authenticator = &return_authenticator;
+
+               status = dcerpc_netr_ServerPasswordSet2_r(p->binding_handle, tctx, &r);
+               result = r.out.result;
+       } else {
+               struct netr_ServerPasswordSet r = {};
+               struct netr_Authenticator credential = {};
+               struct netr_Authenticator return_authenticator = {};
+               struct samr_Password new_password = {};
+
+               r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
+               r.in.account_name = talloc_asprintf(tctx, "%s$", TEST_MACHINE_NAME);
+               r.in.secure_channel_type = 0;
+               r.in.computer_name = TEST_MACHINE_NAME;
+               r.in.credential = &credential;
+               r.in.new_password = &new_password;
+               r.out.return_authenticator = &return_authenticator;
+
+               status = dcerpc_netr_ServerPasswordSet_r(p->binding_handle, tctx, &r);
+               result = r.out.result;
+       }
+
+       torture_assert_ntstatus_ok(tctx, status, "ServerPasswordSet failed");
+
+       if (NT_STATUS_IS_OK(result)) {
+               torture_fail(tctx, "unexpectedly received NT_STATUS_OK");
+       }
+
+       return ok;
+}
 
 
 /*
@@ -584,6 +665,35 @@ bool torture_rpc_schannel(struct torture_context *torture)
        return ret;
 }
 
+bool torture_rpc_schannel_anon_setpw(struct torture_context *torture)
+{
+       bool ret = true;
+       bool ok;
+       uint32_t dcerpc_flags = DCERPC_SCHANNEL | DCERPC_SIGN | DCERPC_SCHANNEL_AUTO;
+
+       ok = test_schannel_anonymous_setPassword(torture,
+                                                dcerpc_flags,
+                                                true);
+       if (!ok) {
+               torture_comment(torture,
+                               "Failed with dcerpc_flags=0x%x\n",
+                               dcerpc_flags);
+               ret = false;
+       }
+
+       ok = test_schannel_anonymous_setPassword(torture,
+                                                dcerpc_flags,
+                                                false);
+       if (!ok) {
+               torture_comment(torture,
+                               "Failed with dcerpc_flags=0x%x\n",
+                               dcerpc_flags);
+               ret = false;
+       }
+
+       return ret;
+}
+
 /*
   test two schannel connections
  */
@@ -609,8 +719,8 @@ bool torture_rpc_schannel2(struct torture_context *torture)
        status = dcerpc_parse_binding(torture, binding, &b);
        torture_assert_ntstatus_ok(torture, status, "Bad binding string");
 
-       b->flags &= ~DCERPC_AUTH_OPTIONS;
-       b->flags |= dcerpc_flags;
+       status = dcerpc_binding_set_flags(b, dcerpc_flags, DCERPC_AUTH_OPTIONS);
+       torture_assert_ntstatus_ok(torture, status, "set flags");
 
        torture_comment(torture, "Opening first connection\n");
        status = dcerpc_pipe_connect_b(torture, &p1, b, &ndr_table_netlogon,
@@ -679,6 +789,7 @@ struct torture_schannel_bench {
        bool stopped;
 };
 
+#if 0
 static void torture_schannel_bench_connected(struct composite_context *c)
 {
        struct torture_schannel_bench_conn *conn =
@@ -692,6 +803,7 @@ static void torture_schannel_bench_connected(struct composite_context *c)
                s->nconns++;
        }
 }
+#endif
 
 static void torture_schannel_bench_recv(struct tevent_req *subreq);
 
@@ -863,8 +975,10 @@ bool torture_rpc_schannel_bench1(struct torture_context *torture)
 
        status = dcerpc_parse_binding(s, binding, &s->b);
        torture_assert_ntstatus_ok(torture, status, "Bad binding string");
-       s->b->flags &= ~DCERPC_AUTH_OPTIONS;
-       s->b->flags |= DCERPC_SCHANNEL | DCERPC_SIGN;
+
+       status = dcerpc_binding_set_flags(s->b, DCERPC_SCHANNEL | DCERPC_SIGN,
+                                         DCERPC_AUTH_OPTIONS);
+       torture_assert_ntstatus_ok(torture, status, "set flags");
 
        torture_comment(torture, "Opening %d connections in parallel\n", s->nprocs);
        for (i=0; i < s->nprocs; i++) {