Blame SOURCES/freeradius-exec-dont-assume-request-presence-when-logging.patch

75e927
From 13c5c908548c29ab30ae2e274a5d2baa96eadae4 Mon Sep 17 00:00:00 2001
75e927
From: Nikolai Kondrashov <Nikolai.Kondrashov@redhat.com>
75e927
Date: Wed, 15 Oct 2014 20:03:11 +0300
75e927
Subject: [PATCH 1/4] exec: Don't assume request presence when logging
75e927
75e927
Use DEBUG* macros for logging, instead of RDEBUG* macros in
75e927
radius_start_program and radius_readfrom_program as these are not
75e927
guaranteed to be invoked with a valid request.
75e927
75e927
For example, not from most of the exec_trigger invocations.
75e927
---
75e927
 src/include/radiusd.h               |  2 +-
75e927
 src/main/exec.c                     | 22 +++++++++++-----------
75e927
 src/modules/rlm_mschap/rlm_mschap.c |  2 +-
75e927
 3 files changed, 13 insertions(+), 13 deletions(-)
75e927
75e927
diff --git a/src/include/radiusd.h b/src/include/radiusd.h
75e927
index 21d510b..ebe3a21 100644
75e927
--- a/src/include/radiusd.h
75e927
+++ b/src/include/radiusd.h
75e927
@@ -606,7 +606,7 @@ int		rad_virtual_server(REQUEST *);
75e927
 pid_t radius_start_program(char const *cmd, REQUEST *request, bool exec_wait,
75e927
 			   int *input_fd, int *output_fd,
75e927
 			   VALUE_PAIR *input_pairs, bool shell_escape);
