Add an append control in attr_rewrite.
authorkkalev <kkalev>
Thu, 17 Oct 2002 13:01:22 +0000 (13:01 +0000)
committerkkalev <kkalev>
Thu, 17 Oct 2002 13:01:22 +0000 (13:01 +0000)
Patch from Alessandro Maioli <amaioli@intelcom.sm>

raddb/radiusd.conf.in
src/modules/rlm_attr_rewrite/rlm_attr_rewrite.c

index 6c42168..d79573a 100644 (file)
@@ -763,6 +763,8 @@ modules {
        #       ignore_case = no
        #       new_attribute = no
        #       max_matches = 10
+       #       ## If set to yes then the replace string will be appended to the original string
+       #       append = no
        #}
 
        # Preprocess the incoming RADIUS request, before handing it off
index c0516c7..d5098d9 100644 (file)
@@ -52,6 +52,7 @@ typedef struct rlm_attr_rewrite_t {
        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 */
+       int  append;            /* Switch to control append mode (1,0) */ 
        int  nocase;            /* Ignore case */
        int  new_attr;          /* Boolean. Do we create a new attribute or not? */
        int  num_matches;       /* Maximum number of matches */
@@ -64,6 +65,7 @@ static CONF_PARSER module_config[] = {
   { "searchfor", PW_TYPE_STRING_PTR, offsetof(rlm_attr_rewrite_t,search), NULL, NULL },
   { "searchin",  PW_TYPE_STRING_PTR, offsetof(rlm_attr_rewrite_t,searchin_str), NULL, "packet" },
   { "replacewith", PW_TYPE_STRING_PTR, offsetof(rlm_attr_rewrite_t,replace), NULL, NULL },
+  { "append", PW_TYPE_BOOLEAN, offsetof(rlm_attr_rewrite_t,append),NULL, "no" },
   { "ignore_case", PW_TYPE_BOOLEAN, offsetof(rlm_attr_rewrite_t,nocase), NULL, "yes" },
   { "new_attribute", PW_TYPE_BOOLEAN, offsetof(rlm_attr_rewrite_t,new_attr), NULL, "no" },
   { "max_matches", PW_TYPE_INTEGER, offsetof(rlm_attr_rewrite_t,num_matches), NULL, "10" },
@@ -256,6 +258,9 @@ do_again:
                        if (pmatch.rm_so == -1)
                                break;
                        len = pmatch.rm_so;
+                       if (data->append) {
+                               len = len + (pmatch.rm_eo - pmatch.rm_so);
+                       } 
                        counter += len;
                        if (counter >= MAX_STRING_LEN) {
                                regfree(&preg);