forked from radsecproxy/radsecproxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathradmsg.h
More file actions
153 lines (134 loc) · 5.06 KB
/
Copy pathradmsg.h
File metadata and controls
153 lines (134 loc) · 5.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/* Copyright (c) 2007-2008, UNINETT AS
* Copyright (c) 2015, NORDUnet A/S
* Copyright (c) 2023, SWITCH */
/* See LICENSE for licensing information. */
#ifndef _RADMSG_H
#define _RADMSG_H
#include "tlv11.h"
#include <stdint.h>
#include <stddef.h>
#define RAD_Min_Length 20
#define RAD_Max_Length 4096
#define RAD_Max_Attr_Value_Length 253
#define RAD_Access_Request 1
#define RAD_Access_Accept 2
#define RAD_Access_Reject 3
#define RAD_Accounting_Request 4
#define RAD_Accounting_Response 5
#define RAD_Access_Challenge 11
#define RAD_Status_Server 12
#define RAD_Status_Client 13
#define RAD_Disconnect_Request 40
#define RAD_Disconnect_ACK 41
#define RAD_Disconnect_NAK 42
#define RAD_CoA_Request 43
#define RAD_CoA_ACK 44
#define RAD_CoA_NAK 45
#define RAD_Protocol_Error 52
#define RAD_Attr_User_Name 1
#define RAD_Attr_User_Password 2
#define RAD_Attr_CHAP_Password 3
#define RAD_Attr_NAS_IP_Address 4
#define RAD_Attr_Framed_IP_Address 8
#define RAD_Attr_Reply_Message 18
#define RAD_Attr_Vendor_Specific 26
#define RAD_Attr_Called_Station_Id 30
#define RAD_Attr_Calling_Station_Id 31
#define RAD_Attr_Proxy_State 33
#define RAD_Attr_Acct_Status_Type 40
#define RAD_Attr_Acct_Input_Octets 42
#define RAD_Attr_Acct_Output_Octets 43
#define RAD_Attr_Acct_Session_Id 44
#define RAD_Attr_Acct_Session_Time 46
#define RAD_Attr_Acct_Input_Packets 47
#define RAD_Attr_Acct_Output_Packets 48
#define RAD_Attr_Acct_Terminate_Cause 49
#define RAD_Attr_Event_Timestamp 55
#define RAD_Attr_CHAP_Challenge 60
#define RAD_Attr_Tunnel_Password 69
#define RAD_Attr_EAP_Message 79
#define RAD_Attr_Message_Authenticator 80
#define RAD_Attr_CUI 89
#define RAD_Attr_Error_Cause 101
#define RAD_Attr_Operator_Name 126
#define RAD_ExtAttr_Original_Packet_Code (struct extattrtype){241, 4}
#define RAD_Acct_Status_Start 1
#define RAD_Acct_Status_Stop 2
#define RAD_Acct_Status_Alive 3
#define RAD_Acct_Status_Interim_Update 3
#define RAD_Acct_Status_Accounting_On 7
#define RAD_Acct_Status_Accounting_Off 8
#define RAD_Acct_Status_Failed 15
#define RAD_Err_Unsupported_Extension 406
#define RAD_Err_Request_Not_Routable 502
#define RAD_Err_Other_Proxy_Processing_Error 505
#define RAD_Err_Resources_Unavailable 506
#define RAD_VS_VENDOR_MS "\x00\x00\x01\x37"
#define RAD_VS_ATTR_MS_MPPE_Send_Key 16
#define RAD_VS_ATTR_MS_MPPE_Recv_Key 17
enum radmsg_auth_state {
RSP_RADMSG_AUTH_UNKNOWN = 0, /* not yet verified or unable to verify */
RSP_RADMSG_INVALID, /* request or response authenticator is invalid*/
RSP_RADMSG_VALID, /* request or rewponse authenticator is valid, no message authenticator present */
RSP_RADMSG_MSGAUTH_INVALID, /* message authenticator present but invalid */
RSP_RADMSG_MSGAUTH_VALID /* message authenticator present and valid, implies request or response authenticator is also valid*/
};
struct radmsg {
uint8_t code;
uint8_t id;
uint8_t auth[20];
struct list *attrs; /*struct tlv*/
enum radmsg_auth_state authstate;
};
/* radius message header length including code, id, length and authenticator */
#define RADHDRLEN 20
#define RADCODE(buf) ((buf)[0])
#define RADID(buf) ((buf)[1])
/* radius message length is a 16bit value starting at byte 2, in network order*/
#define RADLEN(buf) (uint16_t)(buf[2] << 8 | buf[3])
#define RADLEN_SET(buf, val) \
(buf)[2] = (val >> 8) & 0xff; \
(buf)[3] = val & 0xff;
#define RADAUTHLEN 16
#define RADAUTH(buf) ((buf) + 4)
#define ATTRHDRLEN 2
#define ATTRTYPE(x) ((x)[0])
#define ATTRLEN(x) ((x)[1])
#define ATTRVAL(x) ((x) + ATTRHDRLEN)
#define ATTRVALLEN(x) ((x)[1] - ATTRHDRLEN)
#define VSATTRMINVALLEN 5
#define VSATTRVENDORLEN 4
#define VSATTRVAL(buf) (buf + VSATTRVENDORLEN)
int get_checked_rad_length(uint8_t *buf);
void radmsg_free(struct radmsg *);
struct radmsg *radmsg_init(uint8_t, uint8_t, uint8_t *);
int radmsg_add(struct radmsg *, struct tlv *, uint8_t front);
struct tlv *radmsg_gettype(struct radmsg *, uint8_t);
struct tlv *radmsg_getexttype(struct radmsg *msg, struct extattrtype type);
struct list *radmsg_getalltype(const struct radmsg *msg, uint8_t type);
int radmsg_copy_attrs(struct radmsg *dst,
const struct radmsg *src,
uint8_t type);
uint8_t *tlv2buf(uint8_t *p, const struct tlv *tlv);
int radmsg2buf(struct radmsg *msg, uint8_t *, int, uint8_t **);
struct radmsg *buf2radmsg(uint8_t *, int, uint8_t *, int, uint8_t *);
uint8_t attrname2val(char *attrname);
int vattrname2val(char *attrname, uint32_t *vendor, uint32_t *type);
int attrvalidate(unsigned char *attrs, int length);
struct tlv *makevendortlv(uint32_t vendor, struct tlv *attr);
int resizeattr(struct tlv *attr, size_t newlen);
int verifyeapformat(struct radmsg *msg);
const char *radmsgtype2string(uint8_t code);
/**
* convert the attribute value to its string representation form the dictionary
* (see raddict.h)
*
* @param attr the attribute to convert
* @return the string representation or NULL, if the attribute/value is not in the
* dictionary
*/
const char *attrval2strdict(struct tlv *attr);
#endif /*_RADMSG_H*/
/* Local Variables: */
/* c-file-style: "stroustrup" */
/* End: */