--- dict.c	2007-07-11 10:29:29.000000000 -0700
+++ dict.c.new	2010-05-21 11:03:22.831879800 -0700
@@ -1,5 +1,5 @@
 /*
- * $Id: dict.c,v 1.10 2007/07/11 17:29:29 cparker Exp $
+ * $Id: dict.c,v 1.1.1.1 2010/04/22 16:02:05 XYPRO.SCOTTN Exp $
  *
  * Copyright (C) 1995,1996,1997 Lars Fenneberg
  *
@@ -18,6 +18,203 @@
 #include <includes.h>
 #include <freeradius-client.h>
 
+static int rc_add_attribute(rc_handle* rh,
+			    char *namestr,
+			    char *valstr,
+			    char *typestr,
+			    char *optstr,
+			    int line_no,
+			    const char *filename)
+{
+
+	DICT_ATTR      *attr;
+	DICT_VENDOR    *dvend;
+	int             value;
+	int             type;
+	char		*cp;
+	/*
+	 * Validate all entries
+	 */
+	if (strlen (namestr) > NAME_LENGTH)
+	{
+		rc_log(LOG_ERR, "rc_read_dictionary: invalid name length on line %d of dictionary %s",
+			 line_no, filename);
+		return -1;
+	}
+
+	if (!isdigit (*valstr))
+	{
+		rc_log(LOG_ERR,
+		 "rc_read_dictionary: invalid value on line %d of dictionary %s",
+			 line_no, filename);
+		return -1;
+	}
+	value = atoi (valstr);
+
+	if (strcmp (typestr, "string") == 0)
+	{
+		type = PW_TYPE_STRING;
+	}
+	else if (strcmp (typestr, "integer") == 0)
+	{
+		type = PW_TYPE_INTEGER;
+	}
+	else if (strcmp (typestr, "ipaddr") == 0)
+	{
+		type = PW_TYPE_IPADDR;
+	}
+	else if (strcmp (typestr, "date") == 0)
+	{
+		type = PW_TYPE_DATE;
+	}
+	else
+	{
+		rc_log(LOG_ERR,
+		  "rc_read_dictionary: invalid type on line %d of dictionary %s",
+			 line_no, filename);
+		return -1;
+	}
+
+	dvend = NULL;
+	if (optstr[0] != '\0') {
+		char *cp1;
+		for (cp1 = optstr; cp1 != NULL; cp1 = cp) {
+			cp = strchr(cp1, ',');
+			if (cp != NULL) {
+				*cp = '\0';
+				cp++;
+			}
+			if (strncmp(cp1, "vendor=", 7) == 0)
+				cp1 += 7;
+			dvend = rc_dict_findvend(rh, cp1);
+			if (dvend == NULL) {
+				rc_log(LOG_ERR,
+				 "rc_read_dictionary: unknown Vendor-Id %s on line %d of dictionary %s",
+					 cp1, line_no, filename);
+				return -1;
+			}
+		}
+	}
+
+	/* Create a new attribute for the list */
+	if ((attr = malloc (sizeof (DICT_ATTR))) == NULL)
+	{
+		rc_log(LOG_CRIT, "rc_read_dictionary: out of memory");
+		return -1;
+	}
+	strcpy (attr->name, namestr);
+	attr->value = value;
+	attr->type = type;
+
+	if (dvend != NULL)
+		attr->value |= (dvend->vendorpec << 16);
+
+	/* Insert it into the list */
+	attr->next = rh->dictionary_attributes;
+	rh->dictionary_attributes = attr;
+
+	return 0;
+}
+
+static int rc_add_value(rc_handle *rh, 
+			    char *attrstr, 
+			    char *namestr, 
+			    char *valstr,
+			    int line_no,
+			    const char *filename)
+{
+	DICT_VALUE     *dval;
+	int             value;
+
+	/*
+	 * Validate all entries
+	 */
+	if (strlen (attrstr) > NAME_LENGTH)
+	{
+		rc_log(LOG_ERR,
+      "rc_read_dictionary: invalid attribute length on line %d of dictionary %s",
+			 line_no, filename);
+		return -1;
+	}
+
+	if (strlen (namestr) > NAME_LENGTH)
+	{
+		rc_log(LOG_ERR,
+	   "rc_read_dictionary: invalid name length on line %d of dictionary %s",
+			 line_no, filename);
+		return -1;
+	}
+
+	if (!isdigit (*valstr))
+	{
+		rc_log(LOG_ERR,
+		 "rc_read_dictionary: invalid value on line %d of dictionary %s",
+			 line_no, filename);
+		return -1;
+	}
+	value = atoi (valstr);
+
+	/* Create a new VALUE entry for the list */
+	if ((dval = malloc (sizeof (DICT_VALUE))) == NULL)
+	{
+		rc_log(LOG_CRIT, "rc_read_dictionary: out of memory");
+		return -1;
+	}
+	strcpy (dval->attrname, attrstr);
+	strcpy (dval->name, namestr);
+	dval->value = value;
+
+	/* Insert it into the list */
+	dval->next = rh->dictionary_values;
+	rh->dictionary_values = dval;
+
+	return 0;
+}
+
+static int rc_add_vendor(rc_handle *rh, 
+			    char *attrstr, 
+			    char *valstr,
+			    int line_no,
+			    const char *filename)
+{
+	DICT_VENDOR    *dvend;
+	int             value;
+
+	/* Validate all entries */
+	if (strlen (attrstr) > NAME_LENGTH)
+	{
+		rc_log(LOG_ERR,
+		 "rc_read_dictionary: invalid attribute length on line %d of dictionary %s",
+			 line_no, filename);
+		return -1;
+	}
+
+	if (!isdigit (*valstr))
+	{
+		rc_log(LOG_ERR,
+		 "rc_read_dictionary: invalid Vendor-Id on line %d of dictionary %s",
+			 line_no, filename);
+		return -1;
+	}
+	value = atoi (valstr);
+
+	/* Create a new VENDOR entry for the list */
+	dvend = malloc(sizeof(DICT_VENDOR));
+	if (dvend == NULL)
+	{
+		rc_log(LOG_CRIT, "rc_read_dictionary: out of memory");
+		return -1;
+	}
+	strcpy (dvend->vendorname, attrstr);
+	dvend->vendorpec = value;
+
+	/* Insert it into the list */
+	dvend->next = rh->dictionary_vendors;
+	rh->dictionary_vendors = dvend;
+
+	return 0;
+}
+
 /*
  * Function: rc_read_dictionary
  *
@@ -27,7 +224,8 @@
  *
  */
 
