summaryrefslogtreecommitdiff
path: root/lib/examples
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordberg.se>2013-05-15 14:20:52 +0200
committerLinus Nordberg <linus@nordberg.se>2013-05-15 14:20:52 +0200
commitfba1c7d1a6418221a94965d0431bf7df0a9a74a0 (patch)
tree168d4401100181050306a635adc72d118395b391 /lib/examples
parent58f591ffc9a7d4fea5879210d56db3ca11e98f1e (diff)
WIP commit moving towards working server support.
Diffstat (limited to 'lib/examples')
-rw-r--r--lib/examples/Makefile.am2
-rw-r--r--lib/examples/client-blocking.c4
-rw-r--r--lib/examples/client-dispatch.c7
-rw-r--r--lib/examples/client.conf26
-rw-r--r--lib/examples/server.c120
5 files changed, 133 insertions, 26 deletions
diff --git a/lib/examples/Makefile.am b/lib/examples/Makefile.am
index 8dc4f58..d86f4f8 100644
--- a/lib/examples/Makefile.am
+++ b/lib/examples/Makefile.am
@@ -1,6 +1,6 @@
AUTOMAKE_OPTIONS = foreign
INCLUDES = -I$(top_srcdir)/include
-AM_CFLAGS = -Wall -Werror -g
+AM_CFLAGS = -Wall -Werror -g -DDEBUG -DDEBUG_LEVENT
LDADD = ../libradsec.la #-lefence
CFLAGS = $(AM_CFLAGS) -DUSE_CONFIG_FILE
diff --git a/lib/examples/client-blocking.c b/lib/examples/client-blocking.c
index d2ee9f4..82a4453 100644
--- a/lib/examples/client-blocking.c
+++ b/lib/examples/client-blocking.c
@@ -85,9 +85,9 @@ blocking_client (const char *av1, const char *av2, const char *av3,
}
else
{
- if (rs_message_create_authn_request (conn, &req, USER_NAME, USER_PW, SECRET))
+ if (rs_message_create_authn_request (conn, &req, USER_NAME, USER_PW))
goto cleanup;
- if (rs_message_send (req, NULL))
+ if (rs_message_send (req))
goto cleanup;
if (rs_conn_receive_message (conn, req, &resp))
goto cleanup;
diff --git a/lib/examples/client-dispatch.c b/lib/examples/client-dispatch.c
index e007654..8a80ec6 100644
--- a/lib/examples/client-dispatch.c
+++ b/lib/examples/client-dispatch.c
@@ -67,14 +67,13 @@ dispatching_client (struct rs_context *ctx)
if (rs_conn_create(ctx, &conn, CONFIG))
goto out;
- rs_conn_set_callbacks (conn, &cb);
- if (rs_packet_create_authn_request (conn, &req_msg,
- USER_NAME, USER_PW, SECRET))
+ rs_conn_set_callbacks (conn, &cb, &state);
+ if (rs_packet_create_authn_request (conn, &req_msg, USER_NAME, USER_PW))
goto out;
/* Doesn't really send the message but rather queues it for sending.
msg_received_cb() will be invoked with user_data = &state when
the message has been sent. */
- if (rs_packet_send (req_msg, &state))
+ if (rs_packet_send (req_msg))
goto out;
while (1)
diff --git a/lib/examples/client.conf b/lib/examples/client.conf
index 32af3c0..288a084 100644
--- a/lib/examples/client.conf
+++ b/lib/examples/client.conf
@@ -9,6 +9,17 @@ realm blocking-udp {
}
}
+realm testcli-udp {
+ type = "UDP"
+ timeout = 2
+ retries = 2
+ server {
+ hostname = "srv1"
+ service = "4711"
+ secret = "sikrit"
+ }
+}
+
realm blocking-tls {
type = "TLS"
timeout = 1
@@ -22,7 +33,22 @@ realm blocking-tls {
#pskex = "PSK"
server {
hostname = "srv1"
+ # test setup: radsecproxy fronting freeradius on 2083
service = "2083"
+ # test setup: examples/server on 4711
+ #service = "4711"
+ secret = "sikrit"
+ }
+}
+
+realm testcli {
+ type = "TLS"
+ cacertfile = "/home/linus/p/radsecproxy/demoCA/newcerts/01.pem"
+ certfile = "/home/linus/p/radsecproxy/demoCA/newcerts/03.pem"
+ certkeyfile = "/home/linus/p/radsecproxy/demoCA/private/cli1.key"
+ server {
+ hostname = "srv1"
+ service = "4711"
secret = "sikrit"
}
}
diff --git a/lib/examples/server.c b/lib/examples/server.c
index 8c304a0..fb51866 100644
--- a/lib/examples/server.c
+++ b/lib/examples/server.c
@@ -1,7 +1,7 @@
/* RADIUS/RadSec server using libradsec. */
/* Copyright 2013 NORDUnet A/S. All rights reserved.
- See LICENSE for licensing information. */
+ See LICENSE for licensing information. */
#include <stdio.h>
#include <stdlib.h>
@@ -11,49 +11,129 @@
#include <event2/event.h>
#include "debug.h" /* For rs_dump_message(). */
-#define CONFIG_FILE "examples/test.conf"
+#define CONFIG_FILE "examples/server.conf"
#define CONFIG "tls"
#define SECRET "sikrit"
#define USER_NAME "molgan@PROJECT-MOONSHOT.ORG"
#define USER_PW "password"
-void
+static struct rs_peer *
+client_filter_cb (const struct rs_listener *listener,
+ void *user_data)
+{
+ printf ("DEBUG: listener %p (user_data=%p) asking for a client filter list\n",
+ listener, user_data);
+ return NULL;
+}
+
+static void
+disco_cb (void *user_data)
+{
+ struct rs_connection *conn = user_data;
+ assert (conn);
+ printf ("DEBUG: conn %p disconnected\n", conn);
+}
+
+static void
+read_cb (struct rs_message *message, void *user_data)
+{
+ struct rs_connection *conn = user_data;
+ assert (conn);
+ printf ("DEBUG: msg received on connection %p\n", conn);
+ rs_dump_message (message);
+ //if (message_verify_response (conn, fixme)) error;
+}
+
+static void
new_conn_cb (struct rs_connection *conn, void *user_data)
{
- printf ("new connection: fd=%d\n", -1); /* conn->fd */
+ const struct rs_listener *l = user_data;
+ struct rs_conn_callbacks cb = {NULL, /* connected */
+ disco_cb,
+ read_cb,
+ NULL}; /* msg sent */
+
+ printf ("DEBUG: new connection on listener %p: %p, fd=%d\n",
+ l, conn, rs_conn_get_fd (conn));
+ rs_conn_set_callbacks (conn, &cb, conn);
}
+void
+err_cb (struct rs_connection *conn, void *user_data)
+{
+ struct rs_listener *listener = user_data;
+ struct rs_error *err = NULL;
+ assert (conn);
+ err = rs_err_conn_pop (conn);
+
+ printf ("DEBUG: error on conn %p, listener %p: %d (%s)\n", conn, listener,
+ rs_err_code (err, 0), rs_err_msg (err));
+}
+
+#if 0
+void
+stdin_cb (evutil_socket_t s, short flags, void *user_data)
+{
+ struct rs_listener *l = user_data;
+
+ printf ("DEBUG: got data on stdin, quitting\n");
+ assert (event_base_loopbreak (rs_listener_get_eventbase (l)) == 0);
+}
+#endif
+
struct rs_error *
server (struct rs_context *ctx)
{
int r = 0;
struct rs_error *err = NULL;
- struct rs_connection *conn = NULL;
struct rs_listener *listener = NULL;
- const struct rs_listener_callbacks cbs = {};
+ const struct rs_listener_callbacks cbs =
+ {client_filter_cb, new_conn_cb, err_cb};
+ struct event *read_event = NULL;
if (rs_listener_create (ctx, &listener, CONFIG))
goto out;
- rs_listener_set_callbacks (listener, &cbs);
+ rs_listener_set_callbacks (listener, &cbs, listener);
+ if (rs_listener_listen (listener))
+ goto out;
+
+#if 0
+ /* Listen on stdin too, for quitting the server nicely without
+ having to trap SIGKILL. */
+ read_event = event_new (rs_listener_get_eventbase (listener),
+ fileno (stdin),
+ EV_READ,
+ stdin_cb,
+ listener);
+ assert (read_event != NULL);
+ assert (event_add (read_event, NULL) == 0);
+#endif
do
- {
- r = rs_listener_dispatch (listener);
- printf ("DEBUG: rs_listener_dispatch done (r=%d)\n", r);
- }
+ r = rs_listener_dispatch (listener);
while (r == 0);
+ printf ("DEBUG: rs_listener_dispatch done (r=%d)\n", r);
+ if (r < 0)
+ printf ("DEBUG: libevent signals error: %s\n", evutil_gai_strerror (r));
+ if (r == 1)
+ printf ("DEBUG: no events registered, exiting\n");
+
out:
err = rs_err_ctx_pop (ctx);
if (err == NULL)
- err = rs_err_conn_pop (conn);
+ err = rs_err_listener_pop (listener);
-#if 0
+ if (read_event)
+ event_free (read_event);
+ read_event = NULL;
if (listener)
- rs_listener_destroy (listener);
+ {
+ assert (rs_listener_close (listener) == RSE_OK);
+ //rs_listener_destroy (listener);
+ }
listener = NULL;
-#endif
return err;
}
@@ -80,13 +160,15 @@ main (int argc, char *argv[])
err = server (ctx);
out:
- if (ctx)
- rs_context_destroy (ctx);
-
if (err)
{
- fprintf (stderr, "error: %s: %d\n", rs_err_msg (err), rs_err_code (err, 0));
+ fprintf (stderr, "%s: error: %s: %d\n",
+ argv[0], rs_err_msg (err), rs_err_code (err, 0));
return rs_err_code (err, 1);
}
+
+ if (ctx)
+ rs_context_destroy (ctx);
+
return 0;
}