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. */
41 RS_CONN_TYPE_NONE = 0,
47 typedef unsigned int rs_conn_type_t;
50 #if defined (__cplusplus)
55 struct rs_context; /* radsec-impl.h */
56 struct rs_connection; /* radsec-impl.h */
57 struct rs_packet; /* radsec-impl.h */
58 struct rs_conn; /* radsec-impl.h */
59 struct rs_error; /* radsec-impl.h */
60 struct rs_peer; /* radsec-impl.h */
61 struct radius_packet; /* <freeradius/libradius.h> */
62 struct event_base; /* <event2/event-internal.h> */
64 typedef void *(*rs_calloc_fp) (size_t nmemb, size_t size);
65 typedef void *(*rs_malloc_fp) (size_t size);
66 typedef void (*rs_free_fp) (void *ptr);
67 typedef void *(*rs_realloc_fp) (void *ptr, size_t size);
68 struct rs_alloc_scheme {
72 rs_realloc_fp realloc;
75 typedef void (*rs_conn_connected_cb) (void *user_data /* FIXME: peer? */ );
76 typedef void (*rs_conn_disconnected_cb) (void *user_data /* FIXME: reason? */ );
77 typedef void (*rs_conn_packet_received_cb) (struct rs_packet *packet,
79 typedef void (*rs_conn_packet_sent_cb) (void *user_data);
80 struct rs_conn_callbacks {
81 /** Callback invoked when the connection has been established. */
82 rs_conn_connected_cb connected_cb;
83 /** Callback invoked when the connection has been torn down. */
84 rs_conn_disconnected_cb disconnected_cb;
85 /** Callback invoked when a packet was received. */
86 rs_conn_packet_received_cb received_cb;
87 /** Callback invoked when a packet was successfully sent. */
88 rs_conn_packet_sent_cb sent_cb;
92 /* Function prototypes. */
97 /** Create a context. Freed by calling \a rs_context_destroy. Note
98 that the context must not be freed before all other libradsec
99 objects have been freed.
101 \a ctx Address of pointer to a struct rs_context. This is the
102 output of this function.
104 \return RSE_OK (0) on success or RSE_NOMEM on out of memory. */
105 int rs_context_create(struct rs_context **ctx);
107 /** Free a context. Note that the context must not be freed before
108 all other libradsec objects have been freed. */
109 void rs_context_destroy(struct rs_context *ctx);
111 /** Initialize FreeRADIUS dictionary needed for creating packets.
115 \a dict Optional string with full path to FreeRADIUS dictionary.
116 If \a dict is NULL the path to the dictionary file is taken from
117 the "dictionary" configuration directive. Note that the
118 configuration file must be read prior to using this option (see \a
119 rs_context_read_config).
121 \return RSE_OK (0) on success, RSE_NOMEM on memory allocation
122 error and RSE_FR on FreeRADIUS error. */
123 int rs_context_init_freeradius_dict(struct rs_context *ctx, const char *dict);
125 /** Set allocation scheme to use. \a scheme is the allocation scheme
126 to use, see \a rs_alloc_scheme. \return On success, RSE_OK (0) is
127 returned. On error, !0 is returned and a struct \a rs_error is
128 pushed on the error stack for the context. The error can be
129 accessed using \a rs_err_ctx_pop. */
130 int rs_context_set_alloc_scheme(struct rs_context *ctx,
131 struct rs_alloc_scheme *scheme);
133 /** Read configuration file. \a config_file is the path of the
134 configuration file to read. \return On success, RSE_OK (0) is
135 returned. On error, !0 is returned and a struct \a rs_error is
136 pushed on the error stack for the context. The error can be
137 accessed using \a rs_err_ctx_pop. */
138 int rs_context_read_config(struct rs_context *ctx, const char *config_file);
143 /** Create a connection. \a conn is the address of a pointer to an \a
144 rs_connection, the output. Free the connection using \a
145 rs_conn_destroy. Note that a connection must not be freed before
146 all packets associated with the connection have been freed. A
147 packet is associated with a connection when it's created (\a
148 rs_packet_create) or received (\a rs_conn_receive_packet).
150 If \a config is not NULL it should be the name of a configuration
151 found in the config file read in using \a rs_context_read_config.
152 \return On success, RSE_OK (0) is returned. On error, !0 is
153 returned and a struct \a rs_error is pushed on the error stack for
154 the context. The error can be accessed using \a
156 int rs_conn_create(struct rs_context *ctx,
157 struct rs_connection **conn,
160 /** Not implemented. */
161 int rs_conn_add_listener(struct rs_connection *conn,
163 const char *hostname,
165 /** Disconnect connection \a conn. \return RSE_OK (0) on success, !0
166 * on error. On error, errno is set appropriately. */
167 int rs_conn_disconnect (struct rs_connection *conn);
169 /** Disconnect and free memory allocated for connection \a conn. Note
170 that a connection must not be freed before all packets associated
171 with the connection have been freed. A packet is associated with
172 a connection when it's created (\a rs_packet_create) or received
173 (\a rs_conn_receive_packet). \return RSE_OK (0) on success, !0 *
174 on error. On error, errno is set appropriately. */
175 int rs_conn_destroy(struct rs_connection *conn);
177 /** Set connection type for \a conn. */
178 void rs_conn_set_type(struct rs_connection *conn, rs_conn_type_t type);
180 /** Not implemented. */
181 int rs_conn_set_eventbase(struct rs_connection *conn, struct event_base *eb);
183 /** Register callbacks \a cb for connection \a conn. */
184 void rs_conn_set_callbacks(struct rs_connection *conn,
185 struct rs_conn_callbacks *cb);
187 /** Remove callbacks for connection \a conn. */
188 void rs_conn_del_callbacks(struct rs_connection *conn);
190 /** Return callbacks registered for connection \a conn. \return
191 Installed callbacks are returned. */
192 struct rs_conn_callbacks *rs_conn_get_callbacks(struct rs_connection *conn);
194 /** Not implemented. */
195 int rs_conn_select_peer(struct rs_connection *conn, const char *name);
197 /** Not implemented. */
198 int rs_conn_get_current_peer(struct rs_connection *conn,
202 /** Special function used in blocking mode, i.e. with no callbacks
203 registered. For any other use of libradsec, a \a received_cb
204 callback should be registered using \a rs_conn_set_callbacks.
206 If \a req_msg is not NULL, a successfully received RADIUS message
207 is verified against it. If \a pkt_out is not NULL it will upon
208 return contain a pointer to an \a rs_packet containing the new
211 \return On error or if the connect (TCP only) or read times out,
212 \a pkt_out will not be changed and one or more errors are pushed
213 on \a conn (available through \a rs_err_conn_pop). */
214 int rs_conn_receive_packet(struct rs_connection *conn,
215 struct rs_packet *request,
216 struct rs_packet **pkt_out);
218 /** Get the file descriptor associated with connection \a conn.
219 * \return File descriptor. */
220 int rs_conn_fd(struct rs_connection *conn);
222 /** Set the timeout value for connection \a conn. */
223 void rs_conn_set_timeout(struct rs_connection *conn, struct timeval *tv);
225 /* Peer -- client and server. */
226 int rs_peer_create(struct rs_connection *conn, struct rs_peer **peer_out);
227 int rs_peer_set_address(struct rs_peer *peer,
228 const char *hostname,
229 const char *service);
230 int rs_peer_set_secret(struct rs_peer *peer, const char *secret);
231 void rs_peer_set_timeout(struct rs_peer *peer, int timeout);
232 void rs_peer_set_retries(struct rs_peer *peer, int retries);
237 /** Create a packet associated with connection \a conn. */
238 int rs_packet_create(struct rs_connection *conn, struct rs_packet **pkt_out);
240 /** Free all memory allocated for packet \a pkt. */
241 void rs_packet_destroy(struct rs_packet *pkt);
243 /** Send packet \a pkt on the connection associated with \a pkt. \a
244 user_data is sent to the \a rs_conn_packet_received_cb callback
245 registered with the connection. If no callback is registered with
246 the connection, the event loop is run by \a rs_packet_send and it
247 blocks until the packet has been succesfully sent.
249 \return On success, RSE_OK (0) is returned. On error, !0 is
250 returned and a struct \a rs_error is pushed on the error stack for
251 the connection. The error can be accessed using \a
253 int rs_packet_send(struct rs_packet *pkt, void *user_data);
255 /** Return the FreeRADIUS packet associated with packet \a pkt. */
256 struct radius_packet *rs_packet_frpkt(struct rs_packet *pkt);
258 /** Create a RADIUS authentication request packet associated with
259 connection \a conn. Optionally, User-Name and User-Password
260 attributes are added to the packet using the data in \a user_name
262 int rs_packet_create_authn_request(struct rs_connection *conn,
263 struct rs_packet **pkt,
264 const char *user_name,
265 const char *user_pw);
270 /** Find the realm named \a name in the configuration file previoiusly
271 read in using \a rs_context_read_config. */
272 struct rs_realm *rs_conf_find_realm(struct rs_context *ctx, const char *name);
277 /** Create a struct \a rs_error and push it on a FIFO associated with
278 context \a ctx. Note: The depth of the error stack is one (1) at
279 the moment. This will change in a future release. */
280 int rs_err_ctx_push(struct rs_context *ctx, int code, const char *fmt, ...);
281 int rs_err_ctx_push_fl(struct rs_context *ctx,
287 /** Pop the first error from the error FIFO associated with context \a
288 ctx or NULL if there are no errors in the FIFO. */
289 struct rs_error *rs_err_ctx_pop(struct rs_context *ctx);
291 /** Create a struct \a rs_error and push it on a FIFO associated with
292 connection \a conn. Note: The depth of the error stack is one (1)
293 at the moment. This will change in a future release. */
294 int rs_err_conn_push(struct rs_connection *conn,
298 int rs_err_conn_push_fl(struct rs_connection *conn,
304 /** Pop the first error from the error FIFO associated with connection
305 \a conn or NULL if there are no errors in the FIFO. */
306 struct rs_error *rs_err_conn_pop(struct rs_connection *conn);
308 int rs_err_conn_peek_code (struct rs_connection *conn);
309 void rs_err_free(struct rs_error *err);
310 char *rs_err_msg(struct rs_error *err);
311 int rs_err_code(struct rs_error *err, int dofree_flag);
313 #if defined (__cplusplus)
317 /* Local Variables: */
318 /* c-file-style: "stroustrup" */