Simple implementation of experimental radius client.
More...
|
file | radius.c |
| Simple radius client implementation.
|
|
|
void | addradattrint (struct radius_packet *packet, char type, unsigned int val) |
| Add a integer attribute too the packet. More...
|
|
void | addradattrip (struct radius_packet *packet, char type, char *ipaddr) |
| Add a integer attribute too the packet. More...
|
|
void | addradattrstr (struct radius_packet *packet, char type, char *str) |
| Add a integer attribute too the packet. More...
|
|
struct radius_packet * | new_radpacket (unsigned char code) |
| Create a new radius packet. More...
|
|
void | add_radserver (const char *ipaddr, const char *auth, const char *acct, const char *secret, int timeout) |
| Add new radius server to list of servers. More...
|
|
int | send_radpacket (struct radius_packet *packet, const char *userpass, radius_cb read_cb, void *cb_data) |
| Send radius packet. More...
|
|
unsigned char * | radius_attr_first (struct radius_packet *packet) |
| Return first packet attribute. More...
|
|
unsigned char * | radius_attr_next (struct radius_packet *packet, unsigned char *attr) |
| Return next packet attribute. More...
|
|
Simple implementation of experimental radius client.
* User password crypt function from the freeradius project (addattrpasswd)
* Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 The FreeRADIUS Server Project
#define RAD_ATTR_ACCTID 44 |
Radius attribute account id.
Definition at line 556 of file dtsapp.h.
#define RAD_ATTR_EAP 79 /*oct*/ |
Radius attribute EAP.
Definition at line 562 of file dtsapp.h.
#define RAD_ATTR_MESSAGE 80 /*oct*/ |
Radius attribute message.
Definition at line 565 of file dtsapp.h.
#define RAD_ATTR_NAS_IP_ADDR 4 /*ip*/ |
Radius attribute server IP.
Definition at line 547 of file dtsapp.h.
#define RAD_ATTR_NAS_PORT 5 /*int*/ |
Radius attribute server port.
Definition at line 550 of file dtsapp.h.
#define RAD_ATTR_PORT_TYPE 61 /*int*/ |
Radius attribute port type.
Definition at line 559 of file dtsapp.h.
#define RAD_ATTR_SERVICE_TYPE 6 /*int*/ |
Radius attribute service type.
Definition at line 553 of file dtsapp.h.
#define RAD_ATTR_USER_NAME 1 /*string*/ |
Radius attribute username.
Definition at line 541 of file dtsapp.h.
#define RAD_ATTR_USER_PASSWORD 2 /*passwd*/ |
Radius attribute password.
Definition at line 544 of file dtsapp.h.
#define RAD_AUTH_HDR_LEN 20 |
#define RAD_AUTH_PACKET_LEN 4096 |
Auth packet length.
Definition at line 532 of file dtsapp.h.
#define RAD_AUTH_TOKEN_LEN 16 |
#define RAD_MAX_PASS_LEN 128 |
Auth max password length.
Definition at line 538 of file dtsapp.h.
Callback to call when response arrives.
- Parameters
-
packet | Reference to radius packet. |
data | Reference to userdata. |
Definition at line 306 of file dtsapp.h.
Forward decleration of structure.
Definition at line 193 of file dtsapp.h.
Radius packet codes.
Enumerator |
---|
RAD_CODE_AUTHREQUEST |
Radius auth request.
|
RAD_CODE_AUTHACCEPT |
Radius auth accept.
|
RAD_CODE_AUTHREJECT |
Radius auth reject.
|
RAD_CODE_ACCTREQUEST |
Radius accounting request.
|
RAD_CODE_ACCTRESPONSE |
Radius accounting response.
|
RAD_CODE_AUTHCHALLENGE |
Radius auth challenge.
|
Definition at line 568 of file dtsapp.h.
Radius accounting request.
Radius accounting response.
void add_radserver |
( |
const char * |
ipaddr, |
|
|
const char * |
auth, |
|
|
const char * |
acct, |
|
|
const char * |
secret, |
|
|
int |
timeout |
|
) |
| |
Add new radius server to list of servers.
- Parameters
-
ipaddr | IP address or hostname of server. |
auth | Athentification port. |
acct | Accounting port. |
secret | Shared secret. |
timeout | Time to take offline on failure. |
Definition at line 289 of file radius.c.
References radius_server::acctport, addtobucket(), ALLOC_CONST, radius_server::authport, bucket_list_cnt(), create_bucketlist(), radius_server::id, radius_server::name, objalloc(), objunref(), radius_server::secret, radius_server::service, and radius_server::timeout.
292 if ((server =
objalloc(
sizeof(*server), del_radserver))) {
302 gettimeofday(&server->
service, NULL);
void * create_bucketlist(int bitmask, blisthash hash_function)
int timeout
Server timeout.
void * objalloc(int size, objdestroy)
Allocate a referenced lockable object.
const char * name
Server name.
int bucket_list_cnt(struct bucket_list *blist)
Return number of items in the list.
const char * secret
Server secret.
const char * authport
Server authport.
struct timeval service
Server out of service time.
unsigned char id
Server hash based on server count.
const char * acctport
Server accounting port.
#define ALLOC_CONST(const_var, val)
Macro to assign values to char const.
int addtobucket(struct bucket_list *blist, void *data)
Add a reference to the bucketlist.
int objunref(void *data)
Drop reference held.
void addradattrint |
( |
struct radius_packet * |
packet, |
|
|
char |
type, |
|
|
unsigned int |
val |
|
) |
| |
Add a integer attribute too the packet.
- Parameters
-
packet | Radius packet to add too. |
type | Attribute been added. |
val | Value to add. |
Definition at line 149 of file radius.c.
153 addradattr(packet, type, (
unsigned char *)&tval,
sizeof(tval));
void addradattrip |
( |
struct radius_packet * |
packet, |
|
|
char |
type, |
|
|
char * |
ipaddr |
|
) |
| |
Add a integer attribute too the packet.
- Parameters
-
packet | Radius packet to add too. |
type | Attribute been added. |
ipaddr | IP to add. |
Definition at line 160 of file radius.c.
163 tval = inet_addr(ipaddr);
164 addradattr(packet, type, (
unsigned char *)&tval,
sizeof(tval));
void addradattrstr |
( |
struct radius_packet * |
packet, |
|
|
char |
type, |
|
|
char * |
str |
|
) |
| |
Add a integer attribute too the packet.
- Parameters
-
packet | Radius packet to add too. |
type | Attribute been added. |
str | Value to add. |
Definition at line 171 of file radius.c.
172 addradattr(packet, type, (
unsigned char *)str, strlen(str));
Create a new radius packet.
- See Also
- RADIUS_CODE
- Parameters
-
- Returns
- reference to new radius packet of specified type.
Definition at line 221 of file radius.c.
References radius_packet::code, genrand(), radius_packet::len, RAD_AUTH_HDR_LEN, RAD_AUTH_TOKEN_LEN, and radius_packet::token.
224 if ((packet = malloc(
sizeof(*packet)))) {
225 memset(packet, 0,
sizeof(*packet));
unsigned char token[RAD_AUTH_TOKEN_LEN]
Authentification token.
unsigned short len
Packet length.
#define RAD_AUTH_TOKEN_LEN
Auth token length.
#define RAD_AUTH_HDR_LEN
Authentification header length.
unsigned char code
Radius packet code.
int genrand(void *buf, int len)
Generate random sequence.
unsigned char* radius_attr_first |
( |
struct radius_packet * |
packet | ) |
|
Return first packet attribute.
Used with radius_attr_next() to iterate through attributes.
- Parameters
-
- Returns
- Pointer to next attribute
Definition at line 627 of file radius.c.
References radius_packet::attrs.
628 return (packet->
attrs);
unsigned char attrs[RAD_AUTH_PACKET_LEN-RAD_AUTH_HDR_LEN]
Radius Attributes.
unsigned char* radius_attr_next |
( |
struct radius_packet * |
packet, |
|
|
unsigned char * |
attr |
|
) |
| |
Return next packet attribute.
- Parameters
-
packet | Radius packet. |
attr | Last attribute. |
- Returns
- Pointer to next attribute.
Definition at line 635 of file radius.c.
References radius_packet::attrs, radius_packet::len, and RAD_AUTH_HDR_LEN.
638 if (!(offset - attr[1])) {
642 return (attr + attr[1]);
unsigned short len
Packet length.
#define RAD_AUTH_HDR_LEN
Authentification header length.
unsigned char attrs[RAD_AUTH_PACKET_LEN-RAD_AUTH_HDR_LEN]
Radius Attributes.
int send_radpacket |
( |
struct radius_packet * |
packet, |
|
|
const char * |
userpass, |
|
|
radius_cb |
read_cb, |
|
|
void * |
cb_data |
|
) |
| |
Send radius packet.
- Parameters
-
packet | Radius packet to send. |
userpass | Userpassword if required (added last requires special processing) |
read_cb | Callback to call when response arrives. |
cb_data | Reference to pass to callback. |
- Returns
- 0 on success.
Definition at line 452 of file radius.c.
453 return (_send_radpacket(packet, userpass, NULL, read_cb, cb_data));