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 "lib/util/util_file.h"
24 #include "../libcli/netlogon/netlogon.h"
26 NTSTATUS
push_netlogon_samlogon_response(DATA_BLOB
*data
, TALLOC_CTX
*mem_ctx
,
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
,
33 (ndr_push_flags_fn_t
)ndr_push_NETLOGON_SAM_LOGON_RESPONSE_NT40
);
34 } else if (response
->ntver
& NETLOGON_NT_VERSION_5EX
) {
35 ndr_err
= ndr_push_struct_blob(data
, mem_ctx
,
36 &response
->data
.nt5_ex
,
37 (ndr_push_flags_fn_t
)ndr_push_NETLOGON_SAM_LOGON_RESPONSE_EX_with_flags
);
38 } else if (response
->ntver
& NETLOGON_NT_VERSION_5
) {
39 ndr_err
= ndr_push_struct_blob(data
, mem_ctx
,
41 (ndr_push_flags_fn_t
)ndr_push_NETLOGON_SAM_LOGON_RESPONSE
);
43 DEBUG(0, ("Asked to push unknown netlogon response type 0x%02x\n", response
->ntver
));
44 return NT_STATUS_INVALID_PARAMETER
;
46 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
47 DEBUG(2,("failed to push netlogon response of type 0x%02x\n",
49 return ndr_map_error2ntstatus(ndr_err
);
54 NTSTATUS
pull_netlogon_samlogon_response(DATA_BLOB
*data
, TALLOC_CTX
*mem_ctx
,
55 struct netlogon_samlogon_response
*response
)
58 enum ndr_err_code ndr_err
;
60 if (data
->length
< 8) {
61 return NT_STATUS_BUFFER_TOO_SMALL
;
65 if (SVAL(data
->data
, data
->length
- 4) != 0xffff) {
66 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
69 if (SVAL(data
->data
, data
->length
- 2) != 0xffff) {
70 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
73 ntver
= IVAL(data
->data
, data
->length
- 8);
75 if (ntver
== NETLOGON_NT_VERSION_1
) {
76 ndr_err
= ndr_pull_struct_blob_all(data
, mem_ctx
,
78 (ndr_pull_flags_fn_t
)ndr_pull_NETLOGON_SAM_LOGON_RESPONSE_NT40
);
79 response
->ntver
= NETLOGON_NT_VERSION_1
;
80 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err
) && DEBUGLEVEL
>= 10) {
81 NDR_PRINT_DEBUG(NETLOGON_SAM_LOGON_RESPONSE_NT40
,
85 } else if (ntver
& NETLOGON_NT_VERSION_5EX
) {
87 ndr
= ndr_pull_init_blob(data
, mem_ctx
);
89 return NT_STATUS_NO_MEMORY
;
91 ndr_err
= ndr_pull_NETLOGON_SAM_LOGON_RESPONSE_EX_with_flags(
92 ndr
, NDR_SCALARS
|NDR_BUFFERS
, &response
->data
.nt5_ex
,
94 if (ndr
->offset
< ndr
->data_size
) {
97 * We need to handle a bug in IPA (at least <= 4.1.2).
99 * They include the ip address information without setting
100 * NETLOGON_NT_VERSION_5EX_WITH_IP, while using
101 * ndr_push_NETLOGON_SAM_LOGON_RESPONSE_EX instead of
102 * ndr_push_NETLOGON_SAM_LOGON_RESPONSE_EX_with_flags.
104 ndr_err
= ndr_pull_struct_blob_all(data
, mem_ctx
,
106 (ndr_pull_flags_fn_t
)ndr_pull_NETLOGON_SAM_LOGON_RESPONSE_EX
);
108 response
->ntver
= NETLOGON_NT_VERSION_5EX
;
109 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err
) && DEBUGLEVEL
>= 10) {
110 NDR_PRINT_DEBUG(NETLOGON_SAM_LOGON_RESPONSE_EX
,
111 &response
->data
.nt5_ex
);
114 } else if (ntver
& NETLOGON_NT_VERSION_5
) {
115 ndr_err
= ndr_pull_struct_blob_all(data
, mem_ctx
,
117 (ndr_pull_flags_fn_t
)ndr_pull_NETLOGON_SAM_LOGON_RESPONSE
);
118 response
->ntver
= NETLOGON_NT_VERSION_5
;
119 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err
) && DEBUGLEVEL
>= 10) {
120 NDR_PRINT_DEBUG(NETLOGON_SAM_LOGON_RESPONSE
,
121 &response
->data
.nt5
);
124 DEBUG(2,("failed to parse netlogon response of type 0x%02x - unknown response type\n",
126 dump_data(10, data
->data
, data
->length
);
127 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
130 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
131 DEBUG(2,("failed to parse netlogon response of type 0x%02x\n",
133 dump_data(10, data
->data
, data
->length
);
134 return ndr_map_error2ntstatus(ndr_err
);
140 void map_netlogon_samlogon_response(struct netlogon_samlogon_response
*response
)
142 struct NETLOGON_SAM_LOGON_RESPONSE_EX response_5_ex
;
143 switch (response
->ntver
) {
144 case NETLOGON_NT_VERSION_5EX
:
146 case NETLOGON_NT_VERSION_5
:
147 ZERO_STRUCT(response_5_ex
);
148 response_5_ex
.command
= response
->data
.nt5
.command
;
149 response_5_ex
.pdc_name
= response
->data
.nt5
.pdc_name
;
150 response_5_ex
.user_name
= response
->data
.nt5
.user_name
;
151 response_5_ex
.domain_name
= response
->data
.nt5
.domain_name
;
152 response_5_ex
.domain_uuid
= response
->data
.nt5
.domain_uuid
;
153 response_5_ex
.forest
= response
->data
.nt5
.forest
;
154 response_5_ex
.dns_domain
= response
->data
.nt5
.dns_domain
;
155 response_5_ex
.pdc_dns_name
= response
->data
.nt5
.pdc_dns_name
;
156 response_5_ex
.sockaddr
.pdc_ip
= response
->data
.nt5
.pdc_ip
;
157 response_5_ex
.server_type
= response
->data
.nt5
.server_type
;
158 response_5_ex
.nt_version
= response
->data
.nt5
.nt_version
;
159 response_5_ex
.lmnt_token
= response
->data
.nt5
.lmnt_token
;
160 response_5_ex
.lm20_token
= response
->data
.nt5
.lm20_token
;
161 response
->ntver
= NETLOGON_NT_VERSION_5EX
;
162 response
->data
.nt5_ex
= response_5_ex
;
165 case NETLOGON_NT_VERSION_1
:
166 ZERO_STRUCT(response_5_ex
);
167 response_5_ex
.command
= response
->data
.nt4
.command
;
168 response_5_ex
.pdc_name
= response
->data
.nt4
.pdc_name
;
169 response_5_ex
.user_name
= response
->data
.nt4
.user_name
;
170 response_5_ex
.domain_name
= response
->data
.nt4
.domain_name
;
171 response_5_ex
.nt_version
= response
->data
.nt4
.nt_version
;
172 response_5_ex
.lmnt_token
= response
->data
.nt4
.lmnt_token
;
173 response_5_ex
.lm20_token
= response
->data
.nt4
.lm20_token
;
174 response
->ntver
= NETLOGON_NT_VERSION_5EX
;
175 response
->data
.nt5_ex
= response_5_ex
;
181 NTSTATUS
push_nbt_netlogon_response(DATA_BLOB
*data
, TALLOC_CTX
*mem_ctx
,
182 struct nbt_netlogon_response
*response
)
185 enum ndr_err_code ndr_err
;
186 switch (response
->response_type
) {
187 case NETLOGON_GET_PDC
:
188 ndr_err
= ndr_push_struct_blob(data
, mem_ctx
,
189 &response
->data
.get_pdc
,
190 (ndr_push_flags_fn_t
)ndr_push_nbt_netlogon_response_from_pdc
);
191 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
192 status
= ndr_map_error2ntstatus(ndr_err
);
193 DEBUG(0,("Failed to parse netlogon packet of length %d: %s\n",
194 (int)data
->length
, nt_errstr(status
)));
196 (void)file_save("netlogon.dat", data
->data
, data
->length
);
200 status
= NT_STATUS_OK
;
202 case NETLOGON_SAMLOGON
:
203 status
= push_netlogon_samlogon_response(
205 &response
->data
.samlogon
);
207 case NETLOGON_RESPONSE2
:
208 ndr_err
= ndr_push_struct_blob(data
, mem_ctx
,
209 &response
->data
.response2
,
210 (ndr_push_flags_fn_t
)ndr_push_nbt_netlogon_response2
);
211 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
212 return ndr_map_error2ntstatus(ndr_err
);
214 status
= NT_STATUS_OK
;
217 status
= NT_STATUS_INVALID_NETWORK_RESPONSE
;
225 NTSTATUS
pull_nbt_netlogon_response(DATA_BLOB
*data
, TALLOC_CTX
*mem_ctx
,
226 struct nbt_netlogon_response
*response
)
229 enum netlogon_command command
;
230 enum ndr_err_code ndr_err
;
231 if (data
->length
< 4) {
232 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
235 command
= SVAL(data
->data
, 0);
238 case NETLOGON_RESPONSE_FROM_PDC
:
239 ndr_err
= ndr_pull_struct_blob_all(data
, mem_ctx
,
240 &response
->data
.get_pdc
,
241 (ndr_pull_flags_fn_t
)ndr_pull_nbt_netlogon_response_from_pdc
);
242 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
243 status
= ndr_map_error2ntstatus(ndr_err
);
244 DEBUG(0,("Failed to parse netlogon packet of length %d: %s\n",
245 (int)data
->length
, nt_errstr(status
)));
247 (void)file_save("netlogon.dat", data
->data
, data
->length
);
251 status
= NT_STATUS_OK
;
252 response
->response_type
= NETLOGON_GET_PDC
;
254 case LOGON_RESPONSE2
:
255 ndr_err
= ndr_pull_struct_blob(data
, mem_ctx
, &response
->data
.response2
,
256 (ndr_pull_flags_fn_t
)ndr_pull_nbt_netlogon_response2
);
257 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
258 return ndr_map_error2ntstatus(ndr_err
);
260 status
= NT_STATUS_OK
;
261 response
->response_type
= NETLOGON_RESPONSE2
;
263 case LOGON_SAM_LOGON_RESPONSE
:
264 case LOGON_SAM_LOGON_PAUSE_RESPONSE
:
265 case LOGON_SAM_LOGON_USER_UNKNOWN
:
266 case LOGON_SAM_LOGON_RESPONSE_EX
:
267 case LOGON_SAM_LOGON_PAUSE_RESPONSE_EX
:
268 case LOGON_SAM_LOGON_USER_UNKNOWN_EX
:
269 status
= pull_netlogon_samlogon_response(
271 &response
->data
.samlogon
);
272 response
->response_type
= NETLOGON_SAMLOGON
;
275 /* These levels are queries, not responses */
276 case LOGON_PRIMARY_QUERY
:
278 case NETLOGON_ANNOUNCE_UAS
:
279 case LOGON_SAM_LOGON_REQUEST
:
281 status
= NT_STATUS_INVALID_NETWORK_RESPONSE
;