diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2008-05-24 18:19:41 +0200 |
---|---|---|
committer | Jelmer Vernooij <jelmer@samba.org> | 2008-05-24 18:19:41 +0200 |
commit | 6f6234c79f062edf05f82aec5bdca6bc35aa1cf4 (patch) | |
tree | d3ef615b84953c9cd10cfd65d45a3b6f3f9d8bee | |
parent | 453396c67b47bac0b39b276a332cf39c87d36d71 (diff) | |
download | samba-6f6234c79f062edf05f82aec5bdca6bc35aa1cf4.tar.gz samba-6f6234c79f062edf05f82aec5bdca6bc35aa1cf4.tar.bz2 samba-6f6234c79f062edf05f82aec5bdca6bc35aa1cf4.zip |
Remove remaining EJS RPC code, was unused.
(This used to be commit c994fa427fdd1e9682a5ad506aafc77f942122d1)
-rw-r--r-- | source4/scripting/ejs/config.mk | 8 | ||||
-rw-r--r-- | source4/scripting/ejs/ejsrpc.c | 424 | ||||
-rw-r--r-- | source4/scripting/ejs/ejsrpc.h | 172 | ||||
-rw-r--r-- | source4/scripting/ejs/smbcalls_rpc.c | 385 | ||||
-rw-r--r-- | source4/scripting/libjs/management.js | 157 |
5 files changed, 1 insertions, 1145 deletions
diff --git a/source4/scripting/ejs/config.mk b/source4/scripting/ejs/config.mk index c1a1ca1f0f..873dd09248 100644 --- a/source4/scripting/ejs/config.mk +++ b/source4/scripting/ejs/config.mk @@ -1,7 +1,3 @@ -[SUBSYSTEM::EJSRPC] - -EJSRPC_OBJ_FILES = $(ejsscriptsrcdir)/ejsrpc.o - [MODULE::smbcalls_config] OUTPUT_TYPE = MERGED_OBJ SUBSYSTEM = smbcalls @@ -83,16 +79,14 @@ mkinclude ejsnet/config.mk [SUBSYSTEM::smbcalls] PRIVATE_DEPENDENCIES = \ EJS LIBSAMBA-UTIL \ - EJSRPC MESSAGING \ + MESSAGING \ LIBSAMBA-NET LIBCLI_SMB LIBPOPT \ CREDENTIALS POPT_CREDENTIALS POPT_SAMBA \ - dcerpc \ NDR_TABLE smbcalls_OBJ_FILES = $(addprefix $(ejsscriptsrcdir)/, \ smbcalls.o \ smbcalls_cli.o \ - smbcalls_rpc.o \ smbcalls_options.o \ smbcalls_creds.o \ smbcalls_param.o \ diff --git a/source4/scripting/ejs/ejsrpc.c b/source4/scripting/ejs/ejsrpc.c deleted file mode 100644 index c7c02dbd64..0000000000 --- a/source4/scripting/ejs/ejsrpc.c +++ /dev/null @@ -1,424 +0,0 @@ -/* - Unix SMB/CIFS implementation. - - provide interfaces to rpc calls from ejs scripts - - 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 3 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, see <http://www.gnu.org/licenses/>. -*/ - -#include "includes.h" -#include "lib/appweb/ejs/ejs.h" -#include "scripting/ejs/smbcalls.h" -#include "librpc/gen_ndr/lsa.h" -#include "librpc/gen_ndr/winreg.h" -#include "scripting/ejs/ejsrpc.h" -#include "libcli/security/security.h" - -/* - set the switch var to be used by the next union switch -*/ -void ejs_set_switch(struct ejs_rpc *ejs, uint32_t switch_var) -{ - ejs->switch_var = switch_var; -} - -/* - panic in the ejs wrapper code - */ -NTSTATUS ejs_panic(struct ejs_rpc *ejs, const char *why) -{ - ejsSetErrorMsg(ejs->eid, "rpc_call '%s' failed - %s", ejs->callname, why); - return NT_STATUS_INTERNAL_ERROR; -} - -/* - start the ejs pull process for a structure -*/ -NTSTATUS ejs_pull_struct_start(struct ejs_rpc *ejs, struct MprVar **v, const char *name) -{ - return mprGetVar(v, name); -} - - -/* - start the ejs push process for a structure -*/ -NTSTATUS ejs_push_struct_start(struct ejs_rpc *ejs, struct MprVar **v, const char *name) -{ - EJS_CHECK(mprSetVar(*v, name, mprObject(name))); - return mprGetVar(v, name); -} - -/* - pull a uint8 from a mpr variable to a C element -*/ -NTSTATUS ejs_pull_uint8(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, uint8_t *r) -{ - EJS_CHECK(mprGetVar(&v, name)); - *r = mprVarToInteger(v); - return NT_STATUS_OK; - -} - -NTSTATUS ejs_push_uint8(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const uint8_t *r) -{ - return mprSetVar(v, name, mprCreateIntegerVar(*r)); -} - -/* - pull a uint16 from a mpr variable to a C element -*/ -NTSTATUS ejs_pull_uint16(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, uint16_t *r) -{ - EJS_CHECK(mprGetVar(&v, name)); - *r = mprVarToInteger(v); - return NT_STATUS_OK; - -} - -NTSTATUS ejs_push_uint16(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const uint16_t *r) -{ - return mprSetVar(v, name, mprCreateIntegerVar(*r)); -} - -/* - pull a uint32 from a mpr variable to a C element -*/ -NTSTATUS ejs_pull_uint32(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, uint32_t *r) -{ - EJS_CHECK(mprGetVar(&v, name)); - *r = mprVarToInteger(v); - return NT_STATUS_OK; -} - -NTSTATUS ejs_push_uint32(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const uint32_t *r) -{ - return mprSetVar(v, name, mprCreateIntegerVar(*r)); -} - -/* - pull a int32 from a mpr variable to a C element -*/ -NTSTATUS ejs_pull_int32(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, int32_t *r) -{ - EJS_CHECK(mprGetVar(&v, name)); - *r = mprVarToInteger(v); - return NT_STATUS_OK; -} - -NTSTATUS ejs_push_int32(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const int32_t *r) -{ - return mprSetVar(v, name, mprCreateIntegerVar(*r)); -} - -/* - pull a uint32 from a mpr variable to a C element -*/ -NTSTATUS ejs_pull_time_t(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, time_t *r) -{ - EJS_CHECK(mprGetVar(&v, name)); - *r = mprVarToInteger(v); - return NT_STATUS_OK; -} - -NTSTATUS ejs_push_time_t(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const time_t *r) -{ - return mprSetVar(v, name, mprCreateIntegerVar(*r)); -} - -NTSTATUS ejs_pull_hyper(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, uint64_t *r) -{ - EJS_CHECK(mprGetVar(&v, name)); - *r = mprVarToNumber(v); - return NT_STATUS_OK; -} - -NTSTATUS ejs_push_hyper(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const uint64_t *r) -{ - return mprSetVar(v, name, mprCreateNumberVar(*r)); -} - -NTSTATUS ejs_pull_dlong(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, int64_t *r) -{ - return ejs_pull_hyper(ejs, v, name, (uint64_t *)r); -} - -NTSTATUS ejs_push_dlong(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const int64_t *r) -{ - return ejs_push_hyper(ejs, v, name, (const uint64_t *)r); -} - -NTSTATUS ejs_pull_udlong(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, uint64_t *r) -{ - return ejs_pull_hyper(ejs, v, name, r); -} - -NTSTATUS ejs_push_udlong(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const uint64_t *r) -{ - return ejs_push_hyper(ejs, v, name, r); -} - -NTSTATUS ejs_pull_NTTIME(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, uint64_t *r) -{ - return ejs_pull_hyper(ejs, v, name, r); -} - -NTSTATUS ejs_push_NTTIME(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const uint64_t *r) -{ - return ejs_push_hyper(ejs, v, name, r); -} - -NTSTATUS ejs_push_WERROR(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const WERROR *r) -{ - return ejs_push_string(ejs, v, name, win_errstr(*r)); -} - -NTSTATUS ejs_push_NTSTATUS(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const NTSTATUS *r) -{ - return ejs_push_string(ejs, v, name, nt_errstr(*r)); -} - - -/* - pull a enum from a mpr variable to a C element - a enum is just treating as an unsigned integer at this level -*/ -NTSTATUS ejs_pull_enum(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, unsigned *r) -{ - EJS_CHECK(mprGetVar(&v, name)); - *r = mprVarToInteger(v); - return NT_STATUS_OK; - -} - -NTSTATUS ejs_push_enum(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const unsigned *r) -{ - return mprSetVar(v, name, mprCreateIntegerVar(*r)); -} - - -/* - pull a string -*/ -NTSTATUS ejs_pull_string(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const char **s) -{ - EJS_CHECK(mprGetVar(&v, name)); - *s = mprToString(v); - return NT_STATUS_OK; -} - -/* - push a string -*/ -NTSTATUS ejs_push_string(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const char *s) -{ - return mprSetVar(v, name, mprString(s)); -} - - -/* - pull a ipv4address (internally a string) -*/ -NTSTATUS ejs_pull_ipv4address(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const char **s) -{ - return ejs_pull_string(ejs, v, name, s); -} - -/* - push a ipv4address (internally a string) -*/ -NTSTATUS ejs_push_ipv4address(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const char *s) -{ - return ejs_push_string(ejs, v, name, s); -} - - -NTSTATUS ejs_pull_dom_sid(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, struct dom_sid *r) -{ - struct dom_sid *sid; - EJS_CHECK(mprGetVar(&v, name)); - sid = dom_sid_parse_talloc(ejs, mprToString(v)); - NT_STATUS_HAVE_NO_MEMORY(sid); - *r = *sid; - return NT_STATUS_OK; -} - -NTSTATUS ejs_push_dom_sid(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const struct dom_sid *r) -{ - char *sidstr = dom_sid_string(ejs, r); - NT_STATUS_HAVE_NO_MEMORY(sidstr); - return mprSetVar(v, name, mprString(sidstr)); -} - -NTSTATUS ejs_pull_GUID(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, struct GUID *r) -{ - EJS_CHECK(mprGetVar(&v, name)); - return GUID_from_string(mprToString(v), r); -} - -NTSTATUS ejs_push_GUID(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const struct GUID *r) -{ - char *guid = GUID_string(ejs, r); - NT_STATUS_HAVE_NO_MEMORY(guid); - return mprSetVar(v, name, mprString(guid)); -} - -NTSTATUS ejs_push_null(struct ejs_rpc *ejs, struct MprVar *v, const char *name) -{ - return mprSetVar(v, name, mprCreatePtrVar(NULL)); -} - -bool ejs_pull_null(struct ejs_rpc *ejs, struct MprVar *v, const char *name) -{ - NTSTATUS status = mprGetVar(&v, name); - if (!NT_STATUS_IS_OK(status)) { - return false; - } - if (v->type == MPR_TYPE_PTR && v->ptr == NULL) { - return true; - } - return false; -} - -/* - pull a lsa_String -*/ -NTSTATUS ejs_pull_lsa_String(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, struct lsa_String *r) -{ - return ejs_pull_string(ejs, v, name, &r->string); -} - -/* - push a lsa_String -*/ -NTSTATUS ejs_push_lsa_String(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const struct lsa_String *r) -{ - return ejs_push_string(ejs, v, name, r->string); -} - -/* - pull a winreg_String -*/ -NTSTATUS ejs_pull_winreg_String(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, struct winreg_String *r) -{ - return ejs_pull_string(ejs, v, name, &r->name); -} - -/* - push a winreg_String -*/ -NTSTATUS ejs_push_winreg_String(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const struct winreg_String *r) -{ - return ejs_push_string(ejs, v, name, r->name); -} - -NTSTATUS ejs_pull_DATA_BLOB(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, DATA_BLOB *r) -{ - return NT_STATUS_NOT_IMPLEMENTED; -} - -NTSTATUS ejs_push_DATA_BLOB(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, - const DATA_BLOB *r) -{ - return NT_STATUS_NOT_IMPLEMENTED; -} - -NTSTATUS ejs_pull_bool(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, bool *r) -{ - EJS_CHECK(mprGetVar(&v, name)); - *r = mprVarToBool(v); - return NT_STATUS_OK; -} - -NTSTATUS ejs_push_bool(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const bool *r) -{ - return mprSetVar(v, name, mprCreateBoolVar(*r)); -} - - -/* - pull a uint8 array from a mpr variable to a C element - treating as a data blob -*/ -NTSTATUS ejs_pull_array_uint8(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, - uint8_t *r, uint32_t length) -{ - NTSTATUS status; - DATA_BLOB *blob; - - status = mprGetVar(&v, name); - NT_STATUS_NOT_OK_RETURN(status); - - blob = mprToDataBlob(v); - if (blob == NULL) { - return NT_STATUS_OBJECT_NAME_INVALID; - } - if (blob->length != length) { - return NT_STATUS_INFO_LENGTH_MISMATCH; - } - memcpy(r, blob->data, length); - return NT_STATUS_OK; - -} - -NTSTATUS ejs_push_array_uint8(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, - const uint8_t *r, uint32_t length) -{ - DATA_BLOB blob; - blob.data = (uint8_t *)discard_const(r); - blob.length = length; - mprSetVar(v, name, mprDataBlob(blob)); - return NT_STATUS_OK; -} diff --git a/source4/scripting/ejs/ejsrpc.h b/source4/scripting/ejs/ejsrpc.h deleted file mode 100644 index cc22a26700..0000000000 --- a/source4/scripting/ejs/ejsrpc.h +++ /dev/null @@ -1,172 +0,0 @@ -/* - Unix SMB/CIFS implementation. - - ejs <-> rpc interface definitions - - 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 3 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, see <http://www.gnu.org/licenses/>. -*/ - -#include "librpc/gen_ndr/security.h" -#include "librpc/rpc/dcerpc.h" - -struct ejs_rpc { - int eid; - const char *callname; - /* as ejs does only one pass, we can use a single var for switch - handling */ - uint32_t switch_var; -}; - -typedef NTSTATUS (*ejs_pull_t)(struct ejs_rpc *, struct MprVar *, const char *, void *); -typedef NTSTATUS (*ejs_push_t)(struct ejs_rpc *, struct MprVar *, const char *, const void *); -typedef NTSTATUS (*ejs_pull_function_t)(struct ejs_rpc *, struct MprVar *, void *); -typedef NTSTATUS (*ejs_push_function_t)(struct ejs_rpc *, struct MprVar *, const void *); - -NTSTATUS ejs_panic(struct ejs_rpc *ejs, const char *why); -void ejs_set_switch(struct ejs_rpc *ejs, uint32_t switch_var); - -NTSTATUS smbcalls_register_ejs(const char *name, MprCFunction fn); - - -int ejs_rpc_call(int eid, int argc, struct MprVar **argv, - const struct ndr_interface_table *iface, int callnum, - ejs_pull_function_t ejs_pull, ejs_push_function_t ejs_push); - -NTSTATUS ejs_pull_struct_start(struct ejs_rpc *ejs, struct MprVar **v, const char *name); -NTSTATUS ejs_push_struct_start(struct ejs_rpc *ejs, struct MprVar **v, const char *name); - -NTSTATUS ejs_pull_uint8(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, uint8_t *r); -NTSTATUS ejs_push_uint8(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const uint8_t *r); -NTSTATUS ejs_pull_uint16(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, uint16_t *r); -NTSTATUS ejs_push_uint16(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const uint16_t *r); -NTSTATUS ejs_pull_uint32(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, uint32_t *r); -NTSTATUS ejs_push_int32(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const int32_t *r); -NTSTATUS ejs_pull_int32(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, int32_t *r); -NTSTATUS ejs_push_uint32(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const uint32_t *r); -NTSTATUS ejs_pull_hyper(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, uint64_t *r); -NTSTATUS ejs_push_hyper(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const uint64_t *r); -NTSTATUS ejs_pull_dlong(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, int64_t *r); -NTSTATUS ejs_push_dlong(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const int64_t *r); -NTSTATUS ejs_pull_udlong(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, uint64_t *r); -NTSTATUS ejs_push_udlong(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const uint64_t *r); -NTSTATUS ejs_pull_NTTIME(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, uint64_t *r); -NTSTATUS ejs_push_NTTIME(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const uint64_t *r); -NTSTATUS ejs_pull_time_t(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, time_t *r); -NTSTATUS ejs_push_time_t(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const time_t *r); -NTSTATUS ejs_pull_enum(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, unsigned *r); -NTSTATUS ejs_push_enum(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const unsigned *r); -NTSTATUS ejs_pull_string(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const char **s); -NTSTATUS ejs_push_string(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const char *s); -NTSTATUS ejs_pull_ipv4address(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const char **s); -NTSTATUS ejs_push_ipv4address(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const char *s); -void ejs_set_constant_int(int eid, const char *name, int value); -void ejs_set_constant_string(int eid, const char *name, const char *value); - -NTSTATUS ejs_pull_dom_sid(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, struct dom_sid *r); -NTSTATUS ejs_push_dom_sid(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const struct dom_sid *r); -NTSTATUS ejs_push_null(struct ejs_rpc *ejs, struct MprVar *v, const char *name); -bool ejs_pull_null(struct ejs_rpc *ejs, struct MprVar *v, const char *name); -NTSTATUS ejs_push_WERROR(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const WERROR *r); -NTSTATUS ejs_push_NTSTATUS(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const NTSTATUS *r); -NTSTATUS ejs_pull_DATA_BLOB(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, DATA_BLOB *r); -NTSTATUS ejs_push_DATA_BLOB(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const DATA_BLOB *r); -NTSTATUS ejs_pull_bool(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, bool *r); -NTSTATUS ejs_push_bool(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const bool *r); - -NTSTATUS ejs_pull_array_uint8(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, - uint8_t *r, uint32_t length); -NTSTATUS ejs_push_array_uint8(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, - const uint8_t *r, uint32_t length); - -NTSTATUS ejs_pull_GUID(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, struct GUID *r); -NTSTATUS ejs_push_GUID(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const struct GUID *r); - -struct lsa_String; -NTSTATUS ejs_pull_lsa_String(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, struct lsa_String *r); -NTSTATUS ejs_push_lsa_String(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const struct lsa_String *r); - -struct winreg_String; -NTSTATUS ejs_pull_winreg_String(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, struct winreg_String *r); -NTSTATUS ejs_push_winreg_String(struct ejs_rpc *ejs, - struct MprVar *v, const char *name, const struct winreg_String *r); - -#define EJS_ALLOC(ejs, s) do { \ - (s) = talloc_ptrtype(ejs, (s)); \ - if (!(s)) return ejs_panic(ejs, "out of memory"); \ -} while (0) - -#define EJS_ALLOC_N(ejs, s, n) do { \ - (s) = talloc_array_ptrtype(ejs, (s), n); \ - if (!(s)) return ejs_panic(ejs, "out of memory"); \ -} while (0) - -#define EJS_CHECK(cmd) do { \ - NTSTATUS _status; \ - _status = cmd; \ - if (!NT_STATUS_IS_OK(_status)) { \ - return _status; \ - } \ -} while (0) - -/* some types are equivalent for ejs */ -#define ejs_pull_dom_sid2 ejs_pull_dom_sid -#define ejs_push_dom_sid2 ejs_push_dom_sid -#define ejs_pull_dom_sid28 ejs_pull_dom_sid -#define ejs_push_dom_sid28 ejs_push_dom_sid -#define ejs_pull_NTTIME_hyper ejs_pull_NTTIME -#define ejs_push_NTTIME_hyper ejs_push_NTTIME -#define ejs_pull_NTTIME_1sec ejs_pull_NTTIME -#define ejs_push_NTTIME_1sec ejs_push_NTTIME - diff --git a/source4/scripting/ejs/smbcalls_rpc.c b/source4/scripting/ejs/smbcalls_rpc.c deleted file mode 100644 index 94774d708b..0000000000 --- a/source4/scripting/ejs/smbcalls_rpc.c +++ /dev/null @@ -1,385 +0,0 @@ -/* - Unix SMB/CIFS implementation. - - provide interfaces to rpc calls from ejs scripts - - 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 3 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, see <http://www.gnu.org/licenses/>. -*/ - -#include "includes.h" -#include "scripting/ejs/smbcalls.h" -#include "lib/appweb/ejs/ejs.h" -#include "librpc/gen_ndr/echo.h" -#include "lib/cmdline/popt_common.h" -#include "lib/messaging/irpc.h" -#include "scripting/ejs/ejsrpc.h" -#include "lib/util/dlinklist.h" -#include "lib/events/events.h" -#include "librpc/ndr/ndr_table.h" -#include "auth/credentials/credentials.h" -#include "librpc/rpc/dcerpc.h" -#include "cluster/cluster.h" - -/* - state of a irpc 'connection' -*/ -struct ejs_irpc_connection { - const char *server_name; - struct server_id *dest_ids; - struct messaging_context *msg_ctx; -}; - -/* - messaging clients need server IDs as well ... - */ -#define EJS_ID_BASE 0x30000000 - -/* - setup a context for talking to a irpc server - example: - status = irpc.connect("smb_server"); -*/ -static int ejs_irpc_connect(MprVarHandle eid, int argc, char **argv) -{ - NTSTATUS status; - int i; - struct event_context *ev; - struct ejs_irpc_connection *p; - struct MprVar *this = mprGetProperty(ejsGetLocalObject(eid), "this", 0); - - /* validate arguments */ - if (argc != 1) { - ejsSetErrorMsg(eid, "rpc_connect invalid arguments"); - return -1; - } - - p = talloc(this, struct ejs_irpc_connection); - if (p == NULL) { - return -1; - } - - p->server_name = argv[0]; - - ev = mprEventCtx(); - - /* create a messaging context, looping as we have no way to - allocate temporary server ids automatically */ - for (i=0;i<10000;i++) { - p->msg_ctx = messaging_init(p, - lp_messaging_path(p, mprLpCtx()), - cluster_id(EJS_ID_BASE, i), - lp_iconv_convenience(mprLpCtx()), - ev); - if (p->msg_ctx) break; - } - if (p->msg_ctx == NULL) { - ejsSetErrorMsg(eid, "irpc_connect unable to create a messaging context"); - talloc_free(p); - return -1; - } - - p->dest_ids = irpc_servers_byname(p->msg_ctx, p, p->server_name); - if (p->dest_ids == NULL || p->dest_ids[0].id == 0) { - talloc_free(p); - status = NT_STATUS_OBJECT_NAME_NOT_FOUND; - } else { - mprSetPtrChild(this, "irpc", p); - status = NT_STATUS_OK; - } - - mpr_Return(eid, mprNTSTATUS(status)); - return 0; -} - - -/* - connect to an rpc server - examples: - status = rpc.connect("ncacn_ip_tcp:localhost"); - status = rpc.connect("ncacn_ip_tcp:localhost", "pipe_name"); -*/ -static int ejs_rpc_connect(MprVarHandle eid, int argc, char **argv) -{ - const char *binding, *pipe_name; - const struct ndr_interface_table *iface; - NTSTATUS status; - struct dcerpc_pipe *p; - struct cli_credentials *creds; - struct event_context *ev; - struct MprVar *this = mprGetProperty(ejsGetLocalObject(eid), "this", 0); - struct MprVar *credentials; - - /* validate arguments */ - if (argc < 1) { - ejsSetErrorMsg(eid, "rpc_connect invalid arguments"); - return -1; - } - - binding = argv[0]; - if (strchr(binding, ':') == NULL) { - /* its an irpc connect */ - return ejs_irpc_connect(eid, argc, argv); - } - - if (argc > 1) { - pipe_name = argv[1]; - } else { - pipe_name = mprToString(mprGetProperty(this, "pipe_name", NULL)); - } - - iface = ndr_table_by_name(pipe_name); - if (iface == NULL) { - status = NT_STATUS_OBJECT_NAME_INVALID; - goto done; - } - - credentials = mprGetProperty(this, "credentials", NULL); - if (credentials) { - creds = (struct cli_credentials *) - mprGetPtr(credentials, "creds"); - } else { - creds = cmdline_credentials; - } - if (creds == NULL) { - creds = cli_credentials_init(mprMemCtx()); - cli_credentials_set_anonymous(creds); - } - - ev = mprEventCtx(); - - status = dcerpc_pipe_connect(this, &p, binding, iface, creds, ev, - mprLpCtx()); - if (!NT_STATUS_IS_OK(status)) goto done; - - /* callers don't allocate ref vars in the ejs interface */ - p->conn->flags |= DCERPC_NDR_REF_ALLOC; - - /* by making the pipe a child of the connection variable, it will - auto close when it goes out of scope in the script */ - mprSetPtrChild(this, "pipe", p); - -done: - mpr_Return(eid, mprNTSTATUS(status)); - return 0; -} - - -/* - make an irpc call - called via the same interface as rpc -*/ -static int ejs_irpc_call(int eid, struct MprVar *io, - const struct ndr_interface_table *iface, int callnum, - ejs_pull_function_t ejs_pull, ejs_push_function_t ejs_push) -{ - NTSTATUS status; - void *ptr; - struct ejs_rpc *ejs; - const struct ndr_interface_call *call; - struct ejs_irpc_connection *p; - struct irpc_request **reqs; - int i, count; - struct MprVar *results; - - p = (struct ejs_irpc_connection *)mprGetThisPtr(eid, "irpc"); - - ejs = talloc(mprMemCtx(), struct ejs_rpc); - if (ejs == NULL) { - status = NT_STATUS_NO_MEMORY; - goto done; - } - - call = &iface->calls[callnum]; - - ejs->eid = eid; - ejs->callname = call->name; - - /* allocate the C structure */ - ptr = talloc_zero_size(ejs, call->struct_size); - if (ptr == NULL) { - status = NT_STATUS_NO_MEMORY; - goto done; - } - - /* convert the mpr object into a C structure */ - status = ejs_pull(ejs, io, ptr); - if (!NT_STATUS_IS_OK(status)) { - goto done; - } - - for (count=0;p->dest_ids[count].id;count++) /* noop */ ; - - /* we need to make a call per server */ - reqs = talloc_array(ejs, struct irpc_request *, count); - if (reqs == NULL) { - status = NT_STATUS_NO_MEMORY; - goto done; - } - - /* make the actual calls */ - for (i=0;i<count;i++) { - reqs[i] = irpc_call_send(p->msg_ctx, p->dest_ids[i], - iface, callnum, ptr, ptr); - if (reqs[i] == NULL) { - status = NT_STATUS_NO_MEMORY; - goto done; - } - talloc_steal(reqs, reqs[i]); - } - - mprSetVar(io, "results", mprObject("results")); - results = mprGetProperty(io, "results", NULL); - - /* and receive the results, placing them in io.results[i] */ - for (i=0;i<count;i++) { - struct MprVar *output; - - status = irpc_call_recv(reqs[i]); - if (!NT_STATUS_IS_OK(status)) { - goto done; - } - status = ejs_push(ejs, io, ptr); - if (!NT_STATUS_IS_OK(status)) { - goto done; - } - - /* add to the results array */ - output = mprGetProperty(io, "output", NULL); - if (output) { - char idx[16]; - mprItoa(i, idx, sizeof(idx)); - mprSetProperty(results, idx, output); - mprDeleteProperty(io, "output"); - } - } - mprSetVar(results, "length", mprCreateIntegerVar(i)); - -done: - talloc_free(ejs); - mpr_Return(eid, mprNTSTATUS(status)); - if (NT_STATUS_EQUAL(status, NT_STATUS_INTERNAL_ERROR)) { - return -1; - } - return 0; -} - - -/* - backend code for making an rpc call - this is called from the pidl generated ejs - code -*/ - int ejs_rpc_call(int eid, int argc, struct MprVar **argv, - const struct ndr_interface_table *iface, int callnum, - ejs_pull_function_t ejs_pull, ejs_push_function_t ejs_push) -{ - struct MprVar *io; - struct dcerpc_pipe *p; - NTSTATUS status; - void *ptr; - struct rpc_request *req; - struct ejs_rpc *ejs; - const struct ndr_interface_call *call; - - if (argc != 1 || argv[0]->type != MPR_TYPE_OBJECT) { - ejsSetErrorMsg(eid, "rpc_call invalid arguments"); - return -1; - } - - io = argv[0]; - - if (mprGetThisPtr(eid, "irpc")) { - /* its an irpc call */ - return ejs_irpc_call(eid, io, iface, callnum, ejs_pull, ejs_push); - } - - /* get the pipe info */ - p = mprGetThisPtr(eid, "pipe"); - if (p == NULL) { - ejsSetErrorMsg(eid, "rpc_call invalid pipe"); - return -1; - } - - ejs = talloc(mprMemCtx(), struct ejs_rpc); - if (ejs == NULL) { - status = NT_STATUS_NO_MEMORY; - goto done; - } - - call = &iface->calls[callnum]; - - ejs->eid = eid; - ejs->callname = call->name; - - /* allocate the C structure */ - ptr = talloc_zero_size(ejs, call->struct_size); - if (ptr == NULL) { - status = NT_STATUS_NO_MEMORY; - goto done; - } - - /* convert the mpr object into a C structure */ - status = ejs_pull(ejs, io, ptr); - if (!NT_STATUS_IS_OK(status)) { - goto done; - } - - /* make the actual call */ - req = dcerpc_ndr_request_send(p, NULL, iface, callnum, ptr, ptr); - - /* if requested, print the structure */ - if (p->conn->flags & DCERPC_DEBUG_PRINT_IN) { - ndr_print_function_debug(call->ndr_print, call->name, NDR_IN, ptr); - } - - if (req == NULL) { - status = NT_STATUS_NO_MEMORY; - goto done; - } - - status = dcerpc_ndr_request_recv(req); - if (!NT_STATUS_IS_OK(status)) { - goto done; - } - - /* print the 'out' structure, if needed */ - if (p->conn->flags & DCERPC_DEBUG_PRINT_OUT) { - ndr_print_function_debug(call->ndr_print, call->name, NDR_OUT, ptr); - } - - status = ejs_push(ejs, io, ptr); - -done: - talloc_free(ejs); - mpr_Return(eid, mprNTSTATUS(status)); - if (NT_STATUS_EQUAL(status, NT_STATUS_INTERNAL_ERROR)) { - return -1; - } - return 0; -} - -/* - hook called by generated RPC interfaces at the end of their init routines - used to add generic operations on the pipe -*/ -int ejs_rpc_init(struct MprVar *obj, const char *name) -{ - ndr_table_init(); - - mprSetStringCFunction(obj, "connect", ejs_rpc_connect); - if (mprGetProperty(obj, "pipe_name", NULL) == NULL) { - mprSetVar(obj, "pipe_name", mprString(name)); - } - return 0; -} diff --git a/source4/scripting/libjs/management.js b/source4/scripting/libjs/management.js deleted file mode 100644 index 4a43275156..0000000000 --- a/source4/scripting/libjs/management.js +++ /dev/null @@ -1,157 +0,0 @@ -/* - backend code for Samba4 management - Copyright Andrew Tridgell 2005 - Released under the GNU GPL version 3 or later -*/ - - -/* - return a list of current sessions -*/ -function smbsrv_sessions() -{ - var irpc = irpc_init(); - status = irpc.connect("smb_server"); - if (status.is_ok != true) { - return undefined; - } - - var io = irpcObj(); - io.input.level = irpc.SMBSRV_INFO_SESSIONS; - status = irpc.smbsrv_information(io); - if (status.is_ok != true) { - return undefined; - } - - /* gather the results into a single array */ - var i, count=0, ret = new Array(0); - for (i=0;i<io.results.length;i++) { - var sessions = io.results[i].info.sessions.sessions; - var j; - for (j=0;j<sessions.length;j++) { - ret[count] = sessions[j]; - count++; - } - } - return ret; -} - -/* - return a list of current tree connects -*/ -function smbsrv_tcons() -{ - var irpc = irpc_init(); - status = irpc.connect("smb_server"); - if (status.is_ok != true) { - return undefined; - } - - var io = irpcObj(); - io.input.level = irpc.SMBSRV_INFO_TCONS; - status = irpc.smbsrv_information(io); - if (status.is_ok != true) { - return undefined; - } - - /* gather the results into a single array */ - var i, count=0, ret = new Object(); - for (i=0;i<io.results.length;i++) { - var tcons = io.results[i].info.tcons.tcons; - var j; - for (j=0;j<tcons.length;j++) { - ret[count] = tcons[j]; - count++; - } - } - ret.length = count; - return ret; -} - -/* - return nbtd statistics -*/ -function nbtd_statistics() -{ - var irpc = irpc_init(); - status = irpc.connect("nbt_server"); - if (status.is_ok != true) { - return undefined; - } - - var io = irpcObj(); - io.input.level = irpc.NBTD_INFO_STATISTICS; - status = irpc.nbtd_information(io); - if (status.is_ok != true) { - return undefined; - } - return io.results[0].info.stats; -} - -/* - see if a service is enabled -*/ -function service_enabled(name) -{ - var lp = loadparm_init(); - var services = lp.get("server services"); - var i; - for (i=0;i<services.length;i++) { - if (services[i] == name) { - return true; - } - } - return false; -} - -/* - show status of a server -*/ -function server_status(name) -{ - var i; - var io; - var irpc = irpc_init(); - - if (!service_enabled(name)) { - return "DISABLED"; - } - - status = irpc.connect(name + "_server"); - if (status.is_ok != true) { - return "DOWN"; - } - - var io = irpcObj(); - status = irpc.irpc_uptime(io); - if (status.is_ok != true) { - return "NOT RESPONDING"; - } - - return "RUNNING"; -} - -/* - show status of a stream server -*/ -function stream_server_status(name) -{ - var irpc = irpc_init(); - - if (!service_enabled(name)) { - return "DISABLED"; - } - status = irpc.connect(name + "_server"); - if (status.is_ok != true) { - return "0 connections"; - } - - var io = irpcObj(); - status = irpc.irpc_uptime(io); - if (status.is_ok != true) { - return "NOT RESPONDING"; - } - - var n = io.results.length; - return sprintf("%u connection%s", n, plural(n)); -} |