Esempio n. 1
0
 internal void Secure(IWbemCallResult callResult)
 {
     if (null != scope)
     {
         scope.Secure(callResult);
     }
 }
Esempio n. 2
0
 internal void Secure(IWbemCallResult callResult)
 {
     if (null != scope)
     {
         securityHelper.BlessIWbemCallResult(
             callResult,
             scope.Options.Username,
             scope.Options.GetPassword(),
             scope.Options.Authority,
             (int)scope.Options.Impersonation,
             (int)scope.Options.Authentication);
     }
 }
Esempio n. 3
0
        internal void Secure(IWbemCallResult wbemCallResult)
        {
            if (null == securityHelper)
            {
                securityHelper = (IWmiSec) new WmiSec();
            }

            securityHelper.BlessIWbemCallResult(
                ref wbemCallResult,
                options.Username,
                options.GetPassword(),
                options.Authority,
                (int)options.Impersonation,
                (int)options.Authentication);
        }
Esempio n. 4
0
        int IWbemServices_Old.GetObjectAsync_([In][MarshalAs(UnmanagedType.BStr)]  string strObjectPath,
                                              [In] Int32 lFlags,
                                              [In][MarshalAs(UnmanagedType.Interface)]  IWbemContext pCtx,
                                              [In][MarshalAs(UnmanagedType.Interface)]  IWbemObjectSink pResponseHandler)
        {
//            pResponseHandler.SetStatus(0, (int)tag_WBEMSTATUS.WBEM_E_NOT_FOUND, null, null);
//            Marshal.ReleaseComObject(pResponseHandler);
//            return (int)(tag_WBEMSTATUS.WBEM_E_NOT_FOUND);

            Match match = Regex.Match(strObjectPath.ToLower(CultureInfo.InvariantCulture), "(.*?)\\.instanceid=\"(.*?)\",processid=\"(.*?)\"");

            if (match.Success == false)
            {
                pResponseHandler.SetStatus_(0, (int)tag_WBEMSTATUS.WBEM_E_NOT_FOUND, null, IntPtr.Zero);
                Marshal.ReleaseComObject(pResponseHandler);
                return((int)(tag_WBEMSTATUS.WBEM_E_NOT_FOUND));
            }

            string className  = match.Groups[1].Value;
            string instanceId = match.Groups[2].Value;
            string processId  = match.Groups[3].Value;


            if (Instrumentation.ProcessIdentity != processId)
            {
                pResponseHandler.SetStatus_(0, (int)tag_WBEMSTATUS.WBEM_E_NOT_FOUND, null, IntPtr.Zero);
                Marshal.ReleaseComObject(pResponseHandler);
                return((int)(tag_WBEMSTATUS.WBEM_E_NOT_FOUND));
            }

            int    id        = ((IConvertible)instanceId).ToInt32((IFormatProvider)CultureInfo.InvariantCulture.GetFormat(typeof(System.Int32)));
            Object theObject = null;

            try
            {
                InstrumentedAssembly.readerWriterLock.AcquireReaderLock(-1);
                theObject = InstrumentedAssembly.mapIDToPublishedObject[id.ToString((IFormatProvider)CultureInfo.InvariantCulture.GetFormat(typeof(System.Int32)))];
            }
            finally
            {
                InstrumentedAssembly.readerWriterLock.ReleaseReaderLock();
            }

            if (theObject != null)
            {
                Type converterType = (Type)instrumentedAssembly.mapTypeToConverter[theObject.GetType()];
                if (converterType != null)
                {
                    Object       converter = Activator.CreateInstance(converterType);
                    ConvertToWMI func      = (ConvertToWMI)Delegate.CreateDelegate(typeof(ConvertToWMI), converter, "ToWMI");

                    //
                    // Regression: Reuters VSQFE#: 750, PS#141144    [marioh]
                    // GetObjectAsync was missed. Again, here we have to call ToWMI before retrieving the pointer to the object
                    // since we clone a new one during the ToWMI call. The code below was simply moved from a location further down
                    //
                    lock (theObject)
                        func(theObject);
                    //
                    // END: Regression: Reuters VSQFE#: 750, PS#141144    [marioh]


                    IntPtr[] objs = new IntPtr[] { (IntPtr)converter.GetType().GetField("instWbemObjectAccessIP").GetValue(converter) };
                    Marshal.AddRef(objs[0]);
                    IWbemClassObjectFreeThreaded inst = new IWbemClassObjectFreeThreaded(objs[0]);

                    Object o = id;
                    inst.Put_("InstanceId", 0, ref o, 0);
                    o = Instrumentation.ProcessIdentity;
                    inst.Put_("ProcessId", 0, ref o, 0);
                    //               ConvertFuncToWMI func = (ConvertFuncToWMI)InstrumentedAssembly.mapTypeToToWMIFunc[h.Target.GetType()];
                    //
                    // Reuters VSQFE#: 750, PS#141144    [marioh]
                    // The commented out code was moved up before accessing the object pointer in order to get the
                    // newly cloned one.
                    //
//                    lock(theObject)
//                        func(theObject);
                    pResponseHandler.Indicate_(1, objs);

                    pResponseHandler.SetStatus_(0, 0, null, IntPtr.Zero);
                    Marshal.ReleaseComObject(pResponseHandler);
                    return(0);
                }
            }
            pResponseHandler.SetStatus_(0, (int)tag_WBEMSTATUS.WBEM_E_NOT_FOUND, null, IntPtr.Zero);
            Marshal.ReleaseComObject(pResponseHandler);
            return((int)(tag_WBEMSTATUS.WBEM_E_NOT_FOUND));

#if xxx
            IWbemClassObject classObj = null;
            IWbemCallResult  result   = null;
            pNamespace.GetObject("TestInstance", 0, pCtx, ref classObj, ref result);
            IWbemClassObject inst;
            classObj.SpawnInstance(0, out inst);

            TestInstance testInstance = (TestInstance)mapNameToTestInstance[match.Groups[1].Value];

            Object o = (object)testInstance.name;
            inst.Put("name", 0, ref o, 0);
            o = (object)testInstance.value;
            inst.Put("value", 0, ref o, 0);

            pResponseHandler.Indicate(1, new IWbemClassObject[] { inst });
            pResponseHandler.SetStatus_(0, 0, IntPtr.Zero, IntPtr.Zero);
            Marshal.ReleaseComObject(pResponseHandler);
#endif
        }
