summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordu.net>2010-10-03 23:27:46 +0200
committerLinus Nordberg <linus@nordu.net>2010-10-03 23:27:46 +0200
commitdcfb8bca7400c5db4fafbed7aa9395e5f3277d9b (patch)
treeb27ba2c7de397236b85e5a02a6277fe786fc17ff /lib
parent4d99bb55ec1368b42daccb29f0440bc166297a17 (diff)
WIP
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile1
-rw-r--r--lib/examples/Makefile4
-rw-r--r--lib/examples/client-blocking.c9
-rw-r--r--lib/include/radsec/radsec-impl.h1
-rw-r--r--lib/include/radsec/radsec.h20
-rw-r--r--lib/radsec.c24
6 files changed, 41 insertions, 18 deletions
diff --git a/lib/Makefile b/lib/Makefile
index c622dc2..774a0d2 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -1,6 +1,7 @@
CFLAGS = -Wall -g -I include -DDEBUG
OFILES = attr.o \
+ conf.o \
debug.o \
err.o \
packet.o \
diff --git a/lib/examples/Makefile b/lib/examples/Makefile
index 4a0ab8f..4802c4b 100644
--- a/lib/examples/Makefile
+++ b/lib/examples/Makefile
@@ -1,4 +1,6 @@
-SPECIAL = # -DUSE_REQUEST_OBJECT
+SPECIAL =
+#SPECIAL += -DUSE_REQUEST_OBJECT
+#SPECIAL += -DUSE_CONFIG_FILE
CFLAGS = -Wall -g -I ../include $(SPECIAL)
diff --git a/lib/examples/client-blocking.c b/lib/examples/client-blocking.c
index a9a4f32..0e6ad39 100644
--- a/lib/examples/client-blocking.c
+++ b/lib/examples/client-blocking.c
@@ -28,10 +28,11 @@ blocking_client (const char *av1, const char *av2)
if (rs_context_create (&h, "/usr/share/freeradius/dictionary"))
return NULL;
- if (rs_conn_create (h, &conn, RS_CONN_TYPE_UDP))
- return rs_err_conn_pop (conn);
#if !defined (USE_CONFIG_FILE)
- if (rs_server_create (conn, &server, NULL))
+ if (rs_conn_create (h, &conn, NULL))
+ return rs_err_conn_pop (conn);
+ rs_conn_set_type (conn, RS_CONN_TYPE_UDP);
+ if (rs_server_create (conn, &server))
return rs_err_conn_pop (conn);
if (rs_server_set_address (server, av1, atoi (av2)))
return rs_err_conn_pop (conn);
@@ -42,7 +43,7 @@ blocking_client (const char *av1, const char *av2)
#else
if (rs_context_config_read (h, av1))
return rs_err_ctx_pop (h);
- if (rs_server_create (conn, &server, av2))
+ if (rs_conn_create (h, &conn, av2))
return rs_err_conn_pop (conn);
#endif /* USE_CONFIG_FILE */
diff --git a/lib/include/radsec/radsec-impl.h b/lib/include/radsec/radsec-impl.h
index 4f7fa2c..503b2e5 100644
--- a/lib/include/radsec/radsec-impl.h
+++ b/lib/include/radsec/radsec-impl.h
@@ -44,6 +44,7 @@ struct rs_peer {
struct rs_realm {
char *name;
+ enum rs_conn_type type;
struct rs_peer *peers;
};
diff --git a/lib/include/radsec/radsec.h b/lib/include/radsec/radsec.h
index f92da7f..c108d8a 100644
--- a/lib/include/radsec/radsec.h
+++ b/lib/include/radsec/radsec.h
@@ -75,15 +75,9 @@ void rs_context_destroy(struct rs_handle *ctx);
int rs_context_set_alloc_scheme(struct rs_handle *ctx, struct rs_alloc_scheme *scheme);
int rs_context_read_config(struct rs_handle *ctx, const char *config_file);
-/* Server and client configuration. */
-int rs_server_create(struct rs_connection *conn, struct rs_peer **server, const char *config);
-int rs_server_set_address(struct rs_peer *server, const char *hostname, int port);
-int rs_server_set_secret(struct rs_peer *server, const char *secret);
-void rs_server_set_timeout(struct rs_peer *server, int timeout);
-void rs_server_set_tries(struct rs_peer *server, int tries);
-
/* Connection. */
-int rs_conn_create(struct rs_handle *ctx, struct rs_connection **conn, rs_conn_type_t type);
+int rs_conn_create(struct rs_handle *ctx, struct rs_connection **conn, const char *config);
+void rs_conn_set_type(struct rs_connection *conn, rs_conn_type_t type);
int rs_conn_add_listener(struct rs_connection *conn, rs_conn_type_t type, const char *hostname, int port);
void rs_conn_destroy(struct rs_connection *conn);
int rs_conn_set_eventbase(struct rs_connection *conn, struct event_base *eb);
@@ -93,6 +87,13 @@ int rs_conn_select_server(struct rs_connection *conn, const char *name);
int rs_conn_get_current_server(struct rs_connection *conn, const char *name, size_t buflen);
int rs_conn_receive_packet(struct rs_connection *conn, struct rs_packet **pkt_out);
+/* Server and client. */
+int rs_server_create(struct rs_connection *conn, struct rs_peer **server);
+int rs_server_set_address(struct rs_peer *server, const char *hostname, int port);
+int rs_server_set_secret(struct rs_peer *server, const char *secret);
+void rs_server_set_timeout(struct rs_peer *server, int timeout);
+void rs_server_set_tries(struct rs_peer *server, int tries);
+
/* Packet. */
int rs_packet_create_acc_request(struct rs_connection *conn, struct rs_packet **pkt, const char *user_name, const char *user_pw);
//int rs_packet_create_acc_accept(cstruct rs_connection *conn, struct rs_packet **pkt);
@@ -107,6 +108,9 @@ struct radius_packet *rs_packet_frpkt(struct rs_packet *pkt);
int rs_attr_create(struct rs_connection *conn, struct rs_attr **attr, const char *type, const char *val);
void rs_attr_destroy(struct rs_attr *attr);
+/* Config. */
+struct rs_realm *rs_conf_find_realm(struct rs_handle *ctx, const char *name);
+
/* Error. */
int rs_err_ctx_push(struct rs_handle *ctx, int code, const char *fmt, ...);
int rs_err_ctx_push_fl(struct rs_handle *ctx, int code, const char *file, int line, const char *fmt, ...);
diff --git a/lib/radsec.c b/lib/radsec.c
index 6ec2b06..adf5576 100644
--- a/lib/radsec.c
+++ b/lib/radsec.c
@@ -81,7 +81,7 @@ int rs_context_config_read(struct rs_handle *ctx, const char *config_file)
int
rs_conn_create(struct rs_handle *ctx, struct rs_connection **conn,
- rs_conn_type_t type)
+ const char *config)
{
struct rs_connection *c;
@@ -90,13 +90,27 @@ rs_conn_create(struct rs_handle *ctx, struct rs_connection **conn,
{
memset (c, 0, sizeof(struct rs_connection));
c->ctx = ctx;
- c->type = type;
+ if (config)
+ {
+ struct rs_realm *r = rs_conf_find_realm (ctx, config);
+ if (r)
+ {
+ c->type = r->type;
+ c->peers = r->peers; /* FIXME: Copy? */
+ }
+ }
}
if (conn)
*conn = c;
return c ? RSE_OK : rs_err_ctx_push (ctx, RSE_NOMEM, NULL);
}
+void
+rs_conn_set_type(struct rs_connection *conn, rs_conn_type_t type)
+{
+ conn->type = type;
+}
+
struct addrinfo *
_resolv (struct rs_connection *conn, const char *hostname, int port)
{
@@ -157,8 +171,7 @@ _peer_new (struct rs_connection *conn)
}
int
-rs_server_create (struct rs_connection *conn, struct rs_peer **server,
- const char *config)
+rs_server_create (struct rs_connection *conn, struct rs_peer **server)
{
struct rs_peer *srv;
@@ -168,7 +181,8 @@ rs_server_create (struct rs_connection *conn, struct rs_peer **server,
srv->timeout = 1;
srv->tries = 3;
}
- *server = srv;
+ if (*server)
+ *server = srv;
return srv ? RSE_OK : -1;
}