#!/bin/sh exec smbscript "$0" ${1+"$@"} /* work out the minimal schema for a set of objectclasses */ libinclude("base.js"); var ldb = ldb_init(); var options = GetOptions(ARGV, "POPT_AUTOHELP", "POPT_COMMON_SAMBA", "POPT_COMMON_CREDENTIALS", "verbose"); if (options == undefined) { println("Failed to parse options"); return -1; } verbose = options["verbose"]; if (options.ARGV.length != 2) { println("Usage: minschema.js "); return -1; } var url = options.ARGV[0]; var classfile = options.ARGV[1]; /* use command line creds if available */ ldb.credentials = options.get_credentials(); var ok = ldb.connect(url); 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", "possibleInferiors", "displaySpecification", "schemaIDGUID"); attrib_attrs = new Array("objectClass", "lDAPDisplayName", "isSingleValued", "linkID", "systemFlags", "systemOnly", "schemaIDGUID", "adminDisplayName", "attributeID", "attributeSyntax", "oMSyntax", "oMObjectClass"); /* notes: objectClassCategory 1: structural 2: abstract 3: auxiliary */ /* print only if verbose is set */ function dprintf() { if (verbose != undefined) { print(vsprintf(arguments)); } } function get_object_cn(ldb, name) { var attrs = new Array("cn"); var res = ldb.search(sprintf("(ldapDisplayName=%s)", name), rootDse.schemaNamingContext, ldb.SCOPE_SUBTREE, attrs); assert(res != undefined); assert(res.length == 1); var cn = res[0]["cn"]; assert(cn != undefined); if (typeof(cn) == "string") { return cn; } return cn[0]; } /* create an objectclass object */ function obj_objectClass(ldb, name) { var o = new Object(); o.name = name; o.cn = get_object_cn(ldb, name); return o; } /* create an attribute object */ function obj_attribute(ldb, name) { var o = new Object(); o.name = name; o.cn = get_object_cn(ldb, name); return o; } syntaxmap = new Object(); syntaxmap['2.5.5.1'] = '1.3.6.1.4.1.1466.115.121.1.12'; syntaxmap['2.5.5.2'] = '1.3.6.1.4.1.1466.115.121.1.38'; syntaxmap['2.5.5.3'] = '1.2.840.113556.1.4.1362'; syntaxmap['2.5.5.4'] = '1.2.840.113556.1.4.905'; syntaxmap['2.5.5.5'] = '1.3.6.1.4.1.1466.115.121.1.26'; syntaxmap['2.5.5.6'] = '1.3.6.1.4.1.1466.115.121.1.36'; syntaxmap['2.5.5.7'] = '1.2.840.113556.1.4.903'; syntaxmap['2.5.5.8'] = '1.3.6.1.4.1.1466.115.121.1.7'; syntaxmap['2.5.5.9'] = '1.3.6.1.4.1.1466.115.121.1.27'; syntaxmap['2.5.5.10'] = '1.3.6.1.4.1.1466.115.121.1.40'; syntaxmap['2.5.5.11'] = '1.3.6.1.4.1.1466.115.121.1.24'; syntaxmap['2.5.5.12'] = '1.3.6.1.4.1.1466.115.121.1.15'; syntaxmap['2.5.5.13'] = '1.3.6.1.4.1.1466.115.121.1.43'; syntaxmap['2.5.5.14'] = '1.2.840.113556.1.4.904'; syntaxmap['2.5.5.15'] = '1.2.840.113556.1.4.907'; syntaxmap['2.5.5.16'] = '1.2.840.113556.1.4.906'; syntaxmap['2.5.5.17'] = '1.3.6.1.4.1.1466.115.121.1.40'; /* map some attribute syntaxes from some apparently MS specific syntaxes to the standard syntaxes */ function map_attribute_syntax(s) { if (syntaxmap[s] != undefined) { return syntaxmap[s]; } return s; } /* 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.cn); printf("cn: %s\n", o.cn); printf("name: %s\n", o.cn); for (i=0;i