32 #include <netinet/in.h>
38 #include <networkradius-devel/radius.h>
135 #ifdef PW_EAP_MESSAGE
136 #ifndef PW_MESSAGE_AUTHENTICATOR
137 #error EAP-Message requires Message-Authenticator
144 #define NR_MD5_CTX MD5_CTX
146 #define nr_MD5Init MD5_Init
148 #define nr_MD5Update MD5_Update
150 #define nr_MD5Final MD5_Final
152 #define nr_MD5Transform MD5_Transform
156 #include <openssl/md5.h>
158 #define NR_MD5_CTX MD5_CTX
160 #define nr_MD5Init MD5_Init
162 #define nr_MD5Update MD5_Update
164 #define nr_MD5Final MD5_Final
166 #define nr_MD5Transform MD5_Transform
169 #ifndef NR_MAX_PACKET_LEN
179 #define NR_MAX_PACKET_LEN (4096)
182 #ifndef NR_MAX_ATTRIBUTES
192 #define NR_MAX_ATTRIBUTES (200)
195 #undef NR_MAX_PACKET_CODE
201 #define NR_MAX_PACKET_CODE 46
208 #define NR_MAX_VENDOR (1 << 24)
217 #define MAX_STRING_LEN (254)
236 #define PW_ACCESS_REQUEST 1
237 #define PW_ACCESS_ACCEPT 2
238 #define PW_ACCESS_REJECT 3
239 #define PW_ACCOUNTING_REQUEST 4
240 #define PW_ACCOUNTING_RESPONSE 5
241 #define PW_ACCOUNTING_STATUS 6
242 #define PW_ACCESS_CHALLENGE 11
243 #define PW_STATUS_SERVER 12
244 #define PW_DISCONNECT_REQUEST 40
245 #define PW_DISCONNECT_ACK 41
246 #define PW_DISCONNECT_NAK 42
247 #define PW_COA_REQUEST 43
248 #define PW_COA_ACK 44
249 #define PW_COA_NAK 45
319 #define TAG_VALID(x) ((x) < 0x20)
322 #define FLAG_ENCRYPT_NONE (0)
325 #define FLAG_ENCRYPT_USER_PASSWORD (1)
328 #define FLAG_ENCRYPT_TUNNEL_PASSWORD (2)
341 unsigned int has_tlv : 1;
342 unsigned int is_tlv : 1;
344 #ifdef VENDOR_EXTENDED
345 unsigned int extended : 1;
346 unsigned int extended_flags : 1;
347 unsigned int evs : 1;
404 #ifdef NR_TYPE_SIGNED
407 #ifdef NR_TYPE_ABINARY
430 #define vp_strvalue data.strvalue
431 #define vp_octets data.octets
432 #define vp_ipv6addr data.ipv6addr
433 #define vp_ifid data.ifid
434 #define vp_ipv6prefix data.ipv6prefix
435 #define vp_ipaddr data.ipaddr.s_addr
436 #define vp_date data.integer
437 #define vp_integer data.integer
438 #define vp_integer64 data.integer64
439 #ifdef NR_TYPE_ABINARY
440 #define vp_filter data.filter
443 #define vp_ether data.ether
445 #ifdef NR_TYPE_SIGNED
446 #define vp_signed data.sinteger
449 #define vp_tlv data.tlv
453 #define NR_ATTR_MAX_TLV (4)
454 extern const int nr_attr_shift[NR_ATTR_MAX_TLV];
455 extern const int nr_attr_mask[NR_ATTR_MAX_TLV];
456 extern const unsigned int nr_attr_max_tlv;
490 struct sockaddr_storage
src;
491 struct sockaddr_storage
dst;
527 #define NR_PACKET_ENCODED (1 << 0)
528 #define NR_PACKET_HEADER (1 << 1)
529 #define NR_PACKET_SIGNED (1 << 2)
530 #define NR_PACKET_OK (1 << 3)
531 #define NR_PACKET_VERIFIED (1 << 4)
532 #define NR_PACKET_DECODED (1 << 5)
641 struct sockaddr_storage
src;
642 struct sockaddr_storage
dst;
783 unsigned int attr,
unsigned int vendor);
800 unsigned int vendor);
831 unsigned int attr,
unsigned int vendor,
832 char *buffer,
size_t bufsize);
1215 extern struct sockaddr_storage *
nr_ipv42sockaddr(uint32_t ipaddr,
int port,
1216 struct sockaddr_storage *s);
1224 extern int sockaddr_cmp(
const struct sockaddr_storage *a,
1225 const struct sockaddr_storage *b);
1259 struct sockaddr_storage *src,
1260 struct sockaddr_storage *dst);
1274 extern ssize_t
nr_rand_bytes(uint8_t *data,
size_t data_len);
1287 extern uint32_t
nr_rand(
void);
1298 extern void nr_timeval_add(
struct timeval *t,
unsigned int seconds,
1310 extern int nr_timeval_cmp(
const struct timeval *a,
const struct timeval *b);
1383 size_t sizeof_data);
1408 #define nr_debug_error nr_strerror_printf
1410 #define nr_debug_error if (0) nr_strerror_printf
1427 const uint8_t *input,
size_t inlen,
1428 const char *secret,
const uint8_t *vector);
1444 const uint8_t *input,
size_t inlen,
1445 const char *secret,
const uint8_t *vector);
1462 const uint8_t *input,
size_t inlen,
1463 const char *secret,
const uint8_t *vector);
1473 extern void nr_hmac_md5(
const uint8_t *data,
size_t data_len,
1474 const uint8_t *key,
size_t key_len,
1475 uint8_t digest[16]);
1488 extern int nr_tlv_ok(
const uint8_t *data,
size_t length,
1489 size_t dv_type,
size_t dv_length);
1537 const char *secret,
int code,
1538 void *data,
size_t sizeof_data);
1567 const void *data,
size_t data_len);
1624 const VALUE_PAIR **pvp, uint8_t *data,
size_t room);
1641 uint8_t *data,
size_t room);
1656 const uint8_t *data,
size_t length,
1673 const uint8_t *data,
size_t length,
1690 const uint8_t *data,
size_t length,
1707 const uint8_t *data,
size_t length,
1750 unsigned int attr,
unsigned int vendor,
1751 const uint8_t **pdata,
size_t *plength);
1808 #define return_NR_ERR(_x) return -(NR_ERR_ ## _x)
1813 #define return_NR_ERR(_x) {fprintf(stderr, "ERROR %s[%d] %d\n", __FILE__, __LINE__, NR_ERR_ ## _x); return -(NR_ERR_ ## _x);}
1816 #if defined(__GNUC__)
1817 # define PRINTF_LIKE(n) __attribute__ ((format(printf, n, n+1)))
1818 # define NEVER_RETURNS __attribute__ ((noreturn))
1819 # define UNUSED __attribute__ ((unused))
1820 # define BLANK_FORMAT " "
1826 # define PRINTF_LIKE(n)
1831 # define NEVER_RETURNS
1841 # define BLANK_FORMAT ""
size_t length
Definition: client.h:389
ssize_t nr_socket_recv(RADIUS_PACKET *packet)
Definition: socket.c:35
const DICT_VENDOR nr_dict_vendors[]
Definition: dictionaries.c:11
int nr_socket_send_response(RADIUS_PACKET *packet, const RADIUS_PACKET *original)
Definition: socket.c:195
ssize_t nr_packet_vps_append(RADIUS_PACKET *packet, const RADIUS_PACKET *original, const VALUE_PAIR *vps)
Definition: packet.c:928
int nr_packet_response_ok(RADIUS_PACKET const *packet, RADIUS_PACKET const *response)
Definition: packet.c:959
nr_transmit_state_t
Definition: client.h:462
int nr_packet_can_encode(RADIUS_PACKET *packet, const RADIUS_PACKET *original)
Definition: packet.c:515
int nr_transmit(nr_track_id_t *s, struct timeval *when, RADIUS_PACKET *request, RADIUS_PACKET *response)
Definition: transmit.c:180
const DICT_ATTR nr_dict_attrs[]
Definition: dictionaries.c:28
nr_attr_type_t
Definition: client.h:221
ssize_t nr_tunnelpw_decrypt(uint8_t *output, size_t outlen, const uint8_t *input, size_t inlen, const char *secret, const uint8_t *vector)
Definition: crypto.c:124
struct sockaddr_storage src
Definition: client.h:490
const char * secret
Definition: client.h:645
const char * nr_packet_codes[NR_MAX_PACKET_CODE+1]
Definition: packet.c:34
int mrd
Definition: client.h:596
struct value_pair VALUE_PAIR
uint32_t nr_rand(void)
Definition: custom.c:46
uint8_t ifid[8]
Definition: client.h:410
VALUE_PAIR * nr_vp_init(VALUE_PAIR *vp, const DICT_ATTR *da)
Definition: valuepair.c:46
VALUE_PAIR * nr_vp_create(int attr, int vendor, const void *data, size_t data_len)
Definition: valuepair.c:175
unsigned int unknown
Definition: client.h:339
int nr_packet_sign(RADIUS_PACKET *packet, const RADIUS_PACKET *original)
Definition: packet.c:418
struct nr_dict_vendor DICT_VENDOR
int nr_track_id_close(const nr_track_id_t *s)
Definition: id.c:152
size_t length
Definition: client.h:425
ssize_t nr_packet_attr_append(RADIUS_PACKET *packet, const RADIUS_PACKET *original, const DICT_ATTR *da, const void *data, size_t data_len)
Definition: packet.c:858
ssize_t nr_attr2vp_rfc(const RADIUS_PACKET *packet, const RADIUS_PACKET *original, const uint8_t *data, size_t length, VALUE_PAIR **pvp)
Definition: attrs.c:1010
int nr_timeval_cmp(const struct timeval *a, const struct timeval *b)
Definition: custom.c:70
ssize_t nr_vp2vsa(const RADIUS_PACKET *packet, const RADIUS_PACKET *original, const VALUE_PAIR **pvp, uint8_t *data, size_t room)
Definition: attrs.c:387
struct sockaddr_storage dst
Definition: client.h:642
size_t nr_vp_snprintf(char *buffer, size_t bufsize, const VALUE_PAIR *vp)
Definition: print.c:234
int nr_packet_decode(RADIUS_PACKET *packet, const RADIUS_PACKET *original)
Definition: packet.c:364
#define NR_MAX_PACKET_CODE
Definition: client.h:201
uint8_t octets[253]
Definition: client.h:398
unsigned int code
Definition: client.h:497
DICT_ATTR const * nr_dict_attr_names[]
Definition: dictionaries.c:1373
const DICT_ATTR * nr_dict_attr_byvalue(unsigned int attr, unsigned int vendor)
Definition: dict.c:26
size_t sizeof_secret
Definition: client.h:495
int delay
Definition: client.h:519
struct sockaddr_storage src
Definition: client.h:641
void nr_hmac_md5(const uint8_t *data, size_t data_len, const uint8_t *key, size_t key_len, uint8_t digest[16])
Definition: crypto.c:183
int used
Definition: client.h:648
size_t sizeof_secret
Definition: client.h:646
const DICT_ATTR * nr_dict_attr_byname(const char *name)
Definition: dict.c:65
int nr_track_id_packet_alloc(nr_track_id_t *s, RADIUS_PACKET **packet_p, RADIUS_PACKET *original, size_t sizeof_data)
Definition: id.c:163
int tag
Definition: client.h:426
void nr_strerror_printf(const char *fmt,...)
int nr_packet_init(RADIUS_PACKET *packet, const RADIUS_PACKET *original, const char *secret, int code, void *data, size_t sizeof_data)
Definition: packet.c:783
#define MAX_STRING_LEN
Definition: client.h:217
ssize_t nr_attr2data(const RADIUS_PACKET *packet, ssize_t start, unsigned int attr, unsigned int vendor, const uint8_t **pdata, size_t *plength)
Definition: attrs.c:1319
const int nr_dict_num_attrs
Definition: dictionaries.c:1369
int value
Definition: client.h:375
VALUE_PAIR * nr_vp_alloc_raw(unsigned int attr, unsigned int vendor)
Definition: valuepair.c:77
struct value_pair * next
Definition: client.h:427
void nr_track_id_packet_free(nr_track_id_t *s, RADIUS_PACKET *packet)
Definition: id.c:228
const DICT_ATTR * da
Definition: client.h:374
int nr_track_id_socket(nr_track_id_t *s, struct sockaddr_storage *src, struct sockaddr_storage *dst)
Definition: socket.c:357
int mrc
Definition: client.h:620
VALUE_PAIR * nr_vps_find(VALUE_PAIR *head, unsigned int attr, unsigned int vendor)
Definition: valuepair.c:205
const DICT_VENDOR * nr_dict_vendor_byvalue(unsigned int vendor)
Definition: dict.c:154
const char * nr_strerror(int error)
Definition: print.c:283
int sockaddr_cmp(const struct sockaddr_storage *a, const struct sockaddr_storage *b)
Definition: socket.c:236
uint32_t integer
Definition: client.h:402
char strvalue[MAX_STRING_LEN]
Definition: client.h:397
VALUE_PAIR_DATA data
Definition: client.h:428
struct radius_packet RADIUS_PACKET
ssize_t nr_vp2attr(const RADIUS_PACKET *packet, const RADIUS_PACKET *original, const VALUE_PAIR **pvp, uint8_t *data, size_t room)
Definition: attrs.c:559
int code
Definition: client.h:639
ssize_t nr_packet_encode(RADIUS_PACKET *packet, const RADIUS_PACKET *original)
Definition: packet.c:617
size_t sizeof_data
Definition: client.h:523
int nr_packet_verify(RADIUS_PACKET *packet, const RADIUS_PACKET *original)
Definition: packet.c:300
int nr_socket_send(RADIUS_PACKET *packet)
Definition: socket.c:152
int nr_socket_open(struct sockaddr_storage *s)
Definition: socket.c:277
ssize_t nr_password_encrypt(uint8_t *output, size_t outlen, const uint8_t *input, size_t inlen, const char *secret, const uint8_t *vector)
Definition: crypto.c:32
int nr_vp_sscanf(const char *string, VALUE_PAIR **pvp)
Definition: parse.c:148
int id
Definition: client.h:498
const DICT_ATTR * da
Definition: client.h:424
ATTR_FLAGS flags
Definition: client.h:365
const DICT_VALUE * nr_dict_value_byattr(unsigned int attr, unsigned int vendor, int value)
const DICT_VALUE * nr_dict_value_byname(unsigned int attr, unsigned int vendor, const char *name)
int(* packet_send)(void *, RADIUS_PACKET *)
Definition: client.h:651
uint8_t * data
Definition: client.h:522
void nr_timeval_add(struct timeval *t, unsigned int seconds, unsigned int usec)
Definition: custom.c:59
int nr_dict_vendor_byname(const char *name)
Definition: dict.c:138
int nr_transmit_init(nr_track_id_t *s, RADIUS_PACKET *request)
Definition: transmit.c:203
size_t type
Definition: client.h:388
int mrt
Definition: client.h:579
int sockfd
Definition: client.h:637
uint8_t vector[16]
Definition: client.h:500
uint8_t length
Definition: client.h:351
int nr_track_id_init(nr_track_id_t *s, int code, const char *secret)
Definition: id.c:118
uint8_t ipv6prefix[18]
Definition: client.h:411
ssize_t nr_vp2rfc(const RADIUS_PACKET *packet, const RADIUS_PACKET *original, const VALUE_PAIR **pvp, uint8_t *data, size_t room)
Definition: attrs.c:444
void nr_vp_fprintf_list(FILE *fp, const VALUE_PAIR *vps)
Definition: print.c:256
socklen_t sizeof_addr
Definition: client.h:643
RADIUS_PACKET * ids[256]
Definition: client.h:655
int sockfd
Definition: client.h:489
nr_retransmit_config_t timers
Definition: client.h:653
int nr_packet_ok_raw(const uint8_t *data, size_t sizeof_data)
Definition: packet.c:96
ssize_t nr_attr2vp(const RADIUS_PACKET *packet, const RADIUS_PACKET *original, const uint8_t *data, size_t length, VALUE_PAIR **pvp)
Definition: attrs.c:1287
void nr_packet_print_hex(RADIUS_PACKET *packet)
Definition: print.c:73
struct nr_dict_value DICT_VALUE
ssize_t nr_vp_sscanf_value(VALUE_PAIR *vp, const char *value)
Definition: parse.c:78
struct nr_track_id_t nr_track_id_t
struct in_addr ipaddr
Definition: client.h:399
int nr_track_id_release(nr_track_id_t *s, RADIUS_PACKET *packet)
Definition: id.c:69
struct nr_retransmit_config_t nr_retransmit_config_t
ssize_t nr_socket_recv_response(RADIUS_PACKET *response, const RADIUS_PACKET *request)
Definition: socket.c:119
char name[1]
Definition: client.h:376
const char * name
Definition: client.h:366
nr_attr_type_t type
Definition: client.h:363
uint64_t integer64
Definition: client.h:403
ssize_t nr_rand_bytes(uint8_t *data, size_t data_len)
Definition: custom.c:30
const char * secret
Definition: client.h:494
int attempts
Definition: client.h:517
int nr_tlv_ok(const uint8_t *data, size_t length, size_t dv_type, size_t dv_length)
Definition: attrs.c:1032
VALUE_PAIR * vps
Definition: client.h:524
int nr_track_id_realloc(nr_track_id_t *s, RADIUS_PACKET *packet)
Definition: id.c:86
const char * name
Definition: client.h:390
uint8_t encrypt
Definition: client.h:350
VALUE_PAIR * nr_vp_alloc(const DICT_ATTR *da)
Definition: valuepair.c:57
size_t nr_vp_snprintf_value(char *buffer, size_t bufsize, const VALUE_PAIR *vp)
Definition: print.c:157
struct attr_flags ATTR_FLAGS
unsigned int vendor
Definition: client.h:364
int irt
Definition: client.h:569
int flags
Definition: client.h:520
struct timeval timestamp
Definition: client.h:502
int nr_vp_set_data(VALUE_PAIR *vp, const void *data, size_t data_len)
Definition: valuepair.c:103
int nr_track_id_alloc(nr_track_id_t *s, RADIUS_PACKET *packet)
Definition: id.c:49
struct in6_addr ipv6addr
Definition: client.h:400
const int nr_dict_num_names
Definition: dictionaries.c:1371
nr_transmit_state_t state
Definition: client.h:515
int nr_dict_attr_2struct(DICT_ATTR *da, unsigned int attr, unsigned int vendor, char *buffer, size_t bufsize)
Definition: dict.c:94
ssize_t nr_tunnelpw_encrypt(uint8_t *output, size_t outlen, const uint8_t *input, size_t inlen, const char *secret, const uint8_t *vector)
Definition: crypto.c:78
struct nr_dict_attr DICT_ATTR
ssize_t nr_attr2vp_vsa(const RADIUS_PACKET *packet, const RADIUS_PACKET *original, const uint8_t *data, size_t length, VALUE_PAIR **pvp)
Definition: attrs.c:1207
unsigned int has_tag
Definition: client.h:338
size_t length
Definition: client.h:499
void nr_vps_append(VALUE_PAIR **head, VALUE_PAIR *vp)
Definition: valuepair.c:194
int nr_vp_set_raw_data(VALUE_PAIR *vp, const void *data, size_t data_len)
Definition: valuepair.c:151
int(* nr_packet_walk_func_t)(void *, const DICT_ATTR *, const uint8_t *, size_t)
Definition: client.h:1498
int nr_packet_walk(RADIUS_PACKET *packet, void *ctx, nr_packet_walk_func_t callback)
Definition: packet.c:684
MD5 structures and prototypes.
unsigned int attr
Definition: client.h:362
int nr_packet_ok(RADIUS_PACKET *packet)
Definition: packet.c:145
void * ctx
Definition: client.h:650
struct sockaddr_storage * nr_ipv42sockaddr(uint32_t ipaddr, int port, struct sockaddr_storage *s)
Definition: socket.c:216
uint32_t date
Definition: client.h:401
ssize_t nr_attr2vp_raw(const RADIUS_PACKET *packet, const RADIUS_PACKET *original, const uint8_t *data, size_t length, VALUE_PAIR **pvp)
Definition: attrs.c:692
nr_error_t
Definition: client.h:256
socklen_t sizeof_addr
Definition: client.h:492
void nr_vp_free(VALUE_PAIR **head)
Definition: valuepair.c:26
struct sockaddr_storage dst
Definition: client.h:491
union value_pair_data VALUE_PAIR_DATA
unsigned int vendor
Definition: client.h:387