2 Unix SMB/CIFS implementation.
4 CLDAP server structures
6 Copyright (C) Andrew Bartlett <abartlet@samba.org> 2008
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.
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.
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/>.
23 #include "../libcli/netlogon.h"
25 NTSTATUS push_netlogon_samlogon_response(DATA_BLOB *data, TALLOC_CTX *mem_ctx,
26 struct smb_iconv_convenience *iconv_convenience,
27 struct netlogon_samlogon_response *response)
29 enum ndr_err_code ndr_err;
30 if (response->ntver == NETLOGON_NT_VERSION_1) {
31 ndr_err = ndr_push_struct_blob(data, mem_ctx,
34 (ndr_push_flags_fn_t)ndr_push_NETLOGON_SAM_LOGON_RESPONSE_NT40);
35 } else if (response->ntver & NETLOGON_NT_VERSION_5EX) {
36 ndr_err = ndr_push_struct_blob(data, mem_ctx,
39 (ndr_push_flags_fn_t)ndr_push_NETLOGON_SAM_LOGON_RESPONSE_EX_with_flags);
40 } else if (response->ntver & NETLOGON_NT_VERSION_5) {
41 ndr_err = ndr_push_struct_blob(data, mem_ctx,
44 (ndr_push_flags_fn_t)ndr_push_NETLOGON_SAM_LOGON_RESPONSE);
46 DEBUG(0, ("Asked to push unknown netlogon response type 0x%02x\n", response->ntver));
47 return NT_STATUS_INVALID_PARAMETER;
49 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
50 DEBUG(2,("failed to push netlogon response of type 0x%02x\n",
52 return ndr_map_error2ntstatus(ndr_err);
57 NTSTATUS pull_netlogon_samlogon_response(DATA_BLOB *data, TALLOC_CTX *mem_ctx,
58 struct smb_iconv_convenience *iconv_convenience,
59 struct netlogon_samlogon_response *response)
62 enum ndr_err_code ndr_err;
64 if (data->length < 8) {
65 return NT_STATUS_BUFFER_TOO_SMALL;
69 if (SVAL(data->data, data->length - 4) != 0xffff) {
70 return NT_STATUS_INVALID_NETWORK_RESPONSE;
73 if (SVAL(data->data, data->length - 2) != 0xffff) {
74 return NT_STATUS_INVALID_NETWORK_RESPONSE;
77 ntver = IVAL(data->data, data->length - 8);
79 if (ntver == NETLOGON_NT_VERSION_1) {
80 ndr_err = ndr_pull_struct_blob_all(data, mem_ctx,
83 (ndr_pull_flags_fn_t)ndr_pull_NETLOGON_SAM_LOGON_RESPONSE_NT40);
84 response->ntver = NETLOGON_NT_VERSION_1;
85 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && DEBUGLEVEL >= 10) {
86 NDR_PRINT_DEBUG(NETLOGON_SAM_LOGON_RESPONSE_NT40, &response->nt4);
89 } else if (ntver & NETLOGON_NT_VERSION_5EX) {
91 ndr = ndr_pull_init_blob(data, mem_ctx, iconv_convenience);
93 return NT_STATUS_NO_MEMORY;
95 ndr_err = ndr_pull_NETLOGON_SAM_LOGON_RESPONSE_EX_with_flags(ndr, NDR_SCALARS|NDR_BUFFERS, &response->nt5_ex, ntver);
96 if (ndr->offset < ndr->data_size) {
97 ndr_err = ndr_pull_error(ndr, NDR_ERR_UNREAD_BYTES,
98 "not all bytes consumed ofs[%u] size[%u]",
99 ndr->offset, ndr->data_size);
101 response->ntver = NETLOGON_NT_VERSION_5EX;
102 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && DEBUGLEVEL >= 10) {
103 NDR_PRINT_DEBUG(NETLOGON_SAM_LOGON_RESPONSE_EX, &response->nt5_ex);
106 } else if (ntver & NETLOGON_NT_VERSION_5) {
107 ndr_err = ndr_pull_struct_blob_all(data, mem_ctx,
110 (ndr_pull_flags_fn_t)ndr_pull_NETLOGON_SAM_LOGON_RESPONSE);
111 response->ntver = NETLOGON_NT_VERSION_5;
112 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && DEBUGLEVEL >= 10) {
113 NDR_PRINT_DEBUG(NETLOGON_SAM_LOGON_RESPONSE, &response->nt5);
116 DEBUG(2,("failed to parse netlogon response of type 0x%02x - unknown response type\n",
118 dump_data(10, data->data, data->length);
119 return NT_STATUS_INVALID_NETWORK_RESPONSE;
122 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
123 DEBUG(2,("failed to parse netlogon response of type 0x%02x\n",
125 dump_data(10, data->data, data->length);
126 return ndr_map_error2ntstatus(ndr_err);
132 void map_netlogon_samlogon_response(struct netlogon_samlogon_response *response)
134 struct NETLOGON_SAM_LOGON_RESPONSE_EX response_5_ex;
135 switch (response->ntver) {
136 case NETLOGON_NT_VERSION_5EX:
138 case NETLOGON_NT_VERSION_5:
139 ZERO_STRUCT(response_5_ex);
140 response_5_ex.command = response->nt5.command;
141 response_5_ex.pdc_name = response->nt5.pdc_name;
142 response_5_ex.user_name = response->nt5.user_name;
143 response_5_ex.domain = response->nt5.domain_name;
144 response_5_ex.domain_uuid = response->nt5.domain_uuid;
145 response_5_ex.forest = response->nt5.forest;
146 response_5_ex.dns_domain = response->nt5.dns_domain;
147 response_5_ex.pdc_dns_name = response->nt5.pdc_dns_name;
148 response_5_ex.sockaddr.pdc_ip = response->nt5.pdc_ip;
149 response_5_ex.server_type = response->nt5.server_type;
150 response_5_ex.nt_version = response->nt5.nt_version;
151 response_5_ex.lmnt_token = response->nt5.lmnt_token;
152 response_5_ex.lm20_token = response->nt5.lm20_token;
153 response->ntver = NETLOGON_NT_VERSION_5EX;
154 response->nt5_ex = response_5_ex;
157 case NETLOGON_NT_VERSION_1:
158 ZERO_STRUCT(response_5_ex);
159 response_5_ex.command = response->nt4.command;
160 response_5_ex.pdc_name = response->nt4.server;
161 response_5_ex.user_name = response->nt4.user_name;
162 response_5_ex.domain = response->nt4.domain;
163 response_5_ex.nt_version = response->nt4.nt_version;
164 response_5_ex.lmnt_token = response->nt4.lmnt_token;
165 response_5_ex.lm20_token = response->nt4.lm20_token;
166 response->ntver = NETLOGON_NT_VERSION_5EX;
167 response->nt5_ex = response_5_ex;
173 NTSTATUS push_nbt_netlogon_response(DATA_BLOB *data, TALLOC_CTX *mem_ctx,
174 struct smb_iconv_convenience *iconv_convenience,
175 struct nbt_netlogon_response *response)
177 NTSTATUS status = NT_STATUS_INVALID_NETWORK_RESPONSE;
178 enum ndr_err_code ndr_err;
179 switch (response->response_type) {
180 case NETLOGON_GET_PDC:
181 ndr_err = ndr_push_struct_blob(data, mem_ctx, iconv_convenience, &response->get_pdc,
182 (ndr_push_flags_fn_t)ndr_push_nbt_netlogon_response_from_pdc);
183 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
184 status = ndr_map_error2ntstatus(ndr_err);
185 DEBUG(0,("Failed to parse netlogon packet of length %d: %s\n",
186 (int)data->length, nt_errstr(status)));
188 file_save("netlogon.dat", data->data, data->length);
192 status = NT_STATUS_OK;
194 case NETLOGON_SAMLOGON:
195 status = push_netlogon_samlogon_response(data, mem_ctx, iconv_convenience, &response->samlogon);
202 NTSTATUS pull_nbt_netlogon_response(DATA_BLOB *data, TALLOC_CTX *mem_ctx,
203 struct smb_iconv_convenience *iconv_convenience,
204 struct nbt_netlogon_response *response)
206 NTSTATUS status = NT_STATUS_INVALID_NETWORK_RESPONSE;
207 enum netlogon_command command;
208 enum ndr_err_code ndr_err;
209 if (data->length < 4) {
210 return NT_STATUS_INVALID_NETWORK_RESPONSE;
213 command = SVAL(data->data, 0);
216 case NETLOGON_RESPONSE_FROM_PDC:
217 ndr_err = ndr_pull_struct_blob_all(data, mem_ctx, iconv_convenience, &response->get_pdc,
218 (ndr_pull_flags_fn_t)ndr_pull_nbt_netlogon_response_from_pdc);
219 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
220 status = ndr_map_error2ntstatus(ndr_err);
221 DEBUG(0,("Failed to parse netlogon packet of length %d: %s\n",
222 (int)data->length, nt_errstr(status)));
224 file_save("netlogon.dat", data->data, data->length);
228 status = NT_STATUS_OK;
229 response->response_type = NETLOGON_GET_PDC;
231 case LOGON_SAM_LOGON_RESPONSE:
232 case LOGON_SAM_LOGON_PAUSE_RESPONSE:
233 case LOGON_SAM_LOGON_USER_UNKNOWN:
234 case LOGON_SAM_LOGON_RESPONSE_EX:
235 case LOGON_SAM_LOGON_PAUSE_RESPONSE_EX:
236 case LOGON_SAM_LOGON_USER_UNKNOWN_EX:
237 status = pull_netlogon_samlogon_response(data, mem_ctx, iconv_convenience, &response->samlogon);
238 response->response_type = NETLOGON_SAMLOGON;
241 /* These levels are queries, not responses */
242 case LOGON_PRIMARY_QUERY:
243 case NETLOGON_ANNOUNCE_UAS:
244 case LOGON_SAM_LOGON_REQUEST:
245 status = NT_STATUS_INVALID_NETWORK_RESPONSE;