2 Unix SMB/CIFS implementation.
4 Copyright (C) 2004 Jelmer Vernooij <jelmer@samba.org>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "dlinklist.h"
23 #include "lib/com/com.h"
24 #include "lib/events/events.h"
25 #include "librpc/gen_ndr/com_dcom.h"
26 #include "smb_build.h"
28 WERROR com_init_ctx(struct com_context **ctx, struct event_context *event_ctx)
30 *ctx = talloc(NULL, struct com_context);
31 if (event_ctx == NULL) {
32 event_ctx = event_context_init(*ctx);
34 (*ctx)->event_ctx = event_ctx;
38 WERROR com_create_object(struct com_context *ctx, struct GUID *clsid, int num_ifaces, struct GUID *iid, struct IUnknown **ip, WERROR *results)
40 struct IUnknown *iunk = NULL;
41 struct IClassFactory *factory;
44 struct GUID classfact_iid;
46 GUID_from_string(DCERPC_ICLASSFACTORY_UUID, &classfact_iid);
48 /* Obtain class object */
49 error = com_get_class_object(ctx, clsid, &classfact_iid, (struct IUnknown **)&factory);
50 if (!W_ERROR_IS_OK(error)) {
51 DEBUG(3, ("Unable to obtain class object for %s\n", GUID_string(NULL, clsid)));
55 /* Run IClassFactory::CreateInstance() */
56 error = IClassFactory_CreateInstance(factory, ctx, NULL, &classfact_iid, &iunk);
57 if (!W_ERROR_IS_OK(error)) {
58 DEBUG(3, ("Error while calling IClassFactory::CreateInstance : %s\n", win_errstr(error)));
63 DEBUG(0, ("IClassFactory_CreateInstance returned success but result pointer is still NULL!\n"));
64 return WERR_GENERAL_FAILURE;
67 /* Release class object */
68 IUnknown_Release(factory, ctx);
72 /* Do one or more QueryInterface calls */
73 for (i = 0; i < num_ifaces; i++) {
74 results[i] = IUnknown_QueryInterface(iunk, ctx, &iid[i], &ip[i]);
75 if (!W_ERROR_IS_OK(results[i])) error = results[i];
81 WERROR com_get_class_object(struct com_context *ctx, struct GUID *clsid, struct GUID *iid, struct IUnknown **ip)
85 iu = com_class_by_clsid(ctx, clsid);
87 return WERR_CLASS_NOT_REGISTERED;
90 return IUnknown_QueryInterface(iu, ctx, iid, ip);
93 NTSTATUS com_init(void)
95 init_module_fn static_init[] = STATIC_COM_MODULES;
96 init_module_fn *shared_init = load_samba_modules(NULL, "com");
98 run_init_functions(static_init);
99 run_init_functions(shared_init);
101 talloc_free(shared_init);