svn commit: samba r7351 - in branches/SAMBA_4_0/source/scripting: .
ejs
tpot at samba.org
tpot at samba.org
Tue Jun 7 07:00:28 GMT 2005
Author: tpot
Date: 2005-06-07 07:00:28 +0000 (Tue, 07 Jun 2005)
New Revision: 7351
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=7351
Log:
Start of ejs smb client library. I need to figure out a nice API here
that doesn't expose too much of the cifs protocol but still allows
people to do neat things.
Also, talloc lifetimes need to be thought about properly.
Added:
branches/SAMBA_4_0/source/scripting/ejs/smbcalls_cli.c
Modified:
branches/SAMBA_4_0/source/scripting/config.mk
branches/SAMBA_4_0/source/scripting/ejs/smbcalls.c
Changeset:
Modified: branches/SAMBA_4_0/source/scripting/config.mk
===================================================================
--- branches/SAMBA_4_0/source/scripting/config.mk 2005-06-07 06:38:13 UTC (rev 7350)
+++ branches/SAMBA_4_0/source/scripting/config.mk 2005-06-07 07:00:28 UTC (rev 7351)
@@ -6,6 +6,7 @@
scripting/ejs/smbcalls_config.o \
scripting/ejs/smbcalls_ldb.o \
scripting/ejs/smbcalls_nbt.o \
+ scripting/ejs/smbcalls_cli.o \
scripting/ejs/mprutil.o
REQUIRED_SUBSYSTEMS = AUTH EJS LIBBASIC
# End SUBSYSTEM SMBCALLS
Modified: branches/SAMBA_4_0/source/scripting/ejs/smbcalls.c
===================================================================
--- branches/SAMBA_4_0/source/scripting/ejs/smbcalls.c 2005-06-07 06:38:13 UTC (rev 7350)
+++ branches/SAMBA_4_0/source/scripting/ejs/smbcalls.c 2005-06-07 07:00:28 UTC (rev 7351)
@@ -187,6 +187,7 @@
smb_setup_ejs_config();
smb_setup_ejs_ldb();
smb_setup_ejs_nbt();
+ smb_setup_ejs_cli();
ejsDefineCFunction(-1, "typeof", ejs_typeof, NULL, MPR_VAR_SCRIPT_HANDLE);
ejsDefineStringCFunction(-1, "getDomainList", ejs_domain_list, NULL, MPR_VAR_SCRIPT_HANDLE);
Added: branches/SAMBA_4_0/source/scripting/ejs/smbcalls_cli.c
===================================================================
--- branches/SAMBA_4_0/source/scripting/ejs/smbcalls_cli.c 2005-06-07 06:38:13 UTC (rev 7350)
+++ branches/SAMBA_4_0/source/scripting/ejs/smbcalls_cli.c 2005-06-07 07:00:28 UTC (rev 7351)
@@ -0,0 +1,89 @@
+/*
+ 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 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/ejs/ejs.h"
+#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, True);
+
+ 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)) {
+ ejsSetReturnValue(eid, mprNTSTATUS(result));
+ return 0;
+ }
+
+ return 0;
+}
+
+/*
+ setup C functions that be called from ejs
+*/
+void smb_setup_ejs_cli(void)
+{
+ ejsDefineStringCFunction(-1, "connect", ejs_cli_connect, NULL, MPR_VAR_SCRIPT_HANDLE);
+}
More information about the samba-cvs
mailing list