diff options
Diffstat (limited to 'source4')
-rw-r--r-- | source4/build/pidl/Parse/Pidl/Samba/EJS.pm | 2 | ||||
-rw-r--r-- | source4/scripting/ejs/smbcalls_rpc.c | 88 | ||||
-rw-r--r-- | source4/scripting/libjs/management.js | 25 | ||||
-rw-r--r-- | source4/scripting/libjs/samr.js | 31 |
4 files changed, 74 insertions, 72 deletions
diff --git a/source4/build/pidl/Parse/Pidl/Samba/EJS.pm b/source4/build/pidl/Parse/Pidl/Samba/EJS.pm index 5cd7b462ae..c528e13a52 100644 --- a/source4/build/pidl/Parse/Pidl/Samba/EJS.pm +++ b/source4/build/pidl/Parse/Pidl/Samba/EJS.pm @@ -704,7 +704,7 @@ sub EjsInterface($$) pidl "mprSetVar(obj, \"$v\", mprCreateNumberVar($value));"; } } - pidl "return 0;"; + pidl "return ejs_rpc_init(obj, \"$name\");"; deindent; pidl "}\n"; diff --git a/source4/scripting/ejs/smbcalls_rpc.c b/source4/scripting/ejs/smbcalls_rpc.c index 8e7bf57972..223ac5c972 100644 --- a/source4/scripting/ejs/smbcalls_rpc.c +++ b/source4/scripting/ejs/smbcalls_rpc.c @@ -46,33 +46,28 @@ struct ejs_irpc_connection { /* setup a context for talking to a irpc server example: - var conn = new Object(); - status = irpc_connect(conn, "smb_server"); + status = irpc.connect("smb_server"); */ -static int ejs_irpc_connect(MprVarHandle eid, int argc, struct MprVar **argv) +static int ejs_irpc_connect(MprVarHandle eid, int argc, char **argv) { NTSTATUS status; int i; - struct MprVar *conn; struct event_context *ev; struct ejs_irpc_connection *p; + struct MprVar *this = mprGetProperty(ejsGetLocalObject(eid), "this", 0); /* validate arguments */ - if (argc != 2 || - argv[0]->type != MPR_TYPE_OBJECT || - argv[1]->type != MPR_TYPE_STRING) { + if (argc != 1) { ejsSetErrorMsg(eid, "rpc_connect invalid arguments"); return -1; } - conn = argv[0]; - - p = talloc(conn, struct ejs_irpc_connection); + p = talloc(this, struct ejs_irpc_connection); if (p == NULL) { return -1; } - p->server_name = mprToString(argv[1]); + p->server_name = argv[0]; ev = talloc_find_parent_bytype(mprMemCtx(), struct event_context); @@ -93,7 +88,7 @@ static int ejs_irpc_connect(MprVarHandle eid, int argc, struct MprVar **argv) talloc_free(p); status = NT_STATUS_OBJECT_NAME_NOT_FOUND; } else { - mprSetPtrChild(conn, "irpc", p); + mprSetPtrChild(this, "irpc", p); status = NT_STATUS_OK; } @@ -104,32 +99,37 @@ static int ejs_irpc_connect(MprVarHandle eid, int argc, struct MprVar **argv) /* connect to an rpc server - example: - var conn = new Object(); - status = rpc_connect(conn, "ncacn_ip_tcp:localhost", "rpcecho"); + 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, struct MprVar **argv) +static int ejs_rpc_connect(MprVarHandle eid, int argc, char **argv) { const char *binding, *pipe_name; const struct dcerpc_interface_table *iface; NTSTATUS status; struct dcerpc_pipe *p; - struct MprVar *conn; struct cli_credentials *creds = cmdline_credentials; struct event_context *ev; + struct MprVar *this = mprGetProperty(ejsGetLocalObject(eid), "this", 0); /* validate arguments */ - if (argc != 3 || - argv[0]->type != MPR_TYPE_OBJECT || - argv[1]->type != MPR_TYPE_STRING || - argv[2]->type != MPR_TYPE_STRING) { + if (argc < 1) { ejsSetErrorMsg(eid, "rpc_connect invalid arguments"); return -1; } - conn = argv[0]; - binding = mprToString(argv[1]); - pipe_name = mprToString(argv[2]); + 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 = idl_iface_by_name(pipe_name); if (iface == NULL) { @@ -146,7 +146,7 @@ static int ejs_rpc_connect(MprVarHandle eid, int argc, struct MprVar **argv) ev = talloc_find_parent_bytype(mprMemCtx(), struct event_context); - status = dcerpc_pipe_connect(conn, &p, binding, + status = dcerpc_pipe_connect(this, &p, binding, iface->uuid, iface->if_version, creds, ev); if (!NT_STATUS_IS_OK(status)) goto done; @@ -156,8 +156,8 @@ static int ejs_rpc_connect(MprVarHandle eid, int argc, struct MprVar **argv) /* by making the pipe a child of the connection variable, it will auto close when it goes out of scope in the script */ - mprSetPtrChild(conn, "pipe", p); - mprSetPtr(conn, "iface", iface); + mprSetPtrChild(this, "pipe", p); + mprSetPtr(this, "iface", iface); done: mpr_Return(eid, mprNTSTATUS(status)); @@ -168,7 +168,7 @@ done: /* make an irpc call - called via the same interface as rpc */ -static int ejs_irpc_call(int eid, struct MprVar *conn, struct MprVar *io, +static int ejs_irpc_call(int eid, struct MprVar *io, const struct dcerpc_interface_table *iface, int callnum, ejs_pull_function_t ejs_pull, ejs_push_function_t ejs_push) { @@ -181,7 +181,7 @@ static int ejs_irpc_call(int eid, struct MprVar *conn, struct MprVar *io, int i, count; struct MprVar *results; - p = mprGetPtr(conn, "irpc"); + p = mprGetThisPtr(eid, "irpc"); ejs = talloc(mprMemCtx(), struct ejs_rpc); if (ejs == NULL) { @@ -273,7 +273,7 @@ done: const struct dcerpc_interface_table *iface, int callnum, ejs_pull_function_t ejs_pull, ejs_push_function_t ejs_push) { - struct MprVar *conn, *io; + struct MprVar *io; struct dcerpc_pipe *p; NTSTATUS status; void *ptr; @@ -281,23 +281,20 @@ done: struct ejs_rpc *ejs; const struct dcerpc_interface_call *call; - if (argc != 2 || - argv[0]->type != MPR_TYPE_OBJECT || - argv[1]->type != MPR_TYPE_OBJECT) { + if (argc != 1 || argv[0]->type != MPR_TYPE_OBJECT) { ejsSetErrorMsg(eid, "rpc_call invalid arguments"); return -1; } - conn = argv[0]; - io = argv[1]; + io = argv[0]; - if (mprGetPtr(conn, "irpc")) { + if (mprGetThisPtr(eid, "irpc")) { /* its an irpc call */ - return ejs_irpc_call(eid, conn, io, iface, callnum, ejs_pull, ejs_push); + return ejs_irpc_call(eid, io, iface, callnum, ejs_pull, ejs_push); } /* get the pipe info */ - p = mprGetPtr(conn, "pipe"); + p = mprGetThisPtr(eid, "pipe"); if (p == NULL) { ejsSetErrorMsg(eid, "rpc_call invalid pipe"); return -1; @@ -389,9 +386,20 @@ void smb_setup_ejs_rpc(void) { struct ejs_register *r; - ejsDefineCFunction(-1, "rpc_connect", ejs_rpc_connect, NULL, MPR_VAR_SCRIPT_HANDLE); - ejsDefineCFunction(-1, "irpc_connect", ejs_irpc_connect, NULL, MPR_VAR_SCRIPT_HANDLE); for (r=ejs_registered;r;r=r->next) { ejsDefineCFunction(-1, r->name, r->fn, NULL, MPR_VAR_SCRIPT_HANDLE); } } + +/* + 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) +{ + 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 index e1c68ca1de..26c1c0a34a 100644 --- a/source4/scripting/libjs/management.js +++ b/source4/scripting/libjs/management.js @@ -10,16 +10,15 @@ */ function smbsrv_sessions() { - var conn = new Object(); var irpc = irpc_init(); - status = irpc_connect(conn, "smb_server"); + 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(conn, io); + status = irpc.smbsrv_information(io); if (status.is_ok != true) { return undefined; } @@ -43,16 +42,15 @@ function smbsrv_sessions() */ function smbsrv_trees() { - var conn = new Object(); var irpc = irpc_init(); - status = irpc_connect(conn, "smb_server"); + status = irpc.connect("smb_server"); if (status.is_ok != true) { return undefined; } var io = irpcObj(); io.input.level = irpc.SMBSRV_INFO_TREES; - status = irpc.smbsrv_information(conn, io); + status = irpc.smbsrv_information(io); if (status.is_ok != true) { return undefined; } @@ -76,16 +74,15 @@ function smbsrv_trees() */ function nbtd_statistics() { - var conn = new Object(); var irpc = irpc_init(); - status = irpc_connect(conn, "nbt_server"); + 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(conn, io); + status = irpc.nbtd_information(io); if (status.is_ok != true) { return undefined; } @@ -113,7 +110,6 @@ function service_enabled(name) */ function server_status(name) { - var conn = new Object(); var i; var io; var irpc = irpc_init(); @@ -122,13 +118,13 @@ function server_status(name) return "DISABLED"; } - status = irpc_connect(conn, name + "_server"); + status = irpc.connect(name + "_server"); if (status.is_ok != true) { return "DOWN"; } var io = irpcObj(); - status = irpc.irpc_uptime(conn, io); + status = irpc.irpc_uptime(io); if (status.is_ok != true) { return "NOT RESPONDING"; } @@ -141,19 +137,18 @@ function server_status(name) */ function stream_server_status(name) { - var conn = new Object(); var irpc = irpc_init(); if (!service_enabled(name)) { return "DISABLED"; } - status = irpc_connect(conn, name + "_server"); + status = irpc.connect(name + "_server"); if (status.is_ok != true) { return "0 connections"; } var io = irpcObj(); - status = irpc.irpc_uptime(conn, io); + status = irpc.irpc_uptime(io); if (status.is_ok != true) { return "NOT RESPONDING"; } diff --git a/source4/scripting/libjs/samr.js b/source4/scripting/libjs/samr.js index 2363dde686..d0c2b89822 100644 --- a/source4/scripting/libjs/samr.js +++ b/source4/scripting/libjs/samr.js @@ -32,12 +32,11 @@ function samArray(output) */ function samrConnect(conn) { - conn.samr = samr_init(); - conn.sec = security_init(); + security_init(conn); var io = irpcObj(); io.input.system_name = NULL; - io.input.access_mask = conn.sec.SEC_FLAG_MAXIMUM_ALLOWED; - var status = conn.samr.samr_Connect2(conn, io); + io.input.access_mask = conn.SEC_FLAG_MAXIMUM_ALLOWED; + var status = conn.samr_Connect2(io); check_status_ok(status); return io.output.connect_handle; } @@ -49,7 +48,7 @@ function samrClose(conn, handle) { var io = irpcObj(); io.input.handle = handle; - var status = conn.samr.samr_Close(conn, io); + var status = conn.samr_Close(io); check_status_ok(status); } @@ -61,7 +60,7 @@ function samrLookupDomain(conn, handle, domain) var io = irpcObj(); io.input.connect_handle = handle; io.input.domain_name = domain; - var status = conn.samr.samr_LookupDomain(conn, io); + var status = conn.samr_LookupDomain(io); check_status_ok(status); return io.output.sid; } @@ -73,9 +72,9 @@ function samrOpenDomain(conn, handle, sid) { var io = irpcObj(); io.input.connect_handle = handle; - io.input.access_mask = conn.sec.SEC_FLAG_MAXIMUM_ALLOWED; + io.input.access_mask = conn.SEC_FLAG_MAXIMUM_ALLOWED; io.input.sid = sid; - var status = conn.samr.samr_OpenDomain(conn, io); + var status = conn.samr_OpenDomain(io); check_status_ok(status); return io.output.domain_handle; } @@ -87,9 +86,9 @@ function samrOpenUser(conn, handle, rid) { var io = irpcObj(); io.input.domain_handle = handle; - io.input.access_mask = conn.sec.SEC_FLAG_MAXIMUM_ALLOWED; + io.input.access_mask = conn.SEC_FLAG_MAXIMUM_ALLOWED; io.input.rid = rid; - var status = conn.samr.samr_OpenUser(conn, io); + var status = conn.samr_OpenUser(io); check_status_ok(status); return io.output.user_handle; } @@ -104,7 +103,7 @@ function samrEnumDomainUsers(conn, dom_handle) io.input.resume_handle = 0; io.input.acct_flags = 0; io.input.max_size = -1; - var status = conn.samr.samr_EnumDomainUsers(conn, io); + var status = conn.samr_EnumDomainUsers(io); check_status_ok(status); return samArray(io.output); } @@ -119,7 +118,7 @@ function samrEnumDomainGroups(conn, dom_handle) io.input.resume_handle = 0; io.input.acct_flags = 0; io.input.max_size = -1; - var status = conn.samr.samr_EnumDomainGroups(conn, io); + var status = conn.samr_EnumDomainGroups(io); check_status_ok(status); return samArray(io.output); } @@ -133,7 +132,7 @@ function samrEnumDomains(conn, handle) io.input.connect_handle = handle; io.input.resume_handle = 0; io.input.buf_size = -1; - var status = conn.samr.samr_EnumDomains(conn, io); + var status = conn.samr_EnumDomains(io); check_status_ok(status); return samArray(io.output); } @@ -146,7 +145,7 @@ function samrQueryUserInfo(conn, user_handle, level) var r, io = irpcObj(); io.input.user_handle = user_handle; io.input.level = level; - var status = conn.samr.samr_QueryUserInfo(conn, io); + var status = conn.samr_QueryUserInfo(io); check_status_ok(status); return io.output.info.info3; } @@ -160,8 +159,8 @@ function samrFillUserInfo(conn, dom_handle, users, level) var i; for (i=0;i<users.length;i++) { var r, user_handle, info; - user_handle = samrOpenUser(conn, dom_handle, users[i].idx); - info = samrQueryUserInfo(conn, user_handle, level); + user_handle = samrOpenUser(dom_handle, users[i].idx); + info = samrQueryUserInfo(user_handle, level); info.name = users[i].name; info.idx = users[i].idx; users[i] = info; |