Second patch on systemd.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
This one is intended to handle labeling of directories if they do not exist. As well as add use_selinux() function to determine is selinux is enabled, and not do stuff if it is disabled.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.14 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/
iEUEARECAAYFAkxJoiUACgkQrlYvE4MpobNa5wCg2/i63NszDUOvHyhmMdyNkkNE JLcAmMAyIHNFOUWNrBqEuM7JaxjleLU=
=/UUh
-----END PGP SIGNATURE-----
src/main.c +12 -0
@@ -31,6 +31,7 @@#include <signal.h> #include <sys/wait.h> #include <fcntl.h> +#include <selinux/selinux.h> #include "manager.h" #include "log.h"
@@ -857,6 +858,14 @@ int main(int argc, char *argv[]) {if (mount_setup () <0 ) goto finish; +if (use_selinux ()) { + r =matchpathcon_init (NULL ); +if (r <0 &&security_getenforce () ==1 ) { +log_error ("Failed to initialize SELinux Context " ); + goto finish; + } + } +/* Reset all signal handlers. */ assert_se (reset_all_signal_handlers () ==0 );
@@ -1049,6 +1058,9 @@ int main(int argc, char *argv[]) { } finish: +if (use_selinux ()) +matchpathcon_fini (); +if (m)manager_free (m);
src/socket-util.c +3 -2
@@ -316,7 +316,7 @@ int socket_address_listen(if ((r =socket_address_verify (a)) <0 )return r; -if (setsockcreatecon (scon) <0 ) { +if (use_selinux () &&setsockcreatecon (scon) <0 ) {log_error ("Failed to set SELinux context (%s) on socket: %m" , scon);if (security_getenforce () ==1 )return -errno;
@@ -325,7 +325,8 @@ int socket_address_listen( fd =socket (socket_address_family (a), a->type |SOCK_NONBLOCK |SOCK_CLOEXEC ,0 ); r = fd <0 ? -errno :0 ; -setsockcreatecon (NULL ); +if (use_selinux ()) +setsockcreatecon (NULL );if (r <0 )return r;
src/socket.c +4 -3
@@ -711,8 +711,8 @@ static int fifo_address_create(mkdir_parents (path, directory_mode); -if (scon) { -if (scon && ((r =selinux_getfileconfrompath (scon, path,"fifo_file" , &filecon)) ==0 )) { +if (use_selinux () && scon) { +if (((r =selinux_getfileconfrompath (scon, path,"fifo_file" , &filecon)) ==0 )) { r =setfscreatecon (filecon);if (r <0 ) {
@@ -746,7 +746,8 @@ static int fifo_address_create( goto fail; } -setfscreatecon (NULL ); +if (use_selinux ()) +setfscreatecon (NULL );if (fstat (fd, &st) <0 ) { r = -errno;
src/util.c +43 -3
76 lines not on this page · raw message
src/util.h +2 -0
@@ -360,4 +360,6 @@ int ip_tos_from_string(const char *s);const char *signal_to_string (int i);int signal_from_string (const char *s); +int use_selinux (void ); +#endif
Quoted 6 lines · Daniel J Walsh
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1This one is intended to handle labeling of directories if they do not exist. As well as add
use_selinux()function to determine is selinux is enabled, and not do stuff if it is disabled.
selabel_open(), selabel_lookup(), and selabel_close() are preferred to using matchpathcon* in new code. We'd like to deprecate and remove matchpathcon*.
I'm not sure that we truly need to wrap all error handling with a check of security_getenforce(), as that is only for dealing with permission denials, not arbitrary errors that might occur (e.g. out of memory). Or if it is necessary, then I'd tend to take those code fragments (use_selinux() check, call to libselinux function, check error, check security_getenforce()) into wrapper functions so that you don't have to spread them all around the systemd code and your insertions into the systemd code can always just be a simple function call.
Signature · 8 lines
Stephen Smalley 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.