A simple patch for the Zarafa spooler which allows the use of an alias file. See: https://forums.zarafa.com/showthread.php?9193-Patch-for-simple-alias-management
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

alias_patch.diff 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. diff -ruN '--exclude=.svn' orig/zarafa-7.2.0/spooler/alias.cpp zarafa-7.2.0/spooler/alias.cpp
  2. --- orig/zarafa-7.2.0/spooler/alias.cpp 1969-12-31 19:00:00.000000000 -0500
  3. +++ zarafa-7.2.0/spooler/alias.cpp 2015-03-09 13:16:49.487933628 -0400
  4. @@ -0,0 +1,150 @@
  5. +/*
  6. + * Copyright 2015 Christoph Haas <christoph.h@sprinternet.at>
  7. + *
  8. + * This program is free software: you can redistribute it and/or modify
  9. + * it under the terms of the GNU General Public License as published by
  10. + * the Free Software Foundation, either version 3 of the License, or
  11. + * (at your option) any later version.
  12. + *
  13. + * This program is distributed in the hope that it will be useful,
  14. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. + * GNU General Public License for more details.
  17. + *
  18. + * You should have received a copy of the GNU General Public License
  19. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. + *
  21. + */
  22. +
  23. +#include "alias.h"
  24. +
  25. +using namespace std;
  26. +
  27. +extern ECLogger *g_lpLogger;
  28. +
  29. +Alias::Alias(){
  30. + aliasFound = false;
  31. +}
  32. +
  33. +
  34. +/*
  35. + * trim a string
  36. + */
  37. +string Alias::trim(const string &strInput, const string &strTrim) {
  38. + string s = strInput;
  39. + size_t pos;
  40. +
  41. + if (s.empty())
  42. + return s;
  43. +
  44. + pos = s.find_first_not_of(strTrim);
  45. + s.erase(0, pos);
  46. +
  47. + pos = s.find_last_not_of(strTrim);
  48. + if (pos != std::string::npos)
  49. + s.erase(pos + 1, std::string::npos);
  50. +
  51. + return s;
  52. +}
  53. +
  54. +/*
  55. + * Initializes the multimap
  56. + * Reads all rules from a space sepereated string
  57. + * e.g:
  58. + * 1@1.de 2@2.de
  59. + * 1@1.de alias1@1.de
  60. + */
  61. +void Alias::init(char *filename) {
  62. + alias_file.open(filename);
  63. +
  64. + if(alias_file.is_open()) {
  65. + string sLine;
  66. + while (getline(alias_file, sLine)) {
  67. + istringstream ssLine(sLine);
  68. + string sPart;
  69. + string sKey;
  70. + AliasData data;
  71. + int count = 0;
  72. +
  73. + while ( getline(ssLine, sPart, ';') ) {
  74. + sPart = trim(sPart, " \t\r\n");
  75. +
  76. + if(count == 0) {
  77. + sKey = sPart;
  78. + data.ownerMailAddress = sPart;
  79. + } else if(count == 1) {
  80. + remove(sPart.begin(), sPart.end(), ' ');
  81. + data.aliasMailAddress = sPart;
  82. + } else if(count == 2) {
  83. + data.aliasName = sPart;
  84. + }
  85. + count++;
  86. + }
  87. +
  88. + if(count == 3) {
  89. + acl.insert(pair<string, AliasData>(sKey, data));
  90. + }
  91. + }
  92. + } else {
  93. + // the file could not be read
  94. + g_lpLogger->Log(EC_LOGLEVEL_FATAL, "Aliasfile could not be read! (%s)", filename);
  95. + }
  96. +}
  97. +
  98. +/*
  99. + * check if our acl is empty
  100. + */
  101. +bool Alias::isInitialized(void) {
  102. + return !acl.empty(); // if there is no entry in our accesslist we do not have to check anything...
  103. +}
  104. +
  105. +/*
  106. + * check if we have found an alias
  107. + */
  108. +bool Alias::foundAlias(void) {
  109. + return aliasFound;
  110. +}
  111. +
  112. +/*
  113. + * try to compare the given mail addresses with our acl
  114. + * FIXME: aliasing would not work with unicode mailaddresses!
  115. + */
  116. +bool Alias::check_mail(wchar_t *e1, wchar_t *e2) {
  117. + wstring wE1 = wstring(e1);
  118. + wstring wE2 = wstring(e2);
  119. + string sE1(wE1.begin(), wE1.end());
  120. + string sE2(wE2.begin(), wE2.end());
  121. +
  122. + multimap<string, AliasData>::iterator mmIterator;
  123. +
  124. + if(isInitialized()) {
  125. + mmIterator = acl.find(sE1);
  126. + if(mmIterator != acl.end()) {
  127. + do {
  128. + if(mmIterator->second.aliasMailAddress.compare(sE2) == 0) {
  129. + // found positive match in acl
  130. + aliasFound = true;
  131. + aliasFoundData = mmIterator->second;
  132. + return true;
  133. + }
  134. + mmIterator++;
  135. + } while(mmIterator != acl.upper_bound(sE1));
  136. + } else {
  137. + // found noting...
  138. + aliasFound = false;
  139. + return false;
  140. + }
  141. + }
  142. +
  143. + return false;
  144. +}
  145. +
  146. +wstring Alias::getAliasName() {
  147. + wstring name( L"" ); // default will be a empty string
  148. +
  149. + if(foundAlias()) {
  150. + name.assign(aliasFoundData.aliasName.begin(), aliasFoundData.aliasName.end()); // works for ascii only
  151. + }
  152. +
  153. + return name;
  154. +}
  155. diff -ruN '--exclude=.svn' orig/zarafa-7.2.0/spooler/alias.h zarafa-7.2.0/spooler/alias.h
  156. --- orig/zarafa-7.2.0/spooler/alias.h 1969-12-31 19:00:00.000000000 -0500
  157. +++ zarafa-7.2.0/spooler/alias.h 2015-03-09 13:13:50.543932736 -0400
  158. @@ -0,0 +1,52 @@
  159. +/*
  160. + * Copyright 2015 Christoph Haas <christoph.h@sprinternet.at>
  161. + *
  162. + * This program is free software: you can redistribute it and/or modify
  163. + * it under the terms of the GNU General Public License as published by
  164. + * the Free Software Foundation, either version 3 of the License, or
  165. + * (at your option) any later version.
  166. + *
  167. + * This program is distributed in the hope that it will be useful,
  168. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  169. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  170. + * GNU General Public License for more details.
  171. + *
  172. + * You should have received a copy of the GNU General Public License
  173. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  174. + *
  175. + */
  176. +
  177. +#include <fstream>
  178. +#include <sstream>
  179. +#include <string>
  180. +#include <cstring>
  181. +#include <algorithm>
  182. +#include <map>
  183. +
  184. +#include "ECLogger.h"
  185. +
  186. +using namespace std;
  187. +extern ECLogger *g_lpLogger;
  188. +
  189. +struct AliasData {
  190. + string ownerMailAddress;
  191. + string aliasMailAddress;
  192. + string aliasName;
  193. +};
  194. +
  195. +class Alias {
  196. + private:
  197. + ifstream alias_file;
  198. + multimap<string, AliasData> acl;
  199. + bool aliasFound;
  200. + AliasData aliasFoundData;
  201. +
  202. + string trim(const string &strInput, const string &strTrim = " ");
  203. + bool isInitialized (void);
  204. + public:
  205. + Alias();
  206. + void init (char *filename);
  207. + bool foundAlias (void);
  208. + wstring getAliasName (void);
  209. + bool check_mail (wchar_t *e1, wchar_t *e2);
  210. +};
  211. diff -ruN '--exclude=.svn' orig/zarafa-7.2.0/spooler/mailer.cpp zarafa-7.2.0/spooler/mailer.cpp
  212. --- orig/zarafa-7.2.0/spooler/mailer.cpp 2015-03-05 10:54:04.000000000 -0500
  213. +++ zarafa-7.2.0/spooler/mailer.cpp 2015-03-09 13:39:14.851941692 -0400
  214. @@ -45,6 +45,7 @@
  215. #include "platform.h"
  216. #include "mailer.h"
  217. #include "archive.h"
  218. +#include "alias.h"
  219. #include <mapitags.h>
  220. #include <mapiext.h>
  221. @@ -1839,7 +1840,7 @@
  222. */
  223. HRESULT CheckSendAs(IAddrBook *lpAddrBook, IMsgStore *lpUserStore, IMAPISession *lpAdminSession, ECSender *lpMailer,
  224. ULONG ulOwnerCB, LPENTRYID lpOwnerEID, ULONG ulRepresentCB, LPENTRYID lpRepresentEID,
  225. - bool *lpbAllowed, LPMDB *lppRepStore)
  226. + bool *lpbAllowed, LPMDB *lppRepStore, Alias *aliasCheck)
  227. {
  228. HRESULT hr = hrSuccess;
  229. bool bAllowed = false;
  230. @@ -1851,7 +1852,7 @@
  231. LPSPropValue lpRepresentProps = NULL;
  232. SPropValue sSpoofEID = {0};
  233. ULONG ulCmpRes = 0;
  234. - SizedSPropTagArray(3, sptaIDProps) = { 3, { PR_DISPLAY_NAME_W, PR_EC_SENDAS_USER_ENTRYIDS, PR_DISPLAY_TYPE } };
  235. + SizedSPropTagArray(5, sptaIDProps) = { 5, { PR_DISPLAY_NAME_W, PR_EC_SENDAS_USER_ENTRYIDS, PR_DISPLAY_TYPE, PR_SMTP_ADDRESS_W, PR_EMAIL_ADDRESS_W } };
  236. ULONG cValues = 0;
  237. @@ -1901,7 +1902,19 @@
  238. if (lpRepresentProps[2].ulPropTag != PR_DISPLAY_TYPE) { // Required property for a mailuser object
  239. hr = MAPI_E_NOT_FOUND;
  240. - g_lpLogger->Log(EC_LOGLEVEL_NOTICE, "CheckSendAs(): PR_DISPLAY_TYPE missing %x", hr);
  241. + // we are checking a simple textfile for matches.
  242. + // if the users smtp-address is matching we allow the sending
  243. + if(strcmp(g_lpConfig->GetSetting("use_alias_file"), "yes") == 0) {
  244. + if(aliasCheck->check_mail(lpOwnerProps[3].Value.lpszW, lpRepresentProps[4].Value.lpszW)) {
  245. + g_lpLogger->Log(EC_LOGLEVEL_INFO,"alias found in acl: %ls -> %ls", lpOwnerProps[3].Value.lpszW, lpRepresentProps[4].Value.lpszW);
  246. + hr = hrSuccess;
  247. + bAllowed = true;
  248. + } else {
  249. + g_lpLogger->Log(EC_LOGLEVEL_ERROR,"alias not found in acl: %ls -> %ls", lpOwnerProps[3].Value.lpszW, lpRepresentProps[4].Value.lpszW);
  250. + }
  251. + } else {
  252. + g_lpLogger->Log(EC_LOGLEVEL_NOTICE, "CheckSendAs(): PR_DISPLAY_TYPE missing %x", hr);
  253. + }
  254. goto exit;
  255. }
  256. @@ -2271,6 +2284,15 @@
  257. ArchiveResult archiveResult;
  258. + Alias aliasCheck;
  259. +
  260. + if(strcmp(g_lpConfig->GetSetting("use_alias_file"), "yes") == 0) {
  261. + g_lpLogger->Log(EC_LOGLEVEL_INFO,"Alias checking enabled");
  262. + aliasCheck.init(g_lpConfig->GetSetting("alias_file"));
  263. + } else {
  264. + g_lpLogger->Log(EC_LOGLEVEL_INFO,"Alias checking disabled");
  265. + }
  266. +
  267. sending_options sopt;
  268. imopt_default_sending_options(&sopt);
  269. @@ -2438,7 +2460,7 @@
  270. if (!bAllowDelegate) {
  271. hr = CheckSendAs(lpAddrBook, lpUserStore, lpAdminSession, lpMailer, lpPropOwner->Value.bin.cb, (LPENTRYID)lpPropOwner->Value.bin.lpb,
  272. - lpRepEntryID->Value.bin.cb, (LPENTRYID)lpRepEntryID->Value.bin.lpb, &bAllowSendAs, &lpRepStore);
  273. + lpRepEntryID->Value.bin.cb, (LPENTRYID)lpRepEntryID->Value.bin.lpb, &bAllowSendAs, &lpRepStore, &aliasCheck);
  274. if (hr != hrSuccess)
  275. goto exit;
  276. diff -ruN '--exclude=.svn' orig/zarafa-7.2.0/spooler/Makefile.am zarafa-7.2.0/spooler/Makefile.am
  277. --- orig/zarafa-7.2.0/spooler/Makefile.am 2015-03-05 10:52:42.000000000 -0500
  278. +++ zarafa-7.2.0/spooler/Makefile.am 2015-03-09 13:40:47.467933464 -0400
  279. @@ -28,7 +28,7 @@
  280. $(PROG_LIBS) $(PYTHON_LIBS) $(XML2_LIBS)
  281. zarafa_dagent_SOURCES = DAgent.cpp rules.cpp rules.h LMTP.cpp LMTP.h archive.cpp archive.h PyMapiPlugin.cpp PyMapiPlugin.h PythonSWIGRuntime.h
  282. -zarafa_spooler_SOURCES = Spooler.cpp mailer.cpp mailer.h archive.cpp archive.h PyMapiPlugin.cpp PyMapiPlugin.h PythonSWIGRuntime.h
  283. +zarafa_spooler_SOURCES = Spooler.cpp mailer.cpp mailer.h archive.cpp archive.h PyMapiPlugin.cpp PyMapiPlugin.h PythonSWIGRuntime.h alias.cpp alias.h
  284. BUILT_SOURCES=PythonSWIGRuntime.h
  285. diff -ruN '--exclude=.svn' orig/zarafa-7.2.0/spooler/Makefile.in zarafa-7.2.0/spooler/Makefile.in
  286. --- orig/zarafa-7.2.0/spooler/Makefile.in 2015-03-05 10:52:53.000000000 -0500
  287. +++ zarafa-7.2.0/spooler/Makefile.in 2015-03-09 13:43:20.163932624 -0400
  288. @@ -83,7 +83,7 @@
  289. am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
  290. am__v_lt_0 = --silent
  291. am_zarafa_spooler_OBJECTS = Spooler.$(OBJEXT) mailer.$(OBJEXT) \
  292. - archive.$(OBJEXT) PyMapiPlugin.$(OBJEXT)
  293. + archive.$(OBJEXT) PyMapiPlugin.$(OBJEXT) alias.$(OBJEXT)
  294. zarafa_spooler_OBJECTS = $(am_zarafa_spooler_OBJECTS)
  295. zarafa_spooler_DEPENDENCIES = ${top_builddir}/inetmapi/libinetmapi.la \
  296. ${top_builddir}/mapi4linux/src/libmapi.la \
  297. @@ -410,7 +410,7 @@
  298. $(PROG_LIBS) $(PYTHON_LIBS) $(XML2_LIBS)
  299. zarafa_dagent_SOURCES = DAgent.cpp rules.cpp rules.h LMTP.cpp LMTP.h archive.cpp archive.h PyMapiPlugin.cpp PyMapiPlugin.h PythonSWIGRuntime.h
  300. -zarafa_spooler_SOURCES = Spooler.cpp mailer.cpp mailer.h archive.cpp archive.h PyMapiPlugin.cpp PyMapiPlugin.h PythonSWIGRuntime.h
  301. +zarafa_spooler_SOURCES = Spooler.cpp mailer.cpp mailer.h archive.cpp archive.h PyMapiPlugin.cpp PyMapiPlugin.h PythonSWIGRuntime.h alias.cpp alias.h
  302. BUILT_SOURCES = PythonSWIGRuntime.h
  303. CLEANFILES = PythonSWIGRuntime.h
  304. EXTRA_DIST = PythonSWIGRuntime.h
  305. @@ -514,6 +514,7 @@
  306. @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Spooler.Po@am__quote@
  307. @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/archive.Po@am__quote@
  308. @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mailer.Po@am__quote@
  309. +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/alias.Po@am__quote@
  310. @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rules.Po@am__quote@
  311. .cpp.o:
  312. diff -ruN '--exclude=.svn' orig/zarafa-7.2.0/spooler/README.txt zarafa-7.2.0/spooler/README.txt
  313. --- orig/zarafa-7.2.0/spooler/README.txt 1969-12-31 19:00:00.000000000 -0500
  314. +++ zarafa-7.2.0/spooler/README.txt 2015-03-09 13:58:45.579943321 -0400
  315. @@ -0,0 +1,74 @@
  316. +README for the alias extension:
  317. +
  318. +___PREPARATION___:
  319. +
  320. +First read: http://www.zarafa.com/wiki/index.php/Compiling_source_code
  321. +
  322. +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/
  323. +
  324. +
  325. +___BUILDING___:
  326. +
  327. +cd path/to/zarafa-source
  328. +./configure --enable-unicode --enable-release --enable-python --prefix=/usr --with-gsoap-prefix=/opt/zarafa/ --with-ical-prefix=/opt/zarafa/ --with-vmime-prefix=/opt/zarafa/
  329. +make
  330. +checkinstall
  331. +
  332. +
  333. +___GENERAL___:
  334. +
  335. +The alias checking reads its rules from an ansi textfile.
  336. +Each rule needs to be on a new line. The sender mailaddress, alias mailaddress and alias display name are seperated by a semicolon
  337. +
  338. +E.g:
  339. +
  340. +user@zarafa.de;aliasforuser@zarafa.de;Alias Username
  341. +user2@zarafa.com;aliasforuser2@zarafa.de;Alias2 Displayname
  342. +
  343. +Changes to this file would be applied immediately.
  344. +Info: Display name is currentl not in use.
  345. +
  346. +
  347. +___CONFIGURATION___:
  348. +
  349. +The default path for the rule file is: /etc/zarafa/alias.txt
  350. +You can enable/disable the extension in the spooler.cfg file.
  351. +
  352. +WARNING: you have to restart the patched/recompiled spooler version once before you add the new config parameters!
  353. +
  354. +New configuration parameters:
  355. +
  356. +use_alias_file (Values: yes, no ; Default: yes)
  357. +alias_file (Values: Path to alias file ; Default: /etc/zarafa/alias.txt)
  358. diff -ruN '--exclude=.svn' orig/zarafa-7.2.0/spooler/Spooler.cpp zarafa-7.2.0/spooler/Spooler.cpp
  359. --- orig/zarafa-7.2.0/spooler/Spooler.cpp 2015-03-05 10:54:04.000000000 -0500
  360. +++ zarafa-7.2.0/spooler/Spooler.cpp 2015-03-09 13:48:39.411933242 -0400
  361. @@ -1147,6 +1147,8 @@
  362. { "plugin_enabled", "yes" },
  363. { "plugin_path", "/var/lib/zarafa/spooler/plugins" },
  364. { "plugin_manager_path", "/usr/share/zarafa-spooler/python" },
  365. + { "use_alias_file", "yes", CONFIGSETTING_RELOADABLE },
  366. + { "alias_file", "/etc/zarafa/alias.txt", CONFIGSETTING_RELOADABLE },
  367. { NULL, NULL },
  368. };
  369. // SIGSEGV backtrace support