Enable building #WITHOUT_PROXY
[freeradius.git] / src / modules / rlm_attr_rewrite / rlm_attr_rewrite.c
index fdf0121..fd47702 100644 (file)
@@ -39,10 +39,10 @@ RCSID("$Id$")
 
 typedef struct rlm_attr_rewrite_t {
        char *attribute;        /* The attribute to search for */
-       int  attr_num;          /* The attribute number */
+       DICT_ATTR *da;          /* The attribute definition */
        char *search;           /* The pattern to search for */
        int search_len;         /* The length of the search pattern */
-       char *searchin_str;     /* The VALUE_PAIR list to search in. Can be either packet,reply,proxy,proxy_reply or config */
+       char *searchin_str;     /* The VALUE_PAIR list to search in. Can be either packet,reply,proxy,proxy_reply or control (plus it's alias 'config') */
        char searchin;          /* The same as above just coded as a number for speed */
        char *replace;          /* The replacement */
        int replace_len;        /* The length of the replacement string */
@@ -120,17 +120,20 @@ static int attr_rewrite_instantiate(CONF_SECTION *conf, void **instance)
                        data->searchin = RLM_REGEX_INPACKET;
                else if (strcmp(data->searchin_str, "config") == 0)
                        data->searchin = RLM_REGEX_INCONFIG;
+               else if (strcmp(data->searchin_str, "control") == 0)
+                       data->searchin = RLM_REGEX_INCONFIG;
                else if (strcmp(data->searchin_str, "reply") == 0)
                        data->searchin = RLM_REGEX_INREPLY;
+#ifdef WITH_PROXY
                else if (strcmp(data->searchin_str, "proxy") == 0)
                        data->searchin = RLM_REGEX_INPROXY;
                else if (strcmp(data->searchin_str, "proxy_reply") == 0)
                        data->searchin = RLM_REGEX_INPROXYREPLY;
+#endif
                else {
                        radlog(L_ERR, "rlm_attr_rewrite: Illegal searchin directive given. Assuming packet.");
                        data->searchin = RLM_REGEX_INPACKET;
                }
-               free((char *)data->searchin_str);
        }
        dattr = dict_attrbyname(data->attribute);
        if (dattr == NULL) {
@@ -138,7 +141,7 @@ static int attr_rewrite_instantiate(CONF_SECTION *conf, void **instance)
                                data->attribute);
                return -1;
        }
-       data->attr_num = dattr->attr;
+       data->da = dattr;
        /* Add the module instance name */
        data->name = cf_section_name2(conf); /* may be NULL */
 
@@ -167,9 +170,8 @@ static int do_attr_rewrite(void *instance, REQUEST *request)
        char *ptr, *ptr2;
        char search_STR[MAX_STRING_LEN];
        char replace_STR[MAX_STRING_LEN];
-       int replace_len = 0;
 
-       if ((attr_vp = pairfind(request->config_items, PW_REWRITE_RULE)) != NULL){
+       if ((attr_vp = pairfind(request->config_items, PW_REWRITE_RULE, 0)) != NULL){
                if (data->name == NULL || strcmp(data->name,attr_vp->vp_strvalue))
                        return RLM_MODULE_NOOP;
        }
@@ -180,7 +182,6 @@ static int do_attr_rewrite(void *instance, REQUEST *request)
                        DEBUG2("%s: xlat on replace string failed.", data->name);
                        return ret;
                }
-               replace_len = strlen(replace_STR);
                attr_vp = pairmake(data->attribute,replace_STR,0);
                if (attr_vp == NULL){
                        DEBUG2("%s: Could not add new attribute %s with value '%s'", data->name,
@@ -197,6 +198,7 @@ static int do_attr_rewrite(void *instance, REQUEST *request)
                        case RLM_REGEX_INREPLY:
                                pairadd(&request->reply->vps,attr_vp);
                                break;
+#ifdef WITH_PROXY
                        case RLM_REGEX_INPROXY:
                                if (!request->proxy) {
                                        pairbasicfree(attr_vp);
@@ -211,6 +213,7 @@ static int do_attr_rewrite(void *instance, REQUEST *request)
                                }
                                pairadd(&request->proxy_reply->vps, attr_vp);
                                break;
+#endif
                        default:
                                radlog(L_ERR, "%s: Illegal value for searchin. Changing to packet.", data->name);
                                data->searchin = RLM_REGEX_INPACKET;
@@ -220,12 +223,14 @@ static int do_attr_rewrite(void *instance, REQUEST *request)
                DEBUG2("%s: Added attribute %s with value '%s'", data->name,data->attribute,replace_STR);
                ret = RLM_MODULE_OK;
        } else {
+               int replace_len = 0;
+
                /* new_attribute = no */
                switch (data->searchin) {
                        case RLM_REGEX_INPACKET:
-                               if (data->attr_num == PW_USER_NAME)
+                               if (!data->da->vendor && (data->da->attr == PW_USER_NAME))
                                        attr_vp = request->username;
-                               else if (data->attr_num == PW_USER_PASSWORD)
+                               else if (!data->da->vendor && (data->da->attr == PW_USER_PASSWORD))
                                        attr_vp = request->password;
                                else
                                        tmp = request->packet->vps;
@@ -236,6 +241,7 @@ static int do_attr_rewrite(void *instance, REQUEST *request)
                        case RLM_REGEX_INREPLY:
                                tmp = request->reply->vps;
                                break;
+#ifdef WITH_PROXY
                        case RLM_REGEX_INPROXYREPLY:
                                if (!request->proxy_reply)
                                        return RLM_MODULE_NOOP;
@@ -246,15 +252,16 @@ static int do_attr_rewrite(void *instance, REQUEST *request)
                                        return RLM_MODULE_NOOP;
                                tmp = request->proxy->vps;
                                break;
+#endif
                        default:
                                radlog(L_ERR, "%s: Illegal value for searchin. Changing to packet.", data->name);
                                data->searchin = RLM_REGEX_INPACKET;
-                               attr_vp = pairfind(request->packet->vps, data->attr_num);
+                               attr_vp = pairfind(request->packet->vps, data->da->attr, data->da->vendor);
                                break;
                }
 do_again:
                if (tmp != NULL)
-                       attr_vp = pairfind(tmp, data->attr_num);
+                       attr_vp = pairfind(tmp, data->da->attr, data->da->vendor);
                if (attr_vp == NULL) {
                        DEBUG2("%s: Could not find value pair for attribute %s", data->name,data->attribute);
                        return ret;
@@ -437,6 +444,7 @@ static int attr_rewrite_checksimul(void *instance, REQUEST *request)
        return do_attr_rewrite(instance, request);
 }
 
+#ifdef WITH_PROXY
 static int attr_rewrite_preproxy(void *instance, REQUEST *request)
 {
        return do_attr_rewrite(instance, request);
@@ -446,6 +454,7 @@ static int attr_rewrite_postproxy(void *instance, REQUEST *request)
 {
        return do_attr_rewrite(instance, request);
 }
+#endif
 
 static int attr_rewrite_postauth(void *instance, REQUEST *request)
 {
@@ -479,8 +488,12 @@ module_t rlm_attr_rewrite = {
                attr_rewrite_preacct,           /* preaccounting */
                attr_rewrite_accounting,        /* accounting */
                attr_rewrite_checksimul,        /* checksimul */
+#ifdef WITH_PROXY
                attr_rewrite_preproxy,          /* pre-proxy */
                attr_rewrite_postproxy,         /* post-proxy */
+#else
+               NULL, NULL,
+#endif
                attr_rewrite_postauth           /* post-auth */
        },
 };