summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2004-09-24 06:56:11 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:59:09 -0500
commit8e5acb6df0396e65712840f668b34ff4531ff126 (patch)
tree9602920e09d0fbf43591e9f65c91e9e7f897db64
parent3e54089bc1f3c75b1bb7f72f3fa2e458de98295e (diff)
downloadsamba-8e5acb6df0396e65712840f668b34ff4531ff126.tar.gz
samba-8e5acb6df0396e65712840f668b34ff4531ff126.tar.bz2
samba-8e5acb6df0396e65712840f668b34ff4531ff126.zip
r2589: a simple test to help find security related memory leaks. Run valgrind on smbd with
--show-leak=yes and --show-reachable=yes to track them down. (This used to be commit 7b23624a0f50c29346e8b1c4057f1c21f3be6d5a)
-rw-r--r--source4/torture/basic/secleak.c68
-rw-r--r--source4/torture/config.mk3
-rw-r--r--source4/torture/torture.c1
3 files changed, 71 insertions, 1 deletions
diff --git a/source4/torture/basic/secleak.c b/source4/torture/basic/secleak.c
new file mode 100644
index 0000000000..80bc799df0
--- /dev/null
+++ b/source4/torture/basic/secleak.c
@@ -0,0 +1,68 @@
+/*
+ Unix SMB/CIFS implementation.
+
+ find security related memory leaks
+
+ Copyright (C) Andrew Tridgell 2004
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include "includes.h"
+
+static BOOL try_failed_login(struct smbcli_state *cli)
+{
+ NTSTATUS status;
+ union smb_sesssetup setup;
+ struct smbcli_session *session;
+ TALLOC_CTX *mem_ctx = talloc_init("failed_login");
+
+ session = smbcli_session_init(cli->transport);
+ setup.generic.level = RAW_SESSSETUP_GENERIC;
+ setup.generic.in.sesskey = cli->transport->negotiate.sesskey;
+ setup.generic.in.capabilities = cli->transport->negotiate.capabilities;
+ setup.generic.in.password = "INVALID-PASSWORD";
+ setup.generic.in.user = "INVALID-USERNAME";
+ setup.generic.in.domain = "INVALID-DOMAIN";
+
+ status = smb_raw_session_setup(session, mem_ctx, &setup);
+ if (NT_STATUS_IS_OK(status)) {
+ printf("Allowed session setup with invalid credentials?!\n");
+ return False;
+ }
+
+ smbcli_session_close(session);
+ talloc_free(mem_ctx);
+
+ return True;
+}
+
+BOOL torture_sec_leak(int dummy)
+{
+ struct smbcli_state *cli;
+ time_t t1 = time(NULL);
+
+ if (!torture_open_connection(&cli)) {
+ return False;
+ }
+
+ while (time(NULL) < t1+20) {
+ if (!try_failed_login(cli)) {
+ return False;
+ }
+ }
+
+ return True;
+}
diff --git a/source4/torture/config.mk b/source4/torture/config.mk
index 43a42217f5..9c7395e572 100644
--- a/source4/torture/config.mk
+++ b/source4/torture/config.mk
@@ -9,7 +9,8 @@ ADD_OBJ_FILES = \
torture/basic/charset.o \
torture/basic/mangle_test.o \
torture/basic/denytest.o \
- torture/basic/aliases.o
+ torture/basic/aliases.o \
+ torture/basic/secleak.o
REQUIRED_SUBSYSTEMS = \
LIBSMB
# End SUBSYSTEM TORTURE_BASIC
diff --git a/source4/torture/torture.c b/source4/torture/torture.c
index e4729470dd..f6004ed428 100644
--- a/source4/torture/torture.c
+++ b/source4/torture/torture.c
@@ -4185,6 +4185,7 @@ static struct {
{"BASE-OPENATTR", run_openattrtest, 0},
{"BASE-CHARSET", torture_charset, 0},
{"BASE-CHKPATH", torture_chkpath_test, 0},
+ {"BASE-SECLEAK", torture_sec_leak, 0},
/* benchmarking tests */
{"BENCH-HOLDCON", torture_holdcon, 0},