2 Unix SMB/CIFS implementation.
4 find security related memory leaks
6 Copyright (C) Andrew Tridgell 2004
7 Copyright (C) David Mulder 2020
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "libcli/raw/libcliraw.h"
25 #include "libcli/raw/raw_proto.h"
26 #include "libcli/libcli.h"
27 #include "torture/util.h"
28 #include "system/time.h"
29 #include "libcli/smb_composite/smb_composite.h"
30 #include "auth/credentials/credentials.h"
31 #include "param/param.h"
32 #include "libcli/smb2/smb2.h"
33 #include "libcli/smb2/smb2_calls.h"
34 #include "torture/smb2/proto.h"
35 #include "../libcli/smb/smbXcli_base.h"
37 static bool try_failed_login(struct torture_context
*tctx
, struct smb2_tree
*tree
)
40 struct cli_credentials
*credentials
= NULL
;
42 struct smb2_session
*session
= NULL
;
45 session
= smb2_session_init(tree
->session
->transport
,
46 lpcfg_gensec_settings(tctx
, tctx
->lp_ctx
),
48 torture_assert(tctx
, session
, "Session initialization failed");
50 sessid
= smb2cli_session_current_id(tree
->session
->smbXcli
);
51 credentials
= cli_credentials_init(session
);
52 torture_assert_goto(tctx
, credentials
, result
, done
,
53 "Credential allocation failed");
55 cli_credentials_set_conf(credentials
, tctx
->lp_ctx
);
56 cli_credentials_set_domain(credentials
, "INVALID-DOMAIN", CRED_SPECIFIED
);
57 cli_credentials_set_username(credentials
, "INVALID-USERNAME", CRED_SPECIFIED
);
58 cli_credentials_set_password(credentials
, "INVALID-PASSWORD", CRED_SPECIFIED
);
60 status
= smb2_session_setup_spnego(session
, credentials
, sessid
);
61 torture_assert_ntstatus_equal_goto(tctx
, status
,
62 NT_STATUS_LOGON_FAILURE
, result
, done
,
63 "Allowed session setup with invalid credentials?!\n");
66 /* smb2_session_init() steals the transport, and if we don't steal it
67 * back before freeing session, then we segfault on the next iteration
68 * because the transport pointer in the tree is now invalid.
70 tree
->session
->transport
= talloc_steal(tree
->session
, session
->transport
);
76 bool torture_smb2_sec_leak(struct torture_context
*tctx
, struct smb2_tree
*tree
)
78 time_t t1
= time_mono(NULL
);
79 int timelimit
= torture_setting_int(tctx
, "timelimit", 20);
82 while (time_mono(NULL
) < t1
+timelimit
) {
83 result
= try_failed_login(tctx
, tree
);
84 torture_assert(tctx
, result
,
85 "Invalid credentials should have failed");
87 talloc_report(NULL
, stdout
);