DTS Application Library  0.2.3
Application library containing referenced objects and interfaces to common libraries
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
Radius client interface

Simple implementation of experimental radius client. More...

Files

file  radius.c
 Simple radius client implementation.
 

Data Structures

struct  radius_packet
 Radius Packet. More...
 
struct  radius_session
 Radius session. More...
 
struct  radius_connection
 Radius connection. More...
 
struct  radius_server
 Radius Server. More...
 

Macros

#define RAD_AUTH_HDR_LEN   20
 Authentification header length. More...
 
#define RAD_AUTH_PACKET_LEN   4096
 Auth packet length. More...
 
#define RAD_AUTH_TOKEN_LEN   16
 Auth token length. More...
 
#define RAD_MAX_PASS_LEN   128
 Auth max password length. More...
 
#define RAD_ATTR_USER_NAME   1 /*string*/
 Radius attribute username. More...
 
#define RAD_ATTR_USER_PASSWORD   2 /*passwd*/
 Radius attribute password. More...
 
#define RAD_ATTR_NAS_IP_ADDR   4 /*ip*/
 Radius attribute server IP. More...
 
#define RAD_ATTR_NAS_PORT   5 /*int*/
 Radius attribute server port. More...
 
#define RAD_ATTR_SERVICE_TYPE   6 /*int*/
 Radius attribute service type. More...
 
#define RAD_ATTR_ACCTID   44
 Radius attribute account id. More...
 
#define RAD_ATTR_PORT_TYPE   61 /*int*/
 Radius attribute port type. More...
 
#define RAD_ATTR_EAP   79 /*oct*/
 Radius attribute EAP. More...
 
#define RAD_ATTR_MESSAGE   80 /*oct*/
 Radius attribute message. More...
 

Typedefs

typedef struct radius_packet radius_packet
 Forward decleration of structure. More...
 
typedef void(* radius_cb )(struct radius_packet *, void *)
 Callback to call when response arrives. More...
 

Enumerations

enum  RADIUS_CODE {
  RAD_CODE_AUTHREQUEST = 1, RAD_CODE_AUTHACCEPT = 2, RAD_CODE_AUTHREJECT = 3, RAD_CODE_ACCTREQUEST = 4,
  RAD_CODE_ACCTRESPONSE = 5, RAD_CODE_AUTHCHALLENGE = 11
}
 Radius packet codes. More...
 

Functions

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_packetnew_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...
 

Detailed Description

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

Macro Definition Documentation

#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

Authentification header length.

Definition at line 529 of file dtsapp.h.

Referenced by new_radpacket(), and radius_attr_next().

#define RAD_AUTH_PACKET_LEN   4096

Auth packet length.

Definition at line 532 of file dtsapp.h.

#define RAD_AUTH_TOKEN_LEN   16

Auth token length.

Definition at line 535 of file dtsapp.h.

Referenced by new_radpacket().

#define RAD_MAX_PASS_LEN   128

Auth max password length.

Definition at line 538 of file dtsapp.h.

Typedef Documentation

typedef void(* radius_cb)(struct radius_packet *, void *)

Callback to call when response arrives.

Parameters
packetReference to radius packet.
dataReference to userdata.

Definition at line 306 of file dtsapp.h.

typedef struct radius_packet radius_packet

Forward decleration of structure.

Definition at line 193 of file dtsapp.h.

Enumeration Type Documentation

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.

568  {
581 };
Radius auth challenge.
Definition: dtsapp.h:580
Radius auth accept.
Definition: dtsapp.h:572
Radius auth reject.
Definition: dtsapp.h:574
Radius auth request.
Definition: dtsapp.h:570
Radius accounting request.
Definition: dtsapp.h:576
Radius accounting response.
Definition: dtsapp.h:578

Function Documentation

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
ipaddrIP address or hostname of server.
authAthentification port.
acctAccounting port.
secretShared secret.
timeoutTime 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.

289  {
290  struct radius_server *server;
291 
292  if ((server = objalloc(sizeof(*server), del_radserver))) {
293  ALLOC_CONST(server->name, ipaddr);
294  ALLOC_CONST(server->authport, auth);
295  ALLOC_CONST(server->acctport, acct);
296  ALLOC_CONST(server->secret, secret);
297  if (!servers) {
298  servers = create_bucketlist(0, hash_server);
299  }
300  server->id = bucket_list_cnt(servers);
301  server->timeout = timeout;
302  gettimeofday(&server->service, NULL);
303  addtobucket(servers, server);
304  }
305 
306  objunref(server);
307 }
void * create_bucketlist(int bitmask, blisthash hash_function)
Definition: refobj.c:356
int timeout
Server timeout.
Definition: radius.c:117
void * objalloc(int size, objdestroy)
Allocate a referenced lockable object.
Definition: refobj.c:129
const char * name
Server name.
Definition: radius.c:107
int bucket_list_cnt(struct bucket_list *blist)
Return number of items in the list.
Definition: refobj.c:552
const char * secret
Server secret.
Definition: radius.c:113
const char * authport
Server authport.
Definition: radius.c:109
struct timeval service
Server out of service time.
Definition: radius.c:119
unsigned char id
Server hash based on server count.
Definition: radius.c:115
const char * acctport
Server accounting port.
Definition: radius.c:111
Radius Server.
Definition: radius.c:105
#define ALLOC_CONST(const_var, val)
Macro to assign values to char const.
Definition: dtsapp.h:959
int addtobucket(struct bucket_list *blist, void *data)
Add a reference to the bucketlist.
Definition: refobj.c:428
int objunref(void *data)
Drop reference held.
Definition: refobj.c:184
void addradattrint ( struct radius_packet packet,
char  type,
unsigned int  val 
)

