toggle_bool
I wrote up little tool, toggle_bool, inspired by the old avc_toggle. You can specify one or more booleans on the command line, and it will toggle their value, and display their new value.
beta root # toggle_bool admin_sep disable_pax user_pingadmin_sep: activedisable_pax: inactiveuser_ping: inactive
beta root # toggle_bool admin_sep disable_pax user_pingadmin_sep: inactivedisable_pax: activeuser_ping: active
Signature · 8 lines
Chris PeBenito <[email protected]> Developer, Hardened Gentoo Linux Embedded Gentoo Linux Public Key: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0xE6AF9243 Key fingerprint = B0E6 877A 883F A57A 8E6A CB00 BC8E E42D E6AF 9243
/*
* Copyright 1999-2004 Gentoo Technologies, Inc.
* Distributed under the terms of the GNU General Public License v2
* $Header: /var/cvsroot/gentoo-projects/hardened/policycoreutils-extra/src/toggle_bool.c,v 1.1 2004/06/18 03:11:28 pebenito Exp $ */
#include <stdio.h>
#include <libgen.h>
#include <errno.h>
#include <selinux/selinux.h>
int main(int argc, char **argv) {
int rc, i, commit=0;
if(argc < 2) {
printf("Usage: %s boolname1 [boolname2 ...]\n",basename(argv[0]));
return 1;
}
for(i=1; i<argc; i++) {
printf("%s: ",argv[i]);
rc=security_get_boolean_active(argv[i]);
switch(rc) {
case 1:
if(security_set_boolean(argv[i],0) >= 0) {
printf("inactive\n");
commit++;
} else {
printf("%s\n",strerror(errno));
}
break;
case 0:
if(security_set_boolean(argv[i],1) >= 0) {
printf("active\n");
commit++;
} else {
printf("%s\n",strerror(errno));
}
break;
default:
if(errno==ENOENT)
printf("Boolean does not exist\n");
else
printf("%s\n",strerror(errno));
break;
}
}
if(commit > 0)
if(security_commit_booleans() < 0)
printf("Commit failed. (%s) No change to booleans.\n",strerror(errno));
}Oops, it was missing useful return's.
Quoted 13 lines · Chris PeBenito
I wrote up little tool,
toggle_bool, inspired by the oldavc_toggle. You can specify one or more booleans on the command line, and it will toggle their value, and display their new value.beta root #
toggle_booladmin_sepdisable_paxuser_pingadmin_sep: activedisable_pax: inactiveuser_ping: inactivebeta root #
toggle_booladmin_sepdisable_paxuser_pingadmin_sep: inactivedisable_pax: activeuser_ping: active
Signature · 8 lines
Chris PeBenito <[email protected]> Developer, Hardened Gentoo Linux Embedded Gentoo Linux Public Key: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0xE6AF9243 Key fingerprint = B0E6 877A 883F A57A 8E6A CB00 BC8E E42D E6AF 9243
/*
* Copyright 1999-2004 Gentoo Technologies, Inc.
* Distributed under the terms of the GNU General Public License v2
* $Header: /var/cvsroot/gentoo-projects/hardened/policycoreutils-extra/src/toggle_bool.c,v 1.2 2004/06/18 04:09:04 pebenito Exp $ */
#include <stdio.h>
#include <libgen.h>
#include <errno.h>
#include <selinux/selinux.h>
int main(int argc, char **argv) {
int rc, i, commit=0;
if(argc < 2) {
printf("Usage: %s boolname1 [boolname2 ...]\n",basename(argv[0]));
return 1;
}
for(i=1; i<argc; i++) {
printf("%s: ",argv[i]);
rc=security_get_boolean_active(argv[i]);
switch(rc) {
case 1:
if(security_set_boolean(argv[i],0) >= 0) {
printf("inactive\n");
commit++;
} else {
printf("%s\n",strerror(errno));
}
break;
case 0:
if(security_set_boolean(argv[i],1) >= 0) {
printf("active\n");
commit++;
} else {
printf("%s\n",strerror(errno));
}
break;
default:
if(errno==ENOENT)
printf("Boolean does not exist\n");
else
printf("%s\n",strerror(errno));
break;
}
}
if(commit > 0) {
if(security_commit_booleans() < 0) {
printf("Commit failed. (%s) No change to booleans.\n",strerror(errno));
return 1;
} else {
return 0;
}
} else {
return 1;
}
}