www.pudn.com > RadiusSrv.rar > libRadius.h, change:2003-10-27,size:6013b


#ifndef _LIB_RADIUS_H 
#define _LIB_RADIUS_H 
 
#include "../common/GKCommon.h" 
#include "winsock2.h" 
#include "token.h" 
#include "time.h" 
 
/* 
 *  Compatibility 
 */ 
#define dict_vendorcode 
#define dict_vendorpec 
 
#define AUTH_VECTOR_LEN		16 
#define CHAP_VALUE_LENGTH       16 
 
#define MAX_DES_CRYPT_LENGTH           25 
 
#define MAX_STRING_LEN		254	/* RFC2138: string 0-253 octets */ 
#define MAX_PACKET_LEN 4096 
 
#  define AUTH_HDR_LEN		20 
#  define VENDORPEC_USR		429 
#  define TAG_VALID(x)          ((x) > 0 && (x) < 0x20) 
#  define VENDOR(x)		((x >> 16) & 0xffff) 
#  define debug_pair(vp)	do { if (librad_debug) { \ 
					putchar('\t'); \ 
					vp_print(stdout, vp); \ 
					putchar('\n'); \ 
				     } \ 
				} while(0) 
#  define TAG_VALID_ZERO(x)     ((x) >= 0 && (x) < 0x20) 
#  define TAG_ANY               -128   /* minimum signed char */ 
 
enum { 
	RLM_MODULE_REJECT,	/* immediately reject the request */ 
	RLM_MODULE_FAIL,	/* module failed, don't reply */ 
	RLM_MODULE_OK,		/* the module is OK, continue */ 
	RLM_MODULE_HANDLED,	/* the module handled the request, so stop. */ 
	RLM_MODULE_INVALID,	/* the module considers the request invalid. */ 
	RLM_MODULE_USERLOCK,	/* reject the request (user is locked out) */ 
	RLM_MODULE_NOTFOUND,	/* user not found */ 
	RLM_MODULE_NOOP,	/* module succeeded without doing anything */ 
	RLM_MODULE_UPDATED,	/* OK (pairs modified) */ 
	RLM_MODULE_NUMCODES	/* How many return codes there are */ 
}; 
 
/* 
 *  Values of the encryption flags. 
 */ 
#define FLAG_ENCRYPT_NONE            (0) 
#define FLAG_ENCRYPT_USER_PASSWORD   (1) 
#define FLAG_ENCRYPT_TUNNEL_PASSWORD (2) 
#define FLAG_ENCRYPT_ASCEND_SECRET   (3) 
 
 
/* random numbers in isaac.c */ 
/* context of random number generator */ 
typedef struct lrad_randctx { 
  uint32_t randcnt; 
  uint32_t randrsl[256]; 
  uint32_t randmem[256]; 
  uint32_t randa; 
  uint32_t randb; 
  uint32_t randc; 
} lrad_randctx; 
 
typedef struct attr_flags { 
	char			addport;	/* Add port to IP address */ 
	char			has_tag;	/* attribute allows tags */ 
	signed char		tag; 
	uint8_t		        encrypt;	/* encryption method */ 
	signed char		len_disp;	/* length displacement */ 
	char			do_xlat; 
} ATTR_FLAGS; 
 
typedef struct dict_attr { 
	char			name[40]; 
	int			attr; 
	int			type; 
	int			vendor; 
    ATTR_FLAGS              flags; 
	struct dict_attr	*next; 
} DICT_ATTR; 
 
typedef struct dict_value { 
	char			name[40]; 
	char			attrname[40]; 
	int			attr; 
	int			value; 
	struct dict_value	*next; 
} DICT_VALUE; 
 
typedef struct dict_vendor { 
	char			vendorname[40]; 
	int			vendorpec; 
	struct dict_vendor	*next; 
} DICT_VENDOR; 
 
typedef struct value_pair { 
	char			name[40]; 
	int			attribute; 
	int			type; 
	int			length; /* of strvalue */ 
	uint32_t		lvalue; 
	LRAD_TOKEN		oper;//operator; 
	char			strvalue[MAX_STRING_LEN]; 
	ATTR_FLAGS              flags; 
	struct value_pair	*next; 
} VALUE_PAIR; 
 
