]> git.stg.codes - stg.git/blob - stargazer/plugins/other/radius/radius.h
Port to CMake, get rid of os_int.h.
[stg.git] / 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 #ifndef __STG_RADIUS_H__
22 #define __STG_RADIUS_H__
23
24 #include "stg/auth.h"
25 #include "stg/module_settings.h"
26 #include "stg/logger.h"
27
28 #include "config.h"
29 #include "conn.h"
30
31 #include <string>
32 #include <deque>
33 #include <set>
34 #include <cstdint>
35
36 #include <pthread.h>
37 #include <unistd.h>
38 #include <sys/select.h>
39 #include <sys/types.h>
40
41 extern "C" PLUGIN * GetPlugin();
42
43 class STORE;
44 class USERS;
45
46 class RADIUS : public AUTH {
47 public:
48     RADIUS();
49     virtual ~RADIUS() {}
50
51     void SetUsers(USERS* u) { m_users = u; }
52     void SetStore(STORE* s) { m_store = s; }
53     void SetStgSettings(const SETTINGS*) {}
54     void SetSettings(const MODULE_SETTINGS& s) { m_settings = s; }
55     int ParseSettings();
56
57     int Start();
58     int Stop();
59     int Reload(const MODULE_SETTINGS & /*ms*/) { return 0; }
60     bool IsRunning() { return m_running; }
61
62     const std::string& GetStrError() const { return m_error; }
63     std::string GetVersion() const { return "RADIUS data access plugin v. 2.0"; }
64     uint16_t GetStartPosition() const { return 30; }
65     uint16_t GetStopPosition() const { return 30; }
66
67     int SendMessage(const STG_MSG&, uint32_t) const { return 0; }
68
69     void authorize(const USER& user);
70     void unauthorize(const std::string& login, const std::string& reason);
71
72 private:
73     RADIUS(const RADIUS & rvalue);
74     RADIUS & operator=(const RADIUS & rvalue);
75
76     static void* run(void*);
77
78     bool reconnect();
79     int createUNIX() const;
80     int createTCP() const;
81     void runImpl();
82     int maxFD() const;
83     void buildFDSet(fd_set & fds) const;
84     void cleanupConns();
85     void handleEvents(const fd_set & fds);
86     void acceptConnection();
87     void acceptUNIX();
88     void acceptTCP();
89
90     mutable std::string m_error;
91     STG::Config m_config;
92
93     MODULE_SETTINGS m_settings;
94
95     bool m_running;
96     bool m_stopped;
97
98     USERS* m_users;
99     const STORE* m_store;
100
101     int m_listenSocket;
102     std::deque<STG::Conn*> m_conns;
103     std::set<std::string> m_logins;
104
105     pthread_t m_thread;
106
107     PLUGIN_LOGGER m_logger;
108 };
109
110 #endif