| [206] | 1 | /*
|
|---|
| 2 | Unix SMB/CIFS implementation.
|
|---|
| 3 |
|
|---|
| 4 | CLDAP server structures
|
|---|
| 5 |
|
|---|
| 6 | Copyright (C) Andrew Bartlett <[email protected]> 2008
|
|---|
| 7 |
|
|---|
| 8 | This program is free software; you can redistribute it and/or modify
|
|---|
| 9 | it under the terms of the GNU General Public License as published by
|
|---|
| 10 | the Free Software Foundation; either version 3 of the License, or
|
|---|
| 11 | (at your option) any later version.
|
|---|
| 12 |
|
|---|
| 13 | This program is distributed in the hope that it will be useful,
|
|---|
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 16 | GNU General Public License for more details.
|
|---|
| 17 |
|
|---|
| 18 | You should have received a copy of the GNU General Public License
|
|---|
| 19 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|---|
| 20 | */
|
|---|
| 21 |
|
|---|
| 22 | #include "includes.h"
|
|---|
| 23 | #include "libcli/netlogon.h"
|
|---|
| 24 |
|
|---|
| 25 | NTSTATUS push_netlogon_samlogon_response(DATA_BLOB *data, TALLOC_CTX *mem_ctx,
|
|---|
| 26 | struct netlogon_samlogon_response *response)
|
|---|
| 27 | {
|
|---|
| 28 | enum ndr_err_code ndr_err;
|
|---|
| 29 | if (response->ntver == NETLOGON_NT_VERSION_1) {
|
|---|
| 30 | ndr_err = ndr_push_struct_blob(data, mem_ctx,
|
|---|
| 31 | &response->data.nt4,
|
|---|
| 32 | (ndr_push_flags_fn_t)ndr_push_NETLOGON_SAM_LOGON_RESPONSE_NT40);
|
|---|
| 33 | } else if (response->ntver & NETLOGON_NT_VERSION_5EX) {
|
|---|
| 34 | ndr_err = ndr_push_struct_blob(data, mem_ctx,
|
|---|
| 35 | &response->data.nt5_ex,
|
|---|
| 36 | (ndr_push_flags_fn_t)ndr_push_NETLOGON_SAM_LOGON_RESPONSE_EX_with_flags);
|
|---|
| 37 | } else if (response->ntver & NETLOGON_NT_VERSION_5) {
|
|---|
| 38 | ndr_err = ndr_push_struct_blob(data, mem_ctx,
|
|---|
| 39 | &response->data.nt5,
|
|---|
| 40 | (ndr_push_flags_fn_t)ndr_push_NETLOGON_SAM_LOGON_RESPONSE);
|
|---|
| 41 | } else {
|
|---|
| 42 | DEBUG(0, ("Asked to push unknown netlogon response type 0x%02x\n", response->ntver));
|
|---|
| 43 | return NT_STATUS_INVALID_PARAMETER;
|
|---|
| 44 | }
|
|---|
| 45 | if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
|
|---|
| 46 | DEBUG(2,("failed to push netlogon response of type 0x%02x\n",
|
|---|
| 47 | response->ntver));
|
|---|
| 48 | return ndr_map_error2ntstatus(ndr_err);
|
|---|
| 49 | }
|
|---|
| 50 | return NT_STATUS_OK;
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| 53 | NTSTATUS pull_netlogon_samlogon_response(DATA_BLOB *data, TALLOC_CTX *mem_ctx,
|
|---|
| 54 | struct netlogon_samlogon_response *response)
|
|---|
| 55 | {
|
|---|
| 56 | uint32_t ntver;
|
|---|
| 57 | enum ndr_err_code ndr_err;
|
|---|
| 58 |
|
|---|
| 59 | if (data->length < 8) {
|
|---|
| 60 | return NT_STATUS_BUFFER_TOO_SMALL;
|
|---|
| 61 | }
|
|---|
| 62 |
|
|---|
| 63 | /* lmnttoken */
|
|---|
| 64 | if (SVAL(data->data, data->length - 4) != 0xffff) {
|
|---|
| 65 | return NT_STATUS_INVALID_NETWORK_RESPONSE;
|
|---|
| 66 | }
|
|---|
| 67 | /* lm20token */
|
|---|
| 68 | if (SVAL(data->data, data->length - 2) != 0xffff) {
|
|---|
| 69 | return NT_STATUS_INVALID_NETWORK_RESPONSE;
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | ntver = IVAL(data->data, data->length - 8);
|
|---|
| 73 |
|
|---|
| 74 | if (ntver == NETLOGON_NT_VERSION_1) {
|
|---|
| 75 | ndr_err = ndr_pull_struct_blob_all(data, mem_ctx,
|
|---|
| 76 | &response->data.nt4,
|
|---|
| 77 | (ndr_pull_flags_fn_t)ndr_pull_NETLOGON_SAM_LOGON_RESPONSE_NT40);
|
|---|
| 78 | response->ntver = NETLOGON_NT_VERSION_1;
|
|---|
| 79 | if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && DEBUGLEVEL >= 10) {
|
|---|
| 80 | NDR_PRINT_DEBUG(NETLOGON_SAM_LOGON_RESPONSE_NT40,
|
|---|
| 81 | &response->data.nt4);
|
|---|
| 82 | }
|
|---|
| 83 |
|
|---|
| 84 | } else if (ntver & NETLOGON_NT_VERSION_5EX) {
|
|---|
| 85 | struct ndr_pull *ndr;
|
|---|
| 86 | ndr = ndr_pull_init_blob(data, mem_ctx);
|
|---|
| 87 | if (!ndr) {
|
|---|
| 88 | return NT_STATUS_NO_MEMORY;
|
|---|
| 89 | }
|
|---|
| 90 | ndr_err = ndr_pull_NETLOGON_SAM_LOGON_RESPONSE_EX_with_flags(
|
|---|
| 91 | ndr, NDR_SCALARS|NDR_BUFFERS, &response->data.nt5_ex,
|
|---|
| 92 | ntver);
|
|---|
| 93 | if (ndr->offset < ndr->data_size) {
|
|---|
| 94 | ndr_err = ndr_pull_error(ndr, NDR_ERR_UNREAD_BYTES,
|
|---|
| 95 | "not all bytes consumed ofs[%u] size[%u]",
|
|---|
| 96 | ndr->offset, ndr->data_size);
|
|---|
| 97 | }
|
|---|
| 98 | response->ntver = NETLOGON_NT_VERSION_5EX;
|
|---|
| 99 | if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && DEBUGLEVEL >= 10) {
|
|---|
| 100 | NDR_PRINT_DEBUG(NETLOGON_SAM_LOGON_RESPONSE_EX,
|
|---|
| 101 | &response->data.nt5_ex);
|
|---|
| 102 | }
|
|---|
| 103 |
|
|---|
| 104 | } else if (ntver & NETLOGON_NT_VERSION_5) {
|
|---|
| 105 | ndr_err = ndr_pull_struct_blob_all(data, mem_ctx,
|
|---|
| 106 | &response->data.nt5,
|
|---|
| 107 | (ndr_pull_flags_fn_t)ndr_pull_NETLOGON_SAM_LOGON_RESPONSE);
|
|---|
| 108 | response->ntver = NETLOGON_NT_VERSION_5;
|
|---|
| 109 | if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && DEBUGLEVEL >= 10) {
|
|---|
| 110 | NDR_PRINT_DEBUG(NETLOGON_SAM_LOGON_RESPONSE,
|
|---|
| |
|---|