Blame SOURCES/dnsmasq-2.76-dhcp-script-log.patch

598def
From 87444dc6977b61096127dcdfe87dc6cf2c0167d6 Mon Sep 17 00:00:00 2001
598def
From: =?UTF-8?q?Petr=20Men=C5=A1=C3=ADk?= <pemensik@redhat.com>
598def
Date: Sun, 16 Apr 2017 20:20:08 +0100
598def
Subject: [PATCH] Capture and log  STDOUT and STDERR output from dhcp-script.
598def
598def
(cherry picked from commit c77fb9d8f09d136fa71bde2469c4fd11cefa6f4a)
598def
598def
Compile-time check on buffer sizes for leasefile parsing code.
598def
598def
(cherry picked from commit bf4e62c19e619f7edf8d03d58d33a5752f190bfd)
598def
598def
Improve error handling with shcp-script "init" mode.
598def
598def
(cherry picked from commit 3a8b0f6fccf464b1ec6d24c0e00e540ab2b17705)
598def
598def
Tweak logging introduced in 3a8b0f6fccf464b1ec6d24c0e00e540ab2b17705
598def
598def
(cherry picked from commit efff74c1aea14757ce074db28e02671c7f7bb5f5)
598def
598def
Don't die() on failing to parse lease-script output.
598def
598def
(cherry picked from commit 05f76dab89d5b879519a4f45b0cccaa1fc3d162d)
598def
---
598def
 man/dnsmasq.8       |   4 +-
598def
 src/dhcp-common.c   |  16 +++---
598def
 src/dhcp-protocol.h |   4 ++
598def
 src/dnsmasq.c       |   8 +++
598def
 src/dnsmasq.h       |  54 +++++++++---------
598def
 src/helper.c        |  56 +++++++++++++++++-
598def
 src/lease.c         | 159 +++++++++++++++++++++++++++++++---------------------
598def
 src/log.c           |   4 +-
598def
 src/rfc3315.c       |   2 +-
598def
 9 files changed, 202 insertions(+), 105 deletions(-)
598def
598def
diff --git a/man/dnsmasq.8 b/man/dnsmasq.8
598def
index 0521534..97d0a4f 100644
598def
--- a/man/dnsmasq.8
598def
+++ b/man/dnsmasq.8
598def
@@ -1551,8 +1551,8 @@ database.
598def
 
598def
 
598def
 All file descriptors are
598def
-closed except stdin, stdout and stderr which are open to /dev/null
598def
-(except in debug mode).
598def
+closed except stdin, which is open to /dev/null, and stdout and stderr which capture output for logging by dnsmasq. 
598def
+(In debug mode, stdio, stdout and stderr file are left as those inherited from the invoker of dnsmasq).
598def
 
598def
 The script is not invoked concurrently: at most one instance
