From: Frank Brehm Date: Fri, 5 May 2017 09:09:44 +0000 (+0200) Subject: Adding additional checks to pp_lib/barracuda_sync_app.py X-Git-Tag: 0.1.2~174^2~1 X-Git-Url: https://git.uhu-banane.net/?a=commitdiff_plain;h=f395ec8877551dad98cb5828dfb7979c3ebb215a;p=pixelpark%2Fadmin-tools.git Adding additional checks to pp_lib/barracuda_sync_app.py --- diff --git a/pp_lib/barracuda_sync_app.py b/pp_lib/barracuda_sync_app.py index 217c40e..166ecf5 100644 --- a/pp_lib/barracuda_sync_app.py +++ b/pp_lib/barracuda_sync_app.py @@ -30,7 +30,7 @@ from .ldap_app import PpLdapAppError, PpLdapApplication from .mailaddress import MailAddress -__version__ = '0.4.3' +__version__ = '0.4.4' LOG = logging.getLogger(__name__) @@ -95,6 +95,7 @@ class PpBarracudaSyncApp(PpLdapApplication): cfg_stems='barracuda-sync' ) + self._check_virtaliases_files() self._init_ignore_aliases_res() self.initialized = True @@ -181,6 +182,16 @@ class PpBarracudaSyncApp(PpLdapApplication): if hasattr(self.args, 'postfix_dir') and self.args.postfix_dir: self._init_postfix_dir(self.args.postfix_dir) + if not os.path.isdir(self.postfix_config_dir): + LOG.error("Postfix directory {!r} does not exists or is not a directory.".format( + self.postfix_config_dir)) + self.exit(1) + + if not os.path.isdir(self.postfix_maps_dir): + LOG.error("Postfix maps directory {!r} does not exists or is not a directory.".format( + self.postfix_maps_dir)) + self.exit(1) + self._init_virtaliases_files(virtaliases_files) # ------------------------------------------------------------------------- @@ -230,6 +241,30 @@ class PpBarracudaSyncApp(PpLdapApplication): if afile not in self.virtaliases_files: self.virtaliases_files.append(afile) + # ------------------------------------------------------------------------- + def _check_virtaliases_files(self): + + ok = True + for afile in self.virtaliases_files: + + if not os.path.exists(afile): + LOG.error("Virtual aliases file {!r} does not exists.".format(afile)) + ok = False + continue + + if not os.path.isfile(afile): + LOG.error("Virtual aliases file {!r} is not a regular file.".format(afile)) + ok = False + continue + + if not os.access(afile, os.R_OK): + LOG.error("No read access to virtual aliases file {!r}.".format(afile)) + ok = False + continue + + if not ok: + self.exit(1) + # ------------------------------------------------------------------------- def _init_postfix_dir(self, value): @@ -243,6 +278,9 @@ class PpBarracudaSyncApp(PpLdapApplication): self.default_virtaliases_files = [ os.path.join(self.postfix_maps_dir, 'virtual-aliases'), ] + else: + LOG.warn("Postfix directory {!r} does not exists or is not a directory.".format( + value)) # ------------------------------------------------------------------------- def _init_ignore_aliases_res(self): @@ -272,6 +310,32 @@ class PpBarracudaSyncApp(PpLdapApplication): super(PpBarracudaSyncApp, self).pre_run() + self._check_ldap_barracuda_container() + + # ------------------------------------------------------------------------- + def _check_ldap_barracuda_container(self): + + LOG.debug("Checking existence of Baracuda LDAP container {!r}.".format( + self.barracuda_base_dn)) + query = '(objectclass=organizationalunit)' + + self.ldap_connection.search( + search_base=self.barracuda_base_dn, search_filter=query, + search_scope=BASE, attributes='*') + + LOG.debug("Found {} entries.".format(len(self.ldap_connection.response))) + if len(self.ldap_connection.response) < 1: + LOG.error(( + "Did not found LDAP container {!r} for " + "Barracuda alias definitions.").format( + self.barracuda_base_dn)) + self.exit(5) + + entry = self.ldap_connection.response[0] + if self.verbose > 1: + LOG.debug("Container entry - class {cl!r}, content:\n{co}".format( + cl=entry.__class__.__name__, co=pp(entry))) + # ------------------------------------------------------------------------- def _run(self):