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