2 Unix SMB/CIFS implementation.
4 provides interfaces to libnet calls from ejs scripts
6 Copyright (C) Rafal Szczesniak 2005-2007
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/>.
24 #include "lib/appweb/ejs/ejs.h"
25 #include "libnet/libnet.h"
26 #include "scripting/ejs/ejsnet/proto.h"
27 #include "scripting/ejs/smbcalls.h"
28 #include "events/events.h"
29 #include "auth/credentials/credentials.h"
32 static int ejs_net_domainlist(MprVarHandle eid, int argc, char **argv);
37 hostCtx = net.HostMgr(hostname = <default from credentials>)
39 int ejs_net_hostman(MprVarHandle eid, int argc, struct MprVar** argv)
41 struct libnet_context *ctx;
46 ctx = mprGetThisPtr(eid, "ctx");
48 ejsSetErrorMsg(eid, "ctx property returns null pointer");
52 /* fetch the arguments: host name */
54 /* default host (machine) name is supplied in credentials */
55 hostname = cli_credentials_get_workstation(ctx->cred);
57 } else if (argc == 1 && mprVarIsString(argv[0]->type)) {
58 /* host name has been specified */
59 hostname = mprToString(argv[0]);
62 ejsSetErrorMsg(eid, "too many arguments");
66 /* create the NetHostCtx object */
67 obj = mprObject("NetHostCtx");
69 /* create a copy of the string for the object */
70 hostname = talloc_strdup(ctx, hostname);
72 /* add internal libnet_context pointer to the NetHostCtx object */
73 mprSetPtrChild(&obj, "ctx", ctx);
74 mprSetPtrChild(&obj, "hostname", hostname);
76 /* add methods to the object */
77 mprSetStringCFunction(&obj, "DomainList", ejs_net_domainlist);
79 /* set the object returned by this function */
86 static int ejs_net_domainlist(MprVarHandle eid, int argc, char **argv)
91 struct libnet_context *ctx;
92 struct libnet_DomainList req;
93 struct MprVar mprDomains;
95 mem_ctx = talloc_new(mprMemCtx());
96 if (mem_ctx == NULL) {
97 ejsSetErrorMsg(eid, "could not create memory context - out of memory");
102 ctx = mprGetThisPtr(eid, "ctx");
104 ejsSetErrorMsg(eid, "ctx property returns null pointer");
108 hostname = mprGetThisPtr(eid, "hostname");
109 if (hostname == NULL) {
110 ejsSetErrorMsg(eid, "hostname property returns null pointer");
114 /* call the libnet function */
115 req.in.hostname = hostname;
117 status = libnet_DomainList(ctx, mem_ctx, &req);
118 mprDomains = mprDomainsList(mem_ctx, &req, status);
121 talloc_free(mem_ctx);
122 mpr_Return(eid, mprDomains);