Debian Codegraph @

src/authplugins/port.cpp

raw
1 // listening PORT auth plugin
2
3 // This program is free software; you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation; either version 2 of the License, or
6 // (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
17 // INCLUDES
18
19 #ifdef HAVE_CONFIG_H
20 #include "e2config.h"
21 #endif
22
23 #include "../Auth.hpp"
24 #include "../RegExp.hpp"
25 #include "../OptionContainer.hpp"
26 #include "../Logger.hpp"
27
28 #include <algorithm>
29 #include <unistd.h>
30 #include <iostream>
31 #include <fstream>
32
33 // GLOBALS
34
35 extern OptionContainer o;
36
37 // DECLARATIONS
38
39 // structs linking ports to filter groups
40 struct portstruct {
41 unsigned long int port;
42 int group;
43 };
44
45 // class name is relevant!
46 class portinstance : public AuthPlugin
47 {
48 public:
49 // keep credentials for the whole of a connection - IP isn't going to change.
50 // not quite true - what about downstream proxy with x-forwarded-for?
51 portinstance(ConfigVar &definition)
52 : AuthPlugin(definition)
53 {
54 is_connection_based = true;
55 client_ip_based = false;
56 }
57
58 int identify(Socket &peercon, Socket &proxycon, HTTPHeader &h, std::string &string, bool &is_real_user,auth_rec &authrec,NaughtyFilter &cm);
59 //int determineGroup(std::string &user, int &fg, ListContainer &uglc);
60
61 int init(void *args);
62 int quit();
63
64 private:
65 std::deque<portstruct> ipportlist;
66
67 int readIPMelangeList(const char *filename);
68 int searchList(int a, int s, const unsigned int &ip);
69 int inList(const int &ip);
70 };
71
72 // IMPLEMENTATION
73
74 // class factory code *MUST* be included in every plugin
75
76 AuthPlugin *portcreate(ConfigVar &definition)
77 {
78 return new portinstance(definition);
79 }
80
81 // end of Class factory
82
83 //
84 //
85 // Standard plugin funcs
86 //
87 //
88
89 // plugin quit - clear IP, port & range lists
90 int portinstance::quit()
91 {
92 ipportlist.clear();
93 return 0;
94 }
95
96 // plugin init - read in ip melange list
97 int portinstance::init(void *args)
98 {
99 AuthPlugin::init(args);
100 StoryBoardOptions::SB_entry_map sen;
101 sen.entry_function = cv["story_function"];
102 if (sen.entry_function.length() > 0) {
103 sen.entry_id = ENT_STORYA_AUTH_PORT;
104 story_entry = sen.entry_id;
105 o.story.auth_entry_dq.push_back(sen);
106 return 0;
107 } else {
108 E2LOGGER_error("No story_function defined in port auth plugin config");
109 return -1;
110 }
111 }
112
113 // Port-based filter group determination
114 // never actually return NOUSER from this, because we don't actually look in the portgroupslist.
115 // NOUSER stops ConnectionHandler from querying subsequent plugins.
116 int portinstance::identify(Socket &peercon, Socket &proxycon, HTTPHeader &h, std::string &string, bool &is_real_user,auth_rec &authrec,NaughtyFilter &cm)
117 {
118 // we don't get usernames out of this plugin, just a filter group
119 // for now, use the dest Port as the username
120 String s(peercon.getPort());
121 string = s;
122 authrec.user_name = string;
123 authrec.user_source = "port";
124 is_real_user = false;
125 return E2AUTH_OK;
126 }
127