2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Author : Maxim Mamontov <faust@stargazer.dp.ua>
22 * Radius data access plugin for Stargazer
25 * $Date: 2009/12/13 14:17:13 $
39 #include "base_auth.h"
42 #include "../../../user.h"
43 #include "../../../users.h"
45 #include "rad_packets.h"
49 extern "C" BASE_PLUGIN * GetPlugin();
54 //-----------------------------------------------------------------------------
58 virtual ~RAD_SETTINGS(){};
59 const string& GetStrError() const { return errorStr; };
60 int ParseSettings(const MODULE_SETTINGS & s);
61 uint16_t GetPort() const;
62 uint32_t GetServerIP() const;
63 int GetPassword(string * password) const;
64 int GetAuthServices(list<string> * svcs) const;
65 int GetAcctServices(list<string> * svcs) const;
68 int ParseIntInRange(const string & str, int min, int max, int * val);
69 int ParseIP(const string & str, uint32_t * routerIP);
70 int ParseServices(const vector<string> & str, list<string> * lst);
76 list<string> authServices;
77 list<string> acctServices;
79 //-----------------------------------------------------------------------------
82 std::string serviceType;
84 //-----------------------------------------------------------------------------
85 class RADIUS :public BASE_AUTH
91 void SetUsers(USERS * u);
92 void SetTariffs(TARIFFS *){};
93 void SetAdmins(ADMINS *){};
94 void SetTraffcounter(TRAFFCOUNTER *){};
95 void SetStore(BASE_STORE * );
96 void SetStgSettings(const SETTINGS * s);
97 void SetSettings(const MODULE_SETTINGS & s);
102 int Reload() { return 0; };
105 const string & GetStrError() const { return errorStr; };
106 const string GetVersion() const;
107 uint16_t GetStartPosition() const;
108 uint16_t GetStopPosition() const;
110 int SendMessage(const STG_MSG &, uint32_t) const { return 0; };
113 static void * Run(void *);
117 void InitEncrypt(BLOWFISH_CTX * ctx, const string & password);
118 void Decrypt(BLOWFISH_CTX * ctx, char * dst, const char * src, int len8);
119 void Encrypt(BLOWFISH_CTX * ctx, char * dst, const char * src, int len8);
121 int Send(const RAD_PACKET & packet);
122 int RecvData(RAD_PACKET * packet);
123 int ProcessData(RAD_PACKET * packet);
125 int ProcessAutzPacket(RAD_PACKET * packet);
126 int ProcessAuthPacket(RAD_PACKET * packet);
127 int ProcessPostAuthPacket(RAD_PACKET * packet);
128 int ProcessAcctStartPacket(RAD_PACKET * packet);
129 int ProcessAcctStopPacket(RAD_PACKET * packet);
130 int ProcessAcctUpdatePacket(RAD_PACKET * packet);
131 int ProcessAcctOtherPacket(RAD_PACKET * packet);
133 bool FindUser(user_iter * ui, const std::string & login) const;
134 bool CanAuthService(const std::string & svc) const;
135 bool CanAcctService(const std::string & svc) const;
136 bool IsAllowedService(const std::string & svc) const;
138 void SetUserNotifier(user_iter u);
139 void UnSetUserNotifier(user_iter u);
141 bool WaitPackets(int sd) const;
143 void PrintServices(const std::list<std::string> & svcs);
145 struct Printer : public unary_function<std::string, void>
147 void operator()(const std::string & line)
149 printfd("radius.cpp", "'%s'\n", line.c_str());
152 struct SPrinter : public unary_function<std::pair<std::string, RAD_SESSION>, void>
154 void operator()(const std::pair<std::string, RAD_SESSION> & it)
156 printfd("radius.cpp", "%s - ('%s', '%s')\n", it.first.c_str(), it.second.userName.c_str(), it.second.serviceType.c_str());
162 mutable string errorStr;
163 RAD_SETTINGS radSettings;
164 MODULE_SETTINGS settings;
165 list<string> authServices;
166 list<string> acctServices;
167 map<string, RAD_SESSION> sessions;
174 const SETTINGS * stgSettings;
175 const BASE_STORE * store;
178 pthread_mutex_t mutex;
181 struct sockaddr_in inAddr;
185 struct sockaddr_in outerAddr;
186 socklen_t outerAddrLen;
191 //-----------------------------------------------------------------------------