#include #include #include #include "Database.hpp" #include "PostfixPolicyProtocol.hpp" #include "ChildProt.hpp" #include "log.hpp" using namespace std; int main() { clog.rdbuf(new Log("childProt", LOG_MAIL)); string msg; string result; PostfixPolicyProtocol postfixPolicyProtocol; try { postfixPolicyProtocol.processInput(); msg = "sender=" + postfixPolicyProtocol.getSender() + "recipient=" + postfixPolicyProtocol.getRecipient(); DatabaseHandle databaseHandle(DATABASE_FILE); string stmtChildTxt = "SELECT id, delegate FROM child_v WHERE address = '" + postfixPolicyProtocol.getRecipient() + "'"; PreparedStatement pStmtChild = databaseHandle.prepareStatement(stmtChildTxt); result_t child = pStmtChild.next(); if (! child.empty()) { string sender = postfixPolicyProtocol.getSender(); string::size_type atIdx = sender.find('@'); string domain; if (string::npos != atIdx) { domain = sender.substr(atIdx); } else { domain = "UNKNOWN"; } string stmtWhitelistTxt = "SELECT * FROM whitelist_t WHERE child = '" + child["id"] + "' AND (address = '" + sender + "' OR address = '" + domain + "')"; PreparedStatement pStmtWhitelist = databaseHandle.prepareStatement(stmtWhitelistTxt); result_t whitelistEntry = pStmtWhitelist.next(); if (whitelistEntry.empty()) { msg += ", not found, redirect to " + child["delegate"]; result = "REDIRECT " + child["delegate"]; } else { msg += ", found, pass by"; result = "OK"; } } else { msg += ", ignored"; result = "OK"; } } catch (InvalidAddressTuple& iat) { msg = "InvalidAddressTuple"; result = "OK"; } catch (DatabaseError &de) { msg = "DatabaseError"; result = "OK"; } clog << msg << endl; postfixPolicyProtocol.sendResult(result); }