1/*
2 * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23/*-
24 * Copyright 1998 Juniper Networks, Inc.
25 * All rights reserved.
26 *
27 * Redistribution and use in source and binary forms, with or without
28 * modification, are permitted provided that the following conditions
29 * are met:
30 * 1. Redistributions of source code must retain the above copyright
31 *    notice, this list of conditions and the following disclaimer.
32 * 2. Redistributions in binary form must reproduce the above copyright
33 *    notice, this list of conditions and the following disclaimer in the
34 *    documentation and/or other materials provided with the distribution.
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
37 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
39 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
40 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
41 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
42 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
44 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
45 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46 * SUCH DAMAGE.
47 *
48 */
49
50#ifndef RADLIB_PRIVATE_H
51#define RADLIB_PRIVATE_H
52
53#include <sys/types.h>
54#include <netinet/in.h>
55
56#include "radlib.h"
57#include "radlib_vs.h"
58
59/* Handle types */
60#define RADIUS_AUTH		0   /* RADIUS authentication, default */
61#define RADIUS_ACCT		1   /* RADIUS accounting */
62
63/* Defaults */
64#define MAXTRIES		3
65#define PATH_RADIUS_CONF	"/etc/radius.conf"
66#define RADIUS_PORT		1812
67#define RADACCT_PORT		1813
68#define TIMEOUT			3	/* In seconds */
69
70/* Limits */
71#define ERRSIZE		128		/* Maximum error message length */
72#define MAXCONFLINE	1024		/* Maximum config file line length */
73#define MAXSERVERS	10		/* Maximum number of servers to try */
74#define MSGSIZE		4096		/* Maximum RADIUS message */
75#define PASSSIZE	128		/* Maximum significant password chars */
76
77/* Positions of fields in RADIUS messages */
78#define POS_CODE	0		/* Message code */
79#define POS_IDENT	1		/* Identifier */
80#define POS_LENGTH	2		/* Message length */
81#define POS_AUTH	4		/* Authenticator */
82#define LEN_AUTH	16		/* Length of authenticator */
83#define POS_ATTRS	20		/* Start of attributes */
84
85struct rad_server {
86	struct sockaddr_in addr;	/* Address of server */
87	char		*secret;	/* Shared secret */
88	int		 timeout;	/* Timeout in seconds */
89	int		 max_tries;	/* Number of tries before giving up */
90	int		 num_tries;	/* Number of tries so far */
91};
92
93struct rad_handle {
94	int		 fd;		/* Socket file descriptor */
95	struct rad_server servers[MAXSERVERS];	/* Servers to contact */
96	int		 num_servers;	/* Number of valid server entries */
97	int		 ident;		/* Current identifier value */
98	char		 errmsg[ERRSIZE];	/* Most recent error message */
99	unsigned char	 request[MSGSIZE];	/* Request to send */
100	char	 	 request_created; /* rad_create_request() called? */
101	int		 req_len;	/* Length of request */
102	char		 pass[PASSSIZE];	/* Cleartext password */
103	int		 pass_len;	/* Length of cleartext password */
104	int		 pass_pos;	/* Position of scrambled password */
105	char	 	 chap_pass;	/* Have we got a CHAP_PASSWORD ? */
106	int		 authentic_pos;	/* Position of message authenticator */
107	char		 eap_msg;	/* Are we an EAP Proxy? */
108	unsigned char	 response[MSGSIZE];	/* Response received */
109	int		 resp_len;	/* Length of response */
110	int		 resp_pos;	/* Current position scanning attrs */
111	int		 total_tries;	/* How many requests we'll send */
112	int		 try;		/* How many requests we've sent */
113	int		 srv;		/* Server number we did last */
114	int		 type;		/* Handle type */
115};
116
117struct vendor_attribute {
118	u_int32_t vendor_value;
119	u_char attrib_type;
120	u_char attrib_len;
121	u_char attrib_data[1];
122};
123
124#endif
125