-int rc_read_dictionary (rc_handle *rh, const char *filename)
+static int rc_read_dictionary_internal (rc_handle *rh, const char *filename,
+char **p_ifilename)
 {
 	FILE           *dictfd;
 	char            dummystr[AUTH_ID_LEN];
@@ -36,7 +234,7 @@
 	char            attrstr[AUTH_ID_LEN];
 	char            typestr[AUTH_ID_LEN];
 	char		optstr[AUTH_ID_LEN];
-	char		*cp, *ifilename;
+	char		*cp , *ifilename;
 	int             line_no;
 	DICT_ATTR      *attr;
 	DICT_VALUE     *dval;
@@ -84,91 +282,13 @@
 				return -1;
 			}
 
-			/*
-			 * Validate all entries
-			 */
-			if (strlen (namestr) > NAME_LENGTH)
+			if (rc_add_attribute(rh, namestr, valstr, 
+						typestr, optstr,
+						line_no, filename) == -1)
 			{
-				rc_log(LOG_ERR, "rc_read_dictionary: invalid name length on line %d of dictionary %s",
-					 line_no, filename);
 				fclose(dictfd);
 				return -1;
 			}
-
-			if (!isdigit (*valstr))
-			{
-				rc_log(LOG_ERR,
-				 "rc_read_dictionary: invalid value on line %d of dictionary %s",
-					 line_no, filename);
-				fclose(dictfd);
-				return -1;
-			}
-			value = atoi (valstr);
-
-			if (strcmp (typestr, "string") == 0)
-			{
-				type = PW_TYPE_STRING;
-			}
-			else if (strcmp (typestr, "integer") == 0)
-			{
-				type = PW_TYPE_INTEGER;
-			}
-			else if (strcmp (typestr, "ipaddr") == 0)
-			{
-				type = PW_TYPE_IPADDR;
-			}
-			else if (strcmp (typestr, "date") == 0)
-			{
-				type = PW_TYPE_DATE;
-			}
-			else
-			{
-				rc_log(LOG_ERR,
-				  "rc_read_dictionary: invalid type on line %d of dictionary %s",
-					 line_no, filename);
-				fclose(dictfd);
-				return -1;
-			}
-
-			dvend = NULL;
-			if (optstr[0] != '\0') {
-				char *cp1;
-				for (cp1 = optstr; cp1 != NULL; cp1 = cp) {
-					cp = strchr(cp1, ',');
-					if (cp != NULL) {
-						*cp = '\0';
-						cp++;
-					}
-					if (strncmp(cp1, "vendor=", 7) == 0)
-						cp1 += 7;
-					dvend = rc_dict_findvend(rh, cp1);
-					if (dvend == NULL) {
-						rc_log(LOG_ERR,
-						 "rc_read_dictionary: unknown Vendor-Id %s on line %d of dictionary %s",
-							 cp1, line_no, filename);
-						fclose(dictfd);
-						return -1;
-					}
-				}
-			}
-
-			/* Create a new attribute for the list */
-			if ((attr = malloc (sizeof (DICT_ATTR))) == NULL)
-			{
-				rc_log(LOG_CRIT, "rc_read_dictionary: out of memory");
-				fclose(dictfd);
-				return -1;
-			}
-			strcpy (attr->name, namestr);
-			attr->value = value;
-			attr->type = type;
-
-			if (dvend != NULL)
-				attr->value |= (dvend->vendorpec << 16);
-
-			/* Insert it into the list */
-			attr->next = rh->dictionary_attributes;
-			rh->dictionary_attributes = attr;
 		}
 		else if (strncmp (buffer, "VALUE", 5) == 0)
 		{
@@ -183,51 +303,12 @@
 				return -1;
 			}
 
