Merge branch 'master' into wspp-schema
authorAndrew Tridgell <tridge@samba.org>
Tue, 31 Mar 2009 00:58:37 +0000 (11:58 +1100)
committerAndrew Tridgell <tridge@samba.org>
Tue, 31 Mar 2009 00:58:37 +0000 (11:58 +1100)
1  2 
source4/scripting/python/samba/provision.py

index 1e34b11d0a0622abe8cf43c189e64bb53bf64b34,896f237bd79fdabc3cc8b0846e14b5f9011bfa3e..64908ccb4d3603b4fc9a965e560d13fd7da1290e
@@@ -44,7 -44,6 +44,7 @@@ from samba.dcerpc import securit
  import urllib
  from ldb import SCOPE_SUBTREE, SCOPE_ONELEVEL, SCOPE_BASE, LdbError, \
          timestring, CHANGETYPE_MODIFY, CHANGETYPE_NONE
 +from ms_schema import read_ms_schema
  
  __docformat__ = "restructuredText"
  
@@@ -784,8 -783,10 +784,8 @@@ def setup_samdb(path, setup_path, sessi
      if serverrole == "domain controller":
          samdb.set_invocation_id(invocationid)
  
 -    load_schema(setup_path, samdb, names.schemadn, names.netbiosname, 
 -                names.configdn, names.sitename, names.serverdn,
 -                names.hostname)
 -
 +    schema_data = load_schema(setup_path, samdb, names.schemadn, names.netbiosname, 
 +                              names.configdn, names.sitename, names.serverdn)
      samdb.transaction_start()
          
      try:
              "PREFIXMAP_B64": b64encode(prefixmap)
              })
  
 -        message("Setting up sam.ldb Samba4 schema")
 -        setup_add_ldif(samdb, setup_path("schema_samba4.ldif"), 
 -                       {"SCHEMADN": names.schemadn })
 -        message("Setting up sam.ldb AD schema")
 -        setup_add_ldif(samdb, setup_path("schema.ldif"), 
 -                       {"SCHEMADN": names.schemadn})
 +        message("Setting up sam.ldb schema")
 +        samdb.add_ldif(schema_data)
          setup_add_ldif(samdb, setup_path("aggregate_schema.ldif"), 
                         {"SCHEMADN": names.schemadn})
  
@@@ -1051,7 -1056,7 +1051,7 @@@ def provision(setup_dir, message, sessi
                          serverrole=serverrole, ldap_backend=ldap_backend, 
                          ldap_backend_type=ldap_backend_type)
  
