summaryrefslogtreecommitdiff
path: root/testprogs/ejs
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2005-10-14 07:38:16 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:39:51 -0500
commit840364eb9772448a5ff8e64eac58dd43b97550d6 (patch)
tree11f188c66c062d3c18885fc8a7326a3faced0f00 /testprogs/ejs
parent94473233fe8ae7f663d4872eb1d9f25f08afadb9 (diff)
downloadsamba-840364eb9772448a5ff8e64eac58dd43b97550d6.tar.gz
samba-840364eb9772448a5ff8e64eac58dd43b97550d6.tar.bz2
samba-840364eb9772448a5ff8e64eac58dd43b97550d6.zip
r10990: the beginnings of a program designed to work out the minimal schema
needed to represent all the current records on a ADS LDAP server. The idea is we will use something based on this code to work out exactly what schema elements we will need for our initial ADS schema. I plan on expanding this code to automatically work out attribute properties, and write out a schema file that we can load into ldb. Interestingly, it looks like we only need 43 objectclasses and around 200 attributes to represent all records of a newly installed w2k3 ADS server. (This used to be commit 7b0ae77757d347d2b0f5bac3a49e915e24c3ab78)
Diffstat (limited to 'testprogs/ejs')
-rwxr-xr-xtestprogs/ejs/minschema.js112
1 files changed, 112 insertions, 0 deletions
diff --git a/testprogs/ejs/minschema.js b/testprogs/ejs/minschema.js
new file mode 100755
index 0000000000..97697c021a
--- /dev/null
+++ b/testprogs/ejs/minschema.js
@@ -0,0 +1,112 @@
+#!/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
+*/
+
+libinclude("base.js");
+
+var ldb = ldb_init();
+
+var options = GetOptions(ARGV,
+ "POPT_AUTOHELP",
+ "POPT_COMMON_SAMBA",
+ "POPT_COMMON_CREDENTIALS");
+if (options == undefined) {
+ println("Failed to parse options");
+ return -1;
+}
+
+if (options.ARGV.length != 1) {
+ println("Usage: minschema.js <URL>");
+ return -1;
+}
+
+var url = options.ARGV[0];
+
+
+
+var ok = ldb.connect(url);
+assert(ok);
+
+objectclasses = new Object();
+attributes = new Object();
+
+
+/*
+ process an individual record, working out what attributes it has
+*/
+function walk_dn(ldb, dn) {
+ /* get a list of all possible attributes for this object */
+ var attrs = new Array("allowedAttributes");
+ var res = ldb.search("objectClass=*", dn, ldb.SCOPE_BASE, attrs);
+ if (res == undefined) {
+ printf("Unable to fetch allowedAttributes for '%s' - %s\n",
+ dn, ldb.errstring());
+ return;
+ }
+ var allattrs = res[0].allowedAttributes;
+ res = ldb.search("objectClass=*", dn, ldb.SCOPE_BASE, allattrs);
+ if (res == undefined) {
+ printf("Unable to fetch all attributes for '%s' - %s\n",
+ dn, ldb.errstring());
+ return;
+ }
+ var a;
+ var msg = res[0];
+ for (a in msg) {
+ attributes[a] = a;
+ }
+}
+
+/*
+ walk a naming context, looking for all records
+*/
+function walk_naming_context(ldb, namingContext) {
+ var attrs = new Array("objectClass");
+ var res = ldb.search("objectClass=*", namingContext, ldb.SCOPE_DEFAULT, attrs);
+ if (res == undefined) {
+ printf("Unable to fetch objectClasses for '%s' - %s\n",
+ namingContext, ldb.errstring());
+ return;
+ }
+ var r;
+ for (r=0;r<res.length;r++) {
+ var msg = res[r].objectClass;
+ var c;
+ for (c=0;c<msg.length;c++) {
+ var objectClass = msg[c];
+ objectclasses[objectClass] = objectClass;
+ }
+ walk_dn(ldb, res[r].dn);
+ }
+}
+
+/*
+ get a list of naming contexts
+*/
+var attrs = new Array("namingContexts");
+var res = ldb.search("", "", ldb.SCOPE_BASE, attrs);
+var namingContexts = res[0].namingContexts;
+
+/*
+ walk the naming contexts, gathering objectclass values and attribute names
+*/
+for (var c=0;c<namingContexts.length;c++) {
+ walk_naming_context(ldb, namingContexts[c]);
+}
+
+/*
+ dump list of objectclasses
+*/
+printf("objectClasses:\n")
+for (i in objectclasses) {
+ printf("\t%s\n", i);
+}
+printf("attributes:\n")
+for (i in attributes) {
+ printf("\t%s\n", i);
+}
+
+return 0;