logo       

Choosing A Webhost:
A web hosting service is a type of Internet hosting service that allows individuals and organizations to provide their own website accessible via the World Wide Web. Web hosts are companies that provide space on a server they own for use by their clients as well as providing Internet connectivity, typically in a data center. Web hosts can also provide data center space and connectivity to the Internet for servers they do not own to be located in their data center, called colocation. more...

Re: Fedora and udev: msg#00171

Subject: Re: Fedora and udev
This is a multi-part message in MIME format.
Rewritten patch.

Dan
--- udev-030/udev-add.c.selinux 2004-08-25 16:47:52.000000000 -0400
+++ udev-030/udev-add.c 2004-08-26 07:59:42.007575846 -0400
@@ -50,6 +50,11 @@
 
 #define LOCAL_USER "$local"
 
+#ifdef WITH_SELINUX
+#include <selinux/selinux.h>
+static int selinux_enabled=-1;
+#endif
+
 /* 
  * Right now the major/minor of a device is stored in a file called
  * "dev" in sysfs.
@@ -92,7 +97,25 @@
                        break;
                *pos = 0x00;
                if (stat(p, &stats)) {
+#ifdef WITH_SELINUX
+                       if (selinux_enabled) {
+                               int seretval = 0;
+                               security_context_t scontext=NULL;
+                               seretval = matchpathcon(p, S_IFDIR, &scontext);
+                               if (seretval < 0) {
+                                       dbg("matchpathcon(%s) failed\n", p);
+                               } else {
+                                       seretval=setfscreatecon(scontext);
+                                       if (seretval < 0)
+                                               dbg("setfiles %s failed with 
error '%s'",
+                                                   p, strerror(errno));
+                                       /* after mkdir, free the context */
+                                       freecon(scontext);
+                               }
+                       }
+#endif
                        retval = mkdir(p, 0755);