-			/*
-			 * Validate all entries
-			 */
-			if (strlen (attrstr) > NAME_LENGTH)
+			if (rc_add_value(rh, attrstr, namestr, valstr,
+					 line_no, filename) == -1)
 			{
-				rc_log(LOG_ERR,
-		      "rc_read_dictionary: invalid attribute length on line %d of dictionary %s",
-					 line_no, filename);
 				fclose(dictfd);
 				return -1;
 			}
-
-			if (strlen (namestr) > NAME_LENGTH)
-			{
-				rc_log(LOG_ERR,
-			   "rc_read_dictionary: invalid name length on line %d of dictionary %s",
-					 line_no, filename);
-				fclose(dictfd);
-				return -1;
-			}
-
-			if (!isdigit (*valstr))
-			{
-				rc_log(LOG_ERR,
-				 "rc_read_dictionary: invalid value on line %d of dictionary %s",
-					 line_no, filename);
-				fclose(dictfd);
-				return -1;
-			}
-			value = atoi (valstr);
-
-			/* Create a new VALUE entry for the list */
-			if ((dval = malloc (sizeof (DICT_VALUE))) == NULL)
-			{
-				rc_log(LOG_CRIT, "rc_read_dictionary: out of memory");
-				fclose(dictfd);
-				return -1;
-			}
-			strcpy (dval->attrname, attrstr);
-			strcpy (dval->name, namestr);
-			dval->value = value;
-
-			/* Insert it into the list */
-			dval->next = rh->dictionary_values;
-			rh->dictionary_values = dval;
 		}
                 else if (strncmp (buffer, "$INCLUDE", 8) == 0)
                 {
@@ -245,7 +326,13 @@
 			if (namestr[0] != '/') {
 				cp = strrchr(filename, '/');
 				if (cp != NULL) {
-					ifilename = alloca(AUTH_ID_LEN);
+					if (*p_ifilename)
+					{
+					    free(*p_ifilename);
+					    *p_ifilename = NULL;
+					}
+					ifilename = malloc(AUTH_ID_LEN);
+					*p_ifilename = ifilename;
 					*cp = '\0';
 					sprintf(ifilename, "%s/%s", filename, namestr);
 					*cp = '/';
@@ -269,46 +356,86 @@
 				return -1;
 			}
 
-			/* Validate all entries */
-			if (strlen (attrstr) > NAME_LENGTH)
-			{
-				rc_log(LOG_ERR,
-				 "rc_read_dictionary: invalid attribute length on line %d of dictionary %s",
-					 line_no, filename);
-				fclose(dictfd);
-				return -1;
-			}
-
-			if (!isdigit (*valstr))
-			{
-				rc_log(LOG_ERR,
-				 "rc_read_dictionary: invalid Vendor-Id on line %d of dictionary %s",
-					 line_no, filename);
-				fclose(dictfd);
-				return -1;
-			}
-			value = atoi (valstr);
-
-			/* Create a new VENDOR entry for the list */
-			dvend = malloc(sizeof(DICT_VENDOR));
-			if (dvend == NULL)
+			if (rc_add_vendor(rh, attrstr, valstr, line_no, filename) == -1)
 			{
-				rc_log(LOG_CRIT, "rc_read_dictionary: out of memory");
 				fclose(dictfd);
 				return -1;
 			}
-			strcpy (dvend->vendorname, attrstr);
-			dvend->vendorpec = value;
-
-			/* Insert it into the list */
-			dvend->next = rh->dictionary_vendors;
-			rh->dictionary_vendors = dvend;
                 }
 	}
 	fclose (dictfd);
 	return 0;
 }
 
