Skip to contentSkip to conversation

setsebool and togglesebool patch

PATCH Steve G 2 participants 2 messages Nov 4, 2004 – Nov 5, 2004 SELinux security module

lore
Share & tools
lore

Steve G

author
#0 lore raw

Hi,

I've been reviewing the tools distributed in Fedora and have a patch that makes a few changes. Booleans have a transaction-like interface. But the tools do not do a rollback if they blow up in the middle of something. For example, suppose I type in a list of 4 apache booleans I want to toggle, but make a typo in one. 3 of them will get set. Until I correct it, apache would be running with one bool in the opposite state.

Also, setsebool is used by scripts to set the state of a boolean to a particular value. As its stands, it is not done in a transactional way because it does not take a list of name/value pairs. So, there can be a race as parts of a program get the boolean changed.

Also, an audit record is written by the kernel saying ALL the current values during a commit, but you don't have a good way of seeing only the changes that were made by a user.

I've attempted to fix these issues with the attached patch.

togglesebool is updated to do the following:

* It is now all or nothing. Meaning that it toggles all booleans passed or none at all.
* It logs to syslog what was done and by whom.

In order to make the rollback code simple, I needed a change to src/booleans.c so that it would reject anything except 0 or 1.

setsebool had more changes. Rather than review the patch, you might apply it and then review the resulting code. setsebool is used by a configuration tool to write all booleans to memory. The config tool then writes them to disk. So, it was updated to do the following:

* It now takes lists of booleans and treats them in an all or nothing manner. All get set or none at all.
* It takes a -P option to tell it to write the configuration to disk
* It logs to syslog what was changed and by whom.
* Preserves the old syntax. Scripts using it as 'setsebool bool value' will continue to work.

I also updated all affected man pages to document the new syntax.

Thanks,
-Steve Grubb

__________________________________
Do you Yahoo!?
Check out the new Yahoo! Front Page.
www.yahoo.com

man/man8/setsebool.8 +11 -6
diff -ur libselinux-1.17.15.orig/man/man8/setsebool.8 libselinux-1.17.15/man/man8/setsebool.8
@@ -4,16 +4,21 @@
 
 .SH "SYNOPSIS"
 .B setsebool
-.I "boolean value"
+.I "[ -P ] boolean value | bool1=val1 bool2=val2 ..."
 
 .SH "DESCRIPTION"
 .B setsebool 
-sets the current state of a particular SELinux boolean to a given value.
-The value may be 1 or true to enable the boolean, or 0 or false to disable it.
-Only the current boolean value is affected; the boot-time default settings
-defined by
+sets the current state of a particular SELinux boolean or a list of booleans 
+to a given value. The value may be 1 or true to enable the boolean, or 0 or 
+false to disable it. 
+
+Without the -P option, only the current boolean value is 
+affected; the boot-time default settings defined by
 .I /etc/selinux/SELINUXTYPE/booleans
-are not changed by this utility.
+are not changed. 
+
+If the -P option is given, all pending values are written to
+the boolean file on disk.
 
 .SH AUTHOR	
 This manual page was written by Dan Walsh <[email protected]>.
src/booleans.c +2 -0
diff -ur libselinux-1.17.15.orig/src/booleans.c libselinux-1.17.15/src/booleans.c
@@ -165,6 +165,8 @@
 	char buf[2], *fname;
 
 	assert(selinux_mnt);
+	if ( value < 0 || value > 1 )
+		return -1;
 
 	len = strlen(name) + strlen(selinux_mnt) + sizeof(SELINUX_BOOL_DIR);
 	fname = (char*)malloc(sizeof(char) * len);
utils/getsebool.c +3 -1
diff -ur libselinux-1.17.15.orig/utils/getsebool.c libselinux-1.17.15/utils/getsebool.c
@@ -30,7 +30,9 @@
 			errno = 0;
 			rc = security_get_boolean_names(&names, &len);
 			if (rc) {
-				fprintf(stderr, "%s:  Unable to get boolean names:  %s\n", argv[0], strerror(errno));
+				fprintf(stderr, 
+				    "%s:  Unable to get boolean names:  %s\n", 
+				    argv[0], strerror(errno));
 				return 1;
 			}
 			if (!len) {
utils/setsebool.c +180 -21

226 lines not on this page · raw message

utils/togglesebool.c +43 -11

96 lines not on this page · raw message