Add a integer attribute too the packet.

Parameters
packetRadius packet to add too.
typeAttribute been added.
valValue to add.

Definition at line 149 of file radius.c.

149  {
150  unsigned int tval;
151 
152  tval = htonl(val);
153  addradattr(packet, type, (unsigned char *)&tval, sizeof(tval));
154 }
void addradattrip ( struct radius_packet packet,
char  type,
char *  ipaddr 
)

Add a integer attribute too the packet.

Parameters
packetRadius packet to add too.
typeAttribute been added.
ipaddrIP to add.

Definition at line 160 of file radius.c.

160  {
161  unsigned int tval;
162 
163  tval = inet_addr(ipaddr);
164  addradattr(packet, type, (unsigned char *)&tval, sizeof(tval));
165 }
void addradattrstr ( struct radius_packet packet,
char  type,
char *  str 
)

Add a integer attribute too the packet.

Parameters
packetRadius packet to add too.
typeAttribute been added.
strValue to add.

Definition at line 171 of file radius.c.

171  {
172  addradattr(packet, type, (unsigned char *)str, strlen(str));
173 }
struct radius_packet* new_radpacket ( unsigned char  code)

Create a new radius packet.

See Also
RADIUS_CODE
Parameters
codeRadius packet type.
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.

221  {
222  struct radius_packet *packet;
223 
224  if ((packet = malloc(sizeof(*packet)))) {
225  memset(packet, 0, sizeof(*packet));
226  packet->len = RAD_AUTH_HDR_LEN;
227  packet->code = code;
228  genrand(&packet->token, RAD_AUTH_TOKEN_LEN);
229  }
230  return (packet);
231 }
Radius Packet.
Definition: radius.c:45
unsigned char token[RAD_AUTH_TOKEN_LEN]
Authentification token.
Definition: radius.c:54
unsigned short len
Packet length.
Definition: radius.c:52
#define RAD_AUTH_TOKEN_LEN
Auth token length.
Definition: dtsapp.h:535
#define RAD_AUTH_HDR_LEN
Authentification header length.
Definition: dtsapp.h:529
unsigned char code
Radius packet code.
Definition: radius.c:48
int genrand(void *buf, int len)
Generate random sequence.
Definition: util.c:82
unsigned char* radius_attr_first ( struct radius_packet packet)

Return first packet attribute.

Used with radius_attr_next() to iterate through attributes.

Parameters
packetRadius packet.
Returns
Pointer to next attribute

Definition at line 627 of file radius.c.

References radius_packet::attrs.

627  {
628  return (packet->attrs);
629 }
unsigned char attrs[RAD_AUTH_PACKET_LEN-RAD_AUTH_HDR_LEN]
Radius Attributes.
Definition: radius.c:56
unsigned char* radius_attr_next ( struct radius_packet packet,
unsigned char *  attr 
)

Return next packet attribute.

Parameters
packetRadius packet.
attrLast 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.

635  {
636  int offset = (packet->len - RAD_AUTH_HDR_LEN) - (attr - packet->attrs);
637 
638  if (!(offset - attr[1])) {
639  return NULL;
640  }
641 
642  return (attr + attr[1]);
643 }
unsigned short len
Packet length.
Definition: radius.c:52
#define RAD_AUTH_HDR_LEN
Authentification header length.
Definition: dtsapp.h:529
unsigned char attrs[RAD_AUTH_PACKET_LEN-RAD_AUTH_HDR_LEN]
Radius Attributes.
Definition: radius.c:56
int send_radpacket ( struct radius_packet packet,
const char *  userpass,
radius_cb  read_cb,
void *  cb_data 
)

Send radius packet.

Parameters
packetRadius packet to send.
userpassUserpassword if required (added last requires special processing)
read_cbCallback to call when response arrives.
cb_dataReference to pass to callback.
Returns
0 on success.

Definition at line 452 of file radius.c.

452  {
453  return (_send_radpacket(packet, userpass, NULL, read_cb, cb_data));
454 }