Radcli library 1.3.1
A simple radius library
Loading...
Searching...
No Matches
radexample.c

This is an example of how to use the radcli API.

/*
* Copyright (C) 1995,1996,1997 Lars Fenneberg
* Copyright (C) 2015 Nikos Mavrogiannopoulos
*
* See the file COPYRIGHT for the respective terms and conditions.
*
*/
#include <config.h>
#include <stdio.h>
#include <string.h>
#include <radcli/radcli.h>
int
main (int argc, char **argv)
{
int result;
char username[128];
char passwd[AUTH_PASS_LEN + 1];
VALUE_PAIR *send, *received;
uint32_t service;
rc_handle *rh;
/* Not needed if you already used openlog() */
rc_openlog("my-prog-name");
if ((rh = rc_read_config(RC_CONFIG_FILE)) == NULL)
return ERROR_RC;
strcpy(username, "my-username");
strcpy(passwd, "my-password");
send = NULL;
/*
* Fill in User-Name
*/
if (rc_avpair_add(rh, &send, PW_USER_NAME, username, -1, 0) == NULL)
return ERROR_RC;
/*
* Fill in User-Password
*/
if (rc_avpair_add(rh, &send, PW_USER_PASSWORD, passwd, -1, 0) == NULL)
return ERROR_RC;
/*
* Fill in Service-Type
*/
service = PW_AUTHENTICATE_ONLY;
if (rc_avpair_add(rh, &send, PW_SERVICE_TYPE, &service, -1, 0) == NULL)
return ERROR_RC;
result = rc_auth(rh, 0, send, &received, NULL);
if (result == OK_RC) {
VALUE_PAIR *vp = received;
char name[128];
char value[128];
fprintf(stderr, "\"%s\" RADIUS Authentication OK\n", username);
/* print the known attributes in the reply */
while(vp != NULL) {
if (rc_avpair_tostr(rh, vp, name, sizeof(name), value, sizeof(value)) == 0) {
fprintf(stderr, "%s:\t%s\n", name, value);
}
vp = vp->next;
}
} else {
fprintf(stderr, "\"%s\" RADIUS Authentication failure (RC=%i)\n", username, result);
}
return result;
}
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