s4:upgrade.py - Umlaut problem
[ira/wip.git] / source4 / scripting / python / samba / upgrade.py
index 01b62ff984050abf54b0b671b47d989803e24d97..3c45245113ba0694ea96baa6f2f1c81fca57cd1f 100644 (file)
@@ -2,22 +2,24 @@
 #
 #      backend code for upgrading from Samba3
 #      Copyright Jelmer Vernooij 2005-2007
+#      Copyright Matthias Dieter Wallnoefer 2009
 #      Released under the GNU GPL v3 or later
 #
 
 """Support code for upgrading from Samba 3 to Samba 4."""
 
-from provision import findnss, provision, FILL_DRS
+__docformat__ = "restructuredText"
+
+from provision import provision
 import grp
 import ldb
 import time
 import pwd
-import uuid
 import registry
 from samba import Ldb
-from samba.samdb import SamDB
+from samba.param import LoadParm
 
-def import_sam_policy(samldb, samba3_policy, domaindn):
+def import_sam_policy(samldb, policy, dn):
     """Import a Samba 3 policy database."""
     samldb.modify_ldif("""
 dn: %s
@@ -91,7 +93,6 @@ def import_sam_account(samldb,acc,domaindn,domainsid):
         "ntPwdHash:": acc.nt_password,
         })
 
-
 def import_sam_group(samldb, sid, gid, sid_name_use, nt_name, comment, domaindn):
     """Upgrade a SAM group.
     
@@ -131,7 +132,6 @@ def import_sam_group(samldb, sid, gid, sid_name_use, nt_name, comment, domaindn)
         "samba3SidNameUse": str(sid_name_use)
         })
 
-
 def import_idmap(samdb,samba3_idmap,domaindn):
     """Import idmap data.
 
@@ -156,7 +156,6 @@ def import_idmap(samdb,samba3_idmap,domaindn):
                           "type": "group",
                           "unixID": str(gid)})
 
-
 def import_wins(samba4_winsdb, samba3_winsdb):
     """Import settings from a Samba3 WINS database.
     
@@ -207,78 +206,6 @@ def import_wins(samba4_winsdb, samba3_winsdb):
                        "objectClass": "winsMaxVersion",
                        "maxVersion": str(version_id)})
 
-def upgrade_provision(samba3, setup_dir, message, credentials, session_info, lp, paths):
-    oldconf = samba3.get_conf()
-
-    if oldconf.get("domain logons") == "True":
-        serverrole = "domain controller"
-    else:
-        if oldconf.get("security") == "user":
-            serverrole = "standalone"
-        else:
-            serverrole = "member server"
-
-    lp.set("server role", serverrole)
-    domainname = oldconf.get("workgroup")
-    if domainname:
-        domainname = str(domainname)
-    lp.set("workgroup", domainname)
-    realm = oldconf.get("realm")
-    netbiosname = oldconf.get("netbios name")
-
-    secrets_db = samba3.get_secrets_db()
-    
-    if domainname is None:
-        domainname = secrets_db.domains()[0]
-        message("No domain specified in smb.conf file, assuming '%s'" % domainname)
-    
-    if realm is None:
-        realm = domainname.lower()
-        message("No realm specified in smb.conf file, assuming '%s'\n" % realm)
-    lp.set("realm", realm)
-
-    domainguid = secrets_db.get_domain_guid(domainname)
-    domainsid = secrets_db.get_sid(domainname)
-    if domainsid is None:
-        message("Can't find domain secrets for '%s'; using random SID\n" % domainname)
-    
-    if netbiosname is not None:
-        machinepass = secrets_db.get_machine_password(netbiosname)
-    else:
-        machinepass = None
-    
-    domaindn = provision(lp=lp, setup_dir=setup_dir, message=message, 
-                         samdb_fill=FILL_DRS, paths=paths, session_info=session_info, 
-                         credentials=credentials, realm=realm, 
-                         domain=domainname, domainsid=domainsid, domainguid=domainguid, 
-                         machinepass=machinepass, serverrole=serverrole)
-
-    samdb = SamDB(paths.samdb, credentials=credentials, lp=lp, session_info=session_info)
-
-    import_wins(Ldb(paths.winsdb), samba3.get_wins_db())
-
-    # FIXME: import_registry(registry.Registry(), samba3.get_registry())
-
-    # FIXME: import_idmap(samdb,samba3.get_idmap_db(),domaindn)
-    
-    groupdb = samba3.get_groupmapping_db()
-    for sid in groupdb.groupsids():
-        (gid, sid_name_use, nt_name, comment) = groupdb.get_group(sid)
-        # FIXME: import_sam_group(samdb, sid, gid, sid_name_use, nt_name, comment, domaindn)
-
-    # FIXME: Aliases
-
-    passdb = samba3.get_sam_db()
-    for name in passdb:
-        user = passdb[name]
-        #FIXME: import_sam_account(samdb, user, domaindn, domainsid)
-
-    if hasattr(passdb, 'ldap_url'):
-        message("Enabling Samba3 LDAP mappings for SAM database")
-
-        enable_samba3sam(samdb, passdb.ldap_url)
-
-
 def enable_samba3sam(samdb, ldapurl):
     """Enable Samba 3 LDAP URL database.
 
@@ -294,7 +221,6 @@ replace: @LIST
 
     samdb.add({"dn": "@MAP=samba3sam", "@MAP_URL": ldapurl})
 
-
 smbconf_keep = [
     "dos charset", 
     "unix charset",
@@ -397,7 +323,7 @@ def upgrade_smbconf(oldconf,mark):
         kept in the new configuration as "samba3:<name>"
     """
     data = oldconf.data()
