summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source4/scripting/ejs/ejsnet/config.mk4
-rw-r--r--source4/scripting/ejs/ejsnet/mpr_host.c75
-rw-r--r--source4/scripting/ejs/ejsnet/net_host.c125
3 files changed, 203 insertions, 1 deletions
diff --git a/source4/scripting/ejs/ejsnet/config.mk b/source4/scripting/ejs/ejsnet/config.mk
index ce71ff51df..249a33121d 100644
--- a/source4/scripting/ejs/ejsnet/config.mk
+++ b/source4/scripting/ejs/ejsnet/config.mk
@@ -2,7 +2,9 @@
OBJ_FILES = \
net_ctx.o \
net_user.o \
- mpr_user.o
+ mpr_user.o \
+ net_host.o \
+ mpr_host.o
SUBSYSTEM = smbcalls
INIT_FUNCTION = smb_setup_ejs_net
PRIVATE_PROTO_HEADER = proto.h
diff --git a/source4/scripting/ejs/ejsnet/mpr_host.c b/source4/scripting/ejs/ejsnet/mpr_host.c
new file mode 100644
index 0000000000..1755b23085
--- /dev/null
+++ b/source4/scripting/ejs/ejsnet/mpr_host.c
@@ -0,0 +1,75 @@
+/*
+ Unix SMB/CIFS implementation.
+
+ provides interfaces to libnet calls from ejs scripts
+
+ Copyright (C) Rafal Szczesniak 2005-2007
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+
+#include "includes.h"
+#include "lib/appweb/ejs/ejs.h"
+#include "libnet/libnet.h"
+#include "scripting/ejs/smbcalls.h"
+#include "events/events.h"
+#include "auth/credentials/credentials.h"
+
+
+/*
+ Properties:
+ DomainsList.Domains[0]
+ DomainsList.Status
+*/
+struct MprVar mprDomainsList(TALLOC_CTX *mem_ctx, struct libnet_DomainList *list, NTSTATUS result)
+{
+ const char *name = "DomainsList";
+ NTSTATUS status;
+ struct MprVar mprDomainList, mprDomains;
+ struct MprVar mprSid, mprDomainName;
+ struct MprVar mprDomain;
+ int i;
+
+ if (list == NULL || mem_ctx == NULL) {
+ mprDomainList = mprCreateNullVar();
+ goto done;
+ }
+
+ mprDomains = mprArray("Domains");
+ for (i = 0; i < list->out.count; i++) {
+ struct domainlist d = list->out.domains[i];
+
+ /* get domainlist fields */
+ mprSid = mprString(d.sid);
+ mprDomainName = mprString(d.name);
+
+ mprDomain = mprObject("Domain");
+ mprSetVar(&mprDomain, "Name", mprDomainName);
+ mprSetVar(&mprDomain, "SID", mprSid);
+
+ mprAddArray(&mprDomains, i, mprDomain);
+ }
+
+ mprDomainList = mprObject(name);
+ status = mprSetVar(&mprDomainList, "Domains", mprDomains);
+ if (!NT_STATUS_IS_OK(status)) goto done;
+ status = mprSetVar(&mprDomainList, "Count", mprCreateIntegerVar(list->out.count));
+ if (!NT_STATUS_IS_OK(status)) goto done;
+ status = mprSetVar(&mprDomainList, "Status", mprNTSTATUS(result));
+
+done:
+ return mprDomainList;
+}
diff --git a/source4/scripting/ejs/ejsnet/net_host.c b/source4/scripting/ejs/ejsnet/net_host.c
new file mode 100644
index 0000000000..d98f1d118f
--- /dev/null
+++ b/source4/scripting/ejs/ejsnet/net_host.c
@@ -0,0 +1,125 @@
+/*
+ Unix SMB/CIFS implementation.
+
+ provides interfaces to libnet calls from ejs scripts
+
+ Copyright (C) Rafal Szczesniak 2005-2007
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+
+#include "includes.h"
+#include "lib/appweb/ejs/ejs.h"
+#include "libnet/libnet.h"
+#include "scripting/ejs/ejsnet/proto.h"
+#include "scripting/ejs/smbcalls.h"
+#include "events/events.h"
+#include "auth/credentials/credentials.h"
+
+
+static int ejs_net_domainlist(MprVarHandle eid, int argc, char **argv);
+
+
+/*
+ Usage:
+ hostCtx = net.HostMgr(hostname = <default from credentials>)
+*/
+int ejs_net_hostman(MprVarHandle eid, int argc, struct MprVar** argv)
+{
+ struct libnet_context *ctx;
+ const char *hostname;
+ struct MprVar obj;
+
+ /* libnet context */
+ ctx = mprGetThisPtr(eid, "ctx");
+ if (ctx == NULL) {
+ ejsSetErrorMsg(eid, "ctx property returns null pointer");
+ return 0;
+ }
+
+ /* fetch the arguments: host name */
+ if (argc == 0) {
+ /* default host (machine) name is supplied in credentials */
+ hostname = cli_credentials_get_workstation(ctx->cred);
+
+ } else if (argc == 1 && mprVarIsString(argv[0]->type)) {
+ /* host name has been specified */
+ hostname = mprToString(argv[0]);
+
+ } else {
+ ejsSetErrorMsg(eid, "too many arguments");
+ return 0;
+ }
+
+ /* create the NetHostCtx object */
+ obj = mprObject("NetHostCtx");
+
+ /* create a copy of the string for the object */
+ hostname = talloc_strdup(ctx, hostname);
+
+ /* add internal libnet_context pointer to the NetHostCtx object */
+ mprSetPtrChild(&obj, "ctx", ctx);
+ mprSetPtrChild(&obj, "hostname", hostname);
+
+ /* add methods to the object */
+ mprSetStringCFunction(&obj, "DomainList", ejs_net_domainlist);
+
+ /* set the object returned by this function */
+ mpr_Return(eid, obj);
+
+ return 0;
+}
+
+
+static int ejs_net_domainlist(MprVarHandle eid, int argc, char **argv)
+{
+ NTSTATUS status;
+ TALLOC_CTX *mem_ctx;
+ const char* hostname;
+ struct libnet_context *ctx;
+ struct libnet_DomainList req;
+ struct MprVar mprDomains;
+
+ mem_ctx = talloc_new(mprMemCtx());
+ if (mem_ctx == NULL) {
+ ejsSetErrorMsg(eid, "could not create memory context - out of memory");
+ goto done;
+ }
+
+ /* libnet context */
+ ctx = mprGetThisPtr(eid, "ctx");
+ if (ctx == NULL) {
+ ejsSetErrorMsg(eid, "ctx property returns null pointer");
+ goto done;
+ }
+
+ hostname = mprGetThisPtr(eid, "hostname");
+ if (hostname == NULL) {
+ ejsSetErrorMsg(eid, "hostname property returns null pointer");
+ goto done;
+ }
+
+ /* call the libnet function */
+ req.in.hostname = hostname;
+
+ status = libnet_DomainList(ctx, mem_ctx, &req);
+ mprDomains = mprDomainsList(mem_ctx, &req, status);
+
+done:
+ talloc_free(mem_ctx);
+ mpr_Return(eid, mprDomains);
+ return 0;
+}