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/netlogon.h"
25 NTSTATUS
push_netlogon_samlogon_response(DATA_BLOB
*data
, TALLOC_CTX
*mem_ctx
,
26 struct netlogon_samlogon_response
*response
)
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
,
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
,
40 (ndr_push_flags_fn_t
)ndr_push_NETLOGON_SAM_LOGON_RESPONSE
);
42 DEBUG(0, ("Asked to push unknown netlogon response type 0x%02x\n", response
->ntver
));
43 return NT_STATUS_INVALID_PARAMETER
;
45 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
46 DEBUG(2,("failed to push netlogon response of type 0x%02x\n",
48 return ndr_map_error2ntstatus(ndr_err
);
53 NTSTATUS
pull_netlogon_samlogon_response(DATA_BLOB
*data
, TALLOC_CTX
*mem_ctx
,
54 struct netlogon_samlogon_response
*response
)
57 enum ndr_err_code ndr_err
;
59 if (data
->length
< 8) {
60 return NT_STATUS_BUFFER_TOO_SMALL
;
64 if (SVAL(data
->data
, data
->length
- 4) != 0xffff) {
65 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
68 if (SVAL(data
->data
, data
->length
- 2) != 0xffff) {
69 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
72 ntver
= IVAL(data
->data
, data
->length
- 8);
74 if (ntver
== NETLOGON_NT_VERSION_1
) {
75 ndr_err
= ndr_pull_struct_blob_all(data
, mem_ctx
,
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
,
84 } else if (ntver
& NETLOGON_NT_VERSION_5EX
) {
86 ndr
= ndr_pull_init_blob(data
, mem_ctx
);
88 return NT_STATUS_NO_MEMORY
;
90 ndr_err
= ndr_pull_NETLOGON_SAM_LOGON_RESPONSE_EX_with_flags(
91 ndr
, NDR_SCALARS
|NDR_BUFFERS
, &response
->data
.nt5_ex
,
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
);
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
);
104 } else if (ntver
& NETLOGON_NT_VERSION_5
) {
105 ndr_err
= ndr_pull_struct_blob_all(data
, mem_ctx
,
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
,
111 &response
->data
.nt5
);
114 DEBUG(2,("failed to parse netlogon response of type 0x%02x - unknown response type\n",
116 dump_data(10, data
->data
, data
->length
);
117 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
120 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
121 DEBUG(2,("failed to parse netlogon response of type 0x%02x\n",
123 dump_data(10, data
->data
, data
->length
);
124 return ndr_map_error2ntstatus(ndr_err
);
130 void map_netlogon_samlogon_response(struct netlogon_samlogon_response
*response
)
132 struct NETLOGON_SAM_LOGON_RESPONSE_EX response_5_ex
;
133 switch (response
->ntver
) {
134 case NETLOGON_NT_VERSION_5EX
:
136 case NETLOGON_NT_VERSION_5
:
137 ZERO_STRUCT(response_5_ex
);
138 response_5_ex
.command
= response
->data
.nt5
.command
;
139 response_5_ex
.pdc_name
= response
->data
.nt5
.pdc_name
;
140 response_5_ex
.user_name
= response
->data
.nt5
.user_name
;
141 response_5_ex
.domain_name
= response
->data
.nt5
.domain_name
;
142 response_5_ex
.domain_uuid
= response
->data
.nt5
.domain_uuid
;
143 response_5_ex
.forest
= response
->data
.nt5
.forest
;
144 response_5_ex
.dns_domain
= response
->data
.nt5
.dns_domain
;
145 response_5_ex
.pdc_dns_name
= response
->data
.nt5
.pdc_dns_name
;
146 response_5_ex
.sockaddr
.pdc_ip
= response
->data
.nt5
.pdc_ip
;
147 response_5_ex
.server_type
= response
->data
.nt5
.server_type
;
148 response_5_ex
.nt_version
= response
->data
.nt5
.nt_version
;
149 response_5_ex
.lmnt_token
= response
->data
.nt5
.lmnt_token
;
150 response_5_ex
.lm20_token
= response
->data
.nt5
.lm20_token
;
151 response
->ntver
= NETLOGON_NT_VERSION_5EX
;
152 response
->data
.nt5_ex
= response_5_ex
;
155 case NETLOGON_NT_VERSION_1
:
156 ZERO_STRUCT(response_5_ex
);
157 response_5_ex
.command
= response
->data
.nt4
.command
;
158 response_5_ex
.pdc_name
= response
->data
.nt4
.pdc_name
;
159 response_5_ex
.user_name
= response
->data
.nt4
.user_name
;
160 response_5_ex
.domain_name
= response
->data
.nt4
.domain_name
;
161 response_5_ex
.nt_version
= response
->data
.nt4
.nt_version
;
162 response_5_ex
.lmnt_token
= response
->data
.nt4
.lmnt_token
;
163 response_5_ex
.lm20_token
= response
->data
.nt4
.lm20_token
;
164 response
->ntver
= NETLOGON_NT_VERSION_5EX
;
165 response
->data
.nt5_ex
= response_5_ex
;
171 NTSTATUS
push_nbt_netlogon_response(DATA_BLOB
*data
, TALLOC_CTX
*mem_ctx
,
172 struct nbt_netlogon_response
*response
)
174 NTSTATUS status
= NT_STATUS_INVALID_NETWORK_RESPONSE
;
175 enum ndr_err_code ndr_err
;
176 switch (response
->response_type
) {
177 case NETLOGON_GET_PDC
:
178 ndr_err
= ndr_push_struct_blob(data
, mem_ctx
,
179 &response
->data
.get_pdc
,
180 (ndr_push_flags_fn_t
)ndr_push_nbt_netlogon_response_from_pdc
);
181 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
182 status
= ndr_map_error2ntstatus(ndr_err
);
183 DEBUG(0,("Failed to parse netlogon packet of length %d: %s\n",
184 (int)data
->length
, nt_errstr(status
)));
186 file_save("netlogon.dat", data
->data
, data
->length
);
190 status
= NT_STATUS_OK
;
192 case NETLOGON_SAMLOGON
:
193 status
= push_netlogon_samlogon_response(
195 &response
->data
.samlogon
);
197 case NETLOGON_RESPONSE2
:
198 ndr_err
= ndr_push_struct_blob(data
, mem_ctx
,
199 &response
->data
.response2
,
200 (ndr_push_flags_fn_t
)ndr_push_nbt_netlogon_response2
);
201 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
202 return ndr_map_error2ntstatus(ndr_err
);
204 status
= NT_STATUS_OK
;
212 NTSTATUS
pull_nbt_netlogon_response(DATA_BLOB
*data
, TALLOC_CTX
*mem_ctx
,
213 struct nbt_netlogon_response
*response
)
215 NTSTATUS status
= NT_STATUS_INVALID_NETWORK_RESPONSE
;
216 enum netlogon_command command
;
217 enum ndr_err_code ndr_err
;
218 if (data
->length
< 4) {
219 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
222 command
= SVAL(data
->data
, 0);
225 case NETLOGON_RESPONSE_FROM_PDC
:
226 ndr_err
= ndr_pull_struct_blob_all(data
, mem_ctx
,
227 &response
->data
.get_pdc
,
228 (ndr_pull_flags_fn_t
)ndr_pull_nbt_netlogon_response_from_pdc
);
229 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
230 status
= ndr_map_error2ntstatus(ndr_err
);
231 DEBUG(0,("Failed to parse netlogon packet of length %d: %s\n",
232 (int)data
->length
, nt_errstr(status
)));
234 file_save("netlogon.dat", data
->data
, data
->length
);
238 status
= NT_STATUS_OK
;
239 response
->response_type
= NETLOGON_GET_PDC
;
241 case LOGON_RESPONSE2
:
242 ndr_err
= ndr_pull_struct_blob(data
, mem_ctx
, &response
->data
.response2
,
243 (ndr_pull_flags_fn_t
)ndr_pull_nbt_netlogon_response2
);
244 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
245 return ndr_map_error2ntstatus(ndr_err
);
247 status
= NT_STATUS_OK
;
248 response
->response_type
= NETLOGON_RESPONSE2
;
250 case LOGON_SAM_LOGON_RESPONSE
:
251 case LOGON_SAM_LOGON_PAUSE_RESPONSE
:
252 case LOGON_SAM_LOGON_USER_UNKNOWN
:
253 case LOGON_SAM_LOGON_RESPONSE_EX
:
254 case LOGON_SAM_LOGON_PAUSE_RESPONSE_EX
:
255 case LOGON_SAM_LOGON_USER_UNKNOWN_EX
:
256 status
= pull_netlogon_samlogon_response(
258 &response
->data
.samlogon
);
259 response
->response_type
= NETLOGON_SAMLOGON
;
262 /* These levels are queries, not responses */
263 case LOGON_PRIMARY_QUERY
:
265 case NETLOGON_ANNOUNCE_UAS
:
266 case LOGON_SAM_LOGON_REQUEST
:
267 status
= NT_STATUS_INVALID_NETWORK_RESPONSE
;