| 1 | /*
|
|---|
| 2 | * NTLMSSP Acceptor
|
|---|
| 3 | * DCERPC Server functions
|
|---|
| 4 | * Copyright (C) Simo Sorce 2010.
|
|---|
| 5 | *
|
|---|
| 6 | * This program is free software; you can redistribute it and/or modify
|
|---|
| 7 | * it under the terms of the GNU General Public License as published by
|
|---|
| 8 | * the Free Software Foundation; either version 3 of the License, or
|
|---|
| 9 | * (at your option) any later version.
|
|---|
| 10 | *
|
|---|
| 11 | * This program is distributed in the hope that it will be useful,
|
|---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 14 | * GNU General Public License for more details.
|
|---|
| 15 | *
|
|---|
| 16 | * You should have received a copy of the GNU General Public License
|
|---|
| 17 | * along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|---|
| 18 | */
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 | #include "includes.h"
|
|---|
| 22 | #include "rpc_server/dcesrv_ntlmssp.h"
|
|---|
| 23 | #include "../libcli/auth/ntlmssp.h"
|
|---|
| 24 | #include "ntlmssp_wrap.h"
|
|---|
| 25 | #include "auth.h"
|
|---|
| 26 |
|
|---|
| 27 | NTSTATUS ntlmssp_server_auth_start(TALLOC_CTX *mem_ctx,
|
|---|
| 28 | bool do_sign,
|
|---|
| 29 | bool do_seal,
|
|---|
| 30 | bool is_dcerpc,
|
|---|
| 31 | DATA_BLOB *token_in,
|
|---|
| 32 | DATA_BLOB *token_out,
|
|---|
| 33 | struct auth_ntlmssp_state **ctx)
|
|---|
| 34 | {
|
|---|
| 35 | struct auth_ntlmssp_state *a = NULL;
|
|---|
| 36 | NTSTATUS status;
|
|---|
| 37 |
|
|---|
| 38 | status = auth_ntlmssp_start(&a);
|
|---|
| 39 | if (!NT_STATUS_IS_OK(status)) {
|
|---|
| 40 | DEBUG(0, (__location__ ": auth_ntlmssp_start failed: %s\n",
|
|---|
| 41 | nt_errstr(status)));
|
|---|
| 42 | return status;
|
|---|
| 43 | }
|
|---|
| 44 |
|
|---|
| 45 | /* Clear flags, then set them according to requested flags */
|
|---|
| 46 | auth_ntlmssp_and_flags(a, ~(NTLMSSP_NEGOTIATE_SIGN |
|
|---|
| 47 | NTLMSSP_NEGOTIATE_SEAL));
|
|---|
| 48 |
|
|---|
| 49 | if (do_sign) {
|
|---|
| 50 | auth_ntlmssp_or_flags(a, NTLMSSP_NEGOTIATE_SIGN);
|
|---|
| 51 | }
|
|---|
| 52 | if (do_seal) {
|
|---|
| 53 | /* Always implies both sign and seal for ntlmssp */
|
|---|
| 54 | auth_ntlmssp_or_flags(a, NTLMSSP_NEGOTIATE_SIGN |
|
|---|
| 55 | NTLMSSP_NEGOTIATE_SEAL);
|
|---|
| 56 | }
|
|---|
| 57 |
|
|---|
| 58 | status = auth_ntlmssp_update(a, *token_in, token_out);
|
|---|
| 59 | if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
|
|---|
| 60 | DEBUG(0, (__location__ ": auth_ntlmssp_update failed: %s\n",
|
|---|
| 61 | nt_errstr(status)));
|
|---|
| 62 | goto done;
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 | /* Make sure data is bound to the memctx, to be freed the caller */
|
|---|
| 66 | talloc_steal(mem_ctx, token_out->data);
|
|---|
| 67 | /* steal ntlmssp context too */
|
|---|
| 68 | *ctx = talloc_move(mem_ctx, &a);
|
|---|
| 69 |
|
|---|
| 70 | status = NT_STATUS_OK;
|
|---|
| 71 |
|
|---|
| 72 | done:
|
|---|
| 73 | if (!NT_STATUS_IS_OK(status)) {
|
|---|
| 74 | TALLOC_FREE(a);
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | return status;
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| 80 | NTSTATUS ntlmssp_server_step(struct auth_ntlmssp_state *ctx,
|
|---|
| 81 | TALLOC_CTX *mem_ctx,
|
|---|
| 82 | DATA_BLOB *token_in,
|
|---|
| 83 | DATA_BLOB *token_out)
|
|---|
| 84 | {
|
|---|
| 85 | NTSTATUS status;
|
|---|
| 86 |
|
|---|
| 87 | /* this has to be done as root in order to verify the password */
|
|---|
| 88 | become_root();
|
|---|
| 89 | status = auth_ntlmssp_update(ctx, *token_in, token_out);
|
|---|
| 90 | unbecome_root();
|
|---|
| 91 |
|
|---|
| 92 | /* put the output token data on the given mem_ctx */
|
|---|
| 93 | talloc_steal(mem_ctx, token_out->data);
|
|---|
| 94 |
|
|---|
| 95 | return status;
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | NTSTATUS ntlmssp_server_check_flags(struct auth_ntlmssp_state *ctx,
|
|---|
| 99 | bool do_sign, bool do_seal)
|
|---|
| 100 | {
|
|---|
| 101 | if (do_sign && !auth_ntlmssp_negotiated_sign(ctx)) {
|
|---|
| 102 | DEBUG(1, (__location__ "Integrity was requested but client "
|
|---|
| 103 | "failed to negotiate signing.\n"));
|
|---|
| 104 | return NT_STATUS_ACCESS_DENIED;
|
|---|
| 105 | }
|
|---|
| 106 |
|
|---|
| 107 | if (do_seal && !auth_ntlmssp_negotiated_seal(ctx)) {
|
|---|
| 108 | DEBUG(1, (__location__ "Privacy was requested but client "
|
|---|
| 109 | "failed to negotiate sealing.\n"));
|
|---|
| 110 | return NT_STATUS_ACCESS_DENIED;
|
|---|
| 111 | }
|
|---|
| 112 |
|
|---|
| 113 | return NT_STATUS_OK;
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 | NTSTATUS ntlmssp_server_get_user_info(struct auth_ntlmssp_state *ctx,
|
|---|
| 117 | TALLOC_CTX *mem_ctx,
|
|---|
| 118 | struct auth_serversupplied_info **session_info)
|
|---|
| 119 | {
|
|---|
| 120 | NTSTATUS status;
|
|---|
| 121 |
|
|---|
| 122 | status = auth_ntlmssp_steal_session_info(mem_ctx, ctx, session_info);
|
|---|
| 123 | if (!NT_STATUS_IS_OK(status)) {
|
|---|
| 124 | DEBUG(1, (__location__ ": Failed to get authenticated user "
|
|---|
| 125 | "info: %s\n", nt_errstr(status)));
|
|---|
| 126 | return status;
|
|---|
| 127 | }
|
|---|
| 128 |
|
|---|
| 129 | DEBUG(5, (__location__ "OK: user: %s domain: %s workstation: %s\n",
|
|---|
| 130 | auth_ntlmssp_get_username(ctx),
|
|---|
| 131 | auth_ntlmssp_get_domain(ctx),
|
|---|
| 132 | auth_ntlmssp_get_client(ctx)));
|
|---|
| 133 |
|
|---|
| 134 | return NT_STATUS_OK;
|
|---|
| 135 | }
|
|---|