1/*- 2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3 * 4 * Copyright 1998 Juniper Networks, Inc. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 * 28 * $FreeBSD$ 29 */ 30 31#ifndef RADLIB_PRIVATE_H 32#define RADLIB_PRIVATE_H 33 34#include <sys/types.h> 35#include <netinet/in.h> 36 37#include "radlib.h" 38#include "radlib_vs.h" 39 40/* Handle types */ 41#define RADIUS_AUTH 0 /* RADIUS authentication, default */ 42#define RADIUS_ACCT 1 /* RADIUS accounting */ 43#define RADIUS_SERVER 2 /* RADIUS server */ 44 45/* Defaults */ 46#define MAXTRIES 3 47#define PATH_RADIUS_CONF "/etc/radius.conf" 48#define RADIUS_PORT 1812 49#define RADACCT_PORT 1813 50#define TIMEOUT 3 /* In seconds */ 51#define DEAD_TIME 0 52 53/* Limits */ 54#define ERRSIZE 128 /* Maximum error message length */ 55#define MAXCONFLINE 1024 /* Maximum config file line length */ 56#define MAXSERVERS 10 /* Maximum number of servers to try */ 57#define MSGSIZE 4096 /* Maximum RADIUS message */ 58#define PASSSIZE 128 /* Maximum significant password chars */ 59 60/* Positions of fields in RADIUS messages */ 61#define POS_CODE 0 /* Message code */ 62#define POS_IDENT 1 /* Identifier */ 63#define POS_LENGTH 2 /* Message length */ 64#define POS_AUTH 4 /* Authenticator */ 65#define LEN_AUTH 16 /* Length of authenticator */ 66#define POS_ATTRS 20 /* Start of attributes */ 67 68struct rad_server { 69 struct sockaddr_in addr; /* Address of server */ 70 char *secret; /* Shared secret */ 71 int timeout; /* Timeout in seconds */ 72 int max_tries; /* Number of tries before giving up */ 73 int num_tries; /* Number of tries so far */ 74 int is_dead; /* The server did not answer last time */ 75 time_t dead_time; /* Don't try this server for the time period if it is dead */ 76 time_t next_probe; /* Time of a next probe after failure */ 77 in_addr_t bindto; /* Bind to address */ 78}; 79 80struct rad_handle { 81 int fd; /* Socket file descriptor */ 82 struct rad_server servers[MAXSERVERS]; /* Servers to contact */ 83 int num_servers; /* Number of valid server entries */ 84 int ident; /* Current identifier value */ 85 char errmsg[ERRSIZE]; /* Most recent error message */ 86 unsigned char out[MSGSIZE]; /* Request to send */ 87 char out_created; /* rad_create_request() called? */ 88 int out_len; /* Length of request */ 89 char pass[PASSSIZE]; /* Cleartext password */ 90 int pass_len; /* Length of cleartext password */ 91 int pass_pos; /* Position of scrambled password */ 92 char chap_pass; /* Have we got a CHAP_PASSWORD ? */ 93 int authentic_pos; /* Position of message authenticator */ 94 char eap_msg; /* Are we an EAP Proxy? */ 95 unsigned char in[MSGSIZE]; /* Response received */ 96 int in_len; /* Length of response */ 97 int in_pos; /* Current position scanning attrs */ 98 int srv; /* Server number we did last */ 99 int type; /* Handle type */ 100 in_addr_t bindto; /* Current bind address */ 101}; 102 103struct vendor_attribute { 104 u_int32_t vendor_value; 105 u_char attrib_type; 106 u_char attrib_len; 107 u_char attrib_data[1]; 108}; 109 110#endif 111