Index: extensions/app_radgw/radius.c
===================================================================
--- extensions/app_radgw/radius.c	(revision 979)
+++ extensions/app_radgw/radius.c	(revision 996)
@@ -57,8 +57,4 @@
 /*********************************************************************************/
 #include "rgw.h"
-
-/* Overwrite printf */
-#define printf(args...) fd_log_debug(args)
-
 
 static struct radius_attr_hdr *
@@ -237,15 +233,17 @@
 }
 
-
-static void print_char(char c)
+static char print_char_buf[5];
+
+static char * print_char(char c)
 {
 	if (c >= 32 && c < 127)
-		printf("%c", c);
+		sprintf(print_char_buf, "%c", c);
 	else
-		printf("<%02x>", c);
-}
-
-
-static void radius_msg_dump_attr_val(struct radius_attr_hdr *hdr)
+		sprintf(print_char_buf, "<%02x>", c);
+	return print_char_buf;
+}
+
+
+static char * radius_msg_dump_attr_val(struct radius_attr_hdr *hdr, char * outbuf, size_t buflen)
 {
 	struct radius_attr_type *attr;
@@ -253,4 +251,7 @@
 	unsigned char *pos;
 	u8 attrtype;
+	size_t offset = 0;
+	
+	memset(outbuf, 0, buflen);
 
 	attr = radius_get_attr_type(hdr->type);
@@ -266,8 +267,8 @@
 	switch (attrtype) {
 	case RADIUS_ATTR_TEXT:
-		printf("      Value: '");
+		snprintf(outbuf + strlen(outbuf), buflen - strlen(outbuf), "      Value: '");
 		for (i = 0; i < len; i++)
-			print_char(pos[i]);
-		printf("'\n");
+			snprintf(outbuf + strlen(outbuf), buflen - strlen(outbuf), "%s", print_char(pos[i]));
+		snprintf(outbuf + strlen(outbuf), buflen - strlen(outbuf), "'");
 		break;
 
@@ -276,7 +277,7 @@
 			struct in_addr addr;
 			os_memcpy(&addr, pos, 4);
-			printf("      Value: %s\n", inet_ntoa(addr));
+			snprintf(outbuf + strlen(outbuf), buflen - strlen(outbuf), "      Value: %s", inet_ntoa(addr));
 		} else
-			printf("      Invalid IP address length %d\n", len);
+			snprintf(outbuf + strlen(outbuf), buflen - strlen(outbuf), "      Invalid IP address length %d", len);
 		break;
 
@@ -287,14 +288,14 @@
 			struct in6_addr *addr = (struct in6_addr *) pos;
 			atxt = inet_ntop(AF_INET6, addr, buf, sizeof(buf));
-			printf("      Value: %s\n", atxt ? atxt : "?");
+			snprintf(outbuf + strlen(outbuf), buflen - strlen(outbuf), "      Value: %s", atxt ? atxt : "?");
 		} else
-			printf("      Invalid IPv6 address length %d\n", len);
+			snprintf(outbuf + strlen(outbuf), buflen - strlen(outbuf), "      Invalid IPv6 address length %d", len);
 		break;
 
 	case RADIUS_ATTR_INT32:
 		if (len == 4)
-			printf("      Value: %u\n", WPA_GET_BE32(pos));
+			snprintf(outbuf + strlen(outbuf), buflen - strlen(outbuf), "      Value: %u", WPA_GET_BE32(pos));
 		else
-			printf("      Invalid INT32 length %d\n", len);
+			snprintf(outbuf + strlen(outbuf), buflen - strlen(outbuf), "      Invalid INT32 length %d", len);
 		break;
 
@@ -302,10 +303,11 @@
 	case RADIUS_ATTR_UNDIST:
 	default:
-		printf("      Value:");
+		snprintf(outbuf + strlen(outbuf), buflen - strlen(outbuf), "      Value:");
 		for (i = 0; i < len; i++)
-			printf(" %02x", pos[i]);
-		printf("\n");
+			snprintf(outbuf + strlen(outbuf), buflen - strlen(outbuf), " %02x", pos[i]);
 		break;
 	}
+	
+	return outbuf;
 }
 
