commit 7ac4cc3c226226041ff52b696f950cff624180fc Author: Christoph Haas Date: Wed Apr 29 13:37:43 2015 -0700 Alias patch for ZCP 7.1.4 diff --git a/alias_patch.diff b/alias_patch.diff new file mode 100644 index 0000000..bfa65c4 --- /dev/null +++ b/alias_patch.diff @@ -0,0 +1,387 @@ +diff -ruN --exclude=.svn spooler/alias.cpp ZARAFA_SPOOLER/alias.cpp +--- spooler/alias.cpp 1970-01-01 01:00:00.000000000 +0100 ++++ ZARAFA_SPOOLER/alias.cpp 2013-05-03 00:48:14.339367400 +0200 +@@ -0,0 +1,150 @@ ++/* ++ * Copyright 2013 Christoph Haas ++ * ++ * This program is free software: you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, either version 3 of the License, or ++ * (at your option) any later version. ++ * ++ * This program is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with this program. If not, see . ++ * ++ */ ++ ++#include "alias.h" ++ ++using namespace std; ++ ++extern ECLogger *g_lpLogger; ++ ++Alias::Alias(){ ++ aliasFound = false; ++} ++ ++ ++/* ++ * trim a string ++ */ ++string Alias::trim(const string &strInput, const string &strTrim) { ++ string s = strInput; ++ size_t pos; ++ ++ if (s.empty()) ++ return s; ++ ++ pos = s.find_first_not_of(strTrim); ++ s.erase(0, pos); ++ ++ pos = s.find_last_not_of(strTrim); ++ if (pos != std::string::npos) ++ s.erase(pos + 1, std::string::npos); ++ ++ return s; ++} ++ ++/* ++ * Initializes the multimap ++ * Reads all rules from a space sepereated string ++ * e.g: ++ * 1@1.de 2@2.de ++ * 1@1.de alias1@1.de ++ */ ++void Alias::init(char *filename) { ++ alias_file.open(filename); ++ ++ if(alias_file.is_open()) { ++ string sLine; ++ while (getline(alias_file, sLine)) { ++ istringstream ssLine(sLine); ++ string sPart; ++ string sKey; ++ AliasData data; ++ int count = 0; ++ ++ while ( getline(ssLine, sPart, ';') ) { ++ sPart = trim(sPart, " \t\r\n"); ++ ++ if(count == 0) { ++ sKey = sPart; ++ data.ownerMailAddress = sPart; ++ } else if(count == 1) { ++ remove(sPart.begin(), sPart.end(), ' '); ++ data.aliasMailAddress = sPart; ++ } else if(count == 2) { ++ data.aliasName = sPart; ++ } ++ count++; ++ } ++ ++ if(count == 3) { ++ acl.insert(pair(sKey, data)); ++ } ++ } ++ } else { ++ // the file could not be read ++ g_lpLogger->Log(EC_LOGLEVEL_FATAL, "Aliasfile could not be read! (%s)", filename); ++ } ++} ++ ++/* ++ * check if our acl is empty ++ */ ++bool Alias::isInitialized(void) { ++ return !acl.empty(); // if there is no entry in our accesslist we do not have to check anything... ++} ++ ++/* ++ * check if we have found an alias ++ */ ++bool Alias::foundAlias(void) { ++ return aliasFound; ++} ++ ++/* ++ * try to compare the given mail addresses with our acl ++ * FIXME: aliasing would not work with unicode mailaddresses! ++ */ ++bool Alias::check_mail(wchar_t *e1, wchar_t *e2) { ++ wstring wE1 = wstring(e1); ++ wstring wE2 = wstring(e2); ++ string sE1(wE1.begin(), wE1.end()); ++ string sE2(wE2.begin(), wE2.end()); ++ ++ multimap::iterator mmIterator; ++ ++ if(isInitialized()) { ++ mmIterator = acl.find(sE1); ++ if(mmIterator != acl.end()) { ++ do { ++ if(mmIterator->second.aliasMailAddress.compare(sE2) == 0) { ++ // found positive match in acl ++ aliasFound = true; ++ aliasFoundData = mmIterator->second; ++ return true; ++ } ++ mmIterator++; ++ } while(mmIterator != acl.upper_bound(sE1)); ++ } else { ++ // found noting... ++ aliasFound = false; ++ return false; ++ } ++ } ++ ++ return false; ++} ++ ++wstring Alias::getAliasName() { ++ wstring name( L"" ); // default will be a empty string ++ ++ if(foundAlias()) { ++ name.assign(aliasFoundData.aliasName.begin(), aliasFoundData.aliasName.end()); // works for ascii only ++ } ++ ++ return name; ++} +\ No newline at end of file +diff -ruN --exclude=.svn spooler/alias.h ZARAFA_SPOOLER/alias.h +--- spooler/alias.h 1970-01-01 01:00:00.000000000 +0100 ++++ ZARAFA_SPOOLER/alias.h 2013-04-27 20:54:19.619037700 +0200 +@@ -0,0 +1,52 @@ ++/* ++ * Copyright 2013 Christoph Haas ++ * ++ * This program is free software: you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, either version 3 of the License, or ++ * (at your option) any later version. ++ * ++ * This program is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with this program. If not, see . ++ * ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#include "ECLogger.h" ++ ++using namespace std; ++extern ECLogger *g_lpLogger; ++ ++struct AliasData { ++ string ownerMailAddress; ++ string aliasMailAddress; ++ string aliasName; ++}; ++ ++class Alias { ++ private: ++ ifstream alias_file; ++ multimap acl; ++ bool aliasFound; ++ AliasData aliasFoundData; ++ ++ string trim(const string &strInput, const string &strTrim = " "); ++ bool isInitialized (void); ++ public: ++ Alias(); ++ void init (char *filename); ++ bool foundAlias (void); ++ wstring getAliasName (void); ++ bool check_mail (wchar_t *e1, wchar_t *e2); ++}; +diff -ruN --exclude=.svn spooler/mailer.cpp ZARAFA_SPOOLER/mailer.cpp +--- spooler/mailer.cpp 2013-02-28 17:13:18.000000000 +0100 ++++ ZARAFA_SPOOLER/mailer.cpp 2013-05-03 10:14:51.555584600 +0200 +@@ -50,6 +50,7 @@ + #include "platform.h" + #include "mailer.h" + #include "archive.h" ++#include "alias.h" + + #include + #include +@@ -82,6 +83,7 @@ + + #include + #include ++ + using namespace std; + + extern ECConfig *g_lpConfig; +@@ -1688,7 +1690,7 @@ + */ + HRESULT CheckSendAs(IAddrBook *lpAddrBook, IMsgStore *lpUserStore, IMAPISession *lpAdminSession, ECSender *lpMailer, + ULONG ulOwnerCB, LPENTRYID lpOwnerEID, ULONG ulRepresentCB, LPENTRYID lpRepresentEID, +- bool *lpbAllowed, LPMDB *lppRepStore) ++ bool *lpbAllowed, LPMDB *lppRepStore, Alias *aliasCheck) + { + HRESULT hr = hrSuccess; + bool bAllowed = false; +@@ -1700,10 +1702,9 @@ + LPSPropValue lpRepresentProps = NULL; + SPropValue sSpoofEID = {0}; + ULONG ulCmpRes = 0; +- SizedSPropTagArray(3, sptaIDProps) = { 3, { PR_DISPLAY_NAME_W, PR_EC_SENDAS_USER_ENTRYIDS, PR_DISPLAY_TYPE } }; ++ SizedSPropTagArray(5, sptaIDProps) = { 5, { PR_DISPLAY_NAME_W, PR_EC_SENDAS_USER_ENTRYIDS, PR_DISPLAY_TYPE, PR_SMTP_ADDRESS_W, PR_EMAIL_ADDRESS_W } }; + ULONG cValues = 0; + +- + hr = SMTPToZarafa(lpAddrBook, ulRepresentCB, lpRepresentEID, &sSpoofEID.Value.bin.cb, (LPENTRYID*)&sSpoofEID.Value.bin.lpb); + if (hr != hrSuccess) + hr = ContactToZarafa(lpUserStore, lpAddrBook, ulRepresentCB, lpRepresentEID, &sSpoofEID.Value.bin.cb, (LPENTRYID*)&sSpoofEID.Value.bin.lpb); +@@ -1740,6 +1741,18 @@ + + if (lpRepresentProps[2].ulPropTag != PR_DISPLAY_TYPE) { // Required property for a mailuser object + hr = MAPI_E_NOT_FOUND; ++ ++ // we are checking a simple textfile for matches. ++ // if the users smtp-address is matching we allow the sending ++ if(strcmp(g_lpConfig->GetSetting("use_alias_file"), "yes") == 0) { ++ if(aliasCheck->check_mail(lpOwnerProps[3].Value.lpszW, lpRepresentProps[4].Value.lpszW)) { ++ g_lpLogger->Log(EC_LOGLEVEL_INFO,"alias found in acl: %ls -> %ls", lpOwnerProps[3].Value.lpszW, lpRepresentProps[4].Value.lpszW); ++ hr = hrSuccess; ++ bAllowed = true; ++ }else { ++ g_lpLogger->Log(EC_LOGLEVEL_ERROR,"alias not found in acl: %ls -> %ls", lpOwnerProps[3].Value.lpszW, lpRepresentProps[4].Value.lpszW); ++ } ++ } + goto exit; + } + bHasStore = (lpRepresentProps[2].Value.l == DT_MAILUSER); +@@ -2096,6 +2109,15 @@ + ULONG ulResult = 0; + + ArchiveResult archiveResult; ++ ++ Alias aliasCheck; ++ ++ if(strcmp(g_lpConfig->GetSetting("use_alias_file"), "yes") == 0) { ++ g_lpLogger->Log(EC_LOGLEVEL_INFO,"Alias checking enabled"); ++ aliasCheck.init(g_lpConfig->GetSetting("alias_file")); ++ } else { ++ g_lpLogger->Log(EC_LOGLEVEL_INFO,"Alias checking disabled"); ++ } + + sending_options sopt; + +@@ -2264,7 +2286,7 @@ + if (!bAllowDelegate) { + + hr = CheckSendAs(lpAddrBook, lpUserStore, lpAdminSession, lpMailer, lpPropOwner->Value.bin.cb, (LPENTRYID)lpPropOwner->Value.bin.lpb, +- lpRepEntryID->Value.bin.cb, (LPENTRYID)lpRepEntryID->Value.bin.lpb, &bAllowSendAs, &lpRepStore); ++ lpRepEntryID->Value.bin.cb, (LPENTRYID)lpRepEntryID->Value.bin.lpb, &bAllowSendAs, &lpRepStore, &aliasCheck); + if (hr != hrSuccess) + goto exit; + +@@ -2293,7 +2315,6 @@ + sPropSender[1].Value.LPSZ = _T("ZARAFA"); + sPropSender[2].ulPropTag = PR_SENDER_EMAIL_ADDRESS_W; + sPropSender[2].Value.LPSZ = lpUser->lpszMailAddress; +- + sPropSender[3].ulPropTag = PR_SENDER_ENTRYID; + sPropSender[3].Value.bin.cb = lpUser->sUserId.cb; + sPropSender[3].Value.bin.lpb = lpUser->sUserId.lpb; +diff -ruN --exclude=.svn spooler/Makefile.am ZARAFA_SPOOLER/Makefile.am +--- spooler/Makefile.am 2013-02-28 16:11:57.000000000 +0100 ++++ ZARAFA_SPOOLER/Makefile.am 2013-04-27 13:12:21.888888200 +0200 +@@ -27,7 +27,7 @@ + $(PROG_LIBS) $(PYTHON_LIBS) + + zarafa_dagent_SOURCES = DAgent.cpp rules.cpp rules.h LMTP.cpp LMTP.h archive.cpp archive.h PyMapiPlugin.cpp PyMapiPlugin.h PythonSWIGRuntime.h +-zarafa_spooler_SOURCES = Spooler.cpp mailer.cpp mailer.h archive.cpp archive.h PyMapiPlugin.cpp PyMapiPlugin.h PythonSWIGRuntime.h ++zarafa_spooler_SOURCES = Spooler.cpp mailer.cpp mailer.h archive.cpp archive.h PyMapiPlugin.cpp PyMapiPlugin.h PythonSWIGRuntime.h alias.cpp alias.h + + BUILT_SOURCES=PythonSWIGRuntime.h + +diff -ruN --exclude=.svn spooler/Makefile.in ZARAFA_SPOOLER/Makefile.in +--- spooler/Makefile.in 2013-02-28 16:13:50.000000000 +0100 ++++ ZARAFA_SPOOLER/Makefile.in 2013-04-27 13:28:39.964779800 +0200 +@@ -66,7 +66,7 @@ + am__v_lt_ = $(am__v_lt_$(AM_DEFAULT_VERBOSITY)) + am__v_lt_0 = --silent + am_zarafa_spooler_OBJECTS = Spooler.$(OBJEXT) mailer.$(OBJEXT) \ +- archive.$(OBJEXT) PyMapiPlugin.$(OBJEXT) ++ archive.$(OBJEXT) PyMapiPlugin.$(OBJEXT) alias.$(OBJEXT) + zarafa_spooler_OBJECTS = $(am_zarafa_spooler_OBJECTS) + zarafa_spooler_DEPENDENCIES = ${top_builddir}/inetmapi/libinetmapi.la \ + ${top_builddir}/mapi4linux/src/libmapi.la \ +@@ -384,7 +384,7 @@ + $(PROG_LIBS) $(PYTHON_LIBS) + + zarafa_dagent_SOURCES = DAgent.cpp rules.cpp rules.h LMTP.cpp LMTP.h archive.cpp archive.h PyMapiPlugin.cpp PyMapiPlugin.h PythonSWIGRuntime.h +-zarafa_spooler_SOURCES = Spooler.cpp mailer.cpp mailer.h archive.cpp archive.h PyMapiPlugin.cpp PyMapiPlugin.h PythonSWIGRuntime.h ++zarafa_spooler_SOURCES = Spooler.cpp mailer.cpp mailer.h archive.cpp archive.h PyMapiPlugin.cpp PyMapiPlugin.h PythonSWIGRuntime.h alias.cpp alias.h + BUILT_SOURCES = PythonSWIGRuntime.h + CLEANFILES = PythonSWIGRuntime.h + EXTRA_DIST = PythonSWIGRuntime.h +@@ -485,6 +485,7 @@ + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Spooler.Po@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/archive.Po@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mailer.Po@am__quote@ ++@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/alias.Po@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rules.Po@am__quote@ + + .cpp.o: +diff -ruN --exclude=.svn spooler/README.txt ZARAFA_SPOOLER/README.txt +--- spooler/README.txt 1970-01-01 01:00:00.000000000 +0100 ++++ ZARAFA_SPOOLER/README.txt 2013-04-28 01:20:13.946002000 +0200 +@@ -0,0 +1,26 @@ ++README for the alias extension: ++ ++___GENERAL___: ++ ++The alias checking reads its rules from an ansi textfile. ++Each rule needs to be on a new line. The sender mailaddress, alias mailaddress and alias display name are seperated by a semicolon ++E.g: ++ ++user@zarafa.de;aliasforuser@zarafa.de;Alias Username ++user2@zarafa.com;aliasforuser2@zarafa.de;Alias2 Displayname ++ ++Changes to this file would be applied immediately. ++ ++ ++ ++___CONFIGURATION___: ++ ++The default path for the rule file is: /etc/zarafa/alias.txt ++ ++You can enable/disable the extension in the spooler.cfg file. ++WARNING: you have to restart the patched/recompiled spooler version once before you add the new config parameters! ++ ++New configuration parameters: ++ ++use_alias_file (Values: yes, no ; Default: yes) ++alias_file (Values: Path to alias file ; Default: /etc/zarafa/alias.txt) +\ No newline at end of file +diff -ruN --exclude=.svn spooler/Spooler.cpp ZARAFA_SPOOLER/Spooler.cpp +--- spooler/Spooler.cpp 2013-02-28 17:13:18.000000000 +0100 ++++ ZARAFA_SPOOLER/Spooler.cpp 2013-04-27 13:15:02.096661200 +0200 +@@ -1141,6 +1141,8 @@ + { "plugin_enabled", "yes" }, + { "plugin_path", "/var/lib/zarafa/spooler/plugins" }, + { "plugin_manager_path", "/usr/share/zarafa-spooler/python" }, ++ { "use_alias_file", "yes", CONFIGSETTING_RELOADABLE }, ++ { "alias_file", "/etc/zarafa/alias.txt", CONFIGSETTING_RELOADABLE }, + { NULL, NULL }, + }; + // SIGSEGV backtrace support