diff options
author | Tim Potter <tpot@samba.org> | 2005-06-10 08:00:02 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:17:55 -0500 |
commit | aa7b6b3ea57b0e36b7b43ed2f312ee724e243541 (patch) | |
tree | 532603f046c80d432197109ef7904691d96711e5 /source4/scripting | |
parent | a9258487043eb4862769ee8da02b3810db925295 (diff) | |
download | samba-aa7b6b3ea57b0e36b7b43ed2f312ee724e243541.tar.gz samba-aa7b6b3ea57b0e36b7b43ed2f312ee724e243541.tar.bz2 samba-aa7b6b3ea57b0e36b7b43ed2f312ee724e243541.zip |
r7457: Return an ejs C pointer object from the ejs connect() function.
Add a session_setup() function that does an anonymous session setup. Will
add credential passing later.
(This used to be commit 832332de5db7102085e7c44d4256fb199d8123eb)
Diffstat (limited to 'source4/scripting')
-rw-r--r-- | source4/scripting/ejs/smbcalls_cli.c | 78 |
1 files changed, 62 insertions, 16 deletions
diff --git a/source4/scripting/ejs/smbcalls_cli.c b/source4/scripting/ejs/smbcalls_cli.c index de31d7a900..bfc71948b9 100644 --- a/source4/scripting/ejs/smbcalls_cli.c +++ b/source4/scripting/ejs/smbcalls_cli.c @@ -23,20 +23,8 @@ #include "includes.h" #include "lib/ejs/ejs.h" #include "librpc/gen_ndr/ndr_nbt.h" - -static struct MprVar mprTransport(struct smbcli_transport *transport) -{ - struct MprVar res, val; - - res = mprCreateObjVar("transport", MPR_DEFAULT_HASH_SIZE); - - val = mprCreateStringVar(talloc_get_name(transport), 1); - mprCreateProperty(&res, "name", &val); - - /* TODO: Create a C pointer "value" property */ - - return res; -} +#include "libcli/raw/libcliraw.h" +#include "libcli/composite/composite.h" /* Connect to a server */ @@ -93,7 +81,64 @@ static int ejs_cli_connect(MprVarHandle eid, int argc, char **argv) /* Return a socket object */ - ejsSetReturnValue(eid, mprTransport(transport)); + ejsSetReturnValue(eid, mprCreatePtrVar(transport, talloc_get_name(transport))); + + return 0; +} + +/* Perform a session setup: + + session_setup(conn, "DOMAIN\USERNAME%PASSWORD"); + session_setup(conn, USERNAME, PASSWORD); + session_setup(conn, DOMAIN, USERNAME, PASSWORD); + + */ + +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; + + /* Argument parsing */ + + if (argc < 1 || argc > 3) { + ejsSetErrorMsg(eid, "session_setup invalid arguments"); + return -1; + } + + if (argv[0]->type != MPR_TYPE_PTR) { + ejsSetErrorMsg(eid, "first arg is not a connect handle"); + return -1; + } + + transport = argv[0]->ptr; + + /* Do session setup */ + + session = smbcli_session_init(transport, transport, True); + if (!session) { + ejsSetErrorMsg(eid, "session init failed"); + return -1; + } + + creds = cli_credentials_init(session); + cli_credentials_set_anonymous(creds); + + 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); + + session->vuid = setup.out.vuid; + + /* Return a session object */ + + ejsSetReturnValue(eid, mprCreatePtrVar(session, talloc_get_name(session))); return 0; } @@ -103,5 +148,6 @@ static int ejs_cli_connect(MprVarHandle eid, int argc, char **argv) */ void smb_setup_ejs_cli(void) { - ejsDefineStringCFunction(-1, "connect", ejs_cli_connect, NULL, MPR_VAR_SCRIPT_HANDLE); + ejsDefineStringCFunction(-1, "connect", ejs_cli_connect, NULL, MPR_VAR_SCRIPT_HANDLE); + ejsDefineCFunction(-1, "session_setup", ejs_cli_ssetup, NULL, MPR_VAR_SCRIPT_HANDLE); } |