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

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