svn commit: samba r11281 - in
branches/SAMBA_4_0/source/scripting/ejs: .
mimir at samba.org
mimir at samba.org
Mon Oct 24 21:10:55 GMT 2005
Author: mimir
Date: 2005-10-24 21:10:53 +0000 (Mon, 24 Oct 2005)
New Revision: 11281
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=11281
Log:
Initial ejs interface for libnet functions.
rafal
Added:
branches/SAMBA_4_0/source/scripting/ejs/ejsnet.c
branches/SAMBA_4_0/source/scripting/ejs/ejsnet.h
Modified:
branches/SAMBA_4_0/source/scripting/ejs/config.mk
branches/SAMBA_4_0/source/scripting/ejs/smbcalls.c
Changeset:
Modified: branches/SAMBA_4_0/source/scripting/ejs/config.mk
===================================================================
--- branches/SAMBA_4_0/source/scripting/ejs/config.mk 2005-10-24 16:55:26 UTC (rev 11280)
+++ branches/SAMBA_4_0/source/scripting/ejs/config.mk 2005-10-24 21:10:53 UTC (rev 11281)
@@ -28,8 +28,9 @@
smbcalls_creds.o \
smbcalls_samba3.o \
smbcalls_param.o \
+ ejsnet.o \
mprutil.o
-REQUIRED_SUBSYSTEMS = AUTH EJS LIBBASIC EJSRPC MESSAGING LIBSAMBA3
+REQUIRED_SUBSYSTEMS = AUTH EJS LIBBASIC EJSRPC MESSAGING LIBSAMBA3 LIBNET
# End SUBSYSTEM SMBCALLS
#######################
Added: branches/SAMBA_4_0/source/scripting/ejs/ejsnet.c
===================================================================
--- branches/SAMBA_4_0/source/scripting/ejs/ejsnet.c 2005-10-24 16:55:26 UTC (rev 11280)
+++ branches/SAMBA_4_0/source/scripting/ejs/ejsnet.c 2005-10-24 21:10:53 UTC (rev 11281)
@@ -0,0 +1,119 @@
+/*
+ Unix SMB/CIFS implementation.
+
+ provide interfaces to libnet calls from ejs scripts
+
+ Copyright (C) Rafal Szczesniak 2005
+
+ 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 "scripting/ejs/smbcalls.h"
+#include "scripting/ejs/ejsnet.h"
+#include "libnet/libnet.h"
+
+
+static int ejs_net_context(MprVarHandle eid, int argc, struct MprVar **argv)
+{
+ struct cli_credentials *creds;
+ struct libnet_context *ctx;
+ struct MprVar *obj;
+
+ ctx = libnet_context_init(NULL);
+ creds = talloc(ctx, struct cli_credentials);
+ ctx->cred = creds;
+
+ if (argc == 0) {
+ cli_credentials_set_anonymous(creds);
+
+ } else if (argc == 2 || argc == 4 ) {
+
+ if (!mprVarIsString(argv[0]->type)) {
+ ejsSetErrorMsg(eid, "argument 1 must be a string");
+ goto done;
+ }
+ cli_credentials_set_username(creds, argv[0]->string, CRED_SPECIFIED);
+
+ if (!mprVarIsString(argv[1]->type)) {
+ ejsSetErrorMsg(eid, "argument 2 must be a string");
+ goto done;
+ }
+ cli_credentials_set_password(creds, argv[1]->string, CRED_SPECIFIED);
+
+ } else {
+ ejsSetErrorMsg(eid, "invalid number of arguments");
+ goto done;
+ }
+
+
+ if (argc == 4) {
+
+ if (!mprVarIsString(argv[2]->type)) {
+ ejsSetErrorMsg(eid, "argument 3 must be a string");
+ goto done;
+ }
+ cli_credentials_set_domain(creds, argv[2]->string, CRED_SPECIFIED);
+
+ if (!mprVarIsString(argv[3]->type)) {
+ ejsSetErrorMsg(eid, "argument 4 must be a string");
+ goto done;
+ }
+ cli_credentials_set_realm(creds, argv[3]->string, CRED_SPECIFIED);
+ }
+
+ obj = mprInitObject(eid, "NetCtx", argc, argv);
+
+ mprSetStringCFunction(obj, "CreateUser", ejs_net_createuser);
+ mprSetPtrChild(obj, "ctx", ctx);
+
+ return 0;
+done:
+ talloc_free(ctx);
+ return -1;
+}
+
+
+static int ejs_net_createuser(MprVarHandle eid, int argc, char **argv)
+{
+ NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
+ TALLOC_CTX *mem_ctx;
+ struct libnet_context *ctx;
+ struct libnet_CreateUser req;
+
+ if (argc != 1) {
+ ejsSetErrorMsg(eid, "argument 1 must be a string");
+ goto done;
+ }
+
+ ctx = mprGetThisPtr(eid, "ctx");
+ mem_ctx = talloc_init(NULL);
+
+ req.in.domain_name = cli_credentials_get_domain(ctx->cred);
+ req.in.user_name = argv[0];
+
+ status = libnet_CreateUser(ctx, mem_ctx, &req);
+
+ talloc_free(mem_ctx);
+done:
+ return NT_STATUS_IS_OK(status) ? 0 : -1;
+}
+
+
+void ejsnet_setup(void)
+{
+ ejsDefineCFunction(-1, "NetContext", ejs_net_context, NULL, MPR_VAR_SCRIPT_HANDLE);
+}
Added: branches/SAMBA_4_0/source/scripting/ejs/ejsnet.h
===================================================================
--- branches/SAMBA_4_0/source/scripting/ejs/ejsnet.h 2005-10-24 16:55:26 UTC (rev 11280)
+++ branches/SAMBA_4_0/source/scripting/ejs/ejsnet.h 2005-10-24 21:10:53 UTC (rev 11281)
@@ -0,0 +1,27 @@
+/*
+ Unix SMB/CIFS implementation.
+
+ provide interfaces to libnet calls from ejs scripts
+
+ Copyright (C) Rafal Szczesniak 2005
+
+ 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 "lib/appweb/ejs/ejs.h"
+
+
+void ejsnet_setup(void);
+static int ejs_net_createuser(MprVarHandle, int, char**);
Modified: branches/SAMBA_4_0/source/scripting/ejs/smbcalls.c
===================================================================
--- branches/SAMBA_4_0/source/scripting/ejs/smbcalls.c 2005-10-24 16:55:26 UTC (rev 11280)
+++ branches/SAMBA_4_0/source/scripting/ejs/smbcalls.c 2005-10-24 21:10:53 UTC (rev 11281)
@@ -131,6 +131,7 @@
smb_setup_ejs_samba3();
smb_setup_ejs_param();
smb_setup_ejs_datablob();
+ ejsnet_setup();
ejsDefineCFunction(-1, "typeof", ejs_typeof, NULL, MPR_VAR_SCRIPT_HANDLE);
ejsDefineStringCFunction(-1, "libinclude", ejs_libinclude, NULL, MPR_VAR_SCRIPT_HANDLE);
More information about the samba-cvs
mailing list