Main Page | Class List | File List | Class Members

ace-radius/RadiusAttribute.h

00001 /* 00002 * This source file is part of the ace-radius library. This code was 00003 * written by Alex Agranov in 2004-2009, and is covered by the BSD open source 00004 * license. Refer to the accompanying documentation for details on usage and 00005 * license. 00006 */ 00007 00008 #ifndef _RADIUSATTRIBUTE_H__ 00009 #define _RADIUSATTRIBUTE_H__ 00010 00011 #include "Radius.h" 00012 00013 // definition of Attribute Types from RFC2865 00014 #define D_ATTR_USER_NAME 1 00015 #define D_ATTR_USER_PASSWORD 2 00016 #define D_ATTR_CHAP_PASSWORD 3 00017 #define D_ATTR_NAS_IP_ADDRESS 4 00018 #define D_ATTR_NAS_PORT 5 00019 #define D_ATTR_SERVICE_TYPE 6 00020 #define D_ATTR_FRAMED_PROTOCOL 7 00021 #define D_ATTR_FRAMED_IP_ADDRESS 8 00022 #define D_ATTR_FRAMED_IP_NETMASK 9 00023 #define D_ATTR_FRAMED_ROUTING 10 00024 #define D_ATTR_FILTER_ID 11 00025 #define D_ATTR_FRAMED_MTU 12 00026 #define D_ATTR_FRAMED_COMPRESSION 13 00027 #define D_ATTR_LOGIN_IP_HOST 14 00028 #define D_ATTR_LOGIN_SERVICE 15 00029 #define D_ATTR_LOGIN_TCP_PORT 16 00030 #define D_ATTR_OLD_PASSWORD 17 00031 #define D_ATTR_REPLY_MESSAGE 18 00032 #define D_ATTR_CALLBACK_NUMBER 19 00033 #define D_ATTR_CALLBACK_ID 20 00034 #define D_ATTR_FRAMED_ROUTE 22 00035 #define D_ATTR_FRAMED_IPX_NETWORK 23 00036 #define D_ATTR_STATE 24 00037 #define D_ATTR_CLASS 25 00038 #define D_ATTR_VENDOR_SPECIFIC 26 00039 #define D_ATTR_SESSION_TIMEOUT 27 00040 #define D_ATTR_IDLE_TIMEOUT 28 00041 #define D_ATTR_TERMINATION_ACTION 29 00042 #define D_ATTR_CALLED_STATION_ID 30 00043 #define D_ATTR_CALLING_STATION_ID 31 00044 #define D_ATTR_NAS_IDENTIFIER 32 00045 #define D_ATTR_PROXY_STATE 33 00046 #define D_ATTR_LOGIN_LAT_SERVICE 34 00047 #define D_ATTR_LOGIN_LAT_NODE 35 00048 #define D_ATTR_LOGIN_LAT_GROUP 36 00049 #define D_ATTR_FRAMED_APPLETALK_LINK 37 00050 #define D_ATTR_FRAMED_APPLETALK_NETWORK 38 00051 #define D_ATTR_FRAMED_APPLETALK_ZONE 39 00052 // types 40-59 are reserved for accounting - RFC2866 00053 #define D_ATTR_CHAP_CHALLENGE 60 00054 #define D_ATTR_NAS_PORT_TYPE 61 00055 #define D_ATTR_PORT_LIMIT 62 00056 #define D_ATTR_LOGIN_LAT_PROMPT 63 00057 00058 // definition of Attribute Types from RFC2866 00059 #define D_ATTR_ACCT_STATUS_TYPE 40 00060 #define D_ATTR_ACCT_DELAY_TIME 41 00061 #define D_ATTR_ACCT_INPUT_OCTETS 42 00062 #define D_ATTR_ACCT_OUTPUT_OCTETS 43 00063 #define D_ATTR_ACCT_SESSION_ID 44 00064 #define D_ATTR_ACCT_AUTHENTIC 45 00065 #define D_ATTR_ACCT_SESSION_TIME 46 00066 #define D_ATTR_ACCT_INPUT_PACKETS 47 00067 #define D_ATTR_ACCT_OUTPUT_PACKETS 48 00068 #define D_ATTR_ACCT_TERMINATE_CAUSE 49 00069 #define D_ATTR_ACCT_MULTI_SESSION_ID 50 00070 #define D_ATTR_ACCT_LINK_COUNT 51 00071 00072 #define D_ATTR_MAX_KNOWN_TYPE 63 00073 00074 00075 00076 // definition of Acct-Status-Type attribute values from RFC2866 00077 #define D_ACCT_STATUS_START 1 00078 #define D_ACCT_STATUS_STOP 2 00079 #define D_ACCT_STATUS_INTERIM_UPDATE 3 00080 #define D_ACCT_STATUS_ON 7 00081 #define D_ACCT_STATUS_OFF 8 00082 00083 00084 // max length of User-Password attribute 00085 #define D_USER_PASSWORD_MAX_LENGTH 128 00086 00087 00088 00089 class RadiusPacket; 00090 class RadiusSecret; 00091 00107 class RadiusAttribute 00108 { 00109 public: 00110 00112 RadiusAttribute(); 00113 00115 ~RadiusAttribute(); 00116 00117 00119 void dump(); 00120 00121 00123 00131 void init(RadiusPacket * p_packet, uint16_t p_offset); 00132 00133 00135 RadiusPacket * getPacket(void); 00136 00137 00139 uint16_t getOffset(void); 00140 00141 00143 00145 00148 unsigned char getType(void); 00149 00151 00157 int setType(unsigned char p_type); 00158 00159 00161 const char * getTypeDescription(void); 00162 00163 00165 00174 unsigned char getLength(void); 00175 00177 00183 int setLength(unsigned char p_length); 00184 00185 00187 00190 int isValid(void); 00191 00192 00193 // ------------------------------------------------------------ 00194 // get- and set- methods - access data stored in the attribute 00195 00196 // =========================== 00197 // Regular attributes 00198 // =========================== 00199 00201 00204 uint32_t getNumber(void); 00205 00207 00211 int setNumber(uint32_t p_value); 00212 00213 00215 00218 struct in_addr getIPAddress(void); 00219 00221 00225 int setIPAddress(struct in_addr p_value); 00226 00227 00229 00239 int getString(const char * & p_data, uint16_t & p_length); 00240 00242 00257 int setString(const char * p_data, uint16_t p_length = 0); 00258 00259 00260 // =========================== 00261 // Vendor-Specific attribute 00262 // =========================== 00263 00265 00268 uint32_t getVendorId(void); 00269 00271 00275 int setVendorId(uint32_t p_vendorId); 00276 00278 00294 int getVendorRawString(const char * & p_data, uint16_t & p_length); 00295 00297 00318 int setVendorRawString(const char * p_data, uint16_t p_length = 0); 00319 00320 00322 00325 unsigned char getVendorType(); 00326 00328 00332 int setVendorType(unsigned char p_value); 00333 00334 00336 00339 unsigned char getVendorLength(); 00340 00342 00346 int setVendorLength(unsigned char p_length); 00347 00348 00350 00353 uint32_t getVendorNumber(); 00354 00356 00360 int setVendorNumber(uint32_t p_value); 00361 00362 00364 00367 struct in_addr getVendorIPAddress(); 00368 00370 00374 int setVendorIPAddress(struct in_addr p_address); 00375 00376 00378 00388 int getVendorString(const char * & p_data, uint16_t & p_length); 00389 00391 00409 int setVendorString(const char * p_data, uint16_t p_length = 0); 00410 00411 00412 // =========================== 00413 // User-Password attribute 00414 // =========================== 00415 00417 00436 int getUserPassword(char * p_data, uint16_t & p_length, 00437 RadiusSecret * p_secret = NULL); 00438 00440 00461 int setUserPassword(const char * p_data, uint16_t p_length = 0); 00462 00463 // Encode raw data of User-Password attribute 00464 /* 00465 * We need this function in order to re-encode User-Password attribute with new secret key 00466 * when packet is retransmitted through new connection; application should not use this API. 00467 */ 00468 int encodeUserPassword(const unsigned char * p_data, uint16_t p_length); 00469 00470 00471 // =========================== 00472 // Old-Password attribute 00473 // =========================== 00474 00476 00495 int getOldPassword(char * p_data, uint16_t & p_length, 00496 RadiusSecret * p_secret = NULL); 00497 00499 00524 int setOldPassword(const char * p_data, uint16_t p_length = 0); 00525 00526 // Encode raw data of Old-Password attribute 00527 /* 00528 * We need this function in order to re-encode User-Password attribute with new secret key 00529 * when packet is retransmitted through new connection; application should not use this API. 00530 */ 00531 int encodeOldPassword(const unsigned char * p_data, uint16_t p_length); 00532 00533 00534 // =========================== 00535 // CHAP-Password attribute 00536 // =========================== 00537 00539 00542 unsigned char getChapIdentifier(void); 00543 00545 00549 int setChapIdentifier(unsigned char p_chapId); 00550 00552 00562 int getChapString(const char * & p_data, uint16_t & p_length); 00563 00565 00579 int setChapString(const char * p_data, uint16_t p_length = 0); 00580 00581 00582 00583 private: 00584 00585 // Get pointer to the attribute raw data 00586 unsigned char * getRawData(void); 00587 00588 // Types of attribute data 00589 typedef enum AttributeFormat_e 00590 { 00591 E_ATTR_FORMAT_INTEGER, 00592 E_ATTR_FORMAT_IP_ADDRESS, 00593 E_ATTR_FORMAT_STRING, 00594 E_ATTR_FORMAT_VENDOR_SPECIFIC, 00595 E_ATTR_FORMAT_USER_PASSWORD, 00596 E_ATTR_FORMAT_CHAP_PASSWORD 00597 }; 00598 00599 // Dump attribute in readable text format to the STDOUT 00603 void dump(AttributeFormat_e p_format); 00604 00606 00607 // Pointer to the RADIUS packet that this attribute belongs to 00608 RadiusPacket * m_packet; 00609 00610 // Offset of the attribute inside the RADIUS packet 00611 uint16_t m_offset; 00612 }; 00613 00614 #endif // _RADIUSATTRIBUTE_H__ 00615

Generated on Tue Aug 11 18:35:06 2009 for ace-radius by doxygen 1.3.7-20040704