wmi-1.3.16 from opsview.com
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
This directory contains Samba's very simple COM implementation.
|
||||
It is by no means finished yet.
|
||||
|
||||
The main aim of this implementation is for use by our DCOM implementation,
|
||||
which lives in the dcom subdirectory. The local version is used mostly for
|
||||
testing.
|
||||
|
||||
More information on this effort can be found in the DCOM whitepaper in
|
||||
the lorikeet repository.
|
||||
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
Unix SMB/CIFS implementation.
|
||||
Simple class
|
||||
Copyright (C) 2004-2005 Jelmer Vernooij <jelmer@samba.org>
|
||||
|
||||
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/com/com.h"
|
||||
#include "librpc/gen_ndr/com_dcom.h"
|
||||
|
||||
static struct IClassFactory_vtable simple_classobject_vtable;
|
||||
static struct IStream_vtable simple_IStream_vtable;
|
||||
|
||||
static WERROR simple_IUnknown_QueryInterface (struct IUnknown *d, TALLOC_CTX *mem_ctx, struct GUID *iid, struct IUnknown **iun)
|
||||
{
|
||||
*iun = d;
|
||||
return WERR_OK;
|
||||
}
|
||||
|
||||
static uint32_t simple_IUnknown_AddRef (struct IUnknown *d, TALLOC_CTX *mem_ctx)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
static uint32_t simple_IUnknown_Release (struct IUnknown *d, TALLOC_CTX *mem_ctx)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
static WERROR simple_IStream_Read (struct IStream *d, TALLOC_CTX *mem_ctx, uint8_t *pv, uint32_t num_requested, uint32_t *num_readx, uint32_t num_read)
|
||||
{
|
||||
printf("%d bytes are being read\n", num_read);
|
||||
return WERR_OK;
|
||||
}
|
||||
|
||||
static WERROR simple_IStream_Write (struct IStream *d, TALLOC_CTX *mem_ctx, uint8_t *data, uint32_t num_requested, uint32_t num_written)
|
||||
{
|
||||
printf("%d bytes are being written\n", num_requested);
|
||||
return WERR_OK;
|
||||
}
|
||||
|
||||
static WERROR simpleclass_IUnknown_QueryInterface (struct IUnknown *d, TALLOC_CTX *mem_ctx, struct GUID *iid, struct IUnknown **iun)
|
||||
{
|
||||
/* FIXME: Return WERR_IFACE_NOT_SUPPORTED if IID != IID_IUNKNOWN and IID != IID_CLASSFACTORY */
|
||||
*iun = d;
|
||||
return WERR_OK;
|
||||
}
|
||||
|
||||
static WERROR simpleclass_IClassFactory_CreateInstance (struct IClassFactory *d, TALLOC_CTX *mem_ctx, struct IUnknown *iunk, struct GUID *iid, struct IUnknown **ppv)
|
||||
{
|
||||
struct IStream *ret;
|
||||
/* FIXME: Check whether IID == ISTREAM_IID */
|
||||
ret = talloc(mem_ctx, struct IStream);
|
||||
ret->ctx = NULL;
|
||||
ret->vtable = &simple_IStream_vtable;
|
||||
ret->object_data = NULL;
|
||||
|
||||
*ppv = (struct IUnknown *)ret;
|
||||
|
||||
return WERR_OK;
|
||||
}
|
||||
|
||||
static uint32_t simpleclass_IUnknown_AddRef (struct IUnknown *d, TALLOC_CTX *mem_ctx)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
static uint32_t simpleclass_IUnknown_Release (struct IUnknown *d, TALLOC_CTX *mem_ctx)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Everything below this line should be autogenerated later on */
|
||||
static struct IClassFactory_vtable simple_classobject_vtable = {
|
||||
{ 0, 0, 0, { 0, 0 }, { 0, 0, 0, 0, 0, 0 } },
|
||||
simpleclass_IUnknown_QueryInterface,
|
||||
simpleclass_IUnknown_AddRef,
|
||||
simpleclass_IUnknown_Release,
|
||||
simpleclass_IClassFactory_CreateInstance,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
static struct IStream_vtable simple_IStream_vtable = {
|
||||
{ 0, 0, 0, { 0, 0 }, { 0, 0, 0, 0, 0, 0 } },
|
||||
simple_IUnknown_QueryInterface,
|
||||
simple_IUnknown_AddRef,
|
||||
simple_IUnknown_Release,
|
||||
simple_IStream_Read,
|
||||
simple_IStream_Write
|
||||
};
|
||||
|
||||
NTSTATUS com_simple_init(void)
|
||||
{
|
||||
struct GUID clsid;
|
||||
struct IUnknown *class_object = talloc(talloc_autofree_context(), struct IUnknown);
|
||||
|
||||
class_object->ctx = NULL;
|
||||
class_object->object_data = NULL;
|
||||
class_object->vtable = (struct IUnknown_vtable *)&simple_classobject_vtable;
|
||||
|
||||
GUID_from_string(CLSID_SIMPLE, &clsid);
|
||||
GUID_from_string(COM_ICLASSFACTORY_UUID, &simple_classobject_vtable.iid);
|
||||
GUID_from_string(COM_ISTREAM_UUID, &simple_IStream_vtable.iid);
|
||||
|
||||
return com_register_running_class(&clsid, PROGID_SIMPLE, class_object);
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
Unix SMB/CIFS implementation.
|
||||
COM standard objects
|
||||
Copyright (C) Jelmer Vernooij 2004-2005.
|
||||
Copyright (C) 2006 Andrzej Hajda <andrzej.hajda@wp.pl>
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef _COM_H /* _COM_H */
|
||||
#define _COM_H
|
||||
|
||||
struct IUnknown_vtable;
|
||||
|
||||
enum {
|
||||
COM_EXT_WMI_CLASS_CACHE = 1
|
||||
};
|
||||
|
||||
struct com_context
|
||||
{
|
||||
struct dcom_client_context *dcom;
|
||||
struct event_context *event_ctx;
|
||||
struct com_extension {
|
||||
uint32_t id;
|
||||
void *data;
|
||||
struct com_extension *prev, *next;
|
||||
} *extensions;
|
||||
};
|
||||
|
||||
typedef struct IUnknown *(*get_class_object_function) (const struct GUID *clsid);
|
||||
|
||||
|
||||
#include "lib/com/proto.h"
|
||||
|
||||
#endif /* _COM_H */
|
||||
@@ -0,0 +1,23 @@
|
||||
[LIBRARY::com]
|
||||
VERSION = 0.0.1
|
||||
SO_VERSION = 0
|
||||
PRIVATE_PROTO_HEADER = proto.h
|
||||
OBJ_FILES = \
|
||||
tables.o \
|
||||
rot.o \
|
||||
main.o
|
||||
|
||||
[LIBRARY::dcom]
|
||||
VERSION = 0.0.1
|
||||
SO_VERSION = 0
|
||||
PRIVATE_PROTO_HEADER = dcom/proto.h
|
||||
OBJ_FILES = \
|
||||
dcom/main.o \
|
||||
dcom/tables.o
|
||||
PUBLIC_DEPENDENCIES = com DCOM_PROXY_DCOM RPC_NDR_REMACT \
|
||||
RPC_NDR_OXIDRESOLVER
|
||||
|
||||
[MODULE::com_simple]
|
||||
SUBSYSTEM = com
|
||||
OBJ_FILES = classes/simple.o
|
||||
INIT_FUNCTION = com_simple_init
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
Unix SMB/CIFS implementation.
|
||||
COM standard objects
|
||||
Copyright (C) Jelmer Vernooij 2004-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.
|
||||
*/
|
||||
|
||||
#ifndef _DCOM_H /* _DCOM_H */
|
||||
#define _DCOM_H
|
||||
|
||||
struct cli_credentials;
|
||||
struct dcerpc_pipe;
|
||||
struct IRemUnknown;
|
||||
struct rpc_request;
|
||||
|
||||
#include "lib/com/com.h"
|
||||
#include "librpc/gen_ndr/orpc.h"
|
||||
|
||||
#define NT_STATUS_RPC_NT_CALL_FAILED NT_STATUS(0xC002001BL)
|
||||
|
||||
typedef NTSTATUS (*marshal_fn)(struct IUnknown *pv, struct OBJREF *o);
|
||||
typedef NTSTATUS (*unmarshal_fn)(struct OBJREF *o, struct IUnknown **pv);
|
||||
|
||||
#include "lib/com/dcom/proto.h"
|
||||
|
||||
struct dcom_client_context {
|
||||
struct dcom_server_credentials {
|
||||
const char *server;
|
||||
struct cli_credentials *credentials;
|
||||
struct dcom_server_credentials *prev, *next;
|
||||
} *credentials;
|
||||
struct dcom_object_exporter {
|
||||
uint64_t oxid;
|
||||
char *host;
|
||||
struct IRemUnknown *rem_unknown;
|
||||
struct DUALSTRINGARRAY *bindings;
|
||||
struct dcerpc_pipe *pipe;
|
||||
struct dcom_object_exporter *prev, *next;
|
||||
} *object_exporters;
|
||||
};
|
||||
|
||||
struct dcom_proxy_async_call_state {
|
||||
struct IUnknown *d;
|
||||
const struct dcerpc_interface_table *table;
|
||||
uint32_t opnum;
|
||||
void (*continuation)(struct rpc_request *);
|
||||
TALLOC_CTX *mem_ctx;
|
||||
void *r;
|
||||
};
|
||||
|
||||
#define WERR_NDR_CHECK(call) do { NTSTATUS _status; \
|
||||
_status = call; \
|
||||
if (!NT_STATUS_IS_OK(_status)) \
|
||||
return ntstatus_to_werror(_status); \
|
||||
} while (0)
|
||||
|
||||
#define IUnknown_ipid(d) ((d)->obj.u_objref.u_standard.std.ipid)
|
||||
|
||||
#endif /* _DCOM_H */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
Unix SMB/CIFS implementation.
|
||||
DCOM proxy tables functionality
|
||||
Copyright (C) 2005 Jelmer Vernooij <jelmer@samba.org>
|
||||
Copyright (C) 2006 Andrzej Hajda <andrzej.hajda@wp.pl>
|
||||
|
||||
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/util/dlinklist.h"
|
||||
#include "librpc/gen_ndr/com_dcom.h"
|
||||
#include "lib/com/dcom/dcom.h"
|
||||
|
||||
static struct dcom_proxy {
|
||||
struct IUnknown_vtable *vtable;
|
||||
struct dcom_proxy *prev, *next;
|
||||
} *proxies = NULL;
|
||||
|
||||
NTSTATUS dcom_register_proxy(struct IUnknown_vtable *proxy_vtable)
|
||||
{
|
||||
struct dcom_proxy *proxy = talloc(talloc_autofree_context(), struct dcom_proxy);
|
||||
|
||||
proxy->vtable = proxy_vtable;
|
||||
DLIST_ADD(proxies, proxy);
|
||||
|
||||
return NT_STATUS_OK;
|
||||
}
|
||||
|
||||
struct IUnknown_vtable *dcom_proxy_vtable_by_iid(struct GUID *iid)
|
||||
{
|
||||
struct dcom_proxy *p;
|
||||
for (p = proxies; p; p = p->next) {
|
||||
if (GUID_equal(&p->vtable->iid, iid)) {
|
||||
return p->vtable;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static struct dcom_marshal {
|
||||
struct GUID clsid;
|
||||
marshal_fn marshal;
|
||||
unmarshal_fn unmarshal;
|
||||
struct dcom_marshal *prev, *next;
|
||||
} *marshals = NULL;
|
||||
|
||||
NTSTATUS dcom_register_marshal(struct GUID *clsid, marshal_fn marshal, unmarshal_fn unmarshal)
|
||||
{
|
||||
struct dcom_marshal *p = talloc(talloc_autofree_context(), struct dcom_marshal);
|
||||
|
||||
p->clsid = *clsid;
|
||||
p->marshal = marshal;
|
||||
p->unmarshal = unmarshal;
|
||||
DLIST_ADD(marshals, p);
|
||||
return NT_STATUS_OK;
|
||||
}
|
||||
|
||||
_PUBLIC_ marshal_fn dcom_marshal_by_clsid(struct GUID *clsid)
|
||||
{
|
||||
struct dcom_marshal *p;
|
||||
for (p = marshals; p; p = p->next) {
|
||||
if (GUID_equal(&p->clsid, clsid)) {
|
||||
return p->marshal;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
_PUBLIC_ unmarshal_fn dcom_unmarshal_by_clsid(struct GUID *clsid)
|
||||
{
|
||||
struct dcom_marshal *p;
|
||||
for (p = marshals; p; p = p->next) {
|
||||
if (GUID_equal(&p->clsid, clsid)) {
|
||||
return p->unmarshal;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
/*
|
||||
Unix SMB/CIFS implementation.
|
||||
Main COM functionality
|
||||
Copyright (C) 2004 Jelmer Vernooij <jelmer@samba.org>
|
||||
Copyright (C) 2006 Andrzej Hajda <andrzej.hajda@wp.pl>
|
||||
|
||||
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/util/dlinklist.h"
|
||||
#include "lib/com/com.h"
|
||||
#include "lib/events/events.h"
|
||||
#include "librpc/gen_ndr/com_dcom.h"
|
||||
#include "build.h"
|
||||
|
||||
WERROR com_init_ctx(struct com_context **ctx, struct event_context *event_ctx)
|
||||
{
|
||||
*ctx = talloc_zero(NULL, struct com_context);
|
||||
if (event_ctx == NULL) {
|
||||
event_ctx = event_context_init(*ctx);
|
||||
}
|
||||
(*ctx)->event_ctx = event_ctx;
|
||||
return WERR_OK;
|
||||
}
|
||||
|
||||
WERROR com_create_object(struct com_context *ctx, struct GUID *clsid, int num_ifaces, struct GUID *iid, struct IUnknown **ip, WERROR *results)
|
||||
{
|
||||
return WERR_NOT_SUPPORTED;
|
||||
#if 0
|
||||
struct IUnknown *iunk = NULL;
|
||||
struct IClassFactory *factory;
|
||||
WERROR error;
|
||||
NTSTATUS status;
|
||||
int i;
|
||||
struct GUID classfact_iid;
|
||||
|
||||
GUID_from_string(DCERPC_ICLASSFACTORY_UUID, &classfact_iid);
|
||||
|
||||
/* Obtain class object */
|
||||
error = com_get_class_object(ctx, clsid, &classfact_iid, (struct IUnknown **)(&factory));
|
||||
if (!W_ERROR_IS_OK(error)) {
|
||||
DEBUG(3, ("Unable to obtain class object for %s\n", GUID_string(NULL, clsid)));
|
||||
return error;
|
||||
}
|
||||
|
||||
/* Run IClassFactory::CreateInstance() */
|
||||
status = IClassFactory_CreateInstance(factory, ctx, NULL, &classfact_iid, &iunk);
|
||||
if (!NT_STATUS_IS_OK(status)) {
|
||||
DEBUG(3, ("Error while calling IClassFactory::CreateInstance : %s\n", win_errstr(error)));
|
||||
return error;
|
||||
}
|
||||
|
||||
if (!iunk) {
|
||||
DEBUG(0, ("IClassFactory_CreateInstance returned success but result pointer is still NULL!\n"));
|
||||
return WERR_GENERAL_FAILURE;
|
||||
}
|
||||
|
||||
/* Release class object */
|
||||
IUnknown_Release(factory, ctx);
|
||||
|
||||
error = WERR_OK;
|
||||
|
||||
/* Do one or more QueryInterface calls */
|
||||
for (i = 0; i < num_ifaces; i++) {
|
||||
results[i] = IUnknown_QueryInterface(iunk, ctx, &iid[i], &ip[i]);
|
||||
if (!W_ERROR_IS_OK(results[i])) error = results[i];
|
||||
}
|
||||
|
||||
return error;
|
||||
#endif
|
||||
}
|
||||
|
||||
WERROR com_get_class_object(struct com_context *ctx, struct GUID *clsid, struct GUID *iid, struct IUnknown **ip)
|
||||
{
|
||||
return WERR_NOT_SUPPORTED;
|
||||
#if 0
|
||||
struct IUnknown *iu;
|
||||
|
||||
iu = com_class_by_clsid(ctx, clsid);
|
||||
if (!iu) {
|
||||
return WERR_CLASS_NOT_REGISTERED;
|
||||
}
|
||||
|
||||
return IUnknown_QueryInterface(iu, ctx, iid, ip);
|
||||
#endif
|
||||
}
|
||||
|
||||
void *com_extension_by_id(struct com_context *ctx, uint32_t id)
|
||||
{
|
||||
struct com_extension *ce;
|
||||
for (ce = ctx->extensions; ce; ce = ce->next) {
|
||||
if (ce->id == id) {
|
||||
return ce->data;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void com_extension_set(struct com_context *ctx, uint32_t id, void *data)
|
||||
{
|
||||
struct com_extension *ce;
|
||||
for (ce = ctx->extensions; ce; ce = ce->next) {
|
||||
if (ce->id == id) {
|
||||
talloc_free(ce->data);
|
||||
}
|
||||
}
|
||||
if (!ce) {
|
||||
ce = talloc(ctx, struct com_extension);
|
||||
ce->id = id;
|
||||
DLIST_ADD(ctx->extensions, ce);
|
||||
}
|
||||
ce->data = data;
|
||||
}
|
||||
|
||||
NTSTATUS com_init(void)
|
||||
{
|
||||
static BOOL initialized = False;
|
||||
|
||||
init_module_fn static_init[] = STATIC_com_MODULES;
|
||||
init_module_fn *shared_init;
|
||||
|
||||
if (initialized) return NT_STATUS_OK;
|
||||
initialized = True;
|
||||
|
||||
shared_init = load_samba_modules(NULL, "com");
|
||||
|
||||
run_init_functions(static_init);
|
||||
run_init_functions(shared_init);
|
||||
|
||||
talloc_free(shared_init);
|
||||
|
||||
return NT_STATUS_OK;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
Unix SMB/CIFS implementation.
|
||||
|
||||
Running object table functions
|
||||
|
||||
Copyright (C) Jelmer Vernooij 2004-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"
|
||||
|
||||
struct dcom_interface_p *dcom_get_local_iface_p(struct GUID *ipid)
|
||||
{
|
||||
/* FIXME: Call the local ROT and do a
|
||||
* rot_get_interface_pointer call */
|
||||
|
||||
/* FIXME: Perhaps have a local (thread-local) table with
|
||||
* local DCOM objects so that not every DCOM call requires a lookup
|
||||
* to the ROT? */
|
||||
return NULL;
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
Unix SMB/CIFS implementation.
|
||||
COM class tables
|
||||
Copyright (C) 2004 Jelmer Vernooij <jelmer@samba.org>
|
||||
Copyright (C) 2006 Andrzej Hajda <andrzej.hajda@wp.pl>
|
||||
|
||||
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/util/dlinklist.h"
|
||||
#include "lib/com/com.h"
|
||||
#include "librpc/gen_ndr/ndr_misc.h"
|
||||
|
||||
/* Specific implementation of one or more interfaces */
|
||||
struct com_class
|
||||
{
|
||||
const char *progid;
|
||||
struct GUID clsid;
|
||||
|
||||
struct IUnknown *class_object;
|
||||
struct com_class *prev, *next;
|
||||
} * running_classes = NULL;
|
||||
|
||||
static struct IUnknown *get_com_class_running(const struct GUID *clsid)
|
||||
{
|
||||
struct com_class *c = running_classes;
|
||||
|
||||
while(c) {
|
||||
|
||||
if (GUID_equal(clsid, &c->clsid)) {
|
||||
return c->class_object;
|
||||
}
|
||||
|
||||
c = c->next;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static struct IUnknown *get_com_class_so(TALLOC_CTX *mem_ctx, const struct GUID *clsid)
|
||||
{
|
||||
char *mod_name;
|
||||
char *clsid_str;
|
||||
void *mod;
|
||||
get_class_object_function f;
|
||||
|
||||
clsid_str = GUID_string(mem_ctx, clsid);
|
||||
mod_name = talloc_asprintf(mem_ctx, "%s.so", clsid_str);
|
||||
talloc_free(clsid_str);
|
||||
|
||||
mod = dlopen(mod_name, 0);
|
||||
|
||||
if (!mod) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
f = dlsym(mod, "get_class_object");
|
||||
|
||||
if (!f) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return f(clsid);
|
||||
}
|
||||
|
||||
struct IUnknown *com_class_by_clsid(struct com_context *ctx, const struct GUID *clsid)
|
||||
{
|
||||
struct IUnknown *c;
|
||||
|
||||
/* Check list of running COM classes first */
|
||||
c = get_com_class_running(clsid);
|
||||
|
||||
if (c != NULL) {
|
||||
return c;
|
||||
}
|
||||
|
||||
c = get_com_class_so(ctx, clsid);
|
||||
|
||||
if (c != NULL) {
|
||||
return c;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
NTSTATUS com_register_running_class(struct GUID *clsid, const char *progid, struct IUnknown *p)
|
||||
{
|
||||
struct com_class *l = talloc_zero(running_classes?running_classes:talloc_autofree_context(), struct com_class);
|
||||
|
||||
l->clsid = *clsid;
|
||||
l->progid = talloc_strdup(l, progid);
|
||||
l->class_object = p;
|
||||
|
||||
DLIST_ADD(running_classes, l);
|
||||
|
||||
return NT_STATUS_OK;
|
||||
}
|
||||
Reference in New Issue
Block a user