1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-29 21:47:30 +03:00
Jelmer Vernooij 80d3047333 r5490: The big (D)COM commit! :-) Contains most of the changes described in the
DCOM paper in lorikeet. This is the result of 1.5 months work (mainly
figuring out how things *really* work) at the end of 2004.

In general:
- Clearer distinction between COM and DCOM. DCOM is now merely
  the glue between DCE/RPC+ORPC and COM. COM can also work without
  DCOM now. This makes the code a lot clearer.
- Clearer distinction between NDR and DCOM. Before, NDR had a couple of
  "if"s to cope with DCOM, which are now gone.
- Use "real" arguments rather then structures for function arguments in
  COM, mainly because most of these calls are local so packing/unpacking
  data for every call is too much overhead (both speed- and code-wise)
- Support several mechanisms to load class objects:
  - from memory (e.g. part of the current executable, registered at start-up)
  - from shared object files
  - remotely
- Most things are now also named COM rather then DCOM because that's what it
  really is. After an object is created, it no longer matters whether it
  was created locally or remotely.

There is a very simple example class that contains
both a class factory and a class that implements the IStream interface.
It can be tested (locally only, remotely is broken at the moment)
by running the COM-SIMPLE smbtorture test.

Still to-do:
 - Autogenerate parts of the class implementation code (using the coclass definitions in IDL)
 - Test server-side
 - Implement some of the common classes, add definitions for common interfaces.
(This used to be commit 71fd3e5c3aac5f0002001ab29d2248e6c6842d6f)
2007-10-10 13:10:50 -05:00

86 lines
2.5 KiB
C

/*
Unix SMB/CIFS implementation.
Main COM functionality
Copyright (C) 2004 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 "dlinklist.h"
#include "lib/com/com.h"
#include "librpc/gen_ndr/com_dcom.h"
WERROR com_init(struct com_context **ctx)
{
*ctx = talloc(NULL, struct com_context);
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)
{
struct IUnknown *iunk = NULL;
struct IClassFactory *factory;
WERROR error;
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() */
error = IClassFactory_CreateInstance(factory, ctx, NULL, &classfact_iid, &iunk);
if (!W_ERROR_IS_OK(error)) {
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;
}
WERROR com_get_class_object(struct com_context *ctx, struct GUID *clsid, struct GUID *iid, struct IUnknown **ip)
{
struct IUnknown *iu;
iu = com_class_by_clsid(ctx, clsid);
if (!iu) {
return WERR_CLASS_NOT_REGISTERED;
}
return IUnknown_QueryInterface(iu, ctx, iid, ip);
}