root/IoTa-Installer/lib/ldap.py @ 675e977d
2e0a7cb1 | Sylvain L. Sauvage | # -*- coding: utf-8 -*-
|
|
#
|
|||
# This program is a part of the IoTa project.
|
|||
#
|
|||
# Copyright © 2012 Université de Caen Basse-Normandie, GREYC
|
|||
19b58bab | Rémy Ménard | #
|
|
2e0a7cb1 | Sylvain L. Sauvage | # 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, either version 3 of the License, 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 General Public License for more details.
|
|||
# <http://www.gnu.org/licenses/>
|
|||
#
|
|||
# See AUTHORS for a list of contributors.
|
|||
#
|
|||
import installer
|
|||
import utils
|
|||
8fd1d584 | Rémy Ménard | from config import CONFIG
|
|
96454bcd | Sylvain L. Sauvage | ||
2e0a7cb1 | Sylvain L. Sauvage | ||
class LDAPConfigurer(installer.Configurer):
|
|||
def __init__(self):
|
|||
installer.Configurer.__init__(self, "LDAP", "ldap", [
|
|||
96454bcd | Sylvain L. Sauvage | ("Enter the URL to the LDAP directory", "ldap", "url", {}),
|
|
2e0a7cb1 | Sylvain L. Sauvage | ("Enter the LDAP's domain name", "ldap", "base_dn", {}),
|
|
("Enter the LDAP's login", "ldap", "login", {}),
|
|||
("Enter the LDAP's password", "ldap", "password", {}),
|
|||
bf9c3717 | Rémy Ménard | ("Enter the LDAP's user group (if multiples entries, complete the ldif file before to add it)", "ldap", "user_group", {}),
|
|
("Enter the LDAP's user ID", "ldap", "user_id", {}),
|
|||
("Enter the LDAP's owner attribute", "ldap", "attribute_owner", {}),
|
|||
("Enter the LDAP's alias attribute", "ldap", "attribute_alias", {}),
|
|||
2e0a7cb1 | Sylvain L. Sauvage | ("Do you want to create ldif files?", "ldap", "ldif_create", {"type": "YN"}),
|
|
96454bcd | Sylvain L. Sauvage | ("Do you want to automatically add ldif files to LDAP?", "ldap", "ldif_install",
|
|
{ "when": ("ldap", "ldif_create"), "type": "YN"})
|
|||
2e0a7cb1 | Sylvain L. Sauvage | ])
|
|
96454bcd | Sylvain L. Sauvage | ||
2e0a7cb1 | Sylvain L. Sauvage | def postConfigure(self):
|
|
96454bcd | Sylvain L. Sauvage | if self.cisTrue("ldif_create"):
|
|
2e0a7cb1 | Sylvain L. Sauvage | self.createLdifs()
|
|
96454bcd | Sylvain L. Sauvage | if self.cisTrue("ldif_install"):
|
|
2e0a7cb1 | Sylvain L. Sauvage | self.addLdifs()
|
|
8fd1d584 | Rémy Ménard | msg = "Don't forget to add index on the alias attribute (DN of user certificate used when this DN is incompatible with the LDAP tree)\n"
|
|
msg += "In your actual configuration, this attribute is: " + self.cget("attribute_alias") + "\n"
|
|||
msg += "See the INSTALL file"
|
|||
utils.putWarning(msg)
|
|||
96454bcd | Sylvain L. Sauvage | ||
2e0a7cb1 | Sylvain L. Sauvage | def createLdifs(self):
|
|
utils.writeFile("Creating the schema as a ldif file (user.ldif)", "user.ldif", """
|
|||
dn: cn=user,cn=schema,cn=config
|
|||
objectClass: olcSchemaConfig
|
|||
cn: user
|
|||
bf9c3717 | Rémy Ménard | olcAttributeTypes: ( 1.1.2.1.1 NAME '%(owner)s' DESC 'Owner ID' SUP name )
|
|
olcAttributeTypes: ( 1.1.2.1.2 NAME '%(alias)s' DESC 'Alias DN' SUP name )
|
|||
olcObjectClasses: ( 1.1.2.2.1 NAME 'user' DESC 'Define user' SUP top STRUCTURAL MUST ( %(uid)s $ %(owner)s ) MAY ( %(alias)s ) )
|
|||
""" % {"uid": self.cget("user_id"), "owner": self.cget("attribute_owner"), "alias": self.cget("attribute_alias")})
|
|||
group_value = self.cget("user_group").split("=")[-1]
|
|||
2e0a7cb1 | Sylvain L. Sauvage | utils.writeFile("Creating the user group as a ldif file (usergroup.ldif)", "usergroup.ldif", """
|
|
bf9c3717 | Rémy Ménard | dn: %(group)s,%(dn)s
|
|
2e0a7cb1 | Sylvain L. Sauvage | objectclass: top
|
|
objectclass: organizationalUnit
|
|||
bf9c3717 | Rémy Ménard | ou: %(group_val)s
|
|
2e0a7cb1 | Sylvain L. Sauvage | description: users
|
|
bf9c3717 | Rémy Ménard | """ % {"group": self.cget("user_group"), "group_val": group_value, "dn": self.cget("base_dn")} )
|
|
2e0a7cb1 | Sylvain L. Sauvage | utils.writeFile("Creating the user 'superadmin' as a ldif file (superadmin.ldif)", "superadmin.ldif", """
|
|
bf9c3717 | Rémy Ménard | dn: %(uid)s=superadmin,%(group)s,%(dn)s
|
|
2e0a7cb1 | Sylvain L. Sauvage | objectclass: top
|
|
objectclass: user
|
|||
bf9c3717 | Rémy Ménard | %(uid)s: superadmin
|
|
%(owner)s: superadmin
|
|||
""" % {"uid": self.cget("user_id"), "group": self.cget("user_group"), "dn": self.cget("base_dn"), "owner": self.cget("attribute_owner")} )
|
|||
utils.writeFile("Creating the user '%(anonymous)s' as ldif file (anonymous.ldif)", "anonymous.ldif", """
|
|||
dn: %(uid)s=%(anonymous)s,%(group)s,%(dn)s
|
|||
2e0a7cb1 | Sylvain L. Sauvage | objectclass: top
|
|
objectclass: user
|
|||
bf9c3717 | Rémy Ménard | %(uid)s: %(anonymous)s
|
|
%(owner)s: anonymous
|
|||
""" % {"anonymous": CONFIG.get("global", "anonymous_user"), "uid": self.cget("user_id"), "group": self.cget("user_group"), "dn": self.cget("base_dn"), "owner": self.cget("attribute_owner")} )
|
|||
2e0a7cb1 | Sylvain L. Sauvage | ||
def addLdifs(self):
|
|||
utils.createLDAP("Adds the schema (user.ldif)", "user.ldif")
|
|||
utils.execLDAP("Adds the user group (usergroup.ldif)", "usergroup.ldif")
|
|||
utils.execLDAP("Adds the user 'superadmin'", "superadmin.ldif")
|
|||
utils.execLDAP("Adds the user 'anonymous'", "anonymous.ldif")
|