Blame SOURCES/krb5-1.13-selinux-label.patch

5af5b2
SELinux bases access to files on the domain of the requesting process,
5af5b2
the operation being performed, and the context applied to the file.
5af5b2
5af5b2
In many cases, applications needn't be SELinux aware to work properly,
5af5b2
because SELinux can apply a default label to a file based on the label
5af5b2
of the directory in which it's created.
5af5b2
5af5b2
In the case of files such as /etc/krb5.keytab, however, this isn't
5af5b2
sufficient, as /etc/krb5.keytab will almost always need to be given a
5af5b2
label which differs from that of /etc/issue or /etc/resolv.conf.  The
5af5b2
the kdb stash file needs a different label than the database for which
5af5b2
it's holding a master key, even though both typically live in the same
5af5b2
directory.
5af5b2
5af5b2
To give the file the correct label, we can either force a "restorecon"
5af5b2
call to fix a file's label after it's created, or create the file with
5af5b2
the right label, as we attempt to do here.  We lean on THREEPARAMOPEN
5af5b2
and define a similar macro named WRITABLEFOPEN with which we replace
5af5b2
several uses of fopen().
5af5b2
5af5b2
The file creation context that we're manipulating here is a process-wide
5af5b2
attribute.  While for the most part, applications which need to label
5af5b2
files when they're created have tended to be single-threaded, there's
5af5b2
not much we can do to avoid interfering with an application that
5af5b2
manipulates the creation context directly.  Right now we're mediating
5af5b2
access using a library-local mutex, but that can only work for consumers
5af5b2
that are part of this package -- an unsuspecting application will still
5af5b2
stomp all over us.
5af5b2
5af5b2
The selabel APIs for looking up the context should be thread-safe (per
5af5b2
Red Hat #273081), so switching to using them instead of matchpathcon(),
5af5b2
which we used earlier, is some improvement.
5af5b2
5af5b2
--- krb5/src/aclocal.m4
5af5b2
+++ krb5/src/aclocal.m4
5af5b2
@@ -103,6 +103,7 @@ AC_SUBST_FILE(libnodeps_frag)
5af5b2
 dnl
5af5b2
 KRB5_AC_PRAGMA_WEAK_REF
5af5b2
 WITH_LDAP
5af5b2
+KRB5_WITH_SELINUX
5af5b2
 KRB5_LIB_PARAMS
5af5b2
 KRB5_AC_INITFINI
5af5b2
 KRB5_AC_ENABLE_THREADS
5af5b2
@@ -1791,3 +1792,51 @@ AC_SUBST(manlocalstatedir)
5af5b2
 AC_SUBST(PAM_MAN)
5af5b2
 AC_SUBST(NON_PAM_MAN)
5af5b2
 ])dnl
5af5b2
+dnl
5af5b2
+dnl Use libselinux to set file contexts on newly-created files.
5af5b2
+dnl 
5af5b2
+AC_DEFUN(KRB5_WITH_SELINUX,[
5af5b2
+AC_ARG_WITH(selinux,[AC_HELP_STRING(--with-selinux,[compile with SELinux labeling support])],
5af5b2
+           withselinux="$withval",withselinux=auto)
5af5b2
+old_LIBS="$LIBS"
5af5b2
+if test "$withselinux" != no ; then
5af5b2
+       AC_MSG_RESULT([checking for libselinux...])
5af5b2
+       SELINUX_LIBS=
5af5b2
+       AC_CHECK_HEADERS(selinux/selinux.h selinux/label.h)
5af5b2
+       if test "x$ac_cv_header_selinux_selinux_h" != xyes ; then
5af5b2
+               if test "$withselinux" = auto ; then
5af5b2
+                       AC_MSG_RESULT([Unable to locate selinux/selinux.h.])
5af5b2
+                       withselinux=no
5af5b2
+               else
5af5b2
+                       AC_MSG_ERROR([Unable to locate selinux/selinux.h.])
5af5b2
+               fi
5af5b2
+       fi
5af5b2
+
5af5b2
+       LIBS=
5af5b2
+       unset ac_cv_func_setfscreatecon
5af5b2
+       AC_CHECK_FUNCS(setfscreatecon selabel_open)
5af5b2
+       if test "x$ac_cv_func_setfscreatecon" = xno ; then
5af5b2
+               AC_CHECK_LIB(selinux,setfscreatecon)
5af5b2
+               unset ac_cv_func_setfscreatecon
5af5b2
+               AC_CHECK_FUNCS(setfscreatecon selabel_open)
5af5b2
+               if test "x$ac_cv_func_setfscreatecon" = xyes ; then
5af5b2
+                       SELINUX_LIBS="$LIBS"
5af5b2
+               else
5af5b2
+                       if test "$withselinux" = auto ; then
5af5b2
+                               AC_MSG_RESULT([Unable to locate libselinux.])
5af5b2
+                               withselinux=no
5af5b2
+                       else
5af5b2
+                               AC_MSG_ERROR([Unable to locate libselinux.])
5af5b2
+                       fi
5af5b2
+               fi
5af5b2
+       fi
5af5b2
+       if test "$withselinux" != no ; then
5af5b2
+               AC_MSG_NOTICE([building with SELinux labeling support])
5af5b2
+               AC_DEFINE(USE_SELINUX,1,[Define if Kerberos-aware tools should set SELinux file contexts when creating files.])
5af5b2
+               SELINUX_LIBS="$LIBS"
5af5b2
+		EXTRA_SUPPORT_SYMS="$EXTRA_SUPPORT_SYMS krb5int_labeled_open krb5int_labeled_fopen krb5int_push_fscreatecon_for krb5int_pop_fscreatecon"
5af5b2
+       fi
5af5b2
+fi
5af5b2
+LIBS="$old_LIBS"
5af5b2
+AC_SUBST(SELINUX_LIBS)
5af5b2
+])dnl
5af5b2
--- krb5/src/config/pre.in
5af5b2
+++ krb5/src/config/pre.in
5af5b2
@@ -180,6 +180,7 @@ LD_UNRESOLVED_PREFIX = @LD_UNRESOLVED_PREFIX@
4be148
 KRB_INCLUDES = -I$(BUILDTOP)/include -I$(top_srcdir)/include
4be148
 LDFLAGS = @LDFLAGS@
5af5b2
 LIBS = @LIBS@
5af5b2
+SELINUX_LIBS=@SELINUX_LIBS@
5af5b2
 
5af5b2
 INSTALL=@INSTALL@
5af5b2
 INSTALL_STRIP=
