-static void rpc_pipe_bind_step_two_done(struct tevent_req *subreq);
-
-static void rpc_pipe_bind_step_two_trigger(struct tevent_req *req)
-{
- struct rpc_pipe_bind_state *state =
- tevent_req_data(req,
- struct rpc_pipe_bind_state);
- struct dcerpc_binding_handle *b = state->cli->binding_handle;
- struct schannel_state *schannel_auth =
- talloc_get_type_abort(state->cli->auth->auth_ctx,
- struct schannel_state);
- struct tevent_req *subreq;
-
- if (schannel_auth == NULL ||
- !ndr_syntax_id_equal(&state->cli->abstract_syntax,
- &ndr_table_netlogon.syntax_id)) {
- tevent_req_done(req);
- return;
- }
-
- ZERO_STRUCT(state->return_auth);
-
- state->creds = netlogon_creds_copy(state, schannel_auth->creds);
- if (state->creds == NULL) {
- tevent_req_nterror(req, NT_STATUS_NO_MEMORY);
- return;
- }
-
- netlogon_creds_client_authenticator(state->creds, &state->auth);
-
- state->r.in.server_name = state->cli->srv_name_slash;
- state->r.in.computer_name = state->creds->computer_name;
- state->r.in.credential = &state->auth;
- state->r.in.query_level = 1;
- state->r.in.return_authenticator = &state->return_auth;
-
- state->r.out.capabilities = &state->capabilities;
- state->r.out.return_authenticator = &state->return_auth;
-
- subreq = dcerpc_netr_LogonGetCapabilities_r_send(talloc_tos(),
- state->ev,
- b,
- &state->r);
- if (subreq == NULL) {
- tevent_req_nterror(req, NT_STATUS_NO_MEMORY);
- return;
- }
-
- tevent_req_set_callback(subreq, rpc_pipe_bind_step_two_done, req);
- return;
-}
-
-static void rpc_pipe_bind_step_two_done(struct tevent_req *subreq)
-{
- struct tevent_req *req =
- tevent_req_callback_data(subreq,
- struct tevent_req);
- struct rpc_pipe_bind_state *state =
- tevent_req_data(req,
- struct rpc_pipe_bind_state);
- NTSTATUS status;
-
- status = dcerpc_netr_LogonGetCapabilities_r_recv(subreq, talloc_tos());
- TALLOC_FREE(subreq);
- if (NT_STATUS_EQUAL(status, NT_STATUS_RPC_PROCNUM_OUT_OF_RANGE)) {
- if (state->cli->dc->negotiate_flags &
- NETLOGON_NEG_SUPPORTS_AES) {
- DEBUG(5, ("AES is not supported and the error was %s\n",
- nt_errstr(status)));
- tevent_req_nterror(req,
- NT_STATUS_INVALID_NETWORK_RESPONSE);
- return;
- }
-
- /* This is probably NT */
- DEBUG(5, ("We are checking against an NT - %s\n",
- nt_errstr(status)));
- tevent_req_done(req);
- return;
- } else if (!NT_STATUS_IS_OK(status)) {
- DEBUG(0, ("dcerpc_netr_LogonGetCapabilities_r_recv failed with %s\n",
- nt_errstr(status)));
- tevent_req_nterror(req, status);
- return;
- }
-
- if (NT_STATUS_EQUAL(state->r.out.result, NT_STATUS_NOT_IMPLEMENTED)) {
- if (state->creds->negotiate_flags & NETLOGON_NEG_SUPPORTS_AES) {
- /* This means AES isn't supported. */
- DEBUG(5, ("AES is not supported and the error was %s\n",
- nt_errstr(state->r.out.result)));
- tevent_req_nterror(req,
- NT_STATUS_INVALID_NETWORK_RESPONSE);
- return;
- }
-
- /* This is probably an old Samba version */
- DEBUG(5, ("We are checking against an old Samba version - %s\n",
- nt_errstr(state->r.out.result)));
- tevent_req_done(req);
- return;
- }
-
- /* We need to check the credential state here, cause win2k3 and earlier
- * returns NT_STATUS_NOT_IMPLEMENTED */
- if (!netlogon_creds_client_check(state->creds,
- &state->r.out.return_authenticator->cred)) {
- /*
- * Server replied with bad credential. Fail.
- */
- DEBUG(0,("rpc_pipe_bind_step_two_done: server %s "
- "replied with bad credential\n",
- state->cli->desthost));
- tevent_req_nterror(req, NT_STATUS_UNSUCCESSFUL);
- return;
- }
-
- TALLOC_FREE(state->cli->dc);
- state->cli->dc = talloc_steal(state->cli, state->creds);
-
- if (!NT_STATUS_IS_OK(state->r.out.result)) {
- DEBUG(0, ("dcerpc_netr_LogonGetCapabilities_r_recv failed with %s\n",
- nt_errstr(state->r.out.result)));
- tevent_req_nterror(req, state->r.out.result);
- return;
- }
-
- if (state->creds->negotiate_flags !=
- state->r.out.capabilities->server_capabilities) {
- DEBUG(0, ("The client capabilities don't match the server "
- "capabilities: local[0x%08X] remote[0x%08X]\n",
- state->creds->negotiate_flags,
- state->capabilities.server_capabilities));
- tevent_req_nterror(req,
- NT_STATUS_INVALID_NETWORK_RESPONSE);
- return;
- }
-
- /* TODO: Add downgrade dectection. */
-
- tevent_req_done(req);
- return;
-}
-