| 1 |
// ProxyFirstBasic auth plugin |
| 2 |
// |
| 3 |
// Plugin for use where e2g is behind squid and squid sends user in basic |
| 4 |
// format |
| 5 |
|
| 6 |
// For all support, instructions and copyright go to: |
| 7 |
// http://e2guardian.org/ |
| 8 |
// Released under the GPL v2, with the OpenSSL exception described in the README file. |
| 9 |
|
| 10 |
// INCLUDES |
| 11 |
#ifdef HAVE_CONFIG_H |
| 12 |
#include "e2config.h" |
| 13 |
#endif |
| 14 |
|
| 15 |
#include "../Auth.hpp" |
| 16 |
#include "../OptionContainer.hpp" |
| 17 |
#include "../Logger.hpp" |
| 18 |
|
| 19 |
#include <syslog.h> |
| 20 |
|
| 21 |
extern OptionContainer o; |
| 22 |
|
| 23 |
// DECLARATIONS |
| 24 |
|
| 25 |
// class name is relevant! |
| 26 |
class pf_basic_instance : public AuthPlugin |
| 27 |
{ |
| 28 |
public: |
| 29 |
pf_basic_instance(ConfigVar &definition) |
| 30 |
: AuthPlugin(definition) |
| 31 |
{ |
| 32 |
client_ip_based = false; |
| 33 |
}; |
| 34 |
int identify(Socket &peercon, Socket &proxycon, HTTPHeader &h, std::string &string, bool &is_real_user, auth_rec &authrec,NaughtyFilter &cm); |
| 35 |
int init(void *args); |
| 36 |
}; |
| 37 |
|
| 38 |
// IMPLEMENTATION |
| 39 |
|
| 40 |
// class factory code *MUST* be included in every plugin |
| 41 |
|
| 42 |
AuthPlugin *PF_basic_create(ConfigVar &definition) |
| 43 |
{ |
| 44 |
return new pf_basic_instance(definition); |
| 45 |
} |
| 46 |
|
| 47 |
// end of Class factory |
| 48 |
|
| 49 |
// proxy auth header username extraction |
| 50 |
int pf_basic_instance::identify(Socket &peercon, Socket &proxycon, HTTPHeader &h, std::string &string, bool &is_real_user, auth_rec &authrec,NaughtyFilter &cm) |
| 51 |
{ |
| 52 |
// don't match for non-basic auth types |
| 53 |
String t(h.getAuthType()); |
| 54 |
t.toLower(); |
| 55 |
if (t != "basic") |
| 56 |
return E2AUTH_NOMATCH; |
| 57 |
// extract username |
| 58 |
string = h.getAuthData(); |
| 59 |
if (string.length() > 0) { |
| 60 |
string.resize(string.find_first_of(':')); |
| 61 |
authrec.user_name = string; |
| 62 |
authrec.user_source = "pf_basic"; |
| 63 |
is_real_user = true; |
| 64 |
return E2AUTH_OK; |
| 65 |
} |
| 66 |
return E2AUTH_NOMATCH; |
| 67 |
} |
| 68 |
|
| 69 |
int pf_basic_instance::init(void *args) |
| 70 |
{ |
| 71 |
StoryBoardOptions::SB_entry_map sen; |
| 72 |
sen.entry_function = cv["story_function"]; |
| 73 |
if (sen.entry_function.length() > 0) { |
| 74 |
sen.entry_id = ENT_STORYA_AUTH_PF_BASIC; |
| 75 |
story_entry = sen.entry_id; |
| 76 |
o.story.auth_entry_dq.push_back(sen); |
| 77 |
read_def_fg(); |
| 78 |
return 0; |
| 79 |
} else { |
| 80 |
E2LOGGER_error("No story_function defined in proxy auth plugin config"); |
| 81 |
return -1; |
| 82 |
} |
| 83 |
} |
| 84 |
|