All of lore.kernel.org
 help / color / mirror / Atom feed
* [BETTER PATCH] support for altroot in setfiles
@ 2003-05-09 21:30 Joshua Brindle
  0 siblings, 0 replies; only message in thread
From: Joshua Brindle @ 2003-05-09 21:30 UTC (permalink / raw)
  To: SELinux

[-- Attachment #1: Type: text/plain, Size: 562 bytes --]

Ok, i apoligize to everyone for posting that horribly insecure 
patch on this list :) I was going for functionality so that i could
get it working then hope that someone else would fix it up, 
and someone did, a fellow gentoo developer zach welch
(zwelch@gentoo.org) corrected all the buffer and memory problems
 we could find so hopefully this will be much easier to audit and 
incorporate into cvs. Thanks russel and steve for your replies, 
hope you guys like this one better.



Joshua Brindle
UNIX Administrator
Southern Nazarene University


[-- Attachment #2: setfiles.c[1].patch --]
[-- Type: application/octet-stream, Size: 2402 bytes --]

--- setfiles-orig.c	2003-05-08 18:17:48.000000000 -0700
+++ setfiles.c	2003-05-09 14:19:40.000000000 -0700
@@ -89,6 +89,10 @@
 static int use_inum = 0;
 
 static int quiet = 0;
+
+static char *rootpath = NULL;
+static int rootpathlen = 0;
+
 #define QPRINTF(args...) do { if (!quiet) printf(args); } while (0)
 
 /*
@@ -283,15 +287,27 @@
 int match(const char *name, struct stat *sb, security_id_t *out_sid) 
 {
 	int i, ret;
+	const char *fullname = name;
+
+	/* fullname will be the real file that gets labeled
+	 * name will be what is matched in the policy */
+	if (NULL != rootpath) {
+		if (0 != strncmp(rootpath, name, rootpathlen)) {
+			fprintf(stderr, "%s:  %s is not located in %s\n", 
+				progname, name, rootpath);
+			return -1;
+		}
+		name += rootpathlen;
+	}
 
 	if (flask_enabled) {
-		ret = lstat_secure(name, sb, out_sid);
+		ret = lstat_secure(fullname, sb, out_sid);
 	} else {
-		ret = lstat(name, sb);
+		ret = lstat(fullname, sb);
 	} 
 	if (ret) {
 		fprintf(stderr, "%s:  unable to stat file %s\n", progname,
-			name);
+			fullname);
 		return -1;
 	}
 
@@ -564,6 +580,23 @@
 	return 0;
 }
 
+void set_rootpath(const char *arg)
+{
+	int len;
+
+	rootpath = strdup(arg);
+	if (NULL == rootpath) {
+		fprintf(stderr, "%s:  insufficient memory for rootpath\n", 
+			progname);
+		exit(1);
+	}
+
+	/* trim trailing /, if present */
+	len = strlen(rootpath);
+	while ('/' == rootpath[len - 1])
+		rootpath[--len] = 0;
+	rootpathlen = len;
+}
 
 int main(int argc, char **argv)
 {
@@ -577,7 +610,7 @@
 	struct stat sb;
 
 	/* Process any options. */
-	while ((opt = getopt(argc, argv, "dinqsvRW")) > 0) {
+	while ((opt = getopt(argc, argv, "dinqsvrRW")) > 0) {
 		switch (opt) {
 		case 'd':
 			debug = 1;
@@ -604,6 +637,20 @@
 		case 'i':
 			use_inum = 1;
 			break;
+		case 'r':
+			if (optind + 1 >= argc) {
+				fprintf(stderr, "usage:  %s -r rootpath\n", 
+					argv[0]);
+				exit(1);
+			}
+			if (NULL != rootpath) {
+				fprintf(stderr, 
+					"%s: only one -r can be specified\n", 
+					argv[0]);
+				exit(1);
+			}
+			set_rootpath(argv[optind++]);
+			break;
 		}
 	}
 
@@ -919,7 +966,11 @@
 	}
 	else for (; optind < argc; optind++)
 	{
-
+		if (NULL != rootpath) {
+			QPRINTF("%s:  labeling files, pretending %s is /\n",
+				argv[0], rootpath);
+		}
+		
 		if (flask_enabled) {
 			QPRINTF("%s:  labeling files under %s\n", argv[0],
 			       argv[optind]);

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2003-05-09 21:30 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-05-09 21:30 [BETTER PATCH] support for altroot in setfiles Joshua Brindle

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.