598def
 of the script is ever running (dnsmasq waits for an instance of script to exit
598def
diff --git a/src/dhcp-common.c b/src/dhcp-common.c
598def
index 08528e8..ecc752b 100644
598def
--- a/src/dhcp-common.c
598def
+++ b/src/dhcp-common.c
598def
@@ -20,11 +20,11 @@
598def
 
598def
 void dhcp_common_init(void)
598def
 {
598def
-    /* These each hold a DHCP option max size 255
598def
-       and get a terminating zero added */
598def
-  daemon->dhcp_buff = safe_malloc(256);
598def
-  daemon->dhcp_buff2 = safe_malloc(256); 
598def
-  daemon->dhcp_buff3 = safe_malloc(256);
598def
+  /* These each hold a DHCP option max size 255
598def
+     and get a terminating zero added */
598def
+  daemon->dhcp_buff = safe_malloc(DHCP_BUFF_SZ);
598def
+  daemon->dhcp_buff2 = safe_malloc(DHCP_BUFF_SZ); 
598def
+  daemon->dhcp_buff3 = safe_malloc(DHCP_BUFF_SZ);
598def
   
598def
   /* dhcp_packet is used by v4 and v6, outpacket only by v6 
598def
      sizeof(struct dhcp_packet) is as good an initial size as any,
598def
@@ -855,14 +855,14 @@ void log_context(int family, struct dhcp_context *context)
598def
       if (context->flags & CONTEXT_RA_STATELESS)
598def
 	{
598def
 	  if (context->flags & CONTEXT_TEMPLATE)
598def
-	    strncpy(daemon->dhcp_buff, context->template_interface, 256);
598def
+	    strncpy(daemon->dhcp_buff, context->template_interface, DHCP_BUFF_SZ);
598def
 	  else
598def
 	    strcpy(daemon->dhcp_buff, daemon->addrbuff);
598def
 	}
598def
       else 
598def
 #endif
598def
-	inet_ntop(family, start, daemon->dhcp_buff, 256);
598def
-      inet_ntop(family, end, daemon->dhcp_buff3, 256);
598def
+	inet_ntop(family, start, daemon->dhcp_buff, DHCP_BUFF_SZ);
598def
+      inet_ntop(family, end, daemon->dhcp_buff3, DHCP_BUFF_SZ);
598def
       my_syslog(MS_DHCP | LOG_INFO, 
598def
 		(context->flags & CONTEXT_RA_STATELESS) ? 
598def
 		_("%s stateless on %s%.0s%.0s%s") :
598def
diff --git a/src/dhcp-protocol.h b/src/dhcp-protocol.h
598def
index a31d829..0ea449b 100644
598def
--- a/src/dhcp-protocol.h
598def
+++ b/src/dhcp-protocol.h
598def
@@ -19,6 +19,10 @@
598def
 #define DHCP_CLIENT_ALTPORT 1068
598def
 #define PXE_PORT 4011
598def
 
598def
+/* These each hold a DHCP option max size 255
598def
+   and get a terminating zero added */
598def
+#define DHCP_BUFF_SZ 256
598def
+
598def
 #define BOOTREQUEST              1
598def
 #define BOOTREPLY                2
598def
 #define DHCP_COOKIE              0x63825363
598def
diff --git a/src/dnsmasq.c b/src/dnsmasq.c
598def
index 045ec53..9cd4052 100644
598def
--- a/src/dnsmasq.c
598def
+++ b/src/dnsmasq.c
598def
@@ -1294,6 +1294,7 @@ static void async_event(int pipe, time_t now)
598def
 		daemon->tcp_pids[i] = 0;
598def
 	break;
598def
 	
598def
+#if defined(HAVE_SCRIPT)	
598def
       case EVENT_KILLED:
598def
 	my_syslog(LOG_WARNING, _("script process killed by signal %d"), ev.data);
598def
 	break;
598def
@@ -1307,12 +1308,19 @@ static void async_event(int pipe, time_t now)
598def
 		  daemon->lease_change_command, strerror(ev.data));
598def
 	break;
598def
 
598def
+      case EVENT_SCRIPT_LOG:
598def
+	my_syslog(MS_SCRIPT | LOG_DEBUG, "%s", msg ? msg : "");
598def
+        free(msg);
598def
+	msg = NULL;
598def
+	break;
598def
+
598def
 	/* necessary for fatal errors in helper */
598def
       case EVENT_USER_ERR:
598def
       case EVENT_DIE:
598def
       case EVENT_LUA_ERR:
598def
 	fatal_event(&ev, msg);
598def
 	break;
598def
+#endif
598def
 
598def
       case EVENT_REOPEN:
598def
 	/* Note: this may leave TCP-handling processes with the old file still open.
598def
diff --git a/src/dnsmasq.h b/src/dnsmasq.h
598def
index 1896a64..0cfd3c6 100644
598def
--- a/src/dnsmasq.h
598def
+++ b/src/dnsmasq.h
598def
@@ -145,30 +145,31 @@ struct event_desc {
598def
   int event, data, msg_sz;
598def
 };
598def
 
598def
-#define EVENT_RELOAD    1
598def
-#define EVENT_DUMP      2
598def
-#define EVENT_ALARM     3
598def
-#define EVENT_TERM      4
598def
-#define EVENT_CHILD     5
598def
-#define EVENT_REOPEN    6
598def
-#define EVENT_EXITED    7
598def
-#define EVENT_KILLED    8
598def
-#define EVENT_EXEC_ERR  9
598def
-#define EVENT_PIPE_ERR  10
598def
-#define EVENT_USER_ERR  11
598def
-#define EVENT_CAP_ERR   12
598def
-#define EVENT_PIDFILE   13
598def
-#define EVENT_HUSER_ERR 14
598def
-#define EVENT_GROUP_ERR 15
598def
-#define EVENT_DIE       16
598def
-#define EVENT_LOG_ERR   17
598def
-#define EVENT_FORK_ERR  18
598def
-#define EVENT_LUA_ERR   19
598def
-#define EVENT_TFTP_ERR  20
598def
-#define EVENT_INIT      21
598def
-#define EVENT_NEWADDR   22
598def
-#define EVENT_NEWROUTE  23
598def
-#define EVENT_TIME_ERR  24
598def
+#define EVENT_RELOAD     1
598def
+#define EVENT_DUMP       2
598def
+#define EVENT_ALARM      3
598def
+#define EVENT_TERM       4
598def
+#define EVENT_CHILD      5
598def
+#define EVENT_REOPEN     6
598def
+#define EVENT_EXITED     7
598def
+#define EVENT_KILLED     8
598def
+#define EVENT_EXEC_ERR   9
598def
+#define EVENT_PIPE_ERR   10
598def
+#define EVENT_USER_ERR   11
598def
+#define EVENT_CAP_ERR    12
598def
+#define EVENT_PIDFILE    13
598def
+#define EVENT_HUSER_ERR  14
598def
+#define EVENT_GROUP_ERR  15
598def
+#define EVENT_DIE        16
598def
+#define EVENT_LOG_ERR    17
598def
+#define EVENT_FORK_ERR   18
598def
+#define EVENT_LUA_ERR    19
598def
+#define EVENT_TFTP_ERR   20
598def
+#define EVENT_INIT       21
598def
+#define EVENT_NEWADDR    22
598def
+#define EVENT_NEWROUTE   23
598def
+#define EVENT_TIME_ERR   24
598def
+#define EVENT_SCRIPT_LOG 25
598def
 
598def
 /* Exit codes. */
598def
 #define EC_GOOD        0
598def
@@ -242,8 +243,9 @@ struct event_desc {
598def
 
598def
 /* extra flags for my_syslog, we use a couple of facilities since they are known 
598def
    not to occupy the same bits as priorities, no matter how syslog.h is set up. */
598def
-#define MS_TFTP LOG_USER
598def
-#define MS_DHCP LOG_DAEMON 
598def
+#define MS_TFTP   LOG_USER
598def
+#define MS_DHCP   LOG_DAEMON
598def
+#define MS_SCRIPT LOG_MAIL
598def
 
598def
 struct all_addr {
598def
   union {
598def
diff --git a/src/helper.c b/src/helper.c
598def
index 9c37e37..de31383 100644
598def
--- a/src/helper.c
598def
+++ b/src/helper.c
598def
@@ -14,6 +14,7 @@
598def
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
598def
 */
598def
 
598def
+#include <stdio.h>
598def
 #include "dnsmasq.h"
598def
 
598def
 #ifdef HAVE_SCRIPT
598def
@@ -135,7 +136,7 @@ int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd)
598def
 	max_fd != STDIN_FILENO && max_fd != pipefd[0] && 
598def
 	max_fd != event_fd && max_fd != err_fd)
598def
       close(max_fd);
598def
-  
598def
+
598def
 #ifdef HAVE_LUASCRIPT
598def
   if (daemon->luascript)
598def
     {
598def
@@ -189,6 +190,7 @@ int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd)
598def
       unsigned char *buf = (unsigned char *)daemon->namebuff;
598def
       unsigned char *end, *extradata, *alloc_buff = NULL;
598def
       int is6, err = 0;
598def
+      int pipeout[2];
598def
 
598def
       free(alloc_buff);
598def
       
598def
@@ -472,16 +474,54 @@ int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd)
598def
       if (!daemon->lease_change_command)
598def
 	continue;
598def
 
598def
+      /* Pipe to capture stdout and stderr from script */
598def
+      if (!option_bool(OPT_DEBUG) && pipe(pipeout) == -1)
598def
+	continue;
598def
+      
598def
       /* possible fork errors are all temporary resource problems */
598def
       while ((pid = fork()) == -1 && (errno == EAGAIN || errno == ENOMEM))
598def
 	sleep(2);
598def
 
598def
       if (pid == -1)
598def
-	continue;
598def
+        {
598def
+	  if (!option_bool(OPT_DEBUG))
598def
+	    {
598def
+	      close(pipeout[0]);
598def
+	      close(pipeout[1]);
598def
+	    }
598def
+	  continue;
598def
+        }
598def
       
598def
       /* wait for child to complete */
598def
       if (pid != 0)
598def
 	{
598def
+	  if (!option_bool(OPT_DEBUG))
598def
+	    {
598def
+	      FILE *fp;
598def
+	  
598def
+	      close(pipeout[1]);
598def
+	      
598def
+	      /* Read lines sent to stdout/err by the script and pass them back to be logged */
598def
+	      if (!(fp = fdopen(pipeout[0], "r")))
598def
+		close(pipeout[0]);
598def
+	      else
598def
+		{
598def
+		  while (fgets(daemon->packet, daemon->packet_buff_sz, fp))
598def
+		    {
598def
+		      /* do not include new lines, log will append them */
598def
+		      size_t len = strlen(daemon->packet);
598def
+		      if (len > 0)
598def
+			{
598def
+			  --len;
598def
+			  if (daemon->packet[len] == '\n')
598def
+			    daemon->packet[len] = 0;
598def
+			}
598def
+		      send_event(event_fd, EVENT_SCRIPT_LOG, 0, daemon->packet);
598def
+		    }
598def
+		  fclose(fp);
598def
+		}
598def
+	    }
598def
+	  
598def
 	  /* reap our children's children, if necessary */
598def
 	  while (1)
598def
 	    {
598def
@@ -504,6 +544,15 @@ int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd)
598def
 	  
598def
 	  continue;
598def
 	}
598def
+
598def
+      if (!option_bool(OPT_DEBUG))
598def
+	{
598def
+	  /* map stdout/stderr of script to pipeout */
598def
+	  close(pipeout[0]);
598def
+	  dup2(pipeout[1], STDOUT_FILENO);
598def
+	  dup2(pipeout[1], STDERR_FILENO);
598def
+	  close(pipeout[1]);
598def
+	}
598def
       
598def
       if (data.action != ACTION_TFTP && data.action != ACTION_ARP)
598def
 	{
598def
@@ -579,7 +628,8 @@ int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd)
598def
 	    hostname = NULL;
598def
 	  
598def
 	  my_setenv("DNSMASQ_LOG_DHCP", option_bool(OPT_LOG_OPTS) ? "1" : NULL, &err;;
598def
-    }
598def
+	}
598def
+      
598def
       /* we need to have the event_fd around if exec fails */
