1082bfe67SJohn Polstra /*- 2082bfe67SJohn Polstra * Copyright 1998 Juniper Networks, Inc. 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 * 26082bfe67SJohn Polstra * $FreeBSD$ 27082bfe67SJohn Polstra */ 28082bfe67SJohn Polstra 29082bfe67SJohn Polstra #ifndef RADLIB_PRIVATE_H 30082bfe67SJohn Polstra #define RADLIB_PRIVATE_H 31082bfe67SJohn Polstra 32082bfe67SJohn Polstra #include <sys/types.h> 33082bfe67SJohn Polstra #include <netinet/in.h> 34082bfe67SJohn Polstra 35082bfe67SJohn Polstra #include "radlib.h" 36b49a88f6SBrian Somers #include "radlib_vs.h" 37082bfe67SJohn Polstra 380981dfefSJohn Polstra /* Handle types */ 390981dfefSJohn Polstra #define RADIUS_AUTH 0 /* RADIUS authentication, default */ 400981dfefSJohn Polstra #define RADIUS_ACCT 1 /* RADIUS accounting */ 413fc0b61cSAlexander Motin #define RADIUS_SERVER 2 /* RADIUS server */ 420981dfefSJohn Polstra 43082bfe67SJohn Polstra /* Defaults */ 44082bfe67SJohn Polstra #define MAXTRIES 3 45082bfe67SJohn Polstra #define PATH_RADIUS_CONF "/etc/radius.conf" 46082bfe67SJohn Polstra #define RADIUS_PORT 1812 470981dfefSJohn Polstra #define RADACCT_PORT 1813 48082bfe67SJohn Polstra #define TIMEOUT 3 /* In seconds */ 49082bfe67SJohn Polstra 50082bfe67SJohn Polstra /* Limits */ 51082bfe67SJohn Polstra #define ERRSIZE 128 /* Maximum error message length */ 52082bfe67SJohn Polstra #define MAXCONFLINE 1024 /* Maximum config file line length */ 53082bfe67SJohn Polstra #define MAXSERVERS 10 /* Maximum number of servers to try */ 54082bfe67SJohn Polstra #define MSGSIZE 4096 /* Maximum RADIUS message */ 55082bfe67SJohn Polstra #define PASSSIZE 128 /* Maximum significant password chars */ 56082bfe67SJohn Polstra 57082bfe67SJohn Polstra /* Positions of fields in RADIUS messages */ 58082bfe67SJohn Polstra #define POS_CODE 0 /* Message code */ 59082bfe67SJohn Polstra #define POS_IDENT 1 /* Identifier */ 60082bfe67SJohn Polstra #define POS_LENGTH 2 /* Message length */ 61082bfe67SJohn Polstra #define POS_AUTH 4 /* Authenticator */ 62082bfe67SJohn Polstra #define LEN_AUTH 16 /* Length of authenticator */ 63082bfe67SJohn Polstra #define POS_ATTRS 20 /* Start of attributes */ 64082bfe67SJohn Polstra 65082bfe67SJohn Polstra struct rad_server { 66082bfe67SJohn Polstra struct sockaddr_in addr; /* Address of server */ 67082bfe67SJohn Polstra char *secret; /* Shared secret */ 68082bfe67SJohn Polstra int timeout; /* Timeout in seconds */ 69082bfe67SJohn Polstra int max_tries; /* Number of tries before giving up */ 70082bfe67SJohn Polstra int num_tries; /* Number of tries so far */ 71082bfe67SJohn Polstra }; 72082bfe67SJohn Polstra 73082bfe67SJohn Polstra struct rad_handle { 74082bfe67SJohn Polstra int fd; /* Socket file descriptor */ 75082bfe67SJohn Polstra struct rad_server servers[MAXSERVERS]; /* Servers to contact */ 76082bfe67SJohn Polstra int num_servers; /* Number of valid server entries */ 77082bfe67SJohn Polstra int ident; /* Current identifier value */ 78082bfe67SJohn Polstra char errmsg[ERRSIZE]; /* Most recent error message */ 793fc0b61cSAlexander Motin unsigned char out[MSGSIZE]; /* Request to send */ 803fc0b61cSAlexander Motin char out_created; /* rad_create_request() called? */ 813fc0b61cSAlexander Motin int out_len; /* Length of request */ 82082bfe67SJohn Polstra char pass[PASSSIZE]; /* Cleartext password */ 83082bfe67SJohn Polstra int pass_len; /* Length of cleartext password */ 84082bfe67SJohn Polstra int pass_pos; /* Position of scrambled password */ 8548caee2aSBrian Somers char chap_pass; /* Have we got a CHAP_PASSWORD ? */ 86b4b831efSRuslan Ermilov int authentic_pos; /* Position of message authenticator */ 87b4b831efSRuslan Ermilov char eap_msg; /* Are we an EAP Proxy? */ 883fc0b61cSAlexander Motin unsigned char in[MSGSIZE]; /* Response received */ 893fc0b61cSAlexander Motin int in_len; /* Length of response */ 903fc0b61cSAlexander Motin int in_pos; /* Current position scanning attrs */ 9148caee2aSBrian Somers int total_tries; /* How many requests we'll send */ 9248caee2aSBrian Somers int try; /* How many requests we've sent */ 9348caee2aSBrian Somers int srv; /* Server number we did last */ 940981dfefSJohn Polstra int type; /* Handle type */ 95082bfe67SJohn Polstra }; 96082bfe67SJohn Polstra 97b49a88f6SBrian Somers struct vendor_attribute { 98b49a88f6SBrian Somers u_int32_t vendor_value; 99b49a88f6SBrian Somers u_char attrib_type; 100b49a88f6SBrian Somers u_char attrib_len; 101b49a88f6SBrian Somers u_char attrib_data[1]; 102b49a88f6SBrian Somers }; 103b49a88f6SBrian Somers 104082bfe67SJohn Polstra #endif 105