summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
Diffstat (limited to 'source4')
-rw-r--r--source4/build/pidl/ejs.pm76
-rw-r--r--source4/scripting/ejs/ejsrpc.c47
-rw-r--r--source4/scripting/ejs/ejsrpc.h14
-rw-r--r--source4/scripting/ejs/smbcalls_rpc.c4
4 files changed, 112 insertions, 29 deletions
diff --git a/source4/build/pidl/ejs.pm b/source4/build/pidl/ejs.pm
index 14c0c3668f..bd35078abd 100644
--- a/source4/build/pidl/ejs.pm
+++ b/source4/build/pidl/ejs.pm
@@ -97,6 +97,18 @@ sub EjsPullScalar($$)
pidl "\tNDR_CHECK(ejs_pull_$e->{TYPE}(ejs, v, \"$e->{NAME}\", $ptr));\n";
}
+###########################
+# pull a string element
+sub EjsPullString($$$)
+{
+ my $e = shift;
+ my $l = shift;
+ my $env = shift;
+ my $var = util::ParseExpr($e->{NAME}, $env);
+ my $ptr = get_pointer_to($var);
+ pidl "\tNDR_CHECK(ejs_pull_string(ejs, v, \"$e->{NAME}\", $ptr));\n";
+}
+
###########################
# pull an arrar element
@@ -109,7 +121,7 @@ sub EjsPullArray($$$)
my $length = util::ParseExpr($l->{LENGTH_IS}, $env);
my $var = util::ParseExpr($e->{NAME}, $env);
my $ptr = get_pointer_to($var);
- pidl "\tNDR_CHECK(ejs_pull_array(ejs, v, \"$e->{NAME}\", $length, sizeof($ptr\[0]), (void **)$ptr, (ejs_pull_t)ejs_pull_$e->{TYPE}));\n";
+ pidl "\tNDR_CHECK(ejs_pull_array(ejs, v, \"$e->{NAME}\", $length, sizeof($var\[0]), (void **)$ptr, (ejs_pull_t)ejs_pull_$e->{TYPE}));\n";
}
###########################
@@ -119,8 +131,15 @@ sub EjsPullElement($$)
my $e = shift;
my $env = shift;
my $l = $e->{LEVELS}[0];
- ($l->{TYPE} eq "ARRAY") && EjsPullArray($e, $l, $env);
- ($l->{TYPE} eq "DATA") && EjsPullScalar($e, $env);
+ if (util::has_property($e, "charset")) {
+ EjsPullString($e, $l, $env);
+ } elsif ($l->{TYPE} eq "ARRAY") {
+ EjsPullArray($e, $l, $env);
+ } elsif ($l->{TYPE} eq "DATA") {
+ EjsPullScalar($e, $env);
+ } else {
+ pidl "return ejs_panic(ejs, \"unhandled pull type $l->{TYPE}\");\n";
+ }
}
###########################
@@ -169,11 +188,12 @@ sub EjsPullFunction($)
{
my $d = shift;
my $env = GenerateFunctionInEnv($d);
+ my $name = $d->{NAME};
- pidl "\nstatic NTSTATUS ejs_pull_$d->{NAME}(struct ejs_rpc *ejs, struct MprVar *v, struct $d->{NAME} *r)\n";
+ pidl "\nstatic NTSTATUS ejs_pull_$name(struct ejs_rpc *ejs, struct MprVar *v, struct $name *r)\n";
pidl "{\n";
- pidl "\tNDR_CHECK(ejs_pull_struct_start(ejs, &v, \"in\"));\n";
+ pidl "\tNDR_CHECK(ejs_pull_struct_start(ejs, &v, \"input\"));\n";
foreach my $e (@{$d->{ELEMENTS}}) {
next unless (grep(/in/, @{$e->{DIRECTION}}));
@@ -194,15 +214,24 @@ sub EjsPushScalar($$$)
my $env = shift;
my $var = util::ParseExpr($e->{NAME}, $env);
- if (not typelist::is_scalar($l->{DATA_TYPE}) or
- typelist::scalar_is_reference($l->{DATA_TYPE})) {
- $var = get_pointer_to($var);
- }
+ $var = get_pointer_to($var);
pidl "\tNDR_CHECK(ejs_push_$e->{TYPE}(ejs, v, \"$e->{NAME}\", $var));\n";
}
###########################
+# pull a string element
+sub EjsPushString($$$)
+{
+ my $e = shift;
+ my $l = shift;
+ my $env = shift;
+ my $var = util::ParseExpr($e->{NAME}, $env);
+
+ pidl "\tNDR_CHECK(ejs_push_string(ejs, v, \"$e->{NAME}\", $var));\n";
+}
+
+###########################
# pull a pointer element
sub EjsPushPointer($$$)
{
@@ -215,9 +244,7 @@ sub EjsPushPointer($$$)
$var = get_value_of($var);
$l = Ndr::GetNextLevel($e, $l);
}
- if (not typelist::is_scalar($l->{DATA_TYPE})) {
- $var = get_pointer_to($var);
- }
+ $var = get_pointer_to($var);
pidl "\tNDR_CHECK(ejs_push_$e->{TYPE}(ejs, v, \"$e->{NAME}\", $var));\n";
}
@@ -243,9 +270,17 @@ sub EjsPushElement($$)
my $e = shift;
my $env = shift;
my $l = $e->{LEVELS}[0];
- ($l->{TYPE} eq "ARRAY") && EjsPushArray($e, $l, $env);
- ($l->{TYPE} eq "DATA") && EjsPushScalar($e, $l, $env);
- ($l->{TYPE} eq "POINTER") && EjsPushPointer($e, $l, $env);
+ if (util::has_property($e, "charset")) {
+ EjsPushString($e, $l, $env);
+ } elsif ($l->{TYPE} eq "ARRAY") {
+ EjsPushArray($e, $l, $env);
+ } elsif ($l->{TYPE} eq "DATA") {
+ EjsPushScalar($e, $l, $env);
+ } elsif (($l->{TYPE} eq "POINTER")) {
+ EjsPushPointer($e, $l, $env);
+ } else {
+ pidl "return ejs_panic(ejs, \"unhandled push type $l->{TYPE}\");\n";
+ }
}
###########################
@@ -255,7 +290,7 @@ sub EjsStructPush($$)
my $name = shift;
my $d = shift;
my $env = GenerateStructEnv($d);
- pidl "\nstatic NTSTATUS ejs_push_$name(struct ejs_rpc *ejs, struct MprVar *v, const char *name, struct $name *r)\n{\n";
+ pidl "\nstatic NTSTATUS ejs_push_$name(struct ejs_rpc *ejs, struct MprVar *v, const char *name, const struct $name *r)\n{\n";
pidl "\tNDR_CHECK(ejs_push_struct_start(ejs, &v, name));\n";
foreach my $e (@{$d->{ELEMENTS}}) {
EjsPushElement($e, $env);
@@ -270,7 +305,7 @@ sub EjsUnionPush($$)
{
my $name = shift;
my $d = shift;
- pidl "\nstatic NTSTATUS ejs_push_$name(struct ejs_rpc *ejs, struct MprVar *v, const char *name, union $name *r)\n{\n";
+ pidl "\nstatic NTSTATUS ejs_push_$name(struct ejs_rpc *ejs, struct MprVar *v, const char *name, const union $name *r)\n{\n";
pidl "\treturn NT_STATUS_OK;\n";
pidl "}\n\n";
}
@@ -281,8 +316,9 @@ sub EjsEnumPush($$)
{
my $name = shift;
my $d = shift;
- pidl "\nstatic NTSTATUS ejs_push_$name(struct ejs_rpc *ejs, struct MprVar *v, const char *name, enum $name r)\n{\n";
- pidl "\tNDR_CHECK(ejs_push_enum(ejs, v, name, r));\n";
+ pidl "\nstatic NTSTATUS ejs_push_$name(struct ejs_rpc *ejs, struct MprVar *v, const char *name, const enum $name *r)\n{\n";
+ pidl "\tunsigned e = *r;\n";
+ pidl "\tNDR_CHECK(ejs_push_enum(ejs, v, name, &e));\n";
pidl "\treturn NT_STATUS_OK;\n";
pidl "}\n\n";
}
@@ -309,7 +345,7 @@ sub EjsPushFunction($)
pidl "\nstatic NTSTATUS ejs_push_$d->{NAME}(struct ejs_rpc *ejs, struct MprVar *v, const struct $d->{NAME} *r)\n";
pidl "{\n";
- pidl "\tNDR_CHECK(ejs_push_struct_start(ejs, &v, \"out\"));\n";
+ pidl "\tNDR_CHECK(ejs_push_struct_start(ejs, &v, \"output\"));\n";
foreach my $e (@{$d->{ELEMENTS}}) {
next unless (grep(/out/, @{$e->{DIRECTION}}));
diff --git a/source4/scripting/ejs/ejsrpc.c b/source4/scripting/ejs/ejsrpc.c
index 4984518c7f..75f748f146 100644
--- a/source4/scripting/ejs/ejsrpc.c
+++ b/source4/scripting/ejs/ejsrpc.c
@@ -24,21 +24,38 @@
#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)
+NTSTATUS ejs_pull_rpc(int eid, const char *callname,
+ struct MprVar *v, void *ptr, ejs_pull_function_t ejs_pull)
{
- struct ejs_rpc *ejs = talloc(ptr, struct ejs_rpc);
+ struct ejs_rpc *ejs = talloc(ptr, struct ejs_rpc);
+ NT_STATUS_HAVE_NO_MEMORY(ejs);
+ ejs->eid = eid;
+ ejs->callname = callname;
return ejs_pull(ejs, v, ptr);
}
-NTSTATUS ejs_push_rpc(struct MprVar *v, const void *ptr, ejs_push_function_t ejs_push)
+NTSTATUS ejs_push_rpc(int eid, const char *callname,
+ struct MprVar *v, const void *ptr, ejs_push_function_t ejs_push)
{
struct ejs_rpc *ejs = talloc(ptr, struct ejs_rpc);
+ NT_STATUS_HAVE_NO_MEMORY(ejs);
+ ejs->eid = eid;
+ ejs->callname = callname;
return ejs_push(ejs, v, ptr);
}
/*
+ 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;
+}
+
+/*
find a mpr component, allowing for sub objects, using the '.' convention
*/
static struct MprVar *mprGetVar(struct MprVar *v, const char *name)
@@ -279,3 +296,27 @@ NTSTATUS ejs_push_array(struct ejs_rpc *ejs,
return mprSetVar(v, "length", mprCreateIntegerVar(i));
}
+
+/*
+ pull a string
+*/
+NTSTATUS ejs_pull_string(struct ejs_rpc *ejs,
+ struct MprVar *v, const char *name, const char **s)
+{
+ struct MprVar *var;
+ var = mprGetVar(v, name);
+ if (var == NULL) {
+ return NT_STATUS_INVALID_PARAMETER_MIX;
+ }
+ *s = mprToString(var);
+ 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, mprCreateStringVar(s, True));
+}
diff --git a/source4/scripting/ejs/ejsrpc.h b/source4/scripting/ejs/ejsrpc.h
index 1febb90ad6..5fb6ace863 100644
--- a/source4/scripting/ejs/ejsrpc.h
+++ b/source4/scripting/ejs/ejsrpc.h
@@ -21,7 +21,8 @@
*/
struct ejs_rpc {
-
+ int eid;
+ const char *callname;
};
typedef NTSTATUS (*ejs_pull_t)(struct ejs_rpc *, struct MprVar *, const char *, void *);
@@ -29,11 +30,13 @@ typedef NTSTATUS (*ejs_push_t)(struct ejs_rpc *, struct MprVar *, const char *,
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);
+
int ejs_rpc_call(int eid, int argc, struct MprVar **argv, const char *callname,
ejs_pull_function_t ejs_pull, ejs_push_function_t ejs_push);
-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_rpc(int eid, const char *callname, struct MprVar *v, void *ptr, ejs_pull_function_t ejs_pull);
+NTSTATUS ejs_push_rpc(int eid, const char *callname, struct MprVar *v, const void *ptr, 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);
@@ -63,4 +66,7 @@ NTSTATUS ejs_pull_array(struct ejs_rpc *ejs,
NTSTATUS ejs_push_array(struct ejs_rpc *ejs,
struct MprVar *v, const char *name, uint32_t length,
size_t elsize, void *r, ejs_push_t ejs_push);
-
+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);
diff --git a/source4/scripting/ejs/smbcalls_rpc.c b/source4/scripting/ejs/smbcalls_rpc.c
index 631f1c3a37..00675165ea 100644
--- a/source4/scripting/ejs/smbcalls_rpc.c
+++ b/source4/scripting/ejs/smbcalls_rpc.c
@@ -128,7 +128,7 @@ done:
}
/* convert the mpr object into a C structure */
- status = ejs_pull_rpc(io, ptr, ejs_pull);
+ status = ejs_pull_rpc(eid, callname, io, ptr, ejs_pull);
if (!NT_STATUS_IS_OK(status)) {
goto done;
}
@@ -152,7 +152,7 @@ done:
ndr_print_function_debug(call->ndr_print, call->name, NDR_OUT, ptr);
}
- status = ejs_push_rpc(io, ptr, ejs_push);
+ status = ejs_push_rpc(eid, callname, io, ptr, ejs_push);
talloc_free(ptr);
done: