Blame SOURCES/autofs_entries_in_mtab.patch

7a6a25
From 309f8230d67f229b6091876c3ace62370fb3d451 Mon Sep 17 00:00:00 2001
7a6a25
From: =?UTF-8?q?Jan=20=C4=8Cern=C3=BD?= <jcerny@redhat.com>
7a6a25
Date: Fri, 17 May 2019 10:25:08 +0200
7a6a25
Subject: [PATCH 1/2] Handle autofs entries in /etc/mtab
7a6a25
7a6a25
Some file systems can be mounted using autofs, which should be
7a6a25
considered during analysis of /etc/mtab.F or more details,
7a6a25
please see the comment introduced in this patch.
7a6a25
---
7a6a25
 src/OVAL/probes/fsdev.c | 14 ++++++++++++++
7a6a25
 1 file changed, 14 insertions(+)
7a6a25
7a6a25
diff --git a/src/OVAL/probes/fsdev.c b/src/OVAL/probes/fsdev.c
7a6a25
index ca6304890..29250f2bf 100644
7a6a25
--- a/src/OVAL/probes/fsdev.c
7a6a25
+++ b/src/OVAL/probes/fsdev.c
7a6a25
@@ -125,6 +125,20 @@ is_local_fs(struct mntent *ment)
7a6a25
 #if 1
7a6a25
 	char *s;
7a6a25
 
7a6a25
+	/*
7a6a25
+	 * When type of the filesystem is autofs, it means the mtab entry
7a6a25
+	 * describes the autofs configuration, which means ment->mnt_fsname
7a6a25
+	 * is a path to the relevant autofs map, eg. /etc/auto.misc. In this
7a6a25
+	 * situation, the following code which analyses ment->mnt_type would
7a6a25
+	 * not work. When the filesystem handled by autofs is mounted, there
7a6a25
+	 * is another different entry in mtab which contains the real block
7a6a25
+	 * special device or remote filesystem in ment->mnt_fsname, and that
7a6a25
+	 * will be parsed in a different call of this function.
7a6a25
+	 */
7a6a25
+	if (!strcmp(ment->mnt_type, "autofs")) {
7a6a25
+		return 0;
7a6a25
+	}
7a6a25
+
7a6a25
 	s = ment->mnt_fsname;
7a6a25
 	/* If the fsname begins with "//", it is probably CIFS. */
7a6a25
 	if (s[0] == '/' && s[1] == '/')
7a6a25
7a6a25
From fff58197d9747a08d0fc23914a31fefbe44f07ea Mon Sep 17 00:00:00 2001
7a6a25
From: =?UTF-8?q?Jan=20=C4=8Cern=C3=BD?= <jcerny@redhat.com>
7a6a25
Date: Fri, 17 May 2019 16:16:23 +0200
7a6a25
Subject: [PATCH 2/2] Test is_local_fs
7a6a25
7a6a25
Adds a simple unit test that checks whether autofs entries in
7a6a25
/etc/mtab are not considered local.
7a6a25
---
7a6a25
 src/OVAL/probes/fsdev.c                   |  6 ++--
7a6a25
 src/OVAL/probes/public/fsdev.h            | 14 ++++++++
7a6a25
 tests/API/probes/Makefile.am              |  6 ++--
7a6a25
 tests/API/probes/all.sh                   |  1 +
7a6a25
 tests/API/probes/test_fsdev_is_local_fs.c | 41 +++++++++++++++++++++++
7a6a25
 5 files changed, 62 insertions(+), 6 deletions(-)
7a6a25
 create mode 100644 tests/API/probes/test_fsdev_is_local_fs.c
7a6a25
7a6a25
diff --git a/src/OVAL/probes/fsdev.c b/src/OVAL/probes/fsdev.c
7a6a25
index 29250f2bf..d455b39c4 100644
7a6a25
--- a/src/OVAL/probes/fsdev.c
7a6a25
+++ b/src/OVAL/probes/fsdev.c
7a6a25
@@ -118,8 +118,7 @@ static int match_fs(const char *fsname, const char **fs_arr, size_t fs_cnt)
7a6a25
 #define DEVID_ARRAY_ADD  8
7a6a25
 
7a6a25
 #if defined(__linux__)
7a6a25
-static int
7a6a25
-is_local_fs(struct mntent *ment)
7a6a25
+int is_local_fs(struct mntent *ment)
7a6a25
 {
7a6a25
 // todo: would it be usefull to provide the choice during build-time?
7a6a25
 #if 1
7a6a25
@@ -169,8 +168,7 @@ is_local_fs(struct mntent *ment)
7a6a25
 }
7a6a25
 
7a6a25
 #elif defined(_AIX)
