These two patches allow restorecond to use same code as setfiles/restorecon.
First patch rearranges setfiles code separating out shared code into a new c program called restore.c This program will be linked against restorecond and setfiles.
Second patch changes restorecond to use the separated out code and also Allows restorecond to run as a user process, rather then as a system service. So it can run within the user session watching for file creations in the homedir.
policycoreutils/setfiles/restore.c +96 -5
@@ -1,4 +1,5 @@#include "restore.h" +#include <glob.h> #define SKIP -2#define ERR -1
@@ -31,7 +32,6 @@ struct edir {static file_spec_t *fl_head; -static int exclude (const char *file);static int filespec_add (ino_t ino,const security_context_t con,const char *file);static int only_changed_user (const char *a,const char *b);struct restore_opts *r_opts =NULL ;
@@ -53,7 +53,6 @@ void remove_exclude(const char *directory) } }return ; - }void restore_init (struct restore_opts *opts)
@@ -300,8 +299,14 @@ static int process_one(char *name, int recurse_this_path)int rc =0 ;const char *namelist[2 ] = {name,NULL };dev_t dev_num =0 ; -FTS *fts_handle; -FTSENT *ftsent; +FTS *fts_handle =NULL ; +FTSENT *ftsent =NULL ; + +if (r_opts ==NULL ){ +fprintf (stderr, +"Must call initialize first!" ); + goto err; + } fts_handle =fts_open ((char **)namelist, r_opts->fts_flags,NULL );if (fts_handle ==NULL ) {
@@ -357,6 +362,29 @@ err: goto out; } +int process_glob (char *name,int recurse) { +glob_t globbuf; +size_t i =0 ; +int errors =0 ; +memset (&globbuf,0 ,sizeof (globbuf)); + globbuf.gl_offs =0 ; +if (glob (name, +GLOB_TILDE |GLOB_PERIOD , +NULL , + &globbuf) >=0 ) { +for (i =0 ; i < globbuf.gl_pathc; i++) { +int len =strlen (globbuf.gl_pathv[i]) -2 ; +if (len >0 &&strcmp (&globbuf.gl_pathv[i][len--],"/." ) ==0 )continue ; +if (len >0 &&strcmp (&globbuf.gl_pathv[i][len],"/.." ) ==0 )continue ; + errors |=process_one_realpath (globbuf.gl_pathv[i], recurse) <0 ; + } +globfree (&globbuf); + } +else + errors |=process_one_realpath (name, recurse) <0 ; +return errors; +} +int process_one_realpath (char *name,int recurse) {int rc =0 ;
@@ -374,6 +402,7 @@ int process_one_realpath(char *name, int recurse) }else { rc =lstat (name, &sb);if (rc <0 ) { +if (r_opts->ignore_enoent && errno ==ENOENT )return 0 ;fprintf (stderr,"%s: lstat(%s) failed: %s\n" , r_opts->progname, name,strerror (errno));return -1 ;
@@ -409,7 +438,7 @@ int process_one_realpath(char *name, int recurse) } } -static int exclude (const char *file) +int exclude (const char *file) {int i =0 ;for (i =0 ; i < excludeCtr; i++) {
@@ -602,5 +631,67 @@ static int filespec_add(ino_t ino, const security_context_t con, const char *filreturn -1 ; } +#include <sys/utsname.h> +/* +Search /proc/mounts for all file systems that do not support extended +attributes and add them to the exclude directory table. File systems +that support security labels have the seclabel option. +*/ +void exclude_non_seclabel_mounts () +{ +struct utsname uts; +FILE *fp; +size_t len; +ssize_t num; +int index =0 , found =0 ; +char *mount_info[4 ]; +char *buf =NULL , *item; + +/* Check to see if the kernel supports seclabel */ +if (uname (&uts) ==0 &&strverscmp (uts.release,"2.6.30" ) <0 ) +return ; +if (is_selinux_enabled () <=0 ) +return ; + + fp =fopen ("/proc/mounts" ,"r" ); +if (!fp) +return ; + +while ((num =getline (&buf, &len, fp)) !=-1 ) { + found =0 ; + index =0 ; + item =strtok (buf," " ); +while (item !=NULL ) { + mount_info[index] = item; +if (index ==3 ) +break ; + index++; + item =strtok (NULL ," " ); + } +if (index <3 ) { +fprintf (stderr, +"/proc/mounts record \"%s\" has incorrect format.\n" , + buf); +continue ; + } +/* remove pre-existing entry */ +remove_exclude (mount_info[1 ]); + + item =strtok (mount_info[3 ],"," ); +while (item !=NULL ) { +if (strcmp (item,"seclabel" ) ==0 ) { + found =1 ; +break ; + } + item =strtok (NULL ,"," ); + } + +/* exclude mount points without the seclabel option */ +if (!found) +add_exclude (mount_info[1 ]); + } + +free (buf); +}
policycoreutils/setfiles/restore.h +4 -0
@@ -27,6 +27,7 @@ struct restore_opts {int hard_links;int verbose;int logging; +int ignore_enoent;char *rootpath;int rootpathlen;char *progname;
@@ -44,7 +45,10 @@ struct restore_opts {void restore_init (struct restore_opts *opts);void restore_finish ();int add_exclude (const char *directory); +int exclude (const char *path);void remove_exclude (const char *directory);int process_one_realpath (char *name,int recurse); +int process_glob (char *name,int recurse); +void exclude_non_seclabel_mounts ();#endif
policycoreutils/setfiles/restorecon.8 +5 -2
@@ -4,10 +4,10 @@ restorecon \- restore file(s) default SELinux security contexts. .SH "SYNOPSIS" .B restorecon -.I [\-o outfilename ] [\-R] [\-n] [\-v] [\-e directory ] pathname... +.I [\-o outfilename ] [\-R] [\-n] [\-p] [\-v] [\-e directory ] pathname... .P .B restorecon -.I \-f infilename [\-o outfilename ] [\-e directory ] [\-R] [\-n] [\-v] [\-F] +.I \-f infilename [\-o outfilename ] [\-e directory ] [\-R] [\-n] [\-p] [\-v] [\-F] .SH "DESCRIPTION" This manual page describes the
@@ -40,6 +40,9 @@ don't change any file labels. .TP .B \-o outfilename save list of files with incorrect context in outfilename. +.TP +.B \-p +show progress by printing * every 1000 files. .TP .B \-v show changes in file labels.
policycoreutils/setfiles/setfiles.8 +3 -0
@@ -31,6 +31,9 @@ log changes in file labels to syslog. .TP .B \-n don't change any file labels. +.TP +.B \-p +show progress by printing * every 1000 files. .TP .B \-q suppress non-error output.
policycoreutils/setfiles/setfiles.c +7 -71
131 lines not on this page · raw message
policycoreutils/restorecond/Makefile +20 -4
@@ -1,17 +1,28 @@ # Installation directories. PREFIX ?= ${DESTDIR}/usr SBINDIR ?= $(PREFIX)/sbin +LIBDIR ?= $(PREFIX)/lib MANDIR = $(PREFIX)/share/man +AUTOSTARTDIR = $(DESTDIR)/etc/xdg/autostart +DBUSSERVICEDIR = $(DESTDIR)/usr/share/dbus-1/services + +autostart_DATA = sealertauto.desktop INITDIR = $(DESTDIR)/etc/rc.d/init.d SELINUXDIR = $(DESTDIR)/etc/selinux +DBUSFLAGS = -DHAVE_DBUS -I/usr/include/dbus-1.0 -I/usr/lib64/dbus-1.0/include -I/usr/lib/dbus-1.0/include +DBUSLIB = -ldbus-glib-1 -ldbus-1 + CFLAGS ?= -g -Werror -Wall -W -override CFLAGS += -I$(PREFIX)/include -D_FILE_OFFSET_BITS=64 -LDLIBS += -lselinux -L$(PREFIX)/lib +override CFLAGS += -I$(PREFIX)/include $(DBUSFLAGS) -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/lib/glib-2.0/include + +LDLIBS += -lselinux $(DBUSLIB) -lglib-2.0 -L$(LIBDIR) all: restorecond -restorecond: restorecond.o utmpwatcher.o stringslist.o +restorecond.o utmpwatcher.o stringslist.o user.o watch.o: restorecond.h + +restorecond: ../setfiles/restore.o restorecond.o utmpwatcher.o stringslist.o user.o watch.o $(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS) install: all
@@ -22,7 +33,12 @@ install: all -mkdir -p $(INITDIR) install -m 755 restorecond.init $(INITDIR)/restorecond -mkdir -p $(SELINUXDIR) - install -m 600 restorecond.conf $(SELINUXDIR)/restorecond.conf + install -m 644 restorecond.conf $(SELINUXDIR)/restorecond.conf + install -m 644 restorecond_user.conf $(SELINUXDIR)/restorecond_user.conf + -mkdir -p $(AUTOSTARTDIR) + install -m 644 restorecond.desktop $(AUTOSTARTDIR)/restorecond.desktop + -mkdir -p $(DBUSSERVICEDIR) + install -m 600 org.selinux.Restorecond.service $(DBUSSERVICEDIR)/org.selinux.Restorecond.service relabel: install /sbin/restorecon $(SBINDIR)/restorecond
policycoreutils/restorecond/restorecond.8 +12 -3
@@ -3,7 +3,7 @@ restorecond \- daemon that watches for file creation and then sets the default SELinux file context .SH "SYNOPSIS" -.B restorecond [\-d] +.B restorecond [\-d] [\-f restorecond_file ] [\-u] [\-v] .P .SH "DESCRIPTION"
@@ -19,13 +19,22 @@ the correct file context associated with the policy. .B \-d Turns on debugging mode. Application will stay in the foreground and lots of debugs messages start printing. +.TP +.B \-f restorecond_file +Use alternative restorecond.conf file. +.TP +.B \-u +Turns on user mode. Runs restorecond in the user session and reads /etc/selinux/restorecond_user.conf. Uses dbus to make sure only one restorecond is running per user session. +.TP +.B \-v +Turns on verbose debugging. (Report missing files) .SH "AUTHOR" -This man page was written by Dan Walsh <[email protected]>. -The program was written by Dan Walsh <[email protected]>. +This man page and program was written by Dan Walsh <[email protected]>. .SH "FILES" /etc/selinux/restorecond.conf +/etc/selinux/restorecond_user.conf .SH "SEE ALSO" .BR restorecon (8),
policycoreutils/restorecond/restorecond.c +79 -350
501 lines not on this page · raw message
policycoreutils/restorecond/restorecond.conf +1 -4
@@ -4,8 +4,5 @@ /etc/mtab /var/run/utmp /var/log/wtmp -~/* -/root/.ssh +/root/* /root/.ssh/* - -
policycoreutils/restorecond/restorecond.h +17 -2
@@ -24,7 +24,22 @@#ifndef RESTORED_CONFIG_H #define RESTORED_CONFIG_H -void exitApp (const char *msg); -void watch_list_add (int inotify_fd,const char *path); +extern int debug_mode; +extern const char *homedir; +extern int terminate; +extern int master_wd; +extern int run_as_user; + +extern int start (void ); +extern int server (int ,const char *watch_file); + +extern void exitApp (const char *msg); +extern void read_config (int fd,const char *watch_file); + +extern int watch (int fd,const char *watch_file); +extern void watch_list_add (int inotify_fd,const char *path); +extern int watch_list_find (int wd,const char *file); +extern void watch_list_free (int fd); +extern int watch_list_isempty ();#endif
policycoreutils/restorecond/restorecond.init +2 -3
@@ -75,16 +75,15 @@ case "$1" in status restorecond RETVAL=$? ;; - restart|reload) + force-reload|restart|reload) restart ;; condrestart) [ -e /var/lock/subsys/restorecond ] && restart || : ;; *) - echo $"Usage: $0 {start|stop|restart|reload|condrestart}" + echo $"Usage: $0 {start|stop|restart|force-reload|status|condrestart}" RETVAL=3 esac exit $RETVAL -
Quoted 8 lines · Daniel J Walsh
First patch rearranges setfiles code separating out shared code into a new c program called
restore.c
This program will be linked against restorecond and setfiles.Second patch changes restorecond to use the separated out code and also Allows restorecond to run as a user process, rather then as a system service. So it can run within the user session watching for file creations in the homedir.
Can it still run as a system process after this patch?
Signature · 13 lines
Chris PeBenito <[email protected]> Developer, Hardened 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 -- 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.
Quoted 6 lines · Chris PeBenito
Quoted 4 lines · Daniel J Walsh
First patch rearranges setfiles code separating out shared code into a new c program called
restore.c
This program will be linked against restorecond and setfiles.
Quoted 8 lines
Quoted 5 lines
Second patch changes restorecond to use the separated out code and also Allows restorecond to run as a user process, rather then as a system service. So it can run within the user session watching for file creations in the homedir.
Can it still run as a system process after this patch?
Yes.
restorecond -u versus restorcond.
--
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.
Quoted 10 lines · Daniel J Walsh
Quoted 9 lines · Chris PeBenito
Quoted 8 lines · Daniel J Walsh
First patch rearranges setfiles code separating out shared code into a new c program called
restore.c
This program will be linked against restorecond and setfiles.Second patch changes restorecond to use the separated out code and also Allows restorecond to run as a user process, rather then as a system service. So it can run within the user session watching for file creations in the homedir.
Quoted 6 lines
Quoted 2 lines
Can it still run as a system process after this patch?
Yes.
restorecond -u versus restorcond.
It won't build without libdbus on the system though, which may be what Chris' concern is.
--
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.