radius: a server may be a name, and the port is taken as written (#1027)

The port was promised by the man page but never parsed: a server
address with a port was refused, and only the default 1812 could be
used. The address is parsed with parsehost() now, as nserver and
authnserver are, so a name is resolved when the configuration is read,
an IPv6 address may be written in brackets, and the port is the one
authentication is asked on, the accounting of the same server going to
the port after it. The man page says which name servers resolve the
name.
This commit is contained in:
Vladimir Dubrovin committed 2026-11-21 14:44:50 +03:00
1 parent 31438b7c90
commit ca70026d27
3 files changed
+48 -3

No files matched your search

+4 -1
View File
@@ -506,7 +506,10 @@ network conditions.
\fI<NAS_SECRET>\fR \fI<radius_server_1\fR[:\fIport\fR][/\fIlocal_address_1\fR]\fR \fI<radius_server_2\fR[:\fIport\fR][/\fIlocal_address_2\fR]\fR \fI<NAS_SECRET>\fR \fI<radius_server_1\fR[:\fIport\fR][/\fIlocal_address_1\fR]\fR \fI<radius_server_2\fR[:\fIport\fR][/\fIlocal_address_2\fR]\fR
.br .br
Configures RADIUS servers to be used for logging and authentication (log and auth types Configures RADIUS servers to be used for logging and authentication (log and auth types
must be set to radius). port and local address to use with given server may be specified. must be set to radius). A server is a name or an address, resolved when the
configuration is read. port and local address to use with given server may be specified:
the port named is the one authentication is asked on, and the accounting requests of
the same server go to the port after it (1812 and 1813 by default).
.br .br
Attributes within request: User-Name, Password: (username and password if presented by client), Attributes within request: User-Name, Password: (username and password if presented by client),
Service Type: Authenticate-Only, Service Type: Authenticate-Only,
+2 -2
View File
@@ -1776,8 +1776,8 @@ static int h_radius(int argc, unsigned char **argv){
*s = 0; *s = 0;
s++; s++;
} }
if( !getip46(46, argv[nradservers + 2], (struct sockaddr *)&radiuslist[nradservers].authaddr)) return 1; if(parsehost(46, argv[nradservers + 2], (struct sockaddr *)&radiuslist[nradservers].authaddr)) return 1;
if( s && !getip46(46, (unsigned char *)s, (struct sockaddr *)&radiuslist[nradservers].localaddr)) return 2; if(s && parsehost(46, (unsigned char *)s, (struct sockaddr *)&radiuslist[nradservers].localaddr)) return 2;
if(!*SAPORT(&radiuslist[nradservers].authaddr))*SAPORT(&radiuslist[nradservers].authaddr) = htons(1812); if(!*SAPORT(&radiuslist[nradservers].authaddr))*SAPORT(&radiuslist[nradservers].authaddr) = htons(1812);
port = ntohs(*SAPORT(&radiuslist[nradservers].authaddr)); port = ntohs(*SAPORT(&radiuslist[nradservers].authaddr));
radiuslist[nradservers].logaddr = radiuslist[nradservers].authaddr; radiuslist[nradservers].logaddr = radiuslist[nradservers].authaddr;
+42
View File
@@ -0,0 +1,42 @@
"""The radius command: a server may be a name, an address, and carry a
port, with an IPv6 address in brackets.
The port was in the man page but not in the code before: a server with a
port was simply refused. A name is resolved when the configuration is
read, with the name servers in force or the system's.
"""
def run(t):
def accepted(config):
out = t.run_config("radius_cmd", config + "\nnot_a_command\n")
return "'radius' failed" not in out, out
ok, out = accepted("log\nradius s3cret 127.0.0.1:18120")
if ok:
t.ok("a server address with a port is accepted")
else:
t.fail("a server address with a port is accepted",
"'radius' not refused", out)
ok, out = accepted("log\nradius s3cret localhost")
if ok:
t.ok("a server name is accepted, resolved when the file is read")
else:
t.fail("a server name is accepted, resolved when the file is read",
"'radius' not refused", out)
if t.has_ipv6():
ok, out = accepted("log\nradius s3cret [::1]:18120")
if ok:
t.ok("an IPv6 server address in brackets, with a port, is accepted")
else:
t.fail("an IPv6 server address in brackets, with a port, is accepted",
"'radius' not refused", out)
out = t.run_config("radius_bad",
"log\nradius s3cret 999.999.999.999\nnot_a_command\n")
t.contains(out, "'radius' failed",
"an address that is none is refused")
t.not_contains(out, "'not_a_command'",
"and the file stops at the refused line")