summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
authorTim Potter <tpot@samba.org>2005-05-29 22:14:21 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:17:14 -0500
commit4f1a5b716972bc2af916a528399c9dc0c2f18c35 (patch)
treed6b4bbdac96e56a54cf3f9bf03ee157d459fa253 /source4
parent520e2258c9949f9129a2e124035c0200c0c59b39 (diff)
downloadsamba-4f1a5b716972bc2af916a528399c9dc0c2f18c35.tar.gz
samba-4f1a5b716972bc2af916a528399c9dc0c2f18c35.tar.bz2
samba-4f1a5b716972bc2af916a528399c9dc0c2f18c35.zip
r7083: Add a ejs hook to the resolve_name() function.
We need to figure out what the best way to return NTSTATUS codes. In the Python wrappers I threw an exception which could be caught by some code, but I'm not sure whether this is possible in ejs. (This used to be commit 6911e46c6a576a379ea06f9ba3ef6a62653170f0)
Diffstat (limited to 'source4')
-rw-r--r--source4/scripting/ejs/smbcalls.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/source4/scripting/ejs/smbcalls.c b/source4/scripting/ejs/smbcalls.c
index e436fc78df..02b40c46d8 100644
--- a/source4/scripting/ejs/smbcalls.c
+++ b/source4/scripting/ejs/smbcalls.c
@@ -24,6 +24,7 @@
#include "lib/ejs/ejs.h"
#include "param/loadparm.h"
#include "lib/ldb/include/ldb.h"
+#include "librpc/gen_ndr/ndr_nbt.h"
/*
return the type of a variable
@@ -246,6 +247,55 @@ failed:
return -1;
}
+/*
+ look up a netbios name
+
+ syntax:
+ resolveName("frogurt");
+ resolveName("frogurt", 0x1c);
+*/
+
+static int ejs_resolve_name(MprVarHandle eid, int argc, struct MprVar **argv)
+{
+ struct nbt_name name;
+ TALLOC_CTX *tmp_ctx = talloc_new(mprMemCtx());
+ NTSTATUS result;
+ const char *reply_addr;
+
+ /* validate arguments */
+ if (argc == 1) {
+ if (argv[0]->type != MPR_TYPE_STRING) {
+ ejsSetErrorMsg(eid, "resolveName invalid arguments");
+ goto failed;
+ }
+ make_nbt_name_client(&name, mprToString(argv[0]));
+ } else if (argc == 2) {
+ if (argv[1]->type != MPR_TYPE_INT) {
+ ejsSetErrorMsg(eid, "resolveName invalid arguments");
+ goto failed;
+ }
+ make_nbt_name(&name, mprToString(argv[0]), mprToInt(argv[1]));
+ } else {
+ ejsSetErrorMsg(eid, "resolveName invalid arguments");
+ goto failed;
+ }
+
+ result = resolve_name(&name, tmp_ctx, &reply_addr);
+
+ if (!NT_STATUS_IS_OK(result)) {
+ ejsSetErrorMsg(eid, "resolveName name not found");
+ goto failed;
+ }
+
+ ejsSetReturnString(eid, reply_addr);
+
+ talloc_free(tmp_ctx);
+ return 0;
+
+ failed:
+ talloc_free(tmp_ctx);
+ return -1;
+}
/*
setup the C functions that be called from ejs
@@ -256,4 +306,5 @@ void smb_setup_ejs_functions(void)
ejsDefineStringCFunction(-1, "lpServices", ejs_lpServices, NULL, MPR_VAR_SCRIPT_HANDLE);
ejsDefineCFunction(-1, "typeof", ejs_typeof, NULL, MPR_VAR_SCRIPT_HANDLE);
ejsDefineCFunction(-1, "ldbSearch", ejs_ldbSearch, NULL, MPR_VAR_SCRIPT_HANDLE);
+ ejsDefineCFunction(-1, "resolveName", ejs_resolve_name, NULL, MPR_VAR_SCRIPT_HANDLE);
}