Author: mturk Date: Sat Oct 10 12:02:39 2009 New Revision: 823846 URL: http://svn.apache.org/viewvc?rev=823846&view=rev Log: Add few more stub files
Added: commons/sandbox/runtime/trunk/src/main/native/os/win32/scm.c (with props) commons/sandbox/runtime/trunk/src/main/native/os/win32/wmi.cpp (with props) commons/sandbox/runtime/trunk/src/main/native/os/win32/wmiapi.c (with props) Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in?rev=823846&r1=823845&r2=823846&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in (original) +++ commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in Sat Oct 10 12:02:39 2009 @@ -125,6 +125,7 @@ $(SRCDIR)/os/win32/pipe.$(OBJ) \ $(SRCDIR)/os/win32/posix.$(OBJ) \ $(SRCDIR)/os/win32/registry.$(OBJ) \ + $(SRCDIR)/os/win32/scm.$(OBJ) \ $(SRCDIR)/os/win32/secmem.$(OBJ) \ $(SRCDIR)/os/win32/sema.$(OBJ) \ $(SRCDIR)/os/win32/service.$(OBJ) \ @@ -140,6 +141,8 @@ $(SRCDIR)/os/win32/uuid.$(OBJ) \ $(SRCDIR)/os/win32/variant.$(OBJ) \ $(SRCDIR)/os/win32/volume.$(OBJ) \ + $(SRCDIR)/os/win32/wmi.$(OBJ) \ + $(SRCDIR)/os/win32/wmiapi.$(OBJ) \ $(SRCDIR)/os/win32/wutil.$(OBJ) \ $(SRCDIR)/os/win32/wusec.$(OBJ) Added: commons/sandbox/runtime/trunk/src/main/native/os/win32/scm.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/scm.c?rev=823846&view=auto ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/os/win32/scm.c (added) +++ commons/sandbox/runtime/trunk/src/main/native/os/win32/scm.c Sat Oct 10 12:02:39 2009 @@ -0,0 +1,29 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "acr.h" +#include "acr_private.h" +#include "acr_arch.h" +#include "acr_arch_service.h" +#include "acr_clazz.h" +#include "acr_error.h" +#include "acr_memory.h" +#include "acr_string.h" +#include "acr_tlsd.h" +#include "acr_vm.h" + +/* Service Control Manager windows implementation + */ Propchange: commons/sandbox/runtime/trunk/src/main/native/os/win32/scm.c ------------------------------------------------------------------------------ svn:eol-style = native Added: commons/sandbox/runtime/trunk/src/main/native/os/win32/wmi.cpp URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/wmi.cpp?rev=823846&view=auto ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/os/win32/wmi.cpp (added) +++ commons/sandbox/runtime/trunk/src/main/native/os/win32/wmi.cpp Sat Oct 10 12:02:39 2009 @@ -0,0 +1,275 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "acr.h" +#include "acr_private.h" +#include "acr_arch.h" +#include "acr_arch_service.h" +#include "acr_clazz.h" +#include "acr_error.h" +#include "acr_memory.h" +#include "acr_string.h" +#include "acr_tlsd.h" +#include "acr_vm.h" + +#include <comdef.h> +#include <wbemidl.h> +#pragma comment(lib, "wbemuuid.lib") + +typedef struct { + IWbemLocator *pLoc; + IWbemServices *pSvc; + IEnumWbemClassObject *pEnumerator; + IWbemClassObject *pclsObj; + IWbemClassObject *pclsInstance; + IWbemClassObject *pInParams; + IWbemClassObject *pOutParams; + ULONG dwCount; +} wmi_data_t; + +#define DEFAULT_WMI_NS L"ROOT\\CIMV2" + +static int cosec_inited = 0; + +extern "C" +void *wmi_intialize(JNIEnv *_E, const jchar *ns, jsize nsl) +{ + wmi_data_t *wd; + HRESULT hres; + + if (!ns) { + ns = DEFAULT_WMI_NS; + nsl = (sizeof(DEFAULT_WMI_NS) - 1) / sizeof(WCHAR); + } + // Step 1: -------------------------------------------------- + // Initialize COM. ------------------------------------------ + + hres = CoInitializeEx(0, COINIT_MULTITHREADED); + if (FAILED(hres)) { + throwAprException(_E, APR_FROM_OS_ERROR(hres)); + return NULL; + } + + // Step 2: -------------------------------------------------- + // Set general COM security levels -------------------------- + // Note: If you are using Windows 2000, you need to specify - + // the default authentication credentials for a user by using + // a SOLE_AUTHENTICATION_LIST structure in the pAuthList ---- + // parameter of CoInitializeSecurity ------------------------ + if (!cosec_inited) { + hres = CoInitializeSecurity( + NULL, + -1, // COM authentication + NULL, // Authentication services + NULL, // Reserved + RPC_C_AUTHN_LEVEL_DEFAULT, // Default authentication + RPC_C_IMP_LEVEL_IMPERSONATE, // Default Impersonation + NULL, // Authentication info + EOAC_NONE, // Additional capabilities + NULL // Reserved + ); + if (FAILED(hres)) { + throwAprException(_E, APR_FROM_OS_ERROR(hres)); + CoUninitialize(); + return NULL; // Program has failed. + } + cosec_inited = 1; + } + + if (!(wd = ACR_CALLOC(wmi_data_t, 1) { + return NULL; + } + hres = CoCreateInstance( + CLSID_WbemLocator, + 0, + CLSCTX_INPROC_SERVER, + IID_IWbemLocator, (LPVOID *)&wd->pLoc); + + if (FAILED(hres)) { + throwAprException(_E, APR_FROM_OS_ERROR(hres)); + wd->pLoc = NULL; + free(wd); + return NULL; + } + + BSTR bns = SysAllocStringLen(ns, nsl); + // Connect to the root\cimv2 namespace with the + // current user and obtain pointer pSvc + // to make IWbemServices calls. + + hres = wd->pLoc->ConnectServer( + bns, // WMI namespace + NULL, // User name + NULL, // User password + 0, // Locale + NULL, // Security flags + 0, // Authority + 0, // Context object + &wd->pSvc // IWbemServices proxy + ); + SysFreeString(bns); + if (FAILED(hres)) { + throwAprException(_E, APR_FROM_OS_ERROR(hres)); + wd->pLoc->Release(); + CoUninitialize(); + wd->pLoc = NULL; + wd->pSvc = NULL; + goto cleanup; + } + + // Set the IWbemServices proxy so that impersonation + // of the user (client) occurs. + hres = CoSetProxyBlanket( + wd->pSvc, // the proxy to set + RPC_C_AUTHN_WINNT, // authentication service + RPC_C_AUTHZ_NONE, // authorization service + NULL, // Server principal name + RPC_C_AUTHN_LEVEL_CALL, // authentication level + RPC_C_IMP_LEVEL_IMPERSONATE,// impersonation level + NULL, // client identity + EOAC_NONE // proxy capabilities + ); + + if (FAILED(hres)) { + throwAprException(_E, APR_FROM_OS_ERROR(hres)); + wd->pSvc->Release(); + wd->pLoc->Release(); + CoUninitialize(); + wd->pLoc = NULL; + wd->pSvc = NULL; + goto cleanup; + } + + return wd; +cleanup: + x_free(wd); + return NULL; +} + +extern "C" +void wmi_terminate(void *wmi) +{ + wmi_data_t *wd = (wmi_data_t *)wmi; + + if (!wd) + return; + if (wd->pEnumerator) + wd->pEnumerator->Release(); + if (wd->pInParams) + wd->pInParams->Release(); + if (wd->pOutParams) + wd->pOutParams->Release(); + if (wd->pclsObj) + wd->pclsObj->Release(); + if (wd->pSvc) + wd->pSvc->Release(); + if (wd->pLoc) + wd->pLoc->Release(); + CoUninitialize(); + free(wd); +} + +extern "C" +int wmi_query(void *wmi, const jchar *lang, jsize langl, + const jchar *query, jsize queryl) +{ + HRESULT hres; + wmi_data_t *wd = (wmi_data_t *)wmi; + + if (!wd) + return APR_EINVAL; + if (wd->pEnumerator) + wd->pEnumerator->Release(); + BSTR blang = SysAllocStringLen(lang, langl); + BSTR bquery = SysAllocStringLen(query, queryl); + hres = wd->pSvc->ExecQuery( + blang, + bquery, + WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, + NULL, + &wd->pEnumerator); + SysFreeString(blang); + SysFreeString(bquery); + if (FAILED(hres)) { + wd->pEnumerator = NULL; + return APR_FROM_OS_ERROR(hres); + } + + return APR_SUCCESS; +} + +extern "C" +int wmi_query_next(void *wmi) +{ + HRESULT hres; + wmi_data_t *wd = (wmi_data_t *)wmi; + + if (!wd || !wd->pEnumerator) + return APR_EINVAL; + + hres = wd->pEnumerator->Next( + WBEM_INFINITE, + 1, + &wd->pclsObj, + &wd->dwCount); + + if (SUCCEEDED(hres)) { + if (wd->dwCount) + return APR_SUCCESS; + else + return APR_EOF; + } + else + return APR_EOF; +} + +extern "C" +int wmi_query_skip(void *wmi, int count) +{ + HRESULT hres; + wmi_data_t *wd = (wmi_data_t *)wmi; + + if (!wd || !wd->pEnumerator) + return APR_EINVAL; + + hres = wd->pEnumerator->Skip( + WBEM_INFINITE, + count); + + if (SUCCEEDED(hres)) { + return APR_SUCCESS; + } + else + return APR_EOF; +} + +extern "C" +int wmi_query_reset(void *wmi) +{ + HRESULT hres; + wmi_data_t *wd = (wmi_data_t *)wmi; + + if (!wd || !wd->pEnumerator) + return APR_EINVAL; + + hres = wd->pEnumerator->Reset(); + + if (SUCCEEDED(hres)) { + return APR_SUCCESS; + } + else + return APR_EOF; +} Propchange: commons/sandbox/runtime/trunk/src/main/native/os/win32/wmi.cpp ------------------------------------------------------------------------------ svn:eol-style = native Added: commons/sandbox/runtime/trunk/src/main/native/os/win32/wmiapi.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/wmiapi.c?rev=823846&view=auto ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/os/win32/wmiapi.c (added) +++ commons/sandbox/runtime/trunk/src/main/native/os/win32/wmiapi.c Sat Oct 10 12:02:39 2009 @@ -0,0 +1,30 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "acr.h" +#include "acr_private.h" +#include "acr_arch.h" +#include "acr_arch_service.h" +#include "acr_clazz.h" +#include "acr_error.h" +#include "acr_memory.h" +#include "acr_string.h" +#include "acr_tlsd.h" +#include "acr_vm.h" + +/* + * WMI API + */ Propchange: commons/sandbox/runtime/trunk/src/main/native/os/win32/wmiapi.c ------------------------------------------------------------------------------ svn:eol-style = native