mirror of
https://github.com/samba-team/samba.git
synced 2024-12-25 23:21:54 +03:00
r8073: a successful rpc call from ejs!
the ejs_echo.c code is the stuff that needs to be auto-generated by pidl. It only does echo_AddOne so far. We also need a table for registering these calls. The code is hard-wired for echo_AddOne for now.
This commit is contained in:
parent
c03753faa4
commit
b1ea58ddc4
@ -85,6 +85,20 @@ const struct dcerpc_interface_table *idl_iface_by_uuid(const char *uuid)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
find a dcerpc call on an interface by name
|
||||
*/
|
||||
const struct dcerpc_interface_call *dcerpc_iface_find_call(const struct dcerpc_interface_table *iface,
|
||||
const char *name)
|
||||
{
|
||||
int i;
|
||||
for (i=0;i<iface->num_calls;i++) {
|
||||
if (strcmp(iface->calls[i].name, name) == 0) {
|
||||
return &iface->calls[i];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
push a ncacn_packet into a blob, potentially with auth info
|
||||
|
@ -1,3 +1,14 @@
|
||||
#######################
|
||||
# Start LIBRARY EJSRPC
|
||||
[SUBSYSTEM::EJSRPC]
|
||||
OBJ_FILES = \
|
||||
scripting/ejs/ejsrpc.o \
|
||||
scripting/ejs/ejs_echo.o
|
||||
REQUIRED_SUBSYSTEMS = RPC_NDR_ECHO
|
||||
NOPROTO = YES
|
||||
# End SUBSYSTEM EJSRPC
|
||||
#######################
|
||||
|
||||
#######################
|
||||
# Start LIBRARY SMBCALLS
|
||||
[SUBSYSTEM::SMBCALLS]
|
||||
@ -9,7 +20,7 @@ OBJ_FILES = \
|
||||
scripting/ejs/smbcalls_cli.o \
|
||||
scripting/ejs/smbcalls_rpc.o \
|
||||
scripting/ejs/mprutil.o
|
||||
REQUIRED_SUBSYSTEMS = AUTH EJS LIBBASIC RPC_NDR_ECHO
|
||||
REQUIRED_SUBSYSTEMS = AUTH EJS LIBBASIC RPC_NDR_ECHO EJSRPC
|
||||
# End SUBSYSTEM SMBCALLS
|
||||
#######################
|
||||
|
||||
|
45
source/scripting/ejs/ejs_echo.c
Normal file
45
source/scripting/ejs/ejs_echo.c
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
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 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 "lib/ejs/ejs.h"
|
||||
#include "scripting/ejs/ejsrpc.h"
|
||||
#include "librpc/gen_ndr/ndr_echo.h"
|
||||
|
||||
/*
|
||||
this should be auto-generated by pidl, but isn't yet
|
||||
*/
|
||||
NTSTATUS ejs_pull_echo_AddOne(struct ejs_rpc *ejs,
|
||||
struct MprVar *v, struct echo_AddOne *r)
|
||||
{
|
||||
NDR_CHECK(ejs_pull_uint32(ejs, v, "in.in_data", &r->in.in_data));
|
||||
return NT_STATUS_OK;
|
||||
}
|
||||
|
||||
|
||||
NTSTATUS ejs_push_echo_AddOne(struct ejs_rpc *ejs,
|
||||
struct MprVar *v,
|
||||
const struct echo_AddOne *r)
|
||||
{
|
||||
NDR_CHECK(ejs_push_uint32(ejs, v, "out.out_data", *r->out.out_data));
|
||||
return NT_STATUS_OK;
|
||||
}
|
118
source/scripting/ejs/ejsrpc.c
Normal file
118
source/scripting/ejs/ejsrpc.c
Normal file
@ -0,0 +1,118 @@
|
||||
/*
|
||||
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 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 "lib/ejs/ejs.h"
|
||||
#include "scripting/ejs/ejsrpc.h"
|
||||
|
||||
NTSTATUS ejs_pull_rpc(struct MprVar *v, void *ptr, ejs_pull_function_t ejs_pull)
|
||||
{
|
||||
struct ejs_rpc *ejs = talloc(ptr, struct ejs_rpc);
|
||||
return ejs_pull(ejs, v, ptr);
|
||||
}
|
||||
|
||||
|
||||
NTSTATUS ejs_push_rpc(struct MprVar *v, const void *ptr, ejs_push_function_t ejs_push)
|
||||
{
|
||||
struct ejs_rpc *ejs = talloc(ptr, struct ejs_rpc);
|
||||
return ejs_push(ejs, v, ptr);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
find a mpr component, allowing for sub objects, using the '.' convention
|
||||
*/
|
||||
static struct MprVar *mprGetVar(struct MprVar *v, const char *name)
|
||||
{
|
||||
const char *p = strchr(name, '.');
|
||||
char *objname;
|
||||
struct MprVar *v2;
|
||||
if (p == NULL) {
|
||||
return mprGetProperty(v, name, NULL);
|
||||
}
|
||||
objname = talloc_strndup(mprMemCtx(), name, p-name);
|
||||
if (objname == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
v2 = mprGetProperty(v, objname, NULL);
|
||||
if (v2 == NULL) {
|
||||
talloc_free(objname);
|
||||
return NULL;
|
||||
}
|
||||
v2 = mprGetVar(v2, p+1);
|
||||
talloc_free(objname);
|
||||
return v2;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
set a mpr component, allowing for sub objects, using the '.' convention
|
||||
*/
|
||||
static NTSTATUS mprSetVar(struct MprVar *v, const char *name, struct MprVar val)
|
||||
{
|
||||
const char *p = strchr(name, '.');
|
||||
char *objname;
|
||||
struct MprVar *v2;
|
||||
NTSTATUS status;
|
||||
if (p == NULL) {
|
||||
v2 = mprSetProperty(v, name, &val);
|
||||
if (v2 == NULL) {
|
||||
return NT_STATUS_INVALID_PARAMETER_MIX;
|
||||
}
|
||||
return NT_STATUS_OK;
|
||||
}
|
||||
objname = talloc_strndup(mprMemCtx(), name, p-name);
|
||||
if (objname == NULL) {
|
||||
return NT_STATUS_NO_MEMORY;
|
||||
}
|
||||
v2 = mprGetProperty(v, objname, NULL);
|
||||
if (v2 == NULL) {
|
||||
struct MprVar val2 = mprCreateObjVar(objname, MPR_DEFAULT_HASH_SIZE);
|
||||
v2 = mprCreateProperty(v, objname, &val2);
|
||||
}
|
||||
status = mprSetVar(v2, p+1, val);
|
||||
talloc_free(objname);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
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)
|
||||
{
|
||||
struct MprVar *var;
|
||||
var = mprGetVar(v, name);
|
||||
if (var == NULL) {
|
||||
return NT_STATUS_INVALID_PARAMETER_MIX;
|
||||
}
|
||||
*r = mprVarToInteger(var);
|
||||
return NT_STATUS_OK;
|
||||
|
||||
}
|
||||
|
||||
NTSTATUS ejs_push_uint32(struct ejs_rpc *ejs,
|
||||
struct MprVar *v, const char *name, uint32_t r)
|
||||
{
|
||||
return mprSetVar(v, name, mprCreateIntegerVar(r));
|
||||
}
|
48
source/scripting/ejs/ejsrpc.h
Normal file
48
source/scripting/ejs/ejsrpc.h
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
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 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.
|
||||
*/
|
||||
|
||||
struct ejs_rpc {
|
||||
|
||||
};
|
||||
|
||||
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_pull_rpc(struct MprVar *v, void *ptr, ejs_pull_function_t ejs_pull);
|
||||
NTSTATUS ejs_push_rpc(struct MprVar *v, const void *ptr, ejs_push_function_t ejs_push);
|
||||
NTSTATUS ejs_pull_uint32(struct ejs_rpc *ejs,
|
||||
struct MprVar *v, const char *name, uint32_t *r);
|
||||
NTSTATUS ejs_push_uint32(struct ejs_rpc *ejs,
|
||||
struct MprVar *v, const char *name, uint32_t r);
|
||||
|
||||
|
||||
/* echo calls */
|
||||
|
||||
#include "librpc/gen_ndr/ndr_echo.h"
|
||||
|
||||
NTSTATUS ejs_pull_echo_AddOne(struct ejs_rpc *ejs,
|
||||
struct MprVar *v, struct echo_AddOne *r);
|
||||
NTSTATUS ejs_push_echo_AddOne(struct ejs_rpc *ejs,
|
||||
struct MprVar *v,
|
||||
const struct echo_AddOne *r);
|
||||
|
@ -218,9 +218,9 @@ struct MprVar mprWERROR(WERROR status)
|
||||
/*
|
||||
set a pointer in a existing MprVar
|
||||
*/
|
||||
void mprSetPtr(struct MprVar *v, const char *propname, void *p)
|
||||
void mprSetPtr(struct MprVar *v, const char *propname, const void *p)
|
||||
{
|
||||
struct MprVar val = mprCreatePtrVar(p, talloc_get_name(p));
|
||||
struct MprVar val = mprCreatePtrVar(discard_const(p), NULL);
|
||||
mprCreateProperty(v, propname, &val);
|
||||
}
|
||||
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "lib/ejs/ejs.h"
|
||||
#include "librpc/gen_ndr/ndr_echo.h"
|
||||
#include "lib/cmdline/popt_common.h"
|
||||
#include "scripting/ejs/ejsrpc.h"
|
||||
|
||||
/*
|
||||
connect to an rpc server
|
||||
@ -61,9 +62,13 @@ static int ejs_rpc_connect(MprVarHandle eid, int argc, struct MprVar **argv)
|
||||
status = dcerpc_pipe_connect(mprMemCtx(), &p, binding,
|
||||
iface->uuid, iface->if_version,
|
||||
cmdline_credentials, NULL);
|
||||
if (NT_STATUS_IS_OK(status)) {
|
||||
mprSetPtr(conn, "pipe", p);
|
||||
}
|
||||
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;
|
||||
|
||||
mprSetPtr(conn, "pipe", p);
|
||||
mprSetPtr(conn, "iface", iface);
|
||||
|
||||
done:
|
||||
ejsSetReturnValue(eid, mprNTSTATUS(status));
|
||||
@ -78,10 +83,15 @@ done:
|
||||
*/
|
||||
static int ejs_rpc_call(MprVarHandle eid, int argc, struct MprVar **argv)
|
||||
{
|
||||
struct dcerpc_pipe *p;
|
||||
struct MprVar *conn, *io;
|
||||
const char *call;
|
||||
const struct dcerpc_interface_table *iface;
|
||||
struct dcerpc_pipe *p;
|
||||
const char *callname;
|
||||
const struct dcerpc_interface_call *call;
|
||||
NTSTATUS status;
|
||||
void *ptr;
|
||||
struct rpc_request *req;
|
||||
int callnum;
|
||||
|
||||
if (argc != 3 ||
|
||||
argv[0]->type != MPR_TYPE_OBJECT ||
|
||||
@ -91,17 +101,62 @@ static int ejs_rpc_call(MprVarHandle eid, int argc, struct MprVar **argv)
|
||||
return -1;
|
||||
}
|
||||
|
||||
conn = argv[0];
|
||||
call = mprToString(argv[1]);
|
||||
io = argv[2];
|
||||
conn = argv[0];
|
||||
callname = mprToString(argv[1]);
|
||||
io = argv[2];
|
||||
|
||||
/* get the pipe info */
|
||||
p = mprGetPtr(conn, "pipe");
|
||||
if (p == NULL) {
|
||||
iface = mprGetPtr(conn, "iface");
|
||||
if (p == NULL || iface == NULL) {
|
||||
ejsSetErrorMsg(eid, "rpc_call invalid pipe");
|
||||
return -1;
|
||||
}
|
||||
|
||||
status = NT_STATUS_NOT_IMPLEMENTED;
|
||||
/* find the call by name */
|
||||
call = dcerpc_iface_find_call(iface, callname);
|
||||
if (call == NULL) {
|
||||
status = NT_STATUS_OBJECT_NAME_INVALID;
|
||||
goto done;
|
||||
}
|
||||
callnum = call - iface->calls;
|
||||
|
||||
/* allocate the C structure */
|
||||
ptr = talloc_zero_size(mprMemCtx(), call->struct_size);
|
||||
if (ptr == NULL) {
|
||||
status = NT_STATUS_NO_MEMORY;
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* convert the mpr object into a C structure */
|
||||
status = ejs_pull_rpc(io, ptr, (ejs_pull_function_t)ejs_pull_echo_AddOne);
|
||||
if (!NT_STATUS_IS_OK(status)) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
||||
/* make the actual call */
|
||||
req = dcerpc_ndr_request_send(p, NULL, iface, callnum, ptr, ptr);
|
||||
if (req == NULL) {
|
||||
status = NT_STATUS_NO_MEMORY;
|
||||
talloc_free(ptr);
|
||||
goto done;
|
||||
}
|
||||
status = dcerpc_ndr_request_recv(req);
|
||||
|
||||
/* 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_rpc(io, ptr, (ejs_push_function_t)ejs_push_echo_AddOne);
|
||||
|
||||
talloc_free(ptr);
|
||||
done:
|
||||
ejsSetReturnValue(eid, mprNTSTATUS(status));
|
||||
return 0;
|
||||
}
|
||||
@ -114,3 +169,5 @@ void smb_setup_ejs_rpc(void)
|
||||
ejsDefineCFunction(-1, "rpc_connect", ejs_rpc_connect, NULL, MPR_VAR_SCRIPT_HANDLE);
|
||||
ejsDefineCFunction(-1, "rpc_call", ejs_rpc_call, NULL, MPR_VAR_SCRIPT_HANDLE);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user