]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/other/radius/radius.h
В плагине радиуса убраны не используемые переменные и члены класса, а
[stg.git] / projects / stargazer / plugins / other / radius / radius.h
1 /*
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.
6  *
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.
11  *
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
15  */
16
17 /*
18  *    Author : Maxim Mamontov <faust@stargazer.dp.ua>
19  */
20
21 /*
22  *  Radius data access plugin for Stargazer
23  *
24  *  $Revision: 1.10 $
25  *  $Date: 2009/12/13 14:17:13 $
26  *
27  */
28
29 #ifndef RADIUS_H
30 #define RADIUS_H
31
32 #include <string>
33 #include <list>
34 #include <pthread.h>
35 #include <string.h>
36 #include <stdlib.h>
37
38 #include "os_int.h"
39 #include "base_auth.h"
40 #include "notifer.h"
41 #include "user_ips.h"
42 #include "../../../user.h"
43 #include "../../../users.h"
44 #include "blowfish.h"
45 #include "rad_packets.h"
46
47 using namespace std;
48
49 extern "C" BASE_PLUGIN * GetPlugin();
50
51 #define RAD_DEBUG (1)
52
53 class RADIUS;
54 //-----------------------------------------------------------------------------
55 class RAD_SETTINGS
56 {
57 public:
58     virtual         ~RAD_SETTINGS(){};
59     const string&   GetStrError() const { return errorStr; };
60     int             ParseSettings(const MODULE_SETTINGS & s);
61     uint16_t        GetPort() const;
62     int             GetPassword(string * password) const;
63     int             GetAuthServices(list<string> * svcs) const;
64     int             GetAcctServices(list<string> * svcs) const;
65
66 private:
67     int             ParseIntInRange(const string & str, int min, int max, int * val);
68     int             ParseIP(const string & str, uint32_t * routerIP);
69     int             ParseServices(const vector<string> & str, list<string> * lst);
70
71     uint16_t            port;
72     string              errorStr;
73     string              password;
74     list<string>        authServices;
75     list<string>        acctServices;
76 };
77 //-----------------------------------------------------------------------------
78 struct RAD_SESSION {
79     std::string userName;
80     std::string serviceType;
81 };
82 //-----------------------------------------------------------------------------
83 class RADIUS :public BASE_AUTH
84 {
85 public:
86                         RADIUS();
87     virtual             ~RADIUS(){};
88
89     void                SetUsers(USERS * u);
90     void                SetTariffs(TARIFFS *){};
91     void                SetAdmins(ADMINS *){};
92     void                SetTraffcounter(TRAFFCOUNTER *){};
93     void                SetStore(BASE_STORE * );
94     void                SetStgSettings(const SETTINGS * s);
95     void                SetSettings(const MODULE_SETTINGS & s);
96     int                 ParseSettings();
97
98     int                 Start();
99     int                 Stop();
100     int                 Reload() { return 0; };
101     bool                IsRunning();
102
103     const string      & GetStrError() const { return errorStr; };
104     const string        GetVersion() const;
105     uint16_t            GetStartPosition() const;
106     uint16_t            GetStopPosition() const;
107
108     int SendMessage(const STG_MSG &, uint32_t) const { return 0; };
109
110 private:
111     static void *       Run(void *);
112     int                 PrepareNet();
113     int                 FinalizeNet();
114
115     void                InitEncrypt(BLOWFISH_CTX * ctx, const string & password);
116     void                Decrypt(BLOWFISH_CTX * ctx, char * dst, const char * src, int len8);
117     void                Encrypt(BLOWFISH_CTX * ctx, char * dst, const char * src, int len8);
118
119     int                 Send(const RAD_PACKET & packet, struct sockaddr_in * outerAddr);
120     int                 RecvData(RAD_PACKET * packet, struct sockaddr_in * outerAddr);
121     int                 ProcessData(RAD_PACKET * packet);
122
123     int                 ProcessAutzPacket(RAD_PACKET * packet);
124     int                 ProcessAuthPacket(RAD_PACKET * packet);
125     int                 ProcessPostAuthPacket(RAD_PACKET * packet);
126     int                 ProcessAcctStartPacket(RAD_PACKET * packet);
127     int                 ProcessAcctStopPacket(RAD_PACKET * packet);
128     int                 ProcessAcctUpdatePacket(RAD_PACKET * packet);
129     int                 ProcessAcctOtherPacket(RAD_PACKET * packet);
130
131     bool                FindUser(user_iter * ui, const std::string & login) const;
132     bool                CanAuthService(const std::string & svc) const;
133     bool                CanAcctService(const std::string & svc) const;
134     bool                IsAllowedService(const std::string & svc) const;
135
136     void                SetUserNotifier(user_iter u);
137     void                UnSetUserNotifier(user_iter u);
138
139     bool                WaitPackets(int sd) const;
140
141     void                PrintServices(const std::list<std::string> & svcs);
142
143     struct Printer : public unary_function<std::string, void>
144     { 
145         void operator()(const std::string & line)
146         { 
147             printfd("radius.cpp", "'%s'\n", line.c_str()); 
148         }; 
149     };
150     struct SPrinter : public unary_function<std::pair<std::string, RAD_SESSION>, void>
151     { 
152         void operator()(const std::pair<std::string, RAD_SESSION> & it)
153         { 
154             printfd("radius.cpp", "%s - ('%s', '%s')\n", it.first.c_str(), it.second.userName.c_str(), it.second.serviceType.c_str()); 
155         }; 
156     };
157
158     BLOWFISH_CTX        ctx;
159
160     mutable string      errorStr;
161     RAD_SETTINGS        radSettings;
162     MODULE_SETTINGS     settings;
163     list<string>        authServices;
164     list<string>        acctServices;
165     map<string, RAD_SESSION> sessions;
166
167     bool                nonstop;
168     bool                isRunning;
169
170     USERS *             users;
171     const SETTINGS *    stgSettings;
172     const BASE_STORE *  store;
173
174     pthread_t           thread;
175     pthread_mutex_t     mutex;
176
177     int                 sock;
178
179     RAD_PACKET          packet;
180
181 };
182 //-----------------------------------------------------------------------------
183
184 #endif