598def
       if ((i = fcntl(event_fd, F_GETFD)) != -1)
598def
 	fcntl(event_fd, F_SETFD, i | FD_CLOEXEC);
598def
diff --git a/src/lease.c b/src/lease.c
598def
index 20cac90..64047f9 100644
598def
--- a/src/lease.c
598def
+++ b/src/lease.c
598def
@@ -21,94 +21,62 @@
598def
 static struct dhcp_lease *leases = NULL, *old_leases = NULL;
598def
 static int dns_dirty, file_dirty, leases_left;
598def
 
598def
-void lease_init(time_t now)
598def
+static int read_leases(time_t now, FILE *leasestream)
598def
 {
598def
   unsigned long ei;
598def
   struct all_addr addr;
598def
   struct dhcp_lease *lease;
598def
   int clid_len, hw_len, hw_type;
598def
-  FILE *leasestream;
598def
-  
598def
-  leases_left = daemon->dhcp_max;
598def
-  
598def
-  if (option_bool(OPT_LEASE_RO))
598def
-    {
598def
-      /* run "<lease_change_script> init" once to get the
598def
-	 initial state of the database. If leasefile-ro is
598def
-	 set without a script, we just do without any 
598def
-	 lease database. */
598def
-#ifdef HAVE_SCRIPT
598def
-      if (daemon->lease_change_command)
598def
-	{
598def
-	  strcpy(daemon->dhcp_buff, daemon->lease_change_command);
598def
-	  strcat(daemon->dhcp_buff, " init");
598def
-	  leasestream = popen(daemon->dhcp_buff, "r");
598def
-	}
598def
-      else
598def
+  int items;
598def
+  char *domain = NULL;
598def
+
598def
+  *daemon->dhcp_buff3 = *daemon->dhcp_buff2 = '\0';
598def
+
598def
+  /* client-id max length is 255 which is 255*2 digits + 254 colons
598def
+     borrow DNS packet buffer which is always larger than 1000 bytes
598def
+
598def
+     Check various buffers are big enough for the code below */
598def
+
598def
+#if (DHCP_BUFF_SZ < 255) || (MAXDNAME < 64) || (PACKETSZ+MAXDNAME+RRFIXEDSZ  < 764)
598def
+# error Buffer size breakage in leasefile parsing.
598def
 #endif
598def
-	{
598def
-          file_dirty = dns_dirty = 0;
598def
-          return;
598def
-        }
598def
 
598def
-    }
598def
-  else
598def
-    {
598def
-      /* NOTE: need a+ mode to create file if it doesn't exist */
598def
-      leasestream = daemon->lease_stream = fopen(daemon->lease_file, "a+");
598def
-      
598def
-      if (!leasestream)
598def
-	die(_("cannot open or create lease file %s: %s"), daemon->lease_file, EC_FILE);
598def
-      
598def
-      /* a+ mode leaves pointer at end. */
598def
-      rewind(leasestream);
598def
-    }
598def
-  
598def
-  /* client-id max length is 255 which is 255*2 digits + 254 colons 
598def
-     borrow DNS packet buffer which is always larger than 1000 bytes */
598def
-  if (leasestream)
598def
-    while (fscanf(leasestream, "%255s %255s", daemon->dhcp_buff3, daemon->dhcp_buff2) == 2)
598def
+    while ((items=fscanf(leasestream, "%255s %255s", daemon->dhcp_buff3, daemon->dhcp_buff2)) == 2)
598def
       {
598def
+	*daemon->namebuff = *daemon->dhcp_buff = *daemon->packet = '\0';
598def
+	hw_len = hw_type = clid_len = 0;
598def
+	
598def
 #ifdef HAVE_DHCP6
598def
 	if (strcmp(daemon->dhcp_buff3, "duid") == 0)
598def
 	  {
598def
 	    daemon->duid_len = parse_hex(daemon->dhcp_buff2, (unsigned char *)daemon->dhcp_buff2, 130, NULL, NULL);
598def
+	    if (daemon->duid_len < 0)
598def
+	      return 0;
598def
 	    daemon->duid = safe_malloc(daemon->duid_len);
598def
 	    memcpy(daemon->duid, daemon->dhcp_buff2, daemon->duid_len);
598def
 	    continue;
598def
 	  }
598def
 #endif
598def
-
598def
-	ei = atol(daemon->dhcp_buff3);
598def
 	
598def
 	if (fscanf(leasestream, " %64s %255s %764s",
598def
 		   daemon->namebuff, daemon->dhcp_buff, daemon->packet) != 3)
598def
-	  break;
598def
+	  return 0;
598def
 	
598def
-	clid_len = 0;
598def
-	if (strcmp(daemon->packet, "*") != 0)
598def
-	  clid_len = parse_hex(daemon->packet, (unsigned char *)daemon->packet, 255, NULL, NULL);
598def
-	
598def
-	if (inet_pton(AF_INET, daemon->namebuff, &addr.addr.addr4) &&
598def
-	    (lease = lease4_allocate(addr.addr.addr4)))
598def
+	if (inet_pton(AF_INET, daemon->namebuff, &addr.addr.addr4))
598def
 	  {
598def
+	    if ((lease = lease4_allocate(addr.addr.addr4)))
598def
+	      domain = get_domain(lease->addr);
598def
+	    
598def
 	    hw_len = parse_hex(daemon->dhcp_buff2, (unsigned char *)daemon->dhcp_buff2, DHCP_CHADDR_MAX, NULL, &hw_type);
598def
 	    /* For backwards compatibility, no explict MAC address type means ether. */
598def
 	    if (hw_type == 0 && hw_len != 0)
598def
 	      hw_type = ARPHRD_ETHER; 
598def
-
598def
-	    lease_set_hwaddr(lease, (unsigned char *)daemon->dhcp_buff2, (unsigned char *)daemon->packet, 
598def
-			     hw_len, hw_type, clid_len, now, 0);
598def
-	    
598def
-	    if (strcmp(daemon->dhcp_buff, "*") !=  0)
598def
-	      lease_set_hostname(lease, daemon->dhcp_buff, 0, get_domain(lease->addr), NULL);
598def
 	  }
598def
 #ifdef HAVE_DHCP6
598def
 	else if (inet_pton(AF_INET6, daemon->namebuff, &addr.addr.addr6))
598def
 	  {
598def
 	    char *s = daemon->dhcp_buff2;
598def
 	    int lease_type = LEASE_NA;
598def
-	    int iaid;
598def
 
598def
 	    if (s[0] == 'T')
598def
 	      {
598def
@@ -116,23 +84,30 @@ void lease_init(time_t now)
598def
 		s++;
598def
 	      }
598def
 	    
598def
-	    iaid = strtoul(s, NULL, 10);
598def
-	    
598def
 	    if ((lease = lease6_allocate(&addr.addr.addr6, lease_type)))
598def
 	      {
598def
-		lease_set_hwaddr(lease, NULL, (unsigned char *)daemon->packet, 0, 0, clid_len, now, 0);
598def
-		lease_set_iaid(lease, iaid);
598def
-		if (strcmp(daemon->dhcp_buff, "*") !=  0)
598def
-		  lease_set_hostname(lease, daemon->dhcp_buff, 0, get_domain6((struct in6_addr *)lease->hwaddr), NULL);
598def
+		lease_set_iaid(lease, strtoul(s, NULL, 10));
598def
+		domain = get_domain6((struct in6_addr *)lease->hwaddr);
598def
 	      }
598def
 	  }
598def
 #endif
598def
 	else
598def
-	  break;
598def
+	  return 0;
598def
 
598def
 	if (!lease)
598def
 	  die (_("too many stored leases"), NULL, EC_MISC);
598def
-       	
598def
+
598def
+	if (strcmp(daemon->packet, "*") != 0)
598def
+	  clid_len = parse_hex(daemon->packet, (unsigned char *)daemon->packet, 255, NULL, NULL);
598def
+	
598def
+	lease_set_hwaddr(lease, (unsigned char *)daemon->dhcp_buff2, (unsigned char *)daemon->packet, 
598def
+			 hw_len, hw_type, clid_len, now, 0);
598def
+	
598def
+	if (strcmp(daemon->dhcp_buff, "*") !=  0)
598def
+	  lease_set_hostname(lease, daemon->dhcp_buff, 0, domain, NULL);
598def
+
598def
+	ei = atol(daemon->dhcp_buff3);
598def
+
598def
 #ifdef HAVE_BROKEN_RTC
598def
 	if (ei != 0)
598def
 	  lease->expires = (time_t)ei + now;
598def
@@ -148,7 +123,62 @@ void lease_init(time_t now)
598def
 	/* set these correctly: the "old" events are generated later from
598def
 	   the startup synthesised SIGHUP. */
598def
 	lease->flags &= ~(LEASE_NEW | LEASE_CHANGED);
598def
+	
598def
+	*daemon->dhcp_buff3 = *daemon->dhcp_buff2 = '\0';
598def
       }
598def
+    
598def
+    return (items == 0 || items == EOF);
598def
+}
598def
+
598def
+void lease_init(time_t now)
598def
+{
598def
+  FILE *leasestream;
598def
+
598def
+  leases_left = daemon->dhcp_max;
598def
+
598def
+  if (option_bool(OPT_LEASE_RO))
598def
+    {
598def
+      /* run "<lease_change_script> init" once to get the
598def
+	 initial state of the database. If leasefile-ro is
598def
+	 set without a script, we just do without any
598def
+	 lease database. */
598def
+#ifdef HAVE_SCRIPT
598def
+      if (daemon->lease_change_command)
598def
+	{
598def
+	  strcpy(daemon->dhcp_buff, daemon->lease_change_command);
598def
+	  strcat(daemon->dhcp_buff, " init");
598def
+	  leasestream = popen(daemon->dhcp_buff, "r");
598def
+	}
598def
+      else
598def
+#endif
598def
+	{
598def
+          file_dirty = dns_dirty = 0;
598def
+          return;
598def
+        }
598def
+
598def
+    }
598def
+  else
598def
+    {
598def
+      /* NOTE: need a+ mode to create file if it doesn't exist */
598def
+      leasestream = daemon->lease_stream = fopen(daemon->lease_file, "a+");
598def
+
598def
+      if (!leasestream)
598def
+	die(_("cannot open or create lease file %s: %s"), daemon->lease_file, EC_FILE);
598def
+
598def
+      /* a+ mode leaves pointer at end. */
598def
+      rewind(leasestream);
598def
+    }
598def
+
598def
+  if (leasestream)
598def
+    {
598def
+      if (!read_leases(now, leasestream))
598def
+	my_syslog(MS_DHCP | LOG_ERR, _("failed to parse lease database, invalid line: %s %s %s %s ..."),
598def
+		  daemon->dhcp_buff3, daemon->dhcp_buff2,
598def
+		  daemon->namebuff, daemon->dhcp_buff);
598def
+
598def
+      if (ferror(leasestream))
598def
+	die(_("failed to read lease file %s: %s"), daemon->lease_file, EC_FILE);
598def
+    }
598def
   
598def
 #ifdef HAVE_SCRIPT
598def
   if (!daemon->lease_stream)
598def
@@ -162,6 +192,7 @@ void lease_init(time_t now)
598def
 	    errno = ENOENT;
598def
 	  else if (WEXITSTATUS(rc) == 126)
598def
 	    errno = EACCES;
598def
+
598def
 	  die(_("cannot run lease-init script %s: %s"), daemon->lease_change_command, EC_FILE);
598def
 	}
