]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Ensure that log files are plain files. (RT #22771)
authorScott Mann <smann@isc.org>
Fri, 4 Mar 2011 14:10:13 +0000 (14:10 +0000)
committerScott Mann <smann@isc.org>
Fri, 4 Mar 2011 14:10:13 +0000 (14:10 +0000)
CHANGES
bin/named/logconf.c
bin/tests/system/conf.sh.in
bin/tests/system/start.pl
lib/isc/include/isc/file.h
lib/isc/unix/file.c
lib/isc/unix/stdio.c
lib/isc/win32/file.c

diff --git a/CHANGES b/CHANGES
index f820160cc7ee41775dea57159b8c59cb4274e380..7f28c3d9dc7cc70066ba0e09743caf6e72650db0 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,7 @@
+3058.   [bug]           Cause named to terminate at startup or rndc reconfig/
+                        reload to fail, if a log file specified in the conf
+                        file isn't a plain file. [RT #22771]
+
 3057.  [bug]           "rndc secroots" would abort after the first error
                        and so could miss some views. [RT #23488]
 
index e32496507eb3e89f56cea9f6467904526012842b..b08a34568093d718217df96b4a0fa0bd8f7d0d98 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: logconf.c,v 1.42 2007/06/19 23:46:59 tbox Exp $ */
+/* $Id: logconf.c,v 1.42.816.1 2011/03/04 14:10:12 smann Exp $ */
 
 /*! \file */
 
@@ -221,24 +221,36 @@ channel_fromconf(const cfg_obj_t *channel, isc_logconfig_t *lctx) {
                FILE *fp;
                
                /*
-                * Test that the file can be opened, since isc_log_open()
-                * can't effectively report failures when called in
-                * isc_log_doit().
-                */
-               result = isc_stdio_open(dest.file.name, "a", &fp);
-               if (result != ISC_R_SUCCESS)
-                       isc_log_write(ns_g_lctx, CFG_LOGCATEGORY_CONFIG,
-                                     NS_LOGMODULE_SERVER, ISC_LOG_ERROR,
-                                     "logging channel '%s' file '%s': %s",
-                                     channelname, dest.file.name,
-                                     isc_result_totext(result));
-               else
-                       (void)isc_stdio_close(fp);
-
-               /*
-                * Allow named to continue by returning success.
-                */
-               result = ISC_R_SUCCESS;
+                * Test to make sure that file is a plain file.
+                * Fix defect #22771
+               */
+                result = isc_file_isplainfile(dest.file.name);
+                if (result == ISC_R_SUCCESS || 
+                   result == ISC_R_FILENOTFOUND) {
+                       /*
+                        * Test that the file can be opened, since
+                        * isc_log_open() can't effectively report 
+                        * failures when called in
+                        * isc_log_doit().
+                        */
+                       result = isc_stdio_open(dest.file.name, "a", &fp);
+                       if (result != ISC_R_SUCCESS) {
+                               syslog(LOG_ERR,
+                                       "isc_stdio_open '%s' failed: %s",
+                                       dest.file.name, 
+                                       isc_result_totext(result));
+                               fprintf(stderr,
+                                       "isc_stdio_open '%s' failed: %s",
+                                       dest.file.name,
+                                       isc_result_totext(result));
+                       } else
+                               (void)isc_stdio_close(fp);
+               } else {
+                       syslog(LOG_ERR, "isc_file_isplainfile '%s' failed: %s",
+                               dest.file.name, isc_result_totext(result));
+                       fprintf(stderr, "isc_file_isplainfile '%s' failed: %s",
+                               dest.file.name, isc_result_totext(result));
+               }
        }
 
        return (result);
index 90f1c131a59972fa4936f4e747eb417be1e91b63..b9d0a182f766e83cdfb0d2062929fbf2b77574f2 100644 (file)
@@ -15,7 +15,7 @@
 # OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 # PERFORMANCE OF THIS SOFTWARE.
 
-# $Id: conf.sh.in,v 1.59.8.3 2011/03/02 04:47:11 marka Exp $
+# $Id: conf.sh.in,v 1.59.8.4 2011/03/04 14:10:13 smann Exp $
 
 #
 # Common configuration data for system tests, to be sourced into
@@ -54,9 +54,9 @@ JOURNALPRINT=$TOP/bin/tools/named-journalprint
 # v6synth
 SUBDIRS="acl allow_query addzone autosign cacheclean checkconf checknames
         checkzone database dlv dlvauto @DLZ_SYSTEM_TEST@ dlzexternal dns64
-        dnssec forward glue gost ixfr limits lwresd masterfile masterformat
-        metadata notify nsupdate pending pkcs11 resolver rpz rrsetorder
-        sortlist smartsign staticstub stub tkey tsig tsiggss
+        dnssec forward glue gost ixfr limits logfileconfig lwresd masterfile
+        masterformat metadata notify nsupdate pending pkcs11 resolver rpz
+        rrsetorder sortlist smartsign staticstub stub tkey tsig tsiggss
         unknown upforwd views xfer xferquota zonechecks"
 
 # PERL will be an empty string if no perl interpreter was found.
index 75b03d994a8eea503aeb935584d7ebc53ee190d5..00c1cbb1cf7d8f6eda0056382192af529d2ae732 100644 (file)
@@ -15,7 +15,7 @@
 # OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 # PERFORMANCE OF THIS SOFTWARE.
 
-# $Id: start.pl,v 1.16 2010/09/15 12:07:55 marka Exp $
+# $Id: start.pl,v 1.16.54.1 2011/03/04 14:10:13 smann Exp $
 
 # Framework for starting test servers.
 # Based on the type of server specified, check for port availability, remove
@@ -33,6 +33,8 @@ use Getopt::Long;
 #   test - name of the test directory
 #   server - name of the server directory
 #   options - alternate options for the server
+#             NOTE: options must be specified with '-- "<option list>"',
+#              for instance: start.pl . ns1 -- "-c n.conf -d 43"
 
 my $usage = "usage: $0 [--noclean] test-directory [server-directory [server-options]]";
 my $noclean;
index ec00145cf818c7313ff4acd63f9acea7a2722ed8..cb864819337ddcaeb4693a3a6a89087107e032fa 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: file.h,v 1.39 2011/01/11 23:47:14 tbox Exp $ */
+/* $Id: file.h,v 1.39.10.1 2011/03/04 14:10:13 smann Exp $ */
 
 #ifndef ISC_FILE_H
 #define ISC_FILE_H 1
@@ -185,6 +185,27 @@ isc_file_isabsolute(const char *filename);
  * \brief Return #ISC_TRUE if the given file name is absolute.
  */
 
+isc_result_t
+isc_file_isplainfile(const char *name);
+/*!<
+ * \brief Check that the file is a plain file
+ *
+ * Returns:
+ *\li  #ISC_R_SUCCESS
+ *             Success. The file is a plain file.
+ *\li  #ISC_R_INVALIDFILE
+ *             The path specified was not usable by the operating system.
+ *\li  #ISC_R_FILENOTFOUND
+ *             The file does not exist. This return code comes from
+ *             errno=ENOENT when stat returns -1. This code is mentioned
+ *             here, because in logconf.c, it is the one rcode that is
+ *             permitted in addition to ISC_R_SUCCESS. This is done since 
+ *             the next call in logconf.c is to isc_stdio_open(), which
+ *             will create the file if it can.
+ *\li  #other ISC_R_* errors translated from errno
+ *             These occur when stat returns -1 and an errno.
+ */
+
 isc_boolean_t
 isc_file_iscurrentdir(const char *filename);
 /*!<
index c8db210ad7add5bf2144221b2b2b647ae26ebf1a..7474f9f8974ca78370c301d19003ea87be11215c 100644 (file)
@@ -48,7 +48,7 @@
  * SUCH DAMAGE.
  */
 
-/* $Id: file.c,v 1.57 2011/01/11 23:47:14 tbox Exp $ */
+/* $Id: file.c,v 1.57.10.1 2011/03/04 14:10:13 smann Exp $ */
 
 /*! \file */
 
@@ -348,6 +348,23 @@ isc_file_exists(const char *pathname) {
        return (ISC_TF(file_stats(pathname, &stats) == ISC_R_SUCCESS));
 }
 
+isc_result_t
+isc_file_isplainfile(const char *filename) {
+       /*
+        * This function returns success if filename is a plain file.
+        */
+       struct stat filestat;
+       memset(&filestat,0,sizeof(struct stat));
+
+       if ((stat(filename, &filestat)) == -1)
+               return(isc__errno2result(errno));
+
+       if(! S_ISREG(filestat.st_mode))
+               return(ISC_R_INVALIDFILE);
+
+       return(ISC_R_SUCCESS);
+}
+
 isc_boolean_t
 isc_file_isabsolute(const char *filename) {
        REQUIRE(filename != NULL);
index 4e294dbc2fee07dd4d2d53a2d5d6bd8f8def5c27..d6adbde1ac9a2f49224168a12fb684595ffb4b60 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: stdio.c,v 1.8 2007/06/19 23:47:18 tbox Exp $ */
+/* $Id: stdio.c,v 1.8.814.1 2011/03/04 14:10:13 smann Exp $ */
 
 #include <config.h>
 
@@ -23,6 +23,7 @@
 #include <unistd.h>
 
 #include <isc/stdio.h>
+#include <isc/stat.h>
 
 #include "errno2result.h"
 
index 526af77dfc2fb91a4aac977c758b46c780d0b55a..674c0327848ed0a60ba2c8a3f32373b9b38b0d28 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: file.c,v 1.39 2011/01/13 06:36:04 marka Exp $ */
+/* $Id: file.c,v 1.39.8.1 2011/03/04 14:10:13 smann Exp $ */
 
 #include <config.h>
 
@@ -398,6 +398,23 @@ isc_file_exists(const char *pathname) {
        return (ISC_TF(file_stats(pathname, &stats) == ISC_R_SUCCESS));
 }
 
+isc_result_t
+isc_file_isplainfile(const char *filename) {
+       /*
+        * This function returns success if filename is a plain file.
+        */
+       struct stat filestat;
+       memset(&filestat,0,sizeof(struct stat));
+
+       if ((stat(filename, &filestat)) == -1)
+               return(isc__errno2result(errno));
+
+       if(! S_ISREG(filestat.st_mode))
+               return(ISC_R_INVALIDFILE);
+
+       return(ISC_R_SUCCESS);
+}
+
 isc_boolean_t
 isc_file_isabsolute(const char *filename) {
        REQUIRE(filename != NULL);