setfiles support for altroot
PATCH 1/1 setfiles support for altroot
This allows setfiles to label files in somewhere other than / as if they were in /, very useful for labeling off the live filesystem before installing. This is necessary for Gentoo to support SELinux, is it reasonable for it to be imported into CVS and included in the next nsa release? If there are any problems with it let me know (I really suck at C so there probably are problems)
Joshua Brindle
UNIX Administrator
Southern Nazarene University
setfiles/setfiles.c +28 -4
@@ -73,6 +73,7 @@#define FILE_CONTEXT "system_u:object_r:file_t"#define FS_CONTEXT "system_u:object_r:fs_t" +#define SZ 255static int flask_enabled =0 ;static int add_assoc =1 ;
@@ -89,6 +90,9 @@static int use_inum =0 ;static int quiet =0 ; + +static int useroot =0 ; +static char *rootpath; #define QPRINTF(args...) do { if (!quiet) printf(args); } while (0)/*
@@ -280,9 +284,23 @@ } -int match (const char *name,struct stat *sb,security_id_t *out_sid) +int match (const char *my_name,struct stat *sb,security_id_t *out_sid) {int i, ret; +const char *name; + +/* my_name will be the real file, getting labeled +* name will be what is matched in the policy */ + +if (useroot) { + i=0 ; + name=my_name; +while (rootpath[i] == my_name[i]) + i++; + name=&my_name[i]; + }else { + name=my_name; + }if (flask_enabled) { ret =lstat_secure (name, sb, out_sid);
@@ -417,7 +435,6 @@return ; } -#define SZ 255/* * Apply the last matching specification to a file.
@@ -577,7 +594,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 +621,10 @@case 'i' : use_inum =1 ;break ; +case 'r' : + rootpath = argv[optind++]; + useroot =1 ; +break ; } }
@@ -920,7 +943,10 @@else for (; optind < argc; optind++) { -if (flask_enabled) { +if (useroot) +QPRINTF ("%s: labeling files as if %s is /\n" ,argv[0 ],rootpath); + +if (flask_enabled) {QPRINTF ("%s: labeling files under %s\n" , argv[0 ], argv[optind]); }else {
Quoted 5 lines · Joshua Brindle
This allows setfiles to label files in somewhere other than / as if they were in /, very useful for labeling off the live filesystem before installing. This is necessary for Gentoo to support SELinux, is it reasonable for it to be imported into CVS and included in the next nsa release? If there are any problems with it let me know (I really suck at C so there probably are problems)
This sounds useful, but we may not get to reviewing it and merging it for a little bit; we're presently preoccupied with the reworking of SELinux for mainline 2.5.
Signature · 8 lines
Stephen Smalley <[email protected]> National Security Agency -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.