OpenLDAP provisioning tweaks
authorHoward Chu <hyc@symas.com>
Tue, 17 Sep 2013 22:38:42 +0000 (15:38 -0700)
committerNadezhda Ivanova <nivanova@samba.org>
Wed, 18 Sep 2013 19:39:51 +0000 (21:39 +0200)
Remove BerkeleyDB-specific setup.
Streamline cn=samba partition initialization - allow any backend type for it.
Use back-mdb instead of back-ldif for cn=samba partition

Signed-off-by: Howard Chu <hyc@symas.com>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Nadezhda Ivanova <nivanova@symas.com>
Autobuild-User(master): Nadezhda Ivanova <nivanova@samba.org>
Autobuild-Date(master): Wed Sep 18 21:39:51 CEST 2013 on sn-devel-104

python/samba/provision/backend.py
source4/setup/cn=replicator.ldif [deleted file]
source4/setup/cn=samba-admin.ldif [deleted file]
source4/setup/cn=samba.ldif
source4/setup/slapd.conf

index 5360ef4..af7f07f 100644 (file)
@@ -361,19 +361,13 @@ class OpenLDAPBackend(LDAPBackend):
                              schemadn=self.names.schemadn, files=[
                 setup_path("schema_samba4.ldif")])
 
-    def setup_db_config(self, dbdir):
-        """Setup a Berkeley database.
+    def setup_db_dir(self, dbdir):
+        """Create a database directory.
 
         :param dbdir: Database directory.
         """
-        from samba.provision import setup_path
-        if not os.path.isdir(os.path.join(dbdir, "bdb-logs")):
-            os.makedirs(os.path.join(dbdir, "bdb-logs"), 0700)
-            if not os.path.isdir(os.path.join(dbdir, "tmp")):
-                os.makedirs(os.path.join(dbdir, "tmp"), 0700)
-
-        setup_file(setup_path("DB_CONFIG"),
-            os.path.join(dbdir, "DB_CONFIG"), {"LDAPDBDIR": dbdir})
+        if not os.path.exists(dbdir):
+            os.makedirs(dbdir, 0700)
 
     def provision(self):
         from samba.provision import ProvisioningError, setup_path
@@ -420,6 +414,7 @@ class OpenLDAPBackend(LDAPBackend):
         mmr_syncrepl_domaindns_config = ""
         mmr_syncrepl_forestdns_config = ""
         mmr_syncrepl_user_config = ""
+        mmr_pass = ""
 
         if self.ol_mmr_urls is not None:
             # For now, make these equal
@@ -536,31 +531,23 @@ class OpenLDAPBackend(LDAPBackend):
                     "ADMIN_UID": str(os.getuid()),
                     "NOSYNC": nosync_config,})
 
-        self.setup_db_config(os.path.join(self.ldapdir, "db", "forestdns"))
-        self.setup_db_config(os.path.join(self.ldapdir, "db", "domaindns"))
-        self.setup_db_config(os.path.join(self.ldapdir, "db", "user"))
-        self.setup_db_config(os.path.join(self.ldapdir, "db", "config"))
-        self.setup_db_config(os.path.join(self.ldapdir, "db", "schema"))
-
-        if not os.path.exists(os.path.join(self.ldapdir, "db", "samba", "cn=samba")):
-            os.makedirs(os.path.join(self.ldapdir, "db", "samba", "cn=samba"), 0700)
-
-        setup_file(setup_path("cn=samba.ldif"),
-                   os.path.join(self.ldapdir, "db", "samba", "cn=samba.ldif"),
-                   { "UUID": str(uuid.uuid4()),
-                     "LDAPTIME": timestring(int(time.time()))} )
-        setup_file(setup_path("cn=samba-admin.ldif"),
-                   os.path.join(self.ldapdir, "db", "samba", "cn=samba", "cn=samba-admin.ldif"),
-                   {"LDAPADMINPASS_B64": b64encode(self.ldapadminpass),
-                    "UUID": str(uuid.uuid4()),
-                    "LDAPTIME": timestring(int(time.time()))} )
+        self.setup_db_dir(os.path.join(self.ldapdir, "db", "forestdns"))
+        self.setup_db_dir(os.path.join(self.ldapdir, "db", "domaindns"))
+        self.setup_db_dir(os.path.join(self.ldapdir, "db", "user"))
+        self.setup_db_dir(os.path.join(self.ldapdir, "db", "config"))
+        self.setup_db_dir(os.path.join(self.ldapdir, "db", "schema"))
+        self.setup_db_dir(os.path.join(self.ldapdir, "db", "samba"))
 
         if self.ol_mmr_urls is not None:
-            setup_file(setup_path("cn=replicator.ldif"),
-                       os.path.join(self.ldapdir, "db", "samba", "cn=samba", "cn=replicator.ldif"),
-                       {"MMR_PASSWORD_B64": b64encode(mmr_pass),
-                        "UUID": str(uuid.uuid4()),
-                        "LDAPTIME": timestring(int(time.time()))} )
+            mmr = ""
+        else:
+            mmr = "#"
+
+        cn_samba = read_and_sub_file(
+                    setup_path("cn=samba.ldif"),
+                            { "LDAPADMINPASS": self.ldapadminpass,
+                           "MMR_PASSWORD": mmr_pass,
+                           "MMR": mmr })
 
         mapping = "schema-map-openldap-2.3"
         backend_schema = "backend-schema.schema"
@@ -636,6 +623,11 @@ class OpenLDAPBackend(LDAPBackend):
         # Don't confuse the admin by leaving the slapd.conf around
         os.remove(self.slapdconf)
 
+        cn_samba_cmd = [self.slapd_path, "-Tadd", "-b", "cn=samba", "-F", self.olcdir]
+        p = subprocess.Popen(cn_samba_cmd, stdin=subprocess.PIPE, shell=False)
+        p.stdin.write(cn_samba)
+        p.communicate()
+
 
 class FDSBackend(LDAPBackend):
 
diff --git a/source4/setup/cn=replicator.ldif b/source4/setup/cn=replicator.ldif
deleted file mode 100644 (file)
index 6001456..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-dn: cn=replicator
-objectClass: top
-objectClass: person
-cn: replicator
-userPassword:: ${MMR_PASSWORD_B64}
-structuralObjectClass: person
-entryUUID: ${UUID}
-creatorsName:
-createTimestamp: ${LDAPTIME}
-entryCSN: 20080714010529.241039Z#000000#000#000000
-modifiersName:
-modifyTimestamp: ${LDAPTIME}
diff --git a/source4/setup/cn=samba-admin.ldif b/source4/setup/cn=samba-admin.ldif
deleted file mode 100644 (file)
index c59ffd9..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-dn: cn=samba-admin
-objectClass: top
-objectClass: person
-cn: samba-admin
-userPassword:: ${LDAPADMINPASS_B64}
-structuralObjectClass: person
-entryUUID: ${UUID}
-creatorsName:
-createTimestamp: ${LDAPTIME}
-entryCSN: 20080714010529.241038Z#000000#000#000000
-modifiersName:
-modifyTimestamp: ${LDAPTIME}
index 3be6242..79d806c 100644 (file)
@@ -2,10 +2,15 @@ dn: cn=Samba
 objectClass: top
 objectClass: container
 cn: Samba
-structuralObjectClass: container
-entryUUID: b1d4823a-e58c-102c-9f74-51b6d59a1b68
-creatorsName:
-createTimestamp: 20080714010529Z
-entryCSN: 20080714010529.194412Z#000000#000#000000
-modifiersName:
-modifyTimestamp: 20080714010529Z
+
+dn: cn=samba-admin,cn=samba
+objectClass: top
+objectClass: person
+cn: samba-admin
+userPassword: ${LDAPADMINPASS}
+
+${MMR}dn: cn=replicator,cn=samba
+${MMR}objectClass: top
+${MMR}objectClass: person
+${MMR}cn: replicator
+${MMR}userPassword: ${MMR_PASSWORD}
index 231ef82..91406b6 100644 (file)
@@ -65,7 +65,7 @@ ${MEMBEROF_CONFIG}
 
 moduleload syncprov
 
-database       ldif
+database       mdb
 suffix         cn=Samba
 directory       ${LDAPDIR}/db/samba
 rootdn          cn=Manager,cn=Samba