Blame SOURCES/openscap-1.3.4-detect_remote_file_systems-PR_1573.patch

37bf60
diff --git a/src/OVAL/probes/fsdev.c b/src/OVAL/probes/fsdev.c
37bf60
index 82356d5e0..983675098 100644
37bf60
--- a/src/OVAL/probes/fsdev.c
37bf60
+++ b/src/OVAL/probes/fsdev.c
37bf60
@@ -62,6 +62,7 @@
37bf60
 #endif
37bf60
 
37bf60
 #include "fsdev.h"
37bf60
+#include "common/util.h"
37bf60
 
37bf60
 /**
37bf60
  * Compare two dev_t variables.
37bf60
@@ -79,10 +80,6 @@ static int fsdev_cmp(const void *a, const void *b)
37bf60
 #if defined(OS_LINUX)
37bf60
 static int is_local_fs(struct mntent *ment)
37bf60
 {
37bf60
-// todo: would it be usefull to provide the choice during build-time?
37bf60
-#if 1
37bf60
-	char *s;
37bf60
-
37bf60
 	/*
37bf60
 	 * When type of the filesystem is autofs, it means the mtab entry
37bf60
 	 * describes the autofs configuration, which means ment->mnt_fsname
37bf60
@@ -97,37 +94,42 @@ static int is_local_fs(struct mntent *ment)
37bf60
 		return 0;
37bf60
 	}
37bf60
 
37bf60
-	if (ment->mnt_fsname == NULL) {
37bf60
-		return 0;
37bf60
-	}
37bf60
-
37bf60
-	s = ment->mnt_fsname;
37bf60
-	/* If the fsname begins with "//", it is probably CIFS. */
37bf60
-	if (s[0] == '/' && s[1] == '/')
37bf60
-		return 0;
37bf60
-
37bf60
-	/* If there's a ':' in the fsname and it occurs before any
37bf60
-	 * '/', then this is probably NFS and the file system is
37bf60
-	 * considered "remote".
37bf60
+	/*
37bf60
+	 * The following code is inspired by systemd, function fstype_is_network:
37bf60
+	 * https://github.com/systemd/systemd/blob/21fd6bc263f49b57867d90d2e1f9f255e5509134/src/basic/mountpoint-util.c#L290
37bf60
 	 */
37bf60
-	s = strpbrk(s, "/:");
37bf60
-	if (s && *s == ':')
37bf60
-		return 0;
37bf60
 
37bf60
+	const char *fstype = ment->mnt_type;
37bf60
+	if (oscap_str_startswith(fstype, "fuse.")) {
37bf60
+		fstype += strlen("fuse.");
37bf60
+	}
37bf60
+	const char *network_fs[] = {
37bf60
+		"afs",
37bf60
+		"ceph",
37bf60
+		"cifs",
37bf60
+		"smb3",
37bf60
+		"smbfs",
37bf60
+		"sshfs",
37bf60
+		"ncpfs",
37bf60
+		"ncp",
37bf60
+		"nfs",
37bf60
+		"nfs4",
37bf60
+		"gfs",
37bf60
+		"gfs2",
37bf60
+		"glusterfs",
37bf60
+		"gpfs",
37bf60
+		"pvfs2", /* OrangeFS */
37bf60
+		"ocfs2",
37bf60
+		"lustre",
37bf60
+		"davfs",
37bf60
+		NULL
37bf60
+	};
37bf60
+	for (int i = 0; network_fs[i]; i++) {
37bf60
+		if (!strcmp(network_fs[i], fstype)) {
37bf60
+			return 0;
37bf60
+		}
37bf60
+	}
37bf60
 	return 1;
37bf60
-#else
37bf60
-	struct stat st;
37bf60
-
37bf60
-	/* If the file system is not backed-up by a real file, it is
37bf60
-	   considered remote. A notable exception is "tmpfs" to allow
37bf60
-	   traversal of /tmp et al. */
37bf60
-	if (strcmp(ment->mnt_fsname, "tmpfs") != 0
37bf60
-	    && (stat(ment->mnt_fsname, &st) != 0
37bf60
-		|| !(S_ISBLK(st.st_mode))))
37bf60
-		return 0;
37bf60
-	else
37bf60
-		return 1;
37bf60
-#endif
37bf60
 }
37bf60
 
37bf60
 #elif defined(OS_AIX)