fe3d10
From 1b14752bebbdecbb7c89c7fe03853bdf4dff6f64 Mon Sep 17 00:00:00 2001
fe3d10
From: Andreas Schneider <asn@samba.org>
fe3d10
Date: Wed, 9 Feb 2022 16:33:10 +0100
fe3d10
Subject: [PATCH 1/6] selftest: Do not force -d0 for smbd/nmbd/winbindd
fe3d10
fe3d10
We have the env variable SERVER_LOG_LEVEL which allows you to change
fe3d10
the log level on the command line. If we force -d0 this will not work.
fe3d10
fe3d10
make test TESTS="samba" SERVER_LOG_LEVEL=10
fe3d10
fe3d10
Signed-off-by: Andreas Schneider <asn@samba.org>
fe3d10
Reviewed-by: Jeremy Allison <jra@samba.org>
fe3d10
(cherry picked from commit 9693f7ea7383c6a51ab58b7c8255b30206f18a3b)
fe3d10
---
fe3d10
 selftest/target/Samba3.pm | 2 +-
fe3d10
 1 file changed, 1 insertion(+), 1 deletion(-)
fe3d10
fe3d10
diff --git a/selftest/target/Samba3.pm b/selftest/target/Samba3.pm
fe3d10
index b901fd2677a..64a9a791a61 100755
fe3d10
--- a/selftest/target/Samba3.pm
fe3d10
+++ b/selftest/target/Samba3.pm
fe3d10
@@ -2153,7 +2153,7 @@ sub make_bin_cmd
fe3d10
 {
fe3d10
 	my ($self, $binary, $env_vars, $options, $valgrind, $dont_log_stdout) = @_;
fe3d10
 
fe3d10
-	my @optargs = ("-d0");
fe3d10
+	my @optargs = ();
fe3d10
 	if (defined($options)) {
fe3d10
 		@optargs = split(/ /, $options);
fe3d10
 	}
fe3d10
-- 
fe3d10
2.34.1
fe3d10
fe3d10
fe3d10
From 22c2899dfc787736c19857997291c151886b7ac0 Mon Sep 17 00:00:00 2001
fe3d10
From: =?UTF-8?q?Pavel=20Filipensk=C3=BD?= <pfilipen@redhat.com>
fe3d10
Date: Tue, 8 Feb 2022 12:07:03 +0100
fe3d10
Subject: [PATCH 2/6] s3:modules: Implement dummy virus scanner that uses
fe3d10
 filename matching
fe3d10
MIME-Version: 1.0
fe3d10
Content-Type: text/plain; charset=UTF-8
fe3d10
Content-Transfer-Encoding: 8bit
fe3d10
fe3d10
Bug: https://bugzilla.samba.org/show_bug.cgi?id=14971
fe3d10
fe3d10
Signed-off-by: Pavel Filipenský <pfilipen@redhat.com>
fe3d10
Reviewed-by: Jeremy Allison <jra@samba.org>
fe3d10
Reviewed-by: Andreas Schneider <asn@samba.org>
fe3d10
(cherry picked from commit 9f34babec7c6aca3d91f226705d3b3996792e5f1)
fe3d10
---
fe3d10
 source3/modules/vfs_virusfilter.c        | 12 +++++
fe3d10
 source3/modules/vfs_virusfilter_common.h |  4 ++
fe3d10
 source3/modules/vfs_virusfilter_dummy.c  | 58 ++++++++++++++++++++++++
fe3d10
 source3/modules/wscript_build            |  1 +
fe3d10
 4 files changed, 75 insertions(+)
fe3d10
 create mode 100644 source3/modules/vfs_virusfilter_dummy.c
fe3d10
fe3d10
diff --git a/source3/modules/vfs_virusfilter.c b/source3/modules/vfs_virusfilter.c
fe3d10
index 9fafe4e5d41..e6cbee7cd45 100644
fe3d10
--- a/source3/modules/vfs_virusfilter.c
fe3d10
+++ b/source3/modules/vfs_virusfilter.c
fe3d10
@@ -35,12 +35,14 @@
fe3d10
 
fe3d10
 enum virusfilter_scanner_enum {
fe3d10
 	VIRUSFILTER_SCANNER_CLAMAV,
fe3d10
+	VIRUSFILTER_SCANNER_DUMMY,
fe3d10
 	VIRUSFILTER_SCANNER_FSAV,
fe3d10
 	VIRUSFILTER_SCANNER_SOPHOS
fe3d10
 };
fe3d10
 
fe3d10
 static const struct enum_list scanner_list[] = {
fe3d10
 	{ VIRUSFILTER_SCANNER_CLAMAV,	"clamav" },
fe3d10
+	{ VIRUSFILTER_SCANNER_DUMMY,	"dummy" },
fe3d10
 	{ VIRUSFILTER_SCANNER_FSAV,	"fsav" },
fe3d10
 	{ VIRUSFILTER_SCANNER_SOPHOS,	"sophos" },
fe3d10
 	{ -1,				NULL }
fe3d10
@@ -199,6 +201,7 @@ static int virusfilter_vfs_connect(
fe3d10
 	int snum = SNUM(handle->conn);
fe3d10
 	struct virusfilter_config *config = NULL;
fe3d10
 	const char *exclude_files = NULL;
fe3d10
+	const char *infected_files = NULL;
fe3d10
 	const char *temp_quarantine_dir_mode = NULL;
fe3d10
 	const char *infected_file_command = NULL;
fe3d10
 	const char *scan_error_command = NULL;
fe3d10
@@ -255,6 +258,12 @@ static int virusfilter_vfs_connect(
fe3d10
 		set_namearray(&config->exclude_files, exclude_files);
fe3d10
 	}
fe3d10
 
fe3d10
+	infected_files = lp_parm_const_string(
fe3d10
+		snum, "virusfilter", "infected files", NULL);
fe3d10
+	if (infected_files != NULL) {
fe3d10
+		set_namearray(&config->infected_files, infected_files);
fe3d10
+	}
fe3d10
+
fe3d10
 	config->cache_entry_limit = lp_parm_int(
fe3d10
 		snum, "virusfilter", "cache entry limit", 100);
fe3d10
 
fe3d10
@@ -537,6 +546,9 @@ static int virusfilter_vfs_connect(
fe3d10
 	case VIRUSFILTER_SCANNER_CLAMAV:
fe3d10
 		ret = virusfilter_clamav_init(config);
fe3d10
 		break;
fe3d10
+	case VIRUSFILTER_SCANNER_DUMMY:
fe3d10
+		ret = virusfilter_dummy_init(config);
fe3d10
+		break;
fe3d10
 	default:
fe3d10
 		DBG_ERR("Unhandled scanner %d\n", backend);
fe3d10
 		return -1;
fe3d10
diff --git a/source3/modules/vfs_virusfilter_common.h b/source3/modules/vfs_virusfilter_common.h
fe3d10
index f71b0b949a7..463a9d74e9c 100644
fe3d10
--- a/source3/modules/vfs_virusfilter_common.h
fe3d10
+++ b/source3/modules/vfs_virusfilter_common.h
fe3d10
@@ -83,6 +83,9 @@ struct virusfilter_config {
fe3d10
 	/* Exclude files */
fe3d10
 	name_compare_entry		*exclude_files;
fe3d10
 
fe3d10
+	/* Infected files */
fe3d10
+	name_compare_entry		*infected_files;
fe3d10
+
fe3d10
 	/* Scan result cache */
fe3d10
 	struct virusfilter_cache	*cache;
fe3d10
 	int				cache_entry_limit;
fe3d10
@@ -149,5 +152,6 @@ struct virusfilter_backend {
fe3d10
 int virusfilter_sophos_init(struct virusfilter_config *config);
fe3d10
 int virusfilter_fsav_init(struct virusfilter_config *config);
fe3d10
 int virusfilter_clamav_init(struct virusfilter_config *config);
fe3d10
+int virusfilter_dummy_init(struct virusfilter_config *config);
fe3d10
 
fe3d10
 #endif /* _VIRUSFILTER_COMMON_H */
fe3d10
diff --git a/source3/modules/vfs_virusfilter_dummy.c b/source3/modules/vfs_virusfilter_dummy.c
fe3d10
new file mode 100644
fe3d10
index 00000000000..03405cd6629
fe3d10
--- /dev/null
fe3d10
+++ b/source3/modules/vfs_virusfilter_dummy.c
fe3d10
@@ -0,0 +1,58 @@
fe3d10
+/*
fe3d10
+   Samba-VirusFilter VFS modules
fe3d10
+   Dummy scanner with infected files support.
fe3d10
+   Copyright (C) 2022 Pavel Filipenský <pfilipen@redhat.com>
fe3d10
+
fe3d10
+   This program is free software; you can redistribute it and/or modify
fe3d10
+   it under the terms of the GNU General Public License as published by
fe3d10
+   the Free Software Foundation; either version 3 of the License, or
fe3d10
+   (at your option) any later version.
fe3d10
+
fe3d10
+   This program is distributed in the hope that it will be useful,
fe3d10
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
fe3d10
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
fe3d10
+   GNU General Public License for more details.
fe3d10
+
fe3d10
+   You should have received a copy of the GNU General Public License
fe3d10
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
fe3d10
+*/
fe3d10
+
fe3d10
+#include "modules/vfs_virusfilter_utils.h"
fe3d10
+
fe3d10
+static virusfilter_result virusfilter_dummy_scan(
fe3d10
+	struct vfs_handle_struct *handle,
fe3d10
+	struct virusfilter_config *config,
fe3d10
+	const struct files_struct *fsp,
fe3d10
+	char **reportp)
fe3d10
+{
fe3d10
+	bool ok;
fe3d10
+
fe3d10
+	DBG_INFO("Scanning file: %s\n", fsp_str_dbg(fsp));
fe3d10
+	ok = is_in_path(fsp->fsp_name->base_name,
fe3d10
+			config->infected_files,
fe3d10
+			false);
fe3d10
+	return ok ? VIRUSFILTER_RESULT_INFECTED : VIRUSFILTER_RESULT_CLEAN;
fe3d10
+}
fe3d10
+
fe3d10
+static struct virusfilter_backend_fns virusfilter_backend_dummy = {
fe3d10
+	.connect = NULL,
fe3d10
+	.disconnect = NULL,
fe3d10
+	.scan_init = NULL,
fe3d10
+	.scan = virusfilter_dummy_scan,
fe3d10
+	.scan_end = NULL,
fe3d10
+};
fe3d10
+
fe3d10
+int virusfilter_dummy_init(struct virusfilter_config *config)
fe3d10
+{
fe3d10
+	struct virusfilter_backend *backend = NULL;
fe3d10
+
fe3d10
+	backend = talloc_zero(config, struct virusfilter_backend);
fe3d10
+	if (backend == NULL) {
fe3d10
+		return -1;
fe3d10
+	}
fe3d10
+
fe3d10
+	backend->fns = &virusfilter_backend_dummy;
fe3d10
+	backend->name = "dummy";
fe3d10
+	config->backend = backend;
fe3d10
+	return 0;
fe3d10
+}
fe3d10
diff --git a/source3/modules/wscript_build b/source3/modules/wscript_build
fe3d10
index 40df4539392..ff318c3fa06 100644
fe3d10
--- a/source3/modules/wscript_build
fe3d10
+++ b/source3/modules/wscript_build
fe3d10
@@ -591,6 +591,7 @@ bld.SAMBA3_MODULE('vfs_virusfilter',
fe3d10
                  vfs_virusfilter_sophos.c
fe3d10
                  vfs_virusfilter_fsav.c
fe3d10
                  vfs_virusfilter_clamav.c
fe3d10
+                 vfs_virusfilter_dummy.c
fe3d10
                  ''',
fe3d10
                  deps='samba-util VFS_VIRUSFILTER_UTILS',
fe3d10
                  init_function='',
fe3d10
-- 
fe3d10
2.34.1
fe3d10
fe3d10
fe3d10
From a813dc2adec352a85ec526ac9a3ec67139b730d3 Mon Sep 17 00:00:00 2001
fe3d10
From: =?UTF-8?q?Pavel=20Filipensk=C3=BD?= <pfilipen@redhat.com>
fe3d10
Date: Tue, 8 Feb 2022 22:35:29 +0100
fe3d10
Subject: [PATCH 3/6] docs-xml:manpages: Document 'dummy' virusfilter and
fe3d10
 'virusfilter:infected files'
fe3d10
MIME-Version: 1.0
fe3d10
Content-Type: text/plain; charset=UTF-8
fe3d10
Content-Transfer-Encoding: 8bit
fe3d10
fe3d10
Bug: https://bugzilla.samba.org/show_bug.cgi?id=14971
fe3d10
fe3d10
Signed-off-by: Pavel Filipenský <pfilipen@redhat.com>
fe3d10
Reviewed-by: Jeremy Allison <jra@samba.org>
fe3d10
Reviewed-by: Andreas Schneider <asn@samba.org>
fe3d10
(cherry picked from commit 2fd518e5cc63221c162c9b3f8526b9b7c9e34969)
fe3d10
---
fe3d10
 docs-xml/manpages/vfs_virusfilter.8.xml | 12 ++++++++++++
fe3d10
 1 file changed, 12 insertions(+)
fe3d10
fe3d10
diff --git a/docs-xml/manpages/vfs_virusfilter.8.xml b/docs-xml/manpages/vfs_virusfilter.8.xml
fe3d10
index 329a35af68a..88f91d73a42 100644
fe3d10
--- a/docs-xml/manpages/vfs_virusfilter.8.xml
fe3d10
+++ b/docs-xml/manpages/vfs_virusfilter.8.xml
fe3d10
@@ -48,6 +48,10 @@
fe3d10
 		  scanner</para></listitem>
fe3d10
 		  <listitem><para><emphasis>clamav</emphasis>, the ClamAV
fe3d10
 		  scanner</para></listitem>
fe3d10
+		  <listitem><para><emphasis>dummy</emphasis>, dummy scanner used in
fe3d10
+		  tests. Checks against the <emphasis>infected files</emphasis>
fe3d10
+		  parameter and flags any name that matches as infected.
fe3d10
+		  </para></listitem>
fe3d10
 		</itemizedlist>
fe3d10
 		</listitem>
fe3d10
 		</varlistentry>
fe3d10
@@ -264,6 +268,14 @@
fe3d10
 		</listitem>
fe3d10
 		</varlistentry>
fe3d10
 
fe3d10
+		<varlistentry>
fe3d10
+		<term>virusfilter:infected files = empty</term>
fe3d10
+		<listitem>
fe3d10
+		<para>Files that virusfilter <emphasis>dummy</emphasis> flags as infected.</para>
fe3d10
+		<para>If this option is not set, the default is empty.</para>
fe3d10
+		</listitem>
fe3d10
+		</varlistentry>
fe3d10
+
fe3d10
 		<varlistentry>
fe3d10
 		<term>virusfilter:block access on error = false</term>
fe3d10
 		<listitem>
fe3d10
-- 
fe3d10
2.34.1
fe3d10
fe3d10
fe3d10
From b67c6fe07a506627439c6ffd07e687befbc122ba Mon Sep 17 00:00:00 2001
fe3d10
From: =?UTF-8?q?Pavel=20Filipensk=C3=BD?= <pfilipen@redhat.com>
fe3d10
Date: Tue, 8 Feb 2022 15:34:56 +0100
fe3d10
Subject: [PATCH 4/6] selftest: Fix trailing whitespace in Samba3.pm
fe3d10
MIME-Version: 1.0
fe3d10
Content-Type: text/plain; charset=UTF-8
fe3d10
Content-Transfer-Encoding: 8bit
fe3d10
fe3d10
Bug: https://bugzilla.samba.org/show_bug.cgi?id=14971
fe3d10
fe3d10
Signed-off-by: Pavel Filipenský <pfilipen@redhat.com>
fe3d10
Reviewed-by: Jeremy Allison <jra@samba.org>
fe3d10
Reviewed-by: Andreas Schneider <asn@samba.org>
fe3d10
(cherry picked from commit 547b4c595a8513a4be99177edbaa39ce43840f7a)
fe3d10
---
fe3d10
 selftest/target/Samba3.pm | 6 +++---
fe3d10
 1 file changed, 3 insertions(+), 3 deletions(-)
fe3d10
fe3d10
diff --git a/selftest/target/Samba3.pm b/selftest/target/Samba3.pm
fe3d10
index 64a9a791a61..7584a0e7ba9 100755
fe3d10
--- a/selftest/target/Samba3.pm
fe3d10
+++ b/selftest/target/Samba3.pm
fe3d10
@@ -188,7 +188,7 @@ sub getlog_env_app($$$)
fe3d10
 	close(LOG);
fe3d10
 
fe3d10
 	return "" if $out eq $title;
fe3d10
- 
fe3d10
+
fe3d10
 	return $out;
fe3d10
 }
fe3d10
 
fe3d10
@@ -2426,7 +2426,7 @@ sub provision($$)
fe3d10
 	my $nmbdsockdir="$prefix_abs/nmbd";
fe3d10
 	unlink($nmbdsockdir);
fe3d10
 
fe3d10
-	## 
fe3d10
+	##
fe3d10
 	## create the test directory layout
fe3d10
 	##
fe3d10
 	die ("prefix_abs = ''") if $prefix_abs eq "";
fe3d10
@@ -3290,7 +3290,7 @@ sub provision($$)
fe3d10
 	unless (open(PASSWD, ">$nss_wrapper_passwd")) {
fe3d10
            warn("Unable to open $nss_wrapper_passwd");
fe3d10
            return undef;
fe3d10
-        } 
fe3d10
+        }
fe3d10
 	print PASSWD "nobody:x:$uid_nobody:$gid_nobody:nobody gecos:$prefix_abs:/bin/false
fe3d10
 $unix_name:x:$unix_uid:$unix_gids[0]:$unix_name gecos:$prefix_abs:/bin/false
fe3d10
 pdbtest:x:$uid_pdbtest:$gid_nogroup:pdbtest gecos:$prefix_abs:/bin/false
fe3d10
-- 
fe3d10
2.34.1
fe3d10
fe3d10
fe3d10
From b558d8f8be4459fa9e588486984c4cadf65ede12 Mon Sep 17 00:00:00 2001
fe3d10
From: =?UTF-8?q?Pavel=20Filipensk=C3=BD?= <pfilipen@redhat.com>
fe3d10
Date: Tue, 8 Feb 2022 15:35:48 +0100
fe3d10
Subject: [PATCH 5/6] s3:selftest: Add test for virus scanner
fe3d10
MIME-Version: 1.0
fe3d10
Content-Type: text/plain; charset=UTF-8
fe3d10
Content-Transfer-Encoding: 8bit
fe3d10
fe3d10
Bug: https://bugzilla.samba.org/show_bug.cgi?id=14971
fe3d10
fe3d10
Signed-off-by: Pavel Filipenský <pfilipen@redhat.com>
fe3d10
fe3d10
Pair-Programmed-With: Andreas Schneider <asn@samba.org>
fe3d10
Reviewed-by: Jeremy Allison <jra@samba.org>
fe3d10
Reviewed-by: Andreas Schneider <asn@samba.org>
fe3d10
(cherry picked from commit a25c714c34d3e00e0f3c29d2acfa98cf9cdbc544)
fe3d10
---
fe3d10
 selftest/knownfail.d/virus_scanner         |   2 +
fe3d10
 selftest/target/Samba3.pm                  |  12 ++
fe3d10
 source3/script/tests/test_virus_scanner.sh | 124 +++++++++++++++++++++
fe3d10
 source3/selftest/tests.py                  |   9 ++
fe3d10
 4 files changed, 147 insertions(+)
fe3d10
 create mode 100644 selftest/knownfail.d/virus_scanner
fe3d10
 create mode 100755 source3/script/tests/test_virus_scanner.sh
fe3d10
fe3d10
diff --git a/selftest/knownfail.d/virus_scanner b/selftest/knownfail.d/virus_scanner
fe3d10
new file mode 100644
fe3d10
index 00000000000..6df3fd20627
fe3d10
--- /dev/null
fe3d10
+++ b/selftest/knownfail.d/virus_scanner
fe3d10
@@ -0,0 +1,2 @@
fe3d10
+^samba3.blackbox.virus_scanner.check_infected_read  # test download infected file ('vfs objects = virusfilter')
fe3d10
+^samba3.blackbox.virus_scanner.check_infected_write # test upload infected file ('vfs objects = virusfilter')
fe3d10
diff --git a/selftest/target/Samba3.pm b/selftest/target/Samba3.pm
fe3d10
index 7584a0e7ba9..c1d0c60d96a 100755
fe3d10
--- a/selftest/target/Samba3.pm
fe3d10
+++ b/selftest/target/Samba3.pm
fe3d10
@@ -1688,6 +1688,9 @@ sub setup_fileserver
fe3d10
 	my $veto_sharedir="$share_dir/veto";
fe3d10
 	push(@dirs,$veto_sharedir);
fe3d10
 
fe3d10
+	my $virusfilter_sharedir="$share_dir/virusfilter";
fe3d10
+	push(@dirs,$virusfilter_sharedir);
fe3d10
+
fe3d10
 	my $ip4 = Samba::get_ipv4_addr("FILESERVER");
fe3d10
 	my $fileserver_options = "
fe3d10
 	kernel change notify = yes
fe3d10
@@ -1813,6 +1816,15 @@ sub setup_fileserver
fe3d10
 	path = $veto_sharedir
fe3d10
 	delete veto files = yes
fe3d10
 
fe3d10
+[virusfilter]
fe3d10
+	path = $virusfilter_sharedir
fe3d10
+	vfs objects = acl_xattr virusfilter
fe3d10
+	virusfilter:scanner = dummy
fe3d10
+	virusfilter:min file size = 0
fe3d10
+	virusfilter:infected files = *infected*
fe3d10
+	virusfilter:infected file action = rename
fe3d10
+	virusfilter:scan on close = yes
fe3d10
+
fe3d10
 [homes]
fe3d10
 	comment = Home directories
fe3d10
 	browseable = No
fe3d10
diff --git a/source3/script/tests/test_virus_scanner.sh b/source3/script/tests/test_virus_scanner.sh
fe3d10
new file mode 100755
fe3d10
index 00000000000..2234ea6ca89
fe3d10
--- /dev/null
fe3d10
+++ b/source3/script/tests/test_virus_scanner.sh
fe3d10
@@ -0,0 +1,124 @@
fe3d10
+#!/bin/sh
fe3d10
+# Copyright (c) 2022      Pavel Filipenský <pfilipen@redhat.com>
fe3d10
+# shellcheck disable=1091
fe3d10
+
fe3d10
+if [ $# -lt 4 ]; then
fe3d10
+cat <
fe3d10
+Usage: $0 SERVER_IP SHARE LOCAL_PATH SMBCLIENT
fe3d10
+EOF
fe3d10
+exit 1;
fe3d10
+fi
fe3d10
+
fe3d10
+SERVER_IP=${1}
fe3d10
+SHARE=${2}
fe3d10
+LOCAL_PATH=${3}
fe3d10
+SMBCLIENT=${4}
fe3d10
+
fe3d10
+SMBCLIENT="${VALGRIND} ${SMBCLIENT}"
fe3d10
+
fe3d10
+failed=0
fe3d10
+sharedir="${LOCAL_PATH}/${SHARE}"
fe3d10
+
fe3d10
+incdir="$(dirname "$0")/../../../testprogs/blackbox"
fe3d10
+. "${incdir}/subunit.sh"
fe3d10
+
fe3d10
+check_infected_read()
fe3d10
+{
fe3d10
+    rm -rf "${sharedir:?}"/*
fe3d10
+
fe3d10
+    if ! touch "${sharedir}/infected.txt"; then
fe3d10
+        echo "ERROR: Cannot create ${sharedir}/infected.txt"
fe3d10
+        return 1
fe3d10
+    fi
fe3d10
+
fe3d10
+    ${SMBCLIENT} "//${SERVER_IP}/${SHARE}" -U"${USER}"%"${PASSWORD}" -c "get infected.txt ${sharedir}/infected.download.txt"
fe3d10
+
fe3d10
+    # check that virusfilter:rename prefix/suffix was added
fe3d10
+    if [ ! -f "${sharedir}/virusfilter.infected.txt.infected" ]; then
fe3d10
+        echo "ERROR: ${sharedir}/virusfilter.infected.txt.infected is missing."
fe3d10
+        return 1
fe3d10
+    fi
fe3d10
+
fe3d10
+    # check that file was not downloaded
fe3d10
+    if [ -f "${sharedir}/infected.download.txt" ]; then
fe3d10
+        echo "ERROR: {sharedir}/infected.download.txt should not exist."
fe3d10
+        return 1
fe3d10
+    fi
fe3d10
+
fe3d10
+    return 0
fe3d10
+}
fe3d10
+
fe3d10
+check_infected_write()
fe3d10
+{
fe3d10
+    rm -rf "${sharedir:?}"/*
fe3d10
+    smbfile=infected.upload.txt
fe3d10
+    smbfilerenamed="virusfilter.${smbfile}.infected"
fe3d10
+
fe3d10
+    # non empty file is needed
fe3d10
+    # vsf_virusfilter performs a scan only if fsp->fsp_flags.modified
fe3d10
+    if ! echo "Hello Virus!" > "${sharedir}/infected.txt"; then
fe3d10
+        echo "ERROR: Cannot create ${sharedir}/infected.txt"
fe3d10
+        return 1
fe3d10
+    fi
fe3d10
+
fe3d10
+    ${SMBCLIENT} "//${SERVER_IP}/${SHARE}" -U"${USER}"%"${PASSWORD}" -c "put ${sharedir}/infected.txt ${smbfile}"
fe3d10
+
fe3d10
+    # check that virusfilter:rename prefix/suffix was added
fe3d10
+    if [ ! -f "${sharedir}/${smbfilerenamed}" ]; then
fe3d10
+        echo "ERROR: ${sharedir}/${smbfilerenamed} is missing."
fe3d10
+        return 1
fe3d10
+    fi
fe3d10
+
fe3d10
+    # check that file was not uploaded
fe3d10
+    if [ -f "${sharedir}/infected.upload.txt" ]; then
fe3d10
+        echo "ERROR: {sharedir}/${smbfile} should not exist."
fe3d10
+        return 1
fe3d10
+    fi
fe3d10
+
fe3d10
+    return 0
fe3d10
+}
fe3d10
+
fe3d10
+check_healthy_read()
fe3d10
+{
fe3d10
+    rm -rf "${sharedir:?}"/*
fe3d10
+
fe3d10
+    if ! echo "Hello Samba!" > "${sharedir}/healthy.txt"; then
fe3d10
+        echo "ERROR: Cannot create ${sharedir}/healthy.txt"
fe3d10
+        return 1
fe3d10
+    fi
fe3d10
+
fe3d10
+    ${SMBCLIENT} //"${SERVER_IP}"/"${SHARE}" -U"${USER}"%"${PASSWORD}" -c "get healthy.txt ${sharedir}/healthy.download.txt"
fe3d10
+
fe3d10
+    if ! cmp "${sharedir}/healthy.txt" "${sharedir}/healthy.download.txt"; then
fe3d10
+        echo "ERROR: cmp ${sharedir}/healthy.txt ${sharedir}/healthy.download.txt FAILED"
fe3d10
+        return 1
fe3d10
+    fi
fe3d10
+
fe3d10
+    return 0
fe3d10
+}
fe3d10
+
fe3d10
+check_healthy_write()
fe3d10
+{
fe3d10
+    rm -rf "${sharedir:?}"/*
fe3d10
+
fe3d10
+    if ! echo "Hello Samba!" > "${sharedir}/healthy.txt"; then
fe3d10
+        echo "ERROR: Cannot create ${sharedir}/healthy.txt"
fe3d10
+        return 1
fe3d10
+    fi
fe3d10
+
fe3d10
+    ${SMBCLIENT} //"${SERVER_IP}"/"${SHARE}" -U"${USER}"%"${PASSWORD}" -c "put ${sharedir}/healthy.txt healthy.upload.txt"
fe3d10
+
fe3d10
+    if ! cmp "${sharedir}/healthy.txt" "${sharedir}/healthy.upload.txt"; then
fe3d10
+        echo "ERROR: cmp ${sharedir}/healthy.txt ${sharedir}/healthy.upload.txt FAILED"
fe3d10
+        return 1
fe3d10
+    fi
fe3d10
+
fe3d10
+    return 0
fe3d10
+}
fe3d10
+
fe3d10
+testit "check_infected_read"  check_infected_read  || failed=$((failed + 1))
fe3d10
+testit "check_infected_write" check_infected_write || failed=$((failed + 1))
fe3d10
+testit "check_healthy_read"   check_healthy_read   || failed=$((failed + 1))
fe3d10
+testit "check_healthy_write"  check_healthy_write  || failed=$((failed + 1))
fe3d10
+
fe3d10
+testok "$0" "$failed"
fe3d10
diff --git a/source3/selftest/tests.py b/source3/selftest/tests.py
fe3d10
index 701be011f70..6b146c76381 100755
fe3d10
--- a/source3/selftest/tests.py
fe3d10
+++ b/source3/selftest/tests.py
fe3d10
@@ -1240,6 +1240,15 @@ plantestsuite("samba3.blackbox.smbXsrv_client_dead_rec", "fileserver:local",
fe3d10
                '$SERVER_IP',
fe3d10
                "tmp"])
fe3d10
 
fe3d10
+env = 'fileserver'
fe3d10
+plantestsuite("samba3.blackbox.virus_scanner", "%s:local" % (env),
fe3d10
+              [os.path.join(samba3srcdir,
fe3d10
+                            "script/tests/test_virus_scanner.sh"),
fe3d10
+               '$SERVER_IP',
fe3d10
+               "virusfilter",
fe3d10
+               '$LOCAL_PATH',
fe3d10
+               smbclient3])
fe3d10
+
fe3d10
 for env in ['fileserver', 'simpleserver']:
fe3d10
     plantestsuite("samba3.blackbox.smbclient.encryption", env,
fe3d10
                   [os.path.join(samba3srcdir, "script/tests/test_smbclient_encryption.sh"),
fe3d10
-- 
fe3d10
2.34.1
fe3d10
fe3d10
fe3d10
From 275139352e854c7b01a53014b16673c8c7254fa9 Mon Sep 17 00:00:00 2001
fe3d10
From: =?UTF-8?q?Pavel=20Filipensk=C3=BD?= <pfilipen@redhat.com>
fe3d10
Date: Mon, 7 Feb 2022 23:06:10 +0100
fe3d10
Subject: [PATCH 6/6] s3:modules: Fix virusfilter_vfs_openat
fe3d10
MIME-Version: 1.0
fe3d10
Content-Type: text/plain; charset=UTF-8
fe3d10
Content-Transfer-Encoding: 8bit
fe3d10
fe3d10
Bug: https://bugzilla.samba.org/show_bug.cgi?id=14971
fe3d10
fe3d10
Signed-off-by: Pavel Filipenský <pfilipen@redhat.com>
fe3d10
fe3d10
Pair-Programmed-With: Andreas Schneider <asn@samba.org>
fe3d10
Reviewed-by: Jeremy Allison <jra@samba.org>
fe3d10
Reviewed-by: Andreas Schneider <asn@samba.org>
fe3d10
fe3d10
Autobuild-User(master): Jeremy Allison <jra@samba.org>
fe3d10
Autobuild-Date(master): Thu Feb 10 22:09:06 UTC 2022 on sn-devel-184
fe3d10
fe3d10
(cherry picked from commit 3f1c958f6fa9d2991185f4e281a377a295d09f9c)
fe3d10
---
fe3d10
 selftest/knownfail.d/virus_scanner | 2 --
fe3d10
 source3/modules/vfs_virusfilter.c  | 6 +++---
fe3d10
 2 files changed, 3 insertions(+), 5 deletions(-)
fe3d10
 delete mode 100644 selftest/knownfail.d/virus_scanner
fe3d10
fe3d10
diff --git a/selftest/knownfail.d/virus_scanner b/selftest/knownfail.d/virus_scanner
fe3d10
deleted file mode 100644
fe3d10
index 6df3fd20627..00000000000
fe3d10
--- a/selftest/knownfail.d/virus_scanner
fe3d10
+++ /dev/null
fe3d10
@@ -1,2 +0,0 @@
fe3d10
-^samba3.blackbox.virus_scanner.check_infected_read  # test download infected file ('vfs objects = virusfilter')
fe3d10
-^samba3.blackbox.virus_scanner.check_infected_write # test upload infected file ('vfs objects = virusfilter')
fe3d10
diff --git a/source3/modules/vfs_virusfilter.c b/source3/modules/vfs_virusfilter.c
fe3d10
index e6cbee7cd45..d1554967ad1 100644
fe3d10
--- a/source3/modules/vfs_virusfilter.c
fe3d10
+++ b/source3/modules/vfs_virusfilter.c
fe3d10
@@ -1309,21 +1309,21 @@ static int virusfilter_vfs_openat(struct vfs_handle_struct *handle,
fe3d10
 		 */
fe3d10
 		goto virusfilter_vfs_open_next;
fe3d10
 	}
fe3d10
-	ret = S_ISREG(smb_fname->st.st_ex_mode);
fe3d10
+	ret = S_ISREG(sbuf.st_ex_mode);
fe3d10
 	if (ret == 0) {
fe3d10
 		DBG_INFO("Not scanned: Directory or special file: %s/%s\n",
fe3d10
 			 cwd_fname, fname);
fe3d10
 		goto virusfilter_vfs_open_next;
fe3d10
 	}
fe3d10
 	if (config->max_file_size > 0 &&
fe3d10
-	    smb_fname->st.st_ex_size > config->max_file_size)
fe3d10
+	    sbuf.st_ex_size > config->max_file_size)
fe3d10
 	{
fe3d10
 		DBG_INFO("Not scanned: file size > max file size: %s/%s\n",
fe3d10
 			 cwd_fname, fname);
fe3d10
 		goto virusfilter_vfs_open_next;
fe3d10
 	}
fe3d10
 	if (config->min_file_size > 0 &&
fe3d10
-	    smb_fname->st.st_ex_size < config->min_file_size)
fe3d10
+	    sbuf.st_ex_size < config->min_file_size)
fe3d10
 	{
fe3d10
 		DBG_INFO("Not scanned: file size < min file size: %s/%s\n",
fe3d10
 		      cwd_fname, fname);
fe3d10
-- 
fe3d10
2.34.1
fe3d10