7a6a25
-static int
7a6a25
-is_local_fs(struct mntent *ment)
7a6a25
+int is_local_fs(struct mntent *ment)
7a6a25
 {
7a6a25
 	int i;
7a6a25
 	struct vfs_ent *e;
7a6a25
diff --git a/src/OVAL/probes/public/fsdev.h b/src/OVAL/probes/public/fsdev.h
7a6a25
index 382ec536b..aeb455df1 100644
7a6a25
--- a/src/OVAL/probes/public/fsdev.h
7a6a25
+++ b/src/OVAL/probes/public/fsdev.h
7a6a25
@@ -36,6 +36,10 @@
7a6a25
 #include <stdint.h>
7a6a25
 #include <sys/stat.h>
7a6a25
 
7a6a25
+#if defined(__linux__) || defined(_AIX)
7a6a25
+#include <mntent.h>
7a6a25
+#endif
7a6a25
+
7a6a25
 /**
7a6a25
  * Filesystem device structure.
7a6a25
  */
7a6a25
@@ -88,5 +92,15 @@ int fsdev_path(fsdev_t * lfs, const char *path);
7a6a25
  */
7a6a25
 int fsdev_fd(fsdev_t * lfs, int fd);
7a6a25
 
7a6a25
+#if defined(__linux__) || defined(_AIX)
7a6a25
+/**
7a6a25
+ * Detemines whether a given mtab entry is a local file system.
7a6a25
+ * @param ment Structure returned by getmntent (see `man 3 getmntent`).
7a6a25
+ * @retval 1 if local
7a6a25
+ * @retval 0 otherwise
7a6a25
+ */
7a6a25
+int is_local_fs(struct mntent *ment);
7a6a25
+#endif
7a6a25
+
7a6a25
 #endif				/* FSDEV_H */
7a6a25
 /// @}
7a6a25
diff --git a/tests/API/probes/Makefile.am b/tests/API/probes/Makefile.am
7a6a25
index e26a47e63..70442bcc3 100644
7a6a25
--- a/tests/API/probes/Makefile.am
7a6a25
+++ b/tests/API/probes/Makefile.am
7a6a25
@@ -26,14 +26,16 @@ TESTS_ENVIRONMENT = \
7a6a25
 		$(top_builddir)/run
7a6a25
 
7a6a25
 TESTS = all.sh
7a6a25
-check_PROGRAMS = test_api_probes_smoke oval_fts_list
7a6a25
+check_PROGRAMS = test_api_probes_smoke oval_fts_list test_fsdev_is_local_fs
7a6a25
 
7a6a25
 test_api_probes_smoke_SOURCES = test_api_probes_smoke.c
7a6a25
 oval_fts_list_CFLAGS= -I$(top_srcdir)/src/OVAL/probes
7a6a25
 oval_fts_list_SOURCES= oval_fts_list.c
7a6a25
+test_fsdev_is_local_fs_SOURCES = test_fsdev_is_local_fs.c
7a6a25
 
7a6a25
 EXTRA_DIST += \
7a6a25
 	all.sh \
7a6a25
 	fts.sh \
7a6a25
 	gentree.sh \
7a6a25
-	test_api_probes_smoke.c
7a6a25
+	test_api_probes_smoke.c \
7a6a25
+	test_fsdev_is_local_fs.c
7a6a25
diff --git a/tests/API/probes/all.sh b/tests/API/probes/all.sh
7a6a25
index e0c35de88..46c680667 100755
7a6a25
--- a/tests/API/probes/all.sh
7a6a25
+++ b/tests/API/probes/all.sh
7a6a25
@@ -7,6 +7,7 @@ test_init "test_api_probes.log"
7a6a25
 if [ -z ${CUSTOM_OSCAP+x} ] ; then
7a6a25
     test_run "fts test" $srcdir/fts.sh
7a6a25
     test_run "probe api smoke test" ./test_api_probes_smoke
7a6a25
+    test_run "fsdev is_local_fs unit test" ./test_fsdev_is_local_fs
7a6a25
 fi
7a6a25
 
7a6a25
 test_exit
7a6a25
diff --git a/tests/API/probes/test_fsdev_is_local_fs.c b/tests/API/probes/test_fsdev_is_local_fs.c
7a6a25
new file mode 100644
7a6a25
index 000000000..bcc596442
7a6a25
--- /dev/null
7a6a25
+++ b/tests/API/probes/test_fsdev_is_local_fs.c
7a6a25
@@ -0,0 +1,41 @@
7a6a25
+/*
7a6a25
+ * Copyright 2019 Red Hat Inc., Durham, North Carolina.
7a6a25
+ * All Rights Reserved.
7a6a25
+ *
7a6a25
+ * This library is free software; you can redistribute it and/or
7a6a25
+ * modify it under the terms of the GNU Lesser General Public
7a6a25
+ * License as published by the Free Software Foundation; either
7a6a25
+ * version 2.1 of the License, or (at your option) any later version.
7a6a25
+ *
7a6a25
+ * This library is distributed in the hope that it will be useful,
7a6a25
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
7a6a25
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
7a6a25
+ * Lesser General Public License for more details.
7a6a25
+ *
7a6a25
+ * You should have received a copy of the GNU Lesser General Public
7a6a25
+ * License along with this library; if not, write to the Free Software
7a6a25
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
7a6a25
+ *
7a6a25
+ * Authors:
7a6a25
+ *      "Jan Černý" <jcerny@redhat.com>
7a6a25
+ */
7a6a25
+
7a6a25
+#ifdef HAVE_CONFIG_H
7a6a25
+#include <config.h>
7a6a25
+#endif
7a6a25
+
7a6a25
+#include <stdio.h>
7a6a25
+#include <string.h>
7a6a25
+#include <mntent.h>
7a6a25
+#include "fsdev.h"
7a6a25
+
7a6a25
+int main(int argc, char *argv[])
7a6a25
+{
7a6a25
+	struct mntent ment;
7a6a25
+	ment.mnt_type = "autofs";
7a6a25
+	int ret = is_local_fs(&ment);
7a6a25
+	if (ret != 0) {
7a6a25
+		return 1;
7a6a25
+	}
7a6a25
+	return 0;
7a6a25
+}
7a6a25
\ No newline at end of file