+                                                                       
                        if (retval != 0) {
                                dbg("mkdir(%s) failed with error '%s'",
                                    p, strerror(errno));
@@ -117,6 +140,25 @@
        if (((stats.st_mode & S_IFMT) == S_IFBLK || (stats.st_mode & S_IFMT) == 
S_IFCHR) &&
            (stats.st_rdev == makedev(major, minor))) {
                dbg("preserve file '%s', cause it has correct dev_t", file);
+#ifdef WITH_SELINUX
+               /* lkcl: maybe someone would like to do the same thing with 
se/linux
+                * security contexts (check they are the same) but hey, not me!
+                */
+               if (selinux_enabled) {
+                       security_context_t scontext=NULL;
+                       retval = matchpathcon(file, mode, &scontext);
+                       if (retval < 0) {
+                               dbg("matchpathcon(%s) failed\n", file);
+                       } else {
+                               retval=setfilecon(file, scontext);
+                               if (retval < 0)
+                                       dbg("setfiles %s failed with error 
'%s'",
+                                           file, strerror(errno));
+                               freecon(scontext);
+                       }
+               }
+#endif
+
                if (udev_preserve_owner)
                  goto exit;
                else
@@ -129,6 +171,23 @@
                dbg("already present file '%s' unlinked", file);
 
 create:
+#ifdef WITH_SELINUX
+       if (selinux_enabled) {
+               int seretval = 0;
+               security_context_t scontext=NULL;
+               seretval = matchpathcon(file, mode, &scontext);
+               if (seretval < 0) {
+                       dbg("matchpathcon(%s) failed\n", file);
+               } else {
+                       retval=setfscreatecon(scontext);
+                       if (retval < 0)
+                               dbg("setfiles %s failed with error '%s'",
+                                   file, strerror(errno));
+                       freecon(scontext);
+               }
+       }
+#endif
+                                                   
        retval = mknod(file, mode, makedev(major, minor));
        if (retval != 0) {
                dbg("mknod(%s, %#o, %u, %u) failed with error '%s'",
@@ -307,6 +366,23 @@
 
                dbg("symlink(%s, %s)", linktarget, filename);
                if (!fake) {
+#ifdef WITH_SELINUX
+                       if (selinux_enabled) {
+                               int seretval = 0;
+                               security_context_t scontext=NULL;
+                               seretval = matchpathcon(filename, S_IFLNK, 
&scontext);
+                               if (seretval < 0) {
+                                       dbg("matchpathcon(%s) failed\n", 
filename);
+                               } else {
+                                       seretval=setfscreatecon(scontext);
+                                       if (seretval < 0)
+                                               dbg("setfscreatecon %s failed 
with error '%s'",
+                                                   filename, strerror(errno));
+                                       freecon(scontext);
+                               }
+                       }
+#endif
+                       
                        unlink(filename);
                        if (symlink(linktarget, filename) != 0)
                                dbg("symlink(%s, %s) failed with error '%s'",
@@ -406,6 +482,13 @@
        char *pos;
        int retval;
 
+#ifdef WITH_SELINUX
+       int seretval=0;
+       security_context_t prev_scontext=NULL;
+       if (selinux_enabled < 0 )
+               selinux_enabled = (is_selinux_enabled() > 0);
+#endif
+
        memset(&dev, 0x00, sizeof(dev));
 
        dev.type = get_device_type(path, subsystem);
@@ -441,6 +524,24 @@
 
        dbg("name='%s'", dev.name);
 
+#ifdef WITH_SELINUX
+       /* record the present security context, for file-creation
+        * restoration creation purposes.
+        *
+        * we're going to assume that between now and the time that
+        * this context is restored that the only filecreation of any
+        * kind to occur will be mknod, symlink and mkdirs.
+        */
+
+       if (selinux_enabled)
+       {
+               prev_scontext=NULL;
+               seretval = getfscreatecon(&prev_scontext);
+               if (seretval < 0) {
+                       dbg("getfscreatecon failed\n");
+               }
+       }
+#endif
        switch (dev.type) {
        case 'b':
        case 'c':
@@ -477,6 +578,17 @@
                break;
        }
 
+#ifdef WITH_SELINUX
+       if (selinux_enabled) {
+               /* reset the file create context to its former glory */
+               if (seretval == 0) {
+                       if ( setfscreatecon(prev_scontext) < 0 )
+                               dbg("setfscreatecon failed\n");
+                       freecon(prev_scontext);
+               }
+       }
+#endif
+
 exit:
        sysfs_close_class_device(class_dev);
 
--- udev-030/Makefile.selinux   2004-07-09 13:59:09.000000000 -0400
+++ udev-030/Makefile   2004-08-25 16:47:52.000000000 -0400
@@ -25,6 +25,8 @@
 # Leave this set to `false' for production use.
 DEBUG = false
 
+# Set this to compile with Security-Enhanced Linux support.
+WITH_SELINUX = true
 
 ROOT =         udev
 DAEMON =       udevd
@@ -172,6 +175,13 @@
 
 CFLAGS += -I$(PWD)/libsysfs
 
+ifeq ($(strip $(WITH_SELINUX)),true)
+       LIB_OBJS +=     \
+                       -lselinux
+       CFLAGS += \
+               -DWITH_SELINUX
+endif
+
 all: $(ROOT) $(SENDER) $(DAEMON) $(INFO) $(TESTER) $(STARTER)
        @extras="$(EXTRAS)" ; for target in $$extras ; do \
                echo $$target ; \

<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
qnx.openqnx.dev...    gcc.libstdc++.c...    solaris.opensol...    information-ret...    misc.misterhous...    web.catalyst.ge...    apache.webservi...    redhat.release....    hardware.lirc/2...    kernel.autofs/2...    technology.sust...    linux.vdr/2003-...    editors.lyx.gen...    org.user-groups...    netbsd.devel.pk...    xdg.devel/2004-...    version-control...    jakarta.slide.d...    debian.packages...    creativecommons...    ports.ppc.embed...    bug-tracking.bu...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe

Navigation