2 \brief Public interface for libradsec. */
4 /* See the file COPYING for licensing information. */
10 #define RS_FREERADIUS_DICT SYSCONFDIR "/raddb/dictionary"
11 #else /* !SYSCONFDIR */
12 #define RS_FREERADIUS_DICT "/usr/local/raddb/dictionary"
13 #endif /* !SYSCONFDIR */
21 RSE_CONN_TYPE_MISMATCH = 5,
22 RSE_FR = 6, /* FreeRADIUS error. */
25 RSE_EVENT = 9, /* libevent error. */
30 RSE_SSLERR = 14, /* OpenSSL error. */
32 RSE_TIMEOUT_CONN = 16, /* Connection timeout. */
33 RSE_INVAL = 17, /* Invalid argument. */
34 RSE_TIMEOUT_IO = 18, /* I/O timeout. */
35 RSE_TIMEOUT = 19, /* High level timeout. */
37 RSE_CRED = 21, /* Credentials. */
38 RSE_CERT = 22, /* Cert validation. */
42 RS_CONN_TYPE_NONE = 0,
48 typedef unsigned int rs_conn_type_t;
51 #if defined (__cplusplus)
56 struct rs_context; /* radsec-impl.h */
57 struct rs_connection; /* radsec-impl.h */
58 struct rs_packet; /* radsec-impl.h */
59 struct rs_conn; /* radsec-impl.h */
60 struct rs_error; /* radsec-impl.h */
61 struct rs_peer; /* radsec-impl.h */
62 struct radius_packet; /* <freeradius/libradius.h> */
63 struct event_base; /* <event2/event-internal.h> */
65 typedef void *(*rs_calloc_fp) (size_t nmemb, size_t size);
66 typedef void *(*rs_malloc_fp) (size_t size);
67 typedef void (*rs_free_fp) (void *ptr);
68 typedef void *(*rs_realloc_fp) (void *ptr, size_t size);
69 struct rs_alloc_scheme {
73 rs_realloc_fp realloc;
76 typedef void (*rs_conn_connected_cb) (void *user_data /* FIXME: peer? */ );
77 typedef void (*rs_conn_disconnected_cb) (void *user_data /* FIXME: reason? */ );
78 typedef void (*rs_conn_packet_received_cb) (struct rs_packet *packet,
80 typedef void (*rs_conn_packet_sent_cb) (void *user_data);
81 struct rs_conn_callbacks {
82 /** Callback invoked when the connection has been established. */
83 rs_conn_connected_cb connected_cb;
84 /** Callback invoked when the connection has been torn down. */
85 rs_conn_disconnected_cb disconnected_cb;
86 /** Callback invoked when a packet was received. */
87 rs_conn_packet_received_cb received_cb;
88 /** Callback invoked when a packet was successfully sent. */
89 rs_conn_packet_sent_cb sent_cb;
93 /* Function prototypes. */
98 /** Create a context. Freed by calling \a rs_context_destroy. Note
99 that the context must not be freed before all other libradsec
100 objects have been freed.
102 \a ctx Address of pointer to a struct rs_context. This is the
103 output of this function.
105 \return RSE_OK (0) on success or RSE_NOMEM on out of memory. */
106 int rs_context_create(struct rs_context **ctx);
108 /** Free a context. Note that the context must not be freed before
109 all other libradsec objects have been freed. */
110 void rs_context_destroy(struct rs_context *ctx);
112 /** Initialize FreeRADIUS dictionary needed for creating packets.
116 \a dict Optional string with full path to FreeRADIUS dictionary.
117 If \a dict is NULL the path to the dictionary file is taken from
118 the "dictionary" configuration directive. Note that the
119 configuration file must be read prior to using this option (see \a
120 rs_context_read_config).
122 \return RSE_OK (0) on success, RSE_NOMEM on memory allocation
123 error and RSE_FR on FreeRADIUS error. */
124 int rs_context_init_freeradius_dict(struct rs_context *ctx, const char *dict);
126 /** Set allocation scheme to use. \a scheme is the allocation scheme
127 to use, see \a rs_alloc_scheme. \return On success, RSE_OK (0) is
128 returned. On error, !0 is returned and a struct \a rs_error is
129 pushed on the error stack for the context. The error can be
130 accessed using \a rs_err_ctx_pop. */
131 int rs_context_set_alloc_scheme(struct rs_context *ctx,
132 struct rs_alloc_scheme *scheme);
134 /** Read configuration file. \a config_file is the path of the
135 configuration file to read. \return On success, RSE_OK (0) is
136 returned. On error, !0 is returned and a struct \a rs_error is
137 pushed on the error stack for the context. The error can be
138 accessed using \a rs_err_ctx_pop. */
139 int rs_context_read_config(struct rs_context *ctx, const char *config_file);
144 /** Create a connection. \a conn is the address of a pointer to an \a
145 rs_connection, the output. Free the connection using \a
146 rs_conn_destroy. Note that a connection must not be freed before
147 all packets associated with the connection have been freed. A
148 packet is associated with a connection when it's created (\a
149 rs_packet_create) or received (\a rs_conn_receive_packet).
151 If \a config is not NULL it should be the name of a configuration
152 found in the config file read in using \a rs_context_read_config.
153 \return On success, RSE_OK (0) is returned. On error, !0 is
154 returned and a struct \a rs_error is pushed on the error stack for
155 the context. The error can be accessed using \a
157 int rs_conn_create(struct rs_context *ctx,
158 struct rs_connection **conn,
161 /** Not implemented. */
162 int rs_conn_add_listener(struct rs_connection *conn,
164 const char *hostname,
166 /** Disconnect connection \a conn. \return RSE_OK (0) on success, !0
167 * on error. On error, errno is set appropriately. */
168 int rs_conn_disconnect (struct rs_connection *conn);
170 /** Disconnect and free memory allocated for connection \a conn. Note
171 that a connection must not be freed before all packets associated
172 with the connection have been freed. A packet is associated with
173 a connection when it's created (\a rs_packet_create) or received
174 (\a rs_conn_receive_packet). \return RSE_OK (0) on success, !0 *
175 on error. On error, errno is set appropriately. */
176 int rs_conn_destroy(struct rs_connection *conn);
178 /** Set connection type for \a conn. */
179 void rs_conn_set_type(struct rs_connection *conn, rs_conn_type_t type);
181 /** Not implemented. */
182 int rs_conn_set_eventbase(struct rs_connection *conn, struct event_base *eb);
184 /** Register callbacks \a cb for connection \a conn. */
185 void rs_conn_set_callbacks(struct rs_connection *conn,
186 struct rs_conn_callbacks *cb);
188 /** Remove callbacks for connection \a conn. */
189 void rs_conn_del_callbacks(struct rs_connection *conn);
191 /** Return callbacks registered for connection \a conn. \return
192 Installed callbacks are returned. */
193 struct rs_conn_callbacks *rs_conn_get_callbacks(struct rs_connection *conn);
195 /** Not implemented. */
196 int rs_conn_select_peer(struct rs_connection *conn, const char *name);
198 /** Not implemented. */
199 int rs_conn_get_current_peer(struct rs_connection *conn,
203 /** Special function used in blocking mode, i.e. with no callbacks
204 registered. For any other use of libradsec, a \a received_cb
205 callback should be registered using \a rs_conn_set_callbacks.
207 If \a req_msg is not NULL, a successfully received RADIUS message
208 is verified against it. If \a pkt_out is not NULL it will upon
209 return contain a pointer to an \a rs_packet containing the new
212 \return On error or if the connect (TCP only) or read times out,
213 \a pkt_out will not be changed and one or more errors are pushed
214 on \a conn (available through \a rs_err_conn_pop). */
215 int rs_conn_receive_packet(struct rs_connection *conn,
216 struct rs_packet *request,
217 struct rs_packet **pkt_out);
219 /** Get the file descriptor associated with connection \a conn.
220 * \return File descriptor. */
221 int rs_conn_fd(struct rs_connection *conn);
223 /** Set the timeout value for connection \a conn. */
224 void rs_conn_set_timeout(struct rs_connection *conn, struct timeval *tv);
226 /* Peer -- client and server. */
227 int rs_peer_create(struct rs_connection *conn, struct rs_peer **peer_out);
228 int rs_peer_set_address(struct rs_peer *peer,
229 const char *hostname,
230 const char *service);
231 int rs_peer_set_secret(struct rs_peer *peer, const char *secret);
232 void rs_peer_set_timeout(struct rs_peer *peer, int timeout);
233 void rs_peer_set_retries(struct rs_peer *peer, int retries);
238 /** Create a packet associated with connection \a conn. */
239 int rs_packet_create(struct rs_connection *conn, struct rs_packet **pkt_out);
241 /** Free all memory allocated for packet \a pkt. */
242 void rs_packet_destroy(struct rs_packet *pkt);
244 /** Send packet \a pkt on the connection associated with \a pkt. \a
245 user_data is sent to the \a rs_conn_packet_received_cb callback
246 registered with the connection. If no callback is registered with
247 the connection, the event loop is run by \a rs_packet_send and it
248 blocks until the packet has been succesfully sent.
250 \return On success, RSE_OK (0) is returned. On error, !0 is
251 returned and a struct \a rs_error is pushed on the error stack for
252 the connection. The error can be accessed using \a
254 int rs_packet_send(struct rs_packet *pkt, void *user_data);
256 /** Return the FreeRADIUS packet associated with packet \a pkt. */
257 struct radius_packet *rs_packet_frpkt(struct rs_packet *pkt);
259 /** Create a RADIUS authentication request packet associated with
260 connection \a conn. Optionally, User-Name and User-Password
261 attributes are added to the packet using the data in \a user_name
263 int rs_packet_create_authn_request(struct rs_connection *conn,
264 struct rs_packet **pkt,
265 const char *user_name,
266 const char *user_pw);
271 /** Find the realm named \a name in the configuration file previoiusly
272 read in using \a rs_context_read_config. */
273 struct rs_realm *rs_conf_find_realm(struct rs_context *ctx, const char *name);
278 /** Create a struct \a rs_error and push it on a FIFO associated with
279 context \a ctx. Note: The depth of the error stack is one (1) at
280 the moment. This will change in a future release. */
281 int rs_err_ctx_push(struct rs_context *ctx, int code, const char *fmt, ...);
282 int rs_err_ctx_push_fl(struct rs_context *ctx,
288 /** Pop the first error from the error FIFO associated with context \a
289 ctx or NULL if there are no errors in the FIFO. */
290 struct rs_error *rs_err_ctx_pop(struct rs_context *ctx);
292 /** Create a struct \a rs_error and push it on a FIFO associated with
293 connection \a conn. Note: The depth of the error stack is one (1)
294 at the moment. This will change in a future release. */
295 int rs_err_conn_push(struct rs_connection *conn,
299 int rs_err_conn_push_fl(struct rs_connection *conn,
305 /** Pop the first error from the error FIFO associated with connection
306 \a conn or NULL if there are no errors in the FIFO. */
307 struct rs_error *rs_err_conn_pop(struct rs_connection *conn);
309 int rs_err_conn_peek_code (struct rs_connection *conn);
310 void rs_err_free(struct rs_error *err);
311 char *rs_err_msg(struct rs_error *err);
312 int rs_err_code(struct rs_error *err, int dofree_flag);
314 #if defined (__cplusplus)
318 /* Local Variables: */
319 /* c-file-style: "stroustrup" */