Пример #1
0
        private static void SetSecurity(ObjectSecurity security)
        {
            if (null == security)
            {
                throw new ArgumentNullException("security");
            }

            // Set the DACL.
            security.SetSecurityDescriptorSddlForm("D:(A;;GA;;;WD)", AccessControlSections.Access);

            // Can only set integrity levels in the SACL for Vista and newer.
            Version vista = new Version(6, 0);
            if (vista <= Environment.OSVersion.Version)
            {
                security.SetSecurityDescriptorSddlForm("S:(ML;;NW;;;ME)", AccessControlSections.Audit);
            }
        }
Пример #2
0
 internal static object ConvertFromCimToDotNet(object cimObject, Type expectedDotNetType)
 {
     if (expectedDotNetType != null)
     {
         if (cimObject != null)
         {
             if (expectedDotNetType.IsGenericType && expectedDotNetType.GetGenericTypeDefinition().Equals(typeof(Nullable <>)))
             {
                 expectedDotNetType = expectedDotNetType.GetGenericArguments()[0];
             }
             if (!LanguagePrimitives.IsCimIntrinsicScalarType(expectedDotNetType))
             {
                 if (!expectedDotNetType.Equals(typeof(CimInstance)))
                 {
                     if (expectedDotNetType.IsArray)
                     {
                         Type elementType = CimValueConverter.GetElementType(expectedDotNetType);
                         if (elementType != null)
                         {
                             Array arrays  = (Array)LanguagePrimitives.ConvertTo(cimObject, typeof(Array), CultureInfo.InvariantCulture);
                             Array arrays1 = Array.CreateInstance(elementType, arrays.Length);
                             for (int i = 0; i < arrays1.Length; i++)
                             {
                                 object dotNet = CimValueConverter.ConvertFromCimToDotNet(arrays.GetValue(i), elementType);
                                 arrays1.SetValue(dotNet, i);
                             }
                             return(arrays1);
                         }
                     }
                     Type convertibleCimType = CimValueConverter.GetConvertibleCimType(expectedDotNetType);
                     if (convertibleCimType == null)
                     {
                         Func <Func <object>, object> func = (Func <object> innerAction) => {
                             object obj;
                             try
                             {
                                 obj = innerAction();
                             }
                             catch (Exception exception1)
                             {
                                 Exception exception = exception1;
                                 CommandProcessorBase.CheckForSevereException(exception);
                                 throw CimValueConverter.GetInvalidCastException(exception, "InvalidCimToDotNetCast", cimObject, expectedDotNetType.FullName);
                             }
                             return(obj);
                         }
                         ;
                         if (!typeof(ObjectSecurity).IsAssignableFrom(expectedDotNetType))
                         {
                             if (!typeof(X509Certificate2).Equals(expectedDotNetType))
                             {
                                 if (!typeof(X500DistinguishedName).Equals(expectedDotNetType))
                                 {
                                     if (!typeof(PhysicalAddress).Equals(expectedDotNetType))
                                     {
                                         if (!typeof(IPEndPoint).Equals(expectedDotNetType))
                                         {
                                             if (!typeof(XmlDocument).Equals(expectedDotNetType))
                                             {
                                                 throw CimValueConverter.GetInvalidCastException(null, "InvalidCimToDotNetCast", cimObject, expectedDotNetType.FullName);
                                             }
                                             else
                                             {
                                                 return(func(() => {
                                                     int?nullable = null;
                                                     XmlDocument xmlDocument = InternalDeserializer.LoadUnsafeXmlDocument((string)LanguagePrimitives.ConvertTo(cimObject, typeof(string), CultureInfo.InvariantCulture), true, nullable);
                                                     return xmlDocument;
                                                 }
                                                             ));
                                             }
                                         }
                                         else
                                         {
                                             return(func(() => {
                                                 int num = ((string)LanguagePrimitives.ConvertTo(cimObject, typeof(string), CultureInfo.InvariantCulture)).LastIndexOf(':');
                                                 int num1 = int.Parse(((string)LanguagePrimitives.ConvertTo(cimObject, typeof(string), CultureInfo.InvariantCulture)).Substring(num + 1), NumberStyles.Integer, CultureInfo.InvariantCulture);
                                                 IPAddress pAddress = IPAddress.Parse(((string)LanguagePrimitives.ConvertTo(cimObject, typeof(string), CultureInfo.InvariantCulture)).Substring(0, num));
                                                 return new IPEndPoint(pAddress, num1);
                                             }
                                                         ));
                                         }
                                     }
                                     else
                                     {
                                         return(func(() => PhysicalAddress.Parse((string)LanguagePrimitives.ConvertTo(cimObject, typeof(string), CultureInfo.InvariantCulture))));
                                     }
                                 }
                                 else
                                 {
                                     return(func(() => new X500DistinguishedName((byte[])LanguagePrimitives.ConvertTo(cimObject, typeof(byte[]), CultureInfo.InvariantCulture))));
                                 }
                             }
                             else
                             {
                                 return(func(() => new X509Certificate2((byte[])LanguagePrimitives.ConvertTo(cimObject, typeof(byte[]), CultureInfo.InvariantCulture))));
                             }
                         }
                         else
                         {
                             return(func(() => {
                                 ObjectSecurity objectSecurity = (ObjectSecurity)Activator.CreateInstance(expectedDotNetType);
                                 objectSecurity.SetSecurityDescriptorSddlForm((string)LanguagePrimitives.ConvertTo(cimObject, typeof(string), CultureInfo.InvariantCulture));
                                 return objectSecurity;
                             }
                                         ));
                         }
                     }
                     else
                     {
                         object obj1 = LanguagePrimitives.ConvertTo(cimObject, convertibleCimType, CultureInfo.InvariantCulture);
                         object obj2 = LanguagePrimitives.ConvertTo(obj1, expectedDotNetType, CultureInfo.InvariantCulture);
                         return(obj2);
                     }
                 }
                 else
                 {
                     return(LanguagePrimitives.ConvertTo(cimObject, expectedDotNetType, CultureInfo.InvariantCulture));
                 }
             }
             else
             {
                 return(LanguagePrimitives.ConvertTo(cimObject, expectedDotNetType, CultureInfo.InvariantCulture));
             }
         }
         else
         {
             return(null);
         }
     }
     else
     {
         throw new ArgumentNullException("expectedDotNetType");
     }
 }