75e927
-int radius_readfrom_program(REQUEST *request, int fd, pid_t pid, int timeout,
75e927
+int radius_readfrom_program(int fd, pid_t pid, int timeout,
75e927
 			    char *answer, int left);
75e927
 int radius_exec_program(REQUEST *request, char const *cmd, bool exec_wait, bool shell_escape,
75e927
 			char *user_msg, size_t msg_len, int timeout,
75e927
diff --git a/src/main/exec.c b/src/main/exec.c
75e927
index b421053..1188d0a 100644
75e927
--- a/src/main/exec.c
75e927
+++ b/src/main/exec.c
75e927
@@ -103,16 +103,16 @@ pid_t radius_start_program(char const *cmd, REQUEST *request, bool exec_wait,
75e927
 
75e927
 	argc = rad_expand_xlat(request, cmd, MAX_ARGV, argv, true, sizeof(argv_buf), argv_buf);
75e927
 	if (argc <= 0) {
75e927
-		RDEBUG("invalid command line '%s'.", cmd);
75e927
+		DEBUG("invalid command line '%s'.", cmd);
75e927
 		return -1;
75e927
 	}
75e927
 
75e927
 
75e927
 #ifndef NDEBUG
75e927
 	if (debug_flag > 2) {
75e927
-		RDEBUG3("executing cmd %s", cmd);
75e927
+		DEBUG3("executing cmd %s", cmd);
75e927
 		for (i = 0; i < argc; i++) {
75e927
-			RDEBUG3("\t[%d] %s", i, argv[i]);
75e927
+			DEBUG3("\t[%d] %s", i, argv[i]);
75e927
 		}
75e927
 	}
75e927
 #endif
75e927
@@ -124,13 +124,13 @@ pid_t radius_start_program(char const *cmd, REQUEST *request, bool exec_wait,
75e927
 	if (exec_wait) {
75e927
 		if (input_fd) {
75e927
 			if (pipe(to_child) != 0) {
75e927
-				RDEBUG("Couldn't open pipe to child: %s", fr_syserror(errno));
75e927
+				DEBUG("Couldn't open pipe to child: %s", fr_syserror(errno));
75e927
 				return -1;
75e927
 			}
75e927
 		}
75e927
 		if (output_fd) {
75e927
 			if (pipe(from_child) != 0) {
75e927
-				RDEBUG("Couldn't open pipe from child: %s", fr_syserror(errno));
75e927
+				DEBUG("Couldn't open pipe from child: %s", fr_syserror(errno));
75e927
 				/* safe because these either need closing or are == -1 */
75e927
 				close(to_child[0]);
75e927
 				close(to_child[1]);
75e927
@@ -206,7 +206,7 @@ pid_t radius_start_program(char const *cmd, REQUEST *request, bool exec_wait,
75e927
 		 */
75e927
 		devnull = open("/dev/null", O_RDWR);
75e927
 		if (devnull < 0) {
75e927
-			RDEBUG("Failed opening /dev/null: %s\n", fr_syserror(errno));
75e927
+			DEBUG("Failed opening /dev/null: %s\n", fr_syserror(errno));
75e927
 
75e927
 			/*
75e927
 			 *	Where the status code is interpreted as a module rcode
75e927
@@ -287,7 +287,7 @@ pid_t radius_start_program(char const *cmd, REQUEST *request, bool exec_wait,
75e927
 	 *	Parent process.
75e927
 	 */
75e927
 	if (pid < 0) {
75e927
-		RDEBUG("Couldn't fork %s: %s", argv[0], fr_syserror(errno));
75e927
+		DEBUG("Couldn't fork %s: %s", argv[0], fr_syserror(errno));
75e927
 		if (exec_wait) {
75e927
 			/* safe because these either need closing or are == -1 */
75e927
 			close(to_child[0]);
75e927
@@ -320,7 +320,7 @@ pid_t radius_start_program(char const *cmd, REQUEST *request, bool exec_wait,
75e927
 	return pid;
75e927
 #else
75e927
 	if (exec_wait) {
75e927
-		RDEBUG("Wait is not supported");
75e927
+		DEBUG("Wait is not supported");
75e927
 		return -1;
75e927
 	}
75e927
 
75e927
@@ -366,7 +366,7 @@ pid_t radius_start_program(char const *cmd, REQUEST *request, bool exec_wait,
75e927
  * @param left length of buffer.
75e927
  * @return -1 on error, or length of output.
75e927
  */
75e927
-int radius_readfrom_program(REQUEST *request, int fd, pid_t pid, int timeout,
75e927
+int radius_readfrom_program(int fd, pid_t pid, int timeout,
75e927
 			    char *answer, int left)
75e927
 {
75e927
 	int done = 0;
75e927
@@ -422,7 +422,7 @@ int radius_readfrom_program(REQUEST *request, int fd, pid_t pid, int timeout,
75e927
 		rcode = select(fd + 1, &fds, NULL, NULL, &wake);
75e927
 		if (rcode == 0) {
75e927
 		too_long:
75e927
-			RDEBUG("Child PID %u is taking too much time: forcing failure and killing child.", pid);
75e927
+			DEBUG("Child PID %u is taking too much time: forcing failure and killing child.", pid);
75e927
 			kill(pid, SIGTERM);
75e927
 			close(fd); /* should give SIGPIPE to child, too */
75e927
 
75e927
@@ -536,7 +536,7 @@ int radius_exec_program(REQUEST *request, char const *cmd, bool exec_wait, bool
75e927
 	}
75e927
 
75e927
 #ifndef __MINGW32__
75e927
-	len = radius_readfrom_program(request, from_child, pid, timeout, answer, sizeof(answer));
75e927
+	len = radius_readfrom_program(from_child, pid, timeout, answer, sizeof(answer));
75e927
 	if (len < 0) {
75e927
 		/*
75e927
 		 *	Failure - radius_readfrom_program will
75e927
diff --git a/src/modules/rlm_mschap/rlm_mschap.c b/src/modules/rlm_mschap/rlm_mschap.c
75e927
index 0101ddf..03f94a9 100644
75e927
--- a/src/modules/rlm_mschap/rlm_mschap.c
75e927
+++ b/src/modules/rlm_mschap/rlm_mschap.c
75e927
@@ -794,7 +794,7 @@ static int CC_HINT(nonnull (1, 2, 4, 5)) do_mschap_cpw(rlm_mschap_t *inst,
75e927
 		/*
75e927
 		 *  Read from the child
75e927
 		 */
75e927
-		len = radius_readfrom_program(request, from_child, pid, 10, buf, sizeof(buf));
75e927
+		len = radius_readfrom_program(from_child, pid, 10, buf, sizeof(buf));
75e927
 		if (len < 0) {
75e927
 			/* radius_readfrom_program will have closed from_child for us */
75e927
 			REDEBUG("Failure reading from child");
75e927
-- 
75e927
2.1.1
75e927