1082bfe67SJohn Polstra.\" Copyright 1998 Juniper Networks, Inc. 23fc0b61cSAlexander Motin.\" Copyright 2009 Alexander Motin <mav@FreeBSD.org>. 3082bfe67SJohn Polstra.\" All rights reserved. 4082bfe67SJohn Polstra.\" 5082bfe67SJohn Polstra.\" Redistribution and use in source and binary forms, with or without 6082bfe67SJohn Polstra.\" modification, are permitted provided that the following conditions 7082bfe67SJohn Polstra.\" are met: 8082bfe67SJohn Polstra.\" 1. Redistributions of source code must retain the above copyright 9082bfe67SJohn Polstra.\" notice, this list of conditions and the following disclaimer. 10082bfe67SJohn Polstra.\" 2. Redistributions in binary form must reproduce the above copyright 11082bfe67SJohn Polstra.\" notice, this list of conditions and the following disclaimer in the 12082bfe67SJohn Polstra.\" documentation and/or other materials provided with the distribution. 13082bfe67SJohn Polstra.\" 14082bfe67SJohn Polstra.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15082bfe67SJohn Polstra.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16082bfe67SJohn Polstra.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17082bfe67SJohn Polstra.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18082bfe67SJohn Polstra.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19082bfe67SJohn Polstra.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20082bfe67SJohn Polstra.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21082bfe67SJohn Polstra.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22082bfe67SJohn Polstra.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23082bfe67SJohn Polstra.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24082bfe67SJohn Polstra.\" SUCH DAMAGE. 25082bfe67SJohn Polstra.\" 267f3dea24SPeter Wemm.\" $FreeBSD$ 27082bfe67SJohn Polstra.\" 283fc0b61cSAlexander Motin.Dd August 5, 2009 29082bfe67SJohn Polstra.Dt LIBRADIUS 3 30a307d598SRuslan Ermilov.Os 31082bfe67SJohn Polstra.Sh NAME 32082bfe67SJohn Polstra.Nm libradius 333fc0b61cSAlexander Motin.Nd RADIUS client/server library 34082bfe67SJohn Polstra.Sh SYNOPSIS 3532eef9aeSRuslan Ermilov.In radlib.h 3681b380a8SRuslan Ermilov.Ft "struct rad_handle *" 370981dfefSJohn Polstra.Fn rad_acct_open "void" 38082bfe67SJohn Polstra.Ft int 39082bfe67SJohn Polstra.Fn rad_add_server "struct rad_handle *h" "const char *host" "int port" "const char *secret" "int timeout" "int max_tries" 4081b380a8SRuslan Ermilov.Ft "struct rad_handle *" 410981dfefSJohn Polstra.Fn rad_auth_open "void" 42082bfe67SJohn Polstra.Ft void 43082bfe67SJohn Polstra.Fn rad_close "struct rad_handle *h" 44082bfe67SJohn Polstra.Ft int 45082bfe67SJohn Polstra.Fn rad_config "struct rad_handle *h" "const char *file" 46082bfe67SJohn Polstra.Ft int 4748caee2aSBrian Somers.Fn rad_continue_send_request "struct rad_handle *h" "int selected" "int *fd" "struct timeval *tv" 4848caee2aSBrian Somers.Ft int 49082bfe67SJohn Polstra.Fn rad_create_request "struct rad_handle *h" "int code" 503fc0b61cSAlexander Motin.Ft int 513fc0b61cSAlexander Motin.Fn rad_create_response "struct rad_handle *h" "int code" 5281b380a8SRuslan Ermilov.Ft "struct in_addr" 53082bfe67SJohn Polstra.Fn rad_cvt_addr "const void *data" 54082bfe67SJohn Polstra.Ft u_int32_t 55082bfe67SJohn Polstra.Fn rad_cvt_int "const void *data" 56082bfe67SJohn Polstra.Ft char * 57082bfe67SJohn Polstra.Fn rad_cvt_string "const void *data" "size_t len" 58082bfe67SJohn Polstra.Ft int 59082bfe67SJohn Polstra.Fn rad_get_attr "struct rad_handle *h" "const void **data" "size_t *len" 6048caee2aSBrian Somers.Ft int 61fc3f62faSBrian Somers.Fn rad_get_vendor_attr "u_int32_t *vendor" "const void **data" "size_t *len" 62fc3f62faSBrian Somers.Ft int 6348caee2aSBrian Somers.Fn rad_init_send_request "struct rad_handle *h" "int *fd" "struct timeval *tv" 64082bfe67SJohn Polstra.Ft int 65082bfe67SJohn Polstra.Fn rad_put_addr "struct rad_handle *h" "int type" "struct in_addr addr" 66082bfe67SJohn Polstra.Ft int 67082bfe67SJohn Polstra.Fn rad_put_attr "struct rad_handle *h" "int type" "const void *data" "size_t len" 68082bfe67SJohn Polstra.Ft int 69082bfe67SJohn Polstra.Fn rad_put_int "struct rad_handle *h" "int type" "u_int32_t value" 70082bfe67SJohn Polstra.Ft int 71082bfe67SJohn Polstra.Fn rad_put_string "struct rad_handle *h" "int type" "const char *str" 72082bfe67SJohn Polstra.Ft int 73b4b831efSRuslan Ermilov.Fn rad_put_message_authentic "struct rad_handle *h" 74b4b831efSRuslan Ermilov.Ft int 75b49a88f6SBrian Somers.Fn rad_put_vendor_addr "struct rad_handle *h" "int vendor" "int type" "struct in_addr addr" 76b49a88f6SBrian Somers.Ft int 77b49a88f6SBrian Somers.Fn rad_put_vendor_attr "struct rad_handle *h" "int vendor" "int type" "const void *data" "size_t len" 78b49a88f6SBrian Somers.Ft int 79b49a88f6SBrian Somers.Fn rad_put_vendor_int "struct rad_handle *h" "int vendor" "int type" "u_int32_t value" 80b49a88f6SBrian Somers.Ft int 81b49a88f6SBrian Somers.Fn rad_put_vendor_string "struct rad_handle *h" "int vendor" "int type" "const char *str" 82628e6cd4SBrian Somers.Ft ssize_t 83628e6cd4SBrian Somers.Fn rad_request_authenticator "struct rad_handle *h" "char *buf" "size_t len" 84b49a88f6SBrian Somers.Ft int 853fc0b61cSAlexander Motin.Fn rad_receive_request "struct rad_handle *h" 863fc0b61cSAlexander Motin.Ft int 87082bfe67SJohn Polstra.Fn rad_send_request "struct rad_handle *h" 883fc0b61cSAlexander Motin.Ft int 893fc0b61cSAlexander Motin.Fn rad_send_response "struct rad_handle *h" 903fc0b61cSAlexander Motin.Ft "struct rad_handle *" 913fc0b61cSAlexander Motin.Fn rad_server_open "int fd" 9281b380a8SRuslan Ermilov.Ft "const char *" 93628e6cd4SBrian Somers.Fn rad_server_secret "struct rad_handle *h" 94b4b831efSRuslan Ermilov.Ft u_char * 95b4b831efSRuslan Ermilov.Fn rad_demangle "struct rad_handle *h" "const void *mangled" "size_t mlen" 96b4b831efSRuslan Ermilov.Ft u_char * 97b4b831efSRuslan Ermilov.Fn rad_demangle_mppe_key "struct rad_handle *h" "const void *mangled" "size_t mlen" "size_t *len" 9881b380a8SRuslan Ermilov.Ft "const char *" 99082bfe67SJohn Polstra.Fn rad_strerror "struct rad_handle *h" 100082bfe67SJohn Polstra.Sh DESCRIPTION 101082bfe67SJohn PolstraThe 102082bfe67SJohn Polstra.Nm 1033fc0b61cSAlexander Motinlibrary implements the Remote Authentication Dial In User Service (RADIUS). 104b4b831efSRuslan ErmilovRADIUS, defined in RFCs 2865 and 2866, 1050981dfefSJohn Polstraallows clients to perform authentication and accounting by means of 1060981dfefSJohn Polstranetwork requests to remote servers. 10781b380a8SRuslan Ermilov.Ss Initialization 108082bfe67SJohn PolstraTo use the library, an application must first call 1090981dfefSJohn Polstra.Fn rad_auth_open 1103fc0b61cSAlexander Motin, 1110981dfefSJohn Polstra.Fn rad_acct_open 1123fc0b61cSAlexander Motinor 1133fc0b61cSAlexander Motin.Fn rad_server_open 114082bfe67SJohn Polstrato obtain a 11581b380a8SRuslan Ermilov.Vt "struct rad_handle *" , 116082bfe67SJohn Polstrawhich provides the context for subsequent operations. 1170981dfefSJohn PolstraThe former function is used for RADIUS authentication and the 1180981dfefSJohn Polstralatter is used for RADIUS accounting. 119082bfe67SJohn PolstraCalls to 1200981dfefSJohn Polstra.Fn rad_auth_open 1213fc0b61cSAlexander Motin, 1220981dfefSJohn Polstra.Fn rad_acct_open 1233fc0b61cSAlexander Motinand 1243fc0b61cSAlexander Motin.Fn rad_server_open 12581b380a8SRuslan Ermilovalways succeed unless insufficient virtual memory is available. 12681b380a8SRuslan ErmilovIf 1270981dfefSJohn Polstrathe necessary memory cannot be allocated, the functions return 128082bfe67SJohn Polstra.Dv NULL . 1290981dfefSJohn PolstraFor compatibility with earlier versions of this library, 1300981dfefSJohn Polstra.Fn rad_open 1310981dfefSJohn Polstrais provided as a synonym for 1320981dfefSJohn Polstra.Fn rad_auth_open . 133082bfe67SJohn Polstra.Pp 134082bfe67SJohn PolstraBefore issuing any RADIUS requests, the library must be made aware 13581b380a8SRuslan Ermilovof the servers it can contact. 13681b380a8SRuslan ErmilovThe easiest way to configure the 137082bfe67SJohn Polstralibrary is to call 138082bfe67SJohn Polstra.Fn rad_config . 139082bfe67SJohn Polstra.Fn rad_config 140082bfe67SJohn Polstracauses the library to read a configuration file whose format is 141082bfe67SJohn Polstradescribed in 142082bfe67SJohn Polstra.Xr radius.conf 5 . 143082bfe67SJohn PolstraThe pathname of the configuration file is passed as the 14481b380a8SRuslan Ermilov.Fa file 145082bfe67SJohn Polstraargument to 146082bfe67SJohn Polstra.Fn rad_config . 147082bfe67SJohn PolstraThis argument may also be given as 148082bfe67SJohn Polstra.Dv NULL , 149082bfe67SJohn Polstrain which case the standard configuration file 150082bfe67SJohn Polstra.Pa /etc/radius.conf 151082bfe67SJohn Polstrais used. 152082bfe67SJohn Polstra.Fn rad_config 15381b380a8SRuslan Ermilovreturns 0 on success, or \-1 if an error occurs. 154082bfe67SJohn Polstra.Pp 155082bfe67SJohn PolstraThe library can also be configured programmatically by calls to 156082bfe67SJohn Polstra.Fn rad_add_server . 157082bfe67SJohn PolstraThe 15881b380a8SRuslan Ermilov.Fa host 159082bfe67SJohn Polstraparameter specifies the server host, either as a fully qualified 160082bfe67SJohn Polstradomain name or as a dotted-quad IP address in text form. 161082bfe67SJohn PolstraThe 16281b380a8SRuslan Ermilov.Fa port 16381b380a8SRuslan Ermilovparameter specifies the UDP port to contact on the server. 16481b380a8SRuslan ErmilovIf 16581b380a8SRuslan Ermilov.Fa port 166082bfe67SJohn Polstrais given as 0, the library looks up the 167082bfe67SJohn Polstra.Ql radius/udp 1680981dfefSJohn Polstraor 1690981dfefSJohn Polstra.Ql radacct/udp 17081b380a8SRuslan Ermilovservice in the network 17181b380a8SRuslan Ermilov.Xr services 5 17281b380a8SRuslan Ermilovdatabase, and uses the port found 17381b380a8SRuslan Ermilovthere. 17481b380a8SRuslan ErmilovIf no entry is found, the library uses the standard RADIUS 1750981dfefSJohn Polstraports, 1812 for authentication and 1813 for accounting. 1760981dfefSJohn PolstraThe shared secret for the server host is passed to the 17781b380a8SRuslan Ermilov.Fa secret 178082bfe67SJohn Polstraparameter. 17981b380a8SRuslan ErmilovIt may be any 18081b380a8SRuslan Ermilov.Dv NUL Ns -terminated 18181b380a8SRuslan Ermilovstring of bytes. 18281b380a8SRuslan ErmilovThe RADIUS protocol 183082bfe67SJohn Polstraignores all but the leading 128 bytes of the shared secret. 184082bfe67SJohn PolstraThe timeout for receiving replies from the server is passed to the 18581b380a8SRuslan Ermilov.Fa timeout 18681b380a8SRuslan Ermilovparameter, in units of seconds. 18781b380a8SRuslan ErmilovThe maximum number of repeated 188082bfe67SJohn Polstrarequests to make before giving up is passed into the 18981b380a8SRuslan Ermilov.Fa max_tries 190082bfe67SJohn Polstraparameter. 191082bfe67SJohn Polstra.Fn rad_add_server 19281b380a8SRuslan Ermilovreturns 0 on success, or \-1 if an error occurs. 193082bfe67SJohn Polstra.Pp 194082bfe67SJohn Polstra.Fn rad_add_server 195082bfe67SJohn Polstramay be called multiple times, and it may be used together with 196082bfe67SJohn Polstra.Fn rad_config . 197082bfe67SJohn PolstraAt most 10 servers may be specified. 198082bfe67SJohn PolstraWhen multiple servers are given, they are tried in round-robin 199082bfe67SJohn Polstrafashion until a valid response is received, or until each server's 20081b380a8SRuslan Ermilov.Fa max_tries 201082bfe67SJohn Polstralimit has been reached. 20281b380a8SRuslan Ermilov.Ss Creating a RADIUS Request 203082bfe67SJohn PolstraA RADIUS request consists of a code specifying the kind of request, 20481b380a8SRuslan Ermilovand zero or more attributes which provide additional information. 20581b380a8SRuslan ErmilovTo 206082bfe67SJohn Polstrabegin constructing a new request, call 207082bfe67SJohn Polstra.Fn rad_create_request . 208082bfe67SJohn PolstraIn addition to the usual 20981b380a8SRuslan Ermilov.Vt "struct rad_handle *" , 210082bfe67SJohn Polstrathis function takes a 21181b380a8SRuslan Ermilov.Fa code 21281b380a8SRuslan Ermilovparameter which specifies the type of the request. 21381b380a8SRuslan ErmilovMost often this 214082bfe67SJohn Polstrawill be 215082bfe67SJohn Polstra.Dv RAD_ACCESS_REQUEST . 216082bfe67SJohn Polstra.Fn rad_create_request 21781b380a8SRuslan Ermilovreturns 0 on success, or \-1 on if an error occurs. 218082bfe67SJohn Polstra.Pp 219082bfe67SJohn PolstraAfter the request has been created with 220abac9a9eSBrian Somers.Fn rad_create_request , 22181b380a8SRuslan Ermilovattributes can be attached to it. 22281b380a8SRuslan ErmilovThis is done through calls to 223082bfe67SJohn Polstra.Fn rad_put_addr , 224082bfe67SJohn Polstra.Fn rad_put_int , 225082bfe67SJohn Polstraand 226082bfe67SJohn Polstra.Fn rad_put_string . 227082bfe67SJohn PolstraEach accepts a 22881b380a8SRuslan Ermilov.Fa type 229082bfe67SJohn Polstraparameter identifying the attribute, and a value which may be 23081b380a8SRuslan Ermilovan Internet address, an integer, or a 23181b380a8SRuslan Ermilov.Dv NUL Ns -terminated 23281b380a8SRuslan Ermilovstring, 233082bfe67SJohn Polstrarespectively. 234b49a88f6SBrian SomersAlternatively, 235b49a88f6SBrian Somers.Fn rad_put_vendor_addr , 236b49a88f6SBrian Somers.Fn rad_put_vendor_int 237b49a88f6SBrian Somersor 238b49a88f6SBrian Somers.Fn rad_put_vendor_string 23981b380a8SRuslan Ermilovmay be used to specify vendor specific attributes. 24081b380a8SRuslan ErmilovVendor specific 241b49a88f6SBrian Somersdefinitions may be found in 242fe08efe6SRuslan Ermilov.In radlib_vs.h 243082bfe67SJohn Polstra.Pp 244082bfe67SJohn PolstraThe library also provides a function 245082bfe67SJohn Polstra.Fn rad_put_attr 24681b380a8SRuslan Ermilovwhich can be used to supply a raw, uninterpreted attribute. 24781b380a8SRuslan ErmilovThe 24881b380a8SRuslan Ermilov.Fa data 249082bfe67SJohn Polstraargument points to an array of bytes, and the 25081b380a8SRuslan Ermilov.Fa len 251082bfe67SJohn Polstraargument specifies its length. 252082bfe67SJohn Polstra.Pp 253b4b831efSRuslan ErmilovIt is possible adding the Message-Authenticator to the request. 254b4b831efSRuslan ErmilovThis is an HMAC-MD5 hash of the entire Access-Request packet (see RFC 3579). 255b4b831efSRuslan ErmilovThis attribute must be present in any packet that includes an EAP-Message 256b4b831efSRuslan Ermilovattribute. 257b4b831efSRuslan ErmilovIt can be added by using the 258b4b831efSRuslan Ermilov.Fn rad_put_message_authentic 259b4b831efSRuslan Ermilovfunction. 260b4b831efSRuslan ErmilovThe 261b4b831efSRuslan Ermilov.Nm 262b4b831efSRuslan Ermilovlibrary 263b4b831efSRuslan Ermilovcalculates the HMAC-MD5 hash implicitly before sending the request. 264b4b831efSRuslan ErmilovIf the Message-Authenticator was found inside the response packet, 265b4b831efSRuslan Ermilovthen the packet is silently dropped, if the validation failed. 266b4b831efSRuslan ErmilovIn order to get this feature, the library should be compiled with 267b4b831efSRuslan ErmilovOpenSSL support. 268b4b831efSRuslan Ermilov.Pp 269082bfe67SJohn PolstraThe 270082bfe67SJohn Polstra.Fn rad_put_X 27181b380a8SRuslan Ermilovfunctions return 0 on success, or \-1 if an error occurs. 27281b380a8SRuslan Ermilov.Ss Sending the Request and Receiving the Response 27348caee2aSBrian SomersAfter the RADIUS request has been constructed, it is sent either by means of 27448caee2aSBrian Somers.Fn rad_send_request 27548caee2aSBrian Somersor by a combination of calls to 27648caee2aSBrian Somers.Fn rad_init_send_request 27748caee2aSBrian Somersand 27848caee2aSBrian Somers.Fn rad_continue_send_request . 27948caee2aSBrian Somers.Pp 28048caee2aSBrian SomersThe 28148caee2aSBrian Somers.Fn rad_send_request 28248caee2aSBrian Somersfunction sends the request and waits for a valid reply, 283082bfe67SJohn Polstraretrying the defined servers in round-robin fashion as necessary. 284082bfe67SJohn PolstraIf a valid response is received, 285082bfe67SJohn Polstra.Fn rad_send_request 286082bfe67SJohn Polstrareturns the RADIUS code which specifies the type of the response. 287082bfe67SJohn PolstraThis will typically be 288082bfe67SJohn Polstra.Dv RAD_ACCESS_ACCEPT , 289082bfe67SJohn Polstra.Dv RAD_ACCESS_REJECT , 290082bfe67SJohn Polstraor 291082bfe67SJohn Polstra.Dv RAD_ACCESS_CHALLENGE . 292082bfe67SJohn PolstraIf no valid response is received, 293082bfe67SJohn Polstra.Fn rad_send_request 29481b380a8SRuslan Ermilovreturns \-1. 295082bfe67SJohn Polstra.Pp 29648caee2aSBrian SomersAs an alternative, if you do not wish to block waiting for a response, 29748caee2aSBrian Somers.Fn rad_init_send_request 29848caee2aSBrian Somersand 29948caee2aSBrian Somers.Fn rad_continue_send_request 30081b380a8SRuslan Ermilovmay be used instead. 30181b380a8SRuslan ErmilovIf a reply is received from the RADIUS server or a 30248caee2aSBrian Somerstimeout occurs, these functions return a value as described for 30348caee2aSBrian Somers.Fn rad_send_request . 30448caee2aSBrian SomersOtherwise, a value of zero is returned and the values pointed to by 30581b380a8SRuslan Ermilov.Fa fd 30648caee2aSBrian Somersand 30781b380a8SRuslan Ermilov.Fa tv 30848caee2aSBrian Somersare set to the descriptor and timeout that should be passed to 30948caee2aSBrian Somers.Xr select 2 . 31048caee2aSBrian Somers.Pp 31148caee2aSBrian Somers.Fn rad_init_send_request 31248caee2aSBrian Somersmust be called first, followed by repeated calls to 31348caee2aSBrian Somers.Fn rad_continue_send_request 31448caee2aSBrian Somersas long as a return value of zero is given. 31548caee2aSBrian SomersBetween each call, the application should call 31648caee2aSBrian Somers.Xr select 2 , 31748caee2aSBrian Somerspassing 31881b380a8SRuslan Ermilov.Fa *fd 31948caee2aSBrian Somersas a read descriptor and timing out after the interval specified by 32081b380a8SRuslan Ermilov.Fa tv . 32181b380a8SRuslan ErmilovWhen 32281b380a8SRuslan Ermilov.Xr select 2 32381b380a8SRuslan Ermilovreturns, 32448caee2aSBrian Somers.Fn rad_continue_send_request 32548caee2aSBrian Somersshould be called with 32681b380a8SRuslan Ermilov.Fa selected 32748caee2aSBrian Somersset to a non-zero value if 32848caee2aSBrian Somers.Xr select 2 32948caee2aSBrian Somersindicated that the descriptor is readable. 33048caee2aSBrian Somers.Pp 331082bfe67SJohn PolstraLike RADIUS requests, each response may contain zero or more 33281b380a8SRuslan Ermilovattributes. 33381b380a8SRuslan ErmilovAfter a response has been received successfully by 33448caee2aSBrian Somers.Fn rad_send_request 33548caee2aSBrian Somersor 33648caee2aSBrian Somers.Fn rad_continue_send_request , 337082bfe67SJohn Polstraits attributes can be extracted one by one using 338082bfe67SJohn Polstra.Fn rad_get_attr . 339082bfe67SJohn PolstraEach time 340082bfe67SJohn Polstra.Fn rad_get_attr 341082bfe67SJohn Polstrais called, it gets the next attribute from the current response, and 342082bfe67SJohn Polstrastores a pointer to the data and the length of the data via the 343082bfe67SJohn Polstrareference parameters 34481b380a8SRuslan Ermilov.Fa data 345082bfe67SJohn Polstraand 34681b380a8SRuslan Ermilov.Fa len , 34781b380a8SRuslan Ermilovrespectively. 34881b380a8SRuslan ErmilovNote that the data resides in the response itself, 349082bfe67SJohn Polstraand must not be modified. 350082bfe67SJohn PolstraA successful call to 351082bfe67SJohn Polstra.Fn rad_get_attr 352082bfe67SJohn Polstrareturns the RADIUS attribute type. 353082bfe67SJohn PolstraIf no more attributes remain in the current response, 354082bfe67SJohn Polstra.Fn rad_get_attr 355082bfe67SJohn Polstrareturns 0. 35681b380a8SRuslan ErmilovIf an error such as a malformed attribute is detected, \-1 is 357082bfe67SJohn Polstrareturned. 358082bfe67SJohn Polstra.Pp 359fc3f62faSBrian SomersIf 360fc3f62faSBrian Somers.Fn rad_get_attr 361fc3f62faSBrian Somersreturns 362fc3f62faSBrian Somers.Dv RAD_VENDOR_SPECIFIC , 363fc3f62faSBrian Somers.Fn rad_get_vendor_attr 364fc3f62faSBrian Somersmay be called to determine the vendor. 365fc3f62faSBrian SomersThe vendor specific RADIUS attribute type is returned. 366fc3f62faSBrian SomersThe reference parameters 36781b380a8SRuslan Ermilov.Fa data 368fc3f62faSBrian Somersand 36981b380a8SRuslan Ermilov.Fa len 37048091bb0SRuslan Ermilov(as returned from 37148091bb0SRuslan Ermilov.Fn rad_get_attr ) 372fc3f62faSBrian Somersare passed to 373fc3f62faSBrian Somers.Fn rad_get_vendor_attr , 374fc3f62faSBrian Somersand are adjusted to point to the vendor specific attribute data. 375fc3f62faSBrian Somers.Pp 376082bfe67SJohn PolstraThe common types of attributes can be decoded using 377082bfe67SJohn Polstra.Fn rad_cvt_addr , 378082bfe67SJohn Polstra.Fn rad_cvt_int , 379082bfe67SJohn Polstraand 380082bfe67SJohn Polstra.Fn rad_cvt_string . 381082bfe67SJohn PolstraThese functions accept a pointer to the attribute data, which should 382082bfe67SJohn Polstrahave been obtained using 383fc3f62faSBrian Somers.Fn rad_get_attr 384fc3f62faSBrian Somersand optionally 385fc3f62faSBrian Somers.Fn rad_get_vendor_attr . 386082bfe67SJohn PolstraIn the case of 387082bfe67SJohn Polstra.Fn rad_cvt_string , 388082bfe67SJohn Polstrathe length 38981b380a8SRuslan Ermilov.Fa len 39081b380a8SRuslan Ermilovmust also be given. 39181b380a8SRuslan ErmilovThese functions interpret the attribute as an 392082bfe67SJohn PolstraInternet address, an integer, or a string, respectively, and return 393082bfe67SJohn Polstraits value. 394082bfe67SJohn Polstra.Fn rad_cvt_string 39581b380a8SRuslan Ermilovreturns its value as a 39681b380a8SRuslan Ermilov.Dv NUL Ns -terminated 39781b380a8SRuslan Ermilovstring in dynamically 39881b380a8SRuslan Ermilovallocated memory. 39981b380a8SRuslan ErmilovThe application should free the string using 400082bfe67SJohn Polstra.Xr free 3 401082bfe67SJohn Polstrawhen it is no longer needed. 402082bfe67SJohn Polstra.Pp 403082bfe67SJohn PolstraIf insufficient virtual memory is available, 404082bfe67SJohn Polstra.Fn rad_cvt_string 405082bfe67SJohn Polstrareturns 406082bfe67SJohn Polstra.Dv NULL . 407082bfe67SJohn Polstra.Fn rad_cvt_addr 408082bfe67SJohn Polstraand 409082bfe67SJohn Polstra.Fn rad_cvt_int 410082bfe67SJohn Polstracannot fail. 411628e6cd4SBrian Somers.Pp 412628e6cd4SBrian SomersThe 413628e6cd4SBrian Somers.Fn rad_request_authenticator 414628e6cd4SBrian Somersfunction may be used to obtain the Request-Authenticator attribute value 415628e6cd4SBrian Somersassociated with the current RADIUS server according to the supplied 416628e6cd4SBrian Somersrad_handle. 417628e6cd4SBrian SomersThe target buffer 41881b380a8SRuslan Ermilov.Fa buf 419628e6cd4SBrian Somersof length 42081b380a8SRuslan Ermilov.Fa len 421628e6cd4SBrian Somersmust be supplied and should be at least 16 bytes. 422628e6cd4SBrian SomersThe return value is the number of bytes written to 42381b380a8SRuslan Ermilov.Fa buf 42481b380a8SRuslan Ermilovor \-1 to indicate that 42581b380a8SRuslan Ermilov.Fa len 426628e6cd4SBrian Somerswas not large enough. 427628e6cd4SBrian Somers.Pp 428628e6cd4SBrian SomersThe 429628e6cd4SBrian Somers.Fn rad_server_secret 430628e6cd4SBrian Somersreturns the secret shared with the current RADIUS server according to the 431628e6cd4SBrian Somerssupplied rad_handle. 432b4b831efSRuslan Ermilov.Pp 433b4b831efSRuslan ErmilovThe 434b4b831efSRuslan Ermilov.Fn rad_demangle 435b4b831efSRuslan Ermilovfunction demangles attributes containing passwords and MS-CHAPv1 MPPE-Keys. 436b4b831efSRuslan ErmilovThe return value is 437b4b831efSRuslan Ermilov.Dv NULL 438b4b831efSRuslan Ermilovon failure, or the plaintext attribute. 439b4b831efSRuslan ErmilovThis value should be freed using 440b4b831efSRuslan Ermilov.Xr free 3 441b4b831efSRuslan Ermilovwhen it is no longer needed. 442b4b831efSRuslan Ermilov.Pp 443b4b831efSRuslan ErmilovThe 444b4b831efSRuslan Ermilov.Fn rad_demangle_mppe_key 445b4b831efSRuslan Ermilovfunction demangles the send- and recv-keys when using MPPE (see RFC 2548). 446b4b831efSRuslan ErmilovThe return value is 447b4b831efSRuslan Ermilov.Dv NULL 448b4b831efSRuslan Ermilovon failure, or the plaintext attribute. 449b4b831efSRuslan ErmilovThis value should be freed using 450b4b831efSRuslan Ermilov.Xr free 3 451b4b831efSRuslan Ermilovwhen it is no longer needed. 45281b380a8SRuslan Ermilov.Ss Obtaining Error Messages 453082bfe67SJohn PolstraThose functions which accept a 45481b380a8SRuslan Ermilov.Vt "struct rad_handle *" 45581b380a8SRuslan Ermilovargument record an error message if they fail. 45681b380a8SRuslan ErmilovThe error message 457082bfe67SJohn Polstracan be retrieved by calling 458082bfe67SJohn Polstra.Fn rad_strerror . 459082bfe67SJohn PolstraThe message text is overwritten on each new error for the given 46081b380a8SRuslan Ermilov.Vt "struct rad_handle *" . 461082bfe67SJohn PolstraThus the message must be copied if it is to be preserved through 462082bfe67SJohn Polstrasubsequent library calls using the same handle. 46381b380a8SRuslan Ermilov.Ss Cleanup 464082bfe67SJohn PolstraTo free the resources used by the RADIUS library, call 465082bfe67SJohn Polstra.Fn rad_close . 4663fc0b61cSAlexander Motin.Ss Server operation 4673fc0b61cSAlexander MotinServer mode operates much alike to client mode, except packet send and receieve 4683fc0b61cSAlexander Motinsteps are swapped. To operate as server you should obtain server context with 4693fc0b61cSAlexander Motin.Fn rad_server_open 4703fc0b61cSAlexander Motinfunction, passing opened and bound UDP socket file descriptor as argument. 4713fc0b61cSAlexander MotinYou should define allowed clients and their secrets using 4723fc0b61cSAlexander Motin.Fn rad_add_server 4733fc0b61cSAlexander Motinfunction. port, timeout and max_tries arguments are ignored in server mode. 4743fc0b61cSAlexander MotinYou should call 4753fc0b61cSAlexander Motin.Fn rad_receive_request 4763fc0b61cSAlexander Motinfunction to receive request from client. If you do not want to block on socket 4773fc0b61cSAlexander Motinread, you are free to use any poll(), select() or non-blocking sockets for 4783fc0b61cSAlexander Motinthe socket. 4793fc0b61cSAlexander MotinReceived request can be parsed with same parsing functions as for client. 4803fc0b61cSAlexander MotinTo respond to the request you should call 4813fc0b61cSAlexander Motin.Fn rad_create_response 4823fc0b61cSAlexander Motinand fill response content with same packet writing functions as for client. 4833fc0b61cSAlexander MotinWhen packet is ready, it should be sent with 4843fc0b61cSAlexander Motin.Fn rad_send_response 485082bfe67SJohn Polstra.Sh RETURN VALUES 48681b380a8SRuslan ErmilovThe following functions return a non-negative value on success. 48781b380a8SRuslan ErmilovIf 48881b380a8SRuslan Ermilovthey detect an error, they return \-1 and record an error message 489082bfe67SJohn Polstrawhich can be retrieved using 490082bfe67SJohn Polstra.Fn rad_strerror . 491082bfe67SJohn Polstra.Pp 492082bfe67SJohn Polstra.Bl -item -offset indent -compact 493082bfe67SJohn Polstra.It 494082bfe67SJohn Polstra.Fn rad_add_server 495082bfe67SJohn Polstra.It 496082bfe67SJohn Polstra.Fn rad_config 497082bfe67SJohn Polstra.It 498082bfe67SJohn Polstra.Fn rad_create_request 499082bfe67SJohn Polstra.It 5003fc0b61cSAlexander Motin.Fn rad_create_response 5013fc0b61cSAlexander Motin.It 502082bfe67SJohn Polstra.Fn rad_get_attr 503082bfe67SJohn Polstra.It 504082bfe67SJohn Polstra.Fn rad_put_addr 505082bfe67SJohn Polstra.It 506082bfe67SJohn Polstra.Fn rad_put_attr 507082bfe67SJohn Polstra.It 508082bfe67SJohn Polstra.Fn rad_put_int 509082bfe67SJohn Polstra.It 510082bfe67SJohn Polstra.Fn rad_put_string 511082bfe67SJohn Polstra.It 512b4b831efSRuslan Ermilov.Fn rad_put_message_authentic 513b4b831efSRuslan Ermilov.It 51448caee2aSBrian Somers.Fn rad_init_send_request 51548caee2aSBrian Somers.It 51648caee2aSBrian Somers.Fn rad_continue_send_request 51748caee2aSBrian Somers.It 518082bfe67SJohn Polstra.Fn rad_send_request 5193fc0b61cSAlexander Motin.It 5203fc0b61cSAlexander Motin.Fn rad_send_response 521082bfe67SJohn Polstra.El 522082bfe67SJohn Polstra.Pp 523082bfe67SJohn PolstraThe following functions return a 524082bfe67SJohn Polstra.No non- Ns Dv NULL 52581b380a8SRuslan Ermilovpointer on success. 52681b380a8SRuslan ErmilovIf they are unable to allocate sufficient 527082bfe67SJohn Polstravirtual memory, they return 528082bfe67SJohn Polstra.Dv NULL , 529082bfe67SJohn Polstrawithout recording an error message. 530082bfe67SJohn Polstra.Pp 531082bfe67SJohn Polstra.Bl -item -offset indent -compact 532082bfe67SJohn Polstra.It 5330981dfefSJohn Polstra.Fn rad_acct_open 534082bfe67SJohn Polstra.It 5350981dfefSJohn Polstra.Fn rad_auth_open 5360981dfefSJohn Polstra.It 5373fc0b61cSAlexander Motin.Fn rad_server_open 5383fc0b61cSAlexander Motin.It 5390981dfefSJohn Polstra.Fn rad_cvt_string 540082bfe67SJohn Polstra.El 541b4b831efSRuslan Ermilov.Pp 542b4b831efSRuslan ErmilovThe following functions return a 543b4b831efSRuslan Ermilov.No non- Ns Dv NULL 544b4b831efSRuslan Ermilovpointer on success. 545b4b831efSRuslan ErmilovIf they fail, they return 546b4b831efSRuslan Ermilov.Dv NULL , 547b4b831efSRuslan Ermilovwith recording an error message. 548b4b831efSRuslan Ermilov.Pp 549b4b831efSRuslan Ermilov.Bl -item -offset indent -compact 550b4b831efSRuslan Ermilov.It 551b4b831efSRuslan Ermilov.Fn rad_demangle 552b4b831efSRuslan Ermilov.It 553b4b831efSRuslan Ermilov.Fn rad_demangle_mppe_key 554b4b831efSRuslan Ermilov.El 555082bfe67SJohn Polstra.Sh FILES 55681b380a8SRuslan Ermilov.Bl -tag -width indent 55781b380a8SRuslan Ermilov.It Pa /etc/radius.conf 55881b380a8SRuslan Ermilov.El 559082bfe67SJohn Polstra.Sh SEE ALSO 560082bfe67SJohn Polstra.Xr radius.conf 5 561082bfe67SJohn Polstra.Rs 56281b380a8SRuslan Ermilov.%A "C. Rigney, et al" 56342635956SRuslan Ermilov.%T "Remote Authentication Dial In User Service (RADIUS)" 564b4b831efSRuslan Ermilov.%O "RFC 2865" 565082bfe67SJohn Polstra.Re 5660981dfefSJohn Polstra.Rs 56781b380a8SRuslan Ermilov.%A "C. Rigney" 56881b380a8SRuslan Ermilov.%T "RADIUS Accounting" 569b4b831efSRuslan Ermilov.%O "RFC 2866" 570b4b831efSRuslan Ermilov.Re 571b4b831efSRuslan Ermilov.Rs 572b4b831efSRuslan Ermilov.%A G. Zorn 573b4b831efSRuslan Ermilov.%T "Microsoft Vendor-specific RADIUS attributes" 574b4b831efSRuslan Ermilov.%O RFC 2548 575b4b831efSRuslan Ermilov.Re 576b4b831efSRuslan Ermilov.Rs 577b4b831efSRuslan Ermilov.%A C. Rigney, et al 578b4b831efSRuslan Ermilov.%T "RADIUS extensions" 579b4b831efSRuslan Ermilov.%O RFC 2869 5800981dfefSJohn Polstra.Re 581082bfe67SJohn Polstra.Sh AUTHORS 58281b380a8SRuslan Ermilov.An -nosplit 5830981dfefSJohn PolstraThis software was originally written by 584082bfe67SJohn Polstra.An John Polstra , 585b5c508fbSRuslan Ermilovand donated to the 586b5c508fbSRuslan Ermilov.Fx 587b5c508fbSRuslan Ermilovproject by Juniper Networks, Inc. 58881b380a8SRuslan Ermilov.An Oleg Semyonov 58981b380a8SRuslan Ermilovsubsequently added the ability to perform RADIUS 5900981dfefSJohn Polstraaccounting. 591b4b831efSRuslan ErmilovLater additions and changes by 592b4b831efSRuslan Ermilov.An Michael Bretterklieber . 5933fc0b61cSAlexander MotinServer mode support was added by 5943fc0b61cSAlexander Motin.An Alexander Motin . 595