598def
       
598def
diff --git a/src/log.c b/src/log.c
598def
index 8e66629..5fc860b 100644
598def
--- a/src/log.c
598def
+++ b/src/log.c
598def
@@ -288,7 +288,9 @@ void my_syslog(int priority, const char *format, ...)
598def
     func = "-tftp";
598def
   else if ((LOG_FACMASK & priority) == MS_DHCP)
598def
     func = "-dhcp";
598def
-      
598def
+  else if ((LOG_FACMASK & priority) == MS_SCRIPT)
598def
+    func = "-script";
598def
+	    
598def
 #ifdef LOG_PRI
598def
   priority = LOG_PRI(priority);
598def
 #else
598def
diff --git a/src/rfc3315.c b/src/rfc3315.c
598def
index 3f4d69c..a3715cd 100644
598def
--- a/src/rfc3315.c
598def
+++ b/src/rfc3315.c
598def
@@ -1975,7 +1975,7 @@ static void log6_packet(struct state *state, char *type, struct in6_addr *addr,
598def
 
598def
   if (addr)
598def
     {
598def
-      inet_ntop(AF_INET6, addr, daemon->dhcp_buff2, 255);
598def
+      inet_ntop(AF_INET6, addr, daemon->dhcp_buff2, DHCP_BUFF_SZ - 1);
598def
       strcat(daemon->dhcp_buff2, " ");
598def
     }
598def
   else
598def
-- 
598def
2.9.3
598def