Att rewrite output missing last char.

Arran Cudbard-Bell A.Cudbard-Bell at sussex.ac.uk
Tue May 8 15:52:13 CEST 2007


Alan DeKok wrote:
> Arran Cudbard-Bell wrote:
> ...
>> rlm_attr_rewrite: Changed value for attribute Calling-Station-Id from 
>> '00-17-f2-31-b4-81' to '0017f231b48'
>>
>> Seems to be missing last char of value...
> 
>   Try the attached patch.
> 
>   Alan DeKok.
> --
>   http://deployingradius.com       - The web site of the book
>   http://deployingradius.com/blog/ - The blog
> 
> 
> ------------------------------------------------------------------------
> 
> Index: src/modules/rlm_attr_rewrite/rlm_attr_rewrite.c
> ===================================================================
> RCS file: /source/radiusd/src/modules/rlm_attr_rewrite/rlm_attr_rewrite.c,v
> retrieving revision 1.43
> diff -u -r1.43 rlm_attr_rewrite.c
> --- src/modules/rlm_attr_rewrite/rlm_attr_rewrite.c	17 Apr 2007 13:14:50 -0000	1.43
> +++ src/modules/rlm_attr_rewrite/rlm_attr_rewrite.c	8 May 2007 13:26:26 -0000
> @@ -285,9 +285,9 @@
>  		
>  		if ((attr_vp->type == PW_TYPE_IPADDR) &&
>  		    (attr_vp->vp_strvalue[0] == '\0')) {
> -		  inet_ntop(AF_INET, &(attr_vp->vp_ipaddr),
> -			    attr_vp->vp_strvalue,
> -			    sizeof(attr_vp->vp_strvalue));
> +			inet_ntop(AF_INET, &(attr_vp->vp_ipaddr),
> +				  attr_vp->vp_strvalue,
> +				  sizeof(attr_vp->vp_strvalue));
>  		}
>  
>  		ptr = new_str;
> @@ -325,8 +325,9 @@
>  				return ret;
>  			}
>  
> -			strlcpy(ptr, ptr2,len);
> +			memcpy(ptr, ptr2,len);
>  			ptr += len;
> +			*ptr = '\0';
>  			ptr2 += pmatch[0].rm_eo;
>  
>  			if (i == 0){
> @@ -380,8 +381,9 @@
>  				return ret;
>  			}
>  			if (replace_len){
> -				strlcpy(ptr, replace_STR, replace_len);
> +				memcpy(ptr, replace_STR, replace_len);
>  				ptr += replace_len;
> +				*ptr = '\0';
>  			}
>  		}
>  		regfree(&preg);
> @@ -392,7 +394,8 @@
>  					data->attribute, attr_vp->vp_strvalue);
>  			return ret;
>  		}
> -		strlcpy(ptr, ptr2, len);
> +		memcpy(ptr, ptr2, len);
> +		ptr[len] = '\0';
>  
>  		DEBUG2("rlm_attr_rewrite: Changed value for attribute %s from '%s' to '%s'",
>  				data->attribute, attr_vp->vp_strvalue, new_str);
> 
> 
> ------------------------------------------------------------------------
> 
> - 
> List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html

radius_xlat: 
'([0-9a-f]{2})[-:]?([0-9a-f]{2})[-:]?([0-9a-f]{2})[-:]?([0-9a-f]{2,})[-:]?([0-9a-f]{2})[-:]?([0-9a-f]{2})'
radius_xlat:  '0019e30ccd58'
rlm_attr_rewrite: Changed value for attribute Calling-Station-Id from 
'00-19-e3-0c-cd-58' to '0019e30ccd58'

Works !

Thanks,
-- 
Arran Cudbard-Bell (A.Cudbard-Bell at sussex.ac.uk)
Authentication, Authorisation and Accounting Officer
Infrastructure Services | ENG1 E1-1-08
University Of Sussex, Brighton
EXT:01273 873900 | INT: 3900



More information about the Freeradius-Users mailing list