Radcli library 1.3.1
A simple radius library
Loading...
Searching...
No Matches
radexample.c
1/*
2 * Copyright (C) 1995,1996,1997 Lars Fenneberg
3 * Copyright (C) 2015 Nikos Mavrogiannopoulos
4 *
5 * See the file COPYRIGHT for the respective terms and conditions.
6 *
7 */
8
9#include <config.h>
10#include <stdio.h>
11#include <string.h>
12#include <radcli/radcli.h>
13
14int
15main (int argc, char **argv)
16{
17 int result;
18 char username[128];
19 char passwd[AUTH_PASS_LEN + 1];
20 VALUE_PAIR *send, *received;
21 uint32_t service;
22 rc_handle *rh;
23
24 /* Not needed if you already used openlog() */
25 rc_openlog("my-prog-name");
26
27 if ((rh = rc_read_config(RC_CONFIG_FILE)) == NULL)
28 return ERROR_RC;
29
30 strcpy(username, "my-username");
31 strcpy(passwd, "my-password");
32
33 send = NULL;
34
35 /*
36 * Fill in User-Name
37 */
38 if (rc_avpair_add(rh, &send, PW_USER_NAME, username, -1, 0) == NULL)
39 return ERROR_RC;
40
41 /*
42 * Fill in User-Password
43 */
44 if (rc_avpair_add(rh, &send, PW_USER_PASSWORD, passwd, -1, 0) == NULL)
45 return ERROR_RC;
46
47 /*
48 * Fill in Service-Type
49 */
50 service = PW_AUTHENTICATE_ONLY;
51 if (rc_avpair_add(rh, &send, PW_SERVICE_TYPE, &service, -1, 0) == NULL)
52 return ERROR_RC;
53
54 result = rc_auth(rh, 0, send, &received, NULL);
55
56 if (result == OK_RC) {
57 VALUE_PAIR *vp = received;
58 char name[128];
59 char value[128];
60
61 fprintf(stderr, "\"%s\" RADIUS Authentication OK\n", username);
62
63 /* print the known attributes in the reply */
64 while(vp != NULL) {
65 if (rc_avpair_tostr(rh, vp, name, sizeof(name), value, sizeof(value)) == 0) {
66 fprintf(stderr, "%s:\t%s\n", name, value);
67 }
68 vp = vp->next;
69 }
70 } else {
71 fprintf(stderr, "\"%s\" RADIUS Authentication failure (RC=%i)\n", username, result);
72 }
73
74 return result;
75}
void rc_openlog(char const *ident)
Definition: log.c:36
int rc_auth(rc_handle *rh, uint32_t nas_port, VALUE_PAIR *send, VALUE_PAIR **received, char *msg)
Definition: buildreq.c:235
int rc_avpair_tostr(rc_handle const *rh, VALUE_PAIR *pair, char *name, int ln, char *value, int lv)
Definition: avpair.c:831
rc_handle * rc_read_config(char const *filename)
Definition: config.c:568
VALUE_PAIR * rc_avpair_add(rc_handle const *rh, VALUE_PAIR **list, uint32_t attrid, void const *pval, int len, uint32_t vendorspec)
Definition: avpair.c:46
@ PW_SERVICE_TYPE
Its type is integer.
Definition: radcli.h:148
@ PW_USER_NAME
Its type is string.
Definition: radcli.h:143
@ PW_USER_PASSWORD
Its type is string.
Definition: radcli.h:144