Enable building #WITHOUT_PROXY
[freeradius.git] / src / modules / rlm_jradius / rlm_jradius.c
index aa89c50..bd8179e 100644 (file)
@@ -67,6 +67,10 @@ static const int JRADIUS_checksimul   = 5;
 static const int JRADIUS_pre_proxy    = 6;
 static const int JRADIUS_post_proxy   = 7;
 static const int JRADIUS_post_auth    = 8;
+#ifdef WITH_COA
+static const int JRADIUS_recv_coa     = 9;
+static const int JRADIUS_send_coa     = 10;
+#endif
 
 #define LOG_PREFIX  "rlm_jradius: "
 #define MAX_HOSTS   4
@@ -780,7 +784,7 @@ static int read_vps(JRADIUS *inst, JRSOCK *jrsock, VALUE_PAIR **pl, int plen)
     /*
      *     Create new attribute
      */
-    vp = paircreate(atype, -1);
+    vp = paircreate(atype, 0, -1);
     vp->operator = aop;
 
     if (vp->type == -1) {
@@ -793,6 +797,22 @@ static int read_vps(JRADIUS *inst, JRSOCK *jrsock, VALUE_PAIR **pl, int plen)
     }
 
     /*
+     *     WiMAX combo-ip address
+     *     paircreate() cannot recognize the real type of the address.
+     *     ..ugly code...
+     */
+    if (vp->type==PW_TYPE_COMBO_IP) {
+        switch (alen) {
+            case 4:
+                vp->type = PW_TYPE_IPADDR;
+                break;
+            case 16:
+                vp->type = PW_TYPE_IPV6ADDR;
+                break;
+        }
+    }
+
+    /*
      *     Fill in the attribute value based on type
      */
     switch (vp->type) {
@@ -904,8 +924,8 @@ static int read_request(JRADIUS *inst, JRSOCK *jrsock, REQUEST *p)
 static int rlm_jradius_call(char func, void *instance, REQUEST *req, int isproxy)
 {
   JRADIUS        * inst    = instance;
-  RADIUS_PACKET  * request = isproxy ? req->proxy : req->packet;
-  RADIUS_PACKET  * reply   = isproxy ? req->proxy_reply : req->reply;
+  RADIUS_PACKET  * request = req->packet;
+  RADIUS_PACKET  * reply   = req->reply;
   JRSOCK         * jrsock  = 0;
   JRSOCK           sjrsock;
 
@@ -923,6 +943,13 @@ static int rlm_jradius_call(char func, void *instance, REQUEST *req, int isproxy
 #define W_ERR(s) { err=s; goto packerror;  }
 #define R_ERR(s) { err=s; goto parseerror; }
 
+#ifdef WITH_PROXY
+  if (isproxy) {
+         request = req->proxy;
+         reply   = req->proxy_reply;
+  }
+#endif
+
   if (inst->keepalive) {
     jrsock = get_socket(inst);
     if (!jrsock) return exitstatus;
@@ -991,11 +1018,11 @@ static int rlm_jradius_call(char func, void *instance, REQUEST *req, int isproxy
    *    we need to reconfigure a few pointers in the REQUEST object
    */
   if (req->username) {
-    req->username = pairfind(request->vps, PW_USER_NAME);
+    req->username = pairfind(request->vps, PW_USER_NAME, 0);
   }
   if (req->password) {
-    req->password = pairfind(request->vps, PW_PASSWORD);
-    if (!req->password) req->password = pairfind(request->vps, PW_CHAP_PASSWORD);
+    req->password = pairfind(request->vps, PW_PASSWORD, 0);
+    if (!req->password) req->password = pairfind(request->vps, PW_CHAP_PASSWORD, 0);
   }
 
   /*
@@ -1062,6 +1089,17 @@ static int jradius_post_auth(void *instance, REQUEST *request)
   return rlm_jradius_call(JRADIUS_post_auth, instance, request, 0);
 }
 
+#ifdef WITH_COA
+static int jradius_recv_coa(void *instance, REQUEST *request)
+{
+  return rlm_jradius_call(JRADIUS_recv_coa, instance, request, 0);
+}
+static int jradius_send_coa(void *instance, REQUEST *request)
+{
+  return rlm_jradius_call(JRADIUS_send_coa, instance, request, 0);
+}
+#endif
+
 static int jradius_detach(void *instance)
 {
   JRADIUS *inst = (JRADIUS *) instance;
@@ -1085,6 +1123,10 @@ module_t rlm_jradius = {
     jradius_pre_proxy,
     jradius_post_proxy,
     jradius_post_auth
+#ifdef WITH_COA
+    , jradius_recv_coa,
+    jradius_send_coa
+#endif
   },
 };