cb6cc84152c78f23b743f76b3cf6b47ced5f0cda
[gd/samba-autobuild/.git] / source4 / torture / basic / secleak.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    find security related memory leaks
5
6    Copyright (C) Andrew Tridgell 2004
7    
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 3 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 #include "includes.h"
23 #include "torture/torture.h"
24 #include "libcli/raw/libcliraw.h"
25 #include "libcli/libcli.h"
26 #include "torture/util.h"
27 #include "system/time.h"
28 #include "libcli/smb_composite/smb_composite.h"
29 #include "auth/credentials/credentials.h"
30
31 static BOOL try_failed_login(struct smbcli_state *cli)
32 {
33         NTSTATUS status;
34         struct smb_composite_sesssetup setup;
35         struct smbcli_session *session;
36
37         session = smbcli_session_init(cli->transport, cli, False);
38         setup.in.sesskey = cli->transport->negotiate.sesskey;
39         setup.in.capabilities = cli->transport->negotiate.capabilities;
40         setup.in.workgroup = lp_workgroup();
41
42         setup.in.credentials = cli_credentials_init(session);
43         cli_credentials_set_conf(setup.in.credentials);
44         cli_credentials_set_domain(setup.in.credentials, "INVALID-DOMAIN", CRED_SPECIFIED);
45         cli_credentials_set_username(setup.in.credentials, "INVALID-USERNAME", CRED_SPECIFIED);
46         cli_credentials_set_password(setup.in.credentials, "INVALID-PASSWORD", CRED_SPECIFIED);
47
48         status = smb_composite_sesssetup(session, &setup);
49         talloc_free(session);
50         if (NT_STATUS_IS_OK(status)) {
51                 printf("Allowed session setup with invalid credentials?!\n");
52                 return False;
53         }
54
55         return True;
56 }
57
58 BOOL torture_sec_leak(struct torture_context *tctx, struct smbcli_state *cli)
59 {
60         time_t t1 = time(NULL);
61         int timelimit = torture_setting_int(tctx, "timelimit", 20);
62
63         while (time(NULL) < t1+timelimit) {
64                 if (!try_failed_login(cli)) {
65                         return False;
66                 }
67                 talloc_report(NULL, stdout);
68         }
69
70         return True;
71 }