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