From 4298fab790cd8f8f4f6d5c0226934847d67a2c08 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 1 Nov 2005 07:07:48 +0000 Subject: r11436: this is work in progress for generating the schema we need for our ADS ldap server. It's still not quite right, and I'm chasing down a few errors that mmc throws up, but its a lot closer than it was. I had to change the approach quite substantially over the last couple of days, but this approach now seems to be working out. (This used to be commit 38ea11510c8824285d072fe0e03e443d9d584271) --- testprogs/ejs/minschema.js | 525 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 507 insertions(+), 18 deletions(-) (limited to 'testprogs') diff --git a/testprogs/ejs/minschema.js b/testprogs/ejs/minschema.js index 97697c021a..b2daea51c4 100755 --- a/testprogs/ejs/minschema.js +++ b/testprogs/ejs/minschema.js @@ -1,8 +1,7 @@ #!/bin/sh exec smbscript "$0" ${1+"$@"} /* - work out the minimal schema for the existing records on a server by examining - all records and working out what objectclasses and attributes exist + work out the minimal schema for a set of objectclasses */ libinclude("base.js"); @@ -12,19 +11,21 @@ var ldb = ldb_init(); var options = GetOptions(ARGV, "POPT_AUTOHELP", "POPT_COMMON_SAMBA", - "POPT_COMMON_CREDENTIALS"); + "POPT_COMMON_CREDENTIALS", + "verbose"); if (options == undefined) { println("Failed to parse options"); return -1; } +verbose = options["verbose"]; -if (options.ARGV.length != 1) { - println("Usage: minschema.js "); +if (options.ARGV.length != 2) { + println("Usage: minschema.js "); return -1; } var url = options.ARGV[0]; - +var classfile = options.ARGV[1]; var ok = ldb.connect(url); @@ -32,6 +33,249 @@ assert(ok); objectclasses = new Object(); attributes = new Object(); +rootDse = new Object(); + + +/* the attributes we need for objectclasses */ +class_attrs = new Array("objectClass", + "auxiliaryClass", "systemAuxiliaryClass", + "possSuperiors", "systemPossSuperiors", + "lDAPDisplayName", "governsID", + "rDNAttID", "mustContain", "systemMustContain", + "mayContain", "systemMayContain", + "objectClassCategory", "subClassOf", + "defaultObjectCategory", "defaultHidingValue", + "systemFlags", "systemOnly", "defaultSecurityDescriptor", + "objectCategory"); + +attrib_attrs = new Array("objectClass", "lDAPDisplayName", + "isSingleValued", "linkID", "systemFlags", "systemOnly", + "schemaIDGUID", "adminDisplayName", "attributeID", + "attributeSyntax"); + +/* + notes: + + objectClassCategory + 1: structural + 2: abstract + 3: auxiliary +*/ + + +/* + print only if verbose is set +*/ +function dprintf() { + if (verbose != undefined) { + print(vsprintf(arguments)); + } +} + +/* + create an objectclass object +*/ +function obj_objectClass(name) { + var o = new Object(); + o.name = name; + return o; +} + +/* + create an attribute object +*/ +function obj_attribute(name) { + var o = new Object(); + o.name = name; + return o; +} + + +/* + fix a string DN to use ${BASEDN} +*/ +function fix_dn(dn) { + var s = strstr(dn, rootDse.defaultNamingContext); + if (s == NULL) { + return dn; + } + return substr(dn, 0, strlen(dn) - strlen(s)) + "${BASEDN}"; +} + +/* + dump an object as ldif +*/ +function write_ldif_one(o, attrs) { + var i; + printf("dn: CN=%s,CN=Schema,CN=Configuration,${BASEDN}\n", o.name); + printf("name: %s\n", o.name); + for (i=0;i