93772ec
From 9914b93516bbce9b1123ed5f9f796b7028944892 Mon Sep 17 00:00:00 2001
93772ec
From: Robbie Harwood <rharwood@redhat.com>
93772ec
Date: Thu, 17 Dec 2015 13:31:39 -0500
93772ec
Subject: [PATCH] Create KDC and kadmind log files with mode 0640
93772ec
93772ec
In krb5_klog_init(), use open() and fdopen() to open log files so that
93772ec
we can specify a mode.  Specify a mode which doesn't include the
93772ec
group-write, other-read, or other-write bits even if the process umask
93772ec
allows them.
93772ec
93772ec
[ghudson@mit.edu: wrote commit message, de-indented post-open setup
93772ec
code]
93772ec
[rharwood@redhat.com: backport not clean for some reason?]
93772ec
93772ec
ticket: 8344 (new)
93772ec
---
93772ec
 src/lib/kadm5/logger.c | 21 ++++++++++++---------
93772ec
 1 file changed, 12 insertions(+), 9 deletions(-)
93772ec
93772ec
diff --git a/src/lib/kadm5/logger.c b/src/lib/kadm5/logger.c
93772ec
index 19c4355..f4a9387 100644
93772ec
93772ec
--- a/src/lib/kadm5/logger.c	2016-01-21 18:52:52.529544902 +0000
93772ec
+++ b/src/lib/kadm5/logger.c	2016-01-21 18:57:22.923972419 +0000
93772ec
@@ -354,7 +354,7 @@
93772ec
     const char  *logging_profent[3];
93772ec
     const char  *logging_defent[3];
93772ec
     char        **logging_specs;
93772ec
-    int         i, ngood;
93772ec
+    int         i, ngood, fd, append;
93772ec
     char        *cp, *cp2;
93772ec
     char        savec = '\0';
93772ec
     int         error;
93772ec
@@ -422,18 +422,21 @@
93772ec
                     /*
93772ec
                      * Check for append/overwrite, then open the file.
93772ec
                      */
93772ec
-                    if (cp[4] == ':' || cp[4] == '=') {
93772ec
-                        f = WRITABLEFOPEN(&cp[5], (cp[4] == ':') ? "a" : "w");
93772ec
-                        if (f) {
93772ec
-                            set_cloexec_file(f);
93772ec
-                            log_control.log_entries[i].lfu_filep = f;
93772ec
-                            log_control.log_entries[i].log_type = K_LOG_FILE;
93772ec
-                            log_control.log_entries[i].lfu_fname = &cp[5];
93772ec
-                        } else {
93772ec
+                    append = (cp[4] == ':') ? O_APPEND : 0;
93772ec
+                    if (append || cp[4] == '=') {
93772ec
+                        fd = open(&cp[5], O_CREAT | O_WRONLY | append,
93772ec
+                                  S_IRUSR | S_IWUSR | S_IRGRP);
93772ec
+                        if (fd != -1)
93772ec
+                            f = fdopen(fd, append ? "a" : "w");
93772ec
+                        if (fd == -1 || f == NULL) {
93772ec
                             fprintf(stderr,"Couldn't open log file %s: %s\n",
93772ec
                                     &cp[5], error_message(errno));
93772ec
                             continue;
93772ec
                         }
93772ec
+                        set_cloexec_file(f);
93772ec
+                        log_control.log_entries[i].lfu_filep = f;
93772ec
+                        log_control.log_entries[i].log_type = K_LOG_FILE;
93772ec
+                        log_control.log_entries[i].lfu_fname = &cp[5];
93772ec
                     }
93772ec
                 }
93772ec
 #ifdef  HAVE_SYSLOG