summaryrefslogtreecommitdiff
path: root/source4/lib/wmi
diff options
context:
space:
mode:
Diffstat (limited to 'source4/lib/wmi')
-rw-r--r--source4/lib/wmi/tools/wmic.c82
-rw-r--r--source4/lib/wmi/tools/wmis.c12
-rw-r--r--source4/lib/wmi/wbemdata.c117
3 files changed, 104 insertions, 107 deletions
diff --git a/source4/lib/wmi/tools/wmic.c b/source4/lib/wmi/tools/wmic.c
index dc33d71ad1..4b84c27c8d 100644
--- a/source4/lib/wmi/tools/wmic.c
+++ b/source4/lib/wmi/tools/wmic.c
@@ -54,8 +54,8 @@ static void parse_args(int argc, char *argv[], struct program_args *pmyargs)
POPT_COMMON_CONNECTION
POPT_COMMON_CREDENTIALS
POPT_COMMON_VERSION
- {"namespace", 0, POPT_ARG_STRING, &pmyargs->ns, 0,
- "WMI namespace, default to root\\cimv2", 0},
+ {"namespace", 0, POPT_ARG_STRING, &pmyargs->ns, 0,
+ "WMI namespace, default to root\\cimv2", 0},
POPT_TABLEEND
};
@@ -81,7 +81,7 @@ static void parse_args(int argc, char *argv[], struct program_args *pmyargs)
}
if (argc_new != 3 || argv_new[1][0] != '/'
- || argv_new[1][1] != '/') {
+ || argv_new[1][1] != '/') {
poptPrintUsage(pc, stdout, 0);
poptFreeContext(pc);
exit(1);
@@ -100,52 +100,52 @@ static void parse_args(int argc, char *argv[], struct program_args *pmyargs)
}
#define RETURN_CVAR_ARRAY_STR(fmt, arr) {\
- uint32_t i;\
+ uint32_t i;\
char *r;\
\
- if (!arr) {\
- return talloc_strdup(mem_ctx, "NULL");\
- }\
+ if (!arr) {\
+ return talloc_strdup(mem_ctx, "NULL");\
+ }\
r = talloc_strdup(mem_ctx, "(");\
- for (i = 0; i < arr->count; ++i) {\
+ for (i = 0; i < arr->count; ++i) {\
r = talloc_asprintf_append(r, fmt "%s", arr->item[i], (i+1 == arr->count)?"":",");\
- }\
- return talloc_asprintf_append(r, ")");\
+ }\
+ return talloc_asprintf_append(r, ")");\
}
char *string_CIMVAR(TALLOC_CTX *mem_ctx, union CIMVAR *v, enum CIMTYPE_ENUMERATION cimtype)
{
switch (cimtype) {
- case CIM_SINT8: return talloc_asprintf(mem_ctx, "%d", v->v_sint8);
- case CIM_UINT8: return talloc_asprintf(mem_ctx, "%u", v->v_uint8);
- case CIM_SINT16: return talloc_asprintf(mem_ctx, "%d", v->v_sint16);
- case CIM_UINT16: return talloc_asprintf(mem_ctx, "%u", v->v_uint16);
- case CIM_SINT32: return talloc_asprintf(mem_ctx, "%d", v->v_sint32);
- case CIM_UINT32: return talloc_asprintf(mem_ctx, "%u", v->v_uint32);
- case CIM_SINT64: return talloc_asprintf(mem_ctx, "%lld", v->v_sint64);
- case CIM_UINT64: return talloc_asprintf(mem_ctx, "%llu", v->v_sint64);
- case CIM_REAL32: return talloc_asprintf(mem_ctx, "%f", (double)v->v_uint32);
- case CIM_REAL64: return talloc_asprintf(mem_ctx, "%f", (double)v->v_uint64);
- case CIM_BOOLEAN: return talloc_asprintf(mem_ctx, "%s", v->v_boolean?"True":"False");
- case CIM_STRING:
- case CIM_DATETIME:
- case CIM_REFERENCE: return talloc_asprintf(mem_ctx, "%s", v->v_string);
- case CIM_CHAR16: return talloc_asprintf(mem_ctx, "Unsupported");
- case CIM_OBJECT: return talloc_asprintf(mem_ctx, "Unsupported");
- case CIM_ARR_SINT8: RETURN_CVAR_ARRAY_STR("%d", v->a_sint8);
- case CIM_ARR_UINT8: RETURN_CVAR_ARRAY_STR("%u", v->a_uint8);
- case CIM_ARR_SINT16: RETURN_CVAR_ARRAY_STR("%d", v->a_sint16);
- case CIM_ARR_UINT16: RETURN_CVAR_ARRAY_STR("%u", v->a_uint16);
- case CIM_ARR_SINT32: RETURN_CVAR_ARRAY_STR("%d", v->a_sint32);
- case CIM_ARR_UINT32: RETURN_CVAR_ARRAY_STR("%u", v->a_uint32);
- case CIM_ARR_SINT64: RETURN_CVAR_ARRAY_STR("%lld", v->a_sint64);
- case CIM_ARR_UINT64: RETURN_CVAR_ARRAY_STR("%llu", v->a_uint64);
- case CIM_ARR_REAL32: RETURN_CVAR_ARRAY_STR("%f", v->a_real32);
- case CIM_ARR_REAL64: RETURN_CVAR_ARRAY_STR("%f", v->a_real64);
- case CIM_ARR_BOOLEAN: RETURN_CVAR_ARRAY_STR("%d", v->a_boolean);
- case CIM_ARR_STRING: RETURN_CVAR_ARRAY_STR("%s", v->a_string);
- case CIM_ARR_DATETIME: RETURN_CVAR_ARRAY_STR("%s", v->a_datetime);
- case CIM_ARR_REFERENCE: RETURN_CVAR_ARRAY_STR("%s", v->a_reference);
+ case CIM_SINT8: return talloc_asprintf(mem_ctx, "%d", v->v_sint8);
+ case CIM_UINT8: return talloc_asprintf(mem_ctx, "%u", v->v_uint8);
+ case CIM_SINT16: return talloc_asprintf(mem_ctx, "%d", v->v_sint16);
+ case CIM_UINT16: return talloc_asprintf(mem_ctx, "%u", v->v_uint16);
+ case CIM_SINT32: return talloc_asprintf(mem_ctx, "%d", v->v_sint32);
+ case CIM_UINT32: return talloc_asprintf(mem_ctx, "%u", v->v_uint32);
+ case CIM_SINT64: return talloc_asprintf(mem_ctx, "%lld", v->v_sint64);
+ case CIM_UINT64: return talloc_asprintf(mem_ctx, "%llu", v->v_sint64);
+ case CIM_REAL32: return talloc_asprintf(mem_ctx, "%f", (double)v->v_uint32);
+ case CIM_REAL64: return talloc_asprintf(mem_ctx, "%f", (double)v->v_uint64);
+ case CIM_BOOLEAN: return talloc_asprintf(mem_ctx, "%s", v->v_boolean?"True":"False");
+ case CIM_STRING:
+ case CIM_DATETIME:
+ case CIM_REFERENCE: return talloc_asprintf(mem_ctx, "%s", v->v_string);
+ case CIM_CHAR16: return talloc_asprintf(mem_ctx, "Unsupported");
+ case CIM_OBJECT: return talloc_asprintf(mem_ctx, "Unsupported");
+ case CIM_ARR_SINT8: RETURN_CVAR_ARRAY_STR("%d", v->a_sint8);
+ case CIM_ARR_UINT8: RETURN_CVAR_ARRAY_STR("%u", v->a_uint8);
+ case CIM_ARR_SINT16: RETURN_CVAR_ARRAY_STR("%d", v->a_sint16);
+ case CIM_ARR_UINT16: RETURN_CVAR_ARRAY_STR("%u", v->a_uint16);
+ case CIM_ARR_SINT32: RETURN_CVAR_ARRAY_STR("%d", v->a_sint32);
+ case CIM_ARR_UINT32: RETURN_CVAR_ARRAY_STR("%u", v->a_uint32);
+ case CIM_ARR_SINT64: RETURN_CVAR_ARRAY_STR("%lld", v->a_sint64);
+ case CIM_ARR_UINT64: RETURN_CVAR_ARRAY_STR("%llu", v->a_uint64);
+ case CIM_ARR_REAL32: RETURN_CVAR_ARRAY_STR("%f", v->a_real32);
+ case CIM_ARR_REAL64: RETURN_CVAR_ARRAY_STR("%f", v->a_real64);
+ case CIM_ARR_BOOLEAN: RETURN_CVAR_ARRAY_STR("%d", v->a_boolean);
+ case CIM_ARR_STRING: RETURN_CVAR_ARRAY_STR("%s", v->a_string);
+ case CIM_ARR_DATETIME: RETURN_CVAR_ARRAY_STR("%s", v->a_datetime);
+ case CIM_ARR_REFERENCE: RETURN_CVAR_ARRAY_STR("%s", v->a_reference);
default: return talloc_asprintf(mem_ctx, "Unsupported");
}
}
@@ -164,7 +164,7 @@ int main(int argc, char **argv)
struct IEnumWbemClassObject *pEnum = NULL;
struct com_context *ctx = NULL;
- parse_args(argc, argv, &args);
+ parse_args(argc, argv, &args);
wmi_init(&ctx, cmdline_credentials);
diff --git a/source4/lib/wmi/tools/wmis.c b/source4/lib/wmi/tools/wmis.c
index 2b7abbb7bc..314fdd1cd7 100644
--- a/source4/lib/wmi/tools/wmis.c
+++ b/source4/lib/wmi/tools/wmis.c
@@ -81,7 +81,7 @@ static void parse_args(int argc, char *argv[], struct program_args *pmyargs)
}
if (argc_new < 2 || argv_new[1][0] != '/'
- || argv_new[1][1] != '/') {
+ || argv_new[1][1] != '/') {
poptPrintUsage(pc, stdout, 0);
poptFreeContext(pc);
exit(1);
@@ -119,7 +119,7 @@ WERROR WBEM_ConnectServer(struct com_context *ctx, const char *server, const cha
}
GUID_from_string(CLSID_WBEMLEVEL1LOGIN, &clsid);
- GUID_from_string(COM_IWBEMLEVEL1LOGIN_UUID, &iid);
+ GUID_from_string(COM_IWBEMLEVEL1LOGIN_UUID, &iid);
result = dcom_create_object(ctx, &clsid, server, 1, &iid, &mqi, &coresult);
WERR_CHECK("dcom_create_object.");
result = coresult;
@@ -183,12 +183,12 @@ int main(int argc, char **argv)
WERROR result;
NTSTATUS status;
struct IWbemServices *pWS = NULL;
- struct IEnumWbemClassObject *pEnum = NULL;
+ struct IEnumWbemClassObject *pEnum = NULL;
uint32_t cnt;
struct BSTR queryLanguage;
struct BSTR query;
- parse_args(argc, argv, &args);
+ parse_args(argc, argv, &args);
wmi_init(&ctx, cmdline_credentials);
result = WBEM_ConnectServer(ctx, args.hostname, "root\\cimv2", 0, 0, 0, 0, 0, 0, &pWS);
@@ -202,9 +202,9 @@ int main(int argc, char **argv)
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");
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,
+ result = IWbemServices_ExecNotificationQuery(pWS, ctx, queryLanguage,
query, WBEM_FLAG_RETURN_IMMEDIATELY | WBEM_FLAG_FORWARD_ONLY, NULL, &pEnum);
- WERR_CHECK("WMI query execute.");
+ WERR_CHECK("WMI query execute.");
for (cnt = 0; cnt < 4; ++cnt) {
struct WbemClassObject *co;
uint32_t ret;
diff --git a/source4/lib/wmi/wbemdata.c b/source4/lib/wmi/wbemdata.c
index b973e1555d..6783cb7233 100644
--- a/source4/lib/wmi/wbemdata.c
+++ b/source4/lib/wmi/wbemdata.c
@@ -1,6 +1,7 @@
/*
WMI Implementation
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
@@ -33,27 +34,20 @@
#include "libcli/composite/composite.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);
-void duplicate_WbemClassObject(TALLOC_CTX *mem_ctx, const struct WbemClassObject *src, struct WbemClassObject *dst);
-
#define NDR_CHECK_LEN(n) do { if (p + (n) > pend) { \
- DEBUG(0, ("%s(%d): WBEMDATA_ERR(0x%08X): Buffer too small(0x%04X)\n", __FILE__, __LINE__, ndr->offset, p + (n) - pend)); \
+ DEBUG(0, ("%s(%d): WBEMDATA_ERR(0x%08X): Buffer too small(0x%04X)\n", __FILE__, __LINE__, ndr->offset, p + (n) - pend)); \
status = NT_STATUS_UNSUCCESSFUL; \
- goto end; \
+ goto end; \
} \
} while(0)
#define NDR_CHECK_EXPR(expr) do { if (!(expr)) {\
DEBUG(0, ("%s(%d): WBEMDATA_ERR(0x%08X): Error parsing(%s)\n", __FILE__, __LINE__, ndr->offset, #expr)); \
status = NT_STATUS_UNSUCCESSFUL; \
- goto end; \
+ goto end; \
} \
} while(0)
-#define NDR_CHECK_CONST(val, exp) NDR_CHECK_EXPR((val) == (exp))
-#define NDR_CHECK_RSTRING(rstring) NDR_CHECK_EXPR((rstring) >= 0)
-
enum {
DATATYPE_CLASSOBJECT = 2,
DATATYPE_OBJECT = 3,
@@ -89,7 +83,7 @@ static enum ndr_err_code marshal(TALLOC_CTX *mem_ctx, struct IUnknown *pv, struc
o->u_objref.u_custom.pData = talloc_realloc(mp, ndr->data, uint8_t, ndr->offset);
o->u_objref.u_custom.size = ndr->offset;
mp->size = sizeof(struct OBJREF) - sizeof(union OBJREF_Types) + sizeof(struct u_custom) + o->u_objref.u_custom.size - 4;
- if (DEBUGLVL(9)) {
+ if (DEBUGLVL(9)) {
NDR_PRINT_DEBUG(WbemClassObject, wco);
}
return NDR_ERR_SUCCESS;
@@ -123,9 +117,9 @@ static enum ndr_err_code unmarshal(TALLOC_CTX *mem_ctx, struct OBJREF *o, struct
ndr->current_mem_ctx = wco;
ndr_err = ndr_pull_WbemClassObject(ndr, NDR_SCALARS | NDR_BUFFERS, wco);
- if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLVL(9))) {
+ if (NDR_ERR_CODE_IS_SUCCESS(ndr_err) && (DEBUGLVL(9))) {
NDR_PRINT_DEBUG(WbemClassObject, wco);
- }
+ }
if (NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
(*pv)->object_data = wco;
@@ -347,54 +341,54 @@ void duplicate_CIMVAR(TALLOC_CTX *mem_ctx, const union CIMVAR *src, union CIMVAR
uint32_t i;
switch (cimtype & CIM_TYPEMASK) {
- case CIM_SINT8:
- case CIM_UINT8:
- case CIM_SINT16:
- case CIM_UINT16:
- case CIM_SINT32:
- case CIM_UINT32:
- case CIM_SINT64:
- case CIM_UINT64:
- case CIM_REAL32:
- case CIM_REAL64:
- case CIM_BOOLEAN:
+ case CIM_SINT8:
+ case CIM_UINT8:
+ case CIM_SINT16:
+ case CIM_UINT16:
+ case CIM_SINT32:
+ case CIM_UINT32:
+ case CIM_SINT64:
+ case CIM_UINT64:
+ case CIM_REAL32:
+ case CIM_REAL64:
+ case CIM_BOOLEAN:
*dst = *src;
break;
- case CIM_STRING:
- case CIM_DATETIME:
- case CIM_REFERENCE:
+ case CIM_STRING:
+ case CIM_DATETIME:
+ case CIM_REFERENCE:
dst->v_string = talloc_strdup(mem_ctx, src->v_string);
break;
case CIM_OBJECT:
dst->v_object = talloc_zero(mem_ctx, struct WbemClassObject);
duplicate_WbemClassObject(dst->v_object, src->v_object, dst->v_object);
break;
- case CIM_ARR_SINT8:
+ case CIM_ARR_SINT8:
case CIM_ARR_UINT8:
dst->a_uint8 = talloc_memdup(mem_ctx, src->a_uint8, sizeof(struct arr_uint8));
dst->a_uint8->item = talloc_memdup(dst->a_uint8, src->a_uint8->item, src->a_uint8->count);
break;
- case CIM_ARR_SINT16:
- case CIM_ARR_UINT16:
- case CIM_ARR_BOOLEAN:
+ case CIM_ARR_SINT16:
+ case CIM_ARR_UINT16:
+ case CIM_ARR_BOOLEAN:
dst->a_uint8 = talloc_memdup(mem_ctx, src->a_uint8, sizeof(struct arr_uint8));
dst->a_uint8->item = talloc_memdup(dst->a_uint8, src->a_uint8->item, 2*src->a_uint8->count);
break;
- case CIM_ARR_SINT32:
- case CIM_ARR_UINT32:
- case CIM_ARR_REAL32:
+ case CIM_ARR_SINT32:
+ case CIM_ARR_UINT32:
+ case CIM_ARR_REAL32:
dst->a_uint8 = talloc_memdup(mem_ctx, src->a_uint8, sizeof(struct arr_uint8));
dst->a_uint8->item = talloc_memdup(dst->a_uint8, src->a_uint8->item, 4*src->a_uint8->count);
break;
- case CIM_ARR_SINT64:
- case CIM_ARR_UINT64:
+ case CIM_ARR_SINT64:
+ case CIM_ARR_UINT64:
case CIM_ARR_REAL64:
dst->a_uint8 = talloc_memdup(mem_ctx, src->a_uint8, sizeof(struct arr_uint8));
dst->a_uint8->item = talloc_memdup(dst->a_uint8, src->a_uint8->item, 8*src->a_uint8->count);
break;
- case CIM_ARR_STRING:
- case CIM_ARR_DATETIME:
- case CIM_ARR_REFERENCE:
+ case CIM_ARR_STRING:
+ case CIM_ARR_DATETIME:
+ case CIM_ARR_REFERENCE:
dst->a_uint8 = talloc_memdup(mem_ctx, src->a_uint8, sizeof(struct arr_uint8));
dst->a_uint8->item = talloc_memdup(dst->a_uint8, src->a_uint8->item, 4*src->a_uint8->count);
for (i = 0; i < src->a_uint8->count; ++i)
@@ -438,11 +432,11 @@ WERROR IWbemClassObject_Put(struct IWbemClassObject *d, TALLOC_CTX *mem_ctx, con
}
#define WERR_CHECK(msg) if (!W_ERROR_IS_OK(result)) { \
- DEBUG(1, ("ERROR: %s - %s\n", msg, wmi_errstr(result))); \
- goto end; \
- } else { \
- DEBUG(1, ("OK : %s\n", msg)); \
- }
+ DEBUG(1, ("ERROR: %s - %s\n", msg, wmi_errstr(result))); \
+ goto end; \
+ } else { \
+ DEBUG(1, ("OK : %s\n", msg)); \
+ }
struct pair_guid_ptr {
struct GUID guid;
@@ -453,7 +447,7 @@ struct pair_guid_ptr {
static void *get_ptr_by_guid(struct pair_guid_ptr *list, struct GUID *uuid)
{
for (; list; list = list->next) {
- if (GUID_equal(&list->guid, uuid))
+ if (GUID_equal(&list->guid, uuid))
return list->ptr;
}
return NULL;
@@ -472,10 +466,13 @@ static void add_pair_guid_ptr(TALLOC_CTX *mem_ctx, struct pair_guid_ptr **list,
struct IEnumWbemClassObject_data {
struct GUID guid;
- struct IWbemFetchSmartEnum *pFSE;
+ struct IWbemFetchSmartEnum *pFSE;
struct IWbemWCOSmartEnum *pSE;
struct pair_guid_ptr *cache;
};
+#define NDR_CHECK_CONST(val, exp) NDR_CHECK_EXPR((val) == (exp))
+#define NDR_CHECK_RSTRING(rstring) NDR_CHECK_EXPR((rstring) >= 0)
+
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)
{
@@ -613,20 +610,20 @@ end:
struct composite_context *dcom_proxy_IEnumWbemClassObject_Release_send(struct IUnknown *d, TALLOC_CTX *mem_ctx)
{
- struct composite_context *c, *cr;
- struct REMINTERFACEREF iref[3];
- struct dcom_object_exporter *ox;
+ struct composite_context *c, *cr;
+ struct REMINTERFACEREF iref[3];
+ struct dcom_object_exporter *ox;
struct IEnumWbemClassObject_data *ecod;
int n;
- c = composite_create(d->ctx, d->ctx->event_ctx);
- if (c == NULL) return NULL;
- c->private_data = d;
+ c = composite_create(d->ctx, d->ctx->event_ctx);
+ if (c == NULL) return NULL;
+ c->private_data = d;
- ox = object_exporter_by_ip(d->ctx, d);
- iref[0].ipid = IUnknown_ipid(d);
- iref[0].cPublicRefs = 5;
- iref[0].cPrivateRefs = 0;
+ ox = object_exporter_by_ip(d->ctx, d);
+ iref[0].ipid = IUnknown_ipid(d);
+ iref[0].cPublicRefs = 5;
+ iref[0].cPrivateRefs = 0;
n = 1;
ecod = d->object_data;
@@ -642,14 +639,14 @@ struct composite_context *dcom_proxy_IEnumWbemClassObject_Release_send(struct IU
talloc_steal(d, ecod->pSE);
iref[n].ipid = IUnknown_ipid(ecod->pSE);
iref[n].cPublicRefs = 5;
- iref[n].cPrivateRefs = 0;
+ iref[n].cPrivateRefs = 0;
++n;
}
}
cr = IRemUnknown_RemRelease_send(ox->rem_unknown, mem_ctx, n, iref);
- composite_continue(c, cr, dcom_release_continue, c);
- return c;
+ composite_continue(c, cr, dcom_release_continue, c);
+ return c;
}
NTSTATUS dcom_proxy_IWbemClassObject_init(void)
@@ -667,5 +664,5 @@ NTSTATUS dcom_proxy_IWbemClassObject_init(void)
DEBUG(0, ("WARNING: IEnumWbemClassObject should be initialized before IWbemClassObject."));
#endif
- return NT_STATUS_OK;
+ return NT_STATUS_OK;
}