Esempio n. 5
0
        int IWbemServices_Old.GetObjectAsync_([In][MarshalAs(UnmanagedType.BStr)]  string strObjectPath,
                                              [In] Int32 lFlags,
                                              [In][MarshalAs(UnmanagedType.Interface)]  IWbemContext pCtx,
                                              [In][MarshalAs(UnmanagedType.Interface)]  IWbemObjectSink pResponseHandler)
        {
//            pResponseHandler.SetStatus(0, (int)tag_WBEMSTATUS.WBEM_E_NOT_FOUND, null, null);
//            Marshal.ReleaseComObject(pResponseHandler);
//            return (int)(tag_WBEMSTATUS.WBEM_E_NOT_FOUND);

            Match match = Regex.Match(strObjectPath.ToLower(CultureInfo.InvariantCulture), "(.*?)\\.instanceid=\"(.*?)\",processid=\"(.*?)\"");

            if (match.Success == false)
            {
                pResponseHandler.SetStatus_(0, (int)tag_WBEMSTATUS.WBEM_E_NOT_FOUND, null, IntPtr.Zero);
                Marshal.ReleaseComObject(pResponseHandler);
                return((int)(tag_WBEMSTATUS.WBEM_E_NOT_FOUND));
            }

            string className  = match.Groups[1].Value;
            string instanceId = match.Groups[2].Value;
            string processId  = match.Groups[3].Value;


            if (Instrumentation.ProcessIdentity != processId)
            {
                pResponseHandler.SetStatus_(0, (int)tag_WBEMSTATUS.WBEM_E_NOT_FOUND, null, IntPtr.Zero);
                Marshal.ReleaseComObject(pResponseHandler);
                return((int)(tag_WBEMSTATUS.WBEM_E_NOT_FOUND));
            }

            int    id        = ((IConvertible)instanceId).ToInt32(null);
            Object theObject = null;

            try
            {
                InstrumentedAssembly.readerWriterLock.AcquireReaderLock(-1);
                theObject = InstrumentedAssembly.mapIDToPublishedObject[id.ToString()];
            }
            finally
            {
                InstrumentedAssembly.readerWriterLock.ReleaseReaderLock();
            }

            if (theObject != null)
            {
                Type converterType = (Type)instrumentedAssembly.mapTypeToConverter[theObject.GetType()];
                if (converterType != null)
                {
                    Object       converter = Activator.CreateInstance(converterType);
                    ConvertToWMI func      = (ConvertToWMI)Delegate.CreateDelegate(typeof(ConvertToWMI), converter, "ToWMI");
                    IntPtr[]     objs      = new IntPtr[] { (IntPtr)converter.GetType().GetField("instWbemObjectAccessIP").GetValue(converter) };
                    Marshal.AddRef(objs[0]);
                    IWbemClassObjectFreeThreaded inst = new IWbemClassObjectFreeThreaded(objs[0]);

                    Object o = id;
                    inst.Put_("InstanceId", 0, ref o, 0);
                    o = Instrumentation.ProcessIdentity;
                    inst.Put_("ProcessId", 0, ref o, 0);
                    //                ConvertFuncToWMI func = (ConvertFuncToWMI)InstrumentedAssembly.mapTypeToToWMIFunc[h.Target.GetType()];
                    lock (theObject)
                        func(theObject);
                    pResponseHandler.Indicate_(1, objs);

                    pResponseHandler.SetStatus_(0, 0, null, IntPtr.Zero);
                    Marshal.ReleaseComObject(pResponseHandler);
                    return(0);
                }
            }
            pResponseHandler.SetStatus_(0, (int)tag_WBEMSTATUS.WBEM_E_NOT_FOUND, null, IntPtr.Zero);
            Marshal.ReleaseComObject(pResponseHandler);
            return((int)(tag_WBEMSTATUS.WBEM_E_NOT_FOUND));

#if xxx
            IWbemClassObject classObj = null;
            IWbemCallResult  result   = null;
            pNamespace.GetObject("TestInstance", 0, pCtx, ref classObj, ref result);
            IWbemClassObject inst;
            classObj.SpawnInstance(0, out inst);

            TestInstance testInstance = (TestInstance)mapNameToTestInstance[match.Groups[1].Value];

            Object o = (object)testInstance.name;
            inst.Put("name", 0, ref o, 0);
            o = (object)testInstance.value;
            inst.Put("value", 0, ref o, 0);

            pResponseHandler.Indicate(1, new IWbemClassObject[] { inst });
            pResponseHandler.SetStatus_(0, 0, IntPtr.Zero, IntPtr.Zero);
            Marshal.ReleaseComObject(pResponseHandler);
#endif
        }
