r8640: continue the trend by moving the ejs random calls into an object
authorAndrew Tridgell <tridge@samba.org>
Wed, 20 Jul 2005 07:29:23 +0000 (07:29 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:29:48 +0000 (13:29 -0500)
(This used to be commit ed4fb68ef7c28e415408e923bd9eefcd2d60f355)

source4/scripting/ejs/smbcalls_rand.c
source4/scripting/libjs/provision.js
swat/install/newuser.esp

index 81473ad737664c53eb99ecba20fd29c4fc4dff58..043b9cca09a33b4a03e4d076373c1cc5fac0514a 100644 (file)
@@ -80,13 +80,24 @@ static int ejs_randsid(MprVarHandle eid, int argc, struct MprVar **argv)
        return 0;
 }
 
+/*
+  initialise random ejs subsystem
+*/
+static int ejs_random_init(MprVarHandle eid, int argc, struct MprVar **argv)
+{
+       struct MprVar *obj = mprInitObject(eid, "random", argc, argv);
+
+       mprSetCFunction(obj, "random", ejs_random);
+       mprSetCFunction(obj, "randpass", ejs_randpass);
+       mprSetCFunction(obj, "randguid", ejs_randguid);
+       mprSetCFunction(obj, "randsid", ejs_randsid);
+       return 0;
+}
+
 /*
   setup C functions that be called from ejs
 */
 void smb_setup_ejs_random(void)
 {
-       ejsDefineCFunction(-1, "random", ejs_random, NULL, MPR_VAR_SCRIPT_HANDLE);
-       ejsDefineCFunction(-1, "randpass", ejs_randpass, NULL, MPR_VAR_SCRIPT_HANDLE);
-       ejsDefineCFunction(-1, "randguid", ejs_randguid, NULL, MPR_VAR_SCRIPT_HANDLE);
-       ejsDefineCFunction(-1, "randsid", ejs_randsid, NULL, MPR_VAR_SCRIPT_HANDLE);
+       ejsDefineCFunction(-1, "random_init", ejs_random_init, NULL, MPR_VAR_SCRIPT_HANDLE);
 }
index e9a8aad0cca4d732947e39903ce2c6c67c5dcc74..58f0e1824083093f834ecc9d49a958139edfa2ce 100644 (file)
@@ -224,6 +224,7 @@ function provision_guess()
        var subobj = new Object();
        var nss = nss_init();
        var lp = loadparm_init();
+       random_init(local);
 
        subobj.REALM        = lp.get("realm");
        subobj.DOMAIN       = lp.get("workgroup");
@@ -277,6 +278,7 @@ function newuser(username, unixname, password, message)
        var lp = loadparm_init();
        var samdb = lp.get("sam database");
        var ldb = ldb_init();
+       random_init(local);
 
        /* connect to the sam */
        var ok = ldb.connect(samdb);
index 21a2cb361bf35ae1b8bb7e552340474b80705699..42c109df6bc58ff18f5ebd8409adb4b0bc8b5fc1 100644 (file)
@@ -9,6 +9,7 @@
 <%
 var f = FormObj("newuser", 3, 2);
 var i;
+var rand = random_init();
 
 f.element[0].label = "User Name";
 f.element[0].name  = "USERNAME";
@@ -29,7 +30,7 @@ if (form['submit'] == "Add" &&
                form.UNIXNAME = form.USERNAME;
        }
        if (form.PASSWORD == undefined) {
-               form.PASSWORD = randpass();
+               form.PASSWORD = rand.randpass();
        }
        newuser(form.USERNAME, form.UNIXNAME, form.PASSWORD, writefln);
 } else {