components/openscap/patches/recurse_file_system_local.patch
author Mike Sullivan <Mike.Sullivan@Oracle.COM>
Mon, 01 Apr 2013 23:00:57 -0700
changeset 1243 cf247f5101ae
parent 1169 0643a2e92103
child 1369 20813e08fff3
permissions -rw-r--r--
Added tag s12-19 for changeset f52d88cf6f9e

--- openscap-0.8.1/src/OVAL/probes/oval_fts.c.~1~	2011-10-10 02:03:15.000000000 -0700
+++ openscap-0.8.1/src/OVAL/probes/oval_fts.c	2013-02-20 09:31:53.973553902 -0800
@@ -45,6 +45,7 @@
 #include "SEAP/public/seap-debug.h"
 #if defined(__SVR4) && defined(__sun)
 #include "fts_sun.h"
+#include <sys/mntent.h>
 #else
 #include <fts.h>
 #endif
@@ -128,14 +129,73 @@
 	return;
 }
 
+#if defined(__SVR4) && defined(__sun)
+#ifndef MNTTYPE_SMB
+#define MNTTYPE_SMB	"smb"
+#endif
+#ifndef MNTTYPE_PROC
+#define MNTTYPE_PROC	"proc"
+#endif
+
+static bool valid_remote_fs(char *fstype)
+{
+	if (strcmp(fstype, MNTTYPE_NFS) == 0 ||
+	    strcmp(fstype, MNTTYPE_SMBFS) == 0 ||
+	    strcmp(fstype, MNTTYPE_SMB) == 0)
+		return (true);
+	return (false);
+}
+
+static bool valid_local_fs(char *fstype)
+{
+	if (strcmp(fstype, MNTTYPE_SWAP) == 0 ||
+	    strcmp(fstype, MNTTYPE_MNTFS) == 0 ||
+	    strcmp(fstype, MNTTYPE_CTFS) == 0 ||
+	    strcmp(fstype, MNTTYPE_OBJFS) == 0 ||
+	    strcmp(fstype, MNTTYPE_SHAREFS) == 0 ||
+	    strcmp(fstype, MNTTYPE_PROC) == 0 ||
+	    strcmp(fstype, MNTTYPE_LOFS) == 0 ||
+	    strcmp(fstype, MNTTYPE_AUTOFS) == 0)
+		return (false);
+	return (true);
+}
+#endif
+
 static bool OVAL_FTS_localp(OVAL_FTS *ofts, const char *path, void *id)
 {
+#if defined(__SVR4) && defined(__sun)
+	if (id != NULL && (*(char*)id) != '\0') {
+		/* if not a valid local fs skip */
+		if (valid_local_fs((char*)id)) {
+			/* if recurse is local , skip remote fs */
+			if (ofts->filesystem == OVAL_RECURSE_FS_LOCAL) {
+				return (!valid_remote_fs((char*)id));
+			}
+			return (true);
+		}
+		return (false);
+	} else if (path != NULL) {
+		/* id was not set, because fts_read failed to stat the node */
+		struct stat sb;
+		if ((stat(path, &sb) == 0) && (valid_local_fs(sb.st_fstype))) {
+			/* if recurse is local , skip remote fs */
+			if (ofts->filesystem == OVAL_RECURSE_FS_LOCAL) {
+				return (!valid_remote_fs(sb.st_fstype));
+			}
+			return (true);
+		}
+		return (false);
+	} else {
+		return (false);
+	}
+#else	
 	if (id != NULL)
 		return (fsdev_search(ofts->localdevs, id) == 1 ? true : false);
 	else if (path != NULL)
 		return (fsdev_path(ofts->localdevs, path) == 1 ? true : false);
 	else
 		return (false);
+#endif
 }
 
 static char *__regex_locate(char *str)
@@ -410,11 +470,15 @@
 
 	if (path) { /* filepath == NULL */
 		if (filesystem == OVAL_RECURSE_FS_LOCAL) {
+#if	defined(__SVR4) && defined(__sun)
+			ofts->localdevs = NULL;
+#else
 			ofts->localdevs = fsdev_init(NULL, 0);
 			if (ofts->localdevs == NULL) {
 				_F("fsdev_init() failed.\n");
 				return (NULL);
 			}
+#endif
 		}
 
 		ofts->ofts_spath = SEXP_ref(path); /* path entity */
@@ -444,7 +508,18 @@
 		fts_ent = fts_read(ofts->ofts_match_path_fts);
 		if (fts_ent == NULL)
 			return NULL;
-
+#if defined(__SVR4) && defined(__sun)
+		/* pseudo filesystems will be skipped */
+		/* no need to match in non-local fs when local is specified */
+		if ((fts_ent->fts_info == FTS_D || fts_ent->fts_info == FTS_SL)
+		    && (!OVAL_FTS_localp(ofts, fts_ent->fts_path,
+				(fts_ent->fts_statp != NULL) ?
+				&fts_ent->fts_statp->st_fstype : NULL))) {
+			fts_set(ofts->ofts_match_path_fts, fts_ent, FTS_SKIP);
+			dI("Skipping path:%s\n", fts_ent->fts_path);
+			continue;
+		}
+#endif
 		switch (fts_ent->fts_info) {
 		case FTS_DP:
 			continue;
@@ -605,14 +680,23 @@
 					continue;
 				}
 			}
