Extracting a value from an LDAP attribute
Hello all, I have been looking for a way to extract a part of an LDAP attribute that I retrieved and map to the RADIUS attribute " Tunnel-Private-Group-Id". The syntax of my LDAP attribute: "schacUserStatus : urn:mace:terena.org:schac:userStatus:FR:vlan:13+mode=manuel" I want to extract the number of the vlan, to affect it to " Tunnel-Private-Group-Id" attribute. With the given example, I want to only have "13" stored in " Tunnel-Private-Group-Id". I tried that in the ldap module : update { control:Password-With-Header += 'userPassword' reply:Tunnel-Private-Group-ID := 'schacUserStatus' } However, with this solution I retrieve "urn:mace:terena.org:schac:userStatus:FR:vlan:13+mode=manuel" in " Tunnel-Private-Group-Id". I also try to split it, but its length is 1. I read all the documentations at https://networkradius.com/doc/3.0.10 and I still don't know if there is a way to do that in unlang, and if so, do I have to do it in the ldap module, or in my virtual server configuration; or if it's possible to parse the LDAP attribute using Bash commands. Thank you for your advice and help, Florent VERCOURT
On 02/02/2023 10:54, florentvercourt@gmail.com wrote:
I want to extract the number of the vlan, to affect it to " Tunnel-Private-Group-Id" attribute. With the given example, I want to only have "13" stored in " Tunnel-Private-Group-Id".
I tried that in the ldap module :
update {
control:Password-With-Header += 'userPassword'
reply:Tunnel-Private-Group-ID := 'schacUserStatus'
}
However, with this solution I retrieve "urn:mace:terena.org:schac:userStatus:FR:vlan:13+mode=manuel" in" Tunnel-Private-Group-Id".
If the returned value always matches the same kind of format, I would suggest using a regex to extract the relevant part, so, after the call to the ldap module something like: if (&reply:Tunnel-Private-Group-ID =~ /vlan:([0-9]+)/) { update reply { &Tunnel-Private-Group-ID := "%{1}" } } That's looking for any digits after vlan: in the returned value - you will have to understand the possible formats of the returned data to know whether that will work. Nick -- Nick Porter
participants (2)
-
florentvercourt@gmail.com -
Nick Porter