More changes getting WMI code to compile, import manual marshalling.
[samba.git] / source4 / lib / com / dcom / main.c
index f3eb2ab608dd5f22df244889f94ee2f23eb88d87..2770897ca33eace182f1fb53dc4cea6848fc41cc 100644 (file)
@@ -25,6 +25,7 @@
 #include "librpc/gen_ndr/ndr_remact_c.h"
 #include "librpc/gen_ndr/com_dcom.h"
 #include "librpc/gen_ndr/dcom.h"
+#include "librpc/rpc/dcerpc.h"
 #include "lib/com/dcom/dcom.h"
 #include "librpc/ndr/ndr_table.h"
 #include "lib/util/dlinklist.h"
@@ -125,7 +126,9 @@ void dcom_add_server_credentials(struct com_context *ctx, const char *server,
        DLIST_ADD(ctx->dcom->credentials, c);
 }
 
-void dcom_update_credentials_for_aliases(struct com_context *ctx, const char *server, struct DUALSTRINGARRAY *pds)
+void dcom_update_credentials_for_aliases(struct com_context *ctx, 
+                                                                                const char *server, 
+                                                                                struct DUALSTRINGARRAY *pds)
 {
        struct cli_credentials *cc;
        struct dcerpc_binding *b;
@@ -134,10 +137,12 @@ void dcom_update_credentials_for_aliases(struct com_context *ctx, const char *se
 
        cc = dcom_get_server_credentials(ctx, server);
         for (i = 0; pds->stringbindings[i]; ++i) {
-                if (pds->stringbindings[i]->wTowerId != EPM_PROTOCOL_TCP) continue;
+                if (pds->stringbindings[i]->wTowerId != EPM_PROTOCOL_TCP) 
+                                       continue;
                 status = dcerpc_binding_from_STRINGBINDING(ctx, &b, pds->stringbindings[i]);
-               if (!NT_STATUS_IS_OK(status)) continue;
-               dcom_set_server_credentials(ctx, b->host, cc);
+               if (!NT_STATUS_IS_OK(status)) 
+                       continue;
+               dcom_add_server_credentials(ctx, b->host, cc);
                talloc_free(b);
        }
 }
@@ -150,11 +155,12 @@ struct dcom_client_context *dcom_client_init(struct com_context *ctx, struct cli
                 cli_credentials_set_conf(credentials, ctx->lp_ctx);
                 cli_credentials_parse_string(credentials, "%", CRED_SPECIFIED);
        }
-       dcom_set_server_credentials(ctx, NULL, credentials);
+       dcom_add_server_credentials(ctx, NULL, credentials);
        return ctx->dcom;
 }
 
