2 Unix SMB/CIFS implementation.
4 provide hooks into smbd C calls from ejs scripts
6 Copyright (C) Tim Potter 2005
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "scripting/ejs/smbcalls.h"
24 #include "lib/appweb/ejs/ejs.h"
25 #include "librpc/gen_ndr/nbt.h"
26 #include "lib/events/events.h"
27 #include "libcli/resolve/resolve.h"
30 look up a netbios name
33 resolveName(result, "frogurt");
34 resolveName(result, "frogurt", 0x1c);
37 static int ejs_resolve_name(MprVarHandle eid, int argc, struct MprVar **argv)
41 TALLOC_CTX *tmp_ctx = talloc_new(mprMemCtx());
43 const char *reply_addr;
45 /* validate arguments */
46 if (argc < 2 || argc > 3) {
47 ejsSetErrorMsg(eid, "resolveName invalid arguments");
51 if (argv[0]->type != MPR_TYPE_OBJECT) {
52 ejsSetErrorMsg(eid, "resolvename invalid arguments");
56 if (argv[1]->type != MPR_TYPE_STRING) {
57 ejsSetErrorMsg(eid, "resolveName invalid arguments");
62 make_nbt_name_client(&name, mprToString(argv[1]));
64 if (!mprVarIsNumber(argv[1]->type)) {
65 ejsSetErrorMsg(eid, "resolveName invalid arguments");
68 make_nbt_name(&name, mprToString(argv[1]), mprToInt(argv[2]));
73 nt_status = resolve_name(&name, tmp_ctx, &reply_addr, event_context_find(tmp_ctx));
75 if (NT_STATUS_IS_OK(nt_status)) {
76 mprSetPropertyValue(argv[0], "value", mprString(reply_addr));
79 mpr_Return(eid, mprNTSTATUS(nt_status));
87 setup C functions that be called from ejs
89 NTSTATUS smb_setup_ejs_nbt(void)
91 ejsDefineCFunction(-1, "resolveName", ejs_resolve_name, NULL, MPR_VAR_SCRIPT_HANDLE);