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" 94*07d7b74bSAlexander V. Chernikov.Ft "void" 95*07d7b74bSAlexander V. Chernikov.Fn rad_bind_to "struct rad_handle *h" "in_addr_t addr" 96b4b831efSRuslan Ermilov.Ft u_char * 97b4b831efSRuslan Ermilov.Fn rad_demangle "struct rad_handle *h" "const void *mangled" "size_t mlen" 98b4b831efSRuslan Ermilov.Ft u_char * 99b4b831efSRuslan Ermilov.Fn rad_demangle_mppe_key "struct rad_handle *h" "const void *mangled" "size_t mlen" "size_t *len" 10081b380a8SRuslan Ermilov.Ft "const char *" 101082bfe67SJohn Polstra.Fn rad_strerror "struct rad_handle *h" 102082bfe67SJohn Polstra.Sh DESCRIPTION 103082bfe67SJohn PolstraThe 104082bfe67SJohn Polstra.Nm 1053fc0b61cSAlexander Motinlibrary implements the Remote Authentication Dial In User Service (RADIUS). 106b4b831efSRuslan ErmilovRADIUS, defined in RFCs 2865 and 2866, 1070981dfefSJohn Polstraallows clients to perform authentication and accounting by means of 1080981dfefSJohn Polstranetwork requests to remote servers. 10981b380a8SRuslan Ermilov.Ss Initialization 110082bfe67SJohn PolstraTo use the library, an application must first call 1110981dfefSJohn Polstra.Fn rad_auth_open 1123fc0b61cSAlexander Motin, 1130981dfefSJohn Polstra.Fn rad_acct_open 1143fc0b61cSAlexander Motinor 1153fc0b61cSAlexander Motin.Fn rad_server_open 116082bfe67SJohn Polstrato obtain a 11781b380a8SRuslan Ermilov.Vt "struct rad_handle *" , 118082bfe67SJohn Polstrawhich provides the context for subsequent operations. 1190981dfefSJohn PolstraThe former function is used for RADIUS authentication and the 1200981dfefSJohn Polstralatter is used for RADIUS accounting. 121082bfe67SJohn PolstraCalls to 1220981dfefSJohn Polstra.Fn rad_auth_open 1233fc0b61cSAlexander Motin, 1240981dfefSJohn Polstra.Fn rad_acct_open 1253fc0b61cSAlexander Motinand 1263fc0b61cSAlexander Motin.Fn rad_server_open 12781b380a8SRuslan Ermilovalways succeed unless insufficient virtual memory is available. 12881b380a8SRuslan ErmilovIf 1290981dfefSJohn Polstrathe necessary memory cannot be allocated, the functions return 130082bfe67SJohn Polstra.Dv NULL . 1310981dfefSJohn PolstraFor compatibility with earlier versions of this library, 1320981dfefSJohn Polstra.Fn rad_open 1330981dfefSJohn Polstrais provided as a synonym for 1340981dfefSJohn Polstra.Fn rad_auth_open . 135082bfe67SJohn Polstra.Pp 136082bfe67SJohn PolstraBefore issuing any RADIUS requests, the library must be made aware 13781b380a8SRuslan Ermilovof the servers it can contact. 13881b380a8SRuslan ErmilovThe easiest way to configure the 139082bfe67SJohn Polstralibrary is to call 140082bfe67SJohn Polstra.Fn rad_config . 141082bfe67SJohn Polstra.Fn rad_config 142082bfe67SJohn Polstracauses the library to read a configuration file whose format is 143082bfe67SJohn Polstradescribed in 144082bfe67SJohn Polstra.Xr radius.conf 5 . 145082bfe67SJohn PolstraThe pathname of the configuration file is passed as the 14681b380a8SRuslan Ermilov.Fa file 147082bfe67SJohn Polstraargument to 148082bfe67SJohn Polstra.Fn rad_config . 149082bfe67SJohn PolstraThis argument may also be given as 150082bfe67SJohn Polstra.Dv NULL , 151082bfe67SJohn Polstrain which case the standard configuration file 152082bfe67SJohn Polstra.Pa /etc/radius.conf 153082bfe67SJohn Polstrais used. 154082bfe67SJohn Polstra.Fn rad_config 15581b380a8SRuslan Ermilovreturns 0 on success, or \-1 if an error occurs. 156082bfe67SJohn Polstra.Pp 157082bfe67SJohn PolstraThe library can also be configured programmatically by calls to 158082bfe67SJohn Polstra.Fn rad_add_server . 159082bfe67SJohn PolstraThe 16081b380a8SRuslan Ermilov.Fa host 161082bfe67SJohn Polstraparameter specifies the server host, either as a fully qualified 162082bfe67SJohn Polstradomain name or as a dotted-quad IP address in text form. 163082bfe67SJohn PolstraThe 16481b380a8SRuslan Ermilov.Fa port 16581b380a8SRuslan Ermilovparameter specifies the UDP port to contact on the server. 16681b380a8SRuslan ErmilovIf 16781b380a8SRuslan Ermilov.Fa port 168082bfe67SJohn Polstrais given as 0, the library looks up the 169082bfe67SJohn Polstra.Ql radius/udp 1700981dfefSJohn Polstraor 1710981dfefSJohn Polstra.Ql radacct/udp 17281b380a8SRuslan Ermilovservice in the network 17381b380a8SRuslan Ermilov.Xr services 5 17481b380a8SRuslan Ermilovdatabase, and uses the port found 17581b380a8SRuslan Ermilovthere. 17681b380a8SRuslan ErmilovIf no entry is found, the library uses the standard RADIUS 1770981dfefSJohn Polstraports, 1812 for authentication and 1813 for accounting. 1780981dfefSJohn PolstraThe shared secret for the server host is passed to the 17981b380a8SRuslan Ermilov.Fa secret 180082bfe67SJohn Polstraparameter. 18181b380a8SRuslan ErmilovIt may be any 18281b380a8SRuslan Ermilov.Dv NUL Ns -terminated 18381b380a8SRuslan Ermilovstring of bytes. 18481b380a8SRuslan ErmilovThe RADIUS protocol 185082bfe67SJohn Polstraignores all but the leading 128 bytes of the shared secret. 186082bfe67SJohn PolstraThe timeout for receiving replies from the server is passed to the 18781b380a8SRuslan Ermilov.Fa timeout 18881b380a8SRuslan Ermilovparameter, in units of seconds. 18981b380a8SRuslan ErmilovThe maximum number of repeated 190082bfe67SJohn Polstrarequests to make before giving up is passed into the 19181b380a8SRuslan Ermilov.Fa max_tries 192082bfe67SJohn Polstraparameter. 193082bfe67SJohn Polstra.Fn rad_add_server 19481b380a8SRuslan Ermilovreturns 0 on success, or \-1 if an error occurs. 195082bfe67SJohn Polstra.Pp 196082bfe67SJohn Polstra.Fn rad_add_server 197082bfe67SJohn Polstramay be called multiple times, and it may be used together with 198082bfe67SJohn Polstra.Fn rad_config . 199082bfe67SJohn PolstraAt most 10 servers may be specified. 200082bfe67SJohn PolstraWhen multiple servers are given, they are tried in round-robin 201082bfe67SJohn Polstrafashion until a valid response is received, or until each server's 20281b380a8SRuslan Ermilov.Fa max_tries 203082bfe67SJohn Polstralimit has been reached. 20481b380a8SRuslan Ermilov.Ss Creating a RADIUS Request 205082bfe67SJohn PolstraA RADIUS request consists of a code specifying the kind of request, 20681b380a8SRuslan Ermilovand zero or more attributes which provide additional information. 20781b380a8SRuslan ErmilovTo 208082bfe67SJohn Polstrabegin constructing a new request, call 209082bfe67SJohn Polstra.Fn rad_create_request . 210082bfe67SJohn PolstraIn addition to the usual 21181b380a8SRuslan Ermilov.Vt "struct rad_handle *" , 212082bfe67SJohn Polstrathis function takes a 21381b380a8SRuslan Ermilov.Fa code 21481b380a8SRuslan Ermilovparameter which specifies the type of the request. 21581b380a8SRuslan ErmilovMost often this 216082bfe67SJohn Polstrawill be 217082bfe67SJohn Polstra.Dv RAD_ACCESS_REQUEST . 218082bfe67SJohn Polstra.Fn rad_create_request 21981b380a8SRuslan Ermilovreturns 0 on success, or \-1 on if an error occurs. 220082bfe67SJohn Polstra.Pp 221082bfe67SJohn PolstraAfter the request has been created with 222abac9a9eSBrian Somers.Fn rad_create_request , 22381b380a8SRuslan Ermilovattributes can be attached to it. 22481b380a8SRuslan ErmilovThis is done through calls to 225082bfe67SJohn Polstra.Fn rad_put_addr , 226082bfe67SJohn Polstra.Fn rad_put_int , 227082bfe67SJohn Polstraand 228082bfe67SJohn Polstra.Fn rad_put_string . 229082bfe67SJohn PolstraEach accepts a 23081b380a8SRuslan Ermilov.Fa type 231082bfe67SJohn Polstraparameter identifying the attribute, and a value which may be 23281b380a8SRuslan Ermilovan Internet address, an integer, or a 23381b380a8SRuslan Ermilov.Dv NUL Ns -terminated 23481b380a8SRuslan Ermilovstring, 235082bfe67SJohn Polstrarespectively. 236b49a88f6SBrian SomersAlternatively, 237b49a88f6SBrian Somers.Fn rad_put_vendor_addr , 238b49a88f6SBrian Somers.Fn rad_put_vendor_int 239b49a88f6SBrian Somersor 240b49a88f6SBrian Somers.Fn rad_put_vendor_string 24181b380a8SRuslan Ermilovmay be used to specify vendor specific attributes. 24281b380a8SRuslan ErmilovVendor specific 243b49a88f6SBrian Somersdefinitions may be found in 244fe08efe6SRuslan Ermilov.In radlib_vs.h 245082bfe67SJohn Polstra.Pp 246082bfe67SJohn PolstraThe library also provides a function 247082bfe67SJohn Polstra.Fn rad_put_attr 24881b380a8SRuslan Ermilovwhich can be used to supply a raw, uninterpreted attribute. 24981b380a8SRuslan ErmilovThe 25081b380a8SRuslan Ermilov.Fa data 251082bfe67SJohn Polstraargument points to an array of bytes, and the 25281b380a8SRuslan Ermilov.Fa len 253082bfe67SJohn Polstraargument specifies its length. 254082bfe67SJohn Polstra.Pp 255b4b831efSRuslan ErmilovIt is possible adding the Message-Authenticator to the request. 256b4b831efSRuslan ErmilovThis is an HMAC-MD5 hash of the entire Access-Request packet (see RFC 3579). 257b4b831efSRuslan ErmilovThis attribute must be present in any packet that includes an EAP-Message 258b4b831efSRuslan Ermilovattribute. 259b4b831efSRuslan ErmilovIt can be added by using the 260b4b831efSRuslan Ermilov.Fn rad_put_message_authentic 261b4b831efSRuslan Ermilovfunction. 262b4b831efSRuslan ErmilovThe 263b4b831efSRuslan Ermilov.Nm 264b4b831efSRuslan Ermilovlibrary 265b4b831efSRuslan Ermilovcalculates the HMAC-MD5 hash implicitly before sending the request. 266b4b831efSRuslan ErmilovIf the Message-Authenticator was found inside the response packet, 267b4b831efSRuslan Ermilovthen the packet is silently dropped, if the validation failed. 268b4b831efSRuslan ErmilovIn order to get this feature, the library should be compiled with 269b4b831efSRuslan ErmilovOpenSSL support. 270b4b831efSRuslan Ermilov.Pp 271082bfe67SJohn PolstraThe 272082bfe67SJohn Polstra.Fn rad_put_X 27381b380a8SRuslan Ermilovfunctions return 0 on success, or \-1 if an error occurs. 27481b380a8SRuslan Ermilov.Ss Sending the Request and Receiving the Response 27548caee2aSBrian SomersAfter the RADIUS request has been constructed, it is sent either by means of 27648caee2aSBrian Somers.Fn rad_send_request 27748caee2aSBrian Somersor by a combination of calls to 27848caee2aSBrian Somers.Fn rad_init_send_request 27948caee2aSBrian Somersand 28048caee2aSBrian Somers.Fn rad_continue_send_request . 28148caee2aSBrian Somers.Pp 28248caee2aSBrian SomersThe 28348caee2aSBrian Somers.Fn rad_send_request 28448caee2aSBrian Somersfunction sends the request and waits for a valid reply, 285082bfe67SJohn Polstraretrying the defined servers in round-robin fashion as necessary. 286082bfe67SJohn PolstraIf a valid response is received, 287082bfe67SJohn Polstra.Fn rad_send_request 288082bfe67SJohn Polstrareturns the RADIUS code which specifies the type of the response. 289082bfe67SJohn PolstraThis will typically be 290082bfe67SJohn Polstra.Dv RAD_ACCESS_ACCEPT , 291082bfe67SJohn Polstra.Dv RAD_ACCESS_REJECT , 292082bfe67SJohn Polstraor 293082bfe67SJohn Polstra.Dv RAD_ACCESS_CHALLENGE . 294082bfe67SJohn PolstraIf no valid response is received, 295082bfe67SJohn Polstra.Fn rad_send_request 29681b380a8SRuslan Ermilovreturns \-1. 297082bfe67SJohn Polstra.Pp 29848caee2aSBrian SomersAs an alternative, if you do not wish to block waiting for a response, 29948caee2aSBrian Somers.Fn rad_init_send_request 30048caee2aSBrian Somersand 30148caee2aSBrian Somers.Fn rad_continue_send_request 30281b380a8SRuslan Ermilovmay be used instead. 30381b380a8SRuslan ErmilovIf a reply is received from the RADIUS server or a 30448caee2aSBrian Somerstimeout occurs, these functions return a value as described for 30548caee2aSBrian Somers.Fn rad_send_request . 30648caee2aSBrian SomersOtherwise, a value of zero is returned and the values pointed to by 30781b380a8SRuslan Ermilov.Fa fd 30848caee2aSBrian Somersand 30981b380a8SRuslan Ermilov.Fa tv 31048caee2aSBrian Somersare set to the descriptor and timeout that should be passed to 31148caee2aSBrian Somers.Xr select 2 . 31248caee2aSBrian Somers.Pp 31348caee2aSBrian Somers.Fn rad_init_send_request 31448caee2aSBrian Somersmust be called first, followed by repeated calls to 31548caee2aSBrian Somers.Fn rad_continue_send_request 31648caee2aSBrian Somersas long as a return value of zero is given. 31748caee2aSBrian SomersBetween each call, the application should call 31848caee2aSBrian Somers.Xr select 2 , 31948caee2aSBrian Somerspassing 32081b380a8SRuslan Ermilov.Fa *fd 32148caee2aSBrian Somersas a read descriptor and timing out after the interval specified by 32281b380a8SRuslan Ermilov.Fa tv . 32381b380a8SRuslan ErmilovWhen 32481b380a8SRuslan Ermilov.Xr select 2 32581b380a8SRuslan Ermilovreturns, 32648caee2aSBrian Somers.Fn rad_continue_send_request 32748caee2aSBrian Somersshould be called with 32881b380a8SRuslan Ermilov.Fa selected 32948caee2aSBrian Somersset to a non-zero value if 33048caee2aSBrian Somers.Xr select 2 33148caee2aSBrian Somersindicated that the descriptor is readable. 33248caee2aSBrian Somers.Pp 333082bfe67SJohn PolstraLike RADIUS requests, each response may contain zero or more 33481b380a8SRuslan Ermilovattributes. 33581b380a8SRuslan ErmilovAfter a response has been received successfully by 33648caee2aSBrian Somers.Fn rad_send_request 33748caee2aSBrian Somersor 33848caee2aSBrian Somers.Fn rad_continue_send_request , 339082bfe67SJohn Polstraits attributes can be extracted one by one using 340082bfe67SJohn Polstra.Fn rad_get_attr . 341082bfe67SJohn PolstraEach time 342082bfe67SJohn Polstra.Fn rad_get_attr 343082bfe67SJohn Polstrais called, it gets the next attribute from the current response, and 344082bfe67SJohn Polstrastores a pointer to the data and the length of the data via the 345082bfe67SJohn Polstrareference parameters 34681b380a8SRuslan Ermilov.Fa data 347082bfe67SJohn Polstraand 34881b380a8SRuslan Ermilov.Fa len , 34981b380a8SRuslan Ermilovrespectively. 35081b380a8SRuslan ErmilovNote that the data resides in the response itself, 351082bfe67SJohn Polstraand must not be modified. 352082bfe67SJohn PolstraA successful call to 353082bfe67SJohn Polstra.Fn rad_get_attr 354082bfe67SJohn Polstrareturns the RADIUS attribute type. 355082bfe67SJohn PolstraIf no more attributes remain in the current response, 356082bfe67SJohn Polstra.Fn rad_get_attr 357082bfe67SJohn Polstrareturns 0. 35881b380a8SRuslan ErmilovIf an error such as a malformed attribute is detected, \-1 is 359082bfe67SJohn Polstrareturned. 360082bfe67SJohn Polstra.Pp 361fc3f62faSBrian SomersIf 362fc3f62faSBrian Somers.Fn rad_get_attr 363fc3f62faSBrian Somersreturns 364fc3f62faSBrian Somers.Dv RAD_VENDOR_SPECIFIC , 365fc3f62faSBrian Somers.Fn rad_get_vendor_attr 366fc3f62faSBrian Somersmay be called to determine the vendor. 367fc3f62faSBrian SomersThe vendor specific RADIUS attribute type is returned. 368fc3f62faSBrian SomersThe reference parameters 36981b380a8SRuslan Ermilov.Fa data 370fc3f62faSBrian Somersand 37181b380a8SRuslan Ermilov.Fa len 37248091bb0SRuslan Ermilov(as returned from 37348091bb0SRuslan Ermilov.Fn rad_get_attr ) 374fc3f62faSBrian Somersare passed to 375fc3f62faSBrian Somers.Fn rad_get_vendor_attr , 376fc3f62faSBrian Somersand are adjusted to point to the vendor specific attribute data. 377fc3f62faSBrian Somers.Pp 378082bfe67SJohn PolstraThe common types of attributes can be decoded using 379082bfe67SJohn Polstra.Fn rad_cvt_addr , 380082bfe67SJohn Polstra.Fn rad_cvt_int , 381082bfe67SJohn Polstraand 382082bfe67SJohn Polstra.Fn rad_cvt_string . 383082bfe67SJohn PolstraThese functions accept a pointer to the attribute data, which should 384082bfe67SJohn Polstrahave been obtained using 385fc3f62faSBrian Somers.Fn rad_get_attr 386fc3f62faSBrian Somersand optionally 387fc3f62faSBrian Somers.Fn rad_get_vendor_attr . 388082bfe67SJohn PolstraIn the case of 389082bfe67SJohn Polstra.Fn rad_cvt_string , 390082bfe67SJohn Polstrathe length 39181b380a8SRuslan Ermilov.Fa len 39281b380a8SRuslan Ermilovmust also be given. 39381b380a8SRuslan ErmilovThese functions interpret the attribute as an 394082bfe67SJohn PolstraInternet address, an integer, or a string, respectively, and return 395082bfe67SJohn Polstraits value. 396082bfe67SJohn Polstra.Fn rad_cvt_string 39781b380a8SRuslan Ermilovreturns its value as a 39881b380a8SRuslan Ermilov.Dv NUL Ns -terminated 39981b380a8SRuslan Ermilovstring in dynamically 40081b380a8SRuslan Ermilovallocated memory. 40181b380a8SRuslan ErmilovThe application should free the string using 402082bfe67SJohn Polstra.Xr free 3 403082bfe67SJohn Polstrawhen it is no longer needed. 404082bfe67SJohn Polstra.Pp 405082bfe67SJohn PolstraIf insufficient virtual memory is available, 406082bfe67SJohn Polstra.Fn rad_cvt_string 407082bfe67SJohn Polstrareturns 408082bfe67SJohn Polstra.Dv NULL . 409082bfe67SJohn Polstra.Fn rad_cvt_addr 410082bfe67SJohn Polstraand 411082bfe67SJohn Polstra.Fn rad_cvt_int 412082bfe67SJohn Polstracannot fail. 413628e6cd4SBrian Somers.Pp 414628e6cd4SBrian SomersThe 415628e6cd4SBrian Somers.Fn rad_request_authenticator 416628e6cd4SBrian Somersfunction may be used to obtain the Request-Authenticator attribute value 417628e6cd4SBrian Somersassociated with the current RADIUS server according to the supplied 418628e6cd4SBrian Somersrad_handle. 419628e6cd4SBrian SomersThe target buffer 42081b380a8SRuslan Ermilov.Fa buf 421628e6cd4SBrian Somersof length 42281b380a8SRuslan Ermilov.Fa len 423628e6cd4SBrian Somersmust be supplied and should be at least 16 bytes. 424628e6cd4SBrian SomersThe return value is the number of bytes written to 42581b380a8SRuslan Ermilov.Fa buf 42681b380a8SRuslan Ermilovor \-1 to indicate that 42781b380a8SRuslan Ermilov.Fa len 428628e6cd4SBrian Somerswas not large enough. 429628e6cd4SBrian Somers.Pp 430628e6cd4SBrian SomersThe 431628e6cd4SBrian Somers.Fn rad_server_secret 432628e6cd4SBrian Somersreturns the secret shared with the current RADIUS server according to the 433628e6cd4SBrian Somerssupplied rad_handle. 434b4b831efSRuslan Ermilov.Pp 435b4b831efSRuslan ErmilovThe 436*07d7b74bSAlexander V. Chernikov.Fn rad_bind_to 437*07d7b74bSAlexander V. Chernikovassigns a source address for all requests to the current RADIUS server. 438*07d7b74bSAlexander V. Chernikov.Pp 439*07d7b74bSAlexander V. ChernikovThe 440b4b831efSRuslan Ermilov.Fn rad_demangle 441b4b831efSRuslan Ermilovfunction demangles attributes containing passwords and MS-CHAPv1 MPPE-Keys. 442b4b831efSRuslan ErmilovThe return value is 443b4b831efSRuslan Ermilov.Dv NULL 444b4b831efSRuslan Ermilovon failure, or the plaintext attribute. 445b4b831efSRuslan ErmilovThis value should be freed using 446b4b831efSRuslan Ermilov.Xr free 3 447b4b831efSRuslan Ermilovwhen it is no longer needed. 448b4b831efSRuslan Ermilov.Pp 449b4b831efSRuslan ErmilovThe 450b4b831efSRuslan Ermilov.Fn rad_demangle_mppe_key 451b4b831efSRuslan Ermilovfunction demangles the send- and recv-keys when using MPPE (see RFC 2548). 452b4b831efSRuslan ErmilovThe return value is 453b4b831efSRuslan Ermilov.Dv NULL 454b4b831efSRuslan Ermilovon failure, or the plaintext attribute. 455b4b831efSRuslan ErmilovThis value should be freed using 456b4b831efSRuslan Ermilov.Xr free 3 457b4b831efSRuslan Ermilovwhen it is no longer needed. 45881b380a8SRuslan Ermilov.Ss Obtaining Error Messages 459082bfe67SJohn PolstraThose functions which accept a 46081b380a8SRuslan Ermilov.Vt "struct rad_handle *" 46181b380a8SRuslan Ermilovargument record an error message if they fail. 46281b380a8SRuslan ErmilovThe error message 463082bfe67SJohn Polstracan be retrieved by calling 464082bfe67SJohn Polstra.Fn rad_strerror . 465082bfe67SJohn PolstraThe message text is overwritten on each new error for the given 46681b380a8SRuslan Ermilov.Vt "struct rad_handle *" . 467082bfe67SJohn PolstraThus the message must be copied if it is to be preserved through 468082bfe67SJohn Polstrasubsequent library calls using the same handle. 46981b380a8SRuslan Ermilov.Ss Cleanup 470082bfe67SJohn PolstraTo free the resources used by the RADIUS library, call 471082bfe67SJohn Polstra.Fn rad_close . 4723fc0b61cSAlexander Motin.Ss Server operation 473c2025a76SJoel DahlServer mode operates much alike to client mode, except packet send and receive 4743fc0b61cSAlexander Motinsteps are swapped. To operate as server you should obtain server context with 4753fc0b61cSAlexander Motin.Fn rad_server_open 4763fc0b61cSAlexander Motinfunction, passing opened and bound UDP socket file descriptor as argument. 4773fc0b61cSAlexander MotinYou should define allowed clients and their secrets using 4783fc0b61cSAlexander Motin.Fn rad_add_server 4793fc0b61cSAlexander Motinfunction. port, timeout and max_tries arguments are ignored in server mode. 4803fc0b61cSAlexander MotinYou should call 4813fc0b61cSAlexander Motin.Fn rad_receive_request 4823fc0b61cSAlexander Motinfunction to receive request from client. If you do not want to block on socket 4833fc0b61cSAlexander Motinread, you are free to use any poll(), select() or non-blocking sockets for 4843fc0b61cSAlexander Motinthe socket. 4853fc0b61cSAlexander MotinReceived request can be parsed with same parsing functions as for client. 4863fc0b61cSAlexander MotinTo respond to the request you should call 4873fc0b61cSAlexander Motin.Fn rad_create_response 4883fc0b61cSAlexander Motinand fill response content with same packet writing functions as for client. 4893fc0b61cSAlexander MotinWhen packet is ready, it should be sent with 4903fc0b61cSAlexander Motin.Fn rad_send_response 491082bfe67SJohn Polstra.Sh RETURN VALUES 49281b380a8SRuslan ErmilovThe following functions return a non-negative value on success. 49381b380a8SRuslan ErmilovIf 49481b380a8SRuslan Ermilovthey detect an error, they return \-1 and record an error message 495082bfe67SJohn Polstrawhich can be retrieved using 496082bfe67SJohn Polstra.Fn rad_strerror . 497082bfe67SJohn Polstra.Pp 498082bfe67SJohn Polstra.Bl -item -offset indent -compact 499082bfe67SJohn Polstra.It 500082bfe67SJohn Polstra.Fn rad_add_server 501082bfe67SJohn Polstra.It 502082bfe67SJohn Polstra.Fn rad_config 503082bfe67SJohn Polstra.It 504082bfe67SJohn Polstra.Fn rad_create_request 505082bfe67SJohn Polstra.It 5063fc0b61cSAlexander Motin.Fn rad_create_response 5073fc0b61cSAlexander Motin.It 508082bfe67SJohn Polstra.Fn rad_get_attr 509082bfe67SJohn Polstra.It 510082bfe67SJohn Polstra.Fn rad_put_addr 511082bfe67SJohn Polstra.It 512082bfe67SJohn Polstra.Fn rad_put_attr 513082bfe67SJohn Polstra.It 514082bfe67SJohn Polstra.Fn rad_put_int 515082bfe67SJohn Polstra.It 516082bfe67SJohn Polstra.Fn rad_put_string 517082bfe67SJohn Polstra.It 518b4b831efSRuslan Ermilov.Fn rad_put_message_authentic 519b4b831efSRuslan Ermilov.It 52048caee2aSBrian Somers.Fn rad_init_send_request 52148caee2aSBrian Somers.It 52248caee2aSBrian Somers.Fn rad_continue_send_request 52348caee2aSBrian Somers.It 524082bfe67SJohn Polstra.Fn rad_send_request 5253fc0b61cSAlexander Motin.It 5263fc0b61cSAlexander Motin.Fn rad_send_response 527082bfe67SJohn Polstra.El 528082bfe67SJohn Polstra.Pp 529082bfe67SJohn PolstraThe following functions return a 530082bfe67SJohn Polstra.No non- Ns Dv NULL 53181b380a8SRuslan Ermilovpointer on success. 53281b380a8SRuslan ErmilovIf they are unable to allocate sufficient 533082bfe67SJohn Polstravirtual memory, they return 534082bfe67SJohn Polstra.Dv NULL , 535082bfe67SJohn Polstrawithout recording an error message. 536082bfe67SJohn Polstra.Pp 537082bfe67SJohn Polstra.Bl -item -offset indent -compact 538082bfe67SJohn Polstra.It 5390981dfefSJohn Polstra.Fn rad_acct_open 540082bfe67SJohn Polstra.It 5410981dfefSJohn Polstra.Fn rad_auth_open 5420981dfefSJohn Polstra.It 5433fc0b61cSAlexander Motin.Fn rad_server_open 5443fc0b61cSAlexander Motin.It 5450981dfefSJohn Polstra.Fn rad_cvt_string 546082bfe67SJohn Polstra.El 547b4b831efSRuslan Ermilov.Pp 548b4b831efSRuslan ErmilovThe following functions return a 549b4b831efSRuslan Ermilov.No non- Ns Dv NULL 550b4b831efSRuslan Ermilovpointer on success. 551b4b831efSRuslan ErmilovIf they fail, they return 552b4b831efSRuslan Ermilov.Dv NULL , 553b4b831efSRuslan Ermilovwith recording an error message. 554b4b831efSRuslan Ermilov.Pp 555b4b831efSRuslan Ermilov.Bl -item -offset indent -compact 556b4b831efSRuslan Ermilov.It 557b4b831efSRuslan Ermilov.Fn rad_demangle 558b4b831efSRuslan Ermilov.It 559b4b831efSRuslan Ermilov.Fn rad_demangle_mppe_key 560b4b831efSRuslan Ermilov.El 561082bfe67SJohn Polstra.Sh FILES 56281b380a8SRuslan Ermilov.Bl -tag -width indent 56381b380a8SRuslan Ermilov.It Pa /etc/radius.conf 56481b380a8SRuslan Ermilov.El 565082bfe67SJohn Polstra.Sh SEE ALSO 566082bfe67SJohn Polstra.Xr radius.conf 5 567082bfe67SJohn Polstra.Rs 56881b380a8SRuslan Ermilov.%A "C. Rigney, et al" 56942635956SRuslan Ermilov.%T "Remote Authentication Dial In User Service (RADIUS)" 570b4b831efSRuslan Ermilov.%O "RFC 2865" 571082bfe67SJohn Polstra.Re 5720981dfefSJohn Polstra.Rs 57381b380a8SRuslan Ermilov.%A "C. Rigney" 57481b380a8SRuslan Ermilov.%T "RADIUS Accounting" 575b4b831efSRuslan Ermilov.%O "RFC 2866" 576b4b831efSRuslan Ermilov.Re 577b4b831efSRuslan Ermilov.Rs 578b4b831efSRuslan Ermilov.%A G. Zorn 579b4b831efSRuslan Ermilov.%T "Microsoft Vendor-specific RADIUS attributes" 580b4b831efSRuslan Ermilov.%O RFC 2548 581b4b831efSRuslan Ermilov.Re 582b4b831efSRuslan Ermilov.Rs 583b4b831efSRuslan Ermilov.%A C. Rigney, et al 584b4b831efSRuslan Ermilov.%T "RADIUS extensions" 585b4b831efSRuslan Ermilov.%O RFC 2869 5860981dfefSJohn Polstra.Re 587082bfe67SJohn Polstra.Sh AUTHORS 58881b380a8SRuslan Ermilov.An -nosplit 5890981dfefSJohn PolstraThis software was originally written by 590082bfe67SJohn Polstra.An John Polstra , 591b5c508fbSRuslan Ermilovand donated to the 592b5c508fbSRuslan Ermilov.Fx 593b5c508fbSRuslan Ermilovproject by Juniper Networks, Inc. 59481b380a8SRuslan Ermilov.An Oleg Semyonov 59581b380a8SRuslan Ermilovsubsequently added the ability to perform RADIUS 5960981dfefSJohn Polstraaccounting. 597b4b831efSRuslan ErmilovLater additions and changes by 598b4b831efSRuslan Ermilov.An Michael Bretterklieber . 5993fc0b61cSAlexander MotinServer mode support was added by 6003fc0b61cSAlexander Motin.An Alexander Motin . 601