Merge branch 'v4-0-trivial' into v4-0-test
[kai/samba.git] / source / scripting / ejs / smbcalls_cli.c
index 2433b33352616c6ea52cd6092e76c608456dc627..dbb36312da544ba8c5906ecae99645470d997a6f 100644 (file)
@@ -7,7 +7,7 @@
    
    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
+   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,
    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.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include "includes.h"
 #include "scripting/ejs/smbcalls.h"
-#include "lib/ejs/ejs.h"
+#include "lib/appweb/ejs/ejs.h"
 #include "libcli/raw/libcliraw.h"
 #include "libcli/composite/composite.h"
-#include "clilist.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
 
@@ -59,7 +62,7 @@ static int ejs_cli_connect(MprVarHandle eid, int argc, char **argv)
                return -1;
        }
 
-       transport = smbcli_transport_init(sock, sock, False);
+       transport = smbcli_transport_init(sock, sock, false);
 
        if (!transport) {
                ejsSetErrorMsg(eid, "transport init failed");
@@ -190,7 +193,7 @@ static int ejs_cli_ssetup(MprVarHandle eid, int argc, MprVar **argv)
 
        /* Do session setup */
 
-       session = smbcli_session_init(transport, transport, False);
+       session = smbcli_session_init(transport, transport, false);
 
        if (!session) {
                ejsSetErrorMsg(eid, "session init failed");
@@ -250,7 +253,7 @@ static int ejs_cli_tree_connect(MprVarHandle eid, int argc, MprVar **argv)
        }
 
        session = argv[0]->ptr;
-       tree = smbcli_tree_init(session, session, False);
+       tree = smbcli_tree_init(session, session, false);
 
        if (!tree) {
                ejsSetErrorMsg(eid, "tree init failed");
@@ -410,8 +413,9 @@ static int ejs_cli_disconnect(MprVarHandle eid, int argc, MprVar **argv)
 static int ejs_tree_connect(MprVarHandle eid, int argc, char **argv)
 {
        struct cli_credentials *creds;
+       struct smb_composite_connect io;
        struct smbcli_tree *tree;
-       const char *hostname, *sharename;
+       char *hostname, *sharename;
        NTSTATUS result;
        TALLOC_CTX *mem_ctx;
 
@@ -422,19 +426,31 @@ static int ejs_tree_connect(MprVarHandle eid, int argc, char **argv)
 
        /* Set up host, share destination */
 
-       mem_ctx = talloc_init(NULL);
+       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);
+       cli_credentials_set_conf(creds, mprLpCtx());
        cli_credentials_parse_string(creds, argv[1], CRED_SPECIFIED);
 
        /* Do connect */
 
-       result = smbcli_tree_full_connection(NULL, &tree, hostname, 0,
-                                            sharename, "?????", creds, NULL);
+       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);
 
@@ -472,7 +488,7 @@ static int ejs_tree_disconnect(MprVarHandle eid, int argc, MprVar **argv)
                return -1;
        }
 
-       tree = talloc_check_name(argv[0]->ptr, "struct smbcli_tree");
+       tree = talloc_get_type(argv[0]->ptr, struct smbcli_tree);
 
        result = smb_tree_disconnect(tree);
 
@@ -501,7 +517,7 @@ static int ejs_mkdir(MprVarHandle eid, int argc, MprVar **argv)
                return -1;
        }
 
-       tree = argv[0]->ptr;
+       tree = (struct smbcli_tree *)argv[0]->ptr;
 
        if (!mprVarIsString(argv[1]->type)) {
                ejsSetErrorMsg(eid, "arg 2 must be a string");
@@ -535,7 +551,7 @@ static int ejs_rmdir(MprVarHandle eid, int argc, MprVar **argv)
                return -1;
        }
 
-       tree = argv[0]->ptr;
+       tree = (struct smbcli_tree *)argv[0]->ptr;
 
        if (!mprVarIsString(argv[1]->type)) {
                ejsSetErrorMsg(eid, "arg 2 must be a string");
@@ -569,7 +585,7 @@ static int ejs_rename(MprVarHandle eid, int argc, MprVar **argv)
                return -1;
        }
 
-       tree = argv[0]->ptr;
+       tree = (struct smbcli_tree *)argv[0]->ptr;
 
        if (!mprVarIsString(argv[1]->type)) {
                ejsSetErrorMsg(eid, "arg 2 must be a string");
@@ -608,7 +624,7 @@ static int ejs_unlink(MprVarHandle eid, int argc, MprVar **argv)
                return -1;
        }
 
-       tree = argv[0]->ptr;
+       tree = (struct smbcli_tree *)argv[0]->ptr;
 
        if (!mprVarIsString(argv[1]->type)) {
                ejsSetErrorMsg(eid, "arg 2 must be a string");
@@ -635,7 +651,7 @@ static void ejs_list_helper(struct clilist_file_info *info, const char *mask,
        char idx[16];
 
        mprItoa(result->properties->numDataItems, idx, sizeof(idx));
-       mprSetVar(result, idx, mprCreateStringVar(info->name, 1));
+       mprSetVar(result, idx, mprString(info->name));
 }
 
 static int ejs_list(MprVarHandle eid, int argc, MprVar **argv)
@@ -655,7 +671,7 @@ static int ejs_list(MprVarHandle eid, int argc, MprVar **argv)
                return -1;
        }
 
-       tree = argv[0]->ptr;
+       tree = (struct smbcli_tree *)argv[0]->ptr;
 
        if (!mprVarIsString(argv[1]->type)) {
                ejsSetErrorMsg(eid, "arg 2 must be a string");