def load_modules(): for name in env.ldap_modules: funcname = 'load_module_{0}'.format(name) try: puth('Loading module {0}'.format(name)) func = eval(funcname) func() except NameError: pass
def populate_database(): puth('Populating database') with fs.mkstemp() as fp: content = ldif.get_base_structure() open(fp, 'wt').write(content) env.sudo('ldapadd -x -D {0} -w {1} -f {2}'.format( env.ldap_admin_dn, env.ldap_admin_pw, fp))
def unload_schema(): ldap_env = LdapEnv.get() schema_dir = join(ldap_env.cn_config_path, 'cn=schema') files = fs.sh_listdir(schema_dir, sudo=True) files = fnmatch.filter(files, 'cn={*}%s.ldif' % env.ldap_custom_schema_cn) if not files: putw('Failed to detect schema: {0}'.format(env.ldap_custom_schema_cn)) else: filepath = join(schema_dir, files[0]) puth('Removing schema {0}'.format(filepath)) fs.sh_rm(filepath, sudo=True)
def create_database(): ldap_env = LdapEnv.get() if not fs.sh_dir_exists(ldap_env.database_path, sudo=True): puth('Creating database directory {0}'.format(ldap_env.database_path)) fs.sh_makedirs(ldap_env.database_path, user=ldap_env.ldap_user, group=ldap_env.ldap_group, sudo=True) with fs.mkstemp() as fp: content = ldif.get_database() open(fp, 'wt').write(content) puth('Creating database config for {0}'.format(env.ldap_database_name)) env.sudo('ldapadd -Y EXTERNAL -H ldapi:/// -f {0}'.format(fp))
def unload_modules(): ldap_env = LdapEnv.get() for name in env.ldap_modules: filepath = None files = fs.sh_listdir(ldap_env.cn_config_path, sudo=True) files = fnmatch.filter(files, 'cn=module{*}.ldif') for f in files: fp = join(ldap_env.cn_config_path, f) if fs.sh_file_exists(fp, sudo=True): content = fs.sh_cat(fp, sudo=True) if text.safefind('(?m)^olcModuleLoad: {[0-9]+}' + name, content): filepath = fp if not filepath: putw('Failed to detect loaded module: {0}'.format(name)) else: puth('Removing module {0}'.format(name)) fs.sh_rm(filepath, sudo=True)
def drop_database(): ldap_env = LdapEnv.get() files = fs.sh_listdir(ldap_env.cn_config_path, sudo=True) files = fnmatch.filter(files, 'olcDatabase={*}hdb.ldif') filepath = None for f in files: fp = join(ldap_env.cn_config_path, f) content = fs.sh_cat(fp, sudo=True) if text.safefind('(?m)^olcSuffix: ' + env.ldap_dit_dn, content): filepath = fp if not filepath: putw('Failed to detect database: {0}'.format(env.ldap_dit_dn)) else: puth('Removing database config {0}'.format(filepath)) fs.sh_rm(filepath, sudo=True) root, _ = os.path.splitext(filepath) if fs.sh_dir_exists(root, sudo=True): puth('Removing database config subdir {0}'.format(root)) fs.sh_rmtree(root, sudo=True)
def load_schema(): puth('Loading schema') with fs.mkstemp() as fp: content = ldif.get_zarafa_schema() open(fp, 'wt').write(content) env.sudo('ldapadd -Y EXTERNAL -H ldapi:/// -f {0}'.format(fp))
def delete_database_storage(): ldap_env = LdapEnv.get() if fs.sh_dir_exists(ldap_env.database_path, sudo=True): puth('Deleting database directory {0}'.format(ldap_env.database_path)) fs.sh_rmtree(ldap_env.database_path, sudo=True)