summaryrefslogtreecommitdiff
path: root/lib/include/radsec/radsec-impl.h
blob: 963c82132fb80f5152f733af04b6127231cf5633 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/** @file libradsec-impl.h
    @brief Libraray internal header file for libradsec.  */

/* See the file COPYING for licensing information.  */

#include <freeradius/libradius.h>
#include <event2/util.h>
#include <confuse.h>
#if defined(RS_ENABLE_TLS)
#include <openssl/ssl.h>
#endif

/* Constants.  */
#define RS_HEADER_LEN 4

/* Data types.  */
enum rs_cred_type {
    RS_CRED_NONE = 0,
    RS_CRED_TLS_PSK_RSA,	/* RFC 4279.  */
};
typedef unsigned int rs_cred_type_t;

#if defined (__cplusplus)
extern "C" {
#endif

struct rs_credentials {
    enum rs_cred_type type;
    char *identity;
    char *secret;
};

struct rs_error {
    int code;
    char *msg;
    char buf[1024];
};

struct rs_peer {		/* Config object for a connection.  */
    struct rs_connection *conn;
    struct rs_realm *realm;
    struct evutil_addrinfo *addr;
    char *secret;
    struct rs_peer *next;
};

struct rs_realm {	      /* Config object for a RADIUS realm.  */
    char *name;
    enum rs_conn_type type;
    int timeout;
    int retries;
    char *cacertfile;
    char *cacertpath;
    char *certfile;
    char *certkeyfile;
    struct rs_peer *peers;
    struct rs_realm *next;
};

struct rs_context {
    struct rs_realm *realms;
    struct rs_alloc_scheme alloc_scheme;
    struct rs_error *err;
    fr_randctx fr_randctx;
    cfg_t *cfg;
};

struct rs_connection {
    struct rs_context *ctx;
    struct rs_realm *realm;	/* Owned by ctx.  */
    struct event_base *evb;	/* Event base.  */
    struct bufferevent *bev;	/* Buffer event.  */
    struct event *tev;		/* Timeout event.  */
    struct rs_credentials transport_credentials;
    struct rs_conn_callbacks callbacks;
    void *user_data;
    struct rs_peer *peers;
    struct rs_peer *active_peer;
    struct rs_error *err;
    char is_connecting;		/* FIXME: replace with a single state member */
    char is_connected;		/* FIXME: replace with a single state member */
    int fd;			/* Socket.  */
    int tryagain;
    int nextid;
    int user_dispatch_flag : 1;	/* User does the dispatching.  */
#if defined(RS_ENABLE_TLS)
    SSL_CTX *tls_ctx;
    SSL *tls_ssl;
#endif
};

struct rs_packet {
    struct rs_connection *conn;
    char hdr_read_flag;
    uint8_t hdr[4];
    RADIUS_PACKET *rpkt;
    struct rs_packet *original;
    char valid_flag;
    char written_flag;
};

struct rs_attr {
    struct rs_packet *pkt;
    VALUE_PAIR *vp;
};

/* Nonpublic functions.  */
struct rs_error *_rs_resolv(struct evutil_addrinfo **addr,
			    rs_conn_type_t type, const char *hostname,
			    const char *service);
struct rs_peer *_rs_peer_create(struct rs_context *ctx,
				struct rs_peer **rootp);
struct rs_error *_rs_err_create(unsigned int code, const char *file,
				int line, const char *fmt, ...);
int _rs_err_conn_push_err(struct rs_connection *conn,
			  struct rs_error *err);


#if defined (__cplusplus)
}
#endif

/* Convenience macros.  */
#define rs_calloc(h, nmemb, size) \
    (h->alloc_scheme.calloc ? h->alloc_scheme.calloc : calloc)(nmemb, size)
#define rs_malloc(h, size) \
    (h->alloc_scheme.malloc ? h->alloc_scheme.malloc : malloc)(size)
#define rs_free(h, ptr) \
    (h->alloc_scheme.free ? h->alloc_scheme.free : free)(ptr)
#define rs_realloc(h, realloc, ptr, size) \
    (h->alloc_scheme.realloc ? h->alloc_scheme.realloc : realloc)(ptr, size)
#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

/* Local Variables: */
/* c-file-style: "stroustrup" */
/* End: */