r26270: Require specifying the loadparm_context or NULL to cli_credentials_guess().
[abartlet/samba.git/.git] / source4 / scripting / ejs / smbcalls_rpc.c
index 29346f2586ec20ce87b6d87f089a002bb7bf6257..049494cba636e00e8e84a8b107ac654ed3a6fe30 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,
@@ -16,8 +16,7 @@
    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 "lib/cmdline/popt_common.h"
 #include "lib/messaging/irpc.h"
 #include "scripting/ejs/ejsrpc.h"
-#include "dlinklist.h"
+#include "lib/util/dlinklist.h"
 #include "lib/events/events.h"
-#include "librpc/rpc/dcerpc_table.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;
-       uint32_t *dest_ids;
+       struct server_id *dest_ids;
        struct messaging_context *msg_ctx;
 };
 
@@ -78,7 +78,9 @@ static int ejs_irpc_connect(MprVarHandle eid, int argc, char **argv)
        /* 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, EJS_ID_BASE + i, ev);
+               p->msg_ctx = messaging_init(p, 
+                                           lp_messaging_path(p, global_loadparm),
+                                           cluster_id(EJS_ID_BASE + i), ev);
                if (p->msg_ctx) break;
        }
        if (p->msg_ctx == NULL) {
@@ -87,8 +89,8 @@ static int ejs_irpc_connect(MprVarHandle eid, int argc, char **argv)
                return -1;
        }
 
-       p->dest_ids = irpc_servers_byname(p->msg_ctx, p->server_name);
-       if (p->dest_ids == NULL || p->dest_ids[0] == 0) {
+       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 {
@@ -110,7 +112,7 @@ static int ejs_irpc_connect(MprVarHandle eid, int argc, char **argv)
 static int ejs_rpc_connect(MprVarHandle eid, int argc, char **argv)
 {
        const char *binding, *pipe_name;
-       const struct dcerpc_interface_table *iface;
+       const struct ndr_interface_table *iface;
        NTSTATUS status;
        struct dcerpc_pipe *p;
        struct cli_credentials *creds;
@@ -136,7 +138,7 @@ static int ejs_rpc_connect(MprVarHandle eid, int argc, char **argv)
                pipe_name = mprToString(mprGetProperty(this, "pipe_name", NULL));
        }
 
-       iface = idl_iface_by_name(pipe_name);
+       iface = ndr_table_by_name(pipe_name);
        if (iface == NULL) {
                status = NT_STATUS_OBJECT_NAME_INVALID;
                goto done;
@@ -144,13 +146,13 @@ static int ejs_rpc_connect(MprVarHandle eid, int argc, char **argv)
 
        credentials = mprGetProperty(this, "credentials", NULL);
        if (credentials) {
-               creds = mprGetPtr(credentials, "creds");
+               creds = (struct cli_credentials *)
+                               mprGetPtr(credentials, "creds");
        } else {
                creds = cmdline_credentials;
        }
        if (creds == NULL) {
                creds = cli_credentials_init(mprMemCtx());
-               cli_credentials_guess(creds);
                cli_credentials_set_anonymous(creds);
        }
 
@@ -176,19 +178,19 @@ done:
   make an irpc call - called via the same interface as rpc
 */
 static int ejs_irpc_call(int eid, struct MprVar *io, 
-                        const struct dcerpc_interface_table *iface, int callnum,
+                        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 dcerpc_interface_call *call;
+       const struct ndr_interface_call *call;
        struct ejs_irpc_connection *p;
        struct irpc_request **reqs;
        int i, count;
        struct MprVar *results;
 
-       p = mprGetThisPtr(eid, "irpc");
+       p = (struct ejs_irpc_connection *)mprGetThisPtr(eid, "irpc");
 
        ejs = talloc(mprMemCtx(), struct ejs_rpc);
        if (ejs == NULL) {
@@ -214,7 +216,7 @@ static int ejs_irpc_call(int eid, struct MprVar *io,
                goto done;
        }
 
-       for (count=0;p->dest_ids[count];count++) /* noop */ ;
+       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);
@@ -276,7 +278,7 @@ done:
   code
 */
  int ejs_rpc_call(int eid, int argc, struct MprVar **argv,
-                 const struct dcerpc_interface_table *iface, int callnum,
+                 const struct ndr_interface_table *iface, int callnum,
                  ejs_pull_function_t ejs_pull, ejs_push_function_t ejs_push)
 {
        struct MprVar *io;
@@ -285,7 +287,7 @@ done:
        void *ptr;
        struct rpc_request *req;
        struct ejs_rpc *ejs;
-       const struct dcerpc_interface_call *call;
+       const struct ndr_interface_call *call;
 
        if (argc != 1 || argv[0]->type != MPR_TYPE_OBJECT) {
                ejsSetErrorMsg(eid, "rpc_call invalid arguments");
@@ -370,7 +372,7 @@ done:
 */
 int ejs_rpc_init(struct MprVar *obj, const char *name)
 {
-       dcerpc_table_init();
+       ndr_table_init();
 
        mprSetStringCFunction(obj, "connect", ejs_rpc_connect);
        if (mprGetProperty(obj, "pipe_name", NULL) == NULL) {