xref: /freebsd/lib/libradius/radlib_private.h (revision b3e7694832e81d7a904a10f525f8797b753bf0d3)
1082bfe67SJohn Polstra /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
35e53a4f9SPedro F. Giffuni  *
4082bfe67SJohn Polstra  * Copyright 1998 Juniper Networks, Inc.
5082bfe67SJohn Polstra  * All rights reserved.
6082bfe67SJohn Polstra  *
7082bfe67SJohn Polstra  * Redistribution and use in source and binary forms, with or without
8082bfe67SJohn Polstra  * modification, are permitted provided that the following conditions
9082bfe67SJohn Polstra  * are met:
10082bfe67SJohn Polstra  * 1. Redistributions of source code must retain the above copyright
11082bfe67SJohn Polstra  *    notice, this list of conditions and the following disclaimer.
12082bfe67SJohn Polstra  * 2. Redistributions in binary form must reproduce the above copyright
13082bfe67SJohn Polstra  *    notice, this list of conditions and the following disclaimer in the
14082bfe67SJohn Polstra  *    documentation and/or other materials provided with the distribution.
15082bfe67SJohn Polstra  *
16082bfe67SJohn Polstra  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17082bfe67SJohn Polstra  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18082bfe67SJohn Polstra  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19082bfe67SJohn Polstra  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20082bfe67SJohn Polstra  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21082bfe67SJohn Polstra  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22082bfe67SJohn Polstra  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23082bfe67SJohn Polstra  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24082bfe67SJohn Polstra  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25082bfe67SJohn Polstra  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26082bfe67SJohn Polstra  * SUCH DAMAGE.
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 */
49bf5a1b65SSergey Matveychuk #define	DEAD_TIME		0
50082bfe67SJohn Polstra 
51082bfe67SJohn Polstra /* Limits */
52082bfe67SJohn Polstra #define ERRSIZE		128		/* Maximum error message length */
53082bfe67SJohn Polstra #define MAXCONFLINE	1024		/* Maximum config file line length */
54082bfe67SJohn Polstra #define MAXSERVERS	10		/* Maximum number of servers to try */
55082bfe67SJohn Polstra #define MSGSIZE		4096		/* Maximum RADIUS message */
56082bfe67SJohn Polstra #define PASSSIZE	128		/* Maximum significant password chars */
57082bfe67SJohn Polstra 
58082bfe67SJohn Polstra /* Positions of fields in RADIUS messages */
59082bfe67SJohn Polstra #define POS_CODE	0		/* Message code */
60082bfe67SJohn Polstra #define POS_IDENT	1		/* Identifier */
61082bfe67SJohn Polstra #define POS_LENGTH	2		/* Message length */
62082bfe67SJohn Polstra #define POS_AUTH	4		/* Authenticator */
63082bfe67SJohn Polstra #define LEN_AUTH	16		/* Length of authenticator */
64082bfe67SJohn Polstra #define POS_ATTRS	20		/* Start of attributes */
65082bfe67SJohn Polstra 
66082bfe67SJohn Polstra struct rad_server {
67082bfe67SJohn Polstra 	struct sockaddr_in addr;	/* Address of server */
68082bfe67SJohn Polstra 	char		*secret;	/* Shared secret */
69082bfe67SJohn Polstra 	int		 timeout;	/* Timeout in seconds */
70082bfe67SJohn Polstra 	int		 max_tries;	/* Number of tries before giving up */
71082bfe67SJohn Polstra 	int		 num_tries;	/* Number of tries so far */
72bf5a1b65SSergey Matveychuk 	int		 is_dead;	/* The server did not answer last time */
73bf5a1b65SSergey Matveychuk 	time_t		 dead_time;	/* Don't try this server for the time period if it is dead */
74bf5a1b65SSergey Matveychuk 	time_t		 next_probe;	/* Time of a next probe after failure */
75bf5a1b65SSergey Matveychuk 	in_addr_t	 bindto;	/* Bind to address */
76082bfe67SJohn Polstra };
77082bfe67SJohn Polstra 
78082bfe67SJohn Polstra struct rad_handle {
79082bfe67SJohn Polstra 	int		 fd;		/* Socket file descriptor */
80082bfe67SJohn Polstra 	struct rad_server servers[MAXSERVERS];	/* Servers to contact */
81082bfe67SJohn Polstra 	int		 num_servers;	/* Number of valid server entries */
82082bfe67SJohn Polstra 	int		 ident;		/* Current identifier value */
83082bfe67SJohn Polstra 	char		 errmsg[ERRSIZE];	/* Most recent error message */
843fc0b61cSAlexander Motin 	unsigned char	 out[MSGSIZE];	/* Request to send */
853fc0b61cSAlexander Motin 	char		 out_created;	/* rad_create_request() called? */
863fc0b61cSAlexander Motin 	int		 out_len;	/* Length of request */
87082bfe67SJohn Polstra 	char		 pass[PASSSIZE];	/* Cleartext password */
88082bfe67SJohn Polstra 	int		 pass_len;	/* Length of cleartext password */
89082bfe67SJohn Polstra 	int		 pass_pos;	/* Position of scrambled password */
9048caee2aSBrian Somers 	char		 chap_pass;	/* Have we got a CHAP_PASSWORD ? */
91b4b831efSRuslan Ermilov 	int		 authentic_pos;	/* Position of message authenticator */
92b4b831efSRuslan Ermilov 	char		 eap_msg;	/* Are we an EAP Proxy? */
933fc0b61cSAlexander Motin 	unsigned char	 in[MSGSIZE];	/* Response received */
943fc0b61cSAlexander Motin 	int		 in_len;	/* Length of response */
953fc0b61cSAlexander Motin 	int		 in_pos;	/* Current position scanning attrs */
9648caee2aSBrian Somers 	int		 srv;		/* Server number we did last */
970981dfefSJohn Polstra 	int		 type;		/* Handle type */
98bf5a1b65SSergey Matveychuk 	in_addr_t	 bindto;	/* Current bind address */
99082bfe67SJohn Polstra };
100082bfe67SJohn Polstra 
101b49a88f6SBrian Somers struct vendor_attribute {
102b49a88f6SBrian Somers 	u_int32_t vendor_value;
103b49a88f6SBrian Somers 	u_char attrib_type;
104b49a88f6SBrian Somers 	u_char attrib_len;
105b49a88f6SBrian Somers 	u_char attrib_data[1];
106b49a88f6SBrian Somers };
107b49a88f6SBrian Somers 
108082bfe67SJohn Polstra #endif
109