s4-smbtorture: add some ndr validation tests for netlogon_samlogon_response structs.
[Samba/id10ts.git] / source4 / torture / ndr / nbt.c
blobcc25dd5ff53b5b11d3d342818bda59f70669a202
1 /*
2 Unix SMB/CIFS implementation.
3 test suite for nbt ndr operations
5 Copyright (C) Guenther Deschner 2010,2011
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "includes.h"
22 #include "torture/ndr/ndr.h"
23 #include "librpc/gen_ndr/ndr_nbt.h"
24 #include "torture/ndr/proto.h"
26 static const uint8_t netlogon_logon_request_req_data[] = {
27 0x00, 0x00, 0x57, 0x49, 0x4e, 0x39, 0x38, 0x00, 0x47, 0x44, 0x00, 0x5c,
28 0x4d, 0x41, 0x49, 0x4c, 0x53, 0x4c, 0x4f, 0x54, 0x5c, 0x54, 0x45, 0x4d,
29 0x50, 0x5c, 0x4e, 0x45, 0x54, 0x4c, 0x4f, 0x47, 0x4f, 0x4e, 0x00, 0x01,
30 0x01, 0x00, 0xff, 0xff
33 static bool netlogon_logon_request_req_check(struct torture_context *tctx,
34 struct nbt_netlogon_packet *r)
36 torture_assert_int_equal(tctx, r->command, LOGON_REQUEST, "command");
37 torture_assert_str_equal(tctx, r->req.logon0.computer_name, "WIN98", "computer name");
38 torture_assert_str_equal(tctx, r->req.logon0.user_name, "GD", "user_name");
39 torture_assert_str_equal(tctx, r->req.logon0.mailslot_name, "\\MAILSLOT\\TEMP\\NETLOGON", "mailslot_name");
40 torture_assert_int_equal(tctx, r->req.logon0.request_count, 1, "request_count");
41 torture_assert_int_equal(tctx, r->req.logon0.lmnt_token, 1, "lmnt_token");
42 torture_assert_int_equal(tctx, r->req.logon0.lm20_token, 0xffff, "lm20_token");
44 return true;
47 static const uint8_t netlogon_logon_request_resp_data[] = {
48 0x06, 0x00, 0x5c, 0x5c, 0x4d, 0x54, 0x48, 0x45, 0x4c, 0x45, 0x4e, 0x41,
49 0x00, 0xff, 0xff
52 static bool netlogon_logon_request_resp_check(struct torture_context *tctx,
53 struct nbt_netlogon_response2 *r)
55 torture_assert_int_equal(tctx, r->command, LOGON_RESPONSE2, "command");
56 torture_assert_str_equal(tctx, r->pdc_name, "\\\\MTHELENA", "pdc_name");
57 torture_assert_int_equal(tctx, r->lm20_token, 0xffff, "lm20_token");
59 return true;
62 static const uint8_t netlogon_samlogon_response_data[] = {
63 /* 0x04, 0x74, 0x17, 0x00, 0x00, 0x00, 0xfd, 0x33, 0x00, 0x00, 0x03, 0x13, */
64 0x17, 0x00, 0x00, 0x00, 0xfd, 0x33, 0x00, 0x00, 0x03, 0x13,
65 0x44, 0xcd, 0x1c, 0x00, 0x4c, 0x46, 0xa6, 0x21, 0xe9, 0xd6, 0xb9, 0xb1,
66 0x2f, 0xe9, 0x07, 0x77, 0x32, 0x6b, 0x38, 0x64, 0x6f, 0x6d, 0x03, 0x62,
67 0x65, 0x72, 0x06, 0x72, 0x65, 0x64, 0x68, 0x61, 0x74, 0x03, 0x63, 0x6f,
68 0x6d, 0x00, 0xc0, 0x18, 0x08, 0x67, 0x64, 0x77, 0x32, 0x6b, 0x38, 0x72,
69 0x32, 0xc0, 0x18, 0x07, 0x57, 0x32, 0x4b, 0x38, 0x44, 0x4f, 0x4d, 0x00,
70 0x08, 0x47, 0x44, 0x57, 0x32, 0x4b, 0x38, 0x52, 0x32, 0x00, 0x00, 0x17,
71 0x44, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x2d, 0x46, 0x69, 0x72, 0x73,
72 0x74, 0x2d, 0x53, 0x69, 0x74, 0x65, 0x2d, 0x4e, 0x61, 0x6d, 0x65, 0x00,
73 0xc0, 0x51, 0x05, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
76 static bool netlogon_samlogon_response_check(struct torture_context *tctx,
77 struct netlogon_samlogon_response *r)
79 struct GUID guid;
80 torture_assert_ntstatus_ok(tctx, GUID_from_string("cd441303-001c-464c-a621-e9d6b9b12fe9", &guid), "");
82 torture_assert_int_equal(tctx, r->ntver, 5, "ntver");
83 torture_assert_int_equal(tctx, r->data.nt5_ex.command, LOGON_SAM_LOGON_RESPONSE_EX, "command");
84 torture_assert_int_equal(tctx, r->data.nt5_ex.sbz, 0, "sbz");
85 torture_assert_int_equal(tctx, r->data.nt5_ex.server_type, 0x000033fd, "server_type");
86 torture_assert_guid_equal(tctx, r->data.nt5_ex.domain_uuid, guid, "domain_uuid");
87 torture_assert_str_equal(tctx, r->data.nt5_ex.forest, "w2k8dom.ber.redhat.com", "forest");
88 torture_assert_str_equal(tctx, r->data.nt5_ex.dns_domain, "w2k8dom.ber.redhat.com", "dns_domain");
89 torture_assert_str_equal(tctx, r->data.nt5_ex.pdc_dns_name, "gdw2k8r2.w2k8dom.ber.redhat.com", "pdc_dns_name");
90 torture_assert_str_equal(tctx, r->data.nt5_ex.domain_name, "W2K8DOM", "domain_name");
91 torture_assert_str_equal(tctx, r->data.nt5_ex.pdc_name, "GDW2K8R2", "pdc_name");
92 torture_assert_str_equal(tctx, r->data.nt5_ex.user_name, "", "user_name");
93 torture_assert_str_equal(tctx, r->data.nt5_ex.server_site, "Default-First-Site-Name", "server_site");
94 torture_assert_str_equal(tctx, r->data.nt5_ex.client_site, "Default-First-Site-Name", "client_site");
95 torture_assert_int_equal(tctx, r->data.nt5_ex.sockaddr_size, 0, "sockaddr_size");
96 /* sockaddr: struct nbt_sockaddr
97 * sockaddr_family : 0x00000000 (0)
98 * pdc_ip : (null)
99 * remaining : DATA_BLOB length=0 */
100 torture_assert_int_equal(tctx, r->data.nt5_ex.nt_version, 5, "nt_version");
101 /* next_closest_site NULL */
102 torture_assert_int_equal(tctx, r->data.nt5_ex.lmnt_token, 0xffff, "lmnt_token");
103 torture_assert_int_equal(tctx, r->data.nt5_ex.lm20_token, 0xffff, "lm20_token");
105 return true;
108 struct torture_suite *ndr_nbt_suite(TALLOC_CTX *ctx)
110 struct torture_suite *suite = torture_suite_create(ctx, "nbt");
112 torture_suite_add_ndr_pull_test(suite, nbt_netlogon_packet, netlogon_logon_request_req_data, netlogon_logon_request_req_check);
114 torture_suite_add_ndr_pull_test(suite, nbt_netlogon_response2, netlogon_logon_request_resp_data, netlogon_logon_request_resp_check);
116 torture_suite_add_ndr_pull_test(suite,
117 netlogon_samlogon_response,
118 netlogon_samlogon_response_data,
119 netlogon_samlogon_response_check);
121 torture_suite_add_ndr_pullpush_test(suite,
122 netlogon_samlogon_response,
123 data_blob_const(netlogon_samlogon_response_data, sizeof(netlogon_samlogon_response_data)),
124 netlogon_samlogon_response_check);
126 return suite;