Alias patch for ZCP 7.2.0

This commit is contained in:
Christoph Haas UIBK 2015-04-29 13:38:34 -07:00
parent 4d336b7d8d
commit 961eb228fa
1 changed files with 385 additions and 395 deletions

View File

@ -1,395 +1,385 @@
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 <christoph.h@sprinternet.at>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#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<string, AliasData>(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<string, AliasData>::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 <christoph.h@sprinternet.at>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <fstream>
+#include <sstream>
+#include <string>
+#include <cstring>
+#include <algorithm>
+#include <map>
+
+#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<string, AliasData> 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 <mapitags.h>
#include <mapiext.h>
@@ -82,6 +83,7 @@
#include <list>
#include <algorithm>
+
using namespace std;
extern ECConfig *g_lpConfig;
@@ -1758,7 +1760,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;
@@ -1770,10 +1772,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);
@@ -1810,6 +1811,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);
@@ -2166,6 +2179,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;
@@ -2334,7 +2356,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;
@@ -2363,7 +2385,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
@@ -28,7 +28,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 \
@@ -391,7 +391,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
@@ -492,6 +492,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:
+
+___BUILDING___:
+First read: http://www.zarafa.com/wiki/index.php/Compiling_source_code
+
+cd path/to/zarafa-source
+./configure --enable-release --disable-static --with-userscript-prefix=/etc/zarafa/userscripts --with-quotatemplate-prefix=/etc/zarafa/quotamails --enable-python --enable-unicode --disable-swig --disable-tcmalloc
+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.
+
+
+
+___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
@@ -1142,6 +1142,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
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 <christoph.h@sprinternet.at>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#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<string, AliasData>(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<string, AliasData>::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 <christoph.h@sprinternet.at>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <fstream>
+#include <sstream>
+#include <string>
+#include <cstring>
+#include <algorithm>
+#include <map>
+
+#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<string, AliasData> 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 <mapitags.h>
#include <mapiext.h>
@@ -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