xref: /freebsd/lib/libradius/radlib_private.h (revision b4b831ef39a3e2f33a3acd094eac471c502ec259)
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 */
410981dfefSJohn Polstra 
42082bfe67SJohn Polstra /* Defaults */
43082bfe67SJohn Polstra #define MAXTRIES		3
44082bfe67SJohn Polstra #define PATH_RADIUS_CONF	"/etc/radius.conf"
45082bfe67SJohn Polstra #define RADIUS_PORT		1812
460981dfefSJohn Polstra #define RADACCT_PORT		1813
47082bfe67SJohn Polstra #define TIMEOUT			3	/* In seconds */
48082bfe67SJohn Polstra 
49082bfe67SJohn Polstra /* Limits */
50082bfe67SJohn Polstra #define ERRSIZE		128		/* Maximum error message length */
51082bfe67SJohn Polstra #define MAXCONFLINE	1024		/* Maximum config file line length */
52082bfe67SJohn Polstra #define MAXSERVERS	10		/* Maximum number of servers to try */
53082bfe67SJohn Polstra #define MSGSIZE		4096		/* Maximum RADIUS message */
54082bfe67SJohn Polstra #define PASSSIZE	128		/* Maximum significant password chars */
55082bfe67SJohn Polstra 
56082bfe67SJohn Polstra /* Positions of fields in RADIUS messages */
57082bfe67SJohn Polstra #define POS_CODE	0		/* Message code */
58082bfe67SJohn Polstra #define POS_IDENT	1		/* Identifier */
59082bfe67SJohn Polstra #define POS_LENGTH	2		/* Message length */
60082bfe67SJohn Polstra #define POS_AUTH	4		/* Authenticator */
61082bfe67SJohn Polstra #define LEN_AUTH	16		/* Length of authenticator */
62082bfe67SJohn Polstra #define POS_ATTRS	20		/* Start of attributes */
63082bfe67SJohn Polstra 
64082bfe67SJohn Polstra struct rad_server {
65082bfe67SJohn Polstra 	struct sockaddr_in addr;	/* Address of server */
66082bfe67SJohn Polstra 	char		*secret;	/* Shared secret */
67082bfe67SJohn Polstra 	int		 timeout;	/* Timeout in seconds */
68082bfe67SJohn Polstra 	int		 max_tries;	/* Number of tries before giving up */
69082bfe67SJohn Polstra 	int		 num_tries;	/* Number of tries so far */
70082bfe67SJohn Polstra };
71082bfe67SJohn Polstra 
72082bfe67SJohn Polstra struct rad_handle {
73082bfe67SJohn Polstra 	int		 fd;		/* Socket file descriptor */
74082bfe67SJohn Polstra 	struct rad_server servers[MAXSERVERS];	/* Servers to contact */
75082bfe67SJohn Polstra 	int		 num_servers;	/* Number of valid server entries */
76082bfe67SJohn Polstra 	int		 ident;		/* Current identifier value */
77082bfe67SJohn Polstra 	char		 errmsg[ERRSIZE];	/* Most recent error message */
78082bfe67SJohn Polstra 	unsigned char	 request[MSGSIZE];	/* Request to send */
79b4b831efSRuslan Ermilov 	char	 	 request_created; /* rad_create_request() called? */
80082bfe67SJohn Polstra 	int		 req_len;	/* Length of request */
81082bfe67SJohn Polstra 	char		 pass[PASSSIZE];	/* Cleartext password */
82082bfe67SJohn Polstra 	int		 pass_len;	/* Length of cleartext password */
83082bfe67SJohn Polstra 	int		 pass_pos;	/* Position of scrambled password */
8448caee2aSBrian Somers 	char	 	 chap_pass;	/* Have we got a CHAP_PASSWORD ? */
85b4b831efSRuslan Ermilov 	int		 authentic_pos;	/* Position of message authenticator */
86b4b831efSRuslan Ermilov 	char		 eap_msg;	/* Are we an EAP Proxy? */
87082bfe67SJohn Polstra 	unsigned char	 response[MSGSIZE];	/* Response received */
88082bfe67SJohn Polstra 	int		 resp_len;	/* Length of response */
89082bfe67SJohn Polstra 	int		 resp_pos;	/* Current position scanning attrs */
9048caee2aSBrian Somers 	int		 total_tries;	/* How many requests we'll send */
9148caee2aSBrian Somers 	int		 try;		/* How many requests we've sent */
9248caee2aSBrian Somers 	int		 srv;		/* Server number we did last */
930981dfefSJohn Polstra 	int		 type;		/* Handle type */
94082bfe67SJohn Polstra };
95082bfe67SJohn Polstra 
96b49a88f6SBrian Somers struct vendor_attribute {
97b49a88f6SBrian Somers 	u_int32_t vendor_value;
98b49a88f6SBrian Somers 	u_char attrib_type;
99b49a88f6SBrian Somers 	u_char attrib_len;
100b49a88f6SBrian Somers 	u_char attrib_data[1];
101b49a88f6SBrian Somers };
102b49a88f6SBrian Somers 
103082bfe67SJohn Polstra #endif
104