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