summaryrefslogtreecommitdiff
path: root/source4/scripting
diff options
context:
space:
mode:
Diffstat (limited to 'source4/scripting')
-rwxr-xr-xsource4/scripting/bin/samba3dump4
-rwxr-xr-xsource4/scripting/bin/smbstatus159
-rwxr-xr-xsource4/scripting/bin/winreg107
-rw-r--r--source4/scripting/ejs/config.mk25
-rw-r--r--source4/scripting/ejs/ejsrpc.c424
-rw-r--r--source4/scripting/ejs/ejsrpc.h172
-rw-r--r--source4/scripting/ejs/smbcalls.c1
-rw-r--r--source4/scripting/ejs/smbcalls_cli.c722
-rw-r--r--source4/scripting/ejs/smbcalls_nss.c160
-rw-r--r--source4/scripting/ejs/smbcalls_reg.c90
-rw-r--r--source4/scripting/ejs/smbcalls_rpc.c385
-rw-r--r--source4/scripting/libjs/auth.js18
-rw-r--r--source4/scripting/libjs/management.js157
-rwxr-xr-xsource4/scripting/python/examples/samr.py (renamed from source4/scripting/bin/samr.py)2
-rwxr-xr-xsource4/scripting/python/examples/winreg.py (renamed from source4/scripting/bin/winreg.py)2
15 files changed, 78 insertions, 2350 deletions
diff --git a/source4/scripting/bin/samba3dump b/source4/scripting/bin/samba3dump
index d89667233f..c11f8dbd0d 100755
--- a/source4/scripting/bin/samba3dump
+++ b/source4/scripting/bin/samba3dump
@@ -14,7 +14,7 @@ sys.path.insert(0, "bin/python")
import samba
import samba.samba3
-parser = optparse.OptionParser("provision <libdir> [<smb.conf>]")
+parser = optparse.OptionParser("samba3dump <libdir> [<smb.conf>]")
parser.add_option("--format", type="choice", metavar="FORMAT",
choices=["full", "summary"])
@@ -96,7 +96,7 @@ def print_samba3_secrets(secrets):
def print_samba3_regdb(regdb):
print_header("Registry")
- from registry import str_regtype
+ from samba.registry import str_regtype
for k in regdb.keys():
print "[%s]" % k
diff --git a/source4/scripting/bin/smbstatus b/source4/scripting/bin/smbstatus
index 4dfc3365a1..bbd0e84826 100755
--- a/source4/scripting/bin/smbstatus
+++ b/source4/scripting/bin/smbstatus
@@ -1,96 +1,83 @@
-#!/bin/sh
-exec smbscript "$0" ${1+"$@"}
-/*
- provide information on connected users and open files
- Copyright Andrew Tridgell 2005
- Released under the GNU GPL version 3 or later
-*/
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+#
+# provide information on connected users and open files
+# Copyright ǒ Jelmer Vernooij 2008
+#
+# Based on the original in EJS:
+# Copyright Andrew Tridgell 2005
+# Released under the GNU GPL version 3 or later
+#
-libinclude("base.js");
-libinclude("management.js");
+import os, sys
-var options = new Object();
+sys.path.insert(0, "bin/python")
-options = GetOptions(ARGV,
- "POPT_AUTOHELP",
- "POPT_COMMON_SAMBA",
- "POPT_COMMON_VERSION",
- "nbt");
-if (options == undefined) {
- println("Failed to parse options: " + options.ERROR);
- return -1;
-}
+import optparse
+import samba.getopt as options
+from samba import irpc, messaging
-/*
- show open sessions
-*/
-function show_sessions()
-{
- var sessions = smbsrv_sessions();
- var i;
- var sys = sys_init();
- if (sessions == undefined) {
- println("No sessions open");
- return;
- }
- printf("User Client Connected at\n");
- printf("-------------------------------------------------------------------------------\n");
- for (i=0;i<sessions.length;i++) {
- var info = sessions[i];
- var fulluser = sprintf("%s/%s", info.account_name, info.domain_name);
- printf("%-30s %16s %s\n",
- fulluser, info.client_ip, sys.httptime(info.connect_time));
- }
- printf("\n");
-}
+def show_sessions(conn):
+ """show open sessions"""
-/*
- show open tree connects
-*/
-function show_tcons()
-{
- var tcons = smbsrv_tcons();
- var sys = sys_init();
- if (tcons == undefined) {
- println("No tree connects");
- return;
- }
- printf("Share Client Connected at\n");
- printf("-------------------------------------------------------------------------------\n");
- for (i=0;i<tcons.length;i++) {
- var info = tcons[i];
- printf("%-30s %16s %s\n",
- info.share_name, info.client_ip, sys.httptime(info.connect_time));
- }
-}
+ sessions = conn.smbsrv_information(irpc.SMBSRV_INFO_SESSIONS).next()
+ print "User Client Connected at"
+ print "-------------------------------------------------------------------------------"
+ for session in sessions:
+ fulluser = "%s/%s" % (session.account_name, session.domain_name)
+ print "%-30s %16s %s" % (fulluser, session.client_ip, sys.httptime(session.connect_time))
+ print ""
-/*
- show nbtd information
-*/
-function show_nbt()
-{
- var stats = nbtd_statistics();
- if (stats == undefined) {
- println("nbt server not running");
- return;
- }
- var r;
- println("NBT server statistics:");
- for (r in stats) {
- print("\t" + r + ":\t" + stats[r] + "\n");
- }
- println("");
-}
+def show_tcons(open_connection):
+ """show open tree connects"""
+ conn = open_connection("smb_server")
+ tcons = conn.smbsrv_information(irpc.SMBSRV_INFO_TCONS).next()
+ print "Share Client Connected at"
+ print "-------------------------------------------------------------------------------"
+ for tcon in tcons:
+ print "%-30s %16s %s" % (tcon.share_name, tcon.client_ip, sys.httptime(tcon.connect_time))
-var lp = loadparm_init();
-printf("%s\n\n", lp.get("server string"));
+def show_nbt(open_connection):
+ """show nbtd information"""
+ conn = open_connection("nbt_server")
+ stats = conn.nbtd_information(irpc.NBTD_INFO_STATISTICS).next()
+ print "NBT server statistics:"
+ fields = [("total_received", "Total received"),
+ ("total_sent", "Total sent"),
+ ("query_count", "Query count"),
+ ("register_count", "Register count"),
+ ("release_count", "Release count")]
+ for (field, description) in fields:
+ print "\t%s:\t%s" % (description, getattr(stats, field))
+ print
-if (options['nbt'] != undefined) {
- show_nbt();
-} else {
- show_sessions();
- show_tcons();
-}
+parser = optparse.OptionParser("%s [options]" % sys.argv[0])
+sambaopts = options.SambaOptions(parser)
+parser.add_option_group(sambaopts)
+parser.add_option("--messaging-path", type="string", metavar="PATH",
+ help="messaging path")
+parser.add_option("--nbt", help="show NetBIOS status", action="store_true")
-return 0;
+opts, args = parser.parse_args()
+
+lp = sambaopts.get_loadparm()
+
+print "%s" % lp.get("server string")
+
+messaging_path = (opts.messaging_path or os.path.join(lp.get("private dir"), "smbd.tmp", "messaging"))
+
+def open_connection(name):
+ return messaging.ClientConnection(name, messaging_path=messaging_path)
+
+if opts.nbt:
+ show_nbt(open_connection)
+else:
+ try:
+ conn = open_connection("smb_server")
+ except RuntimeError, (num, msg):
+ if msg == 'NT_STATUS_OBJECT_NAME_NOT_FOUND':
+ print "No active connections"
+ else:
+ show_sessions(conn)
+ show_tcons(conn)
diff --git a/source4/scripting/bin/winreg b/source4/scripting/bin/winreg
deleted file mode 100755
index 883c6d7ee3..0000000000
--- a/source4/scripting/bin/winreg
+++ /dev/null
@@ -1,107 +0,0 @@
-#!/bin/sh
-exec smbscript "$0" ${1+"$@"}
-/*
- tool to manipulate a remote registry
- Copyright Andrew Tridgell 2005
- Released under the GNU GPL version 3 or later
-*/
-
-var options = GetOptions(ARGV,
- "POPT_AUTOHELP",
- "POPT_COMMON_SAMBA",
- "POPT_COMMON_CREDENTIALS",
- "createkey=s");
-if (options == undefined) {
- println("Failed to parse options");
- return -1;
-}
-
-libinclude("base.js");
-libinclude("winreg.js");
-
-if (options.ARGV.length < 1) {
- println("Usage: winreg.js <BINDING> [path]");
- return -1;
-}
-var binding = options.ARGV[0];
-reg = winregObj();
-
-print("Connecting to " + binding + "\n");
-status = reg.connect(binding);
-if (status.is_ok != true) {
- print("Failed to connect to " + binding + " - " + status.errstr + "\n");
- return -1;
-}
-
-function list_values(path) {
- var list = reg.enum_values(path);
- var i;
- if (list == undefined) {
- return;
- }
- for (i=0;i<list.length;i++) {
- var v = list[i];
- printf("\ttype=%-30s size=%4d '%s'\n", reg.typestring(v.type), v.size, v.name);
- if (v.type == reg.REG_SZ || v.type == reg.REG_EXPAND_SZ) {
- printf("\t\t'%s'\n", v.value);
- }
- if (v.type == reg.REG_MULTI_SZ) {
- var j;
- for (j in v.value) {
- printf("\t\t'%s'\n", v.value[j]);
- }
- }
- if (v.type == reg.REG_DWORD || v.type == reg.REG_DWORD_BIG_ENDIAN) {
- printf("\t\t0x%08x (%d)\n", v.value, v.value);
- }
- if (v.type == reg.REG_QWORD) {
- printf("\t\t0x%llx (%lld)\n", v.value, v.value);
- }
- }
-}
-
-function list_path(path) {
- var count = 0;
- var list = reg.enum_path(path);
- if (list == undefined) {
- println("Unable to list " + path);
- return 0;
- }
- var i;
- list_values(path);
- count = count + list.length;
- for (i=0;i<list.length;i++) {
- var npath;
- if (path) {
- npath = path + "\\" + list[i];
- } else {
- npath = list[i];
- }
- println(npath);
- count = count + list_path(npath);
- }
- return count;
-}
-
-var root;
-
-if (options.ARGV.length > 1) {
- root = options.ARGV[1];
-} else {
- root = '';
-}
-
-if (options.createkey) {
- var ok = reg.create_key("HKLM\\SOFTWARE", options.createkey);
- if (!ok) {
- println("Failed to create key");
- }
-} else {
- printf("Listing registry tree '%s'\n", root);
- var count = list_path(root);
- if (count == 0) {
- println("No entries found");
- return 1;
- }
-}
-return 0;
diff --git a/source4/scripting/ejs/config.mk b/source4/scripting/ejs/config.mk
index c1a1ca1f0f..c5199669d5 100644
--- a/source4/scripting/ejs/config.mk
+++ b/source4/scripting/ejs/config.mk
@@ -1,7 +1,3 @@
-[SUBSYSTEM::EJSRPC]
-
-EJSRPC_OBJ_FILES = $(ejsscriptsrcdir)/ejsrpc.o
-
[MODULE::smbcalls_config]
OUTPUT_TYPE = MERGED_OBJ
SUBSYSTEM = smbcalls
@@ -17,14 +13,6 @@ PRIVATE_DEPENDENCIES = LIBLDB SAMDB LIBNDR
smbcalls_ldb_OBJ_FILES = $(ejsscriptsrcdir)/smbcalls_ldb.o
-[MODULE::smbcalls_reg]
-SUBSYSTEM = smbcalls
-OUTPUT_TYPE = MERGED_OBJ
-INIT_FUNCTION = smb_setup_ejs_reg
-PRIVATE_DEPENDENCIES = registry SAMDB LIBNDR
-
-smbcalls_reg_OBJ_FILES = $(ejsscriptsrcdir)/smbcalls_reg.o
-
[MODULE::smbcalls_nbt]
SUBSYSTEM = smbcalls
OUTPUT_TYPE = MERGED_OBJ
@@ -39,14 +27,6 @@ INIT_FUNCTION = smb_setup_ejs_random
smbcalls_rand_OBJ_FILES = $(ejsscriptsrcdir)/smbcalls_rand.o
-[MODULE::smbcalls_nss]
-SUBSYSTEM = smbcalls
-OUTPUT_TYPE = MERGED_OBJ
-INIT_FUNCTION = smb_setup_ejs_nss
-PRIVATE_DEPENDENCIES = NSS_WRAPPER
-
-smbcalls_nss_OBJ_FILES = $(ejsscriptsrcdir)/smbcalls_nss.o
-
[MODULE::smbcalls_data]
SUBSYSTEM = smbcalls
OUTPUT_TYPE = MERGED_OBJ
@@ -83,16 +63,13 @@ mkinclude ejsnet/config.mk
[SUBSYSTEM::smbcalls]
PRIVATE_DEPENDENCIES = \
EJS LIBSAMBA-UTIL \
- EJSRPC MESSAGING \
+ MESSAGING \
LIBSAMBA-NET LIBCLI_SMB LIBPOPT \
CREDENTIALS POPT_CREDENTIALS POPT_SAMBA \
- dcerpc \
NDR_TABLE
smbcalls_OBJ_FILES = $(addprefix $(ejsscriptsrcdir)/, \
smbcalls.o \
- smbcalls_cli.o \
- smbcalls_rpc.o \
smbcalls_options.o \
smbcalls_creds.o \
smbcalls_param.o \
diff --git a/source4/scripting/ejs/ejsrpc.c b/source4/scripting/ejs/ejsrpc.c
deleted file mode 100644
index c7c02dbd64..0000000000
--- a/source4/scripting/ejs/ejsrpc.c
+++ /dev/null
@@ -1,424 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
-
- provide interfaces to rpc calls from ejs scripts
-
- Copyright (C) Andrew Tridgell 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 3 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, see <http://www.gnu.org/licenses/>.
-*/
-
-#include "includes.h"
-#include "lib/appweb/ejs/ejs.h"
-#include "scripting/ejs/smbcalls.h"
-#include "librpc/gen_ndr/lsa.h"
-#include "librpc/gen_ndr/winreg.h"
-#include "scripting/ejs/ejsrpc.h"
-#include "libcli/security/security.h"
-
-/*
- set the switch var to be used by the next union switch
-*/
-void ejs_set_switch(struct ejs_rpc *ejs, uint32_t switch_var)
-{
- ejs->switch_var = switch_var;
-}
-
-/*
- panic in the ejs wrapper code
- */
-NTSTATUS ejs_panic(struct ejs_rpc *ejs, const char *why)
-{
- ejsSetErrorMsg(ejs->eid, "rpc_call '%s' failed - %s", ejs->callname, why);
- return NT_STATUS_INTERNAL_ERROR;
-}
-
-/*
- start the ejs pull process for a structure
-*/
-NTSTATUS ejs_pull_struct_start(struct ejs_rpc *ejs, struct MprVar **v, const char *name)
-{
- return mprGetVar(v, name);
-}
-
-
-/*
- start the ejs push process for a structure
-*/
-NTSTATUS ejs_push_struct_start(struct ejs_rpc *ejs, struct MprVar **v, const char *name)
-{
- EJS_CHECK(mprSetVar(*v, name, mprObject(name)));
- return mprGetVar(v, name);
-}
-
-/*
- pull a uint8 from a mpr variable to a C element
-*/
-NTSTATUS ejs_pull_uint8(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, uint8_t *r)
-{
- EJS_CHECK(mprGetVar(&v, name));
- *r = mprVarToInteger(v);
- return NT_STATUS_OK;
-
-}
-
-NTSTATUS ejs_push_uint8(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, const uint8_t *r)
-{
- return mprSetVar(v, name, mprCreateIntegerVar(*r));
-}
-
-/*
- pull a uint16 from a mpr variable to a C element
-*/
-NTSTATUS ejs_pull_uint16(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, uint16_t *r)
-{
- EJS_CHECK(mprGetVar(&v, name));
- *r = mprVarToInteger(v);
- return NT_STATUS_OK;
-
-}
-
-NTSTATUS ejs_push_uint16(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, const uint16_t *r)
-{
- return mprSetVar(v, name, mprCreateIntegerVar(*r));
-}
-
-/*
- pull a uint32 from a mpr variable to a C element
-*/
-NTSTATUS ejs_pull_uint32(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, uint32_t *r)
-{
- EJS_CHECK(mprGetVar(&v, name));
- *r = mprVarToInteger(v);
- return NT_STATUS_OK;
-}
-
-NTSTATUS ejs_push_uint32(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, const uint32_t *r)
-{
- return mprSetVar(v, name, mprCreateIntegerVar(*r));
-}
-
-/*
- pull a int32 from a mpr variable to a C element
-*/
-NTSTATUS ejs_pull_int32(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, int32_t *r)
-{
- EJS_CHECK(mprGetVar(&v, name));
- *r = mprVarToInteger(v);
- return NT_STATUS_OK;
-}
-
-NTSTATUS ejs_push_int32(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, const int32_t *r)
-{
- return mprSetVar(v, name, mprCreateIntegerVar(*r));
-}
-
-/*
- pull a uint32 from a mpr variable to a C element
-*/
-NTSTATUS ejs_pull_time_t(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, time_t *r)
-{
- EJS_CHECK(mprGetVar(&v, name));
- *r = mprVarToInteger(v);
- return NT_STATUS_OK;
-}
-
-NTSTATUS ejs_push_time_t(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, const time_t *r)
-{
- return mprSetVar(v, name, mprCreateIntegerVar(*r));
-}
-
-NTSTATUS ejs_pull_hyper(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, uint64_t *r)
-{
- EJS_CHECK(mprGetVar(&v, name));
- *r = mprVarToNumber(v);
- return NT_STATUS_OK;
-}
-
-NTSTATUS ejs_push_hyper(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, const uint64_t *r)
-{
- return mprSetVar(v, name, mprCreateNumberVar(*r));
-}
-
-NTSTATUS ejs_pull_dlong(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, int64_t *r)
-{
- return ejs_pull_hyper(ejs, v, name, (uint64_t *)r);
-}
-
-NTSTATUS ejs_push_dlong(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, const int64_t *r)
-{
- return ejs_push_hyper(ejs, v, name, (const uint64_t *)r);
-}
-
-NTSTATUS ejs_pull_udlong(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, uint64_t *r)
-{
- return ejs_pull_hyper(ejs, v, name, r);
-}
-
-NTSTATUS ejs_push_udlong(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, const uint64_t *r)
-{
- return ejs_push_hyper(ejs, v, name, r);
-}
-
-NTSTATUS ejs_pull_NTTIME(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, uint64_t *r)
-{
- return ejs_pull_hyper(ejs, v, name, r);
-}
-
-NTSTATUS ejs_push_NTTIME(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, const uint64_t *r)
-{
- return ejs_push_hyper(ejs, v, name, r);
-}
-
-NTSTATUS ejs_push_WERROR(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, const WERROR *r)
-{
- return ejs_push_string(ejs, v, name, win_errstr(*r));
-}
-
-NTSTATUS ejs_push_NTSTATUS(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, const NTSTATUS *r)
-{
- return ejs_push_string(ejs, v, name, nt_errstr(*r));
-}
-
-
-/*
- pull a enum from a mpr variable to a C element
- a enum is just treating as an unsigned integer at this level
-*/
-NTSTATUS ejs_pull_enum(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, unsigned *r)
-{
- EJS_CHECK(mprGetVar(&v, name));
- *r = mprVarToInteger(v);
- return NT_STATUS_OK;
-
-}
-
-NTSTATUS ejs_push_enum(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, const unsigned *r)
-{
- return mprSetVar(v, name, mprCreateIntegerVar(*r));
-}
-
-
-/*
- pull a string
-*/
-NTSTATUS ejs_pull_string(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, const char **s)
-{
- EJS_CHECK(mprGetVar(&v, name));
- *s = mprToString(v);
- return NT_STATUS_OK;
-}
-
-/*
- push a string
-*/
-NTSTATUS ejs_push_string(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, const char *s)
-{
- return mprSetVar(v, name, mprString(s));
-}
-
-
-/*
- pull a ipv4address (internally a string)
-*/
-NTSTATUS ejs_pull_ipv4address(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, const char **s)
-{
- return ejs_pull_string(ejs, v, name, s);
-}
-
-/*
- push a ipv4address (internally a string)
-*/
-NTSTATUS ejs_push_ipv4address(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, const char *s)
-{
- return ejs_push_string(ejs, v, name, s);
-}
-
-
-NTSTATUS ejs_pull_dom_sid(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, struct dom_sid *r)
-{
- struct dom_sid *sid;
- EJS_CHECK(mprGetVar(&v, name));
- sid = dom_sid_parse_talloc(ejs, mprToString(v));
- NT_STATUS_HAVE_NO_MEMORY(sid);
- *r = *sid;
- return NT_STATUS_OK;
-}
-
-NTSTATUS ejs_push_dom_sid(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, const struct dom_sid *r)
-{
- char *sidstr = dom_sid_string(ejs, r);
- NT_STATUS_HAVE_NO_MEMORY(sidstr);
- return mprSetVar(v, name, mprString(sidstr));
-}
-
-NTSTATUS ejs_pull_GUID(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, struct GUID *r)
-{
- EJS_CHECK(mprGetVar(&v, name));
- return GUID_from_string(mprToString(v), r);
-}
-
-NTSTATUS ejs_push_GUID(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, const struct GUID *r)
-{
- char *guid = GUID_string(ejs, r);
- NT_STATUS_HAVE_NO_MEMORY(guid);
- return mprSetVar(v, name, mprString(guid));
-}
-
-NTSTATUS ejs_push_null(struct ejs_rpc *ejs, struct MprVar *v, const char *name)
-{
- return mprSetVar(v, name, mprCreatePtrVar(NULL));
-}
-
-bool ejs_pull_null(struct ejs_rpc *ejs, struct MprVar *v, const char *name)
-{
- NTSTATUS status = mprGetVar(&v, name);
- if (!NT_STATUS_IS_OK(status)) {
- return false;
- }
- if (v->type == MPR_TYPE_PTR && v->ptr == NULL) {
- return true;
- }
- return false;
-}
-
-/*
- pull a lsa_String
-*/
-NTSTATUS ejs_pull_lsa_String(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, struct lsa_String *r)
-{
- return ejs_pull_string(ejs, v, name, &r->string);
-}
-
-/*
- push a lsa_String
-*/
-NTSTATUS ejs_push_lsa_String(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, const struct lsa_String *r)
-{
- return ejs_push_string(ejs, v, name, r->string);
-}
-
-/*
- pull a winreg_String
-*/
-NTSTATUS ejs_pull_winreg_String(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, struct winreg_String *r)
-{
- return ejs_pull_string(ejs, v, name, &r->name);
-}
-
-/*
- push a winreg_String
-*/
-NTSTATUS ejs_push_winreg_String(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, const struct winreg_String *r)
-{
- return ejs_push_string(ejs, v, name, r->name);
-}
-
-NTSTATUS ejs_pull_DATA_BLOB(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, DATA_BLOB *r)
-{
- return NT_STATUS_NOT_IMPLEMENTED;
-}
-
-NTSTATUS ejs_push_DATA_BLOB(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name,
- const DATA_BLOB *r)
-{
- return NT_STATUS_NOT_IMPLEMENTED;
-}
-
-NTSTATUS ejs_pull_bool(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, bool *r)
-{
- EJS_CHECK(mprGetVar(&v, name));
- *r = mprVarToBool(v);
- return NT_STATUS_OK;
-}
-
-NTSTATUS ejs_push_bool(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, const bool *r)
-{
- return mprSetVar(v, name, mprCreateBoolVar(*r));
-}
-
-
-/*
- pull a uint8 array from a mpr variable to a C element - treating as a data blob
-*/
-NTSTATUS ejs_pull_array_uint8(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name,
- uint8_t *r, uint32_t length)
-{
- NTSTATUS status;
- DATA_BLOB *blob;
-
- status = mprGetVar(&v, name);
- NT_STATUS_NOT_OK_RETURN(status);
-
- blob = mprToDataBlob(v);
- if (blob == NULL) {
- return NT_STATUS_OBJECT_NAME_INVALID;
- }
- if (blob->length != length) {
- return NT_STATUS_INFO_LENGTH_MISMATCH;
- }
- memcpy(r, blob->data, length);
- return NT_STATUS_OK;
-
-}
-
-NTSTATUS ejs_push_array_uint8(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name,
- const uint8_t *r, uint32_t length)
-{
- DATA_BLOB blob;
- blob.data = (uint8_t *)discard_const(r);
- blob.length = length;
- mprSetVar(v, name, mprDataBlob(blob));
- return NT_STATUS_OK;
-}
diff --git a/source4/scripting/ejs/ejsrpc.h b/source4/scripting/ejs/ejsrpc.h
deleted file mode 100644
index cc22a26700..0000000000
--- a/source4/scripting/ejs/ejsrpc.h
+++ /dev/null
@@ -1,172 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
-
- ejs <-> rpc interface definitions
-
- Copyright (C) Andrew Tridgell 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 3 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, see <http://www.gnu.org/licenses/>.
-*/
-
-#include "librpc/gen_ndr/security.h"
-#include "librpc/rpc/dcerpc.h"
-
-struct ejs_rpc {
- int eid;
- const char *callname;
- /* as ejs does only one pass, we can use a single var for switch
- handling */
- uint32_t switch_var;
-};
-
-typedef NTSTATUS (*ejs_pull_t)(struct ejs_rpc *, struct MprVar *, const char *, void *);
-typedef NTSTATUS (*ejs_push_t)(struct ejs_rpc *, struct MprVar *, const char *, const void *);
-typedef NTSTATUS (*ejs_pull_function_t)(struct ejs_rpc *, struct MprVar *, void *);
-typedef NTSTATUS (*ejs_push_function_t)(struct ejs_rpc *, struct MprVar *, const void *);
-
-NTSTATUS ejs_panic(struct ejs_rpc *ejs, const char *why);
-void ejs_set_switch(struct ejs_rpc *ejs, uint32_t switch_var);
-
-NTSTATUS smbcalls_register_ejs(const char *name, MprCFunction fn);
-
-
-int ejs_rpc_call(int eid, int argc, struct MprVar **argv,
- const struct ndr_interface_table *iface, int callnum,
- ejs_pull_function_t ejs_pull, ejs_push_function_t ejs_push);
-
-NTSTATUS ejs_pull_struct_start(struct ejs_rpc *ejs, struct MprVar **v, const char *name);
-NTSTATUS ejs_push_struct_start(struct ejs_rpc *ejs, struct MprVar **v, const char *name);
-
-NTSTATUS ejs_pull_uint8(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, uint8_t *r);
-NTSTATUS ejs_push_uint8(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, const uint8_t *r);
-NTSTATUS ejs_pull_uint16(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, uint16_t *r);
-NTSTATUS ejs_push_uint16(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, const uint16_t *r);
-NTSTATUS ejs_pull_uint32(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, uint32_t *r);
-NTSTATUS ejs_push_int32(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, const int32_t *r);
-NTSTATUS ejs_pull_int32(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, int32_t *r);
-NTSTATUS ejs_push_uint32(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, const uint32_t *r);
-NTSTATUS ejs_pull_hyper(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, uint64_t *r);
-NTSTATUS ejs_push_hyper(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, const uint64_t *r);
-NTSTATUS ejs_pull_dlong(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, int64_t *r);
-NTSTATUS ejs_push_dlong(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, const int64_t *r);
-NTSTATUS ejs_pull_udlong(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, uint64_t *r);
-NTSTATUS ejs_push_udlong(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, const uint64_t *r);
-NTSTATUS ejs_pull_NTTIME(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, uint64_t *r);
-NTSTATUS ejs_push_NTTIME(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, const uint64_t *r);
-NTSTATUS ejs_pull_time_t(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, time_t *r);
-NTSTATUS ejs_push_time_t(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, const time_t *r);
-NTSTATUS ejs_pull_enum(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, unsigned *r);
-NTSTATUS ejs_push_enum(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, const unsigned *r);
-NTSTATUS ejs_pull_string(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, const char **s);
-NTSTATUS ejs_push_string(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, const char *s);
-NTSTATUS ejs_pull_ipv4address(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, const char **s);
-NTSTATUS ejs_push_ipv4address(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, const char *s);
-void ejs_set_constant_int(int eid, const char *name, int value);
-void ejs_set_constant_string(int eid, const char *name, const char *value);
-
-NTSTATUS ejs_pull_dom_sid(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, struct dom_sid *r);
-NTSTATUS ejs_push_dom_sid(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, const struct dom_sid *r);
-NTSTATUS ejs_push_null(struct ejs_rpc *ejs, struct MprVar *v, const char *name);
-bool ejs_pull_null(struct ejs_rpc *ejs, struct MprVar *v, const char *name);
-NTSTATUS ejs_push_WERROR(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, const WERROR *r);
-NTSTATUS ejs_push_NTSTATUS(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, const NTSTATUS *r);
-NTSTATUS ejs_pull_DATA_BLOB(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, DATA_BLOB *r);
-NTSTATUS ejs_push_DATA_BLOB(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, const DATA_BLOB *r);
-NTSTATUS ejs_pull_bool(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, bool *r);
-NTSTATUS ejs_push_bool(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, const bool *r);
-
-NTSTATUS ejs_pull_array_uint8(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name,
- uint8_t *r, uint32_t length);
-NTSTATUS ejs_push_array_uint8(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name,
- const uint8_t *r, uint32_t length);
-
-NTSTATUS ejs_pull_GUID(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, struct GUID *r);
-NTSTATUS ejs_push_GUID(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, const struct GUID *r);
-
-struct lsa_String;
-NTSTATUS ejs_pull_lsa_String(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, struct lsa_String *r);
-NTSTATUS ejs_push_lsa_String(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, const struct lsa_String *r);
-
-struct winreg_String;
-NTSTATUS ejs_pull_winreg_String(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, struct winreg_String *r);
-NTSTATUS ejs_push_winreg_String(struct ejs_rpc *ejs,
- struct MprVar *v, const char *name, const struct winreg_String *r);
-
-#define EJS_ALLOC(ejs, s) do { \
- (s) = talloc_ptrtype(ejs, (s)); \
- if (!(s)) return ejs_panic(ejs, "out of memory"); \
-} while (0)
-
-#define EJS_ALLOC_N(ejs, s, n) do { \
- (s) = talloc_array_ptrtype(ejs, (s), n); \
- if (!(s)) return ejs_panic(ejs, "out of memory"); \
-} while (0)
-
-#define EJS_CHECK(cmd) do { \
- NTSTATUS _status; \
- _status = cmd; \
- if (!NT_STATUS_IS_OK(_status)) { \
- return _status; \
- } \
-} while (0)
-
-/* some types are equivalent for ejs */
-#define ejs_pull_dom_sid2 ejs_pull_dom_sid
-#define ejs_push_dom_sid2 ejs_push_dom_sid
-#define ejs_pull_dom_sid28 ejs_pull_dom_sid
-#define ejs_push_dom_sid28 ejs_push_dom_sid
-#define ejs_pull_NTTIME_hyper ejs_pull_NTTIME
-#define ejs_push_NTTIME_hyper ejs_push_NTTIME
-#define ejs_pull_NTTIME_1sec ejs_pull_NTTIME
-#define ejs_push_NTTIME_1sec ejs_push_NTTIME
-
diff --git a/source4/scripting/ejs/smbcalls.c b/source4/scripting/ejs/smbcalls.c
index 98d6be07bf..bdf70ca831 100644
--- a/source4/scripting/ejs/smbcalls.c
+++ b/source4/scripting/ejs/smbcalls.c
@@ -203,7 +203,6 @@ void smb_setup_ejs_functions(void (*exception_handler)(const char *))
ejs_exception_handler = exception_handler;
- smb_setup_ejs_cli();
smb_setup_ejs_options();
smb_setup_ejs_credentials();
smb_setup_ejs_param();
diff --git a/source4/scripting/ejs/smbcalls_cli.c b/source4/scripting/ejs/smbcalls_cli.c
deleted file mode 100644
index dbb36312da..0000000000
--- a/source4/scripting/ejs/smbcalls_cli.c
+++ /dev/null
@@ -1,722 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
-
- provide hooks into smbd C calls from ejs scripts
-
- Copyright (C) Tim Potter 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 3 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, see <http://www.gnu.org/licenses/>.
-*/
-
-#include "includes.h"
-#include "scripting/ejs/smbcalls.h"
-#include "lib/appweb/ejs/ejs.h"
-#include "libcli/raw/libcliraw.h"
-#include "libcli/composite/composite.h"
-#include "libcli/smb_composite/smb_composite.h"
-#include "libcli/libcli.h"
-#include "libcli/resolve/resolve.h"
-#include "auth/credentials/credentials.h"
-#include "param/param.h"
-
-#if 0
-
-#include "librpc/gen_ndr/ndr_nbt.h"
-
-/* Connect to a server */
-
-static int ejs_cli_connect(MprVarHandle eid, int argc, char **argv)
-{
- struct smbcli_socket *sock;
- struct smbcli_transport *transport;
- struct nbt_name calling, called;
- NTSTATUS result;
-
- if (argc != 1) {
- ejsSetErrorMsg(eid, "connect invalid arguments");
- return -1;
- }
-
- /* Socket connect */
-
- sock = smbcli_sock_init(NULL, NULL);
-
- if (!sock) {
- ejsSetErrorMsg(eid, "socket initialisation failed");
- return -1;
- }
-
- if (!smbcli_sock_connect_byname(sock, argv[0], 0)) {
- ejsSetErrorMsg(eid, "socket connect failed");
- return -1;
- }
-
- transport = smbcli_transport_init(sock, sock, false);
-
- if (!transport) {
- ejsSetErrorMsg(eid, "transport init failed");
- return -1;
- }
-
- /* Send a netbios session request */
-
- make_nbt_name_client(&calling, lp_netbios_name());
-
- nbt_choose_called_name(NULL, &called, argv[0], NBT_NAME_SERVER);
-
- if (!smbcli_transport_connect(transport, &calling, &called)) {
- ejsSetErrorMsg(eid, "transport establishment failed");
- return -1;
- }
-
- result = smb_raw_negotiate(transport, lp_maxprotocol());
-
- if (!NT_STATUS_IS_OK(result)) {
- mpr_Return(eid, mprNTSTATUS(result));
- return 0;
- }
-
- /* Return a socket object */
-
- mpr_Return(eid, mprCreatePtrVar(transport));
-
- return 0;
-}
-
-/* Perform a session setup:
-
- session_setup(conn, "DOMAIN\\USERNAME%PASSWORD");
- session_setup(conn, USERNAME, PASSWORD);
- session_setup(conn, DOMAIN, USERNAME, PASSWORD);
- session_setup(conn); // anonymous
-
- */
-
-static int ejs_cli_ssetup(MprVarHandle eid, int argc, MprVar **argv)
-{
- struct smbcli_transport *transport;
- struct smbcli_session *session;
- struct smb_composite_sesssetup setup;
- struct cli_credentials *creds;
- NTSTATUS status;
- int result = -1;
-
- /* Argument parsing */
-
- if (argc < 1 || argc > 4) {
- ejsSetErrorMsg(eid, "session_setup invalid arguments");
- return -1;
- }
-
- if (!mprVarIsPtr(argv[0]->type)) {
- ejsSetErrorMsg(eid, "first arg is not a connect handle");
- return -1;
- }
-
- transport = argv[0]->ptr;
- creds = cli_credentials_init(transport);
- cli_credentials_set_conf(creds);
-
- if (argc == 4) {
-
- /* DOMAIN, USERNAME, PASSWORD form */
-
- if (!mprVarIsString(argv[1]->type)) {
- ejsSetErrorMsg(eid, "arg 1 must be a string");
- goto done;
- }
-
- cli_credentials_set_domain(creds, argv[1]->string,
- CRED_SPECIFIED);
-
- if (!mprVarIsString(argv[2]->type)) {
- ejsSetErrorMsg(eid, "arg 2 must be a string");
- goto done;
- }
-
- cli_credentials_set_username(creds, argv[2]->string,
- CRED_SPECIFIED);
-
- if (!mprVarIsString(argv[3]->type)) {
- ejsSetErrorMsg(eid, "arg 3 must be a string");
- goto done;
- }
-
- cli_credentials_set_password(creds, argv[3]->string,
- CRED_SPECIFIED);
-
- } else if (argc == 3) {
-
- /* USERNAME, PASSWORD form */
-
- if (!mprVarIsString(argv[1]->type)) {
- ejsSetErrorMsg(eid, "arg1 must be a string");
- goto done;
- }
-
- cli_credentials_set_username(creds, argv[1]->string,
- CRED_SPECIFIED);
-
- if (!mprVarIsString(argv[2]->type)) {
-
- ejsSetErrorMsg(eid, "arg2 must be a string");
- goto done;
- }
-
- cli_credentials_set_password(creds, argv[2]->string,
- CRED_SPECIFIED);
-
- } else if (argc == 2) {
-
- /* DOMAIN/USERNAME%PASSWORD form */
-
- cli_credentials_parse_string(creds, argv[1]->string,
- CRED_SPECIFIED);
-
- } else {
-
- /* Anonymous connection */
-
- cli_credentials_set_anonymous(creds);
- }
-
- /* Do session setup */
-
- session = smbcli_session_init(transport, transport, false);
-
- if (!session) {
- ejsSetErrorMsg(eid, "session init failed");
- return -1;
- }
-
- setup.in.sesskey = transport->negotiate.sesskey;
- setup.in.capabilities = transport->negotiate.capabilities;
- setup.in.credentials = creds;
- setup.in.workgroup = lp_workgroup();
-
- status = smb_composite_sesssetup(session, &setup);
-
- if (!NT_STATUS_IS_OK(status)) {
- ejsSetErrorMsg(eid, "session_setup: %s", nt_errstr(status));
- return -1;
- }
-
- session->vuid = setup.out.vuid;
-
- /* Return a session object */
-
- mpr_Return(eid, mprCreatePtrVar(session));
-
- result = 0;
-
- done:
- talloc_free(creds);
- return result;
-}
-
-/* Perform a tree connect
-
- tree_connect(session, SHARE);
-
- */
-
-static int ejs_cli_tree_connect(MprVarHandle eid, int argc, MprVar **argv)
-{
- struct smbcli_session *session;
- struct smbcli_tree *tree;
- union smb_tcon tcon;
- TALLOC_CTX *mem_ctx;
- NTSTATUS status;
- const char *password = "";
-
- /* Argument parsing */
-
- if (argc != 2) {
- ejsSetErrorMsg(eid, "tree_connect invalid arguments");
- return -1;
- }
-
- if (!mprVarIsPtr(argv[0]->type)) {
- ejsSetErrorMsg(eid, "first arg is not a session handle");
- return -1;
- }
-
- session = argv[0]->ptr;
- tree = smbcli_tree_init(session, session, false);
-
- if (!tree) {
- ejsSetErrorMsg(eid, "tree init failed");
- return -1;
- }
-
- mem_ctx = talloc_init("tcon");
- if (!mem_ctx) {
- ejsSetErrorMsg(eid, "talloc_init failed");
- return -1;
- }
-
- /* Do tree connect */
-
- tcon.generic.level = RAW_TCON_TCONX;
- tcon.tconx.in.flags = 0;
-
- if (session->transport->negotiate.sec_mode & NEGOTIATE_SECURITY_USER_LEVEL) {
- tcon.tconx.in.password = data_blob(NULL, 0);
- } else if (session->transport->negotiate.sec_mode & NEGOTIATE_SECURITY_CHALLENGE_RESPONSE) {
- tcon.tconx.in.password = data_blob_talloc(mem_ctx, NULL, 24);
- if (session->transport->negotiate.secblob.length < 8) {
- ejsSetErrorMsg(eid, "invalid security blob");
- return -1;
- }
- SMBencrypt(password, session->transport->negotiate.secblob.data, tcon.tconx.in.password.data);
- } else {
- tcon.tconx.in.password = data_blob_talloc(mem_ctx, password, strlen(password)+1);
- }
-
- tcon.tconx.in.path = argv[1]->string;
- tcon.tconx.in.device = "?????";
-
- status = smb_tree_connect(tree, mem_ctx, &tcon);
-
- if (!NT_STATUS_IS_OK(status)) {
- ejsSetErrorMsg(eid, "tree_connect: %s", nt_errstr(status));
- return -1;
- }
-
- tree->tid = tcon.tconx.out.tid;
-
- talloc_free(mem_ctx);
-
- mpr_Return(eid, mprCreatePtrVar(tree));
-
- return 0;
-}
-
-/* Perform a tree disconnect
-
- tree_disconnect(tree);
-
- */
-static int ejs_cli_tree_disconnect(MprVarHandle eid, int argc, MprVar **argv)
-{
- struct smbcli_tree *tree;
- NTSTATUS status;
-
- /* Argument parsing */
-
- if (argc != 1) {
- ejsSetErrorMsg(eid, "tree_disconnect invalid arguments");
- return -1;
- }
-
- if (!mprVarIsPtr(argv[0]->type)) {
- ejsSetErrorMsg(eid, "first arg is not a tree handle");
- return -1;
- }
-
- tree = argv[0]->ptr;
-
- status = smb_tree_disconnect(tree);
-
- if (!NT_STATUS_IS_OK(status)) {
- ejsSetErrorMsg(eid, "tree_disconnect: %s", nt_errstr(status));
- return -1;
- }
-
- talloc_free(tree);
-
- return 0;
-}
-
-/* Perform a ulogoff
-
- session_logoff(session);
-
- */
-static int ejs_cli_session_logoff(MprVarHandle eid, int argc, MprVar **argv)
-{
- struct smbcli_session *session;
- NTSTATUS status;
-
- /* Argument parsing */
-
- if (argc != 1) {
- ejsSetErrorMsg(eid, "session_logoff invalid arguments");
- return -1;
- }
-
- if (!mprVarIsPtr(argv[0]->type)) {
- ejsSetErrorMsg(eid, "first arg is not a session handle");
- return -1;
- }
-
- session = argv[0]->ptr;
-
- status = smb_raw_ulogoff(session);
-
- if (!NT_STATUS_IS_OK(status)) {
- ejsSetErrorMsg(eid, "session_logoff: %s", nt_errstr(status));
- return -1;
- }
-
- talloc_free(session);
-
- return 0;
-}
-
-/* Perform a connection close
-
- disconnect(conn);
-
- */
-static int ejs_cli_disconnect(MprVarHandle eid, int argc, MprVar **argv)
-{
- struct smbcli_sock *sock;
-
- /* Argument parsing */
-
- if (argc != 1) {
- ejsSetErrorMsg(eid, "disconnect invalid arguments");
- return -1;
- }
-
- if (!mprVarIsPtr(argv[0]->type)) {
- ejsSetErrorMsg(eid, "first arg is not a connect handle");
- return -1;
- }
-
- sock = argv[0]->ptr;
-
- talloc_free(sock);
-
- return 0;
-}
-
-#endif
-
-/* Perform a tree connect:
-
- tree_handle = tree_connect("\\\\frogurt\\homes", "user%pass");
- */
-
-static int ejs_tree_connect(MprVarHandle eid, int argc, char **argv)
-{
- struct cli_credentials *creds;
- struct smb_composite_connect io;
- struct smbcli_tree *tree;
- char *hostname, *sharename;
- NTSTATUS result;
- TALLOC_CTX *mem_ctx;
-
- if (argc != 2) {
- ejsSetErrorMsg(eid, "tree_connect(): invalid number of args");
- return -1;
- }
-
- /* Set up host, share destination */
-
- mem_ctx = talloc_new(mprMemCtx());
- smbcli_parse_unc(argv[0], mem_ctx, &hostname, &sharename);
-
- /* Set up credentials */
-
- creds = cli_credentials_init(NULL);
- cli_credentials_set_conf(creds, mprLpCtx());
- cli_credentials_parse_string(creds, argv[1], CRED_SPECIFIED);
-
- /* Do connect */
-
- io.in.dest_host = hostname;
- io.in.dest_ports = lp_smb_ports(mprLpCtx());
- io.in.called_name = strupper_talloc(mem_ctx, hostname);
- io.in.service = sharename;
- io.in.service_type = "?????";
- io.in.credentials = creds;
- io.in.fallback_to_anonymous = false;
- io.in.workgroup = lp_workgroup(mprLpCtx());
- lp_smbcli_options(mprLpCtx(), &io.in.options);
-
- result = smb_composite_connect(&io, mem_ctx,
- lp_resolve_context(mprLpCtx()),
- NULL);
- tree = io.out.tree;
-
- talloc_free(mem_ctx);
-
- if (!NT_STATUS_IS_OK(result)) {
- mpr_Return(eid, mprNTSTATUS(result));
- return 0;
- }
-
- mpr_Return(eid, mprCreatePtrVar(tree));
-
- return 0;
-}
-
-#define IS_TREE_HANDLE(x) (mprVarIsPtr((x)->type) && \
- talloc_check_name((x)->ptr, "struct smbcli_tree"))
-
-/* Perform a tree disconnect:
-
- tree_disconnect(tree_handle);
- */
-
-static int ejs_tree_disconnect(MprVarHandle eid, int argc, MprVar **argv)
-{
- struct smbcli_tree *tree;
- NTSTATUS result;
-
- if (argc != 1) {
- ejsSetErrorMsg(eid,
- "tree_disconnect(): invalid number of args");
- return -1;
- }
-
- if (!IS_TREE_HANDLE(argv[0])) {
- ejsSetErrorMsg(eid, "first arg is not a tree handle");
- return -1;
- }
-
- tree = talloc_get_type(argv[0]->ptr, struct smbcli_tree);
-
- result = smb_tree_disconnect(tree);
-
- mpr_Return(eid, mprNTSTATUS(result));
-
- return 0;
-}
-
-/* Create a directory:
-
- result = mkdir(tree_handle, DIRNAME);
- */
-
-static int ejs_mkdir(MprVarHandle eid, int argc, MprVar **argv)
-{
- struct smbcli_tree *tree;
- NTSTATUS result;
-
- if (argc != 2) {
- ejsSetErrorMsg(eid, "mkdir(): invalid number of args");
- return -1;
- }
-
- if (!IS_TREE_HANDLE(argv[0])) {
- ejsSetErrorMsg(eid, "first arg is not a tree handle");
- return -1;
- }
-
- tree = (struct smbcli_tree *)argv[0]->ptr;
-
- if (!mprVarIsString(argv[1]->type)) {
- ejsSetErrorMsg(eid, "arg 2 must be a string");
- return -1;
- }
-
- result = smbcli_mkdir(tree, argv[1]->string);
-
- mpr_Return(eid, mprNTSTATUS(result));
-
- return 0;
-}
-
-/* Remove a directory:
-
- result = rmdir(tree_handle, DIRNAME);
- */
-
-static int ejs_rmdir(MprVarHandle eid, int argc, MprVar **argv)
-{
- struct smbcli_tree *tree;
- NTSTATUS result;
-
- if (argc != 2) {
- ejsSetErrorMsg(eid, "rmdir(): invalid number of args");
- return -1;
- }
-
- if (!IS_TREE_HANDLE(argv[0])) {
- ejsSetErrorMsg(eid, "first arg is not a tree handle");
- return -1;
- }
-
- tree = (struct smbcli_tree *)argv[0]->ptr;
-
- if (!mprVarIsString(argv[1]->type)) {
- ejsSetErrorMsg(eid, "arg 2 must be a string");
- return -1;
- }
-
- result = smbcli_rmdir(tree, argv[1]->string);
-
- mpr_Return(eid, mprNTSTATUS(result));
-
- return 0;
-}
-
-/* Rename a file or directory:
-
- result = rename(tree_handle, SRCFILE, DESTFILE);
- */
-
-static int ejs_rename(MprVarHandle eid, int argc, MprVar **argv)
-{
- struct smbcli_tree *tree;
- NTSTATUS result;
-
- if (argc != 3) {
- ejsSetErrorMsg(eid, "rename(): invalid number of args");
- return -1;
- }
-
- if (!IS_TREE_HANDLE(argv[0])) {
- ejsSetErrorMsg(eid, "first arg is not a tree handle");
- return -1;
- }
-
- tree = (struct smbcli_tree *)argv[0]->ptr;
-
- if (!mprVarIsString(argv[1]->type)) {
- ejsSetErrorMsg(eid, "arg 2 must be a string");
- return -1;
- }
-
- if (!mprVarIsString(argv[2]->type)) {
- ejsSetErrorMsg(eid, "arg 3 must be a string");
- return -1;
- }
-
- result = smbcli_rename(tree, argv[1]->string, argv[2]->string);
-
- mpr_Return(eid, mprNTSTATUS(result));
-
- return 0;
-}
-
-/* Unlink a file or directory:
-
- result = unlink(tree_handle, FILENAME);
- */
-
-static int ejs_unlink(MprVarHandle eid, int argc, MprVar **argv)
-{
- struct smbcli_tree *tree;
- NTSTATUS result;
-
- if (argc != 2) {
- ejsSetErrorMsg(eid, "unlink(): invalid number of args");
- return -1;
- }
-
- if (!IS_TREE_HANDLE(argv[0])) {
- ejsSetErrorMsg(eid, "first arg is not a tree handle");
- return -1;
- }
-
- tree = (struct smbcli_tree *)argv[0]->ptr;
-
- if (!mprVarIsString(argv[1]->type)) {
- ejsSetErrorMsg(eid, "arg 2 must be a string");
- return -1;
- }
-
- result = smbcli_unlink(tree, argv[1]->string);
-
- mpr_Return(eid, mprNTSTATUS(result));
-
- return 0;
-}
-
-/* List directory contents
-
- result = list(tree_handle, ARG1, ...);
- */
-
-static void ejs_list_helper(struct clilist_file_info *info, const char *mask,
- void *state)
-
-{
- MprVar *result = (MprVar *)state;
- char idx[16];
-
- mprItoa(result->properties->numDataItems, idx, sizeof(idx));
- mprSetVar(result, idx, mprString(info->name));
-}
-
-static int ejs_list(MprVarHandle eid, int argc, MprVar **argv)
-{
- struct smbcli_tree *tree;
- char *mask;
- uint16_t attribute;
- MprVar result;
-
- if (argc != 3) {
- ejsSetErrorMsg(eid, "list(): invalid number of args");
- return -1;
- }
-
- if (!IS_TREE_HANDLE(argv[0])) {
- ejsSetErrorMsg(eid, "first arg is not a tree handle");
- return -1;
- }
-
- tree = (struct smbcli_tree *)argv[0]->ptr;
-
- if (!mprVarIsString(argv[1]->type)) {
- ejsSetErrorMsg(eid, "arg 2 must be a string");
- return -1;
- }
-
- mask = argv[1]->string;
-
- if (!mprVarIsNumber(argv[2]->type)) {
- ejsSetErrorMsg(eid, "arg 3 must be a number");
- return -1;
- }
-
- attribute = mprVarToInteger(argv[2]);
-
- result = mprObject("list");
-
- smbcli_list(tree, mask, attribute, ejs_list_helper, &result);
-
- mpr_Return(eid, result);
-
- return 0;
-}
-
-/*
- setup C functions that be called from ejs
-*/
-void smb_setup_ejs_cli(void)
-{
- ejsDefineStringCFunction(-1, "tree_connect", ejs_tree_connect, NULL, MPR_VAR_SCRIPT_HANDLE);
- ejsDefineCFunction(-1, "tree_disconnect", ejs_tree_disconnect, NULL, MPR_VAR_SCRIPT_HANDLE);
-
- ejsDefineCFunction(-1, "mkdir", ejs_mkdir, NULL, MPR_VAR_SCRIPT_HANDLE);
- ejsDefineCFunction(-1, "rmdir", ejs_rmdir, NULL, MPR_VAR_SCRIPT_HANDLE);
- ejsDefineCFunction(-1, "rename", ejs_rename, NULL, MPR_VAR_SCRIPT_HANDLE);
- ejsDefineCFunction(-1, "unlink", ejs_unlink, NULL, MPR_VAR_SCRIPT_HANDLE);
- ejsDefineCFunction(-1, "list", ejs_list, NULL, MPR_VAR_SCRIPT_HANDLE);
-
-
-#if 0
- ejsDefineStringCFunction(-1, "connect", ejs_cli_connect, NULL, MPR_VAR_SCRIPT_HANDLE);
- ejsDefineCFunction(-1, "session_setup", ejs_cli_ssetup, NULL, MPR_VAR_SCRIPT_HANDLE);
- ejsDefineCFunction(-1, "tree_connect", ejs_cli_tree_connect, NULL, MPR_VAR_SCRIPT_HANDLE);
- ejsDefineCFunction(-1, "tree_disconnect", ejs_cli_tree_disconnect, NULL, MPR_VAR_SCRIPT_HANDLE);
- ejsDefineCFunction(-1, "session_logoff", ejs_cli_session_logoff, NULL, MPR_VAR_SCRIPT_HANDLE);
- ejsDefineCFunction(-1, "disconnect", ejs_cli_disconnect, NULL, MPR_VAR_SCRIPT_HANDLE);
-#endif
-}
diff --git a/source4/scripting/ejs/smbcalls_nss.c b/source4/scripting/ejs/smbcalls_nss.c
deleted file mode 100644
index 58f86d3b6c..0000000000
--- a/source4/scripting/ejs/smbcalls_nss.c
+++ /dev/null
@@ -1,160 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
-
- provide access to getpwnam() and related calls
-
- Copyright (C) Andrew Tridgell 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 3 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, see <http://www.gnu.org/licenses/>.
-*/
-
-#include "includes.h"
-#include "scripting/ejs/smbcalls.h"
-#include "lib/appweb/ejs/ejs.h"
-#include "system/passwd.h"
-
-
-/*
- return a struct passwd as an object
-*/
-static struct MprVar mpr_passwd(struct passwd *pwd)
-{
- struct MprVar ret;
- if (pwd == NULL) {
- return mprCreateUndefinedVar();
- }
- ret = mprObject("passwd");
-
- mprSetVar(&ret, "pw_name", mprString(pwd->pw_name));
- mprSetVar(&ret, "pw_passwd", mprString(pwd->pw_passwd));
- mprSetVar(&ret, "pw_uid", mprCreateIntegerVar(pwd->pw_uid));
- mprSetVar(&ret, "pw_gid", mprCreateIntegerVar(pwd->pw_gid));
- mprSetVar(&ret, "pw_gecos", mprString(pwd->pw_gecos));
- mprSetVar(&ret, "pw_dir", mprString(pwd->pw_dir));
- mprSetVar(&ret, "pw_shell", mprString(pwd->pw_shell));
- return ret;
-}
-
-/*
- return a struct passwd as an object
-*/
-static struct MprVar mpr_group(struct group *grp)
-{
- struct MprVar ret;
- if (grp == NULL) {
- return mprCreateUndefinedVar();
- }
- ret = mprObject("group");
-
- mprSetVar(&ret, "gr_name", mprString(grp->gr_name));
- mprSetVar(&ret, "gr_passwd", mprString(grp->gr_passwd));
- mprSetVar(&ret, "gr_gid", mprCreateIntegerVar(grp->gr_gid));
- mprSetVar(&ret, "gr_mem", mprList("gr_mem", (const char **)grp->gr_mem));
- return ret;
-}
-
-
-/*
- usage:
- var pw = nss.getpwnam("root");
-
- returns an object containing struct passwd entries
-*/
-static int ejs_getpwnam(MprVarHandle eid, int argc, struct MprVar **argv)
-{
- /* validate arguments */
- if (argc != 1 || argv[0]->type != MPR_TYPE_STRING) {
- ejsSetErrorMsg(eid, "getpwnam invalid arguments");
- return -1;
- }
-
- mpr_Return(eid, mpr_passwd(getpwnam(mprToString(argv[0]))));
- return 0;
-}
-
-/*
- usage:
- var pw = nss.getpwuid(0);
-
- returns an object containing struct passwd entries
-*/
-static int ejs_getpwuid(MprVarHandle eid, int argc, struct MprVar **argv)
-{
- /* validate arguments */
- if (argc != 1 || !mprVarIsNumber(argv[0]->type)) {
- ejsSetErrorMsg(eid, "getpwuid invalid arguments");
- return -1;
- }
- mpr_Return(eid, mpr_passwd(getpwuid(mprToInt(argv[0]))));
- return 0;
-}
-
-/*
- usage:
- var pw = nss.getgrnam("users");
-
- returns an object containing struct group entries
-*/
-static int ejs_getgrnam(MprVarHandle eid, int argc, struct MprVar **argv)
-{
- /* validate arguments */
- if (argc != 1 || argv[0]->type != MPR_TYPE_STRING) {
- ejsSetErrorMsg(eid, "getgrnam invalid arguments");
- return -1;
- }
- mpr_Return(eid, mpr_group(getgrnam(mprToString(argv[0]))));
- return 0;
-}
-
-/*
- usage:
- var pw = nss.getgrgid(0);
-
- returns an object containing struct group entries
-*/
-static int ejs_getgrgid(MprVarHandle eid, int argc, struct MprVar **argv)
-{
- /* validate arguments */
- if (argc != 1 || argv[0]->type != MPR_TYPE_STRING) {
- ejsSetErrorMsg(eid, "getgrgid invalid arguments");
- return -1;
- }
- mpr_Return(eid, mpr_group(getgrgid(mprToInt(argv[0]))));
- return 0;
-}
-
-
-/*
- initialise nss ejs subsystem
-*/
-static int ejs_nss_init(MprVarHandle eid, int argc, struct MprVar **argv)
-{
- struct MprVar *nss = mprInitObject(eid, "nss", argc, argv);
-
- mprSetCFunction(nss, "getpwnam", ejs_getpwnam);
- mprSetCFunction(nss, "getpwuid", ejs_getpwuid);
- mprSetCFunction(nss, "getgrnam", ejs_getgrnam);
- mprSetCFunction(nss, "getgrgid", ejs_getgrgid);
-
- return 0;
-}
-
-/*
- setup C functions that be called from ejs
-*/
-NTSTATUS smb_setup_ejs_nss(void)
-{
- ejsDefineCFunction(-1, "nss_init", ejs_nss_init, NULL, MPR_VAR_SCRIPT_HANDLE);
- return NT_STATUS_OK;
-}
diff --git a/source4/scripting/ejs/smbcalls_reg.c b/source4/scripting/ejs/smbcalls_reg.c
deleted file mode 100644
index ed8653d3a7..0000000000
--- a/source4/scripting/ejs/smbcalls_reg.c
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
-
- provide hooks into smbd C calls from ejs scripts
-
- Copyright (C) Jelmer Vernooij 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 3 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, see <http://www.gnu.org/licenses/>.
-*/
-
-#include "includes.h"
-#include "scripting/ejs/smbcalls.h"
-#include "lib/appweb/ejs/ejs.h"
-#include "dsdb/samdb/samdb.h"
-#include "librpc/ndr/libndr.h"
-#include "lib/registry/registry.h"
-
-/*
- get the connected db
- */
-static struct registry_context *ejs_get_reg_context(int eid)
-{
- struct registry_context *rctx = (struct registry_context *)mprGetThisPtr(eid, "registry");
- if (rctx == NULL) {
- ejsSetErrorMsg(eid, "unable to find registry");
- }
- return rctx;
-}
-
-static int ejs_apply_patchfile(MprVarHandle eid, int argc, struct MprVar **argv)
-{
- struct registry_context *rctx;
- WERROR error;
-
- /* validate arguments */
- if (argc != 1) {
- ejsSetErrorMsg(eid, "reg.apply_patchfile invalid number of arguments");
- return -1;
- }
-
- rctx = ejs_get_reg_context(eid);
- if (rctx == NULL) {
- return -1;
- }
-
- error = reg_diff_apply(rctx, mprToString(argv[0]));
-
- mpr_Return(eid, mprWERROR(error));
-
- return 0;
-}
-
-/*
- initialise registry ejs subsystem
-*/
-static int ejs_reg_open(MprVarHandle eid, int argc, struct MprVar **argv)
-{
- struct MprVar *reg = mprInitObject(eid, "registry", argc, argv);
- struct registry_context *rctx;
- WERROR error;
-
- error = reg_open_samba(mprMemCtx(), &rctx, mprEventCtx(), mprLpCtx(), NULL, NULL);
- SMB_ASSERT(W_ERROR_IS_OK(error));
-
- mprSetPtrChild(reg, "registry", rctx);
- mprSetCFunction(reg, "apply_patchfile", ejs_apply_patchfile);
-
- return 0;
-}
-
-
-/*
- setup C functions that be called from ejs
-*/
-NTSTATUS smb_setup_ejs_reg(void)
-{
- ejsDefineCFunction(-1, "reg_open", ejs_reg_open, NULL, MPR_VAR_SCRIPT_HANDLE);
- return NT_STATUS_OK;
-}
diff --git a/source4/scripting/ejs/smbcalls_rpc.c b/source4/scripting/ejs/smbcalls_rpc.c
deleted file mode 100644
index 94774d708b..0000000000
--- a/source4/scripting/ejs/smbcalls_rpc.c
+++ /dev/null
@@ -1,385 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
-
- provide interfaces to rpc calls from ejs scripts
-
- Copyright (C) Andrew Tridgell 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 3 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, see <http://www.gnu.org/licenses/>.
-*/
-
-#include "includes.h"
-#include "scripting/ejs/smbcalls.h"
-#include "lib/appweb/ejs/ejs.h"
-#include "librpc/gen_ndr/echo.h"
-#include "lib/cmdline/popt_common.h"
-#include "lib/messaging/irpc.h"
-#include "scripting/ejs/ejsrpc.h"
-#include "lib/util/dlinklist.h"
-#include "lib/events/events.h"
-#include "librpc/ndr/ndr_table.h"
-#include "auth/credentials/credentials.h"
-#include "librpc/rpc/dcerpc.h"
-#include "cluster/cluster.h"
-
-/*
- state of a irpc 'connection'
-*/
-struct ejs_irpc_connection {
- const char *server_name;
- struct server_id *dest_ids;
- struct messaging_context *msg_ctx;
-};
-
-/*
- messaging clients need server IDs as well ...
- */
-#define EJS_ID_BASE 0x30000000
-
-/*
- setup a context for talking to a irpc server
- example:
- status = irpc.connect("smb_server");
-*/
-static int ejs_irpc_connect(MprVarHandle eid, int argc, char **argv)
-{
- NTSTATUS status;
- int i;
- struct event_context *ev;
- struct ejs_irpc_connection *p;
- struct MprVar *this = mprGetProperty(ejsGetLocalObject(eid), "this", 0);
-
- /* validate arguments */
- if (argc != 1) {
- ejsSetErrorMsg(eid, "rpc_connect invalid arguments");
- return -1;
- }
-
- p = talloc(this, struct ejs_irpc_connection);
- if (p == NULL) {
- return -1;
- }
-
- p->server_name = argv[0];
-
- ev = mprEventCtx();
-
- /* create a messaging context, looping as we have no way to
- allocate temporary server ids automatically */
- for (i=0;i<10000;i++) {
- p->msg_ctx = messaging_init(p,
- lp_messaging_path(p, mprLpCtx()),
- cluster_id(EJS_ID_BASE, i),
- lp_iconv_convenience(mprLpCtx()),
- ev);
- if (p->msg_ctx) break;
- }
- if (p->msg_ctx == NULL) {
- ejsSetErrorMsg(eid, "irpc_connect unable to create a messaging context");
- talloc_free(p);
- return -1;
- }
-
- p->dest_ids = irpc_servers_byname(p->msg_ctx, p, p->server_name);
- if (p->dest_ids == NULL || p->dest_ids[0].id == 0) {
- talloc_free(p);
- status = NT_STATUS_OBJECT_NAME_NOT_FOUND;
- } else {
- mprSetPtrChild(this, "irpc", p);
- status = NT_STATUS_OK;
- }
-
- mpr_Return(eid, mprNTSTATUS(status));
- return 0;
-}
-
-
-/*
- connect to an rpc server
- examples:
- status = rpc.connect("ncacn_ip_tcp:localhost");
- status = rpc.connect("ncacn_ip_tcp:localhost", "pipe_name");
-*/
-static int ejs_rpc_connect(MprVarHandle eid, int argc, char **argv)
-{
- const char *binding, *pipe_name;
- const struct ndr_interface_table *iface;
- NTSTATUS status;
- struct dcerpc_pipe *p;
- struct cli_credentials *creds;
- struct event_context *ev;
- struct MprVar *this = mprGetProperty(ejsGetLocalObject(eid), "this", 0);
- struct MprVar *credentials;
-
- /* validate arguments */
- if (argc < 1) {
- ejsSetErrorMsg(eid, "rpc_connect invalid arguments");
- return -1;
- }
-
- binding = argv[0];
- if (strchr(binding, ':') == NULL) {
- /* its an irpc connect */
- return ejs_irpc_connect(eid, argc, argv);
- }
-
- if (argc > 1) {
- pipe_name = argv[1];
- } else {
- pipe_name = mprToString(mprGetProperty(this, "pipe_name", NULL));
- }
-
- iface = ndr_table_by_name(pipe_name);
- if (iface == NULL) {
- status = NT_STATUS_OBJECT_NAME_INVALID;
- goto done;
- }
-
- credentials = mprGetProperty(this, "credentials", NULL);
- if (credentials) {
- creds = (struct cli_credentials *)
- mprGetPtr(credentials, "creds");
- } else {
- creds = cmdline_credentials;
- }
- if (creds == NULL) {
- creds = cli_credentials_init(mprMemCtx());
- cli_credentials_set_anonymous(creds);
- }
-
- ev = mprEventCtx();
-
- status = dcerpc_pipe_connect(this, &p, binding, iface, creds, ev,
- mprLpCtx());
- if (!NT_STATUS_IS_OK(status)) goto done;
-
- /* callers don't allocate ref vars in the ejs interface */
- p->conn->flags |= DCERPC_NDR_REF_ALLOC;
-
- /* by making the pipe a child of the connection variable, it will
- auto close when it goes out of scope in the script */
- mprSetPtrChild(this, "pipe", p);
-
-done:
- mpr_Return(eid, mprNTSTATUS(status));
- return 0;
-}
-
-
-/*
- make an irpc call - called via the same interface as rpc
-*/
-static int ejs_irpc_call(int eid, struct MprVar *io,
- const struct ndr_interface_table *iface, int callnum,
- ejs_pull_function_t ejs_pull, ejs_push_function_t ejs_push)
-{
- NTSTATUS status;
- void *ptr;
- struct ejs_rpc *ejs;
- const struct ndr_interface_call *call;
- struct ejs_irpc_connection *p;
- struct irpc_request **reqs;
- int i, count;
- struct MprVar *results;
-
- p = (struct ejs_irpc_connection *)mprGetThisPtr(eid, "irpc");
-
- ejs = talloc(mprMemCtx(), struct ejs_rpc);
- if (ejs == NULL) {
- status = NT_STATUS_NO_MEMORY;
- goto done;
- }
-
- call = &iface->calls[callnum];
-
- ejs->eid = eid;
- ejs->callname = call->name;
-
- /* allocate the C structure */
- ptr = talloc_zero_size(ejs, call->struct_size);
- if (ptr == NULL) {
- status = NT_STATUS_NO_MEMORY;
- goto done;
- }
-
- /* convert the mpr object into a C structure */
- status = ejs_pull(ejs, io, ptr);
- if (!NT_STATUS_IS_OK(status)) {
- goto done;
- }
-
- for (count=0;p->dest_ids[count].id;count++) /* noop */ ;
-
- /* we need to make a call per server */
- reqs = talloc_array(ejs, struct irpc_request *, count);
- if (reqs == NULL) {
- status = NT_STATUS_NO_MEMORY;
- goto done;
- }
-
- /* make the actual calls */
- for (i=0;i<count;i++) {
- reqs[i] = irpc_call_send(p->msg_ctx, p->dest_ids[i],
- iface, callnum, ptr, ptr);
- if (reqs[i] == NULL) {
- status = NT_STATUS_NO_MEMORY;
- goto done;
- }
- talloc_steal(reqs, reqs[i]);
- }
-
- mprSetVar(io, "results", mprObject("results"));
- results = mprGetProperty(io, "results", NULL);
-
- /* and receive the results, placing them in io.results[i] */
- for (i=0;i<count;i++) {
- struct MprVar *output;
-
- status = irpc_call_recv(reqs[i]);
- if (!NT_STATUS_IS_OK(status)) {
- goto done;
- }
- status = ejs_push(ejs, io, ptr);
- if (!NT_STATUS_IS_OK(status)) {
- goto done;
- }
-
- /* add to the results array */
- output = mprGetProperty(io, "output", NULL);
- if (output) {
- char idx[16];
- mprItoa(i, idx, sizeof(idx));
- mprSetProperty(results, idx, output);
- mprDeleteProperty(io, "output");
- }
- }
- mprSetVar(results, "length", mprCreateIntegerVar(i));
-
-done:
- talloc_free(ejs);
- mpr_Return(eid, mprNTSTATUS(status));
- if (NT_STATUS_EQUAL(status, NT_STATUS_INTERNAL_ERROR)) {
- return -1;
- }
- return 0;
-}
-
-
-/*
- backend code for making an rpc call - this is called from the pidl generated ejs
- code
-*/
- int ejs_rpc_call(int eid, int argc, struct MprVar **argv,
- const struct ndr_interface_table *iface, int callnum,
- ejs_pull_function_t ejs_pull, ejs_push_function_t ejs_push)
-{
- struct MprVar *io;
- struct dcerpc_pipe *p;
- NTSTATUS status;
- void *ptr;
- struct rpc_request *req;
- struct ejs_rpc *ejs;
- const struct ndr_interface_call *call;
-
- if (argc != 1 || argv[0]->type != MPR_TYPE_OBJECT) {
- ejsSetErrorMsg(eid, "rpc_call invalid arguments");
- return -1;
- }
-
- io = argv[0];
-
- if (mprGetThisPtr(eid, "irpc")) {
- /* its an irpc call */
- return ejs_irpc_call(eid, io, iface, callnum, ejs_pull, ejs_push);
- }
-
- /* get the pipe info */
- p = mprGetThisPtr(eid, "pipe");
- if (p == NULL) {
- ejsSetErrorMsg(eid, "rpc_call invalid pipe");
- return -1;
- }
-
- ejs = talloc(mprMemCtx(), struct ejs_rpc);
- if (ejs == NULL) {
- status = NT_STATUS_NO_MEMORY;
- goto done;
- }
-
- call = &iface->calls[callnum];
-
- ejs->eid = eid;
- ejs->callname = call->name;
-
- /* allocate the C structure */
- ptr = talloc_zero_size(ejs, call->struct_size);
- if (ptr == NULL) {
- status = NT_STATUS_NO_MEMORY;
- goto done;
- }
-
- /* convert the mpr object into a C structure */
- status = ejs_pull(ejs, io, ptr);
- if (!NT_STATUS_IS_OK(status)) {
- goto done;
- }
-
- /* make the actual call */
- req = dcerpc_ndr_request_send(p, NULL, iface, callnum, ptr, ptr);
-
- /* if requested, print the structure */
- if (p->conn->flags & DCERPC_DEBUG_PRINT_IN) {
- ndr_print_function_debug(call->ndr_print, call->name, NDR_IN, ptr);
- }
-
- if (req == NULL) {
- status = NT_STATUS_NO_MEMORY;
- goto done;
- }
-
- status = dcerpc_ndr_request_recv(req);
- if (!NT_STATUS_IS_OK(status)) {
- goto done;
- }
-
- /* print the 'out' structure, if needed */
- if (p->conn->flags & DCERPC_DEBUG_PRINT_OUT) {
- ndr_print_function_debug(call->ndr_print, call->name, NDR_OUT, ptr);
- }
-
- status = ejs_push(ejs, io, ptr);
-
-done:
- talloc_free(ejs);
- mpr_Return(eid, mprNTSTATUS(status));
- if (NT_STATUS_EQUAL(status, NT_STATUS_INTERNAL_ERROR)) {
- return -1;
- }
- return 0;
-}
-
-/*
- hook called by generated RPC interfaces at the end of their init routines
- used to add generic operations on the pipe
-*/
-int ejs_rpc_init(struct MprVar *obj, const char *name)
-{
- ndr_table_init();
-
- mprSetStringCFunction(obj, "connect", ejs_rpc_connect);
- if (mprGetProperty(obj, "pipe_name", NULL) == NULL) {
- mprSetVar(obj, "pipe_name", mprString(name));
- }
- return 0;
-}
diff --git a/source4/scripting/libjs/auth.js b/source4/scripting/libjs/auth.js
deleted file mode 100644
index 3fe81d0ea7..0000000000
--- a/source4/scripting/libjs/auth.js
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
- auth js library functions
- Copyright Andrew Tridgell 2005
- released under the GNU GPL version 3 or later
-*/
-
-
-/*
- get a list of domains for SWAT authentication
-*/
-function getDomainList()
-{
- var ret = new Array(2);
- var lp = loadparm_init();
- ret[0] = "System User";
- ret[1] = lp.get("workgroup");
- return ret;
-}
diff --git a/source4/scripting/libjs/management.js b/source4/scripting/libjs/management.js
deleted file mode 100644
index 4a43275156..0000000000
--- a/source4/scripting/libjs/management.js
+++ /dev/null
@@ -1,157 +0,0 @@
-/*
- backend code for Samba4 management
- Copyright Andrew Tridgell 2005
- Released under the GNU GPL version 3 or later
-*/
-
-
-/*
- return a list of current sessions
-*/
-function smbsrv_sessions()
-{
- var irpc = irpc_init();
- status = irpc.connect("smb_server");
- if (status.is_ok != true) {
- return undefined;
- }
-
- var io = irpcObj();
- io.input.level = irpc.SMBSRV_INFO_SESSIONS;
- status = irpc.smbsrv_information(io);
- if (status.is_ok != true) {
- return undefined;
- }
-
- /* gather the results into a single array */
- var i, count=0, ret = new Array(0);
- for (i=0;i<io.results.length;i++) {
- var sessions = io.results[i].info.sessions.sessions;
- var j;
- for (j=0;j<sessions.length;j++) {
- ret[count] = sessions[j];
- count++;
- }
- }
- return ret;
-}
-
-/*
- return a list of current tree connects
-*/
-function smbsrv_tcons()
-{
- var irpc = irpc_init();
- status = irpc.connect("smb_server");
- if (status.is_ok != true) {
- return undefined;
- }
-
- var io = irpcObj();
- io.input.level = irpc.SMBSRV_INFO_TCONS;
- status = irpc.smbsrv_information(io);
- if (status.is_ok != true) {
- return undefined;
- }
-
- /* gather the results into a single array */
- var i, count=0, ret = new Object();
- for (i=0;i<io.results.length;i++) {
- var tcons = io.results[i].info.tcons.tcons;
- var j;
- for (j=0;j<tcons.length;j++) {
- ret[count] = tcons[j];
- count++;
- }
- }
- ret.length = count;
- return ret;
-}
-
-/*
- return nbtd statistics
-*/
-function nbtd_statistics()
-{
- var irpc = irpc_init();
- status = irpc.connect("nbt_server");
- if (status.is_ok != true) {
- return undefined;
- }
-
- var io = irpcObj();
- io.input.level = irpc.NBTD_INFO_STATISTICS;
- status = irpc.nbtd_information(io);
- if (status.is_ok != true) {
- return undefined;
- }
- return io.results[0].info.stats;
-}
-
-/*
- see if a service is enabled
-*/
-function service_enabled(name)
-{
- var lp = loadparm_init();
- var services = lp.get("server services");
- var i;
- for (i=0;i<services.length;i++) {
- if (services[i] == name) {
- return true;
- }
- }
- return false;
-}
-
-/*
- show status of a server
-*/
-function server_status(name)
-{
- var i;
- var io;
- var irpc = irpc_init();
-
- if (!service_enabled(name)) {
- return "DISABLED";
- }
-
- status = irpc.connect(name + "_server");
- if (status.is_ok != true) {
- return "DOWN";
- }
-
- var io = irpcObj();
- status = irpc.irpc_uptime(io);
- if (status.is_ok != true) {
- return "NOT RESPONDING";
- }
-
- return "RUNNING";
-}
-
-/*
- show status of a stream server
-*/
-function stream_server_status(name)
-{
- var irpc = irpc_init();
-
- if (!service_enabled(name)) {
- return "DISABLED";
- }
- status = irpc.connect(name + "_server");
- if (status.is_ok != true) {
- return "0 connections";
- }
-
- var io = irpcObj();
- status = irpc.irpc_uptime(io);
- if (status.is_ok != true) {
- return "NOT RESPONDING";
- }
-
- var n = io.results.length;
- return sprintf("%u connection%s", n, plural(n));
-}
diff --git a/source4/scripting/bin/samr.py b/source4/scripting/python/examples/samr.py
index e91b5bc312..1f2afbe688 100755
--- a/source4/scripting/bin/samr.py
+++ b/source4/scripting/python/examples/samr.py
@@ -100,7 +100,7 @@ if len(sys.argv) != 2:
binding = sys.argv[1]
-print "Connecting to " + binding
+print "Connecting to %s" % binding
try:
samr = samr.samr(binding)
except Exception, e:
diff --git a/source4/scripting/bin/winreg.py b/source4/scripting/python/examples/winreg.py
index 19d39e56ab..80b48ecfd7 100755
--- a/source4/scripting/bin/winreg.py
+++ b/source4/scripting/python/examples/winreg.py
@@ -11,7 +11,7 @@ import sys
# Find right directory when running from source tree
sys.path.insert(0, "bin/python")
-import winreg
+from samba.dcerpc import winreg
import optparse
import samba.getopt as options