5af5b2
@@ -379,7 +380,7 @@ SUPPORT_LIB			= -l$(SUPPORT_LIBNAME)
5af5b2
 # HESIOD_LIBS is -lhesiod...
5af5b2
 HESIOD_LIBS	= @HESIOD_LIBS@
5af5b2
 
5af5b2
-KRB5_BASE_LIBS	= $(KRB5_LIB) $(K5CRYPTO_LIB) $(COM_ERR_LIB) $(SUPPORT_LIB) $(GEN_LIB) $(LIBS) $(DL_LIB)
5af5b2
+KRB5_BASE_LIBS	= $(KRB5_LIB) $(K5CRYPTO_LIB) $(COM_ERR_LIB) $(SUPPORT_LIB) $(GEN_LIB) $(LIBS) $(SELINUX_LIBS) $(DL_LIB)
5af5b2
 KDB5_LIBS	= $(KDB5_LIB) $(GSSRPC_LIBS)
5af5b2
 GSS_LIBS	= $(GSS_KRB5_LIB)
5af5b2
 # needs fixing if ever used on Mac OS X!
5af5b2
--- krb5/src/configure.in
5af5b2
+++ krb5/src/configure.in
5af5b2
@@ -1053,6 +1053,8 @@ fi
5af5b2
 
5af5b2
 KRB5_WITH_PAM
5af5b2
 
5af5b2
+KRB5_WITH_SELINUX
5af5b2
+
5af5b2
 # Make localedir work in autoconf 2.5x.
5af5b2
 if test "${localedir+set}" != set; then
5af5b2
     localedir='$(datadir)/locale'
5af5b2
--- krb5/src/include/k5-int.h
5af5b2
+++ krb5/src/include/k5-int.h
01ee0a
@@ -129,6 +129,7 @@ typedef unsigned char   u_char;
5af5b2
 
01ee0a
 
01ee0a
 #include "k5-platform.h"
5af5b2
+#include "k5-label.h"
5af5b2
 
4be148
 #define KRB5_KDB_MAX_LIFE       (60*60*24) /* one day */
4be148
 #define KRB5_KDB_MAX_RLIFE      (60*60*24*7) /* one week */
5af5b2
--- krb5/src/include/k5-label.h
5af5b2
+++ krb5/src/include/k5-label.h
5af5b2
@@ -0,0 +1,32 @@
5af5b2
+#ifndef _KRB5_LABEL_H
5af5b2
+#define _KRB5_LABEL_H
5af5b2
+
5af5b2
+#ifdef THREEPARAMOPEN
5af5b2
+#undef THREEPARAMOPEN
5af5b2
+#endif
5af5b2
+#ifdef WRITABLEFOPEN
5af5b2
+#undef WRITABLEFOPEN
5af5b2
+#endif
5af5b2
+
5af5b2
+/* Wrapper functions which help us create files and directories with the right
5af5b2
+ * context labels. */
5af5b2
+#ifdef USE_SELINUX
5af5b2
+#include <sys/types.h>
5af5b2
+#include <sys/stat.h>
5af5b2
+#include <fcntl.h>
5af5b2
+#include <stdio.h>
5af5b2
+#include <unistd.h>
5af5b2
+FILE *krb5int_labeled_fopen(const char *path, const char *mode);
5af5b2
+int krb5int_labeled_creat(const char *path, mode_t mode);
5af5b2
+int krb5int_labeled_open(const char *path, int flags, ...);
5af5b2
+int krb5int_labeled_mkdir(const char *path, mode_t mode);
5af5b2
+int krb5int_labeled_mknod(const char *path, mode_t mode, dev_t device);
5af5b2
+#define THREEPARAMOPEN(x,y,z) krb5int_labeled_open(x,y,z)
5af5b2
+#define WRITABLEFOPEN(x,y) krb5int_labeled_fopen(x,y)
5af5b2
+void *krb5int_push_fscreatecon_for(const char *pathname);
5af5b2
+void krb5int_pop_fscreatecon(void *previous);
5af5b2
+#else
5af5b2
+#define WRITABLEFOPEN(x,y) fopen(x,y)
5af5b2
+#define THREEPARAMOPEN(x,y,z) open(x,y,z)
5af5b2
+#endif
5af5b2
+#endif
5af5b2
--- krb5/src/include/krb5/krb5.hin
5af5b2
+++ krb5/src/include/krb5/krb5.hin
5af5b2
@@ -87,6 +87,12 @@
5af5b2
 #define THREEPARAMOPEN(x,y,z) open(x,y,z)
5af5b2
 #endif
5af5b2
 
5af5b2
+#if KRB5_PRIVATE
5af5b2
+#ifndef WRITABLEFOPEN
5af5b2
+#define WRITABLEFOPEN(x,y) fopen(x,y)
5af5b2
+#endif
5af5b2
+#endif
5af5b2
+
5af5b2
 #define KRB5_OLD_CRYPTO
5af5b2
 
5af5b2
 #include <stdlib.h>
