r24557: rename 'dcerpc_table_' -> 'ndr_table_'
[jelmer/samba4-debian.git] / source / winbind / wb_init_domain.c
index cdc1491f2b3da53e16b635419ac539ca98f0d7ee..da03f0d406f6ee936c5c537f2339d69cdb3dbfac 100644 (file)
@@ -79,7 +79,7 @@ static void init_domain_recv_ldapconn(struct composite_context *ctx);
 static void init_domain_recv_samr(struct composite_context *ctx);
 
 static struct dcerpc_binding *init_domain_binding(struct init_domain_state *state, 
-                                                 const struct dcerpc_interface_table *table) 
+                                                 const struct ndr_interface_table *table) 
 {
        struct dcerpc_binding *binding;
        NTSTATUS status;
@@ -142,25 +142,26 @@ struct composite_context *wb_init_domain_send(TALLOC_CTX *mem_ctx,
        state->domain->dc_name = dom_info->dcs[0].name;
        state->domain->dc_address = dom_info->dcs[0].address;
 
+       state->domain->libnet_ctx = libnet_context_init(service->task->event_ctx);
+
        /* Create a credentials structure */
-       state->domain->schannel_creds = cli_credentials_init(state->domain);
-       if (state->domain->schannel_creds == NULL) goto failed;
+       state->domain->libnet_ctx->cred = cli_credentials_init(state->domain);
+       if (state->domain->libnet_ctx->cred == NULL) goto failed;
 
-       cli_credentials_set_event_context(state->domain->schannel_creds, service->task->event_ctx);
+       cli_credentials_set_event_context(state->domain->libnet_ctx->cred, service->task->event_ctx);
 
-       cli_credentials_set_conf(state->domain->schannel_creds);
+       cli_credentials_set_conf(state->domain->libnet_ctx->cred);
 
        /* Connect the machine account to the credentials */
        state->ctx->status =
-               cli_credentials_set_machine_account(state->domain->
-                                                   schannel_creds);
+               cli_credentials_set_machine_account(state->domain->libnet_ctx->cred);
        if (!NT_STATUS_IS_OK(state->ctx->status)) goto failed;
 
-       state->domain->netlogon_binding = init_domain_binding(state, &dcerpc_table_netlogon);
+       state->domain->netlogon_binding = init_domain_binding(state, &ndr_table_netlogon);
 
        state->domain->netlogon_pipe = NULL;
 
-       if ((!cli_credentials_is_anonymous(state->domain->schannel_creds)) &&
+       if ((!cli_credentials_is_anonymous(state->domain->libnet_ctx->cred)) &&
            ((lp_server_role() == ROLE_DOMAIN_MEMBER) ||
             (lp_server_role() == ROLE_DOMAIN_CONTROLLER)) &&
            (dom_sid_equal(state->domain->info->sid,
@@ -178,8 +179,8 @@ struct composite_context *wb_init_domain_send(TALLOC_CTX *mem_ctx,
        /* No encryption on anonymous pipes */
 
        ctx = dcerpc_pipe_connect_b_send(state, state->domain->netlogon_binding, 
-                                        &dcerpc_table_netlogon,
-                                        state->domain->schannel_creds,
+                                        &ndr_table_netlogon,
+                                        state->domain->libnet_ctx->cred,
                                         service->task->event_ctx);
        
        if (composite_nomem(ctx, state->ctx)) {
@@ -211,7 +212,7 @@ static void init_domain_recv_netlogonpipe(struct composite_context *ctx)
        }
        talloc_steal(state->domain->netlogon_pipe, state->domain->netlogon_binding);
 
-       state->domain->lsa_binding = init_domain_binding(state, &dcerpc_table_lsarpc);
+       state->domain->lsa_binding = init_domain_binding(state, &ndr_table_lsarpc);
 
        /* For debugging, it can be a real pain if all the traffic is encrypted */
        if (lp_winbind_sealed_pipes()) {
@@ -220,21 +221,21 @@ static void init_domain_recv_netlogonpipe(struct composite_context *ctx)
                state->domain->lsa_binding->flags |= (DCERPC_SIGN);
        }
 
-       state->domain->lsa_pipe = NULL;
+       state->domain->libnet_ctx->lsa.pipe = NULL;
 
        /* this will make the secondary connection on the same IPC$ share, 
           secured with SPNEGO or NTLMSSP */
        ctx = dcerpc_secondary_auth_connection_send(state->domain->netlogon_pipe,
                                                    state->domain->lsa_binding,
-                                                   &dcerpc_table_lsarpc,
-                                                   state->domain->schannel_creds
+                                                   &ndr_table_lsarpc,
+                                                   state->domain->libnet_ctx->cred
                );
        composite_continue(state->ctx, ctx, init_domain_recv_lsa_pipe, state);
 }
 
 static bool retry_with_schannel(struct init_domain_state *state, 
                                struct dcerpc_binding *binding,
-                               const struct dcerpc_interface_table *table,
+                               const struct ndr_interface_table *table,
                                void (*continuation)(struct composite_context *))
 {
        struct composite_context *ctx;
@@ -253,7 +254,7 @@ static bool retry_with_schannel(struct init_domain_state *state,
                ctx = dcerpc_secondary_auth_connection_send(state->domain->netlogon_pipe,
                                                            binding,
                                                            table, 
-                                                           state->domain->schannel_creds);
+                                                           state->domain->libnet_ctx->cred);
                composite_continue(state->ctx, ctx, continuation, state);               
                return true;
        } else {
@@ -271,31 +272,31 @@ static void init_domain_recv_lsa_pipe(struct composite_context *ctx)
                                struct init_domain_state);
 
        state->ctx->status = dcerpc_secondary_auth_connection_recv(ctx, state->domain,
-                                                                  &state->domain->lsa_pipe);
+                                                                  &state->domain->libnet_ctx->lsa.pipe);
        if (NT_STATUS_EQUAL(state->ctx->status, NT_STATUS_LOGON_FAILURE)) {
                if (retry_with_schannel(state, state->domain->lsa_binding, 
-                                       &dcerpc_table_lsarpc,
+                                       &ndr_table_lsarpc,
                                        init_domain_recv_lsa_pipe)) {
                        return;
                }
        }
        if (!composite_is_ok(state->ctx)) return;
 
-       talloc_steal(state->domain, state->domain->lsa_pipe);
-       talloc_steal(state->domain->lsa_pipe, state->domain->lsa_binding);
-
-       state->domain->lsa_policy_handle = talloc(state, struct policy_handle);
-       if (composite_nomem(state->domain->lsa_policy_handle, state->ctx)) return;
+       talloc_steal(state->domain->libnet_ctx, state->domain->libnet_ctx->lsa.pipe);
+       talloc_steal(state->domain->libnet_ctx->lsa.pipe, state->domain->lsa_binding);
+       state->domain->libnet_ctx->lsa.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
+       state->domain->libnet_ctx->lsa.name = state->domain->info->name;
 
+       ZERO_STRUCT(state->domain->libnet_ctx->lsa.handle);
        state->lsa_openpolicy.in.system_name =
                talloc_asprintf(state, "\\\\%s",
-                               dcerpc_server_name(state->domain->lsa_pipe));
+                               dcerpc_server_name(state->domain->libnet_ctx->lsa.pipe));
        ZERO_STRUCT(state->objectattr);
        state->lsa_openpolicy.in.attr = &state->objectattr;
        state->lsa_openpolicy.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
-       state->lsa_openpolicy.out.handle = state->domain->lsa_policy_handle;
+       state->lsa_openpolicy.out.handle = &state->domain->libnet_ctx->lsa.handle;
 
-       req = dcerpc_lsa_OpenPolicy2_send(state->domain->lsa_pipe, state,
+       req = dcerpc_lsa_OpenPolicy2_send(state->domain->libnet_ctx->lsa.pipe, state,
                                          &state->lsa_openpolicy);
 
        composite_continue_rpc(state->ctx, req, init_domain_recv_lsa_policy, state);
@@ -314,7 +315,7 @@ static void init_domain_recv_lsa_policy(struct rpc_request *req)
        if ((!NT_STATUS_IS_OK(state->ctx->status)
              || !NT_STATUS_IS_OK(state->lsa_openpolicy.out.result))) {
                if (retry_with_schannel(state, state->domain->lsa_binding, 
-                                       &dcerpc_table_lsarpc,
+                                       &ndr_table_lsarpc,
                                        init_domain_recv_lsa_pipe)) {
                        return;
                }
@@ -323,10 +324,10 @@ static void init_domain_recv_lsa_policy(struct rpc_request *req)
        state->ctx->status = state->lsa_openpolicy.out.result;
        if (!composite_is_ok(state->ctx)) return;
 
-       state->queryinfo.in.handle = state->domain->lsa_policy_handle;
+       state->queryinfo.in.handle = &state->domain->libnet_ctx->lsa.handle;
        state->queryinfo.in.level = LSA_POLICY_INFO_ACCOUNT_DOMAIN;
 
-       req = dcerpc_lsa_QueryInfoPolicy_send(state->domain->lsa_pipe, state,
+       req = dcerpc_lsa_QueryInfoPolicy_send(state->domain->libnet_ctx->lsa.pipe, state,
                                              &state->queryinfo);
        composite_continue_rpc(state->ctx, req,
                               init_domain_recv_queryinfo, state);
@@ -349,7 +350,7 @@ static void init_domain_recv_queryinfo(struct rpc_request *req)
        if (strcasecmp(state->domain->info->name, dominfo->name.string) != 0) {
                DEBUG(2, ("Expected domain name %s, DC %s said %s\n",
                          state->domain->info->name,
-                         dcerpc_server_name(state->domain->lsa_pipe),
+                         dcerpc_server_name(state->domain->libnet_ctx->lsa.pipe),
                          dominfo->name.string));
                composite_error(state->ctx, NT_STATUS_INVALID_DOMAIN_STATE);
                return;
@@ -358,19 +359,19 @@ static void init_domain_recv_queryinfo(struct rpc_request *req)
        if (!dom_sid_equal(state->domain->info->sid, dominfo->sid)) {
                DEBUG(2, ("Expected domain sid %s, DC %s said %s\n",
                          dom_sid_string(state, state->domain->info->sid),
-                         dcerpc_server_name(state->domain->lsa_pipe),
+                         dcerpc_server_name(state->domain->libnet_ctx->lsa.pipe),
                          dom_sid_string(state, dominfo->sid)));
                composite_error(state->ctx, NT_STATUS_INVALID_DOMAIN_STATE);
                return;
        }
 
-       state->domain->samr_binding = init_domain_binding(state, &dcerpc_table_samr);
+       state->domain->samr_binding = init_domain_binding(state, &ndr_table_samr);
 
        /* We want to use the same flags as the LSA pipe did (so, if
         * it needed schannel, then we need that here too) */
        state->domain->samr_binding->flags = state->domain->lsa_binding->flags;
 
-       state->domain->samr_pipe = NULL;
+       state->domain->libnet_ctx->samr.pipe = NULL;
 
        ctx = wb_connect_samr_send(state, state->domain);
        composite_continue(state->ctx, ctx, init_domain_recv_samr, state);
@@ -387,12 +388,15 @@ static void init_domain_recv_samr(struct composite_context *ctx)
 
        state->ctx->status = wb_connect_samr_recv(
                ctx, state->domain,
-               &state->domain->samr_pipe,
-               &state->domain->samr_handle, 
-               &state->domain->domain_handle);
+               &state->domain->libnet_ctx->samr.pipe,
+               &state->domain->libnet_ctx->samr.handle, 
+               &state->domain->libnet_ctx->samr.handle);
        if (!composite_is_ok(state->ctx)) return;
 
-       talloc_steal(state->domain->samr_pipe, state->domain->samr_binding);
+       talloc_steal(state->domain->libnet_ctx->samr.pipe, state->domain->samr_binding);
+       state->domain->libnet_ctx->samr.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
+       state->domain->libnet_ctx->samr.name = state->domain->info->name;
+       state->domain->libnet_ctx->samr.sid = state->domain->info->sid;
 
        state->domain->ldap_conn =
                ldap4_new_connection(state->domain, state->ctx->event_ctx);
@@ -419,7 +423,7 @@ static void init_domain_recv_ldapconn(struct composite_context *ctx)
                                      state->domain->dc_name);
                state->ctx->status =
                        ldap_bind_sasl(state->domain->ldap_conn,
-                                      state->domain->schannel_creds);
+                                      state->domain->libnet_ctx->cred);
                DEBUG(0, ("ldap_bind returned %s\n",
                          nt_errstr(state->ctx->status)));
        }