Esempio n. 6
0
		private ManagementPath GetPath(IWbemCallResult callResult)
		{
			ManagementPath managementPath = null;
			try
			{
				string str = null;
				int resultString_ = callResult.GetResultString_(-1, out str);
				if (resultString_ < 0)
				{
					object propertyValue = base.GetPropertyValue("__PATH");
					if (propertyValue == null)
					{
						propertyValue = base.GetPropertyValue("__RELPATH");
						if (propertyValue != null)
						{
							managementPath = new ManagementPath(this.scope.Path.Path);
							managementPath.RelativePath = (string)propertyValue;
						}
					}
					else
					{
						managementPath = new ManagementPath((string)propertyValue);
					}
				}
				else
				{
					managementPath = new ManagementPath(this.scope.Path.Path);
					managementPath.RelativePath = str;
				}
			}
			catch
			{
			}
			if (managementPath == null)
			{
				managementPath = new ManagementPath();
			}
			return managementPath;
		}
        private ManagementPath GetPath(IWbemCallResult callResult)
        {
            ManagementPath newPath = null;
            int status = (int)ManagementStatus.NoError;

            try
            {
                //
                // Obtain the path from the call result.
                // Note this will return the relative path at best.
                //
                string resultPath = null;

                status = callResult.GetResultString_(
                    (int)tag_WBEM_TIMEOUT_TYPE.WBEM_INFINITE, 
                    out resultPath);
                        
                if (status >= 0)
                {
                    newPath = new ManagementPath(scope.Path.Path);
                    newPath.RelativePath = resultPath;
                }
                else
                {
                    //
                    // That didn't work. Use the path in the object instead.
                    //
                    object pathValue = GetPropertyValue("__PATH");

                    // No path? Try Relpath?
                    if (pathValue != null)
                        newPath = new ManagementPath((string)pathValue);
                    else
                    {
                        pathValue = GetPropertyValue("__RELPATH");

                        if (pathValue != null)
                        {
                            newPath = new ManagementPath(scope.Path.Path);
                            newPath.RelativePath = (string)pathValue;
                        }
                    }
                }

            } 
            catch 
           {
           }

            if (newPath == null)
                newPath = new ManagementPath();

            return newPath;
        }
