summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordberg.se>2013-02-11 16:46:54 +0100
committerLinus Nordberg <linus@nordberg.se>2013-02-11 16:46:54 +0100
commite6b0f4f404e06be4fdbf7a7cf5a475278ba3e587 (patch)
tree208d2bbe39fb496cb357d650cdf7436444b5198a
parent0eb67a0ad70d0ce4ba82c131ece4da3107cf3a68 (diff)
Add the dummy server example.
This is not a server. It's just testing server config atm.
-rw-r--r--lib/examples/Makefile.am9
-rw-r--r--lib/examples/server.c83
2 files changed, 86 insertions, 6 deletions
diff --git a/lib/examples/Makefile.am b/lib/examples/Makefile.am
index 9a2cd55..8dc4f58 100644
--- a/lib/examples/Makefile.am
+++ b/lib/examples/Makefile.am
@@ -2,12 +2,9 @@ AUTOMAKE_OPTIONS = foreign
INCLUDES = -I$(top_srcdir)/include
AM_CFLAGS = -Wall -Werror -g
-noinst_PROGRAMS = client client2
+LDADD = ../libradsec.la #-lefence
+CFLAGS = $(AM_CFLAGS) -DUSE_CONFIG_FILE
+noinst_PROGRAMS = client client2 server
client_SOURCES = client-blocking.c
-client_LDADD = ../libradsec.la #-lefence
-client_CFLAGS = $(AM_CFLAGS) -DUSE_CONFIG_FILE
-
client2_SOURCES = client-dispatch.c
-client2_LDADD = ../libradsec.la #-lefence
-client2_CFLAGS = $(AM_CFLAGS) -DUSE_CONFIG_FILE
diff --git a/lib/examples/server.c b/lib/examples/server.c
new file mode 100644
index 0000000..88c2bf4
--- /dev/null
+++ b/lib/examples/server.c
@@ -0,0 +1,83 @@
+/* RADIUS/RadSec server using libradsec. */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <string.h>
+#include <radsec/radsec.h>
+#include <event2/event.h>
+#include "debug.h" /* For rs_dump_message(). */
+
+#define CONFIG_FILE "examples/test.conf"
+#define CONFIG "tls"
+
+#define SECRET "sikrit"
+#define USER_NAME "molgan@PROJECT-MOONSHOT.ORG"
+#define USER_PW "password"
+
+
+struct rs_error *
+server (struct rs_context *ctx)
+{
+ struct rs_error *err = NULL;
+ struct rs_connection *conn = NULL;
+#if 0
+ struct rs_listener *listener = NULL;
+
+ if (rs_listener_create (ctx, &listener, CONFIG))
+ goto out;
+
+ while (1)
+ {
+ if (rs_listener_dispatch (listener))
+ goto out;
+ }
+
+ out:
+#endif
+
+ err = rs_err_ctx_pop (ctx);
+ if (err == NULL)
+ err = rs_err_conn_pop (conn);
+
+#if 0
+ if (listener)
+ rs_listener_destroy (listener);
+ listener = NULL;
+#endif
+
+ return err;
+}
+
+int
+main (int argc, char *argv[])
+{
+ struct rs_error *err = NULL;
+ struct rs_context *ctx = NULL;
+
+ if (rs_context_create (&ctx))
+ goto out;
+ if (rs_context_read_config (ctx, CONFIG_FILE))
+ goto out;
+
+ { /* DEBUG printouts */
+ char *buf = NULL;
+ int err = rs_context_print_config (ctx, &buf);
+ assert (err == RSE_OK);
+ fputs (buf, stdout);
+ free (buf);
+ }
+
+ 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));
+ return rs_err_code (err, 1);
+ }
+ return 0;
+}