/* 
 *	vector:		Request authenticator from access-request packet 
 *			Put in there by rad_decode, and must be put in the 
 *			response RADIUS_PACKET as well before calling rad_send 
 * 
 *	verified:	Filled in by rad_decode for accounting-request packets 
 * 
 *	data,data_len:	Used between rad_recv and rad_decode. 
 */ 
typedef struct radius_packet { 
	int			sockfd; 
	uint32_t		src_ipaddr; 
	uint32_t		dst_ipaddr; 
	u_short			src_port; 
	u_short			dst_port; 
	int			id; 
	int			code; 
	uint8_t			vector[AUTH_VECTOR_LEN]; 
	time_t			timestamp; 
	int			verified; 
	uint8_t			*data; 
	int			data_len; 
	VALUE_PAIR		*vps; 
} RADIUS_PACKET; 
 
/* md5.c */ 
 
void librad_md5_calc(unsigned char *output, unsigned char *input, 
		     unsigned int inputlen); 
 
/* hmac.c */ 
 
void lrad_hmac_md5(const unsigned char *text, int text_len, 
		   const unsigned char *key, int key_len, 
		   unsigned char *digest); 
 
/* radius.c */ 
RADIUS_PACKET *rad_recv(int fd); 
int		rad_send(RADIUS_PACKET *, const RADIUS_PACKET *, const char *secret); 
int		rad_decode(RADIUS_PACKET *packet, RADIUS_PACKET *original, const char *secret); 
RADIUS_PACKET	*rad_alloc(int newvector); 
void		rad_free(RADIUS_PACKET **); 
int		rad_pwencode(char *encpw, int *len, const char *secret, const char *vector); 
int		rad_pwdecode(char *encpw, int len, const char *secret, const char *vector); 
int		rad_tunnel_pwencode(char *encpw, int *len, const char *secret, const char *vector); 
int		rad_tunnel_pwdecode(char *encpw, int *len, const char *secret, const char *vector); 
int		rad_chap_encode(RADIUS_PACKET *packet, char *output, int id, VALUE_PAIR *password); 
 
/* valuepair.c */ 
VALUE_PAIR	*paircreate(int attr, int type); 
void		pairfree(VALUE_PAIR **); 
VALUE_PAIR	*pairfind(VALUE_PAIR *, int); 
void		pairdelete(VALUE_PAIR **, int); 
void		pairadd(VALUE_PAIR **, VALUE_PAIR *); 
VALUE_PAIR	*paircopy(VALUE_PAIR *vp); 
VALUE_PAIR	*paircopy2(VALUE_PAIR *vp, int attr); 
void		pairmove(VALUE_PAIR **to, VALUE_PAIR **from); 
void		pairmove2(VALUE_PAIR **to, VALUE_PAIR **from, int attr); 
VALUE_PAIR	*pairparsevalue(VALUE_PAIR *vp, const char *value); 
VALUE_PAIR	*pairmake(const char *attribute, const char *value, int oper/*operator*/); 
VALUE_PAIR	*pairread(char **ptr, LRAD_TOKEN *eol); 
LRAD_TOKEN	userparse(char *buffer, VALUE_PAIR **first_pair); 
 
 
/* 
 *	Dictionary functions. 
 */ 
int		dict_addvendor(const char *name, int value); 
int		dict_addattr(const char *name, int vendor, int type, int value, ATTR_FLAGS flags); 
int		dict_addvalue(const char *namestr, char *attrstr, int value); 
int		dict_init(const char *dir, const char *fn); 
DICT_ATTR	*dict_attrbyvalue(int attr); 
DICT_ATTR	*dict_attrbyname(const char *attr); 
DICT_VALUE	*dict_valbyattr(int attr, int val); 
DICT_VALUE	*dict_valbyname(int attr, const char *val); 
int		dict_vendorname(const char *name); 
 
extern int	librad_max_attributes; /* per incoming packet */ 
 
/* 
 *	Several handy miscellaneous functions. 
 */ 
char		*strNcpy(char *dest, const char *src, int n); 
char *		ip_ntoa(char *, uint32_t); 
 
#endif