svn commit: samba r23124 - in branches/SAMBA_4_0/source/scripting/ejs/ejsnet: .

mimir at samba.org mimir at samba.org
Thu May 24 21:44:28 GMT 2007


Author: mimir
Date: 2007-05-24 21:44:27 +0000 (Thu, 24 May 2007)
New Revision: 23124

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=23124

Log:
add host subcontext providing (at the moment) list of domains
hosted on the server.


rafal


Added:
   branches/SAMBA_4_0/source/scripting/ejs/ejsnet/mpr_host.c
   branches/SAMBA_4_0/source/scripting/ejs/ejsnet/net_host.c
Modified:
   branches/SAMBA_4_0/source/scripting/ejs/ejsnet/config.mk


Changeset:
Modified: branches/SAMBA_4_0/source/scripting/ejs/ejsnet/config.mk
===================================================================
--- branches/SAMBA_4_0/source/scripting/ejs/ejsnet/config.mk	2007-05-24 21:29:15 UTC (rev 23123)
+++ branches/SAMBA_4_0/source/scripting/ejs/ejsnet/config.mk	2007-05-24 21:44:27 UTC (rev 23124)
@@ -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

Added: branches/SAMBA_4_0/source/scripting/ejs/ejsnet/mpr_host.c
===================================================================
--- branches/SAMBA_4_0/source/scripting/ejs/ejsnet/mpr_host.c	2007-05-24 21:29:15 UTC (rev 23123)
+++ branches/SAMBA_4_0/source/scripting/ejs/ejsnet/mpr_host.c	2007-05-24 21:44:27 UTC (rev 23124)
@@ -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;
+}

Added: branches/SAMBA_4_0/source/scripting/ejs/ejsnet/net_host.c
===================================================================
--- branches/SAMBA_4_0/source/scripting/ejs/ejsnet/net_host.c	2007-05-24 21:29:15 UTC (rev 23123)
+++ branches/SAMBA_4_0/source/scripting/ejs/ejsnet/net_host.c	2007-05-24 21:44:27 UTC (rev 23124)
@@ -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;
+}



More information about the samba-cvs mailing list