]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/other/radius/radius.h
Hide or add proper copy ctor and assignement operator, initialize
[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 <pthread.h>
33
34 #include <cstring>
35 #include <cstdlib>
36 #include <string>
37 #include <list>
38 #include <map>
39 #include <vector>
40
41 #include "stg/os_int.h"
42 #include "stg/auth.h"
43 #include "stg/module_settings.h"
44 #include "stg/notifer.h"
45 #include "stg/user_ips.h"
46 #include "stg/user.h"
47 #include "stg/users.h"
48 #include "stg/blowfish.h"
49 #include "stg/rad_packets.h"
50
51 extern "C" PLUGIN * GetPlugin();
52
53 #define RAD_DEBUG (1)
54
55 class RADIUS;
56 //-----------------------------------------------------------------------------
57 class RAD_SETTINGS {
58 public:
59     RAD_SETTINGS()
60         : port(0), errorStr(), password(),
61           authServices(), acctServices()
62     {}
63     virtual ~RAD_SETTINGS() {}
64     const string & GetStrError() const { return errorStr; }
65     int ParseSettings(const MODULE_SETTINGS & s);
66     uint16_t GetPort() const { return port; }
67     const std::string & GetPassword() const { return password; }
68     const std::list<string> & GetAuthServices() const { return authServices; }
69     const std::list<string> & GetAcctServices() const { return acctServices; }
70
71 private:
72     int ParseServices(const std::vector<std::string> & str, std::list<std::string> * lst);
73
74     uint16_t port;
75     std::string errorStr;
76     std::string password;
77     std::list<std::string> authServices;
78     std::list<std::string> acctServices;
79 };
80 //-----------------------------------------------------------------------------
81 struct RAD_SESSION {
82     RAD_SESSION() : userName(), serviceType() {}
83     std::string userName;
84     std::string serviceType;
85 };
86 //-----------------------------------------------------------------------------
87 class RADIUS :public AUTH {
88 public:
89                         RADIUS();
90     virtual             ~RADIUS() {}
91
92     void                SetUsers(USERS * u) { users = u; }
93     void                SetStore(STORE * s) { store = s; }
94     void                SetStgSettings(const SETTINGS *) {}
95     void                SetSettings(const MODULE_SETTINGS & s) { settings = s; }
96     int                 ParseSettings();
97
98     int                 Start();
99     int                 Stop();
100     int                 Reload() { return 0; }
101     bool                IsRunning() { return isRunning; }
102
103     const std::string & GetStrError() const { return errorStr; }
104     const std::string   GetVersion() const { return "RADIUS data access plugin v 0.6"; }
105     uint16_t            GetStartPosition() const { return 20; }
106     uint16_t            GetStopPosition() const { return 20; }
107
108     int SendMessage(const STG_MSG &, uint32_t) const { return 0; }
109
110 private:
111     RADIUS(const RADIUS & rvalue);
112     RADIUS & operator=(const RADIUS & rvalue);
113
114     static void *       Run(void *);
115     int                 PrepareNet();
116     int                 FinalizeNet();
117
118     int                 Send(const RAD_PACKET & packet, struct sockaddr_in * outerAddr);
119     int                 RecvData(RAD_PACKET * packet, struct sockaddr_in * outerAddr);
120     int                 ProcessData(RAD_PACKET * packet);
121
122     int                 ProcessAutzPacket(RAD_PACKET * packet);
123     int                 ProcessAuthPacket(RAD_PACKET * packet);
124     int                 ProcessPostAuthPacket(RAD_PACKET * packet);
125     int                 ProcessAcctStartPacket(RAD_PACKET * packet);
126     int                 ProcessAcctStopPacket(RAD_PACKET * packet);
127     int                 ProcessAcctUpdatePacket(RAD_PACKET * packet);
128     int                 ProcessAcctOtherPacket(RAD_PACKET * packet);
129
130     bool                FindUser(USER_PTR * ui, const std::string & login) const;
131     bool                CanAuthService(const std::string & svc) const;
132     bool                CanAcctService(const std::string & svc) const;
133     bool                IsAllowedService(const std::string & svc) const;
134
135     void                PrintServices(const std::list<std::string> & svcs);
136
137     struct Printer : public unary_function<std::string, void>
138     { 
139         void operator()(const std::string & line)
140         { 
141             printfd("radius.cpp", "'%s'\n", line.c_str()); 
142         }; 
143     };
144     struct SPrinter : public unary_function<std::pair<std::string, RAD_SESSION>, void>
145     { 
146         void operator()(const std::pair<std::string, RAD_SESSION> & it)
147         { 
148             printfd("radius.cpp", "%s - ('%s', '%s')\n", it.first.c_str(), it.second.userName.c_str(), it.second.serviceType.c_str()); 
149         }; 
150     };
151
152     BLOWFISH_CTX        ctx;
153
154     mutable std::string errorStr;
155     RAD_SETTINGS        radSettings;
156     MODULE_SETTINGS     settings;
157     std::list<std::string> authServices;
158     std::list<std::string> acctServices;
159     std::map<std::string, RAD_SESSION> sessions;
160
161     bool                nonstop;
162     bool                isRunning;
163
164     USERS *             users;
165     const SETTINGS *    stgSettings;
166     const STORE *       store;
167
168     pthread_t           thread;
169     pthread_mutex_t     mutex;
170
171     int                 sock;
172
173     RAD_PACKET          packet;
174
175 };
176 //-----------------------------------------------------------------------------
177
178 #endif