All of lore.kernel.org
 help / color / mirror / Atom feed
* idea: setfiles to exclude specific type
@ 2004-11-22 15:54 Yuichi Nakamura
  2004-11-22 17:00 ` Daniel J Walsh
  2004-11-22 19:20 ` Colin Walters
  0 siblings, 2 replies; 5+ messages in thread
From: Yuichi Nakamura @ 2004-11-22 15:54 UTC (permalink / raw)
  To: sds, dwalsh, selinux; +Cc: himainu-ynakam

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

Hello.

I add setfiles "-x" option.
I attach my idea in "setfiles.diff".

-x option is used to exclude specified type.

For example,
# setfiles file_contexts /home -x httpd_user_rw_t
setfiles skips relabeling files that have "httpd_user_rw_t".

The reason why this option is necessary is following.
I heard that fixfiles.cron is removed, because unwanted alerts are displayed.
In some case, types must be preserved.
http://www.redhat.com/archives/fedora-selinux-list/2004-November/msg00061.html

But I think fixfiles.cron is useful, and hope it is included again.
Because integrity of label is critical for SELinux.

I think to suppress unwanted alerts, 
it is necessary to add new option in setfiles and modify fixfiles.

Does it sound reasonable?

---
Yuichi Nakamura
Japan SELinux Users Group(JSELUG)
http://www.selinux.gr.jp/

[-- Attachment #2: setfiles.diff --]
[-- Type: application/octet-stream, Size: 2871 bytes --]

--- setfiles.c.orig	2004-11-19 15:40:07.000000000 -0500
+++ setfiles.c	2004-11-19 16:22:19.444466440 -0500
@@ -4,7 +4,7 @@
  * AUTHOR:  Stephen Smalley <sds@epoch.ncsc.mil>
  * This program was derived in part from the setfiles.pl script
  * developed by Secure Computing Corporation.
- *
+ * -x option: Yuichi Nakamura <ynakam@selinux.gr.jp>
  * PURPOSE:
  * This program reads a set of file security context specifications
  * based on pathname regular expressions and labels files
@@ -25,6 +25,7 @@
  * -v	Show changes in file labels.  
  * -W   Warn about entries that have no matching file.
  * -o filename write out file names with wrong context.
+ * -x   Specify type to exclude
  *
  * spec_file	The specification file.
  * pathname...	The file systems to label (omit if using -s).	
@@ -81,10 +82,12 @@
 static int excludeCtr=0;
 struct edir {
 	char *directory;
+	char *type;
         int size;
 };
 static struct edir excludeArray[MAX_EXCLUDES];
 
+
 /*
  * Command-line options.
  */
@@ -153,12 +156,35 @@
 	return tmp - buf;
 }
 
+int checktype(const char *file, char *type, int size){
+	security_context_t con;
+	char *c;
+	int ret;
+
+	ret = getfilecon(file, &con);
+	if(ret == -1){
+		return 0;
+	}
+	c = strrchr(con,':');
+	c++;
+	if(strcmp(c,type) ==0 ){
+		return 1;
+	}
+	return 0;
+}
+
 static int exclude(const char *file) {
 	int i=0;
-	for(i=0; i < excludeCtr; i++) { 
-		if (strncmp(file,excludeArray[i].directory,excludeArray[i].size)==0) {
-			if (file[excludeArray[i].size]==0 || 
-			    file[excludeArray[i].size]=='/') {
+	for(i=0; i < excludeCtr; i++) {
+		if(excludeArray[i].type == NULL){
+			if (strncmp(file,excludeArray[i].directory,excludeArray[i].size)==0) {
+				if (file[excludeArray[i].size]==0 || 
+				    file[excludeArray[i].size]=='/') {
+					return 1;
+				}
+			}
+		}else{
+			if( checktype(file,excludeArray[i].type,excludeArray[i].size) == 1){
 				return 1;
 			}
 		}
@@ -775,7 +801,7 @@
 	memset(excludeArray,0, sizeof(excludeArray));
 
 	/* Process any options. */
-	while ((opt = getopt(argc, argv, "c:dlnqrsvWe:o:")) > 0) {
+	while ((opt = getopt(argc, argv, "c:dlnqrsvWe:x:o:")) > 0) {
 		switch (opt) {
 		case 'c':
 		{
@@ -818,6 +844,7 @@
 			}
 			len=strlen(optarg);
 			excludeArray[excludeCtr].directory = strdup(optarg);
+			excludeArray[excludeCtr].type = NULL;
 			if (!excludeArray[excludeCtr].directory) {
 				fprintf(stderr, "Out of memory.\n");
 				exit(1);
@@ -830,7 +857,21 @@
 			}
 			break;
 		}
-			
+		case 'x':
+		{
+			int len;
+			len=strlen(optarg);
+			excludeArray[excludeCtr].type = strdup(optarg);
+			excludeArray[excludeCtr].directory = NULL;
+			excludeArray[excludeCtr++].size = len;
+			if (excludeCtr > MAX_EXCLUDES) {
+				fprintf(stderr, "Maximum excludes %d exceeded.\n", 
+					MAX_EXCLUDES);
+				exit(1);
+			}
+			break;
+		}
+	
 		case 'd':
 			debug = 1;
 			break;

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2004-11-22 19:28 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-11-22 15:54 idea: setfiles to exclude specific type Yuichi Nakamura
2004-11-22 17:00 ` Daniel J Walsh
2004-11-22 17:58   ` Yuichi Nakamura
2004-11-22 19:20 ` Colin Walters
2004-11-22 19:27   ` Daniel J Walsh

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.