summaryrefslogtreecommitdiff
path: root/source4/scripting/libjs
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2005-07-18 23:58:18 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:29:37 -0500
commit09fb6d2280187527898ae5af9c266c7474901dac (patch)
tree0596f22070826cf11e6e0be250c42940099db063 /source4/scripting/libjs
parent0752efe05554de05eea1812a4dd721692ca8bf95 (diff)
downloadsamba-09fb6d2280187527898ae5af9c266c7474901dac.tar.gz
samba-09fb6d2280187527898ae5af9c266c7474901dac.tar.bz2
samba-09fb6d2280187527898ae5af9c266c7474901dac.zip
r8558: move newuser logic into the provision.js lib
(This used to be commit b6ef32ddd1fdca0d40a12f34fa5f7a484b3c2071)
Diffstat (limited to 'source4/scripting/libjs')
-rw-r--r--source4/scripting/libjs/provision.js84
1 files changed, 84 insertions, 0 deletions
diff --git a/source4/scripting/libjs/provision.js b/source4/scripting/libjs/provision.js
index bf39bcb992..c7fb1b5fc5 100644
--- a/source4/scripting/libjs/provision.js
+++ b/source4/scripting/libjs/provision.js
@@ -226,4 +226,88 @@ function provision_guess()
return subobj;
}
+/*
+ search for one attribute as a string
+ */
+function searchone(ldb, expression, attribute)
+{
+ var attrs = new Array(attribute);
+ res = ldb.search(expression, attrs);
+ if (res.length != 1 ||
+ res[0][attribute] == undefined) {
+ return undefined;
+ }
+ return res[0][attribute];
+}
+
+/*
+ add a new user record
+*/
+function newuser(username, unixname, password, message)
+{
+ var samdb = lpGet("sam database");
+ var ldb = ldb_init();
+
+ /* connect to the sam */
+ var ok = ldb.connect(samdb);
+ assert(ok);
+
+ /* find the DNs for the domain and the domain users group */
+ var domain_dn = searchone(ldb, "objectClass=domainDNS", "dn");
+ assert(domain_dn != undefined);
+ var dom_users = searchone(ldb, "name=Domain Users", "dn");
+ assert(dom_users != undefined);
+
+ var user_dn = sprintf("CN=%s,CN=Users,%s", username, domain_dn);
+
+
+ /*
+ the new user record. note the reliance on the samdb module to fill
+ in a sid, guid etc
+ */
+ var ldif = sprintf("
+dn: %s
+sAMAccountName: %s
+name: %s
+memberOf: %s
+unixName: %s
+objectGUID: %s
+unicodePwd: %s
+objectClass: user
+",
+ user_dn, username, username, dom_users,
+ unixname, randguid(), password);
+ /*
+ add the user to the users group as well
+ */
+ var modgroup = sprintf("
+dn: %s
+changetype: modify
+add: member
+member: %s
+",
+ dom_users, user_dn);
+
+
+ /*
+ now the real work
+ */
+ message("Adding user %s\n", user_dn);
+ ok = ldb.add(ldif);
+ if (ok != true) {
+ message("Failed to add %s - %s\n", user_dn, ldb.errstring());
+ return false;
+ }
+
+ message("Modifying group %s\n", dom_users);
+ ok = ldb.modify(modgroup);
+ if (ok != true) {
+ message("Failed to modify %s - %s\n", dom_users, ldb.errstring());
+ return false;
+ }
+
+ return true;
+}
+
+
return 0;