-static NTSTATUS dcom_connect_host(struct com_context *ctx, struct dcerpc_pipe **p, const char *server)
+static NTSTATUS dcom_connect_host(struct com_context *ctx, 
+                                                                 struct dcerpc_pipe **p, const char *server)
 {
        struct dcerpc_binding *bd;
        const char * available_transports[] = { "ncacn_ip_tcp", "ncacn_np" };
@@ -170,7 +176,8 @@ static NTSTATUS dcom_connect_host(struct com_context *ctx, struct dcerpc_pipe **
        loc_ctx = talloc_new(ctx);
 
        /* Allow server name to contain a binding string */
-       if (strchr(server, ':') && NT_STATUS_IS_OK(dcerpc_parse_binding(loc_ctx, server, &bd))) {
+       if (strchr(server, ':') && 
+               NT_STATUS_IS_OK(dcerpc_parse_binding(loc_ctx, server, &bd))) {
                if (DEBUGLVL(11))
                        bd->flags |= DCERPC_DEBUG_PRINT_BOTH;
                status = dcerpc_pipe_connect_b(ctx->event_ctx, p, bd, 
@@ -185,9 +192,11 @@ static NTSTATUS dcom_connect_host(struct com_context *ctx, struct dcerpc_pipe **
                if (!binding) {
                        status = NT_STATUS_NO_MEMORY;
                        goto end;
-               };
-               status = dcerpc_pipe_connect(ctx->event_ctx, p, binding, &ndr_table_IRemoteActivation,
-                                            dcom_get_server_credentials(ctx, server), ctx->event_ctx, ctx->lp_ctx);
+               }
+               status = dcerpc_pipe_connect(ctx->event_ctx, p, binding, 
+                                                                        &ndr_table_IRemoteActivation, 
+                                                                        dcom_get_server_credentials(ctx, server), 
+                                                                        ctx->event_ctx, ctx->lp_ctx);
 
                if (NT_STATUS_IS_OK(status)) {
                        if (DEBUGLVL(11))
@@ -203,7 +212,8 @@ end:
        return status;
 }
 
-struct dcom_object_exporter *object_exporter_by_oxid(struct com_context *ctx, uint64_t oxid)
+struct dcom_object_exporter *object_exporter_by_oxid(struct com_context *ctx, 
+                                                                                                        uint64_t oxid)
 {
        struct dcom_object_exporter *ox;
        for (ox = ctx->dcom->object_exporters; ox; ox = ox->next) {
@@ -500,7 +510,7 @@ NTSTATUS dcom_get_pipe(struct IUnknown *iface, struct dcerpc_pipe **pp)
        return NT_STATUS_OK;
 }
 
-NTSTATUS dcom_OBJREF_from_IUnknown(struct OBJREF *o, struct IUnknown *p)
+NTSTATUS dcom_OBJREF_from_IUnknown(TALLLOC_CTX *mem_ctx, struct OBJREF *o, struct IUnknown *p)
 {
        /* FIXME: Cache generated objref objects? */
        ZERO_STRUCTP(o);
@@ -516,7 +526,7 @@ NTSTATUS dcom_OBJREF_from_IUnknown(struct OBJREF *o, struct IUnknown *p)
 
                        marshal = dcom_marshal_by_clsid(&o->u_objref.u_custom.clsid);
                        if (marshal) {
-                               return marshal(p, o);
+                               return marshal(mem_ctx, p, o);
                        } else {
                                return NT_STATUS_NOT_SUPPORTED;
                        }
@@ -527,15 +537,16 @@ NTSTATUS dcom_OBJREF_from_IUnknown(struct OBJREF *o, struct IUnknown *p)
        return NT_STATUS_OK;
 }
 
-NTSTATUS dcom_IUnknown_from_OBJREF(struct com_context *ctx, struct IUnknown **_p, struct OBJREF *o)
+enum ndr_err_code dcom_IUnknown_from_OBJREF(struct com_context *ctx, struct IUnknown **_p, struct OBJREF *o)
 {
        struct IUnknown *p;
        struct dcom_object_exporter *ox;
+       unmarshal_fn unmarshal;
 
        switch(o->flags) {
        case OBJREF_NULL: 
                *_p = NULL;
-               return NT_STATUS_OK;
+               return NDR_ERR_SUCCESS;
 
        case OBJREF_STANDARD:
                p = talloc_zero(ctx, struct IUnknown);
@@ -545,7 +556,7 @@ NTSTATUS dcom_IUnknown_from_OBJREF(struct com_context *ctx, struct IUnknown **_p
 
                if (!p->vtable) {
                        DEBUG(0, ("Unable to find proxy class for interface with IID %s\n", GUID_string(ctx, &o->iid)));
-                       return NT_STATUS_NOT_SUPPORTED;
+                       return NDR_ERR_INVALID_POINTER;
                }
 
                p->vtable->Release_send = dcom_release_send;
@@ -553,7 +564,7 @@ NTSTATUS dcom_IUnknown_from_OBJREF(struct com_context *ctx, struct IUnknown **_p
                ox = object_exporter_by_oxid(ctx, o->u_objref.u_standard.std.oxid);
                /* FIXME: Add object to list of objects to ping */
                *_p = p;
-               return NT_STATUS_OK;
+               return NDR_ERR_SUCCESS;
                
        case OBJREF_HANDLER:
                p = talloc_zero(ctx, struct IUnknown);
@@ -572,17 +583,16 @@ NTSTATUS dcom_IUnknown_from_OBJREF(struct com_context *ctx, struct IUnknown **_p
                p->ctx = ctx;   
                p->vtable = NULL;
                p->obj = *o;
-               unmarshal_fn unmarshal;
                unmarshal = dcom_unmarshal_by_clsid(&o->u_objref.u_custom.clsid);
                *_p = p;
                if (unmarshal) {
                    return unmarshal(ctx, o, _p);
                } else {
-                   return NT_STATUS_NOT_SUPPORTED;
+                   return NDR_ERR_BAD_SWITCH;
                }
        }
 
-       return NT_STATUS_NOT_SUPPORTED;
+       return NDR_ERR_BAD_SWITCH;
 }
 
 uint64_t dcom_get_current_oxid(void)