>From 2c4ac45a3f881564cc0b46094b88af35af3c66eb Mon Sep 17 00:00:00 2001
From: Phil Mayers <p.mayers@imperial.ac.uk>
Date: Mon, 11 Oct 2010 15:50:27 +0100
Subject: [PATCH 3/4] move SoH code into main server

---
 src/include/soh.h                             |    2 +-
 src/lib/Makefile                              |    2 +-
 src/main/Makefile.in                          |    3 +-
 src/main/soh.c                                |   43 +++++++++++++------------
 src/modules/rlm_eap/types/rlm_eap_peap/peap.c |    2 +-
 src/modules/rlm_soh/rlm_soh.c                 |    4 +-
 6 files changed, 29 insertions(+), 27 deletions(-)

diff --git a/src/include/soh.h b/src/include/soh.h
index 7dc17f9..27954a1 100644
--- a/src/include/soh.h
+++ b/src/include/soh.h
@@ -32,7 +32,7 @@ RCSIDH(soh_h, "$Id$")
 extern "C" {
 #endif
 
-int soh_verify(VALUE_PAIR *sohvp, const uint8_t *data, unsigned int data_len);
+int soh_verify(REQUEST *request, VALUE_PAIR *sohvp, const uint8_t *data, unsigned int data_len);
 uint16_t soh_pull_be_16(const uint8_t *p);
 uint32_t soh_pull_be_24(const uint8_t *p);
 uint32_t soh_pull_be_32(const uint8_t *p);
diff --git a/src/lib/Makefile b/src/lib/Makefile
index b3bf7fe..286cc02 100644
--- a/src/lib/Makefile
+++ b/src/lib/Makefile
@@ -10,7 +10,7 @@ SRCS		= dict.c filters.c hash.c hmac.c hmacsha1.c isaac.c log.c \
 		  misc.c missing.c md4.c md5.c print.c radius.c rbtree.c \
 		  sha1.c snprintf.c strlcat.c strlcpy.c token.c udpfromto.c \
 		  valuepair.c fifo.c packet.c event.c getaddrinfo.c vqp.c \
-		  heap.c dhcp.c soh.c
+		  heap.c dhcp.c
 
 LT_OBJS		= $(SRCS:.c=.lo)
 
diff --git a/src/main/Makefile.in b/src/main/Makefile.in
index d626478..5459bc6 100644
--- a/src/main/Makefile.in
+++ b/src/main/Makefile.in
@@ -8,7 +8,8 @@ SERVER_SRCS	= acct.c auth.c client.c conffile.c crypt.c exec.c files.c \
 		  listen.c log.c mainconfig.c modules.c modcall.c \
 		  radiusd.c stats.c \
 		  session.c threads.c util.c valuepair.c version.c  \
-		  xlat.c event.c realms.c evaluate.c vmps.c detail.c
+		  xlat.c event.c realms.c evaluate.c vmps.c detail.c \
+		  soh.c
 
 SERVER_OBJS	+= $(SERVER_SRCS:.c=.lo)
 
diff --git a/src/main/soh.c b/src/main/soh.c
index 3310c36..ea078f5 100644
--- a/src/main/soh.c
+++ b/src/main/soh.c
@@ -23,6 +23,7 @@
 #include <freeradius-devel/ident.h>
 RCSID("$Id$")
 
+#include <freeradius-devel/radiusd.h>
 #include <freeradius-devel/soh.h>
 
 /*
@@ -101,7 +102,7 @@ uint32_t soh_pull_be_32(const uint8_t *p) {
  * unknown types; we need to know their length ahead of time. Therefore, we abort
  * if we find an unknown type.
  */
-static int eapsoh_mstlv(VALUE_PAIR *sohvp, const uint8_t *p, unsigned int data_len) {
+static int eapsoh_mstlv(REQUEST *request, VALUE_PAIR *sohvp, const uint8_t *p, unsigned int data_len) {
 	VALUE_PAIR *vp;
 	uint8_t c;
 	int t;
@@ -116,7 +117,7 @@ static int eapsoh_mstlv(VALUE_PAIR *sohvp, const uint8_t *p, unsigned int data_l
 				 * MS-SOH section 2.2.4.1
 				 */
 				if (data_len < 18) {
-					DEBUG("insufficient data for MS-Machine-Inventory-Packet\n");
+					RDEBUG("insufficient data for MS-Machine-Inventory-Packet\n");
 					return 0;
 				}
 				data_len -= 18;
@@ -171,7 +172,7 @@ static int eapsoh_mstlv(VALUE_PAIR *sohvp, const uint8_t *p, unsigned int data_l
 				/* MS-Packet-Info
 				 * MS-SOH 2.2.4.3
 				 */
-				DEBUG("SoH MS-Packet-Info %s vers=%i\n", *p & 0x10 ? "request" : "response", *p & 0xf);
+				RDEBUG("SoH MS-Packet-Info %s vers=%i\n", *p & 0x10 ? "request" : "response", *p & 0xf);
 				p++;
 				data_len--;
 				break;
@@ -252,7 +253,7 @@ static int eapsoh_mstlv(VALUE_PAIR *sohvp, const uint8_t *p, unsigned int data_l
 				break;
 
 			default:
-				DEBUG("SoH Unknown MS TV %i stopping\n", c);
+				RDEBUG("SoH Unknown MS TV %i stopping\n", c);
 				return 0;
 		}
 	}
@@ -304,7 +305,7 @@ static const char* healthclass2str(uint8_t hc) {
 	return NULL;
 }
 
-int soh_verify(VALUE_PAIR *sohvp, const uint8_t *data, unsigned int data_len) {
+int soh_verify(REQUEST *request, VALUE_PAIR *sohvp, const uint8_t *data, unsigned int data_len) {
 
 	VALUE_PAIR *vp;
 	eap_soh hdr;
@@ -318,14 +319,14 @@ int soh_verify(VALUE_PAIR *sohvp, const uint8_t *data, unsigned int data_len) {
 	hdr.tlv_vendor = soh_pull_be_32(data); data += 4;
 
 	if (hdr.tlv_type != 7 || hdr.tlv_vendor != 0x137) {
-		DEBUG("SoH payload is %i %08x not a ms-vendor packet\n", hdr.tlv_type, hdr.tlv_vendor);
+		RDEBUG("SoH payload is %i %08x not a ms-vendor packet\n", hdr.tlv_type, hdr.tlv_vendor);
 		return -1;
 	}
 
 	hdr.soh_type = soh_pull_be_16(data); data += 2;
 	hdr.soh_len = soh_pull_be_16(data); data += 2;
 	if (hdr.soh_type != 1) {
-		DEBUG("SoH tlv %04x is not a response\n", hdr.soh_type);
+		RDEBUG("SoH tlv %04x is not a response\n", hdr.soh_type);
 		return -1;
 	}
 
@@ -338,13 +339,13 @@ int soh_verify(VALUE_PAIR *sohvp, const uint8_t *data, unsigned int data_len) {
 
 
 	if (resp.outer_type!=7 || resp.vendor != 0x137) {
-		DEBUG("SoH response outer type %i/vendor %08x not recognised\n", resp.outer_type, resp.vendor);
+		RDEBUG("SoH response outer type %i/vendor %08x not recognised\n", resp.outer_type, resp.vendor);
 		return -1;
 	}
 	switch (resp.inner_type) {
 		case 1:
 			/* no mode sub-header */
-			DEBUG("SoH without mode subheader\n");
+			RDEBUG("SoH without mode subheader\n");
 			break;
 		case 2:
 			mode.outer_type = soh_pull_be_16(data); data += 2;
@@ -356,13 +357,13 @@ int soh_verify(VALUE_PAIR *sohvp, const uint8_t *data, unsigned int data_len) {
 			data += 2;
 
 			if (mode.outer_type != 7 || mode.vendor != 0x137 || mode.content_type != 0) {
-				DEBUG("SoH mode subheader outer type %i/vendor %08x/content type %i invalid\n", mode.outer_type, mode.vendor, mode.content_type);
+				RDEBUG("SoH mode subheader outer type %i/vendor %08x/content type %i invalid\n", mode.outer_type, mode.vendor, mode.content_type);
 				return -1;
 			}
-			DEBUG("SoH with mode subheader\n");
+			RDEBUG("SoH with mode subheader\n");
 			break;
 		default:
-			DEBUG("SoH invalid inner type %i\n", resp.inner_type);
+			RDEBUG("SoH invalid inner type %i\n", resp.inner_type);
 			return -1;
 	}
 
@@ -400,7 +401,7 @@ int soh_verify(VALUE_PAIR *sohvp, const uint8_t *data, unsigned int data_len) {
 				 */
 				curr_shid = soh_pull_be_24(data);
 				curr_shid_c = data[3];
-				DEBUG("SoH System-Health-ID vendor %08x component=%i\n", curr_shid, curr_shid_c);
+				RDEBUG("SoH System-Health-ID vendor %08x component=%i\n", curr_shid, curr_shid_c);
 				break;
 
 			case 7:
@@ -411,10 +412,10 @@ int soh_verify(VALUE_PAIR *sohvp, const uint8_t *data, unsigned int data_len) {
 				 * N bytes payload; for Microsoft component#0 this is the MS TV stuff
 				 */
 				if (curr_shid==0x137 && curr_shid_c==0) {
-					DEBUG("SoH MS type-value payload\n");
-					eapsoh_mstlv(sohvp, data + 4, tlv.tlv_len - 4);
+					RDEBUG("SoH MS type-value payload\n");
+					eapsoh_mstlv(request, sohvp, data + 4, tlv.tlv_len - 4);
 				} else {
-					DEBUG("SoH unhandled vendor-specific TLV %08x/component=%i %i bytes payload\n", curr_shid, curr_shid_c, tlv.tlv_len);
+					RDEBUG("SoH unhandled vendor-specific TLV %08x/component=%i %i bytes payload\n", curr_shid, curr_shid_c, tlv.tlv_len);
 				}
 				break;
 
@@ -424,7 +425,7 @@ int soh_verify(VALUE_PAIR *sohvp, const uint8_t *data, unsigned int data_len) {
 				 *
 				 * 1 byte integer
 				 */
-				DEBUG("SoH Health-Class %i\n", data[0]);
+				RDEBUG("SoH Health-Class %i\n", data[0]);
 				curr_hc = data[0];
 				break;
 
@@ -434,7 +435,7 @@ int soh_verify(VALUE_PAIR *sohvp, const uint8_t *data, unsigned int data_len) {
 				 *
 				 * 1 byte integer
 				 */
-				DEBUG("SoH Software-Version %i\n", data[0]);
+				RDEBUG("SoH Software-Version %i\n", data[0]);
 				break;
 
 			case 11:
@@ -450,14 +451,14 @@ int soh_verify(VALUE_PAIR *sohvp, const uint8_t *data, unsigned int data_len) {
 				 *  1 bit - 1==product up-to-date
 				 *  1 bit - 1==product enabled
 				 */
-				DEBUG("SoH Health-Class-Status - current shid=%08x component=%i\n", curr_shid, curr_shid_c);
+				RDEBUG("SoH Health-Class-Status - current shid=%08x component=%i\n", curr_shid, curr_shid_c);
 
 				if (curr_shid==0x137 && curr_shid_c==128) {
 
 					const char *s, *t;
 					uint32_t hcstatus = soh_pull_be_32(data);
 
-					DEBUG("SoH Health-Class-Status microsoft DWORD=%08x\n", hcstatus);
+					RDEBUG("SoH Health-Class-Status microsoft DWORD=%08x\n", hcstatus);
 
 					vp = pairmake("SoH-MS-Windows-Health-Status", NULL, T_OP_EQ);
 					switch (curr_hc) {
@@ -566,7 +567,7 @@ int soh_verify(VALUE_PAIR *sohvp, const uint8_t *data, unsigned int data_len) {
 				break;
 
 			default:
-				DEBUG("SoH Unknown TLV %i len=%i\n", tlv.tlv_type, tlv.tlv_len);
+				RDEBUG("SoH Unknown TLV %i len=%i\n", tlv.tlv_type, tlv.tlv_len);
 				break;
 		}
 
diff --git a/src/modules/rlm_eap/types/rlm_eap_peap/peap.c b/src/modules/rlm_eap/types/rlm_eap_peap/peap.c
index 13424a8..9ce9c46 100644
--- a/src/modules/rlm_eap/types/rlm_eap_peap/peap.c
+++ b/src/modules/rlm_eap/types/rlm_eap_peap/peap.c
@@ -194,7 +194,7 @@ static VALUE_PAIR* eapsoh_verify(REQUEST *request, const uint8_t *data, unsigned
 	}
 
 
-	rv = soh_verify(vp, data, data_len - 8);
+	rv = soh_verify(request, vp, data, data_len - 8);
 	if (rv<0) {
 		RDEBUG("SoH - error decoding payload: %s", fr_strerror());
 	} else {
diff --git a/src/modules/rlm_soh/rlm_soh.c b/src/modules/rlm_soh/rlm_soh.c
index 027e0f6..4cb7aad 100644
--- a/src/modules/rlm_soh/rlm_soh.c
+++ b/src/modules/rlm_soh/rlm_soh.c
@@ -176,7 +176,7 @@ static int soh_postauth(UNUSED void * instance, REQUEST *request)
 					} else {
 						RDEBUG("SoH decoding NAP from DHCP request");
 						/* SoH payload */
-						soh_verify(request->packet->vps, data, vlen);
+						soh_verify(request, request->packet->vps, data, vlen);
 					}
 					break;
 				default:
@@ -205,7 +205,7 @@ static int soh_authorize(UNUSED void * instance, REQUEST *request)
 
 	RDEBUG("SoH radius VP found");
 	/* decode it */
-	rv = soh_verify(request->packet->vps, vp->vp_octets, vp->length);
+	rv = soh_verify(request, request->packet->vps, vp->vp_octets, vp->length);
 
 	return RLM_MODULE_OK;
 }
-- 
1.6.6.1

