summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
Diffstat (limited to 'source4')
-rw-r--r--source4/scripting/ejs/smbcalls_sys.c30
-rw-r--r--source4/scripting/libjs/provision.js22
2 files changed, 34 insertions, 18 deletions
diff --git a/source4/scripting/ejs/smbcalls_sys.c b/source4/scripting/ejs/smbcalls_sys.c
index 4dc5045ff6..af51c815dc 100644
--- a/source4/scripting/ejs/smbcalls_sys.c
+++ b/source4/scripting/ejs/smbcalls_sys.c
@@ -171,16 +171,30 @@ static int ejs_sys_file_save(MprVarHandle eid, int argc, char **argv)
/*
+ initialise sys ejs subsystem
+*/
+static int ejs_sys_init(MprVarHandle eid, int argc, struct MprVar **argv)
+{
+ struct MprVar obj = mprObject("sys");
+
+ mprSetCFunction(&obj, "interfaces", ejs_sys_interfaces);
+ mprSetCFunction(&obj, "hostname", ejs_sys_hostname);
+ mprSetCFunction(&obj, "nttime", ejs_sys_nttime);
+ mprSetCFunction(&obj, "gmtime", ejs_sys_gmtime);
+ mprSetCFunction(&obj, "ldaptime", ejs_sys_ldaptime);
+ mprSetStringCFunction(&obj, "unlink", ejs_sys_unlink);
+ mprSetStringCFunction(&obj, "file_load", ejs_sys_file_load);
+ mprSetStringCFunction(&obj, "file_save", ejs_sys_file_save);
+
+ mpr_Return(eid, obj);
+ return 0;
+}
+
+
+/*
setup C functions that be called from ejs
*/
void smb_setup_ejs_system(void)
{
- ejsDefineCFunction(-1, "sys_interfaces", ejs_sys_interfaces, NULL, MPR_VAR_SCRIPT_HANDLE);
- ejsDefineCFunction(-1, "sys_hostname", ejs_sys_hostname, NULL, MPR_VAR_SCRIPT_HANDLE);
- ejsDefineCFunction(-1, "sys_nttime", ejs_sys_nttime, NULL, MPR_VAR_SCRIPT_HANDLE);
- ejsDefineCFunction(-1, "sys_gmtime", ejs_sys_gmtime, NULL, MPR_VAR_SCRIPT_HANDLE);
- ejsDefineCFunction(-1, "sys_ldaptime", ejs_sys_ldaptime, NULL, MPR_VAR_SCRIPT_HANDLE);
- ejsDefineStringCFunction(-1, "sys_unlink", ejs_sys_unlink, NULL, MPR_VAR_SCRIPT_HANDLE);
- ejsDefineStringCFunction(-1, "sys_file_load", ejs_sys_file_load, NULL, MPR_VAR_SCRIPT_HANDLE);
- ejsDefineStringCFunction(-1, "sys_file_save", ejs_sys_file_save, NULL, MPR_VAR_SCRIPT_HANDLE);
+ ejsDefineCFunction(-1, "sys_init", ejs_sys_init, NULL, MPR_VAR_SCRIPT_HANDLE);
}
diff --git a/source4/scripting/libjs/provision.js b/source4/scripting/libjs/provision.js
index 6d4e4a3bc0..06b6f03779 100644
--- a/source4/scripting/libjs/provision.js
+++ b/source4/scripting/libjs/provision.js
@@ -7,6 +7,8 @@
/* used to generate sequence numbers for records */
provision_next_usn = 1;
+sys = sys_init();
+
/*
find a user or group from a list of possibilities
*/
@@ -59,7 +61,7 @@ unixName: ${UNIXNAME}
*/
function nttime()
{
- return "" + sys_nttime();
+ return "" + sys.nttime();
}
/*
@@ -67,7 +69,7 @@ function nttime()
*/
function ldaptime()
{
- return sys_ldaptime(sys_nttime());
+ return sys.ldaptime(sys.nttime());
}
/*
@@ -75,7 +77,7 @@ function ldaptime()
*/
function datestring()
{
- var t = sys_gmtime(sys_nttime());
+ var t = sys.gmtime(sys.nttime());
return sprintf("%04u%02u%02u%02u",
t.tm_year+1900, t.tm_mon+1, t.tm_mday, t.tm_hour);
}
@@ -85,7 +87,7 @@ function datestring()
*/
function hostip()
{
- var list = sys_interfaces();
+ var list = sys.interfaces();
return list[0];
}
@@ -103,7 +105,7 @@ function nextusn()
*/
function hostname()
{
- var s = split(".", sys_hostname());
+ var s = split(".", sys.hostname());
return s[0];
}
@@ -123,9 +125,9 @@ function setup_ldb(ldif, dbname, subobj)
var db = lpGet("private dir") + "/" + dbname;
var src = lpGet("setup directory") + "/" + ldif;
- sys_unlink(db);
+ sys.unlink(db);
- var data = sys_file_load(src);
+ var data = sys.file_load(src);
data = data + extra;
data = substitute_var(data, subobj);
@@ -141,12 +143,12 @@ function setup_file(template, fname, subobj)
var f = lpGet("private dir") + "/" + fname;
var src = lpGet("setup directory") + "/" + template;
- sys_unlink(f);
+ sys.unlink(f);
- var data = sys_file_load(src);
+ var data = sys.file_load(src);
data = substitute_var(data, subobj);
- ok = sys_file_save(f, data);
+ ok = sys.file_save(f, data);
assert(ok);
}