5af5b2
--- krb5/src/kadmin/dbutil/dump.c
5af5b2
+++ krb5/src/kadmin/dbutil/dump.c
5af5b2
@@ -376,12 +376,21 @@ create_ofile(char *ofile, char **tmpname
5af5b2
 {
5af5b2
     int fd = -1;
5af5b2
     FILE *f;
5af5b2
+#ifdef USE_SELINUX
5af5b2
+    void *selabel;
5af5b2
+#endif
5af5b2
 
5af5b2
     *tmpname = NULL;
5af5b2
     if (asprintf(tmpname, "%s-XXXXXX", ofile) < 0)
5af5b2
         goto error;
5af5b2
 
5af5b2
+#ifdef USE_SELINUX
5af5b2
+    selabel = krb5int_push_fscreatecon_for(ofile);
5af5b2
+#endif
5af5b2
     fd = mkstemp(*tmpname);
5af5b2
+#ifdef USE_SELINUX
5af5b2
+    krb5int_pop_fscreatecon(selabel);
5af5b2
+#endif
5af5b2
     if (fd == -1)
5af5b2
         goto error;
5af5b2
 
5af5b2
@@ -514,7 +514,7 @@ prep_ok_file(krb5_context context, char
5af5b2
         return 0;
5af5b2
     }
5af5b2
 
5af5b2
-    *fd = open(file_ok, O_WRONLY | O_CREAT | O_TRUNC, 0600);
5af5b2
+    *fd = THREEPARAMOPEN(file_ok, O_WRONLY | O_CREAT | O_TRUNC, 0600);
5af5b2
     if (*fd == -1) {
5af5b2
         com_err(progname, errno, _("while creating 'ok' file, '%s'"), file_ok);
5af5b2
         exit_status++;
4be148
--- krb5/src/build-tools/krb5-config.in
4be148
+++ krb5/src/build-tools/krb5-config.in
5af5b2
@@ -38,6 +38,7 @@ RPATH_FLAG='@RPATH_FLAG@'
5af5b2
 DEFCCNAME='@DEFCCNAME@'
5af5b2
 DEFKTNAME='@DEFKTNAME@'
5af5b2
 DEFCKTNAME='@DEFCKTNAME@'
5af5b2
+SELINUX_LIBS='@SELINUX_LIBS@'
5af5b2
 
5af5b2
 LIBS='@LIBS@'
5af5b2
 GEN_LIB=@GEN_LIB@
5af5b2
@@ -218,7 +219,7 @@
5af5b2
     fi
5af5b2
 
5af5b2
     # If we ever support a flag to generate output suitable for static
5af5b2
-    # linking, we would output "-lkrb5support $GEN_LIB $LIBS $DL_LIB"
5af5b2
+    # linking, we would output "-lkrb5support $GEN_LIB $LIBS $SELINUX_LIBS $DL_LIB"
5af5b2
     # here.
5af5b2
 
5af5b2
     echo $lib_flags
5af5b2
--- krb5/src/lib/kadm5/logger.c
5af5b2
+++ krb5/src/lib/kadm5/logger.c
5af5b2
@@ -425,7 +425,7 @@ krb5_klog_init(krb5_context kcontext, ch
5af5b2
                      * Check for append/overwrite, then open the file.
5af5b2
                      */
5af5b2
                     if (cp[4] == ':' || cp[4] == '=') {
5af5b2
-                        f = fopen(&cp[5], (cp[4] == ':') ? "a" : "w");
5af5b2
+                        f = WRITABLEFOPEN(&cp[5], (cp[4] == ':') ? "a" : "w");
5af5b2
                         if (f) {
5af5b2
                             set_cloexec_file(f);
5af5b2
                             log_control.log_entries[i].lfu_filep = f;
5af5b2
@@ -961,7 +961,7 @@ krb5_klog_reopen(krb5_context kcontext)
5af5b2
              * In case the old logfile did not get moved out of the
5af5b2
              * way, open for append to prevent squashing the old logs.
5af5b2
              */
5af5b2
-            f = fopen(log_control.log_entries[lindex].lfu_fname, "a+");
5af5b2
+            f = WRITABLEFOPEN(log_control.log_entries[lindex].lfu_fname, "a+");
5af5b2
             if (f) {
5af5b2
                 set_cloexec_file(f);
5af5b2
                 log_control.log_entries[lindex].lfu_filep = f;
5af5b2
--- krb5/src/lib/krb5/keytab/kt_file.c
5af5b2
+++ krb5/src/lib/krb5/keytab/kt_file.c
5af5b2
@@ -1050,7 +1050,7 @@ krb5_ktfileint_open(krb5_context context
5af5b2
 
5af5b2
     KTCHECKLOCK(id);
5af5b2
     errno = 0;
5af5b2
-    KTFILEP(id) = fopen(KTFILENAME(id),
5af5b2
+    KTFILEP(id) = WRITABLEFOPEN(KTFILENAME(id),
5af5b2
                         (mode == KRB5_LOCKMODE_EXCLUSIVE) ?
5af5b2
                         fopen_mode_rbplus : fopen_mode_rb);
5af5b2
     if (!KTFILEP(id)) {
5af5b2
@@ -1058,7 +1058,7 @@ krb5_ktfileint_open(krb5_context context
5af5b2
             /* try making it first time around */
4be148
             k5_create_secure_file(context, KTFILENAME(id));
5af5b2
             errno = 0;
5af5b2
-            KTFILEP(id) = fopen(KTFILENAME(id), fopen_mode_rbplus);
5af5b2
+            KTFILEP(id) = WRITABLEFOPEN(KTFILENAME(id), fopen_mode_rbplus);
5af5b2
             if (!KTFILEP(id))
5af5b2
                 goto report_errno;
5af5b2
             writevno = 1;
5af5b2
--- krb5/src/plugins/kdb/db2/adb_openclose.c
5af5b2
+++ krb5/src/plugins/kdb/db2/adb_openclose.c
5af5b2
@@ -201,7 +201,7 @@ osa_adb_init_db(osa_adb_db_t *dbp, char 
5af5b2
          * POSIX systems
5af5b2
          */
5af5b2
         lockp->lockinfo.filename = strdup(lockfilename);
5af5b2
-        if ((lockp->lockinfo.lockfile = fopen(lockfilename, "r+")) == NULL) {
5af5b2
+        if ((lockp->lockinfo.lockfile = WRITABLEFOPEN(lockfilename, "r+")) == NULL) {
5af5b2
             /*
5af5b2
              * maybe someone took away write permission so we could only
5af5b2
              * get shared locks?
5af5b2
--- krb5/src/plugins/kdb/db2/libdb2/btree/bt_open.c
5af5b2
+++ krb5/src/plugins/kdb/db2/libdb2/btree/bt_open.c
5af5b2
@@ -60,6 +60,7 @@ static char sccsid[] = "@(#)bt_open.c	8.
01ee0a
 #include <string.h>
01ee0a
 #include <unistd.h>
5af5b2
 
5af5b2
+#include "k5-int.h"
5af5b2
 #include "db-int.h"
5af5b2
 #include "btree.h"
5af5b2
 
5af5b2
@@ -203,7 +204,7 @@ __bt_open(fname, flags, mode, openinfo, 
5af5b2
 			goto einval;
5af5b2
 		}
5af5b2
 
5af5b2
-		if ((t->bt_fd = open(fname, flags | O_BINARY, mode)) < 0)
5af5b2
+		if ((t->bt_fd = THREEPARAMOPEN(fname, flags | O_BINARY, mode)) < 0)
5af5b2
 			goto err;
5af5b2
 
5af5b2
 	} else {
5af5b2
--- krb5/src/plugins/kdb/db2/libdb2/hash/hash.c
5af5b2
+++ krb5/src/plugins/kdb/db2/libdb2/hash/hash.c
5af5b2
@@ -51,6 +51,7 @@ static char sccsid[] = "@(#)hash.c	8.12 
5af5b2
 #include <assert.h>
5af5b2
 #endif
5af5b2
 
5af5b2
+#include "k5-int.h"
5af5b2
 #include "db-int.h"
5af5b2
 #include "hash.h"
5af5b2
 #include "page.h"
5af5b2
@@ -140,7 +141,7 @@ __kdb2_hash_open(file, flags, mode, info
5af5b2
 		new_table = 1;
5af5b2
 	}
5af5b2
 	if (file) {
5af5b2
-		if ((hashp->fp = open(file, flags|O_BINARY, mode)) == -1)
5af5b2
+		if ((hashp->fp = THREEPARAMOPEN(file, flags|O_BINARY, mode)) == -1)
5af5b2
 			RETURN_ERROR(errno, error0);
5af5b2
 		(void)fcntl(hashp->fp, F_SETFD, 1);
5af5b2
 	}
5af5b2
--- krb5/src/plugins/kdb/ldap/ldap_util/kdb5_ldap_services.c
5af5b2
+++ krb5/src/plugins/kdb/ldap/ldap_util/kdb5_ldap_services.c
5af5b2
@@ -179,7 +179,7 @@ done:
5af5b2
 
5af5b2
     /* set password in the file */
5af5b2
     old_mode = umask(0177);
5af5b2
-    pfile = fopen(file_name, "a+");
5af5b2
+    pfile = WRITABLEFOPEN(file_name, "a+");
5af5b2
     if (pfile == NULL) {
5af5b2
         com_err(me, errno, _("Failed to open file %s: %s"), file_name,
5af5b2
                 strerror (errno));
5af5b2
@@ -220,6 +220,9 @@ done:
5af5b2
          * Delete the existing entry and add the new entry
5af5b2
          */
5af5b2
         FILE *newfile;
5af5b2
+#ifdef USE_SELINUX
5af5b2
+        void *selabel;
5af5b2
+#endif
5af5b2
 
5af5b2
         mode_t omask;
5af5b2
 
5af5b2
@@ -231,7 +234,13 @@ done:
5af5b2
         }
5af5b2
 
5af5b2
         omask = umask(077);
5af5b2
+#ifdef USE_SELINUX
5af5b2
+        selabel = krb5int_push_fscreatecon_for(file_name);
5af5b2
+#endif
5af5b2
         newfile = fopen(tmp_file, "w");
5af5b2
+#ifdef USE_SELINUX
5af5b2
+        krb5int_pop_fscreatecon(selabel);
5af5b2
+#endif
5af5b2
         umask (omask);
5af5b2
         if (newfile == NULL) {
5af5b2
             com_err(me, errno, _("Error creating file %s"), tmp_file);
5af5b2
--- krb5/src/slave/kpropd.c
5af5b2
+++ krb5/src/slave/kpropd.c
5af5b2
@@ -437,6 +437,9 @@ void doit(fd)
5af5b2
     krb5_enctype etype;
5af5b2
     int database_fd;
01ee0a
     char host[INET6_ADDRSTRLEN + 1];
5af5b2
+#ifdef USE_SELINUX
5af5b2
+    void *selabel;
5af5b2
+#endif
5af5b2
 
5af5b2
     signal_wrapper(SIGALRM, alarm_handler);
5af5b2
     alarm(params.iprop_resync_timeout);
5af5b2
@@ -515,9 +518,15 @@ void doit(fd)
5af5b2
         free(name);
5af5b2
         exit(1);
5af5b2
     }
5af5b2
+#ifdef USE_SELINUX
5af5b2
+    selabel = krb5int_push_fscreatecon_for(file);
5af5b2
+#endif
5af5b2
     omask = umask(077);
01ee0a
     lock_fd = open(temp_file_name, O_RDWR | O_CREAT, 0600);
01ee0a
     (void)umask(omask);
5af5b2
+#ifdef USE_SELINUX
5af5b2
+    krb5int_pop_fscreatecon(selabel);
5af5b2
+#endif
5af5b2
     retval = krb5_lock_file(kpropd_context, lock_fd,
01ee0a
                             KRB5_LOCKMODE_EXCLUSIVE | KRB5_LOCKMODE_DONTBLOCK);
5af5b2
     if (retval) {
5af5b2
--- krb5/src/util/profile/prof_file.c
5af5b2
+++ krb5/src/util/profile/prof_file.c
5af5b2
@@ -30,6 +30,7 @@
5af5b2
 #endif
5af5b2
 
5af5b2
 #include "k5-platform.h"
5af5b2
+#include "k5-label.h"
5af5b2
 
5af5b2
 struct global_shared_profile_data {
5af5b2
     /* This is the head of the global list of shared trees */
5af5b2
@@ -418,7 +419,7 @@ static errcode_t write_data_to_file(prf_
5af5b2
 
5af5b2
     errno = 0;
5af5b2
 
5af5b2
-    f = fopen(new_file, "w");
5af5b2
+    f = WRITABLEFOPEN(new_file, "w");
5af5b2
     if (!f) {
5af5b2
         retval = errno;
5af5b2
         if (retval == 0)
5af5b2
--- krb5/src/util/support/Makefile.in
5af5b2
+++ krb5/src/util/support/Makefile.in
5af5b2
@@ -54,6 +54,7 @@ IPC_SYMS= \
5af5b2
 
5af5b2
 STLIBOBJS= \
5af5b2
 	threads.o \
5af5b2
+	selinux.o \
5af5b2
 	init-addrinfo.o \
5af5b2
 	plugins.o \
5af5b2
 	errors.o \
5af5b2
@@ -108,7 +109,7 @@ SRCS=\
5af5b2
 
5af5b2
 SHLIB_EXPDEPS =
5af5b2
 # Add -lm if dumping thread stats, for sqrt.
5af5b2
-SHLIB_EXPLIBS= $(LIBS) $(DL_LIB)
5af5b2
+SHLIB_EXPLIBS= $(LIBS) $(SELINUX_LIBS) $(DL_LIB)
4be148
 
4be148
 DEPLIBS=
5af5b2
 
5af5b2
--- krb5/src/util/support/selinux.c
5af5b2
+++ krb5/src/util/support/selinux.c
4be148
@@ -0,0 +1,381 @@
5af5b2
+/*
4be148
+ * Copyright 2007,2008,2009,2011,2012,2013 Red Hat, Inc.  All Rights Reserved.
5af5b2
+ *
5af5b2
+ * Redistribution and use in source and binary forms, with or without
5af5b2
+ * modification, are permitted provided that the following conditions are met:
5af5b2
+ *
5af5b2
+ *  Redistributions of source code must retain the above copyright notice, this
5af5b2
+ *  list of conditions and the following disclaimer.
5af5b2
+ *
5af5b2
+ *  Redistributions in binary form must reproduce the above copyright notice,
5af5b2
+ *  this list of conditions and the following disclaimer in the documentation
5af5b2
+ *  and/or other materials provided with the distribution.
5af5b2
+ *
5af5b2
+ *  Neither the name of Red Hat, Inc. nor the names of its contributors may be
5af5b2
+ *  used to endorse or promote products derived from this software without
5af5b2
+ *  specific prior written permission.
5af5b2
+ *
5af5b2
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
5af5b2
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
5af5b2
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
5af5b2
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
5af5b2
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
5af5b2
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
5af5b2
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
5af5b2
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
5af5b2
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
5af5b2
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
5af5b2
+ * POSSIBILITY OF SUCH DAMAGE.
5af5b2
+ * 
5af5b2
+ * File-opening wrappers for creating correctly-labeled files.  So far, we can
5af5b2
+ * assume that this is Linux-specific, so we make many simplifying assumptions.
5af5b2
+ */
5af5b2
+
5af5b2
+#include "../../include/autoconf.h"
5af5b2
+
5af5b2
+#ifdef USE_SELINUX
5af5b2
+
5af5b2
+#include <k5-label.h>
5af5b2
+#include <k5-platform.h>
5af5b2
+#include <sys/types.h>
5af5b2
+#include <sys/stat.h>
5af5b2
+#include <errno.h>
5af5b2
+#include <fcntl.h>
5af5b2
+#include <limits.h>
5af5b2
+#include <pthread.h>
5af5b2
+#include <stdarg.h>
5af5b2
+#include <stdio.h>
5af5b2
+#include <stdlib.h>
5af5b2
+#include <string.h>
5af5b2
+#include <unistd.h>
5af5b2
+#include <selinux/selinux.h>
5af5b2
+#include <selinux/context.h>
5af5b2
+#ifdef HAVE_SELINUX_LABEL_H
5af5b2
+#include <selinux/label.h>
5af5b2
+#endif
5af5b2
+
5af5b2
+/* #define DEBUG 1 */
5af5b2
+
5af5b2
+/* Mutex used to serialize use of the process-global file creation context. */
5af5b2
+k5_mutex_t labeled_mutex = K5_MUTEX_PARTIAL_INITIALIZER;
5af5b2
+
5af5b2
+/* Make sure we finish initializing that mutex before attempting to use it. */
5af5b2
+k5_once_t labeled_once = K5_ONCE_INIT;
5af5b2
+static void
5af5b2
+label_mutex_init(void)
5af5b2
+{
5af5b2
+	k5_mutex_finish_init(&labeled_mutex);
5af5b2
+}
5af5b2
+
5af5b2
+#ifdef HAVE_SELINUX_LABEL_H
5af5b2
+static struct selabel_handle *selabel_ctx;
5af5b2
+static time_t selabel_last_changed;
5af5b2
+
5af5b2
+MAKE_FINI_FUNCTION(cleanup_fscreatecon);
5af5b2
+
5af5b2
+static void
5af5b2
+cleanup_fscreatecon(void)
5af5b2
+{
5af5b2
+	if (selabel_ctx != NULL) {
5af5b2
+		selabel_close(selabel_ctx);
5af5b2
+		selabel_ctx = NULL;
5af5b2
+	}
5af5b2
+}
5af5b2
+#endif
5af5b2
+
5af5b2
+static security_context_t
5af5b2
+push_fscreatecon(const char *pathname, mode_t mode)
5af5b2
+{
5af5b2
+	security_context_t previous, configuredsc, currentsc, derivedsc;
5af5b2
+	context_t current, derived;
5af5b2
+	const char *fullpath, *currentuser;
5af5b2
+
5af5b2
+	previous = NULL;
5af5b2
+	if (is_selinux_enabled()) {
5af5b2
+		if (getfscreatecon(&previous) == 0) {
5af5b2
+			char *genpath;
5af5b2
+			genpath = NULL;
5af5b2
+			if (pathname[0] != '/') {
5af5b2
+				char *wd;
5af5b2
+				size_t len;
5af5b2
+				len = 0;
5af5b2
+				wd = getcwd(NULL, len);
5af5b2
+				if (wd == NULL) {
5af5b2
+					if (previous != NULL) {
5af5b2
+						freecon(previous);
5af5b2
+					}
5af5b2
+					return NULL;
5af5b2
+				}
5af5b2
+				len = strlen(wd) + 1 + strlen(pathname) + 1;
5af5b2
+				genpath = malloc(len);
5af5b2
+				if (genpath == NULL) {
5af5b2
+					free(wd);
5af5b2
+					if (previous != NULL) {
5af5b2
+						freecon(previous);
5af5b2
+					}
5af5b2
+					return NULL;
5af5b2
+				}
5af5b2
+				sprintf(genpath, "%s/%s", wd, pathname);
5af5b2
+				free(wd);
5af5b2
+				fullpath = genpath;
5af5b2
+			} else {
5af5b2
+				fullpath = pathname;
5af5b2
+			}
5af5b2
+#ifdef DEBUG
5af5b2
+			if (isatty(fileno(stderr))) {
5af5b2
+				fprintf(stderr, "Looking up context for "
5af5b2
+					"\"%s\"(%05o).\n", fullpath, mode);
5af5b2
+			}
5af5b2
+#endif
5af5b2
+			configuredsc = NULL;
5af5b2
+#ifdef HAVE_SELINUX_LABEL_H
5af5b2
+			if ((selabel_ctx != NULL) ||
5af5b2
+			    (selabel_last_changed == 0)) {
5af5b2
+				const char *cpath;
5af5b2
+				struct stat st;
5af5b2
+				int i = -1;
5af5b2
+				cpath = selinux_file_context_path();
5af5b2
+				if ((cpath == NULL) ||
5af5b2
+				    ((i = stat(cpath, &st)) != 0) ||
5af5b2
+				    (st.st_mtime != selabel_last_changed)) {
5af5b2
+					if (selabel_ctx != NULL) {
5af5b2
+						selabel_close(selabel_ctx);
5af5b2
+						selabel_ctx = NULL;
5af5b2
+					}
5af5b2
+					selabel_last_changed = i ?
5af5b2
+							       time(NULL) :
5af5b2
+							       st.st_mtime;
5af5b2
+				}
5af5b2
+			}
5af5b2
+			if (selabel_ctx == NULL) {
5af5b2
+				selabel_ctx = selabel_open(SELABEL_CTX_FILE,
5af5b2
+							   NULL, 0);
5af5b2
+			}
5af5b2
+			if (selabel_ctx != NULL) {
5af5b2
+				if (selabel_lookup(selabel_ctx, &configuredsc,
5af5b2
+						   fullpath, mode) != 0) {
5af5b2
+					free(genpath);
5af5b2
+					if (previous != NULL) {
5af5b2
+						freecon(previous);
5af5b2
+					}
5af5b2
+					return NULL;
5af5b2
+				}
5af5b2
+			}
5af5b2
+#else
5af5b2
+			if (matchpathcon(fullpath, mode, &configuredsc) != 0) {
5af5b2
+				free(genpath);
5af5b2
+				if (previous != NULL) {
5af5b2
+					freecon(previous);
5af5b2
+				}
5af5b2
+				return NULL;
5af5b2
+			}
5af5b2
+#endif
5af5b2
+			free(genpath);
5af5b2
+			if (configuredsc == NULL) {
5af5b2
+				if (previous != NULL) {
5af5b2
+					freecon(previous);
5af5b2
+				}
5af5b2
+				return NULL;
5af5b2
+			}
5af5b2
+			currentsc = NULL;
5af5b2
+			getcon(&currentsc);
5af5b2
+			if (currentsc != NULL) {
5af5b2
+				derived = context_new(configuredsc);
5af5b2
+				if (derived != NULL) {
5af5b2
+					current = context_new(currentsc);
5af5b2
+					if (current != NULL) {
5af5b2
+						currentuser = context_user_get(current);
5af5b2
+						if (currentuser != NULL) {
5af5b2
+							if (context_user_set(derived,
5af5b2
+									     currentuser) == 0) {
5af5b2
+								derivedsc = context_str(derived);
5af5b2
+								if (derivedsc != NULL) {
5af5b2
+									freecon(configuredsc);
5af5b2
+									configuredsc = strdup(derivedsc);
5af5b2
+								}
5af5b2
+							}
5af5b2
+						}
5af5b2
+						context_free(current);
5af5b2
+					}
5af5b2
+					context_free(derived);
5af5b2
+				}
5af5b2
+				freecon(currentsc);
5af5b2
+			}
5af5b2
+#ifdef DEBUG
5af5b2
+			if (isatty(fileno(stderr))) {
5af5b2
+				fprintf(stderr, "Setting file creation context "
5af5b2
+					"to \"%s\".\n", configuredsc);
5af5b2
+			}
5af5b2
+#endif
5af5b2
+			if (setfscreatecon(configuredsc) != 0) {
5af5b2
+				freecon(configuredsc);
5af5b2
+				if (previous != NULL) {
5af5b2
+					freecon(previous);
5af5b2
+				}
5af5b2
+				return NULL;
5af5b2
+			}
5af5b2
+			freecon(configuredsc);
5af5b2
+#ifdef DEBUG
5af5b2
+		} else {
5af5b2
+			if (isatty(fileno(stderr))) {
5af5b2
+				fprintf(stderr, "Unable to determine "
5af5b2
+					"current context.\n");
5af5b2
+			}
5af5b2
+#endif
5af5b2
+		}
5af5b2
+	}
5af5b2
+	return previous;
5af5b2
+}
5af5b2
+
5af5b2
+static void
5af5b2
+pop_fscreatecon(security_context_t previous)
5af5b2
+{
5af5b2
+	if (is_selinux_enabled()) {
5af5b2
+#ifdef DEBUG
5af5b2
+		if (isatty(fileno(stderr))) {
5af5b2
+			if (previous != NULL) {
5af5b2
+				fprintf(stderr, "Resetting file creation "
5af5b2
+					"context to \"%s\".\n", previous);
5af5b2
+			} else {
5af5b2
+				fprintf(stderr, "Resetting file creation "
5af5b2
+					"context to default.\n");
5af5b2
+			}
5af5b2
+		}
5af5b2
+#endif
5af5b2
+		setfscreatecon(previous);
5af5b2
+		if (previous != NULL) {
5af5b2
+			freecon(previous);
5af5b2
+		}
5af5b2
+	}
5af5b2
+}
5af5b2
+
5af5b2
+void *
5af5b2
+krb5int_push_fscreatecon_for(const char *pathname)
5af5b2
+{
5af5b2
+	struct stat st;
5af5b2
+	void *retval;
5af5b2
+	k5_once(&labeled_once, label_mutex_init);
4be148
+	k5_mutex_lock(&labeled_mutex);
4be148
+	if (stat(pathname, &st) != 0) {
4be148
+		st.st_mode = S_IRUSR | S_IWUSR;
5af5b2
+	}
4be148
+	retval = push_fscreatecon(pathname, st.st_mode);
4be148
+	return retval ? retval : (void *) -1;
5af5b2
+}
5af5b2
+
5af5b2
+void
5af5b2
+krb5int_pop_fscreatecon(void *con)
5af5b2
+{
5af5b2
+	if (con != NULL) {
5af5b2
+		pop_fscreatecon((con == (void *) -1) ? NULL : con);
5af5b2
+		k5_mutex_unlock(&labeled_mutex);
5af5b2
+	}
5af5b2
+}
5af5b2
+
5af5b2
+FILE *
5af5b2
+krb5int_labeled_fopen(const char *path, const char *mode)
5af5b2
+{
5af5b2
+	FILE *fp;
5af5b2
+	int errno_save;
5af5b2
+	security_context_t ctx;
5af5b2
+
5af5b2
+	if ((strcmp(mode, "r") == 0) ||
5af5b2
+	    (strcmp(mode, "rb") == 0)) {
5af5b2
+		return fopen(path, mode);
5af5b2
+	}
5af5b2
+
5af5b2
+	k5_once(&labeled_once, label_mutex_init);
4be148
+	k5_mutex_lock(&labeled_mutex);
4be148
+	ctx = push_fscreatecon(path, 0);
4be148
+	fp = fopen(path, mode);
4be148
+	errno_save = errno;
4be148
+	pop_fscreatecon(ctx);
4be148
+	k5_mutex_unlock(&labeled_mutex);
4be148
+	errno = errno_save;
5af5b2
+	return fp;
5af5b2
+}
5af5b2
+
5af5b2
+int
5af5b2
+krb5int_labeled_creat(const char *path, mode_t mode)
5af5b2
+{
5af5b2
+	int fd;
5af5b2
+	int errno_save;
5af5b2
+	security_context_t ctx;
5af5b2
+
5af5b2
+	k5_once(&labeled_once, label_mutex_init);
4be148
+	k5_mutex_lock(&labeled_mutex);
4be148
+	ctx = push_fscreatecon(path, 0);
4be148
+	fd = creat(path, mode);
4be148
+	errno_save = errno;
4be148
+	pop_fscreatecon(ctx);
4be148
+	k5_mutex_unlock(&labeled_mutex);
4be148
+	errno = errno_save;
5af5b2
+	return fd;
5af5b2
+}
5af5b2
+
5af5b2
+int
5af5b2
+krb5int_labeled_mknod(const char *path, mode_t mode, dev_t dev)
5af5b2
+{
5af5b2
+	int ret;
5af5b2
+	int errno_save;
5af5b2
+	security_context_t ctx;
5af5b2
+
5af5b2
+	k5_once(&labeled_once, label_mutex_init);
4be148
+	k5_mutex_lock(&labeled_mutex);
4be148
+	ctx = push_fscreatecon(path, mode);
4be148
+	ret = mknod(path, mode, dev);
4be148
+	errno_save = errno;
4be148
+	pop_fscreatecon(ctx);
4be148
+	k5_mutex_unlock(&labeled_mutex);
4be148
+	errno = errno_save;
5af5b2
+	return ret;
5af5b2
+}
5af5b2
+
5af5b2
+int
5af5b2
+krb5int_labeled_mkdir(const char *path, mode_t mode)
5af5b2
+{
5af5b2
+	int ret;
5af5b2
+	int errno_save;
5af5b2
+	security_context_t ctx;
5af5b2
+
5af5b2
+	k5_once(&labeled_once, label_mutex_init);
4be148
+	k5_mutex_lock(&labeled_mutex);
4be148
+	ctx = push_fscreatecon(path, S_IFDIR);
4be148
+	ret = mkdir(path, mode);
4be148
+	errno_save = errno;
4be148
+	pop_fscreatecon(ctx);
4be148
+	k5_mutex_unlock(&labeled_mutex);
4be148
+	errno = errno_save;
5af5b2
+	return ret;
5af5b2
+}
5af5b2
+
5af5b2
+int
5af5b2
+krb5int_labeled_open(const char *path, int flags, ...)
5af5b2
+{
5af5b2
+	int fd;
5af5b2
+	int errno_save;
5af5b2
+	security_context_t ctx;
5af5b2
+	mode_t mode;
5af5b2
+	va_list ap;
5af5b2
+
5af5b2
+	if ((flags & O_CREAT) == 0) {
5af5b2
+		return open(path, flags);
5af5b2
+	}
5af5b2
+
5af5b2
+	k5_once(&labeled_once, label_mutex_init);
4be148
+	k5_mutex_lock(&labeled_mutex);
4be148
+	ctx = push_fscreatecon(path, 0);
4be148
+
4be148
+	va_start(ap, flags);
4be148
+	mode = va_arg(ap, mode_t);
4be148
+	fd = open(path, flags, mode);
4be148
+	va_end(ap);
4be148
+
4be148
+	errno_save = errno;
4be148
+	pop_fscreatecon(ctx);
4be148
+	k5_mutex_unlock(&labeled_mutex);
4be148
+	errno = errno_save;
5af5b2
+	return fd;
5af5b2
+}
5af5b2
+
5af5b2
+#endif
5af5b2
--- krb5/src/lib/krb5/rcache/rc_dfl.c
5af5b2
+++ krb5/src/lib/krb5/rcache/rc_dfl.c
5af5b2
@@ -813,6 +813,9 @@ krb5_rc_dfl_expunge_locked(krb5_context 
5af5b2
     krb5_error_code retval = 0;
5af5b2
     krb5_rcache tmp;
5af5b2
     krb5_deltat lifespan = t->lifespan;  /* save original lifespan */
5af5b2
+#ifdef USE_SELINUX
5af5b2
+    void *selabel;
5af5b2
+#endif
5af5b2
 
5af5b2
     if (! t->recovering) {
5af5b2
         name = t->name;
5af5b2
@@ -834,7 +837,17 @@ krb5_rc_dfl_expunge_locked(krb5_context 
5af5b2
     retval = krb5_rc_resolve(context, tmp, 0);
5af5b2
     if (retval)
5af5b2
         goto cleanup;
5af5b2
+#ifdef USE_SELINUX
5af5b2
+    if (t->d.fn != NULL)
5af5b2
+        selabel = krb5int_push_fscreatecon_for(t->d.fn);
5af5b2
+    else
5af5b2
+        selabel = NULL;
5af5b2
+#endif
5af5b2
     retval = krb5_rc_initialize(context, tmp, lifespan);
5af5b2
+#ifdef USE_SELINUX
5af5b2
+    if (selabel != NULL)
5af5b2
+        krb5int_pop_fscreatecon(selabel);
5af5b2
+#endif
5af5b2
     if (retval)
5af5b2
         goto cleanup;
5af5b2
     for (q = t->a; q; q = q->na) {
5af5b2
--- krb5/src/lib/krb5/ccache/cc_dir.c
5af5b2
+++ krb5/src/lib/krb5/ccache/cc_dir.c
5af5b2
@@ -185,10 +185,19 @@ write_primary_file(const char *primary_p
5af5b2
     char *newpath = NULL;
5af5b2
     FILE *fp = NULL;
5af5b2
     int fd = -1, status;
5af5b2
+#ifdef USE_SELINUX
5af5b2
+    void *selabel;
5af5b2
+#endif
5af5b2
 
5af5b2
     if (asprintf(&newpath, "%s.XXXXXX", primary_path) < 0)
5af5b2
         return ENOMEM;
5af5b2
+#ifdef USE_SELINUX
5af5b2
+    selabel = krb5int_push_fscreatecon_for(primary_path);
5af5b2
+#endif
5af5b2
     fd = mkstemp(newpath);
5af5b2
+#ifdef USE_SELINUX
5af5b2
+    krb5int_pop_fscreatecon(selabel);
5af5b2
+#endif
5af5b2
     if (fd < 0)
5af5b2
         goto cleanup;
5af5b2
 #ifdef HAVE_CHMOD
5af5b2
@@ -223,10 +232,23 @@
5af5b2
 verify_dir(krb5_context context, const char *dirname)
5af5b2
 {
5af5b2
     struct stat st;
5af5b2
+    int status;
5af5b2
+#ifdef USE_SELINUX
5af5b2
+    void *selabel;
5af5b2
+#endif
5af5b2
 
5af5b2
     if (stat(dirname, &st) < 0) {
5af5b2
-        if (errno == ENOENT && mkdir(dirname, S_IRWXU) == 0)
5af5b2
-            return 0;
5af5b2
+        if (errno == ENOENT) {
5af5b2
+#ifdef USE_SELINUX
5af5b2
+            selabel = krb5int_push_fscreatecon_for(dirname);
5af5b2
+#endif
5af5b2
+            status = mkdir(dirname, S_IRWXU);
5af5b2
+#ifdef USE_SELINUX
5af5b2
+            krb5int_pop_fscreatecon(selabel);
5af5b2
+#endif
5af5b2
+            if (status == 0)
5af5b2
+                return 0;
5af5b2
+        }
01ee0a
         k5_setmsg(context, KRB5_FCC_NOFILE,
01ee0a
                   _("Credential cache directory %s does not exist"),
01ee0a
                   dirname);
5af5b2
--- krb5/src/lib/krb5/os/trace.c
5af5b2
+++ krb5/src/lib/krb5/os/trace.c
5af5b2
@@ -401,7 +401,7 @@ krb5_set_trace_filename(krb5_context con
5af5b2
     fd = malloc(sizeof(*fd));
5af5b2
     if (fd == NULL)
5af5b2
         return ENOMEM;
5af5b2
-    *fd = open(filename, O_WRONLY|O_CREAT|O_APPEND, 0600);
5af5b2
+    *fd = THREEPARAMOPEN(filename, O_WRONLY|O_CREAT|O_APPEND, 0600);
5af5b2
     if (*fd == -1) {
5af5b2
         free(fd);
5af5b2
         return errno;
5af5b2
--- krb5/src/plugins/kdb/db2/kdb_db2.c
5af5b2
+++ krb5/src/plugins/kdb/db2/kdb_db2.c
5af5b2
@@ -683,8 +683,8 @@
5af5b2
     if (retval)
5af5b2
         return retval;
5af5b2
 
5af5b2
-    dbc->db_lf_file = open(dbc->db_lf_name, O_CREAT | O_RDWR | O_TRUNC,
5af5b2
-                           0600);
5af5b2
+    dbc->db_lf_file = THREEPARAMOPEN(dbc->db_lf_name,
5af5b2
+                                     O_CREAT | O_RDWR | O_TRUNC, 0600);
5af5b2
     if (dbc->db_lf_file < 0) {
5af5b2
         retval = errno;
5af5b2
         goto cleanup;
5af5b2
--- krb5/src/plugins/kdb/db2/libdb2/recno/rec_open.c
5af5b2
+++ krb5/src/plugins/kdb/db2/libdb2/recno/rec_open.c
5af5b2
@@ -51,6 +51,7 @@
5af5b2
 #include <stdio.h>
5af5b2
 #include <unistd.h>
5af5b2
 
5af5b2
+#include "k5-int.h"
5af5b2
 #include "db-int.h"
5af5b2
 #include "recno.h"
5af5b2
 
5af5b2
@@ -68,7 +69,8 @@
5af5b2
 	int rfd = -1, sverrno;
5af5b2
 
5af5b2
 	/* Open the user's file -- if this fails, we're done. */
5af5b2
-	if (fname != NULL && (rfd = open(fname, flags | O_BINARY, mode)) < 0)
5af5b2
+	if (fname != NULL &&
5af5b2
+            (rfd = THREEPARAMOPEN(fname, flags | O_BINARY, mode)) < 0)
5af5b2
 		return (NULL);
5af5b2
 
5af5b2
 	if (fname != NULL && fcntl(rfd, F_SETFD, 1) == -1) {
5af5b2
--- krb5/src/kdc/main.c
5af5b2
+++ krb5/src/kdc/main.c
5af5b2
@@ -905,7 +905,7 @@ write_pid_file(const char *path)
5af5b2
     FILE *file;
5af5b2
     unsigned long pid;
5af5b2
 
5af5b2
-    file = fopen(path, "w");
5af5b2
+    file = WRITABLEFOPEN(path, "w");
5af5b2
     if (file == NULL)
5af5b2
         return errno;
5af5b2
     pid = (unsigned long) getpid();
5af5b2
--- krb5/src/lib/kdb/kdb_log.c
5af5b2
+++ krb5/src/lib/kdb/kdb_log.c
01ee0a
@@ -456,7 +456,7 @@ ulog_map(krb5_context context, const cha
01ee0a
     int ulogfd = -1;
5af5b2
 
01ee0a
     if (stat(logname, &st) == -1) {
5af5b2
-        ulogfd = open(logname, O_RDWR | O_CREAT, 0600);
5af5b2
+        ulogfd = THREEPARAMOPEN(logname, O_RDWR | O_CREAT, 0600);
4be148
         if (ulogfd == -1)
4be148
             return errno;
4be148
 
5af5b2
--- krb5/src/util/gss-kernel-lib/Makefile.in
5af5b2
+++ krb5/src/util/gss-kernel-lib/Makefile.in
5af5b2
@@ -60,6 +60,7 @@ HEADERS= \
5af5b2
 	gssapi_err_generic.h \
5af5b2
 	k5-int.h \
5af5b2
 	k5-int-pkinit.h \
5af5b2
+	k5-label.h \
5af5b2
 	k5-thread.h \
5af5b2
 	k5-platform.h \
5af5b2
 	k5-buf.h \
5af5b2
@@ -166,10 +167,12 @@ gssapi_generic.h: $(GSS_GENERIC)/gssapi_
5af5b2
 	$(CP) $(GSS_GENERIC)/gssapi_generic.h $@
5af5b2
 gssapi_err_generic.h: $(GSS_GENERIC_BUILD)/gssapi_err_generic.h
5af5b2
 	$(CP) $(GSS_GENERIC_BUILD)/gssapi_err_generic.h $@
5af5b2
-k5-int.h: $(INCLUDE)/k5-int.h
5af5b2
+k5-int.h: $(INCLUDE)/k5-int.h k5-label.h
5af5b2
 	$(CP) $(INCLUDE)/k5-int.h $@
5af5b2
 k5-int-pkinit.h: $(INCLUDE)/k5-int-pkinit.h
5af5b2
 	$(CP) $(INCLUDE)/k5-int-pkinit.h $@
5af5b2
+k5-label.h: $(INCLUDE)/k5-label.h
5af5b2
+	$(CP) $(INCLUDE)/k5-label.h $@
5af5b2
 k5-thread.h: $(INCLUDE)/k5-thread.h
5af5b2
 	$(CP) $(INCLUDE)/k5-thread.h $@
5af5b2
 k5-platform.h: $(INCLUDE)/k5-platform.h