Debian Codegraph @

src/Auth.hpp

raw
1 // AuthPlugin class - interface for plugins for retrieving client usernames
2 // and filter group membership
3
4 // For all support, instructions and copyright go to:
5 // http://e2guardian.org/
6 // Released under the GPL v2, with the OpenSSL exception described in the README file.
7
8 #ifndef __HPP_AUTH
9 #define __HPP_AUTH
10
11 // INCLUDES
12
13 #include "Plugin.hpp"
14 #include "ConfigVar.hpp"
15 #include "HTTPHeader.hpp"
16 #include "ListContainer.hpp"
17 #include "LOptionContainer.hpp"
18 #include <deque>
19
20 // DEFINES
21
22 // success
23 #define E2AUTH_OK 0
24
25 // auth info required for this method not found (continue querying other plugins)
26 #define E2AUTH_NOMATCH 2
27
28 // auth info found, but no such user in filtergroupslist (stop querying plugins - use this code with caution!)
29 #define E2AUTH_NOUSER 3
30
31 // auth info found, but no such user in group for this plugin stop querying plugins - use this code with caution!)
32 #define E2AUTH_NOGROUP 3
33
34 // redirect the user to a login page
35 #define E2AUTH_REDIRECT 4
36
37 // allow access to http[s] based auth system, but with no persitance
38 #define E2AUTH_OK_NOPERSIST 9
39
40 // auth plugin found a partial or incomplet answer (Eg NTLM): just break ident loop for this request
41 #define E2AUTH_NOIDENTPART 5
42
43 // identify returns this if it has determined both user and group (and added group id to authrec)
44 #define E2AUTH_OK_GOT_GROUP 10
45
46 // This means plugin has sent 407 to client, so no further processing of this request
47 #define E2AUTH_407_SENT 11
48
49 // identify returns this if it has determined both user and group (and added group name to authrec)
50 #define E2AUTH_OK_GOT_GROUP_NAME 12
51
52 // any < 0 return code signifies error
53
54 // auth_rec structure for use by storyboarding/extended logging
55 struct auth_rec {
56 String user_name;
57 bool is_authed;
58 int filter_group;
59 String fg_name;
60 bool is_proxy = false;
61 bool is_transparent = false;
62 bool is_icap = false;
63 bool is_tlsproxy = false;
64 String user_source;
65 String group_source;
66 };
67
68 // DECLARATIONS
69
70 class AuthPlugin : public Plugin
71 {
72 public:
73 AuthPlugin(ConfigVar &definition);
74
75 virtual int init(void *args);
76 virtual int quit();
77
78 // determine the username
79 // return one of these codes:
80 // OK - success, username in string
81 // REDIRECT - redirect user to URL in string
82 // NOMATCH - did not find the necessary info in the request (query remaining plugins)
83 // any < 0 - error
84 virtual int identify(Socket &peercon, Socket &proxycon, HTTPHeader &h, std::string &string, bool &is_real_user, auth_rec &authrec,NaughtyFilter &cm) = 0;
85
86 // determine what filter group the given username is in
87 // queries the standard filtergroupslist
88 // return one of these codes:
89 // OK - success, group no. in fg
90 // NOMATCH - did not find a group for this user (query remaining plugins)
91 // NOUSER - did not find a group for this user (do not query remaining plugins)
92 // any < 0 - error
93 virtual int determineGroup(std::string &user, int &fg,StoryBoard &story,NaughtyFilter &cm);
94
95 // is this a connection-based auth type, i.e. assume all subsequent requests on the pconn are from the same user?
96 bool is_connection_based;
97
98 std::deque<int> portlist; // holds list of ports this plugin is valid for
99 void read_ports();
100 bool port_matched(int &port);
101
102
103 int default_fg = 0;
104 int tran_default_fg = 0;
105 int get_default(bool is_transparent);
106
107 void read_def_fg();
108
109 bool client_ip_based;
110
111 int story_entry = 0;
112
113 String getPluginName();
114 virtual bool isTransparent()
115 {
116 return false;
117 };
118 virtual bool isSSL()
119 {
120 return false;
121 };
122
123 protected:
124 ConfigVar cv;
125 String bearer_secret;
126 String bearer_realm;
127
128 private:
129 String pluginName;
130 };
131
132 // class factory functions for Auth plugins
133 typedef AuthPlugin *authcreate_t(ConfigVar &);
134
135 // Return an instance of the plugin defined in the given configuration file
136 AuthPlugin *auth_plugin_load(const char *pluginConfigPath);
137
138 #endif