torture-ndr: fixed NDR tests for NBT blobs
[kai/samba-autobuild/.git] / source4 / torture / ndr / nbt.c
1 /*
2    Unix SMB/CIFS implementation.
3    test suite for nbt ndr operations
4
5    Copyright (C) Guenther Deschner 2010
6
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.
11
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.
16
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/>.
19 */
20
21 #include "includes.h"
22 #include "torture/ndr/ndr.h"
23 #include "librpc/gen_ndr/ndr_nbt.h"
24 #include "torture/ndr/proto.h"
25
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
31 };
32
33 static bool netlogon_logon_request_req_check(struct torture_context *tctx,
34                                              struct nbt_netlogon_packet *r)
35 {
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");
43
44         return true;
45 }
46
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
50 };
51
52 static bool netlogon_logon_request_resp_check(struct torture_context *tctx,
53                                               struct nbt_netlogon_response2 *r)
54 {
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");
58
59         return true;
60 }
61
62 struct torture_suite *ndr_nbt_suite(TALLOC_CTX *ctx)
63 {
64         struct torture_suite *suite = torture_suite_create(ctx, "nbt");
65
66         torture_suite_add_ndr_pull_test(suite, nbt_netlogon_packet, netlogon_logon_request_req_data, netlogon_logon_request_req_check);
67
68         torture_suite_add_ndr_pull_test(suite, nbt_netlogon_response2, netlogon_logon_request_resp_data, netlogon_logon_request_resp_check);
69
70         return suite;
71 }