summaryrefslogtreecommitdiff
path: root/lib/radsec.c
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordu.net>2010-09-27 18:47:07 +0200
committerLinus Nordberg <linus@nordu.net>2010-09-27 18:57:06 +0200
commitaa354bb116fb38c9b049070dea4752afe9a3ea34 (patch)
tree51001c4157aef25682eeb5c460438dc5c47ed323 /lib/radsec.c
parent94e3f46ef6c976f6bbd670555262ec6466314d8a (diff)
WIP on libradsec: 94e3f46 Example client crafting simple packet using freeradius-libradius.
Diffstat (limited to 'lib/radsec.c')
-rw-r--r--lib/radsec.c85
1 files changed, 59 insertions, 26 deletions
diff --git a/lib/radsec.c b/lib/radsec.c
index 760da84..f645ee1 100644
--- a/lib/radsec.c
+++ b/lib/radsec.c
@@ -1,17 +1,51 @@
+#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
+#include <libgen.h>
+
+#include <freeradius/libradius.h>
#include "libradsec.h"
#include "libradsec-impl.h"
-#define ERR_OK 0
-#define ERR_NOMEM 1
-#define ERR_NOSYS 2
-#define ERR_SOME_ERROR 99
-
-int rs_context_create(struct rs_handle **ctx)
+int
+rs_context_create(struct rs_handle **ctx, const char *dict)
{
- *ctx = (struct rs_handle *) malloc (sizeof (struct rs_handle));
- return (ctx ? ERR_OK : ERR_NOMEM);
+ struct rs_handle *h;
+
+ *ctx = NULL;
+ h = (struct rs_handle *) malloc (sizeof (struct rs_handle));
+ if (h)
+ {
+ char *buf;
+ char *dir, *fn;
+
+ buf = malloc (strlen (dict) + 1);
+ if (!buf)
+ {
+ free (h);
+ return RSE_NOMEM;
+ }
+ strcpy (buf, dict);
+ dir = dirname (buf);
+ free (buf);
+ strcpy (buf, dict);
+ fn = basename (buf);
+ free (buf);
+ if (dict_init (dir, fn) < 0)
+ {
+ free (h);
+ return RSE_SOME_ERROR;
+ }
+#if defined (DEBUG)
+ fr_log_fp = stderr;
+ fr_debug_flag = 1;
+#endif
+ fr_randinit (&h->fr_randctx, 0);
+ fr_rand_seed (NULL, 0);
+
+ *ctx = h;
+ }
+ return (h ? RSE_OK : RSE_NOMEM);
}
void rs_context_destroy(struct rs_handle *ctx)
@@ -21,51 +55,50 @@ void rs_context_destroy(struct rs_handle *ctx)
int rs_context_set_alloc_scheme(struct rs_handle *ctx, struct rs_alloc_scheme *scheme)
{
- return ERR_NOSYS;
+ return RSE_NOSYS;
}
int rs_context_config_read(struct rs_handle *ctx, const char *config_file)
{
- return ERR_NOSYS;
+ return RSE_NOSYS;
}
int rs_conn_create(const struct rs_handle *ctx, struct rs_connection **conn)
{
- return ERR_NOSYS;
+ return RSE_NOSYS;
}
-int rs_conn_destroy(struct rs_connection *conn)
+int rs_conn_add_server(struct rs_connection *conn, rs_conn_type_t type, const char *host, int port, int timeout, int tries, const char *secret)
{
- return ERR_NOSYS;
+ return RSE_NOSYS;
}
-int rs_conn_set_eventbase(struct rs_connection *conn, struct event_base *eb)
+int rs_conn_add_listener(struct rs_connection *conn, rs_conn_type_t type, const char *host, int port, const char *secret)
{
- return ERR_NOSYS;
+ return RSE_NOSYS;
}
-int rs_conn_set_callbacks(struct rs_connection *conn, struct rs_conn_callbacks *cb)
+int rs_conn_destroy(struct rs_connection *conn)
{
- return ERR_NOSYS;
+ return RSE_NOSYS;
}
-int rs_conn_set_server(struct rs_connection *conn, const char *name)
+int rs_conn_set_eventbase(struct rs_connection *conn, struct event_base *eb)
{
- return ERR_NOSYS;
+ return RSE_NOSYS;
}
-int rs_conn_get_server(const struct rs_connection *conn, const char *name, size_t buflen)
+int rs_conn_set_callbacks(struct rs_connection *conn, struct rs_conn_callbacks *cb)
{
- return ERR_NOSYS;
+ return RSE_NOSYS;
}
-int rs_packet_send(const struct rs_conn *conn, const struct rs_packet *pkt, void *user_data)
+int rs_conn_set_server(struct rs_connection *conn, const char *name)
{
- return ERR_NOSYS;
+ return RSE_NOSYS;
}
-int rs_packet_receive(const struct rs_conn *conn, struct rs_packet **pkt)
+int rs_conn_get_server(const struct rs_connection *conn, const char *name, size_t buflen)
{
- return ERR_NOSYS;
+ return RSE_NOSYS;
}
-