00001 /* 00002 * RadiusClass -- An C++-Library for radius authentication 00003 * and accounting. 00004 * 00005 * Copyright (C) 2005 EWE TEL GmbH/Ralf Luebben <ralfluebben@gmx.de> 00006 * 00007 * This program is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License version 2 00009 * as published by the Free Software Foundation. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program (see the file COPYING included with this 00018 * distribution); if not, write to the Free Software Foundation, Inc., 00019 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 */ 00021 00022 #ifndef _RADIUSPACKET_H_ 00023 #define _RADIUSPACKET_H_ 00024 00025 #include <stdio.h> 00026 #include <openssl/md5.h> 00027 #include <stdlib.h> 00028 #include <string.h> 00029 #include <sys/types.h> 00030 #include <sys/socket.h> 00031 #include <netinet/in.h> 00032 #include <arpa/inet.h> 00033 #include <netdb.h> 00034 #include <errno.h> 00035 #include <unistd.h> 00036 #include <fcntl.h> 00037 #include <sys/select.h> 00038 #include <time.h> 00039 #include <iostream> 00040 00041 #include "error.h" 00042 #include "radius.h" 00043 #include "RadiusAttribute.h" 00044 #include "RadiusServer.h" 00045 00046 #include <map> 00047 #include <list> 00048 #include <utility> 00049 00050 using namespace std; 00051 using std::multimap; 00052 00055 class RadiusPacket 00056 { 00057 private: 00058 00059 multimap<Octet,RadiusAttribute> attribs; 00060 int sock; 00061 Octet code; 00062 Octet identifier; 00063 unsigned short int length; 00064 Octet authenticator[RADIUS_PACKET_AUTHENTICATOR_LEN]; 00069 Octet *sendbuffer; 00070 int sendbufferlen; 00071 Octet *recvbuffer; 00072 int recvbufferlen; 00073 void calcacctdigest(const char *secret); 00076 //private functions 00077 void getRandom(int len, Octet *num); 00078 int shapeRadiusPacket(const char *); 00079 int unShapeRadiusPacket(void); 00080 00081 public: 00082 RadiusPacket(void); 00083 ~RadiusPacket(void); 00084 RadiusPacket(Octet code); 00085 00086 int addRadiusAttribute(RadiusAttribute *); 00087 00088 void dumpRadiusPacket(void); 00089 void dumpShapedRadiusPacket(void); 00090 00091 int radiusSend(list<RadiusServer>::iterator); 00092 int radiusReceive(list<RadiusServer> *); 00093 00094 int getRadiusAttribNumber(void); 00095 char * getAuthenticator(void); 00096 00097 int getCode(void); 00098 00099 pair<multimap<Octet,RadiusAttribute>::iterator,multimap<Octet,RadiusAttribute>::iterator> findAttributes(int type); 00100 }; 00101 00102 00103 00104 00105 00106 #endif //_RADIUSPACKET_H_