summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2008-09-14 16:39:57 +0200
committerJelmer Vernooij <jelmer@samba.org>2008-09-15 17:40:24 +0200
commit2fc75a6c4e930cee03ab53ab758b60fc4f9ff0f7 (patch)
tree3b6d68bb160b07e8a4d4d104ced1c8cb7a329a0b /source4
parent307f7d7d77abe1e76af074333d9527558a7e7ee1 (diff)
downloadsamba-2fc75a6c4e930cee03ab53ab758b60fc4f9ff0f7.tar.gz
samba-2fc75a6c4e930cee03ab53ab758b60fc4f9ff0f7.tar.bz2
samba-2fc75a6c4e930cee03ab53ab758b60fc4f9ff0f7.zip
Adapt to changes in Samba API's, fix formatting.
Diffstat (limited to 'source4')
-rw-r--r--source4/lib/wmi/tools/wmic.c27
-rw-r--r--source4/lib/wmi/tools/wmis.c32
-rw-r--r--source4/lib/wmi/wbemdata.c67
-rw-r--r--source4/lib/wmi/wmi.h3
-rw-r--r--source4/lib/wmi/wmicore.c19
5 files changed, 62 insertions, 86 deletions
diff --git a/source4/lib/wmi/tools/wmic.c b/source4/lib/wmi/tools/wmic.c
index 611a2dc36f..3d5d654eb8 100644
--- a/source4/lib/wmi/tools/wmic.c
+++ b/source4/lib/wmi/tools/wmic.c
@@ -1,6 +1,7 @@
/*
WMI Sample client
Copyright (C) 2006 Andrzej Hajda <andrzej.hajda@wp.pl>
+ Copyright (C) 2008 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
@@ -27,16 +28,12 @@
#include "librpc/gen_ndr/ndr_remact_c.h"
#include "librpc/gen_ndr/ndr_epmapper_c.h"
#include "librpc/gen_ndr/com_dcom.h"
-#include "librpc/rpc/dcerpc_table.h"
#include "lib/com/dcom/dcom.h"
#include "lib/com/proto.h"
#include "lib/com/dcom/proto.h"
-struct WBEMCLASS;
-struct WBEMOBJECT;
-
-#include "wmi/wmi.h"
+#include "lib/wmi/wmi.h"
struct program_args {
char *hostname;
@@ -164,23 +161,11 @@ int main(int argc, char **argv)
WERROR result;
NTSTATUS status;
struct IWbemServices *pWS = NULL;
+ struct BSTR queryLanguage, query;
parse_args(argc, argv, &args);
- dcerpc_init();
- dcerpc_table_init();
-
- dcom_proxy_IUnknown_init();
- dcom_proxy_IWbemLevel1Login_init();
- dcom_proxy_IWbemServices_init();
- dcom_proxy_IEnumWbemClassObject_init();
- dcom_proxy_IRemUnknown_init();
- dcom_proxy_IWbemFetchSmartEnum_init();
- dcom_proxy_IWbemWCOSmartEnum_init();
-
- struct com_context *ctx = NULL;
- com_init_ctx(&ctx, NULL);
- dcom_client_init(ctx, cmdline_credentials);
+ wmi_init(&ctx, cmdline_credentials);
if (!args.ns)
args.ns = "root\\cimv2";
@@ -188,7 +173,9 @@ int main(int argc, char **argv)
WERR_CHECK("Login to remote object.");
struct IEnumWbemClassObject *pEnum = NULL;
- result = IWbemServices_ExecQuery(pWS, ctx, "WQL", args.query, WBEM_FLAG_RETURN_IMMEDIATELY | WBEM_FLAG_ENSURE_LOCATABLE, NULL, &pEnum);
+ queryLanguage.data = "WQL";
+ query.data = args.query;
+ result = IWbemServices_ExecQuery(pWS, ctx, queryLanguage, query, WBEM_FLAG_RETURN_IMMEDIATELY | WBEM_FLAG_ENSURE_LOCATABLE, NULL, &pEnum);
WERR_CHECK("WMI query execute.");
IEnumWbemClassObject_Reset(pEnum, ctx);
diff --git a/source4/lib/wmi/tools/wmis.c b/source4/lib/wmi/tools/wmis.c
index 72ca4ebdfe..2b7abbb7bc 100644
--- a/source4/lib/wmi/tools/wmis.c
+++ b/source4/lib/wmi/tools/wmis.c
@@ -141,10 +141,13 @@ WERROR WBEM_RemoteExecute(struct IWbemServices *pWS, const char *cmdline, uint32
WERROR result;
union CIMVAR v;
TALLOC_CTX *ctx;
+ struct BSTR objectPath, methodName;
ctx = talloc_new(0);
- result = IWbemServices_GetObject(pWS, ctx, "Win32_Process",
+ objectPath.data = "Win32_Process";
+
+ result = IWbemServices_GetObject(pWS, ctx, objectPath,
WBEM_FLAG_RETURN_WBEM_COMPLETE, NULL, &wco, NULL);
WERR_CHECK("GetObject.");
@@ -158,7 +161,8 @@ WERROR WBEM_RemoteExecute(struct IWbemServices *pWS, const char *cmdline, uint32
result = IWbemClassObject_Put(in, ctx, "CommandLine", 0, &v, 0);
WERR_CHECK("IWbemClassObject_Put(CommandLine).");
- result = IWbemServices_ExecMethod(pWS, ctx, "Win32_Process", "Create", 0, NULL, in, &out,
+ methodName.data = "Create";
+ result = IWbemServices_ExecMethod(pWS, ctx, objectPath, methodName, 0, NULL, in, &out,
NULL);
WERR_CHECK("IWbemServices_ExecMethod.");
@@ -181,24 +185,12 @@ int main(int argc, char **argv)
struct IWbemServices *pWS = NULL;
struct IEnumWbemClassObject *pEnum = NULL;
uint32_t cnt;
+ struct BSTR queryLanguage;
+ struct BSTR query;
parse_args(argc, argv, &args);
- dcerpc_init();
- ndr_table_init();
-
- dcom_proxy_IUnknown_init();
- dcom_proxy_IWbemLevel1Login_init();
- dcom_proxy_IWbemServices_init();
- dcom_proxy_IEnumWbemClassObject_init();
- dcom_proxy_IRemUnknown_init();
- dcom_proxy_IWbemFetchSmartEnum_init();
- dcom_proxy_IWbemWCOSmartEnum_init();
- dcom_proxy_IWbemClassObject_init();
-
- com_init_ctx(&ctx, NULL);
- dcom_client_init(ctx, cmdline_credentials);
-
+ wmi_init(&ctx, cmdline_credentials);
result = WBEM_ConnectServer(ctx, args.hostname, "root\\cimv2", 0, 0, 0, 0, 0, 0, &pWS);
WERR_CHECK("WBEM_ConnectServer.");
@@ -208,8 +200,10 @@ int main(int argc, char **argv)
printf("2: ReturnCode: %d\n", cnt);
printf("3: Monitoring directory C:\\wmi_test_dir_tmp. Please create/delete files in that directory to see notifications, after 4 events program quits.\n");
- result = IWbemServices_ExecNotificationQuery(pWS, ctx, "WQL",
- "SELECT * FROM __InstanceOperationEvent WITHIN 1 WHERE Targetinstance ISA 'CIM_DirectoryContainsFile' and TargetInstance.GroupComponent= 'Win32_Directory.Name=\"C:\\\\\\\\wmi_test_dir_tmp\"'", WBEM_FLAG_RETURN_IMMEDIATELY | WBEM_FLAG_FORWARD_ONLY, NULL, &pEnum);
+ query.data = "SELECT * FROM __InstanceOperationEvent WITHIN 1 WHERE Targetinstance ISA 'CIM_DirectoryContainsFile' and TargetInstance.GroupComponent= 'Win32_Directory.Name=\"C:\\\\\\\\wmi_test_dir_tmp\"'";
+ queryLanguage.data = "WQL";
+ result = IWbemServices_ExecNotificationQuery(pWS, ctx, queryLanguage,
+ query, WBEM_FLAG_RETURN_IMMEDIATELY | WBEM_FLAG_FORWARD_ONLY, NULL, &pEnum);
WERR_CHECK("WMI query execute.");
for (cnt = 0; cnt < 4; ++cnt) {
struct WbemClassObject *co;
diff --git a/source4/lib/wmi/wbemdata.c b/source4/lib/wmi/wbemdata.c
index ffe1bf6648..b973e1555d 100644
--- a/source4/lib/wmi/wbemdata.c
+++ b/source4/lib/wmi/wbemdata.c
@@ -31,7 +31,7 @@
#include "librpc/gen_ndr/ndr_misc.h"
#include "lib/talloc/talloc.h"
#include "libcli/composite/composite.h"
-#include "wmi/proto.h"
+#include "lib/wmi/wmi.h"
NTSTATUS ndr_pull_WbemClassObject_Object(struct ndr_pull *ndr, int ndr_flags, struct WbemClassObject *r);
void duplicate_CIMVAR(TALLOC_CTX *mem_ctx, const union CIMVAR *src, union CIMVAR *dst, enum CIMTYPE_ENUMERATION cimtype);
@@ -54,8 +54,6 @@ void duplicate_WbemClassObject(TALLOC_CTX *mem_ctx, const struct WbemClassObject
#define NDR_CHECK_CONST(val, exp) NDR_CHECK_EXPR((val) == (exp))
#define NDR_CHECK_RSTRING(rstring) NDR_CHECK_EXPR((rstring) >= 0)
-#define NTERR_CHECK(call) status = call; if (!NT_STATUS_IS_OK(status)) goto end;
-
enum {
DATATYPE_CLASSOBJECT = 2,
DATATYPE_OBJECT = 3,
@@ -63,17 +61,14 @@ enum {
COFLAG_IS_CLASS = 4,
};
-static NTSTATUS marshal(struct IUnknown *pv, struct OBJREF *o)
+static enum ndr_err_code marshal(TALLOC_CTX *mem_ctx, struct IUnknown *pv, struct OBJREF *o)
{
struct ndr_push *ndr;
- NTSTATUS status;
struct WbemClassObject *wco;
- TALLOC_CTX *mem_ctx;
struct MInterfacePointer *mp;
mp = (struct MInterfacePointer *)((char *)o - offsetof(struct MInterfacePointer, obj)); // FIXME:high remove this Mumbo Jumbo
wco = pv->object_data;
- mem_ctx = talloc_new(0);
ndr = talloc_zero(mem_ctx, struct ndr_push);
ndr->flags = 0;
ndr->alloc_size = 1024;
@@ -81,15 +76,15 @@ static NTSTATUS marshal(struct IUnknown *pv, struct OBJREF *o)
if (wco) {
uint32_t ofs;
- NTERR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, 0x12345678));
- NTERR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, 0));
- NTERR_CHECK(ndr_push_WbemClassObject(ndr, NDR_SCALARS | NDR_BUFFERS, wco));
+ NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, 0x12345678));
+ NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, 0));
+ NDR_CHECK(ndr_push_WbemClassObject(ndr, NDR_SCALARS | NDR_BUFFERS, wco));
ofs = ndr->offset;
ndr->offset = 4;
- NTERR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, ofs - 8));
+ NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, ofs - 8));
ndr->offset = ofs;
} else {
- NTERR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, 0));
+ NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, 0));
}
o->u_objref.u_custom.pData = talloc_realloc(mp, ndr->data, uint8_t, ndr->offset);
o->u_objref.u_custom.size = ndr->offset;
@@ -97,17 +92,14 @@ static NTSTATUS marshal(struct IUnknown *pv, struct OBJREF *o)
if (DEBUGLVL(9)) {
NDR_PRINT_DEBUG(WbemClassObject, wco);
}
-end:
- talloc_free(mem_ctx);
- return status;
+ return NDR_ERR_SUCCESS;
}
-static NTSTATUS unmarshal(struct OBJREF *o, struct IUnknown **pv)
+static enum ndr_err_code unmarshal(TALLOC_CTX *mem_ctx, struct OBJREF *o, struct IUnknown **pv)
{
struct ndr_pull *ndr;
- TALLOC_CTX *mem_ctx;
struct WbemClassObject *wco;
- NTSTATUS status;
+ enum ndr_err_code ndr_err;
uint32_t u;
mem_ctx = talloc_new(0);
@@ -116,42 +108,37 @@ static NTSTATUS unmarshal(struct OBJREF *o, struct IUnknown **pv)
ndr->data = o->u_objref.u_custom.pData;
ndr->data_size = o->u_objref.u_custom.size;
- NTERR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &u));
+ NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &u));
if (!u) {
talloc_free(*pv);
*pv = NULL;
- status = NT_STATUS_OK;
- goto end;
+ return NDR_ERR_SUCCESS;
}
- NTERR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &u));
+ NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &u));
if (u + 8 > ndr->data_size) {
DEBUG(1, ("unmarshall_IWbemClassObject: Incorrect data_size"));
- status = NT_STATUS_BUFFER_TOO_SMALL;
- goto end;
+ return NDR_ERR_BUFSIZE;
}
wco = talloc_zero(*pv, struct WbemClassObject);
ndr->current_mem_ctx = wco;
- status = ndr_pull_WbemClassObject(ndr, NDR_SCALARS | NDR_BUFFERS, wco);
+ ndr_err = ndr_pull_WbemClassObject(ndr, NDR_SCALARS | NDR_BUFFERS, wco);
- if (NT_STATUS_IS_OK(status) && (DEBUGLVL(9))) {
+ if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLVL(9))) {
NDR_PRINT_DEBUG(WbemClassObject, wco);
}
- if (NT_STATUS_IS_OK(status)) {
+ if (NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
(*pv)->object_data = wco;
} else {
talloc_free(wco);
}
-end:
- talloc_free(mem_ctx);
- return status;
+ return NDR_ERR_SUCCESS;
}
WERROR dcom_IWbemClassObject_from_WbemClassObject(struct com_context *ctx, struct IWbemClassObject **_p, struct WbemClassObject *wco)
{
struct IWbemClassObject *p;
-
p = talloc_zero(ctx, struct IWbemClassObject);
p->ctx = ctx;
p->obj.signature = 0x574f454d;
@@ -490,20 +477,18 @@ struct IEnumWbemClassObject_data {
struct pair_guid_ptr *cache;
};
-static NTSTATUS WBEMDATA_Parse(uint8_t *data, uint32_t size, struct IEnumWbemClassObject *d, uint32_t uCount, struct WbemClassObject **apObjects)
+static enum ndr_err_code WBEMDATA_Parse(TALLOC_CTX *mem_ctx, uint8_t *data, uint32_t size, struct IEnumWbemClassObject *d, uint32_t uCount, struct WbemClassObject **apObjects)
{
struct ndr_pull *ndr;
- TALLOC_CTX *mem_ctx;
uint32_t u, i, ofs_next;
uint8_t u8, datatype;
NTSTATUS status;
struct GUID guid;
struct IEnumWbemClassObject_data *ecod;
- if (!uCount) return NT_STATUS_NOT_IMPLEMENTED;
+ if (!uCount) return NDR_ERR_BAD_SWITCH;
ecod = d->object_data;
- mem_ctx = talloc_new(0);
ndr = talloc_zero(mem_ctx, struct ndr_pull);
ndr->current_mem_ctx = d->ctx;
@@ -568,18 +553,14 @@ static NTSTATUS WBEMDATA_Parse(uint8_t *data, uint32_t size, struct IEnumWbemCla
break;
default:
DEBUG(0, ("WBEMDATA_Parse: Data type %d not supported\n", datatype));
- status = NT_STATUS_NOT_SUPPORTED;
- goto end;
+ return NDR_ERR_BAD_SWITCH;
}
ndr->offset = ofs_next;
if (DEBUGLVL(9)) {
NDR_PRINT_DEBUG(WbemClassObject, apObjects[i]);
}
}
- status = NT_STATUS_OK;
-end:
- talloc_free(mem_ctx);
- return status;
+ return NDR_ERR_SUCCESS;
}
struct composite_context *dcom_proxy_IEnumWbemClassObject_Release_send(struct IUnknown *d, TALLOC_CTX *mem_ctx);
@@ -619,9 +600,7 @@ WERROR IEnumWbemClassObject_SmartNext(struct IEnumWbemClassObject *d, TALLOC_CTX
}
if (data) {
- status = WBEMDATA_Parse(data, size, d, *puReturned, apObjects);
- result = ntstatus_to_werror(status);
- WERR_CHECK("WBEMDATA_Parse.");
+ NDR_CHECK(WBEMDATA_Parse(mem_ctx, data, size, d, *puReturned, apObjects));
}
end:
if (!W_ERROR_IS_OK(result)) {
diff --git a/source4/lib/wmi/wmi.h b/source4/lib/wmi/wmi.h
index 32cc88efd5..085e01215f 100644
--- a/source4/lib/wmi/wmi.h
+++ b/source4/lib/wmi/wmi.h
@@ -52,6 +52,7 @@ WERROR WbemClassObject_Get(struct WbemClassObject *d, TALLOC_CTX *mem_ctx, const
WERROR IWbemClassObject_Put(struct IWbemClassObject *d, TALLOC_CTX *mem_ctx, const char *name, uint32_t flags, union CIMVAR *val, enum CIMTYPE_ENUMERATION cimtype);
WERROR IEnumWbemClassObject_SmartNext(struct IEnumWbemClassObject *d, TALLOC_CTX *mem_ctx, int32_t lTimeout, uint32_t uCount, struct WbemClassObject **apObjects, uint32_t *puReturned);
struct composite_context *dcom_proxy_IEnumWbemClassObject_Release_send(struct IUnknown *d, TALLOC_CTX *mem_ctx);
-NTSTATUS dcom_proxy_IWbemClassObject_init(void);
+
+void wmi_init(struct com_context **ctx, struct cli_credentials *credentials);
#endif
diff --git a/source4/lib/wmi/wmicore.c b/source4/lib/wmi/wmicore.c
index cdfe037b69..fbd6b339bf 100644
--- a/source4/lib/wmi/wmicore.c
+++ b/source4/lib/wmi/wmicore.c
@@ -24,6 +24,9 @@
#include "lib/com/dcom/dcom.h"
#include "librpc/gen_ndr/wmi.h"
#include "librpc/gen_ndr/com_wmi.h"
+#include "librpc/rpc/dcerpc.h"
+#include "librpc/ndr/ndr_table.h"
+#include "param/param.h"
struct IWbemServices;
struct IWbemContext;
@@ -34,8 +37,20 @@ struct IWbemContext;
} else { \
DEBUG(1, ("OK : %s\n", msg)); \
}
+
+void wmi_init(struct com_context **ctx, struct cli_credentials *credentials)
+{
+ dcerpc_init();
+ ndr_table_init();
+
+ /* FIXME: Register DCOM proxies? */
+
+ com_init_ctx(ctx, NULL);
+ dcom_client_init(*ctx, credentials);
+}
+
/** FIXME: Use credentials struct rather than user/password here */
-WERROR WBEM_ConnectServer(struct com_context *ctx, const char *server, const char *nspace,
+WERROR WBEM_ConnectServer(struct com_context *ctx, const char *server, const uint16_t *nspace,
const char *user, const char *password,
const char *locale, uint32_t flags, const char *authority,
struct IWbemContext* wbem_ctx, struct IWbemServices** services)
@@ -52,7 +67,7 @@ WERROR WBEM_ConnectServer(struct com_context *ctx, const char *server, const cha
cred = talloc_asprintf(NULL, "%s%%%s", user, password);
cc = cli_credentials_init(cred);
- cli_credentials_set_conf(cc);
+ cli_credentials_set_conf(cc, global_loadparm);
cli_credentials_parse_string(cc, cred, CRED_SPECIFIED);
dcom_set_server_credentials(ctx, server, cc);
talloc_free(cred);