-     if lp.get("server role") == "domain controller":
+     if serverrole == "domain controller":
          if paths.netlogon is None:
              message("Existing smb.conf does not have a [netlogon] share, but you are configuring a DC.")
              message("Please either remove %s or see the template at %s" % 
@@@ -1244,33 -1249,28 +1244,33 @@@ def provision_backend(setup_dir=None, m
      except OSError:
          pass
  
 -    schemadb = Ldb(schemadb_path, lp=lp)
 +    schemadb = SamDB(schemadb_path, lp=lp)
 +    schemadb.transaction_start()
 +    try:
   
 -    prefixmap = open(setup_path("prefixMap.txt"), 'r').read()
 +        prefixmap = open(setup_path("prefixMap.txt"), 'r').read()
  
 -    setup_add_ldif(schemadb, setup_path("provision_schema_basedn.ldif"), 
 -                   {"SCHEMADN": names.schemadn,
 -                    "ACI": "#",
 -                    })
 -    setup_modify_ldif(schemadb, 
 -                      setup_path("provision_schema_basedn_modify.ldif"), \
 -                          {"SCHEMADN": names.schemadn,
 -                           "NETBIOSNAME": names.netbiosname,
 -                           "DEFAULTSITE": DEFAULTSITE,
 -                           "CONFIGDN": names.configdn,
 -                           "SERVERDN": names.serverdn,
 -                           "PREFIXMAP_B64": b64encode(prefixmap)
 -                           })
 -    
 -    setup_add_ldif(schemadb, setup_path("schema_samba4.ldif"), 
 -                   {"SCHEMADN": names.schemadn })
 -    setup_add_ldif(schemadb, setup_path("schema.ldif"), 
 -                   {"SCHEMADN": names.schemadn})
 +        setup_add_ldif(schemadb, setup_path("provision_schema_basedn.ldif"), 
 +                       {"SCHEMADN": names.schemadn,
 +                        "ACI": "#",
 +                        })
 +        setup_modify_ldif(schemadb, 
 +                          setup_path("provision_schema_basedn_modify.ldif"), \
 +                              {"SCHEMADN": names.schemadn,
 +                               "NETBIOSNAME": names.netbiosname,
 +                               "DEFAULTSITE": DEFAULTSITE,
 +                               "CONFIGDN": names.configdn,
 +                               "SERVERDN": names.serverdn,
 +                               "PREFIXMAP_B64": b64encode(prefixmap)
 +                               })
 +        
 +        data = load_schema(setup_path, schemadb, names.schemadn, names.netbiosname, 
 +                           names.configdn, DEFAULTSITE, names.serverdn)
 +        schemadb.add_ldif(data)
 +    except:
 +        schemadb.transaction_cancel()
 +        raise
 +    schemadb.transaction_commit()
  
      if ldap_backend_type == "fedora-ds":
          if ldap_backend_port is not None:
  
          ldapuser = "--username=samba-admin"
  
 -            
 -    schema_command = "bin/ad2oLschema --option=convert:target=" + ldap_backend_type + " -I " + setup_path(mapping) + " -H tdb://" + schemadb_path + " -O " + os.path.join(paths.ldapdir, backend_schema)
 -            
 -    os.system(schema_command)
 +
 +    backend_schema_data = schemadb.convert_schema_to_openldap(ldap_backend_type, open(setup_path(mapping), 'r').read())
 +    assert backend_schema_data is not None
 +    open(os.path.join(paths.ldapdir, backend_schema), 'w').write(backend_schema_data)
  
      message("Your %s Backend for Samba4 is now configured, and is ready to be started" % ldap_backend_type)
      message("Server Role:         %s" % serverrole)
@@@ -1649,7 -1649,7 +1649,7 @@@ def create_krb5_conf(path, setup_path, 
  
  
  def load_schema(setup_path, samdb, schemadn, netbiosname, configdn, sitename,
 -                serverdn, servername):
 +                serverdn):
      """Load schema for the SamDB.
      
      :param samdb: Load a schema into a SamDB.
      :param netbiosname: NetBIOS name of the host.
      :param configdn: DN of the configuration
      :param serverdn: DN of the server
 -    :param servername: Host name of the server
 +
 +    Returns the schema data loaded, to avoid double-parsing when then needing to add it to the db
      """
 -    schema_data = open(setup_path("schema.ldif"), 'r').read()
 +    schema_data = get_schema_data(setup_path, {"SCHEMADN": schemadn})
      schema_data += open(setup_path("schema_samba4.ldif"), 'r').read()
      schema_data = substitute_var(schema_data, {"SCHEMADN": schemadn})
      check_all_substituted(schema_data)
                      "DEFAULTSITE": sitename,
                      "PREFIXMAP_B64": prefixmap,
                      "SERVERDN": serverdn,
 -                    "SERVERNAME": servername,
      })
      check_all_substituted(head_data)
      samdb.attach_schema_from_ldif(head_data, schema_data)
 +    return schema_data;
 +
 +def get_schema_data(setup_path, subst_vars = None):
 +    """Get schema data from the AD schema files instead of schema.ldif.
 +
 +    :param setup_path: Setup path function.
 +    :param subst_vars: Optional variables to substitute in the file.
 +
 +    Returns the schema data after substitution
 +    """ 
  
 +    # this data used to be read from schema.ldif
 +    
 +    data = read_ms_schema(setup_path('ad-schema/MS-AD_Schema_2K8Attributes.txt'),
 +                          setup_path('ad-schema/MS-AD_Schema_2K8Classes.txt'))
 +
 +    if subst_vars is not None:
 +        data = substitute_var(data, subst_vars)
 +    check_all_substituted(data)
 +    return data