]> git.stg.codes - stg.git/blob - stargazer/plugins/other/radius/config.h
Public interfaces: part 1
[stg.git] / stargazer / plugins / other / radius / config.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/module_settings.h"
24
25 #include <map>
26 #include <string>
27 #include <cstdint>
28
29 #include <unistd.h> // uid_t, gid_t
30 #include <sys/stat.h> // mode_t
31
32 namespace STG
33 {
34
35 struct User;
36
37 struct Config
38 {
39     typedef std::map<std::string, std::string> Pairs;
40     typedef std::pair<std::string, std::string> Pair;
41     enum Type { UNIX, TCP };
42     enum ReturnCode
43     {
44         REJECT,   // Reject the request immediately.
45         FAIL,     // Module failed.
46         OK,       // Module is OK, continue.
47         HANDLED,  // The request is handled, no further handling.
48         INVALID,  // The request is invalud.
49         USERLOCK, // Reject the request, user is locked.
50         NOTFOUND, // User not found.
51         NOOP,     // Module performed no action.
52         UPDATED   // Module sends some updates.
53     };
54
55     class Authorize
56     {
57         public:
58             Authorize() : m_auth(false) {}
59             Authorize(const Pairs& cond) : m_auth(true), m_cond(cond) {}
60
61             bool check(const User& user, const Pairs& radiusData) const;
62             bool exists() const { return m_auth; }
63         private:
64             bool m_auth;
65             Pairs m_cond;
66     };
67
68     struct Section
69     {
70         Section() = default;
71         Section(const Pairs& ma, const Pairs& mo, const Pairs& re, ReturnCode code, const Authorize& auth)
72             : match(ma), modify(mo), reply(re), returnCode(code), authorize(auth) {}
73         Pairs match;
74         Pairs modify;
75         Pairs reply;
76         ReturnCode returnCode;
77         Authorize authorize;
78     };
79
80     Config() = default;
81     Config(const ModuleSettings& settings);
82
83     Section autz;
84     Section auth;
85     Section postauth;
86     Section preacct;
87     Section acct;
88
89     bool verbose;
90
91     std::string address;
92     Type connectionType;
93     std::string bindAddress;
94     std::string portStr;
95     uint16_t port;
96     std::string key;
97
98     uid_t sockUID;
99     gid_t sockGID;
100     mode_t sockMode;
101 };
102
103 } // namespace STG