@@ -314,4 +316,5 @@
 {
 	unsigned char *auth;
+	char buf[256];
 	size_t i;
 	if (! TRACE_BOOL(FULL) )
@@ -329,5 +332,5 @@
 		struct radius_attr_hdr *attr = (struct radius_attr_hdr *)(msg->radius.buf + msg->radius.attr_pos[i]);
 		fd_log_debug("    - Type: 0x%02hhx (%s)       Len: %-3hhu", attr->type, rgw_msg_attrtype_str(attr->type), attr->length);
-		radius_msg_dump_attr_val(attr);
+		fd_log_debug("%s", radius_msg_dump_attr_val(attr, buf, sizeof(buf)));
 	}
 	if (has_meta && msg->ps_nb) {
@@ -336,5 +339,5 @@
 			struct radius_attr_hdr *attr = (struct radius_attr_hdr *)(msg->radius.buf + msg->radius.attr_pos[i]);
 			fd_log_debug("    - Type: 0x%02hhx (%s)       Len: %-3hhu", attr->type, rgw_msg_attrtype_str(attr->type), attr->length);
-			radius_msg_dump_attr_val(attr);
+			fd_log_debug("%s", radius_msg_dump_attr_val(attr, buf, sizeof(buf)));
 		}
 	}
@@ -355,5 +358,5 @@
 					   auth, MD5_MAC_LEN);
 		if (attr == NULL) {
-			printf("WARNING: Could not add Message-Authenticator\n");
+			fd_log_debug("WARNING: Could not add Message-Authenticator");
 			return -1;
 		}
@@ -365,5 +368,5 @@
 
 	if (msg->buf_used > 0xffff) {
-		printf("WARNING: too long RADIUS message (%lu)\n",
+		fd_log_debug("WARNING: too long RADIUS message (%lu)",
 		       (unsigned long) msg->buf_used);
 		return -1;
@@ -386,5 +389,5 @@
 				       auth, MD5_MAC_LEN);
 	    if (attr == NULL) {
-		    printf("WARNING: Could not add Message-Authenticator\n");
+		    fd_log_debug("WARNING: Could not add Message-Authenticator");
 		    return -1;
 	    }
@@ -410,5 +413,5 @@
 
 	if (msg->buf_used > 0xffff) {
-		printf("WARNING: too long RADIUS message (%lu)\n",
+		fd_log_debug("WARNING: too long RADIUS message (%lu)",
 		       (unsigned long) msg->buf_used);
 		return -1;
@@ -433,5 +436,5 @@
 
 	if (msg->buf_used > 0xffff) {
-		printf("WARNING: too long RADIUS messages (%lu)\n",
+		fd_log_debug("WARNING: too long RADIUS messages (%lu)",
 		       (unsigned long) msg->buf_used);
 	}
@@ -468,5 +471,5 @@
 
 	if (data_len > RADIUS_MAX_ATTR_LEN) {
-		printf("radius_msg_add_attr: too long attribute (%lu bytes)\n",
+		fd_log_debug("radius_msg_add_attr: too long attribute (%lu bytes)",
 		       (unsigned long) data_len);
 		return NULL;
@@ -692,5 +695,5 @@
 		if (tmp->type == RADIUS_ATTR_MESSAGE_AUTHENTICATOR) {
 			if (attr != NULL) {
-				printf("Multiple Message-Authenticator attributes in RADIUS message\n");
+				fd_log_debug("Multiple Message-Authenticator attributes in RADIUS message");
 				return 1;
 			}
@@ -700,5 +703,5 @@
 
 	if (attr == NULL) {
-		printf("No Message-Authenticator attribute found\n");
+		fd_log_debug("No Message-Authenticator attribute found");
 		return 1;
 	}
@@ -720,5 +723,5 @@
 
 	if (os_memcmp(orig, auth, MD5_MAC_LEN) != 0) {
-		printf("Invalid Message-Authenticator!\n");
+		fd_log_debug("Invalid Message-Authenticator!");
 		return 1;
 	}
@@ -736,5 +739,5 @@
 
 	if (sent_msg == NULL) {
-		printf("No matching Access-Request message found\n");
+		fd_log_debug("No matching Access-Request message found");
 		return 1;
 	}
@@ -757,5 +760,5 @@
 	md5_vector(4, addr, len, hash);
 	if (os_memcmp(hash, msg->hdr->authenticator, MD5_MAC_LEN) != 0) {
-		printf("Response Authenticator invalid!\n");
+		fd_log_debug("Response Authenticator invalid!");
 		return 1;
 	}
@@ -895,5 +898,5 @@
 	left = len - 2;
 	if (left % 16) {
-		printf("Invalid ms key len %lu\n", (unsigned long) left);
+		fd_log_debug("Invalid ms key len %lu", (unsigned long) left);
 		return NULL;
 	}
@@ -929,5 +932,5 @@
 
 	if (plain[0] == 0 || plain[0] > plen - 1) {
-		printf("Failed to decrypt MPPE key\n");
+		fd_log_debug("Failed to decrypt MPPE key");
 		os_free(plain);
 		return NULL;
