diff options
author | Thomas Bruederli <bruederli@kolabsys.com> | 2014-04-23 17:54:57 -0400 |
---|---|---|
committer | Thomas Bruederli <bruederli@kolabsys.com> | 2014-04-23 17:54:57 -0400 |
commit | c7c17c997481b817a42cc8c44d62f4c77d231f22 (patch) | |
tree | e4246aa82656fd186753543879f0f57d1bef8815 | |
parent | fa3076751a06dc0b9d648719e517619d61e9e03d (diff) | |
download | pykolab-c7c17c997481b817a42cc8c44d62f4c77d231f22.tar.gz |
Add kolabd plugin to cleanup Roundcube's database after deleting a Kolab user from LDAP
-rw-r--r-- | pykolab/auth/ldap/__init__.py | 9 | ||||
-rw-r--r-- | pykolab/plugins/roundcubedb/__init__.py | 69 |
2 files changed, 78 insertions, 0 deletions
diff --git a/pykolab/auth/ldap/__init__.py b/pykolab/auth/ldap/__init__.py index c0c3297..8379c0c 100644 --- a/pykolab/auth/ldap/__init__.py +++ b/pykolab/auth/ldap/__init__.py @@ -1436,6 +1436,15 @@ class LDAP(pykolab.base.Base): self.imap.user_mailbox_delete(entry[result_attribute]) self.imap.cleanup_acls(entry[result_attribute]) + # let plugins act upon this deletion + conf.plugins.exec_hook( + 'user_delete', + kw = { + 'user': entry, + 'domain': self.domain + } + ) + def _change_moddn_group(self, entry, change): # TODO: If the rdn attribute is the same as the result attribute... pass diff --git a/pykolab/plugins/roundcubedb/__init__.py b/pykolab/plugins/roundcubedb/__init__.py new file mode 100644 index 0000000..a7f289e --- /dev/null +++ b/pykolab/plugins/roundcubedb/__init__.py @@ -0,0 +1,69 @@ +# -*- coding: utf-8 -*- +# Copyright 2014 Kolab Systems AG (http://www.kolabsys.com) +# +# Thomas Bruederli (Kolab Systems) <bruederli(a)kolabsys.com> +# +# 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; version 3 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 Library General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# + +import os +import pykolab +import subprocess + +from pykolab.translate import _ + +log = pykolab.getLogger('pykolab.plugins.roundcubedb') +conf = pykolab.getConf() + +class KolabRoundcubedb(object): + """ + Pykolab plugin to update Roundcube's database on Kolab users db changes + """ + + def __init__(self): + pass + + def add_options(self, *args, **kw): + pass + + def user_delete(self, *args, **kw): + """ + The arguments passed to the 'user_delete' hook: + + user - full user entry from LDAP + domain - domain name + """ + + log.debug(_("user_delete: %r") % (kw), level=9) + + if os.path.isdir('/usr/share/roundcubemail'): + rcpath = '/usr/share/roundcubemail/' + elif os.path.isdir('/usr/share/roundcube'): + rcpath = '/usr/share/roundcube/' + else: + log.error(_("Roundcube installation path not found.")) + return False + + result_attribute = conf.get('cyrus-sasl', 'result_attribute') + + # execute Roundcube's bin/deluser.sh script to do the work + if kw.has_key('user') and kw['user'].has_key(result_attribute) and os.path.exists(rcpath + 'bin/deluser.sh'): + proc = subprocess.Popen([ 'sudo -u apache', rcpath + 'bin/deluser.sh', kw['user'][result_attribute] ], stderr=subprocess.PIPE, stdout=subprocess.PIPE) + procout, procerr = proc.communicate() + if proc.returncode != 0: + log.error(rcpath + "bin/deluser.sh exited with error %d: %r" % (proc.returncode, procerr)) + else: + log.debug(rcpath + "bin/deluser.sh success: %r; %r" % (procout, procerr), level=9) + + return None |