<p></p>

<h3>Description</h3>
<p>I've been trying to setup kamailio with the latest freeradius-client. I've been using the docker image <code>kamailio/kamailio:5.3.1-jessie</code> adding the freeradius-client (latest github pool).</p>
<p>However it seems that kamailio cannot create a proper radius request and fails with error <code>3(9) ERROR: auth_radius [sterman.c:264]: radius_authorize_sterman(): unable to add User-Name attribute</code></p>
<h3>Troubleshooting</h3>
<h4>Reproduction</h4>
<p>Install freeradius-client</p>
<pre><code>    git clone https://github.com/FreeRADIUS/freeradius-client.git \
    && cd freeradius-client/ \
    && ./configure \
    && make \
    && make install
</code></pre>
<p>Modify the <code>/usr/local/etc/radiusclient/dictionary</code> and append the following lines</p>
<pre><code>$INCLUDE /etc/radiusclient/dictionary.sip
$INCLUDE /etc/radiusclient/dictionary.kamailio # https://github.com/kamailio/kamailio/blob/master/src/modules/auth_radius/cfg/dictionary.kamailio
</code></pre>
<p>Configure auth_radius</p>
<pre><code>loadmodule "auth_radius.so"
loadmodule "misc_radius.so"

modparam("auth_radius|misc_radius", "radius_config", "/usr/local/etc/radiusclient/radiusclient.conf")
</code></pre>
<h4>Debugging Data</h4>
<p>I've went on the tried to debug the issue from the freeradius-client's point of view since it was easier to compile and iterate, and I've added various logs here and there to try and figure out what was wrong. From what I've seen, kamailio invokes <code>INIT_AV</code> to setup the <code>attrs</code> dictionary containing the dictionary attributes and matching values.</p>
<p><a href="https://github.com/kamailio/kamailio/blob/360e012d9d93c80b62b6e75bfac6e3340407ee98/src/modules/misc_radius/radius.h#L106">https://github.com/kamailio/kamailio/blob/360e012d9d93c80b62b6e75bfac6e3340407ee98/src/modules/misc_radius/radius.h#L106</a></p>
<p>I've traced the <code>rc_dict_findattr</code> and it seems that the library properly returns <code>User-Name</code> attribute with value <code>1</code>.</p>
<p>However in the <code>radius_authorize_sterman</code> function</p>
<p><a href="https://github.com/kamailio/kamailio/blob/360e012d9d93c80b62b6e75bfac6e3340407ee98/src/modules/auth_radius/sterman.c#L221">https://github.com/kamailio/kamailio/blob/360e012d9d93c80b62b6e75bfac6e3340407ee98/src/modules/auth_radius/sterman.c#L221</a></p>
<p>the application tries to add the AVPs by invoking <code>rc_avpair_add</code> and passing <code>attr[...].v</code> value. I've logged the <code>rc_avpair_add</code> parameters passed and it seems that <code>attr[...].v</code> is not 1 as expected but 0, thus failing since 0 is an invalid attribute code.</p>
<p>I modified freeradius-client to replace <code>attrid</code> with 1 if it were a 0 as a test, and it seems that all calls to <code>rc_avpair_add</code> by sterman.c are passing 0 as attribute value leading to a radius message like:</p>
<pre><code>(0)   User-Name = "test@localhost"
(0)   User-Name = "test"
(0)   User-Name = "localhost"
(0)   User-Name = "X3q5AV96t9WlJ5ZnoFFQQq/ftg7u+Mx5KRxYYIA="
(0)   User-Name = "sip:localhost"
(0)   User-Name = "REGISTER"
(0)   User-Name = "bc6c2152d2e068e16f76188d69e66340"
(0)   User-Name = "\017"
(0)   User-Name = "test"
(0)   NAS-Port = 5060
(0)   NAS-IP-Address = 10.10.10.4
</code></pre>
<p>(As you can see pretty much all attributes are replaced by User-Name)</p>
<p>It looks like <code>attrs</code> dictionary although initialized at <code>mod_init</code>, at a later stage is somehow corrupted or reset.</p>
<h3>Additional Information</h3>
<ul>
<li><strong>Kamailio Version</strong> - output of <code>kamailio -v</code></li>
</ul>
<pre><code>version: kamailio 5.3.1 (x86_64/linux)
flags: USE_TCP, USE_TLS, USE_SCTP, TLS_HOOKS, USE_RAW_SOCKS, DISABLE_NAGLE, USE_MCAST, DNS_IP_HACK, SHM_MMAP, PKG_MALLOC, Q_MALLOC, F_MALLOC, TLSF_MALLOC, DBG_SR_MEMORY, USE_FUTEX, FAST_LOCK-ADAPTIVE_WAIT, USE_DNS_CACHE, USE_DNS_FAILOVER, USE_NAPTR, USE_DST_BLACKLIST, HAVE_RESOLV_RES
ADAPTIVE_WAIT_LOOPS 1024, MAX_RECV_BUFFER_SIZE 262144, MAX_URI_SIZE 1024, BUF_SIZE 65535, DEFAULT PKG_SIZE 8MB
poll method support: poll, epoll_lt, epoll_et, sigio_rt, select.
id: unknown
compiled with gcc 4.9.2
</code></pre>
<ul>
<li><strong>Operating System</strong>:</li>
</ul>

<pre><code>Linux bea2be591c38 4.19.76-linuxkit #1 SMP Tue May 26 11:42:35 UTC 2020 x86_64 GNU/Linux
</code></pre>
<p>This is tested on a docker installation using <code>kamailio/kamailio:5.3.1-jessie</code></p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/kamailio/kamailio/issues/2496">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/ABO7UZOWMVGAOSCKZJGOEUDSJFSRLANCNFSM4SEIW4RQ">unsubscribe</a>.<img src="https://github.com/notifications/beacon/ABO7UZLA7NEJOTCOBOULK3LSJFSRLA5CNFSM4SEIW4R2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4KUXJYYQ.gif" height="1" width="1" alt="" /></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/kamailio/kamailio/issues/2496",
"url": "https://github.com/kamailio/kamailio/issues/2496",
"name": "View Issue"
},
"description": "View this Issue on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>