diff -ruN '--exclude=.svn' orig/zarafa-7.2.0/spooler/alias.cpp zarafa-7.2.0/spooler/alias.cpp --- orig/zarafa-7.2.0/spooler/alias.cpp 1969-12-31 19:00:00.000000000 -0500 +++ zarafa-7.2.0/spooler/alias.cpp 2015-03-09 13:16:49.487933628 -0400 @@ -0,0 +1,150 @@ +/* + * Copyright 2015 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; +} diff -ruN '--exclude=.svn' orig/zarafa-7.2.0/spooler/alias.h zarafa-7.2.0/spooler/alias.h --- orig/zarafa-7.2.0/spooler/alias.h 1969-12-31 19:00:00.000000000 -0500 +++ zarafa-7.2.0/spooler/alias.h 2015-03-09 13:13:50.543932736 -0400 @@ -0,0 +1,52 @@ +/* + * Copyright 2015 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' orig/zarafa-7.2.0/spooler/mailer.cpp zarafa-7.2.0/spooler/mailer.cpp --- orig/zarafa-7.2.0/spooler/mailer.cpp 2015-03-05 10:54:04.000000000 -0500 +++ zarafa-7.2.0/spooler/mailer.cpp 2015-03-09 13:39:14.851941692 -0400 @@ -45,6 +45,7 @@ #include "platform.h" #include "mailer.h" #include "archive.h" +#include "alias.h" #include #include @@ -1839,7 +1840,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; @@ -1851,7 +1852,7 @@ 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; @@ -1901,7 +1902,19 @@ if (lpRepresentProps[2].ulPropTag != PR_DISPLAY_TYPE) { // Required property for a mailuser object hr = MAPI_E_NOT_FOUND; - g_lpLogger->Log(EC_LOGLEVEL_NOTICE, "CheckSendAs(): PR_DISPLAY_TYPE missing %x", hr); + // 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); + } + } else { + g_lpLogger->Log(EC_LOGLEVEL_NOTICE, "CheckSendAs(): PR_DISPLAY_TYPE missing %x", hr); + } goto exit; } @@ -2271,6 +2284,15 @@ 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; imopt_default_sending_options(&sopt); @@ -2438,7 +2460,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; diff -ruN '--exclude=.svn' orig/zarafa-7.2.0/spooler/Makefile.am zarafa-7.2.0/spooler/Makefile.am --- orig/zarafa-7.2.0/spooler/Makefile.am 2015-03-05 10:52:42.000000000 -0500 +++ zarafa-7.2.0/spooler/Makefile.am 2015-03-09 13:40:47.467933464 -0400 @@ -28,7 +28,7 @@ $(PROG_LIBS) $(PYTHON_LIBS) $(XML2_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' orig/zarafa-7.2.0/spooler/Makefile.in zarafa-7.2.0/spooler/Makefile.in --- orig/zarafa-7.2.0/spooler/Makefile.in 2015-03-05 10:52:53.000000000 -0500 +++ zarafa-7.2.0/spooler/Makefile.in 2015-03-09 13:43:20.163932624 -0400 @@ -83,7 +83,7 @@ am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) 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 \ @@ -410,7 +410,7 @@ $(PROG_LIBS) $(PYTHON_LIBS) $(XML2_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 @@ -514,6 +514,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' orig/zarafa-7.2.0/spooler/README.txt zarafa-7.2.0/spooler/README.txt --- orig/zarafa-7.2.0/spooler/README.txt 1969-12-31 19:00:00.000000000 -0500 +++ zarafa-7.2.0/spooler/README.txt 2015-03-09 13:58:45.579943321 -0400 @@ -0,0 +1,74 @@ +README for the alias extension: + +___PREPARATION___: + +First read: http://www.zarafa.com/wiki/index.php/Compiling_source_code + +For Debian 7 and ZCP 7.2 you can read my blog post: https://blog.sprinternet.at/2015/03/zarafa-zcp-7-2-auf-debian-wheezy-kompilieren/ + + +___BUILDING___: + +cd path/to/zarafa-source +./configure --enable-unicode --enable-release --enable-python --prefix=/usr --with-gsoap-prefix=/opt/zarafa/ --with-ical-prefix=/opt/zarafa/ --with-vmime-prefix=/opt/zarafa/ +make +checkinstall + + +___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. +Info: Display name is currentl not in use. + + +___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) diff -ruN '--exclude=.svn' orig/zarafa-7.2.0/spooler/Spooler.cpp zarafa-7.2.0/spooler/Spooler.cpp --- orig/zarafa-7.2.0/spooler/Spooler.cpp 2015-03-05 10:54:04.000000000 -0500 +++ zarafa-7.2.0/spooler/Spooler.cpp 2015-03-09 13:48:39.411933242 -0400 @@ -1147,6 +1147,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