commit 53941d7314d45553bb33a9dc581f761f37fde88b Author: Daniel Berteaud Date: Thu Feb 28 16:16:15 2013 +0100 initial commit diff --git a/createlinks b/createlinks new file mode 100644 index 0000000..f6a9996 --- /dev/null +++ b/createlinks @@ -0,0 +1,8 @@ +#!/usr/bin/perl -w + +use esmith::Build::CreateLinks qw(:all); + +event_link("dovecot-acl", "email-update", "85"); +event_link("dovecot-acl", "user-create", "85"); + +safe_touch("root/etc/dovecot/sharedmailbox/dict.db"); diff --git a/root/etc/e-smith/db/configuration/defaults/sieve/TCPPort b/root/etc/e-smith/db/configuration/defaults/sieve/TCPPort new file mode 100644 index 0000000..025479c --- /dev/null +++ b/root/etc/e-smith/db/configuration/defaults/sieve/TCPPort @@ -0,0 +1 @@ +4190 diff --git a/root/etc/e-smith/db/configuration/defaults/sieve/access b/root/etc/e-smith/db/configuration/defaults/sieve/access new file mode 100644 index 0000000..3e18ebf --- /dev/null +++ b/root/etc/e-smith/db/configuration/defaults/sieve/access @@ -0,0 +1 @@ +private diff --git a/root/etc/e-smith/db/configuration/defaults/sieve/status b/root/etc/e-smith/db/configuration/defaults/sieve/status new file mode 100644 index 0000000..86981e6 --- /dev/null +++ b/root/etc/e-smith/db/configuration/defaults/sieve/status @@ -0,0 +1 @@ +enabled diff --git a/root/etc/e-smith/db/configuration/defaults/sieve/type b/root/etc/e-smith/db/configuration/defaults/sieve/type new file mode 100644 index 0000000..24e1098 --- /dev/null +++ b/root/etc/e-smith/db/configuration/defaults/sieve/type @@ -0,0 +1 @@ +service diff --git a/root/etc/e-smith/events/actions/dovecot-acl b/root/etc/e-smith/events/actions/dovecot-acl new file mode 100644 index 0000000..3ff142f --- /dev/null +++ b/root/etc/e-smith/events/actions/dovecot-acl @@ -0,0 +1,89 @@ +#!/usr/bin/perl -w + + +use esmith::ConfigDB; +use esmith::AccountsDB; +use File::Find; + +my $c = esmith::ConfigDB->open || die "Couldn't open ConfigDB\n"; +my $a = esmith::AccountsDB->open_ro || die "Couldn't open AccountsdDB\n"; + +my $dovecot = $c->get('dovecot'); + +die "couldn't find dovecot service\n" unless ($dovecot); + +my $event = $ARGV[0]; + +# SharedMailboxes disabled ? +if (($dovecot->prop('SharedMailbox') || 'disabled') eq 'disabled'){ + if (($dovecot->prop('SharedMailboxAcl') || 'yes') ne 'no'){ + foreach my $user ($a->users){ + my $name = $user->key; + die "Error removing SharedMailbox ACLs ($name"."'s Maildir)\n" unless ( + system('/usr/bin/setfacl', + '-R', + '-x', + 'g:sharedmailbox', + "/home/e-smith/files/users/$name") == 0 && + system('/bin/chmod', + '-R', + 'g-s', + "/home/e-smith/files/users/$name/Maildir") == 0 + ); + } + } + $dovecot->set_prop('SharedMailboxAcl','no'); + exit(0); +} + +# If SharedMailbox is enabled + +# Set the correct ACL during user creation +if ($event && $event eq 'user-create'){ + my $user = $ARGV[1]; + set_acl($user); +} + +if (($dovecot->prop('SharedMailboxAcl') || 'no') ne 'yes'){ + # ACL for existing users haven't been set yet + foreach my $user ($a->users){ + my $name = $user->key; + set_acl($name); + } + $dovecot->set_prop('SharedMailboxAcl','yes'); +} + +# Set ACL on a user's Maildir +sub set_acl { + my $user = shift; + die "Missing username\n" unless ($user); + die "Couldn't find $user"."'s home dir\n" unless (-e "/home/e-smith/files/users/$user"); + find(\&dirperm, "/home/e-smith/files/users/$user/Maildir"); + die "Error applying permissions to $user 's Maildir\n" unless ( + # sharedmailbox group needs read / write access on Maildir + system('/usr/bin/setfacl', + '-R', + '-m', + 'u::rwX,g::rwX,g:sharedmailbox:rwX,d:u::rwX,d:g::rwX,d:g:sharedmailbox:rwX', + "/home/e-smith/files/users/$user/Maildir") == 0 && + # Grant sharedmailbox group permission to go through + # the home dir so it can access the Maildir, but don't let it read + # anything (except the Maildir) + system('/usr/bin/setfacl', + '-m', + 'g:sharedmailbox:x', + "/home/e-smith/files/users/$user") == 0 + ); +} + +# The kernel will handle group perms when a user +# create a dir in another user's Maildir (if IMAP ACL allows it) +# This will prevent dovecot errors, see +# http://wiki2.dovecot.org/SharedMailboxes/Permissions and +# http://wiki2.dovecot.org/Errors/ChgrpNoPerm +sub dirperm { + system('/bin/chmod', + 'g+s', + "$_") if (-d); +} + diff --git a/root/etc/e-smith/templates-user/.qmail/80DovecotLDA b/root/etc/e-smith/templates-user/.qmail/80DovecotLDA new file mode 100644 index 0000000..2847f27 --- /dev/null +++ b/root/etc/e-smith/templates-user/.qmail/80DovecotLDA @@ -0,0 +1,20 @@ +# Dovecot LDA delivery +{ + # vim: ft=perl: + use esmith::ConfigDB; + my $cdb = esmith::ConfigDB->open_ro || die "Couldn't open ConfigDB\n"; + my $sieve = $cdb->get('sieve'); + my $usersieve = $props{Sieve} || 'enabled'; + my $globalsieve = ($sieve) ? ($sieve->prop('status') || 'disabled') : 'disabled'; + + if (($usersieve ne 'enabled') || ($globalsieve ne 'enabled')){ + $OUT .= "# Sieve is disabled\n"; + } + elsif ($props{EmailForward} !~ /^(local|both)$/) { + $OUT .= "# No local delivery (Dovecot LDA)\n"; + } + else{ + $OUT .= '| /var/qmail/bin/preline -f /usr/libexec/dovecot/dovecot-lda -a "$RECIPIENT"; if [ $? -ne 0 ] ; then exit -1; else exit 99; fi;'; + } +} + diff --git a/root/etc/e-smith/templates/etc/dovecot/dovecot.conf/10protocols11sieve b/root/etc/e-smith/templates/etc/dovecot/dovecot.conf/10protocols11sieve new file mode 100644 index 0000000..d0be3ab --- /dev/null +++ b/root/etc/e-smith/templates/etc/dovecot/dovecot.conf/10protocols11sieve @@ -0,0 +1,6 @@ +{ +if (($sieve{'status'} || 'disabled') eq 'enabled'){ + $proto .= " sieve"; +} +$OUT .= ""; +} diff --git a/root/etc/e-smith/templates/etc/dovecot/dovecot.conf/30listener11sieve b/root/etc/e-smith/templates/etc/dovecot/dovecot.conf/30listener11sieve new file mode 100644 index 0000000..42c8e8a --- /dev/null +++ b/root/etc/e-smith/templates/etc/dovecot/dovecot.conf/30listener11sieve @@ -0,0 +1,19 @@ +{ +if (($sieve{'status'} || 'enabled') eq 'enabled'){ + my $port = $sieve{'TCPPort'} || '4190'; + my $address = $sieve{'Listen'} || '127.0.0.1'; + $OUT .=<<"HERE"; + +service managesieve-login { + inet_listener sieve { + port = $port + address = $address + } +} + +HERE +} +else { + $OUT .= "# Sieve is disabled"; +} +} diff --git a/root/etc/e-smith/templates/etc/dovecot/dovecot.conf/40lda b/root/etc/e-smith/templates/etc/dovecot/dovecot.conf/40lda new file mode 100644 index 0000000..ec4b723 --- /dev/null +++ b/root/etc/e-smith/templates/etc/dovecot/dovecot.conf/40lda @@ -0,0 +1,19 @@ + +postmaster_address = postmaster@{$DomainName} +lda_original_recipient_header = to + +{ +my $reason = $dovecot{'RejectMessage'} || ''; +my $subject = $dovecot{'RejectSubject'} || ''; +if ($reason ne ''){ + $OUT .= "rejection_reason = $reason\n"; +} +if ($subject ne ''){ + $OUT .= "rejection_subject = $subject\n"; +} +} + +protocol lda \{ + mail_plugins = $mail_plugins {$OUT .= (($sieve{'status'} || 'disabled') eq 'enabled') ? 'sieve':''} +\} + diff --git a/root/etc/e-smith/templates/etc/dovecot/dovecot.conf/65pluginAcl b/root/etc/e-smith/templates/etc/dovecot/dovecot.conf/65pluginAcl new file mode 100644 index 0000000..947b4b8 --- /dev/null +++ b/root/etc/e-smith/templates/etc/dovecot/dovecot.conf/65pluginAcl @@ -0,0 +1,68 @@ +{ +return "" if (($dovecot{'SharedMailbox'} || 'disabled') eq 'disabled'); + +push @plugins, 'acl'; +push @imap_plugins, 'imap_acl'; + +my $string =<<'HERE'; + +mail_access_groups = sharedmailbox + +service dict { + unix_listener dict { + mode = 0660 + group = sharedmailbox + } +} + +service auth { + unix_listener auth-userdb { + mode = 0660 + group = sharedmailbox + } +} + +service imap { + executable = imap imap-postlogin +} + +service imap-postlogin { + executable = script-login -d /usr/bin/imap-postlogin + unix_listener imap-postlogin { + } +} + + +namespace { + type = private + separator = / + prefix = + inbox = yes +} + +namespace { + type = shared + separator = / + prefix = shared/%%u/ + location = maildir:%%h/Maildir:INDEX=~/Maildir/shared/%%u + subscriptions = no + list = children +} + +plugin { + acl_shared_dict = file:/home/e-smith/db/dovecot/sharedmailbox.db +} + +plugin { + acl = vfile +} + +plugin { + acl_anyone = allow +} + +HERE + +push @conf, $string; +$OUT .= ''; +} diff --git a/root/usr/bin/imap-postlogin b/root/usr/bin/imap-postlogin new file mode 100644 index 0000000..0d17572 --- /dev/null +++ b/root/usr/bin/imap-postlogin @@ -0,0 +1,5 @@ +#!/bin/sh +ACL_GROUPS=`groups $USER | tr ' ' ','` +export ACL_GROUPS +export USERDB_KEYS="$USERDB_KEYS acl_groups" +exec "$@" diff --git a/smeserver-dovecot-extras.spec b/smeserver-dovecot-extras.spec new file mode 100644 index 0000000..49e2feb --- /dev/null +++ b/smeserver-dovecot-extras.spec @@ -0,0 +1,62 @@ +%define version 0.0.1 +%define release 1.beta0 +%define name smeserver-dovecot-extras + + +Summary: Additional features for dovecot on SME Server +Name: %{name} +Version: %{version} +Release: %{release}%{?dist} +License: GPL +Group: Networking/Daemons +Source: %{name}-%{version}.tar.gz + +BuildRoot: /var/tmp/%{name}-%{version}-%{release}-buildroot +BuildArchitectures: noarch +BuildRequires: e-smith-devtools + +Requires: smeserver-dovecot +Requires: dovecot-pigeonhole +Requires: acl + +%description +Add IMAP acl (sharedmailbox) and sieve capabilities to the IMAP server + +%changelog +* Tue Nov 29 2011 Daniel Berteaud - 0.0.1 +- initial release + +%prep +%setup -q -n %{name}-%{version} + +%build +perl createlinks + +%install +/bin/rm -rf $RPM_BUILD_ROOT +(cd root ; /usr/bin/find . -depth -print | /bin/cpio -dump $RPM_BUILD_ROOT) +/bin/rm -f %{name}-%{version}-filelist +/sbin/e-smith/genfilelist $RPM_BUILD_ROOT \ + --dir /home/e-smith/db/dovecot 'attr(2770,root,sharedmailbox)' \ + --file /home/e-smith/db/dovecot/sharedmailbox.db 'attr(0660,root,sharedmailbox) %config(noreplace)' \ + --file /usr/bin/imap-postlogin 'attr(0755,root,root)' \ + > %{name}-%{version}-filelist + +%files -f %{name}-%{version}-filelist +%defattr(-,root,root) + +%clean +rm -rf $RPM_BUILD_ROOT + +%pre +/usr/sbin/groupadd -g 439 sharedmailbox 2> /dev/null || : + +%post +# Migrate the sharedmailbox dict to its new location +if [ -e /etc/dovecot/sharedmailbox/dict.db ]; then + mv -f /etc/dovecot/sharedmailbox/dict.db /home/e-smith/db/dovecot/sharedmailbox.db + rm -rf /etc/dovecot/sharedmailbox +fi + +%preun +