secon (Was: Policycoreutils patch)
Quoted 5 lines · Stephen Smalley
What is the purpose of the secon utility added by this patch? Assuming that it is useful, a few quick comments on the implementation:
- Themy_getXcon_rawfunctions should be moved into libselinux (without themy_prefix, of course) so that we don't need any code outside of libselinux directly reading/proc/pid/attrfiles.
Yes, I'd known about that ... I'll be providing changes for libselinux
in the next day or so.
The initial version with my_ functions was simply to make it easier for
others to be able to compile the code.
Quoted 9 lines
- Falling back to the current context when the exec or fscreate context is not set is not correct. Absence of exec or fscreate context just means that the default policy behavior (e.g.
type_transitionor default inheritance) will be applied. While default inheritance would mean that the current context is applied for exec, there could be atype_transition, and it makes no sense at all for fscreate (where default inheritance combines information from the current context with the parent directory context). I think you just want to report NULL / none or similar to the user.
I was wary of reporting just a blank, but it's a simple change to fix
that.
Quoted 3 lines
- The call to
selinux_trans_to_raw_context()doesn't make sense since you are already calling the_rawfunctions. Ifopt->disp_rawis set, then no further processing should be required, right?
If the context comes from the user (Ie. stdin or argument), we don't
know if the context is raw or translated. So we always convert. This allows:
id -Z | secon -R -
...to output the right thing.
The other thing we are looking at is what the default should be, Steve
Grubb suggested that reading from stdin should be it ... but I don't like that from a UI POV and that most cases are better handled otherwise (Ie. ls -Z is never going to be parsable, IMO, so secon -f is much better).
Signature · 6 lines
James Antill <[email protected]> -- James Antill <[email protected]>
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 7 lines · Stephen Smalley
Quoted 2 lines · James Antill
This is due to
context_new(), can I fix this inside that function (Ie.
don't fail out when the passed value == "")?Seems like the caller should handle it instead. "" isn't a valid context, after all.
Fair enough.
Quoted 2 lines
BTW, working off the sourceforge selinux subversion tree is preferred, svn co https://svn.sourceforge.net/svnroot/selinux/trunk selinux-usr
Ok, I can do that :).
Quoted 2 lines
Note that we update the ChangeLog and VERSION files ourselves upon merging patches, no need to touch those.
Ok, here's the latest changes for secon. It's the above fixes and man
pages changes with sensitivity/clearance naming changes. Also a couple of typos.
I've also re-included the policycoreutils change for setfiles, against
the selinux svn tree.
Signature · 1 line
James Antill <[email protected]>
secon/secon.1 +6 -3
@@ -3,7 +3,7 @@ secon \- See a context, from a file, program or user input. .SH SYNOPSIS .B secon -[\fB-hVurtlmPRfLp\fR] +[\fB-hVurtscmPRfLp\fR] [\fICONTEXT\fR] .br [\fB--file\fR]
@@ -39,11 +39,14 @@ \fB\-t\fR, \fB\-\-type\fR show the type of the security context .TP -\fB\-l\fR, \fB\-\-level\fR +\fB\-s\fR, \fB\-\-sensitivity\fR show the sensitivity level of the security context .TP +\fB\-c\fR, \fB\-\-clearance\fR +show the clearance level of the security context +.TP \fB\-m\fR, \fB\-\-mls-range\fR -show the sensitivity level and clearance of the security context +show the sensitivity level and clearance, as a range, of the security context .TP \fB\-R\fR, \fB\-\-raw\fR outputs the sensitivity level and clearance in an untranslated format.
secon/secon.c +72 -33
181 lines not on this page · raw message
setfiles/setfiles.c +36 -2
@@ -75,7 +75,12 @@#include <selinux/selinux.h> #include <syslog.h> #include <libgen.h> +#include <libaudit.h> +#ifndef AUDIT_FS_RELABEL +#define AUDIT_FS_RELABEL 2309 +#endif +static int add_assoc =1 ;static FILE *outfile=NULL ;static int force=0 ;
@@ -395,7 +400,7 @@/* trim trailing /, if present */ len =strlen (rootpath); -while ('/' == rootpath[len -1 ]) +while (len && ('/' == rootpath[len -1 ])) rootpath[--len] =0 ; rootpathlen = len; }
@@ -443,11 +448,35 @@return 0 ; } +static void maybe_audit_mass_relabel (int done_root,int errs) +{ +int audit_fd =-1 ; +int rc =0 ; + +if (!done_root)/* only audit a forced full relabel */ +return ; + + audit_fd =audit_open (); + +if (audit_fd <0 ) { +fprintf (stderr,"Error connecting to audit system.\n" ); +return ; + } + + rc =audit_log_user_message (audit_fd,AUDIT_FS_RELABEL , +"op=mass relabel" ,NULL ,NULL ,NULL , !errs); +if (rc <=0 ) { +fprintf (stderr,"Error sending audit message: %s.\n" ,strerror (errno)); + } +audit_close (audit_fd); +} +int main (int argc,char **argv) {struct stat sb;int opt, rc, i; - +int done_root =0 ;/* have we processed the / directory as an arg */ +memset (excludeArray,0 ,sizeof (excludeArray));/* Validate all file contexts during matchpathcon_init. */
@@ -618,6 +647,8 @@ }else for (; optind < argc; optind++) { + done_root |= !strcmp (argv[optind],"/" ); +if (NULL != rootpath) {qprintf ("%s: labeling files, pretending %s is /\n" , argv[0 ], rootpath);
@@ -648,6 +679,7 @@fprintf (stderr,"%s: error while labeling files under %s\n" , argv[0 ], argv[optind]); +maybe_audit_mass_relabel (done_root,1 );exit (1 ); } }
@@ -664,6 +696,8 @@matchpathcon_filespec_destroy (); } +maybe_audit_mass_relabel (done_root,0 ); +if (warn_no_match)matchpathcon_checkmatches (argv[0 ]);
setfiles/Makefile +1 -0
@@ -7,6 +7,7 @@ CFLAGS = -Werror -Wall -W override CFLAGS += -D_FILE_OFFSET_BITS=64 -I$(PREFIX)/include LDLIBS = -lselinux -lsepol -L$(LIBDIR) +LDLIBS += -laudit all: setfiles