Subject: Re: bin/24583: /etc/security doesn't parse /etc/exports correctly
To: None <gnats-bugs@netbsd.org>
From: Jukka Salmi <j+nbsd@2004.salmi.ch>
List: netbsd-bugs
Date: 11/22/2004 15:07:09
--WIyZ46R2i8wDzkSu
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Just to update this PR: here is the patch for current (same
functionality as the one posted before), slightly modified
so it applies cleanly to the recently changed /etc/security
rev. 1.93.

-- 
bashian roulette:
$ ((RANDOM%6)) || rm -rf ~

--WIyZ46R2i8wDzkSu
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="etc_security.current-patch"

--- etc/security.orig	2004-11-22 14:43:50.000000000 +0100
+++ etc/security	2004-11-22 14:55:22.000000000 +0100
@@ -576,20 +576,46 @@
 		# ignore comments and blank lines
 		if ($0 ~ /^\#/ || $0 ~ /^$/ )
 			next;
+		# manage line continuation
+		while ($NF ~ /^\\$/) {
+			$NF = "";
+			line = $0 "";
+			getline;
+			$0 = line $0 "";
+		}
 
-		readonly = 0;
-		for (i = 2; i <= NF; ++i) {
-			if ($i ~ /-ro/)
-				readonly = 1;
-			else if ($i ~ /^-network=/)
-				next;
-			else if ($i !~ /^-/)
-				next;
+		delete dir;
+		readonly = ndir = 0;
+		for (i = 1; i <= NF; ++i) {
+			if ($i ~ /^\//) dir[ndir++] = $i;
+			else if ($i ~ /^-/) {
+				if ($i ~ /^-(ro|o)$/) readonly = 1;
+				if ($i ~ /^-network/) next;
+			}
+			else next;
 		}
 		if (readonly)
-			print "File system " $1 " globally exported, read-only."
+			for (item in dir)
+				rodir[nrodir++] = dir[item];
 		else
-			print "File system " $1 " globally exported, read-write."
+			for (item in dir)
+				rwdir[nrwdir++] = dir[item];
+
+	}
+
+	END {
+		if (nrodir) {
+			printf("Globally exported file system%s, read-only:\n",
+				nrodir > 1 ? "s" : "");
+			for (item in rodir)
+				printf("\t%s\n", rodir[item]);
+		}
+		if (nrwdir) {
+			printf("Globally exported file system%s, read-write:\n",
+				nrwdir > 1 ? "s" : "");
+			for (item in rwdir)
+				printf("\t%s\n", rwdir[item]);
+		}
 	}' < /etc/exports > $OUTPUT
 	if [ -s $OUTPUT ] ; then
 		printf "\nChecking for globally exported file systems.\n"

--WIyZ46R2i8wDzkSu--