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 $
41 #include "stg/os_int.h"
43 #include "stg/module_settings.h"
44 #include "stg/notifer.h"
45 #include "stg/user_ips.h"
47 #include "stg/users.h"
48 #include "stg/blowfish.h"
49 #include "stg/rad_packets.h"
51 extern "C" PLUGIN * GetPlugin();
56 //-----------------------------------------------------------------------------
59 RAD_SETTINGS() : port(0) {}
60 virtual ~RAD_SETTINGS() {}
61 const string & GetStrError() const { return errorStr; }
62 int ParseSettings(const MODULE_SETTINGS & s);
63 uint16_t GetPort() const { return port; }
64 const std::string & GetPassword() const { return password; }
65 const std::list<string> & GetAuthServices() const { return authServices; }
66 const std::list<string> & GetAcctServices() const { return acctServices; }
69 int ParseServices(const std::vector<std::string> & str, std::list<std::string> * lst);
74 std::list<std::string> authServices;
75 std::list<std::string> acctServices;
77 //-----------------------------------------------------------------------------
80 std::string serviceType;
82 //-----------------------------------------------------------------------------
83 class RADIUS :public AUTH {
88 void SetUsers(USERS * u);
89 void SetStore(STORE * );
90 void SetStgSettings(const SETTINGS * s);
91 void SetSettings(const MODULE_SETTINGS & s);
96 int Reload() { return 0; }
99 const std::string & GetStrError() const { return errorStr; }
100 const std::string GetVersion() const;
101 uint16_t GetStartPosition() const;
102 uint16_t GetStopPosition() const;
104 int SendMessage(const STG_MSG &, uint32_t) const { return 0; }
107 static void * Run(void *);
111 int Send(const RAD_PACKET & packet, struct sockaddr_in * outerAddr);
112 int RecvData(RAD_PACKET * packet, struct sockaddr_in * outerAddr);
113 int ProcessData(RAD_PACKET * packet);
115 int ProcessAutzPacket(RAD_PACKET * packet);
116 int ProcessAuthPacket(RAD_PACKET * packet);
117 int ProcessPostAuthPacket(RAD_PACKET * packet);
118 int ProcessAcctStartPacket(RAD_PACKET * packet);
119 int ProcessAcctStopPacket(RAD_PACKET * packet);
120 int ProcessAcctUpdatePacket(RAD_PACKET * packet);
121 int ProcessAcctOtherPacket(RAD_PACKET * packet);
123 bool FindUser(USER_PTR * ui, const std::string & login) const;
124 bool CanAuthService(const std::string & svc) const;
125 bool CanAcctService(const std::string & svc) const;
126 bool IsAllowedService(const std::string & svc) const;
128 bool WaitPackets(int sd) const;
130 void PrintServices(const std::list<std::string> & svcs);
132 struct Printer : public unary_function<std::string, void>
134 void operator()(const std::string & line)
136 printfd("radius.cpp", "'%s'\n", line.c_str());
139 struct SPrinter : public unary_function<std::pair<std::string, RAD_SESSION>, void>
141 void operator()(const std::pair<std::string, RAD_SESSION> & it)
143 printfd("radius.cpp", "%s - ('%s', '%s')\n", it.first.c_str(), it.second.userName.c_str(), it.second.serviceType.c_str());
149 mutable std::string errorStr;
150 RAD_SETTINGS radSettings;
151 MODULE_SETTINGS settings;
152 std::list<std::string> authServices;
153 std::list<std::string> acctServices;
154 std::map<std::string, RAD_SESSION> sessions;
160 const SETTINGS * stgSettings;
164 pthread_mutex_t mutex;
171 //-----------------------------------------------------------------------------