diff options
author | Andrew Tridgell <tridge@samba.org> | 2005-07-12 02:34:49 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:20:07 -0500 |
commit | b1e93b296ea8f62ce0f15ccef5f6ae5339f4929f (patch) | |
tree | 2ba5c18f14d374a29a79061ee17b7dff28186355 /source4/scripting/ejs/smbcalls_sys.c | |
parent | 36bb0ffd4c59b17c7f942d874e18865707d3c696 (diff) | |
download | samba-b1e93b296ea8f62ce0f15ccef5f6ae5339f4929f.tar.gz samba-b1e93b296ea8f62ce0f15ccef5f6ae5339f4929f.tar.bz2 samba-b1e93b296ea8f62ce0f15ccef5f6ae5339f4929f.zip |
r8337: - use 64 bit access functions in ejs calls
- added access to smbd random functions
- fixed ordering in join()
- added sys_interfaces(), sys_hostname(), sys_nttime() and sys_ldaptime()
(This used to be commit 28c1a1f3c0cd2f8228fd8c3c695ab6f45226fa3f)
Diffstat (limited to 'source4/scripting/ejs/smbcalls_sys.c')
-rw-r--r-- | source4/scripting/ejs/smbcalls_sys.c | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/source4/scripting/ejs/smbcalls_sys.c b/source4/scripting/ejs/smbcalls_sys.c new file mode 100644 index 0000000000..a76690b597 --- /dev/null +++ b/source4/scripting/ejs/smbcalls_sys.c @@ -0,0 +1,95 @@ +/* + Unix SMB/CIFS implementation. + + provide access to system functions + + Copyright (C) Andrew Tridgell 2005 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" +#include "scripting/ejs/smbcalls.h" +#include "lib/ejs/ejs.h" + +/* + return the list of configured network interfaces +*/ +static int ejs_sys_interfaces(MprVarHandle eid, int argc, struct MprVar **argv) +{ + int i, count = iface_count(); + struct MprVar ret = mprObject("interfaces"); + for (i=0;i<count;i++) { + mprAddArray(&ret, i, mprString(iface_n_ip(i))); + } + mpr_Return(eid, ret); + return 0; +} + +/* + return the hostname from gethostname() +*/ +static int ejs_sys_hostname(MprVarHandle eid, int argc, struct MprVar **argv) +{ + char name[200]; + if (gethostname(name, sizeof(name)-1) == -1) { + ejsSetErrorMsg(eid, "gethostname failed - %s", strerror(errno)); + return -1; + } + mpr_Return(eid, mprString(name)); + return 0; +} + + +/* + return current time as a 64 bit nttime value +*/ +static int ejs_sys_nttime(MprVarHandle eid, int argc, struct MprVar **argv) +{ + struct timeval tv = timeval_current(); + struct MprVar v = mprCreateNumberVar(timeval_to_nttime(&tv)); + mpr_Return(eid, v); + return 0; +} + +/* + return a ldap time string from a nttime +*/ +static int ejs_sys_ldaptime(MprVarHandle eid, int argc, struct MprVar **argv) +{ + char *s; + time_t t; + if (argc != 1 || !mprVarIsNumber(argv[0]->type)) { + ejsSetErrorMsg(eid, "sys_ldaptime invalid arguments"); + return -1; + } + t = nt_time_to_unix(mprVarToNumber(argv[0])); + s = ldap_timestring(mprMemCtx(), t); + mpr_Return(eid, mprString(s)); + talloc_free(s); + 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_ldaptime", ejs_sys_ldaptime, NULL, MPR_VAR_SCRIPT_HANDLE); +} |