summaryrefslogtreecommitdiff
path: root/lib/examples
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/examples
parent94e3f46ef6c976f6bbd670555262ec6466314d8a (diff)
WIP on libradsec: 94e3f46 Example client crafting simple packet using freeradius-libradius.
Diffstat (limited to 'lib/examples')
-rw-r--r--lib/examples/Makefile2
-rw-r--r--lib/examples/client.c97
2 files changed, 20 insertions, 79 deletions
diff --git a/lib/examples/Makefile b/lib/examples/Makefile
index 1817d90..e07a32b 100644
--- a/lib/examples/Makefile
+++ b/lib/examples/Makefile
@@ -5,7 +5,7 @@ all: blocking.o
blocking.o: blocking.c blocking.h ../libradsec-base.h ../libradsec.h
$(CC) $(CFLAGS) -c -I .. $^
-client: client.c ../radsec.o ../libradsec.h ../debug.h
+client: client.c ../libradsec.a ../libradsec.h ../libradsec-impl.h
$(CC) $(CFLAGS) -o $@ -L /usr/lib/freeradius -lfreeradius-radius $^
clean:
diff --git a/lib/examples/client.c b/lib/examples/client.c
index 64a4436..37601b6 100644
--- a/lib/examples/client.c
+++ b/lib/examples/client.c
@@ -3,7 +3,6 @@
#include <stdio.h>
#include <string.h>
#include <unistd.h>
-#include <freeradius/libradius.h>
#include "../libradsec.h"
#include "../debug.h"
@@ -12,90 +11,32 @@
#define USER_PW "hemligt"
int
-rsx_client ()
+rsx_client (const char *srvname, int srvport)
{
- fr_randctx fr_ctx;
- struct rs_handle *ctx;
- struct rs_connection *conn;
- RADIUS_PACKET *pkt;
- VALUE_PAIR *vp;
- char user_pw[MAX_STRING_LEN];
- uint8_t reqauth[AUTH_VECTOR_LEN];
+ struct rs_context *h;
+ struct rs_connecion *conn;
+ struct rs_packet *req, *resp;
- fr_log_fp = stderr;
- fr_debug_flag = 1;
- fr_randinit (&fr_ctx, 0);
- fr_rand_seed (NULL, 0);
+ if (rs_context_create (&h, "/usr/share/freeradius/dictionary"))
+ return rs_err_code (rs_ctx_err_code (h));
- printf ("creating context\n");
- if (rs_context_create(&ctx))
- return -1;
+ if (rs_conn_new (h, &conn))
+ return rs_err_code (rs_conn_err_code (conn));
+ if (rs_conn_add_server (conn, RS_CONN_TYPE_UDP, srvname, srvport, 10, 3, SECRET))
+ return rs_err_code (rs_conn_err_code (conn));
-#if 0
- printf ("reading config\n");
- if (rs_context_config_read(ctx, "libradsec.conf"))
- return -1;
-#endif
+ if (rs_packet_create_acc_request (conn, &req, USER_NAME, USER_PW))
+ return rs_err_code (rs_conn_err_code (conn));
- printf ("init dict");
- if (dict_init("/usr/share/freeradius", "dictionary"))
- return -1;
+ if (rs_packet_send (req))
+ return rs_err_code (rs_conn_err_code (conn));
+ req = NULL;
-#if 0
- printf ("creating connection\n");
- if (rs_conn_create(ctx, &conn))
- return -1;
-#endif
+ if (rs_packet_recv (conn, &resp))
+ return rs_err_code (rs_conn_err_code (conn));
- printf ("creating a packet\n");
- pkt = rad_alloc (1);
- if (!pkt) {
- fr_perror ("pairmake");
- return -1;
- }
-
- {
- size_t pwlen = sizeof(USER_PW);
- strncpy (user_pw, USER_PW, sizeof(user_pw));
- rad_pwencode(user_pw, &pwlen, SECRET, reqauth);
- }
-
- printf ("creating value pairs\n");
- vp = pairmake ("User-Name", USER_NAME, 0);
- if (!vp) {
- fr_perror ("paircreate");
- return -1;
- }
- pairadd (&vp, pairmake ("User-Password", user_pw, 0));
- pkt->vps = vp;
-
- printf ("attributes:\n");
- vp_printlist (stdout, vp);
-
- printf ("encoding packet\n");
- rad_encode (pkt, NULL, SECRET);
- print_hex (pkt); /* DEBUG */
-
-#if 0
- rs_packet_create (&pkt, RS_ACCESS_REQUEST);
- rs_attrib_create (&attr, RS_...);
- rs_packet_add_attrib (pkt, attr);
-#endif
-
- //rs_packet_send (conn, pkt, ...);
-
- rad_free(&pkt);
-
-#if 0
- printf ("destroying connection\n");
- if (rs_conn_destroy(conn))
- return -1;
-#endif
-
- printf ("destroying context\n");
- rs_context_destroy(ctx);
-
- return 0;
+ rs_conn_destroy (conn);
+ rs_context_destroy (h);
}
int