Esempio n. 8
0
        int IWbemServices_Old.GetObjectAsync_([In][MarshalAs(UnmanagedType.BStr)]  string strObjectPath,
                                              [In] Int32 lFlags,
                                              [In][MarshalAs(UnmanagedType.Interface)]  IWbemContext pCtx,
                                              [In][MarshalAs(UnmanagedType.Interface)]  IWbemObjectSink pResponseHandler)
        {
//            pResponseHandler.SetStatus(0, (int)tag_WBEMSTATUS.WBEM_E_NOT_FOUND, null, null);
//            Marshal.ReleaseComObject(pResponseHandler);
//            return (int)(tag_WBEMSTATUS.WBEM_E_NOT_FOUND);

            Match match = Regex.Match(strObjectPath.ToLower(), "(.*?)\\.instanceid=\"(.*?)\",processid=\"(.*?)\"");

            if (match.Success == false)
            {
                pResponseHandler.SetStatus_(0, (int)tag_WBEMSTATUS.WBEM_E_NOT_FOUND, null, IntPtr.Zero);
                Marshal.ReleaseComObject(pResponseHandler);
                return((int)(tag_WBEMSTATUS.WBEM_E_NOT_FOUND));
            }

            string className  = match.Groups[1].Value;
            string instanceId = match.Groups[2].Value;
            string processId  = match.Groups[3].Value;


            if (Instrumentation.ProcessIdentity != processId)
            {
                pResponseHandler.SetStatus_(0, (int)tag_WBEMSTATUS.WBEM_E_NOT_FOUND, null, IntPtr.Zero);
                Marshal.ReleaseComObject(pResponseHandler);
                return((int)(tag_WBEMSTATUS.WBEM_E_NOT_FOUND));
            }

            int id = ((IConvertible)instanceId).ToInt32(null);

            if (InstrumentedAssembly.mapIDToRef.ContainsKey(id))
            {
                GCHandle h = (GCHandle)InstrumentedAssembly.mapIDToRef[id];
                if (h.IsAllocated)
                {
                    IWbemClassObjectFreeThreaded classObj;
                    pNamespace.GetObject_(h.Target.GetType().Name, 0, pCtx, out classObj, IntPtr.Zero);
                    IWbemClassObjectFreeThreaded inst;
                    classObj.SpawnInstance_(0, out inst);

                    Object o = h.GetHashCode();
                    inst.Put_("InstanceId", 0, ref o, 0);
                    o = Instrumentation.ProcessIdentity;
                    inst.Put_("ProcessId", 0, ref o, 0);
                    ConvertFuncToWMI func = (ConvertFuncToWMI)InstrumentedAssembly.mapTypeToToWMIFunc[h.Target.GetType()];
//                    func(h.Target, inst);
//                    pResponseHandler.Indicate_(1, ref inst);

                    pResponseHandler.SetStatus_(0, 0, null, IntPtr.Zero);
                    Marshal.ReleaseComObject(pResponseHandler);
                    return(0);
                }
            }
            pResponseHandler.SetStatus_(0, (int)tag_WBEMSTATUS.WBEM_E_NOT_FOUND, null, IntPtr.Zero);
            Marshal.ReleaseComObject(pResponseHandler);
            return((int)(tag_WBEMSTATUS.WBEM_E_NOT_FOUND));

#if xxx
            IWbemClassObject classObj = null;
            IWbemCallResult  result   = null;
            pNamespace.GetObject("TestInstance", 0, pCtx, ref classObj, ref result);
            IWbemClassObject inst;
            classObj.SpawnInstance(0, out inst);

            TestInstance testInstance = (TestInstance)mapNameToTestInstance[match.Groups[1].Value];

            Object o = (object)testInstance.name;
            inst.Put("name", 0, ref o, 0);
            o = (object)testInstance.value;
            inst.Put("value", 0, ref o, 0);

            pResponseHandler.Indicate(1, new IWbemClassObject[] { inst });
            pResponseHandler.SetStatus_(0, 0, IntPtr.Zero, IntPtr.Zero);
            Marshal.ReleaseComObject(pResponseHandler);
#endif
        }