summaryrefslogtreecommitdiff
path: root/lib/examples
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordu.net>2011-03-12 12:41:19 +0100
committerLinus Nordberg <linus@nordu.net>2011-03-12 12:41:19 +0100
commit2af84872cb78becf43f7bf4a654418fb7fc532d5 (patch)
tree7c3f33df5316fd67431fc4e70356d7a62da4543f /lib/examples
parent319c2bf1b2886b2e5cd1c5d60a8950493d2d4d75 (diff)
parentefce8db03af505f76c0c579f2439757bd6998dc9 (diff)
Merge branch 'udp' into libradsec.
Diffstat (limited to 'lib/examples')
-rw-r--r--lib/examples/Makefile.am2
-rw-r--r--lib/examples/client-blocking.c72
-rw-r--r--lib/examples/client-udp.conf6
3 files changed, 38 insertions, 42 deletions
diff --git a/lib/examples/Makefile.am b/lib/examples/Makefile.am
index 49d3409..ee0787b 100644
--- a/lib/examples/Makefile.am
+++ b/lib/examples/Makefile.am
@@ -4,5 +4,5 @@ AM_CFLAGS = -Wall -g
bin_PROGRAMS = client
client_SOURCES = client-blocking.c
-client_LDADD = ../libradsec.la
+client_LDADD = ../libradsec.la #-lefence
client_CFLAGS = $(AM_CFLAGS) -DUSE_CONFIG_FILE
diff --git a/lib/examples/client-blocking.c b/lib/examples/client-blocking.c
index 27f87ca..15152b6 100644
--- a/lib/examples/client-blocking.c
+++ b/lib/examples/client-blocking.c
@@ -8,6 +8,7 @@
#include <freeradius/libradius.h>
#include <radsec/radsec.h>
#include <radsec/request.h>
+#include "debug.h" /* For rs_dump_packet(). */
#define SECRET "sikrit"
#define USER_NAME "molgan"
@@ -16,9 +17,11 @@
struct rs_error *
blocking_client (const char *av1, const char *av2, int use_request_object_flag)
{
- struct rs_context *h;
- struct rs_connection *conn;
- struct rs_packet *req, *resp = NULL;
+ struct rs_context *h = NULL;
+ struct rs_connection *conn = NULL;
+ struct rs_request *request = NULL;
+ struct rs_packet *req = NULL, *resp = NULL;
+ struct rs_error *err = NULL;
if (rs_context_create (&h, "/usr/share/freeradius/dictionary"))
return NULL;
@@ -28,67 +31,60 @@ blocking_client (const char *av1, const char *av2, int use_request_object_flag)
struct rs_peer *server;
if (rs_conn_create (h, &conn, NULL))
- return rs_err_conn_pop (conn);
+ goto cleanup;
rs_conn_set_type (conn, RS_CONN_TYPE_UDP);
if (rs_peer_create (conn, &server))
- return rs_err_conn_pop (conn);
+ goto cleanup;
if (rs_peer_set_address (server, av1, av2))
- return rs_err_conn_pop (conn);
+ goto cleanup;
rs_peer_set_timeout (server, 1);
rs_peer_set_retries (server, 3);
if (rs_peer_set_secret (server, SECRET))
- return rs_err_conn_pop (conn);
+ goto cleanup;
}
#else
if (rs_context_read_config (h, av1))
- return rs_err_ctx_pop (h);
+ goto cleanup;
if (rs_conn_create (h, &conn, av2))
- return rs_err_conn_pop (conn);
+ goto cleanup;
#endif /* USE_CONFIG_FILE */
if (use_request_object_flag)
{
- struct rs_request *request;
-
if (rs_request_create_authn (conn, &request, USER_NAME, USER_PW))
- return rs_err_conn_pop (conn);
+ goto cleanup;
if (rs_request_send (request, &resp))
- return rs_err_conn_pop (conn);
- rs_request_destroy (request);
+ goto cleanup;
}
else
{
if (rs_packet_create_authn_request (conn, &req, USER_NAME, USER_PW))
- return rs_err_conn_pop (conn);
-
+ goto cleanup;
if (rs_packet_send (req, NULL))
- {
- rs_packet_destroy (req);
- return rs_err_conn_pop (conn);
- }
+ goto cleanup;
if (rs_conn_receive_packet (conn, req, &resp))
- {
- rs_packet_destroy (req);
- return rs_err_conn_pop (conn);
- }
- rs_packet_destroy (req);
+ goto cleanup;
}
if (resp)
- {
- RADIUS_PACKET *fr_pkt = NULL;
- VALUE_PAIR *fr_vp = NULL;
+ rs_dump_packet (resp);
+ else
+ fprintf (stderr, "%s: no response\n", __func__);
- fr_pkt = rs_packet_frpkt (resp);
- fr_vp = fr_pkt->vps; /* FIXME: Is there an accessor? */
- if (fr_vp)
- vp_printlist(stdout, fr_vp);
- rs_packet_destroy (resp);
- }
+ cleanup:
+ err = rs_err_conn_pop (conn);
+ if (resp)
+ rs_packet_destroy (resp);
+ if (req)
+ rs_packet_destroy (req);
+ if (conn)
+ rs_conn_destroy (conn);
+ if (request)
+ rs_request_destroy (request);
+ if (h)
+ rs_context_destroy (h);
- rs_conn_destroy (conn);
- rs_context_destroy (h);
- return NULL;
+ return err;
}
int
@@ -106,7 +102,7 @@ main (int argc, char *argv[])
err = blocking_client (argv[1], argv[2], use_request_object_flag);
if (err)
{
- fprintf (stderr, "%s\n", rs_err_msg (err, 0));
+ fprintf (stderr, "%s\n", rs_err_msg (err));
return rs_err_code (err, 1);
}
return 0;
diff --git a/lib/examples/client-udp.conf b/lib/examples/client-udp.conf
index a83fb26..8578e8b 100644
--- a/lib/examples/client-udp.conf
+++ b/lib/examples/client-udp.conf
@@ -1,10 +1,10 @@
config blocking-udp {
type = "UDP"
+ timeout = 2
+ retries = 2
server {
- hostname = "localhost"
+ hostname = "127.0.0.1"
service = "1820"
secret = "sikrit"
- timeout = 1 /* optional */
- tries = 10 /* optional */
}
}