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 2 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, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "scripting/ejs/smbcalls.h"
25 #include "lib/appweb/ejs/ejs.h"
26 #include "librpc/gen_ndr/nbt.h"
27 #include "lib/events/events.h"
28 #include "libcli/resolve/resolve.h"
31 look up a netbios name
34 resolveName(result, "frogurt");
35 resolveName(result, "frogurt", 0x1c);
38 static int ejs_resolve_name(MprVarHandle eid, int argc, struct MprVar **argv)
42 TALLOC_CTX *tmp_ctx = talloc_new(mprMemCtx());
44 const char *reply_addr;
46 /* validate arguments */
47 if (argc < 2 || argc > 3) {
48 ejsSetErrorMsg(eid, "resolveName invalid arguments");
52 if (argv[0]->type != MPR_TYPE_OBJECT) {
53 ejsSetErrorMsg(eid, "resolvename invalid arguments");
57 if (argv[1]->type != MPR_TYPE_STRING) {
58 ejsSetErrorMsg(eid, "resolveName invalid arguments");
63 make_nbt_name_client(&name, mprToString(argv[1]));
65 if (!mprVarIsNumber(argv[1]->type)) {
66 ejsSetErrorMsg(eid, "resolveName invalid arguments");
69 make_nbt_name(&name, mprToString(argv[1]), mprToInt(argv[2]));
74 nt_status = resolve_name(&name, tmp_ctx, &reply_addr, event_context_find(tmp_ctx));
76 if (NT_STATUS_IS_OK(nt_status)) {
77 mprSetPropertyValue(argv[0], "value", mprString(reply_addr));
80 mpr_Return(eid, mprNTSTATUS(nt_status));
88 setup C functions that be called from ejs
90 void smb_setup_ejs_nbt(void)
92 ejsDefineCFunction(-1, "resolveName", ejs_resolve_name, NULL, MPR_VAR_SCRIPT_HANDLE);