-
+#if	defined(__SVR4) && defined(__sun)
+			/* pseudo filesystems will be skipped */
+			/* don't recurse into non-local fs if configured so */
+			if ((fts_ent->fts_info == FTS_D || fts_ent->fts_info == FTS_SL)
+			    && (!OVAL_FTS_localp(ofts, fts_ent->fts_path,
+					(fts_ent->fts_statp != NULL) ?
+					&fts_ent->fts_statp->st_fstype : NULL))) {
+#else
 			/* don't recurse into non-local fs if configured so */
 			if (ofts->filesystem == OVAL_RECURSE_FS_LOCAL
 			    && (fts_ent->fts_info == FTS_D || fts_ent->fts_info == FTS_SL)
 			    && (!OVAL_FTS_localp(ofts, fts_ent->fts_path,
 					(fts_ent->fts_statp != NULL) ?
 					&fts_ent->fts_statp->st_dev : NULL))) {
+#endif
 				fts_set(ofts->ofts_recurse_path_fts, fts_ent, FTS_SKIP);
+				dI("Skipping path:%s\n", fts_ent->fts_path);
 				continue;
 			}
 		}
@@ -644,12 +728,18 @@
 
 				if (ofts->ofts_recurse_path_curdepth == 0)
 					ofts->ofts_recurse_path_devid = fts_ent->fts_statp->st_dev;
-
+#if 	defined(__SVR4) && defined(__sun)
+				if ((!OVAL_FTS_localp(ofts, fts_ent->fts_path,
+						(fts_ent->fts_statp != NULL) ?
+						&fts_ent->fts_statp->st_fstype : NULL)))
+					break;
+#else
 				if (ofts->filesystem == OVAL_RECURSE_FS_LOCAL
 				    && (!OVAL_FTS_localp(ofts, fts_ent->fts_path,
 						(fts_ent->fts_statp != NULL) ?
 						&fts_ent->fts_statp->st_dev : NULL)))
 					break;
+#endif
 				if (ofts->filesystem == OVAL_RECURSE_FS_DEFINED
 				    && ofts->ofts_recurse_path_devid != fts_ent->fts_statp->st_dev)
 					break;
--- openscap-0.8.1/src/OVAL/probes/fsdev.c.~1~	2011-09-21 04:46:46.000000000 -0700
+++ openscap-0.8.1/src/OVAL/probes/fsdev.c	2013-02-19 11:12:36.120977086 -0800
@@ -223,7 +223,7 @@
 	FILE *fp;
 	size_t i;
 
-	struct mnttab *ment;
+	struct mnttab ment;
 	struct stat st;
 
 	fp = fopen(MNTTAB, "r");
@@ -248,9 +248,8 @@
 	i = 0;
 
 	if (fs == NULL) {
-		while ((getmntent(fp, ment)) != 0) {
-                        /* TODO: Is this check reliable? */
-                        if (stat (ment->mnt_special, &st) == 0 && (st.st_mode & S_IFCHR)) {
+		while ((getmntent(fp, &ment)) == 0) {
+                        if (stat (ment.mnt_special, &st) == 0 && (st.st_mode & S_IFCHR)) {
 
 				if (i >= lfs->cnt) {
 					lfs->cnt += DEVID_ARRAY_ADD;
@@ -261,9 +260,12 @@
 			}
 		}
 	} else {
-		while ((getmntent(fp, ment)) != 0) {
+		while ((getmntent(fp, &ment)) == 0) {
 
-			if (match_fs(ment->mnt_fstype, fs, fs_cnt)) {
+			if (match_fs(ment.mnt_fstype, fs, fs_cnt)) {
+
+				if (stat(ment.mnt_mountp, &st) != 0)
+					continue;
 
 				if (i >= lfs->cnt) {
 					lfs->cnt += DEVID_ARRAY_ADD;
--- openscap-0.8.1/src/OVAL/fts_sun.c.~1~	2011-09-21 04:46:45.000000000 -0700
+++ openscap-0.8.1/src/OVAL/fts_sun.c	2013-02-15 17:11:38.926803711 -0800
@@ -1022,6 +1022,10 @@
 	p->fts_instr = FTS_NOINSTR;
 	p->fts_number = 0;
 	p->fts_pointer = NULL;
+#if	defined(__SVR4) && defined(__sun)
+	if (!ISSET(FTS_NOSTAT))
+		p->fts_statp->st_fstype[0] = '\0';
+#endif
 	return (p);
 }