LCOV - code coverage report
Current view: top level - source4/torture/ndr - nbt.c (source / functions) Hit Total Coverage
Test: coverage report for vadcx-master-patch-75612 fe003de8 Lines: 86 92 93.5 %
Date: 2024-02-29 22:57:05 Functions: 7 7 100.0 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             :    test suite for nbt ndr operations
       4             : 
       5             :    Copyright (C) Guenther Deschner 2010-2012
       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           2 : static bool netlogon_logon_request_req_check(struct torture_context *tctx,
      34             :                                              struct nbt_netlogon_packet *r)
      35             : {
      36           2 :         torture_assert_int_equal(tctx, r->command, LOGON_REQUEST, "command");
      37           2 :         torture_assert_str_equal(tctx, r->req.logon0.computer_name, "WIN98", "computer name");
      38           2 :         torture_assert_str_equal(tctx, r->req.logon0.user_name, "GD", "user_name");
      39           2 :         torture_assert_str_equal(tctx, r->req.logon0.mailslot_name, "\\MAILSLOT\\TEMP\\NETLOGON", "mailslot_name");
      40           2 :         torture_assert_int_equal(tctx, r->req.logon0.request_count, 1, "request_count");
      41           2 :         torture_assert_int_equal(tctx, r->req.logon0.lmnt_token, 1, "lmnt_token");
      42           2 :         torture_assert_int_equal(tctx, r->req.logon0.lm20_token, 0xffff, "lm20_token");
      43             : 
      44           0 :         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           2 : static bool netlogon_logon_request_resp_check(struct torture_context *tctx,
      53             :                                               struct nbt_netlogon_response2 *r)
      54             : {
      55           2 :         torture_assert_int_equal(tctx, r->command, LOGON_RESPONSE2, "command");
      56           2 :         torture_assert_str_equal(tctx, r->pdc_name, "\\\\MTHELENA", "pdc_name");
      57           2 :         torture_assert_int_equal(tctx, r->lm20_token, 0xffff, "lm20_token");
      58             : 
      59           0 :         return true;
      60             : }
      61             : 
      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,
      74             : };
      75             : 
      76           4 : static bool netlogon_samlogon_response_check(struct torture_context *tctx,
      77             :                                              struct netlogon_samlogon_response *r)
      78             : {
      79           4 :         struct GUID guid;
      80           4 :         torture_assert_ntstatus_ok(tctx, GUID_from_string("cd441303-001c-464c-a621-e9d6b9b12fe9", &guid), "");
      81             : 
      82           4 :         torture_assert_int_equal(tctx, r->ntver, 5, "ntver");
      83           4 :         torture_assert_int_equal(tctx, r->data.nt5_ex.command, LOGON_SAM_LOGON_RESPONSE_EX, "command");
      84           4 :         torture_assert_int_equal(tctx, r->data.nt5_ex.sbz, 0, "sbz");
      85           4 :         torture_assert_int_equal(tctx, r->data.nt5_ex.server_type, 0x000033fd, "server_type");
      86           4 :         torture_assert_guid_equal(tctx, r->data.nt5_ex.domain_uuid, guid, "domain_uuid");
      87           4 :         torture_assert_str_equal(tctx, r->data.nt5_ex.forest, "w2k8dom.ber.redhat.com", "forest");
      88           4 :         torture_assert_str_equal(tctx, r->data.nt5_ex.dns_domain, "w2k8dom.ber.redhat.com", "dns_domain");
      89           4 :         torture_assert_str_equal(tctx, r->data.nt5_ex.pdc_dns_name, "gdw2k8r2.w2k8dom.ber.redhat.com", "pdc_dns_name");
      90           4 :         torture_assert_str_equal(tctx, r->data.nt5_ex.domain_name, "W2K8DOM", "domain_name");
      91           4 :         torture_assert_str_equal(tctx, r->data.nt5_ex.pdc_name, "GDW2K8R2", "pdc_name");
      92           4 :         torture_assert_str_equal(tctx, r->data.nt5_ex.user_name, "", "user_name");
      93           4 :         torture_assert_str_equal(tctx, r->data.nt5_ex.server_site, "Default-First-Site-Name", "server_site");
      94           4 :         torture_assert_str_equal(tctx, r->data.nt5_ex.client_site, "Default-First-Site-Name", "client_site");
      95           4 :         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           4 :         torture_assert_int_equal(tctx, r->data.nt5_ex.nt_version, 5, "nt_version");
     101             :         /* next_closest_site NULL */
     102           4 :         torture_assert_int_equal(tctx, r->data.nt5_ex.lmnt_token, 0xffff, "lmnt_token");
     103           4 :         torture_assert_int_equal(tctx, r->data.nt5_ex.lm20_token, 0xffff, "lm20_token");
     104             : 
     105           0 :         return true;
     106             : }
     107             : 
     108             : static const uint8_t nbt_netlogon_packet_data[] = {
     109             :         0x12, 0x00, 0x00, 0x00, 0x4c, 0x00, 0x45, 0x00, 0x4e, 0x00, 0x4e, 0x00,
     110             :         0x59, 0x00, 0x00, 0x00, 0x4c, 0x00, 0x45, 0x00, 0x4e, 0x00, 0x4e, 0x00,
     111             :         0x59, 0x00, 0x24, 0x00, 0x00, 0x00, 0x5c, 0x4d, 0x41, 0x49, 0x4c, 0x53,
     112             :         0x4c, 0x4f, 0x54, 0x5c, 0x4e, 0x45, 0x54, 0x5c, 0x47, 0x45, 0x54, 0x44,
     113             :         0x43, 0x35, 0x32, 0x45, 0x41, 0x41, 0x38, 0x43, 0x30, 0x00, 0x80, 0x00,
     114             :         0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x04, 0x00, 0x00,
     115             :         0x00, 0x00, 0x00, 0x05, 0x15, 0x00, 0x00, 0x00, 0x9c, 0x4e, 0x59, 0xff,
     116             :         0xe1, 0xa0, 0x39, 0xac, 0x29, 0xa6, 0xe2, 0xda, 0x01, 0x00, 0x00, 0x00,
     117             :         0xff, 0xff, 0xff, 0xff
     118             : };
     119             : 
     120           2 : static bool nbt_netlogon_packet_check(struct torture_context *tctx,
     121             :                                       struct nbt_netlogon_packet *r)
     122             : {
     123           2 :         torture_assert_int_equal(tctx, r->command, LOGON_SAM_LOGON_REQUEST, "command");
     124           2 :         torture_assert_int_equal(tctx, r->req.logon.request_count, 0, "request_count");
     125           2 :         torture_assert_str_equal(tctx, r->req.logon.computer_name, "LENNY", "computer_name");
     126           2 :         torture_assert_str_equal(tctx, r->req.logon.user_name, "LENNY$", "user_name");
     127           2 :         torture_assert_str_equal(tctx, r->req.logon.mailslot_name, "\\MAILSLOT\\NET\\GETDC52EAA8C0", "mailslot_name");
     128           2 :         torture_assert_int_equal(tctx, r->req.logon.acct_control, 0x00000080, "acct_control");
     129           2 :         torture_assert_int_equal(tctx, r->req.logon.sid_size, 24, "sid_size");
     130           2 :         torture_assert_int_equal(tctx, r->req.logon._pad.length, 2, "_pad.length");
     131           2 :         torture_assert_sid_equal(tctx, &r->req.logon.sid, dom_sid_parse_talloc(tctx, "S-1-5-21-4284042908-2889457889-3672286761"), "sid");
     132           2 :         torture_assert_int_equal(tctx, r->req.logon.nt_version, NETLOGON_NT_VERSION_1, "nt_version");
     133           2 :         torture_assert_int_equal(tctx, r->req.logon.lmnt_token, 0xffff, "lmnt_token");
     134           2 :         torture_assert_int_equal(tctx, r->req.logon.lm20_token, 0xffff, "lm20_token");
     135             : 
     136           0 :         return true;
     137             : }
     138             : 
     139             : static const uint8_t nbt_netlogon_packet_logon_primary_query_data[] = {
     140             :         0x07, 0x00, 0x58, 0x50, 0x44, 0x41, 0x54, 0x45, 0x56, 0x2d, 0x50, 0x52,
     141             :         0x4f, 0x00, 0x5c, 0x4d, 0x41, 0x49, 0x4c, 0x53, 0x4c, 0x4f, 0x54, 0x5c,
     142             :         0x4e, 0x45, 0x54, 0x5c, 0x47, 0x45, 0x54, 0x44, 0x43, 0x38, 0x31, 0x37,
     143             :         0x00, 0x00, 0x58, 0x00, 0x50, 0x00, 0x44, 0x00, 0x41, 0x00, 0x54, 0x00,
     144             :         0x45, 0x00, 0x56, 0x00, 0x2d, 0x00, 0x50, 0x00, 0x52, 0x00, 0x4f, 0x00,
     145             :         0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff
     146             : };
     147             : 
     148           4 : static bool nbt_netlogon_packet_logon_primary_query_check(struct torture_context *tctx,
     149             :                                                           struct nbt_netlogon_packet *r)
     150             : {
     151           4 :         torture_assert_int_equal(tctx, r->command, LOGON_PRIMARY_QUERY, "command");
     152           4 :         torture_assert_str_equal(tctx, r->req.pdc.computer_name, "XPDATEV-PRO", "computer_name");
     153           4 :         torture_assert_str_equal(tctx, r->req.pdc.mailslot_name, "\\MAILSLOT\\NET\\GETDC817", "mailslot_name");
     154           4 :         torture_assert_int_equal(tctx, r->req.pdc._pad.length, 1, "_pad.length");
     155           4 :         torture_assert_int_equal(tctx, r->req.pdc._pad.data[0], 0, "_pad.data");
     156           4 :         torture_assert_str_equal(tctx, r->req.pdc.unicode_name, "XPDATEV-PRO", "unicode_name");
     157           4 :         torture_assert_int_equal(tctx, r->req.pdc.nt_version, 0x0000000b, "nt_version");
     158           4 :         torture_assert_int_equal(tctx, r->req.pdc.lmnt_token, 0xffff, "lmnt_token");
     159           4 :         torture_assert_int_equal(tctx, r->req.pdc.lm20_token, 0xffff, "lm20_token");
     160             : 
     161           0 :         return true;
     162             : }
     163             : 
     164             : static const uint8_t netlogon_samlogon_response_data2[] = {
     165             : /*      0x04, 0x77, 0x17, 0x00, 0x00, 0x00, 0xfd, 0x33, 0x00, 0x00, 0x55, 0xaf,*/
     166             :                     0x17, 0x00, 0x00, 0x00, 0xfd, 0x33, 0x00, 0x00, 0x55, 0xaf,
     167             :         0x8d, 0x13, 0x8c, 0x91, 0x70, 0x41, 0x9d, 0x46, 0xd4, 0xd5, 0x04, 0x90,
     168             :         0xaa, 0x13, 0x03, 0x62, 0x6c, 0x61, 0x04, 0x62, 0x61, 0x73, 0x65, 0x00,
     169             :         0xc0, 0x18, 0x0a, 0x57, 0x32, 0x4b, 0x38, 0x52, 0x32, 0x2d, 0x32, 0x31,
     170             :         0x39, 0xc0, 0x18, 0x03, 0x42, 0x4c, 0x41, 0x00, 0x0a, 0x57, 0x32, 0x4b,
     171             :         0x38, 0x52, 0x32, 0x2d, 0x32, 0x31, 0x39, 0x00, 0x0a, 0x77, 0x32, 0x30,
     172             :         0x31, 0x32, 0x72, 0x32, 0x2d, 0x6c, 0x36, 0x05, 0x62, 0x61, 0x73, 0x65,
     173             :         0x2e, 0x00, 0x17, 0x44, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x2d, 0x46,
     174             :         0x69, 0x72, 0x73, 0x74, 0x2d, 0x53, 0x69, 0x74, 0x65, 0x2d, 0x4e, 0x61,
     175             :         0x6d, 0x65, 0x00, 0xc0, 0x54, 0x05, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff,
     176             :         0xff
     177             : };
     178             : 
     179           2 : static bool netlogon_samlogon_response_check2(struct torture_context *tctx,
     180             :                                               struct netlogon_samlogon_response *r)
     181             : {
     182           2 :         struct GUID guid;
     183           2 :         torture_assert_ntstatus_ok(tctx, GUID_from_string("138daf55-918c-4170-9d46-d4d50490aa13", &guid), "");
     184             : 
     185           2 :         torture_assert_int_equal(tctx, r->ntver, 5, "ntver");
     186           2 :         torture_assert_int_equal(tctx, r->data.nt5_ex.command, LOGON_SAM_LOGON_RESPONSE_EX, "command");
     187           2 :         torture_assert_int_equal(tctx, r->data.nt5_ex.sbz, 0, "sbz");
     188           2 :         torture_assert_int_equal(tctx, r->data.nt5_ex.server_type, 0x000033fd, "server_type");
     189           2 :         torture_assert_guid_equal(tctx, r->data.nt5_ex.domain_uuid, guid, "domain_uuid");
     190           2 :         torture_assert_str_equal(tctx, r->data.nt5_ex.forest, "bla.base", "forest");
     191           2 :         torture_assert_str_equal(tctx, r->data.nt5_ex.dns_domain, "bla.base", "dns_domain");
     192           2 :         torture_assert_str_equal(tctx, r->data.nt5_ex.pdc_dns_name, "W2K8R2-219.bla.base", "pdc_dns_name");
     193           2 :         torture_assert_str_equal(tctx, r->data.nt5_ex.domain_name, "BLA", "domain_name");
     194           2 :         torture_assert_str_equal(tctx, r->data.nt5_ex.pdc_name, "W2K8R2-219", "pdc_name");
     195           2 :         torture_assert_str_equal(tctx, r->data.nt5_ex.user_name, "w2012r2-l6.base.", "user_name");
     196           2 :         torture_assert_str_equal(tctx, r->data.nt5_ex.server_site, "Default-First-Site-Name", "server_site");
     197           2 :         torture_assert_str_equal(tctx, r->data.nt5_ex.client_site, "Default-First-Site-Name", "client_site");
     198           2 :         torture_assert_int_equal(tctx, r->data.nt5_ex.sockaddr_size, 0, "sockaddr_size");
     199             :         /*
     200             :          * sockaddr: struct nbt_sockaddr
     201             :          *             sockaddr_family          : 0x00000000 (0)
     202             :          *             pdc_ip                   : (null)
     203             :          *             remaining                : DATA_BLOB length=0
     204             :          */
     205           2 :         torture_assert_int_equal(tctx, r->data.nt5_ex.nt_version, 5, "nt_version");
     206             :         /* next_closest_site NULL */
     207           2 :         torture_assert_int_equal(tctx, r->data.nt5_ex.lmnt_token, 0xffff, "lmnt_token");
     208           2 :         torture_assert_int_equal(tctx, r->data.nt5_ex.lm20_token, 0xffff, "lm20_token");
     209             : 
     210           0 :         return true;
     211             : }
     212             : 
     213             : 
     214        2354 : struct torture_suite *ndr_nbt_suite(TALLOC_CTX *ctx)
     215             : {
     216        2354 :         struct torture_suite *suite = torture_suite_create(ctx, "nbt");
     217             : 
     218        2354 :         torture_suite_add_ndr_pull_test(suite, nbt_netlogon_packet, netlogon_logon_request_req_data, netlogon_logon_request_req_check);
     219             : 
     220        2354 :         torture_suite_add_ndr_pull_test(suite,
     221             :                                         nbt_netlogon_packet,
     222             :                                         nbt_netlogon_packet_logon_primary_query_data,
     223             :                                         nbt_netlogon_packet_logon_primary_query_check);
     224             : 
     225        2354 :         torture_suite_add_ndr_pull_test(suite, nbt_netlogon_response2, netlogon_logon_request_resp_data, netlogon_logon_request_resp_check);
     226             : 
     227        2354 :         torture_suite_add_ndr_pull_test(suite,
     228             :                                         netlogon_samlogon_response,
     229             :                                         netlogon_samlogon_response_data,
     230             :                                         netlogon_samlogon_response_check);
     231             : 
     232        2354 :         torture_suite_add_ndr_pull_validate_test(suite,
     233             :                                             netlogon_samlogon_response,
     234             :                                             netlogon_samlogon_response_data,
     235             :                                             netlogon_samlogon_response_check);
     236             : 
     237        2354 :         torture_suite_add_ndr_pull_validate_test(suite,
     238             :                                             nbt_netlogon_packet,
     239             :                                             nbt_netlogon_packet_data,
     240             :                                             nbt_netlogon_packet_check);
     241             : 
     242        2354 :         torture_suite_add_ndr_pull_validate_test(suite,
     243             :                                             nbt_netlogon_packet,
     244             :                                             nbt_netlogon_packet_logon_primary_query_data,
     245             :                                             nbt_netlogon_packet_logon_primary_query_check);
     246             : 
     247        2354 :         torture_suite_add_ndr_pull_validate_test(suite,
     248             :                                             netlogon_samlogon_response,
     249             :                                             netlogon_samlogon_response_data2,
     250             :                                             netlogon_samlogon_response_check2);
     251             : 
     252        2354 :         return suite;
     253             : }

Generated by: LCOV version 1.14