+int rc_read_dictionary (rc_handle *rh, const char *filename)
+{
+     char *ifilename = NULL;
+     int rc = rc_read_dictionary_internal(rh, filename, &ifilename);
+     if (ifilename != NULL)
+     	free(ifilename);
+    return rc;
+}
+
+int rc_load_dictionary(rc_handle *rh, const DICTIONARY_DATA* data)
+{
+	int		line_no = 0;
+	int		good = 1;
+	char            namestr[AUTH_ID_LEN];
+	char            valstr[AUTH_ID_LEN];
+	char            attrstr[AUTH_ID_LEN];
+	char            typestr[AUTH_ID_LEN];
+	char		optstr[AUTH_ID_LEN];
+
+	while (good && data->entry_type != DDATA_END)
+	{
+		++line_no;
+		switch (data->entry_type)
+		{
+		case DDATA_ATTRIBUTE:
+			strncpy(namestr, data->field1, AUTH_ID_LEN);
+			strncpy(valstr,  data->field2, AUTH_ID_LEN);
+			strncpy(typestr, data->field3, AUTH_ID_LEN);
+			strncpy(optstr,  data->field4, AUTH_ID_LEN);
+			if (rc_add_attribute(rh,
+			    namestr, valstr, typestr, optstr,
+			    line_no, "(internal)") == -1)
+			{
+				good = 0;
+			}
+			break;
+		case DDATA_VALUE:
+			strncpy(attrstr, data->field1, AUTH_ID_LEN);
+			strncpy(namestr, data->field2, AUTH_ID_LEN);
+			strncpy(valstr,  data->field3, AUTH_ID_LEN);
+			if (rc_add_value(rh,
+			    attrstr, namestr, valstr,
+			    line_no, "(internal)") == -1)
+			{
+				good = 0;
+			}
+			break;
+		case DDATA_VENDOR:
+			strncpy(attrstr, data->field1, AUTH_ID_LEN);
+			strncpy(valstr,  data->field2, AUTH_ID_LEN);
+			if (rc_add_vendor(rh,
+			    attrstr, valstr,
+			    line_no, "(internal)") == -1)
+			{
+				good = 0;
+			}
+			break;
+		default:
+			rc_log(LOG_ERR,
+			  "rc_load_dictionary: invalid entry type on item %d\n",
+			  line_no);
+			good = 0;
+			break;
+		}
+		++data;
+	}
+	return good ? 0 : -1;
+}
+
 /*
  * Function: rc_dict_getattr
  *
--- freeradius-client.h	2008-02-10 22:54:23.000000000 -0800
+++ freeradius-client.h.new	2010-05-21 11:01:45.458749400 -0700
@@ -1,5 +1,5 @@
 /*
- * $Id: freeradius-client.h,v 1.13 2008/02/11 06:54:23 sobomax Exp $
+ * $Id: freeradius-client.h,v 1.1.1.1 2010/04/22 16:02:04 XYPRO.SCOTTN Exp $
  *
  * Copyright (C) 1995,1996,1997,1998 Lars Fenneberg
  *
@@ -352,6 +352,20 @@
 	struct dict_vendor *next;
 } DICT_VENDOR;
 
+/* for a canned dictionary */
+#define DDATA_END		0
+#define DDATA_ATTRIBUTE		1
+#define DDATA_VALUE		2
+#define DDATA_VENDOR		3
+typedef struct dictionary_data
+{
+    int entry_type;
+    const char *field1;
+    const char *field2;
+    const char *field3;
+    const char *field4;
+} DICTIONARY_DATA;
+
 typedef struct value_pair
 {
 	char               name[NAME_LENGTH + 1];
@@ -454,6 +468,7 @@
 /*	dict.c			*/
 
 int rc_read_dictionary(rc_handle *, const char *);
+int rc_load_dictionary(rc_handle *, const DICTIONARY_DATA *);
 DICT_ATTR *rc_dict_getattr(const rc_handle *, int);
 DICT_ATTR *rc_dict_findattr(const rc_handle *, const char *);
 DICT_VALUE *rc_dict_findval(const rc_handle *, const char *);
