udev_selinux.c revision 8481f8ce2bd2b19ebcf3cb96ac6825093f626b0f
d657c51f14601d0235434ffb78cf6ac0f27cc83cLennart Poettering#include <stdlib.h>
220a21d38f675eb835f5758e3d23e896573aa5eaLennart Poettering#include <string.h>
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poettering#include <stdio.h>
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poettering#include <fcntl.h>
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poettering#include <unistd.h>
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poettering#include <errno.h>
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poettering#include <ctype.h>
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poettering#include <selinux/selinux.h>
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poettering
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poettering#include "udev.h"
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poettering#include "udev_version.h"
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poettering#include "udev_selinux.h"
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poettering#include "logging.h"
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poettering
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poettering
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poetteringvoid selinux_add_node(char *filename)
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poettering{
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poettering int retval;
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poettering
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poettering if (is_selinux_enabled() > 0) {
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poettering security_context_t scontext;
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poettering retval = matchpathcon(filename, 0, &scontext);
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poettering if (retval < 0) {
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poettering dbg("matchpathcon(%s) failed\n", filename);
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poettering } else {
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poettering retval=setfilecon(filename,scontext);
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poettering if (retval < 0)
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poettering dbg("setfiles %s failed with error '%s'",
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poettering filename, strerror(errno));
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poettering free(scontext);
28c85daf0ae80d1d5f8b878efa4bdad690e1f29bLennart Poettering }
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poettering }
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poettering}
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poettering
a11c7ea52cc31a8c95e46e781469d3a104f48090Lennart Poettering