[Pkg-shadow-commits] r3655 - in upstream/trunk: . lib libmisc po
Nicolas FRANÇOIS
nekral-guest at alioth.debian.org
Fri Dec 9 22:13:02 UTC 2011
Author: nekral-guest
Date: 2011-12-09 22:13:02 +0000 (Fri, 09 Dec 2011)
New Revision: 3655
Added:
upstream/trunk/lib/selinux.c
Modified:
upstream/trunk/ChangeLog
upstream/trunk/lib/Makefile.am
upstream/trunk/lib/commonio.c
upstream/trunk/lib/prototypes.h
upstream/trunk/libmisc/copydir.c
upstream/trunk/po/POTFILES.in
Log:
* lib/prototypes.h, lib/Makefile.am, po/POTFILES.in,
libmisc/copydir.c, lib/selinux.c: Move set_selinux_file_context()
and reset_selinux_file_context() from libmisc/copydir.c to
lib/selinux.c.
* lib/commonio.c: Use set_selinux_file_context() and
reset_selinux_file_context() instead of using the existing
database SELinux context to set the context for the newly created
files.
Modified: upstream/trunk/ChangeLog
===================================================================
--- upstream/trunk/ChangeLog 2011-12-09 21:35:57 UTC (rev 3654)
+++ upstream/trunk/ChangeLog 2011-12-09 22:13:02 UTC (rev 3655)
@@ -1,3 +1,14 @@
+2011-12-09 Peter Vrabec <pvrabec at redhat.com>
+
+ * lib/prototypes.h, lib/Makefile.am, po/POTFILES.in,
+ libmisc/copydir.c, lib/selinux.c: Move set_selinux_file_context()
+ and reset_selinux_file_context() from libmisc/copydir.c to
+ lib/selinux.c.
+ * lib/commonio.c: Use set_selinux_file_context() and
+ reset_selinux_file_context() instead of using the existing
+ database SELinux context to set the context for the newly created
+ files.
+
2011-12-09 Nicolas François <nicolas.francois at centraliens.net>
* src/vipw.c: Do not use a hardcoded program name in the usage
Modified: upstream/trunk/lib/Makefile.am
===================================================================
--- upstream/trunk/lib/Makefile.am 2011-12-09 21:35:57 UTC (rev 3654)
+++ upstream/trunk/lib/Makefile.am 2011-12-09 22:13:02 UTC (rev 3655)
@@ -39,6 +39,7 @@
pwio.c \
pwio.h \
pwmem.c \
+ selinux.c \
semanage.c \
sgetgrent.c \
sgetpwent.c \
Modified: upstream/trunk/lib/commonio.c
===================================================================
--- upstream/trunk/lib/commonio.c 2011-12-09 21:35:57 UTC (rev 3654)
+++ upstream/trunk/lib/commonio.c 2011-12-09 22:13:02 UTC (rev 3655)
@@ -45,9 +45,6 @@
#include <stdio.h>
#include <signal.h>
#include "nscd.h"
-#ifdef WITH_SELINUX
-#include <selinux/selinux.h>
-#endif /* WITH_SELINUX */
#ifdef WITH_TCB
#include <tcb.h>
#endif /* WITH_TCB */
@@ -652,15 +649,6 @@
/* Do not inherit fd in spawned processes (e.g. nscd) */
fcntl (fileno (db->fp), F_SETFD, FD_CLOEXEC);
-#ifdef WITH_SELINUX
- db->scontext = NULL;
- if ((is_selinux_enabled () > 0) && (!db->readonly)) {
- if (fgetfilecon (fileno (db->fp), &db->scontext) < 0) {
- goto cleanup_errno;
- }
- }
-#endif /* WITH_SELINUX */
-
buflen = BUFLEN;
buf = (char *) malloc (buflen);
if (NULL == buf) {
@@ -745,12 +733,6 @@
cleanup_errno:
saved_errno = errno;
free_linked_list (db);
-#ifdef WITH_SELINUX
- if (db->scontext != NULL) {
- freecon (db->scontext);
- db->scontext = NULL;
- }
-#endif /* WITH_SELINUX */
fclose (db->fp);
db->fp = NULL;
errno = saved_errno;
@@ -932,10 +914,6 @@
int errors = 0;
struct stat sb;
-#ifdef WITH_SELINUX
- /*@null@*/security_context_t old_context = NULL;
-#endif /* WITH_SELINUX */
-
if (!db->isopen) {
errno = EINVAL;
return 0;
@@ -959,23 +937,17 @@
db->fp = NULL;
goto fail;
}
-#ifdef WITH_SELINUX
- if (db->scontext != NULL) {
- if (getfscreatecon (&old_context) < 0) {
- errors++;
- goto fail;
- }
- if (setfscreatecon (db->scontext) < 0) {
- errors++;
- goto fail;
- }
- }
-#endif /* WITH_SELINUX */
+
/*
* Create backup file.
*/
snprintf (buf, sizeof buf, "%s-", db->filename);
+#ifdef WITH_SELINUX
+ if (set_selinux_file_context (buf) != 0) {
+ errors++;
+ }
+#endif
if (create_backup (buf, db->fp) != 0) {
errors++;
}
@@ -984,6 +956,11 @@
errors++;
}
+#ifdef WITH_SELINUX
+ if (reset_selinux_file_context () != 0) {
+ errors++;
+ }
+#endif
if (errors != 0) {
db->fp = NULL;
goto fail;
@@ -1040,19 +1017,6 @@
errors++;
success:
-#ifdef WITH_SELINUX
- if (db->scontext != NULL) {
- if (NULL != old_context) {
- if (setfscreatecon (old_context) < 0) {
- errors++;
- }
- freecon (old_context);
- old_context = NULL;
- }
- freecon (db->scontext);
- db->scontext = NULL;
- }
-#endif /* WITH_SELINUX */
free_linked_list (db);
return errors == 0;
}
Modified: upstream/trunk/lib/prototypes.h
===================================================================
--- upstream/trunk/lib/prototypes.h 2011-12-09 21:35:57 UTC (rev 3654)
+++ upstream/trunk/lib/prototypes.h 2011-12-09 22:13:02 UTC (rev 3655)
@@ -297,6 +297,10 @@
/* salt.c */
extern /*@observer@*/const char *crypt_make_salt (/*@null@*//*@observer@*/const char *meth, /*@null@*/void *arg);
+/* selinux.c */
+extern int set_selinux_file_context (const char *dst_name);
+extern int reset_selinux_file_context (void);
+
/* semanage.c */
extern int set_seuser(const char *login_name, const char *seuser_name);
extern int del_seuser(const char *login_name);
Added: upstream/trunk/lib/selinux.c
===================================================================
--- upstream/trunk/lib/selinux.c (rev 0)
+++ upstream/trunk/lib/selinux.c 2011-12-09 22:13:02 UTC (rev 3655)
@@ -0,0 +1,102 @@
+/*
+ * Copyright (c) 2011 , Peter Vrabec <pvrabec at redhat.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the copyright holders or contributors may not be used to
+ * endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <config.h>
+
+#ifdef WITH_SELINUX
+
+#include "defines.h"
+
+#include <selinux/selinux.h>
+
+
+static bool selinux_checked = false;
+static bool selinux_enabled;
+
+/*
+ * set_selinux_file_context - Set the security context before any file or
+ * directory creation.
+ *
+ * set_selinux_file_context () should be called before any creation
+ * of file, symlink, directory, ...
+ *
+ * Callers may have to Reset SELinux to create files with default
+ * contexts with reset_selinux_file_context
+ */
+int set_selinux_file_context (const char *dst_name)
+{
+ /*@null@*/security_context_t scontext = NULL;
+
+ if (!selinux_checked) {
+ selinux_enabled = is_selinux_enabled () > 0;
+ selinux_checked = true;
+ }
+
+ if (selinux_enabled) {
+ /* Get the default security context for this file */
+ if (matchpathcon (dst_name, 0, &scontext) < 0) {
+ if (security_getenforce () != 0) {
+ return 1;
+ }
+ }
+ /* Set the security context for the next created file */
+ if (setfscreatecon (scontext) < 0) {
+ if (security_getenforce () != 0) {
+ return 1;
+ }
+ }
+ freecon (scontext);
+ }
+ return 0;
+}
+
+/*
+ * reset_selinux_file_context - Reset the security context to the default
+ * policy behavior
+ *
+ * reset_selinux_file_context () should be called after the context
+ * was changed with set_selinux_file_context ()
+ */
+int reset_selinux_file_context (void)
+{
+ if (!selinux_checked) {
+ selinux_enabled = is_selinux_enabled () > 0;
+ selinux_checked = true;
+ }
+ if (selinux_enabled) {
+ if (setfscreatecon (NULL) != 0) {
+ return 1;
+ }
+ }
+ return 0;
+}
+
+#else /* !WITH_SELINUX */
+extern int errno; /* warning: ANSI C forbids an empty source file */
+#endif /* !WITH_SELINUX */
Modified: upstream/trunk/libmisc/copydir.c
===================================================================
--- upstream/trunk/libmisc/copydir.c 2011-12-09 21:35:57 UTC (rev 3654)
+++ upstream/trunk/libmisc/copydir.c 2011-12-09 22:13:02 UTC (rev 3655)
@@ -55,10 +55,6 @@
#include <attr/libattr.h>
#endif /* WITH_ATTR */
-#ifdef WITH_SELINUX
-static bool selinux_checked = false;
-static bool selinux_enabled;
-#endif /* WITH_SELINUX */
static /*@null@*/const char *src_orig;
static /*@null@*/const char *dst_orig;
@@ -112,66 +108,6 @@
uid_t old_uid, uid_t new_uid,
gid_t old_gid, gid_t new_gid);
-#ifdef WITH_SELINUX
-/*
- * set_selinux_file_context - Set the security context before any file or
- * directory creation.
- *
- * set_selinux_file_context () should be called before any creation
- * of file, symlink, directory, ...
- *
- * Callers may have to Reset SELinux to create files with default
- * contexts with reset_selinux_file_context
- */
-int set_selinux_file_context (const char *dst_name)
-{
- /*@null@*/security_context_t scontext = NULL;
-
- if (!selinux_checked) {
- selinux_enabled = is_selinux_enabled () > 0;
- selinux_checked = true;
- }
-
- if (selinux_enabled) {
- /* Get the default security context for this file */
- if (matchpathcon (dst_name, 0, &scontext) < 0) {
- if (security_getenforce () != 0) {
- return 1;
- }
- }
- /* Set the security context for the next created file */
- if (setfscreatecon (scontext) < 0) {
- if (security_getenforce () != 0) {
- return 1;
- }
- }
- freecon (scontext);
- }
- return 0;
-}
-
-/*
- * reset_selinux_file_context - Reset the security context to the default
- * policy behavior
- *
- * reset_selinux_file_context () should be called after the context
- * was changed with set_selinux_file_context ()
- */
-int reset_selinux_file_context (void)
-{
- if (!selinux_checked) {
- selinux_enabled = is_selinux_enabled () > 0;
- selinux_checked = true;
- }
- if (selinux_enabled) {
- if (setfscreatecon (NULL) != 0) {
- return 1;
- }
- }
- return 0;
-}
-#endif /* WITH_SELINUX */
-
#if defined(WITH_ACL) || defined(WITH_ATTR)
/*
* error_acl - format the error messages for the ACL and EQ libraries.
Modified: upstream/trunk/po/POTFILES.in
===================================================================
--- upstream/trunk/po/POTFILES.in 2011-12-09 21:35:57 UTC (rev 3654)
+++ upstream/trunk/po/POTFILES.in 2011-12-09 22:13:02 UTC (rev 3655)
@@ -17,6 +17,7 @@
lib/pwauth.c
lib/pwio.c
lib/pwmem.c
+lib/selinux.c
lib/semanage.c
lib/sgetgrent.c
lib/sgetpwent.c
More information about the Pkg-shadow-commits
mailing list