1 /* $NetBSD: radlib_private.h,v 1.4 2009/01/19 07:21:59 lukem Exp $ */
2 
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: /repoman/r/ncvs/src/lib/libradius/radlib_private.h,v 1.6 2004/04/27 15:00:29 ru Exp $
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 
44 /* Defaults */
45 #define MAXTRIES              3
46 #define PATH_RADIUS_CONF      "/etc/radius.conf"
47 #define RADIUS_PORT           1812
48 #define RADACCT_PORT                    1813
49 #define TIMEOUT                         3         /* In seconds */
50 
51 /* Limits */
52 #define ERRSIZE               128                 /* Maximum error message length */
53 #define MAXCONFLINE 1024                /* Maximum config file line length */
54 #define MAXSERVERS  10                  /* Maximum number of servers to try */
55 #define MSGSIZE               4096                /* Maximum RADIUS message */
56 #define PASSSIZE    128                 /* Maximum significant password chars */
57 
58 /* Positions of fields in RADIUS messages */
59 #define POS_CODE    0                   /* Message code */
60 #define POS_IDENT   1                   /* Identifier */
61 #define POS_LENGTH  2                   /* Message length */
62 #define POS_AUTH    4                   /* Authenticator */
63 #define LEN_AUTH    16                  /* Length of authenticator */
64 #define POS_ATTRS   20                  /* Start of attributes */
65 
66 struct rad_server {
67           struct sockaddr_in addr;      /* Address of server */
68           char                *secret;  /* Shared secret */
69           int                  timeout; /* Timeout in seconds */
70           int                  max_tries;         /* Number of tries before giving up */
71           int                  num_tries;         /* Number of tries so far */
72 };
73 
74 struct rad_handle {
75           int                  fd;                /* Socket file descriptor */
76           struct rad_server servers[MAXSERVERS];  /* Servers to contact */
77           size_t               num_servers;       /* Number of valid server entries */
78           int                  ident;             /* Current identifier value */
79           char                 errmsg[ERRSIZE];   /* Most recent error message */
80           unsigned char        request[MSGSIZE];  /* Request to send */
81           char                 request_created; /* rad_create_request() called? */
82           size_t               req_len; /* Length of request */
83           char                 pass[PASSSIZE];    /* Cleartext password */
84           size_t               pass_len;          /* Length of cleartext password */
85           size_t               pass_pos;          /* Position of scrambled password */
86           char                 chap_pass;         /* Have we got a CHAP_PASSWORD ? */
87           size_t               authentic_pos;     /* Position of message authenticator */
88           char                 eap_msg; /* Are we an EAP Proxy? */
89           unsigned char        response[MSGSIZE]; /* Response received */
90           size_t               resp_len;          /* Length of response */
91           size_t               resp_pos;          /* Current position scanning attrs */
92           size_t               total_tries;       /* How many requests we'll send */
93           size_t               try;               /* How many requests we've sent */
94           size_t               srv;               /* Server number we did last */
95           int                  type;              /* Handle type */
96 };
97 
98 struct vendor_attribute {
99           u_int32_t vendor_value;
100           u_char attrib_type;
101           u_char attrib_len;
102           u_char attrib_data[1];
103 };
104 
105 #endif
106