LCOV - code coverage report
Current view: top level - source4/torture/dfs - domaindfs.c (source / functions) Hit Total Coverage
Test: coverage report for master 2f515e9b Lines: 165 186 88.7 %
Date: 2024-04-21 15:09:00 Functions: 8 8 100.0 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             :    test suite for various Domain DFS
       4             :    Copyright (C) Matthieu Patou 2010
       5             : 
       6             :    This program is free software; you can redistribute it and/or modify
       7             :    it under the terms of the GNU General Public License as published by
       8             :    the Free Software Foundation; either version 3 of the License, or
       9             :    (at your option) any later version.
      10             : 
      11             :    This program is distributed in the hope that it will be useful,
      12             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14             :    GNU General Public License for more details.
      15             : 
      16             :    You should have received a copy of the GNU General Public License
      17             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      18             : */
      19             : 
      20             : #include "includes.h"
      21             : #include "libcli/libcli.h"
      22             : #include "torture/smbtorture.h"
      23             : #include "torture/util.h"
      24             : #include "../librpc/gen_ndr/ndr_dfsblobs.h"
      25             : #include "librpc/ndr/libndr.h"
      26             : #include "param/param.h"
      27             : #include "torture/torture.h"
      28             : #include "torture/dfs/proto.h"
      29             : 
      30           3 : static bool test_getdomainreferral(struct torture_context *tctx,
      31             :                                struct smbcli_state *cli)
      32             : {
      33           0 :         struct dfs_GetDFSReferral r;
      34           0 :         struct dfs_referral_resp resp;
      35             : 
      36           3 :         r.in.req.max_referral_level = 3;
      37           3 :         r.in.req.servername = "";
      38           3 :         r.out.resp = &resp;
      39             : 
      40           3 :         torture_assert_ntstatus_ok(tctx,
      41             :                    dfs_cli_do_call(cli->tree, &r),
      42             :                    "Get Domain referral failed");
      43             : 
      44           3 :         torture_assert_int_equal(tctx, resp.path_consumed, 0,
      45             :                                  "Path consumed not equal to 0");
      46           3 :         torture_assert_int_equal(tctx, resp.nb_referrals != 0, 1,
      47             :                                  "0 domains referrals returned");
      48           3 :         torture_assert_int_equal(tctx, resp.header_flags, 0,
      49             :                                  "Header flag different it's not a referral server");
      50           3 :         torture_assert_int_equal(tctx, resp.referral_entries[1].version, 3,
      51             :                                  talloc_asprintf(tctx,
      52             :                                         "Not expected version for referral entry 1 got %d expected 3",
      53             :                                         resp.referral_entries[1].version));
      54           3 :         torture_assert_int_equal(tctx, resp.referral_entries[0].version, 3,
      55             :                                  talloc_asprintf(tctx,
      56             :                                         "Not expected version for referral entry 0 got %d expected 3",
      57             :                                         resp.referral_entries[0].version));
      58           3 :         torture_assert_int_equal(tctx, resp.referral_entries[0].referral.v3.server_type,
      59             :                                  DFS_SERVER_NON_ROOT,
      60             :                                  talloc_asprintf(tctx,
      61             :                                         "Wrong server type, expected non root server and got %d",
      62             :                                         resp.referral_entries[0].referral.v3.server_type));
      63           3 :         torture_assert_int_equal(tctx, resp.referral_entries[0].referral.v3.entry_flags,
      64             :                                  DFS_FLAG_REFERRAL_DOMAIN_RESP,
      65             :                                  talloc_asprintf(tctx,
      66             :                                         "Wrong entry flag expected to have a domain response and got %d",
      67             :                                         resp.referral_entries[0].referral.v3.entry_flags));
      68           3 :         torture_assert_int_equal(tctx, strlen(
      69             :                                  resp.referral_entries[0].referral.v3.referrals.r2.special_name) > 0,
      70             :                                  1,
      71             :                                  "Length of domain is 0 or less");
      72           3 :         torture_assert_int_equal(tctx,
      73             :                                  resp.referral_entries[0].referral.v3.referrals.r2.special_name[0] == '\\',
      74             :                                  1,
      75             :                                  "domain didn't start with a \\");
      76           3 :         return true;
      77             : }
      78             : 
      79           3 : static bool test_getdcreferral(struct torture_context *tctx,
      80             :                                struct smbcli_state *cli)
      81             : {
      82           0 :         struct dfs_GetDFSReferral r, r2, r3;
      83           0 :         struct dfs_referral_resp resp, resp2, resp3;
      84           0 :         const char* str;
      85           0 :         const char* str2;
      86             : 
      87           3 :         r.in.req.max_referral_level = 3;
      88           3 :         r.in.req.servername = "";
      89           3 :         r.out.resp = &resp;
      90             : 
      91           3 :         torture_assert_ntstatus_ok(tctx,
      92             :                    dfs_cli_do_call(cli->tree, &r),
      93             :                    "Get Domain referral failed");
      94             : 
      95           3 :         str = resp.referral_entries[0].referral.v3.referrals.r2.special_name;
      96           3 :         if( strchr(str, '.') == NULL ) {
      97           3 :                 str = resp.referral_entries[1].referral.v3.referrals.r2.special_name;
      98             :         }
      99             : 
     100           3 :         r2.in.req.max_referral_level = 3;
     101           3 :         r2.in.req.servername = str;
     102           3 :         r2.out.resp = &resp2;
     103             : 
     104           3 :         torture_assert_ntstatus_ok(tctx,
     105             :                    dfs_cli_do_call(cli->tree, &r2),
     106             :                    "Get DC Domain referral failed");
     107             : 
     108             : 
     109           3 :         torture_assert_int_equal(tctx, resp2.path_consumed, 0,
     110             :                                  "Path consumed not equal to 0");
     111           3 :         torture_assert_int_equal(tctx, resp2.nb_referrals , 1,
     112             :                                  "We do not received only 1 referral");
     113           3 :         torture_assert_int_equal(tctx, resp2.header_flags, 0,
     114             :                                  "Header flag different it's not a referral server");
     115           3 :         torture_assert_int_equal(tctx, resp2.referral_entries[0].version, 3,
     116             :                                  talloc_asprintf(tctx,
     117             :                                         "Not expected version for referral entry 0 got %d expected 3",
     118             :                                         resp2.referral_entries[0].version));
     119           3 :         torture_assert_int_equal(tctx, resp2.referral_entries[0].referral.v3.server_type,
     120             :                                  DFS_SERVER_NON_ROOT,
     121             :                                  talloc_asprintf(tctx,
     122             :                                         "Wrong server type, expected non root server and got %d",
     123             :                                         resp2.referral_entries[0].referral.v3.server_type));
     124           3 :         torture_assert_int_equal(tctx, resp2.referral_entries[0].referral.v3.entry_flags,
     125             :                                  DFS_FLAG_REFERRAL_DOMAIN_RESP,
     126             :                                  talloc_asprintf(tctx,
     127             :                                         "Wrong entry flag expected to have a domain response and got %d",
     128             :                                         resp2.referral_entries[0].referral.v3.entry_flags));
     129           3 :         torture_assert_int_equal(tctx, strlen(
     130             :                                  resp2.referral_entries[0].referral.v3.referrals.r2.special_name) > 0,
     131             :                                  1,
     132             :                                  "Length of domain is 0 or less");
     133           3 :         torture_assert_int_equal(tctx, strlen(
     134             :                                  resp2.referral_entries[0].referral.v3.referrals.r2.expanded_names[0]) > 0,
     135             :                                  1,
     136             :                                  "Length of first dc is less than 0");
     137           3 :         str = strchr(resp2.referral_entries[0].referral.v3.referrals.r2.expanded_names[0], '.');
     138           3 :         str2 = resp2.referral_entries[0].referral.v3.referrals.r2.special_name;
     139           3 :         if (str2[0] == '\\') {
     140           0 :                 str2++;
     141             :         }
     142           3 :         torture_assert_int_equal(tctx, strlen(str) >0, 1 ,"Length of domain too short");
     143           3 :         str++;
     144           3 :         torture_assert_int_equal(tctx, strcmp(str,str2), 0,
     145             :                                         talloc_asprintf(tctx, "Pb domain of the dc is not "\
     146             :                                                                 "the same as the requested: domain was = %s got =%s",str2 ,str));
     147           3 :         torture_assert_int_equal(tctx,
     148             :                                  resp.referral_entries[0].referral.v3.referrals.r2.special_name[0] == '\\',
     149             :                                  1,
     150             :                                  "dc name didn't start with a \\");
     151             : 
     152           3 :         r3.in.req.max_referral_level = 3;
     153             :         /*
     154             :          * Windows 7 and at least windows 2008 server sends domain.fqdn instead of \domain.fqdn
     155             :          * (as it is specified in the spec)
     156             :          * Let's check that we are able to support it too
     157             :          */
     158           3 :         r3.in.req.servername = str;
     159           3 :         r3.out.resp = &resp3;
     160             : 
     161           3 :         torture_assert_ntstatus_ok(tctx,
     162             :                    dfs_cli_do_call(cli->tree, &r3),
     163             :                    "Get DC Domain referral failed");
     164             : 
     165           3 :         torture_assert_int_equal(tctx, resp3.path_consumed, 0,
     166             :                                  "Path consumed not equal to 0");
     167           3 :         torture_assert_int_equal(tctx, resp3.nb_referrals , 1,
     168             :                                  "We do not received only 1 referral");
     169           3 :         torture_assert_int_equal(tctx, resp3.header_flags, 0,
     170             :                                  "Header flag different it's not a referral server");
     171           3 :         torture_assert_int_equal(tctx, resp3.referral_entries[0].version, 3,
     172             :                                  talloc_asprintf(tctx,
     173             :                                         "Not expected version for referral entry 0 got %d expected 3",
     174             :                                         resp3.referral_entries[0].version));
     175           3 :         torture_assert_int_equal(tctx, resp3.referral_entries[0].referral.v3.server_type,
     176             :                                  DFS_SERVER_NON_ROOT,
     177             :                                  talloc_asprintf(tctx,
     178             :                                         "Wrong server type, expected non root server and got %d",
     179             :                                         resp3.referral_entries[0].referral.v3.server_type));
     180           3 :         torture_assert_int_equal(tctx, resp3.referral_entries[0].referral.v3.entry_flags,
     181             :                                  DFS_FLAG_REFERRAL_DOMAIN_RESP,
     182             :                                  talloc_asprintf(tctx,
     183             :                                         "Wrong entry flag expected to have a domain response and got %d",
     184             :                                         resp3.referral_entries[0].referral.v3.entry_flags));
     185           3 :         torture_assert_int_equal(tctx, strlen(
     186             :                                  resp3.referral_entries[0].referral.v3.referrals.r2.special_name) > 0,
     187             :                                  1,
     188             :                                  "Length of domain is 0 or less");
     189           3 :         torture_assert_int_equal(tctx, strlen(
     190             :                                  resp3.referral_entries[0].referral.v3.referrals.r2.expanded_names[0]) > 0,
     191             :                                  1,
     192             :                                  "Length of first dc is less than 0");
     193           3 :         return true;
     194             : }
     195             : 
     196           3 : static bool test_getdcreferral_netbios(struct torture_context *tctx,
     197             :                                struct smbcli_state *cli)
     198             : {
     199           0 :         struct dfs_GetDFSReferral r, r2, r3;
     200           0 :         struct dfs_referral_resp resp, resp2, resp3;
     201           0 :         const char* str;
     202             : 
     203           3 :         r.in.req.max_referral_level = 3;
     204           3 :         r.in.req.servername = "";
     205           3 :         r.out.resp = &resp;
     206             : 
     207           3 :         torture_assert_ntstatus_ok(tctx,
     208             :                    dfs_cli_do_call(cli->tree, &r),
     209             :                    "Get Domain referral failed");
     210             : 
     211           3 :         r2.in.req.max_referral_level = 3;
     212             : 
     213           3 :         str = resp.referral_entries[0].referral.v3.referrals.r2.special_name;
     214           3 :         if( strchr(str, '.') != NULL ) {
     215           0 :                 str = resp.referral_entries[1].referral.v3.referrals.r2.special_name;
     216             :         }
     217             : 
     218           3 :         r2.in.req.servername = str;
     219           3 :         r2.out.resp = &resp2;
     220             : 
     221           3 :         torture_assert_ntstatus_ok(tctx,
     222             :                    dfs_cli_do_call(cli->tree, &r2),
     223             :                    "Get DC Domain referral failed");
     224             : 
     225           3 :         torture_assert_int_equal(tctx, resp2.path_consumed, 0,
     226             :                                  "Path consumed not equal to 0");
     227           3 :         torture_assert_int_equal(tctx, resp2.nb_referrals , 1,
     228             :                                  "We do not received only 1 referral");
     229           3 :         torture_assert_int_equal(tctx, resp2.header_flags, 0,
     230             :                                  "Header flag different it's not a referral server");
     231           3 :         torture_assert_int_equal(tctx, resp2.referral_entries[0].version, 3,
     232             :                                  talloc_asprintf(tctx,
     233             :                                         "Not expected version for referral entry 0 got %d expected 3",
     234             :                                         resp2.referral_entries[0].version));
     235           3 :         torture_assert_int_equal(tctx, resp2.referral_entries[0].referral.v3.server_type,
     236             :                                  DFS_SERVER_NON_ROOT,
     237             :                                  talloc_asprintf(tctx,
     238             :                                         "Wrong server type, expected non root server and got %d",
     239             :                                         resp2.referral_entries[0].referral.v3.server_type));
     240           3 :         torture_assert_int_equal(tctx, resp2.referral_entries[0].referral.v3.entry_flags,
     241             :                                  DFS_FLAG_REFERRAL_DOMAIN_RESP,
     242             :                                  talloc_asprintf(tctx,
     243             :                                         "Wrong entry flag expected to have a domain response and got %d",
     244             :                                         resp2.referral_entries[0].referral.v3.entry_flags));
     245           3 :         torture_assert_int_equal(tctx, strlen(
     246             :                                  resp2.referral_entries[0].referral.v3.referrals.r2.special_name) > 0,
     247             :                                  1,
     248             :                                  "Length of domain is 0 or less");
     249           3 :         torture_assert_int_equal(tctx, strlen(
     250             :                                  resp2.referral_entries[0].referral.v3.referrals.r2.expanded_names[0]) > 0,
     251             :                                  1,
     252             :                                  "Length of first dc is less than 0");
     253           3 :         torture_assert(tctx, strchr(
     254             :                        resp2.referral_entries[0].referral.v3.referrals.r2.expanded_names[0],'.') == NULL,
     255             :                        "referral contains dots it's not a netbios name");
     256             : 
     257           3 :         r3.in.req.max_referral_level = 3;
     258             :         /*
     259             :          * Windows 7 and at least windows 2008 server sends domain.fqdn instead of \domain.fqdn
     260             :          * (as it is specified in the spec)
     261             :          * Let's check that we are able to support it too
     262             :          */
     263           3 :         r3.in.req.servername = str + 1;
     264           3 :         r3.out.resp = &resp3;
     265             : 
     266           3 :         torture_assert_ntstatus_ok(tctx,
     267             :                    dfs_cli_do_call(cli->tree, &r3),
     268             :                    "Get DC Domain referral failed");
     269             : 
     270           3 :         torture_assert_int_equal(tctx, resp3.path_consumed, 0,
     271             :                                  "Path consumed not equal to 0");
     272           3 :         torture_assert_int_equal(tctx, resp3.nb_referrals , 1,
     273             :                                  "We do not received only 1 referral");
     274           3 :         torture_assert_int_equal(tctx, resp3.header_flags, 0,
     275             :                                  "Header flag different it's not a referral server");
     276           3 :         torture_assert_int_equal(tctx, resp3.referral_entries[0].version, 3,
     277             :                                  talloc_asprintf(tctx,
     278             :                                         "Not expected version for referral entry 0 got %d expected 3",
     279             :                                         resp3.referral_entries[0].version));
     280           3 :         torture_assert_int_equal(tctx, resp3.referral_entries[0].referral.v3.server_type,
     281             :                                  DFS_SERVER_NON_ROOT,
     282             :                                  talloc_asprintf(tctx,
     283             :                                         "Wrong server type, expected non root server and got %d",
     284             :                                         resp3.referral_entries[0].referral.v3.server_type));
     285           3 :         torture_assert_int_equal(tctx, resp3.referral_entries[0].referral.v3.entry_flags,
     286             :                                  DFS_FLAG_REFERRAL_DOMAIN_RESP,
     287             :                                  talloc_asprintf(tctx,
     288             :                                         "Wrong entry flag expected to have a domain response and got %d",
     289             :                                         resp3.referral_entries[0].referral.v3.entry_flags));
     290           3 :         torture_assert_int_equal(tctx, strlen(
     291             :                                  resp3.referral_entries[0].referral.v3.referrals.r2.special_name) > 0,
     292             :                                  1,
     293             :                                  "Length of domain is 0 or less");
     294           3 :         torture_assert_int_equal(tctx, strlen(
     295             :                                  resp3.referral_entries[0].referral.v3.referrals.r2.expanded_names[0]) > 0,
     296             :                                  1,
     297             :                                  "Length of first dc is less than 0");
     298           3 :         torture_assert(tctx, strchr(
     299             :                        resp3.referral_entries[0].referral.v3.referrals.r2.expanded_names[0],'.') == NULL,
     300             :                        "referral contains dots it's not a netbios name");
     301           3 :         return true;
     302             : }
     303             : 
     304           3 : static bool test_getsysvolreferral(struct torture_context *tctx,
     305             :                                struct smbcli_state *cli)
     306             : {
     307           0 :         const char* str;
     308           0 :         struct dfs_GetDFSReferral r, r2, r3;
     309           0 :         struct dfs_referral_resp resp, resp2, resp3;
     310             : 
     311           3 :         r.in.req.max_referral_level = 3;
     312           3 :         r.in.req.servername = "";
     313           3 :         r.out.resp = &resp;
     314             : 
     315           3 :         torture_assert_ntstatus_ok(tctx,
     316             :                    dfs_cli_do_call(cli->tree, &r),
     317             :                    "Get Domain referral failed");
     318             : 
     319           3 :         str = resp.referral_entries[0].referral.v3.referrals.r2.special_name;
     320           3 :         if( strchr(str, '.') == NULL ) {
     321           3 :                 str = resp.referral_entries[1].referral.v3.referrals.r2.special_name;
     322             :         }
     323             : 
     324           3 :         r2.in.req.max_referral_level = 3;
     325           3 :         r2.in.req.servername = str;
     326           3 :         r2.out.resp = &resp2;
     327             : 
     328           3 :         torture_assert_ntstatus_ok(tctx,
     329             :                    dfs_cli_do_call(cli->tree, &r2),
     330             :                    "Get DC Domain referral failed");
     331             : 
     332           3 :         r3.in.req.max_referral_level = 3;
     333           3 :         r3.in.req.servername = talloc_asprintf(tctx, "%s\\sysvol", str);
     334           3 :         r3.out.resp = &resp3;
     335             : 
     336           3 :         torture_assert_ntstatus_ok(tctx,
     337             :                    dfs_cli_do_call(cli->tree, &r3),
     338             :                    "Get sysvol Domain referral failed");
     339             : 
     340           3 :         torture_assert_int_equal(tctx, resp3.path_consumed, 2*strlen(r3.in.req.servername),
     341             :                                  "Path consumed not equal to length of the request");
     342           3 :         torture_assert_int_equal(tctx, resp3.nb_referrals != 0, 1,
     343             :                                  "We do not receive at least 1 referral");
     344           3 :         torture_assert_int_equal(tctx, resp3.header_flags, DFS_HEADER_FLAG_STORAGE_SVR,
     345             :                                  "Header flag different it's not a referral for a storage");
     346           3 :         torture_assert_int_equal(tctx, resp3.referral_entries[0].version, 3,
     347             :                                  talloc_asprintf(tctx,
     348             :                                         "Not expected version for referral entry 0 got %d expected 3",
     349             :                                         resp3.referral_entries[0].version));
     350           3 :         torture_assert_int_equal(tctx, resp3.referral_entries[0].referral.v3.server_type,
     351             :                                  DFS_SERVER_NON_ROOT,
     352             :                                  talloc_asprintf(tctx,
     353             :                                         "Wrong server type, expected non root server and got %d",
     354             :                                         resp3.referral_entries[0].referral.v3.server_type));
     355           3 :         torture_assert_int_equal(tctx, resp3.referral_entries[0].referral.v3.entry_flags,
     356             :                                  0,
     357             :                                  talloc_asprintf(tctx,
     358             :                                         "Wrong entry flag expected to have a non domain response and got %d",
     359             :                                         resp3.referral_entries[0].referral.v3.entry_flags));
     360           3 :         torture_assert_int_equal(tctx, strlen(
     361             :                                  resp3.referral_entries[0].referral.v3.referrals.r1.DFS_path) > 0,
     362             :                                  1,
     363             :                                  "Length of domain is 0 or less");
     364           3 :         torture_assert_int_equal(tctx, strstr(resp3.referral_entries[0].referral.v3.referrals.r1.DFS_path,
     365             :                                         str+1) != NULL, 1,
     366             :                                         talloc_asprintf(tctx,
     367             :                                                 "Wrong DFS_path %s unable to find substring %s in it",
     368             :                                                 resp3.referral_entries[0].referral.v3.referrals.r1.DFS_path,
     369             :                                                 str+1));
     370           3 :         torture_assert_int_equal(tctx, strlen(
     371             :                                  resp3.referral_entries[0].referral.v3.referrals.r1.netw_address) > 0,
     372             :                                  1,
     373             :                                  "Length of first referral is less than 0");
     374           3 :         torture_assert_int_equal(tctx, strstr(resp3.referral_entries[0].referral.v3.referrals.r1.netw_address,
     375             :                                         str+1) != NULL, 1,
     376             :                                         talloc_asprintf(tctx,
     377             :                                                 "Wrong DFS_path %s unable to find substring %s in it",
     378             :                                                 resp3.referral_entries[0].referral.v3.referrals.r1.netw_address,
     379             :                                                 str+1));
     380             :         /*
     381             :          * Due to strange behavior with XP and level 4
     382             :          * we are obliged to degrade to level 3 ...
     383             :          */
     384           3 :         r3.in.req.max_referral_level = 4;
     385             : 
     386           3 :         torture_assert_ntstatus_ok(tctx,
     387             :                    dfs_cli_do_call(cli->tree, &r3),
     388             :                    "Get sysvol Domain referral failed");
     389             : 
     390           3 :         torture_assert_int_equal(tctx, resp3.referral_entries[0].version, 4,
     391             :                                  talloc_asprintf(tctx,
     392             :                                         "Not expected version for referral entry 0 got %d expected 4",
     393             :                                         resp3.referral_entries[0].version));
     394           3 :         torture_assert(tctx, all_zero(resp3.referral_entries[0].referral.v3.service_site_guid.value, 16),
     395             :                        talloc_asprintf(tctx,
     396             :                                         "Service_site_guid is not NULL as expected"));
     397             : #if 0
     398             :         /* Shouldn't be needed anymore*/
     399             :         r3.in.req.max_referral_level = 4;
     400             : 
     401             :         torture_assert_ntstatus_ok(tctx,
     402             :                    dfs_cli_do_call(cli->tree, &r3),
     403             :                    "Get sysvol Domain referral failed");
     404             : 
     405             :         torture_assert_int_equal(tctx, resp3.referral_entries[0].version, 3,
     406             :                                  talloc_asprintf(tctx,
     407             :                                         "Not expected version for referral entry 0 got %d expected 3 in degraded mode",
     408             :                                         resp3.referral_entries[0].version));
     409             :         /*
     410             :          * We do not support fallback indication for the moment
     411             :          */
     412             :         torture_assert_int_equal(tctx, resp3.header_flags,
     413             :                                         DFS_HEADER_FLAG_STORAGE_SVR | DFS_HEADER_FLAG_TARGET_BCK,
     414             :                                         "Header flag different it's not a referral for a storage with fallback");
     415             :         torture_assert_int_equal(tctx, resp3.referral_entries[0].referral.v4.entry_flags,
     416             :                                  DFS_FLAG_REFERRAL_FIRST_TARGET_SET,
     417             :                                  talloc_asprintf(tctx,
     418             :                                         "Wrong entry flag expected to have a non domain response and got %d",
     419             :                                         resp3.referral_entries[0].referral.v4.entry_flags));
     420             : #endif
     421           3 :         return true;
     422             : }
     423             : 
     424           3 : static bool test_unknowndomain(struct torture_context *tctx,
     425             :                                struct smbcli_state *cli)
     426             : {
     427           0 :         struct dfs_GetDFSReferral r, r2;
     428           0 :         struct dfs_referral_resp resp, resp2;
     429             : 
     430           3 :         r.in.req.max_referral_level = 3;
     431           3 :         r.in.req.servername = "";
     432           3 :         r.out.resp = &resp;
     433             : 
     434           3 :         torture_assert_ntstatus_ok(tctx,
     435             :                    dfs_cli_do_call(cli->tree, &r),
     436             :                    "Get Domain referral failed");
     437             : 
     438           3 :         r2.in.req.max_referral_level = 3;
     439           3 :         r2.in.req.servername = "foobar.none.net";
     440           3 :         r2.out.resp = &resp2;
     441             : 
     442           3 :         torture_assert_ntstatus_equal(tctx,
     443             :                    dfs_cli_do_call(cli->tree, &r2),
     444             :                    NT_STATUS_INVALID_PARAMETER,
     445             :                    "Get DC Domain didn't return expected error code");
     446             : 
     447           3 :         return true;
     448             : }
     449             : 
     450           3 : static bool test_getsysvolplusreferral(struct torture_context *tctx,
     451             :                                struct smbcli_state *cli)
     452             : {
     453           0 :         const char* str;
     454           0 :         struct dfs_GetDFSReferral r, r2, r3;
     455           0 :         struct dfs_referral_resp resp, resp2, resp3;
     456             : 
     457           3 :         r.in.req.max_referral_level = 3;
     458           3 :         r.in.req.servername = "";
     459           3 :         r.out.resp = &resp;
     460             : 
     461           3 :         torture_assert_ntstatus_ok(tctx,
     462             :                    dfs_cli_do_call(cli->tree, &r),
     463             :                    "Get Domain referral failed");
     464             : 
     465           3 :         r2.in.req.max_referral_level = 3;
     466           3 :         r2.in.req.servername = resp.referral_entries[0].referral.v3.referrals.r2.special_name;
     467           3 :         r2.out.resp = &resp2;
     468             : 
     469           3 :         torture_assert_ntstatus_ok(tctx,
     470             :                    dfs_cli_do_call(cli->tree, &r2),
     471             :                    "Get DC Domain referral failed");
     472             : 
     473           3 :         str = resp2.referral_entries[0].referral.v3.referrals.r2.special_name;
     474           3 :         r3.in.req.max_referral_level = 3;
     475           3 :         r3.in.req.servername = talloc_asprintf(tctx, "%s\\sysvol\\foo", str);
     476           3 :         r3.out.resp = &resp3;
     477             : 
     478           3 :         torture_assert_ntstatus_equal(tctx,
     479             :                    dfs_cli_do_call(cli->tree, &r3),
     480             :                    NT_STATUS_NOT_FOUND,
     481             :                    "Bad behavior with subtree sysvol referral");
     482             : 
     483           3 :         return true;
     484             : }
     485             : 
     486           3 : static bool test_low_referral_level(struct torture_context *tctx,
     487             :                                struct smbcli_state *cli)
     488             : {
     489           0 :         struct dfs_GetDFSReferral r;
     490           0 :         struct dfs_referral_resp resp;
     491             : 
     492           3 :         r.in.req.max_referral_level = 2;
     493           3 :         r.in.req.servername = "";
     494           3 :         r.out.resp = &resp;
     495             : 
     496           3 :         torture_assert_ntstatus_equal(tctx,
     497             :                    dfs_cli_do_call(cli->tree, &r),
     498             :                    NT_STATUS_UNSUCCESSFUL,
     499             :                    "Unexpected STATUS for invalid referral request");
     500             : 
     501           3 :         return true;
     502             : }
     503             : 
     504        2354 : NTSTATUS torture_dfs_init(TALLOC_CTX *ctx)
     505             : {
     506        2354 :         struct torture_suite *suite = torture_suite_create(ctx, "dfs");
     507        2354 :         struct torture_suite *suite_basic = torture_suite_create(suite, "domain");
     508             : 
     509        2354 :         torture_suite_add_suite(suite, suite_basic);
     510             : 
     511        2354 :         torture_suite_add_1smb_test(suite_basic, "domain referral",
     512             :                                     test_getdomainreferral);
     513        2354 :         torture_suite_add_1smb_test(suite_basic, "dc referral",
     514             :                                     test_getdcreferral);
     515        2354 :         torture_suite_add_1smb_test(suite_basic, "dc referral netbios",
     516             :                                     test_getdcreferral_netbios);
     517             : 
     518        2354 :         torture_suite_add_1smb_test(suite_basic, "sysvol referral",
     519             :                                     test_getsysvolreferral);
     520             : 
     521             :         /* Non standard case */
     522             : 
     523        2354 :         torture_suite_add_1smb_test(suite_basic, "dc referral on unknown domain",
     524             :                                     test_unknowndomain);
     525        2354 :         torture_suite_add_1smb_test(suite_basic, "sysvol with subtree referral",
     526             :                                     test_getsysvolplusreferral);
     527        2354 :         torture_suite_add_1smb_test(suite_basic, "referral with a level 2",
     528             :                                     test_low_referral_level);
     529             : 
     530             :         /*
     531             :          * test with invalid level
     532             :          * test with netbios
     533             :          */
     534             : 
     535        2354 :         suite->description = talloc_strdup(suite, "DFS referrals calls");
     536             : 
     537        2354 :         torture_register_suite(ctx, suite);
     538             : 
     539        2354 :         return NT_STATUS_OK;
     540             : }

Generated by: LCOV version 1.14