Joe Maimon wrote:
Hello all,OK this patch seems to do it. I took the path of least resistance.
I am looking into adding the attribute client-short-name to be treated much as client-ip-address is in rlm_preprocess.
However there seems to be two ways of going about obtaining the information.
1) Lookup the client name based on the request->packet->src_ipaddr
2) Modify the request structure to store the client.
Any suggestions?
Thanks, Joe
Things done by the patch.
1) Move the code which adds client-ip-address to its own function , and updating calls to it.
2) Add attribute client-short-name
3) Add code to new function to add client-short-name to the request pairs if we can figure it out.
4) Update comments
- List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html
Only in freeradius-0.9.3-jm/libltdl: stamp-h1
diff -ur freeradius-0.9.3/share/dictionary freeradius-0.9.3-jm/share/dictionary
--- freeradius-0.9.3/share/dictionary Wed Aug 27 12:00:15 2003
+++ freeradius-0.9.3-jm/share/dictionary Sun Nov 30 12:10:50 2003
@@ -229,6 +229,7 @@
ATTRIBUTE Rewrite-Rule 1078 string
ATTRIBUTE Sql-Group 1079 string
ATTRIBUTE Response-Packet-Type 1080 integer
+ATTRIBUTE Client-Short-Name 1081 string
#
# Non-Protocol Attributes
diff -ur freeradius-0.9.3/src/include/radius.h freeradius-0.9.3-jm/src/include/radius.h
--- freeradius-0.9.3/src/include/radius.h Mon Apr 21 16:39:57 2003
+++ freeradius-0.9.3-jm/src/include/radius.h Sun Nov 30 12:12:44 2003
@@ -182,6 +182,7 @@
#define PW_REWRITE_RULE 1078
#define PW_SQL_GROUP 1079
#define PW_RESPONSE_PACKET_TYPE 1080
+#define PW_CLIENT_SHORT_NAME 1081
/*
* Integer Translations
diff -ur freeradius-0.9.3/src/modules/rlm_preprocess/rlm_preprocess.c
freeradius-0.9.3-jm/src/modules/rlm_preprocess/rlm_preprocess.c
--- freeradius-0.9.3/src/modules/rlm_preprocess/rlm_preprocess.c Mon Jul 7
15:17:31 2003
+++ freeradius-0.9.3-jm/src/modules/rlm_preprocess/rlm_preprocess.c Sun Nov 30
15:06:07 2003
@@ -564,7 +564,12 @@
/*
* If the NAS wasn't smart enought to add a NAS-IP-Address
* to the request, then add it ourselves.
+ *
+ * Note also that this is a server configuration item,
+ * and will NOT make it to any packets being sent from
+ * the server.
*/
+
static void add_nas_attr(REQUEST *request)
{
VALUE_PAIR *nas;
@@ -581,28 +586,68 @@
pairadd(&request->packet->vps, nas);
}
+}
+
+/*
+ * Note also that these are server configuration items,
+ * and will NOT make it to any packets being sent from
+ * the server.
+ */
+
+
+static void add_client_attr(REQUEST *request)
+{
+ VALUE_PAIR *client_attr = NULL;
+ RADCLIENT *client = NULL;
+
+
+
/*
* Add in a Client-IP-Address, to tell the user
* the source IP of the request. That is, the client,
*
* Note that this MAY BE different from the NAS-IP-Address,
* especially if the request is being proxied.
+ */
+
+ client_attr = pairfind(request->packet->vps, PW_CLIENT_IP_ADDRESS);
+ if (!client_attr) {
+ client_attr = paircreate(PW_CLIENT_IP_ADDRESS, PW_TYPE_IPADDR);
+ if (!client_attr) {
+ radlog(L_ERR, "No memory");
+ exit(1);
+ }
+ client_attr->lvalue = request->packet->src_ipaddr;
+ ip_hostname(client_attr->strvalue, sizeof(client_attr->strvalue),
client_attr->lvalue);
+ pairadd(&request->packet->vps, client_attr);
+ }
+
+ /*
+ * Add in a Client-Short-Name, so that we may match on short
+ * name of the client who made the request
*
- * Note also that this is a server configuration item,
- * and will NOT make it to any packets being sent from
- * the server.
*/
- nas = paircreate(PW_CLIENT_IP_ADDRESS, PW_TYPE_IPADDR);
- if (!nas) {
- radlog(L_ERR, "No memory");
- exit(1);
+
+ client_attr = NULL;
+ client = client_find(request->packet->src_ipaddr);
+ if(!client)
+ return;
+
+ client_attr = pairfind(request->packet->vps, PW_CLIENT_SHORT_NAME);
+ if (!client_attr) {
+ client_attr = paircreate(PW_CLIENT_SHORT_NAME, PW_TYPE_STRING);
+ if (!client_attr) {
+ radlog(L_ERR, "No memory");
+ exit(1);
+ }
+
+
strncpy(client_attr->strvalue,client->shortname,sizeof(client->shortname)-1);
+ client_attr->strvalue[sizeof(client->shortname)-1] = '\0';
+ pairadd(&request->packet->vps, client_attr);
}
- nas->lvalue = request->packet->src_ipaddr;
- ip_hostname(nas->strvalue, sizeof(nas->strvalue), nas->lvalue);
- pairadd(&request->packet->vps, nas);
+
}
-
/*
* Initialize.
*/
@@ -701,6 +746,7 @@
* comparisons.
*/
add_nas_attr(request);
+ add_client_attr(request);
hints_setup(data->hints, request);
@@ -758,6 +804,7 @@
* Ensure that we log the NAS IP Address in the packet.
*/
add_nas_attr(request);
+ add_client_attr(request);
r = hints_setup(data->hints, request);