-    newconf = param_init()
+    newconf = LoadParm()
 
     for s in data:
         for p in data[s]:
@@ -438,3 +364,73 @@ def import_registry(samba4_registry, samba3_regdb):
             key_handle.set_value(value_name, value_type, value_data)
 
 
+def upgrade_provision(samba3, setup_dir, message, credentials, session_info,
+                      smbconf, targetdir):
+    oldconf = samba3.get_conf()
+
+    if oldconf.get("domain logons") == "True":
+        serverrole = "domain controller"
+    else:
+        if oldconf.get("security") == "user":
+            serverrole = "standalone"
+        else:
+            serverrole = "member server"
+
+    domainname = oldconf.get("workgroup")
+    realm = oldconf.get("realm")
+    netbiosname = oldconf.get("netbios name")
+
+    secrets_db = samba3.get_secrets_db()
+    
+    if domainname is None:
+        domainname = secrets_db.domains()[0]
+        message("No domain specified in smb.conf file, assuming '%s'" % domainname)
+    
+    if realm is None:
+        if oldconf.get("domain logons") == "True":
+            message("No realm specified in smb.conf file and being a DC. That upgrade path doesn't work! Please add a 'realm' directive to your old smb.conf to let us know which one you want to use (generally it's the upcased DNS domainname).")
+            return
+        else:
+            realm = domainname.upper()
+            message("No realm specified in smb.conf file, assuming '%s'" % realm)
+
+    domainguid = secrets_db.get_domain_guid(domainname)
+    domainsid = secrets_db.get_sid(domainname)
+    if domainsid is None:
+        message("Can't find domain secrets for '%s'; using random SID" % domainname)
+    
+    if netbiosname is not None:
+        machinepass = secrets_db.get_machine_password(netbiosname)
+    else:
+        machinepass = None
+
+    result = provision(setup_dir=setup_dir, message=message, 
+                       session_info=session_info, credentials=credentials,
+                       targetdir=targetdir, realm=realm, domain=domainname,
+                       domainguid=domainguid, domainsid=domainsid,
+                       hostname=netbiosname, machinepass=machinepass,
+                       serverrole=serverrole)
+
+    # FIXME: import_wins(Ldb(result.paths.winsdb), samba3.get_wins_db())
+
+    # FIXME: import_registry(registry.Registry(), samba3.get_registry())
+
+    # FIXME: import_idmap(samdb,samba3.get_idmap_db(),domaindn)
+    
+    groupdb = samba3.get_groupmapping_db()
+    for sid in groupdb.groupsids():
+        (gid, sid_name_use, nt_name, comment) = groupdb.get_group(sid)
+        # FIXME: import_sam_group(samdb, sid, gid, sid_name_use, nt_name, comment, domaindn)
+
+    # FIXME: Aliases
+
+    passdb = samba3.get_sam_db()
+    for name in passdb:
+        user = passdb[name]
+        #FIXME: import_sam_account(result.samdb, user, domaindn, domainsid)
+
+    if hasattr(passdb, 'ldap_url'):
+        message("Enabling Samba3 LDAP mappings for SAM database")
+
+        enable_samba3sam(result.samdb, passdb.ldap_url)
+