internal PolicyLevel (string label, PolicyLevelType type) { this.label = label; _type = type; full_trust_assemblies = new ArrayList (); named_permission_sets = new ArrayList (); }
internal PolicyLevel(PolicyLevelType type, string path, System.Security.Policy.ConfigId configId) { this.m_type = type; this.m_path = path; this.m_loaded = path == null; if (this.m_path == null) { this.m_rootCodeGroup = this.CreateDefaultAllGroup(); this.SetFactoryPermissionSets(); this.SetDefaultFullTrustAssemblies(); } this.m_configId = configId; }
private void DeriveTypeFromLabel() { if (this.m_label.Equals(Environment.GetResourceString("Policy_PL_User"))) { this.m_type = PolicyLevelType.User; } else if (this.m_label.Equals(Environment.GetResourceString("Policy_PL_Machine"))) { this.m_type = PolicyLevelType.Machine; } else if (this.m_label.Equals(Environment.GetResourceString("Policy_PL_Enterprise"))) { this.m_type = PolicyLevelType.Enterprise; } else { if (!this.m_label.Equals(Environment.GetResourceString("Policy_PL_AppDomain"))) { throw new ArgumentException(Environment.GetResourceString("Policy_Default")); } this.m_type = PolicyLevelType.AppDomain; } }
static public PolicyLevel LoadPolicyLevelFromFile( String path, PolicyLevelType type ) { if (path == null) throw new ArgumentNullException( "path" ); ConfigId id = SharedStatics.GetNextConfigId(); ConfigRetval retval = Config.InitData( id, path ); if ((retval & ConfigRetval.ConfigFile) == 0) throw new ArgumentException( Environment.GetResourceString( "Argument_PolicyFileDoesNotExist" ) ); String name = Enum.GetName( typeof( PolicyLevelType ), type ); if (name == null) return null; String fullPath = Path.GetFullPath( path ); FileIOPermission perm = new FileIOPermission( PermissionState.None ); perm.AddPathList( FileIOPermissionAccess.Read, fullPath ); perm.AddPathList( FileIOPermissionAccess.Write, fullPath ); perm.Demand(); PolicyLevel level = new PolicyLevel( name, id, type == PolicyLevelType.Machine ); level.ThrowOnLoadError = true; level.CheckLoaded( false ); return level; }
// Hardcode defaults in case // (a) the specified policy file doesn't exists; and // (b) no corresponding default policy file exists internal void CreateDefaultLevel (PolicyLevelType type) { PolicyStatement psu = new PolicyStatement (DefaultPolicies.FullTrust); switch (type) { case PolicyLevelType.Machine: // by default all stuff is in the machine policy... PolicyStatement psn = new PolicyStatement (DefaultPolicies.Nothing); root_code_group = new UnionCodeGroup (new AllMembershipCondition (), psn); root_code_group.Name = "All_Code"; UnionCodeGroup myComputerZone = new UnionCodeGroup (new ZoneMembershipCondition (SecurityZone.MyComputer), psu); myComputerZone.Name = "My_Computer_Zone"; // TODO: strongname code group for ECMA and MS keys root_code_group.AddChild (myComputerZone); UnionCodeGroup localIntranetZone = new UnionCodeGroup (new ZoneMembershipCondition (SecurityZone.Intranet), new PolicyStatement (DefaultPolicies.LocalIntranet)); localIntranetZone.Name = "LocalIntranet_Zone"; // TODO: same site / same directory root_code_group.AddChild (localIntranetZone); PolicyStatement psi = new PolicyStatement (DefaultPolicies.Internet); UnionCodeGroup internetZone = new UnionCodeGroup (new ZoneMembershipCondition (SecurityZone.Internet), psi); internetZone.Name = "Internet_Zone"; // TODO: same site root_code_group.AddChild (internetZone); UnionCodeGroup restrictedZone = new UnionCodeGroup (new ZoneMembershipCondition (SecurityZone.Untrusted), psn); restrictedZone.Name = "Restricted_Zone"; root_code_group.AddChild (restrictedZone); UnionCodeGroup trustedZone = new UnionCodeGroup (new ZoneMembershipCondition (SecurityZone.Trusted), psi); trustedZone.Name = "Trusted_Zone"; // TODO: same site root_code_group.AddChild (trustedZone); break; case PolicyLevelType.User: case PolicyLevelType.Enterprise: case PolicyLevelType.AppDomain: // while the other policies don't restrict anything root_code_group = new UnionCodeGroup (new AllMembershipCondition (), psu); root_code_group.Name = "All_Code"; break; } }
private PolicyLevel Load(string xml, PolicyLevelType type) { return(SecurityManager.LoadPolicyLevelFromString(xml, type)); // return SecurityManager.LoadPolicyLevelFromFile (@"C:\WINDOWS\Microsoft.NET\Framework\v1.0.3705\CONFIG\minimal.config", type); }
public static PolicyLevel LoadPolicyLevelFromString(string str, PolicyLevelType type) { return(SecurityManager.LoadPolicyLevelFromStringHelper(str, null, type)); }
public static PolicyLevel LoadPolicyLevelFromFile(string path, PolicyLevelType type) { throw new NotSupportedException(); }
internal static string GetLocationFromType (PolicyLevelType type) { switch (type) { case PolicyLevelType.User: return Config.UserDirectory + "security.config"; case PolicyLevelType.Machine: return Config.MachineDirectory + "security.config"; case PolicyLevelType.Enterprise: return Config.MachineDirectory + "enterprisesec.config"; default: return null; } }
private static PolicyLevel LoadPolicyLevelFromStringHelper (string str, string path, PolicyLevelType type) { if (str == null) throw new ArgumentNullException( "str" ); Contract.EndContractBlock(); PolicyLevel level = new PolicyLevel(type, path); Parser parser = new Parser( str ); SecurityElement elRoot = parser.GetTopElement(); if (elRoot == null) throw new ArgumentException( String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString( "Policy_BadXml" ), "configuration" ) ); SecurityElement elMscorlib = elRoot.SearchForChildByTag( "mscorlib" ); if (elMscorlib == null) throw new ArgumentException( String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString( "Policy_BadXml" ), "mscorlib" ) ); SecurityElement elSecurity = elMscorlib.SearchForChildByTag( "security" ); if (elSecurity == null) throw new ArgumentException( String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString( "Policy_BadXml" ), "security" ) ); SecurityElement elPolicy = elSecurity.SearchForChildByTag( "policy" ); if (elPolicy == null) throw new ArgumentException( String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString( "Policy_BadXml" ), "policy" ) ); SecurityElement elPolicyLevel = elPolicy.SearchForChildByTag( "PolicyLevel" ); if (elPolicyLevel != null) level.FromXml( elPolicyLevel ); else throw new ArgumentException( String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString( "Policy_BadXml" ), "PolicyLevel" ) ); return level; }
public static System.Security.Policy.PolicyLevel LoadPolicyLevelFromString(string str, PolicyLevelType type) { }
public static System.Security.Policy.PolicyLevel LoadPolicyLevelFromString(string str, PolicyLevelType type) { }
public static System.Security.Policy.PolicyLevel LoadPolicyLevelFromFile(string path, PolicyLevelType type) { }
public static PolicyLevel LoadPolicyLevelFromFile (string path, PolicyLevelType type) { throw new NotSupportedException (); }
public static PolicyLevel LoadPolicyLevelFromString (string str, PolicyLevelType type) { throw new NotSupportedException (); }
public static System.Security.Policy.PolicyLevel LoadPolicyLevelFromFile(string path, PolicyLevelType type) { Contract.Ensures(Contract.Result<System.Security.Policy.PolicyLevel>() != null); return default(System.Security.Policy.PolicyLevel); }
// Token: 0x06001E18 RID: 7704 RVA: 0x0006907C File Offset: 0x0006727C private static PolicyLevel LoadPolicyLevelFromStringHelper(string str, string path, PolicyLevelType type) { if (str == null) { throw new ArgumentNullException("str"); } PolicyLevel policyLevel = new PolicyLevel(type, path); Parser parser = new Parser(str); SecurityElement topElement = parser.GetTopElement(); if (topElement == null) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Policy_BadXml"), "configuration")); } SecurityElement securityElement = topElement.SearchForChildByTag("mscorlib"); if (securityElement == null) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Policy_BadXml"), "mscorlib")); } SecurityElement securityElement2 = securityElement.SearchForChildByTag("security"); if (securityElement2 == null) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Policy_BadXml"), "security")); } SecurityElement securityElement3 = securityElement2.SearchForChildByTag("policy"); if (securityElement3 == null) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Policy_BadXml"), "policy")); } SecurityElement securityElement4 = securityElement3.SearchForChildByTag("PolicyLevel"); if (securityElement4 != null) { policyLevel.FromXml(securityElement4); return(policyLevel); } throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Policy_BadXml"), "PolicyLevel")); }
internal PolicyLevel (PolicyLevelType type, string path) : this (type, path, ConfigId.None) {}
static public PolicyLevel LoadPolicyLevelFromString( String str, PolicyLevelType type ) { #if _DEBUG if (debug) { DEBUG_OUT( "Input string =" ); DEBUG_OUT( str ); } #endif if (str == null) throw new ArgumentNullException( "str" ); String name = Enum.GetName( typeof( PolicyLevelType ), type ); if (name == null) return null; Parser parser = new Parser( str ); PolicyLevel level = new PolicyLevel( name, ConfigId.None, type == PolicyLevelType.Machine ); SecurityElement elRoot = parser.GetTopElement(); if (elRoot == null) { throw new ArgumentException( String.Format( Environment.GetResourceString( "Policy_BadXml" ), "configuration" ) ); } SecurityElement elMscorlib = elRoot.SearchForChildByTag( "mscorlib" ); if (elMscorlib == null) { throw new ArgumentException( String.Format( Environment.GetResourceString( "Policy_BadXml" ), "mscorlib" ) ); } SecurityElement elSecurity = elMscorlib.SearchForChildByTag( "security" ); if (elSecurity == null) { throw new ArgumentException( String.Format( Environment.GetResourceString( "Policy_BadXml" ), "security" ) ); } SecurityElement elPolicy = elSecurity.SearchForChildByTag( "policy" ); if (elPolicy == null) { throw new ArgumentException( String.Format( Environment.GetResourceString( "Policy_BadXml" ), "policy" ) ); } SecurityElement elPolicyLevel = elPolicy.SearchForChildByTag( "PolicyLevel" ); if (elPolicyLevel != null) { level.FromXml( elPolicyLevel ); } else { throw new ArgumentException( String.Format( Environment.GetResourceString( "Policy_BadXml" ), "PolicyLevel" ) ); } level.Loaded = true; return level; }
static public PolicyLevel LoadPolicyLevelFromFile(string path, PolicyLevelType type) { if (path == null) throw new ArgumentNullException( "path" ); Contract.EndContractBlock(); if (!AppDomain.CurrentDomain.IsLegacyCasPolicyEnabled) { throw new NotSupportedException(Environment.GetResourceString("NotSupported_RequiresCasPolicyExplicit")); } // We need to retain V1.x compatibility by throwing the same exception type. if (!File.InternalExists(path)) throw new ArgumentException( Environment.GetResourceString("Argument_PolicyFileDoesNotExist")); String fullPath = Path.GetFullPath( path ); FileIOPermission perm = new FileIOPermission( PermissionState.None ); perm.AddPathList( FileIOPermissionAccess.Read, fullPath ); perm.AddPathList( FileIOPermissionAccess.Write, fullPath ); perm.Demand(); using (FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read)) { using (StreamReader reader = new StreamReader(stream)) { return LoadPolicyLevelFromStringHelper(reader.ReadToEnd(), path, type); } } }
public static PolicyLevel LoadPolicyLevelFromFile(string path, PolicyLevelType type) { return default(PolicyLevel); }
public static PolicyLevel LoadPolicyLevelFromFile (string path, PolicyLevelType type) { if (path == null) throw new ArgumentNullException ("path"); PolicyLevel pl = null; try { pl = new PolicyLevel (type.ToString (), type); pl.LoadFromFile (path); } catch (Exception e) { throw new ArgumentException (Locale.GetText ("Invalid policy XML"), e); } return pl; }
public static PolicyLevel LoadPolicyLevelFromString(string str, PolicyLevelType type) { return default(PolicyLevel); }
public static System.Security.Policy.PolicyLevel LoadPolicyLevelFromFile (string path, PolicyLevelType type) { Contract.Requires(path != null); return default(System.Security.Policy.PolicyLevel); }
static PolicyLevel GetLevel( PolicyLevelType type ) { IEnumerator enumerator; try { enumerator = SecurityManager.PolicyHierarchy(); } catch (SecurityException) { Error(null, String.Format(CultureInfo.CurrentCulture, manager.GetString("Error_InsufficientRightsToRetrieveLevel")), -1); // not reached return null; } while (enumerator.MoveNext()) { PolicyLevel level = (PolicyLevel)enumerator.Current; if (level.Type.Equals( type )) { return level; } } return null; }
public static PolicyLevel LoadPolicyLevelFromString(string str, PolicyLevelType type) { throw new NotSupportedException(); }
private static PolicyLevel LoadPolicyLevelFromStringHelper(string str, string path, PolicyLevelType type) { if (str == null) { throw new ArgumentNullException("str"); } Contract.EndContractBlock(); PolicyLevel level = new PolicyLevel(type, path); Parser parser = new Parser(str); SecurityElement elRoot = parser.GetTopElement(); if (elRoot == null) { throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Policy_BadXml"), "configuration")); } SecurityElement elMscorlib = elRoot.SearchForChildByTag("mscorlib"); if (elMscorlib == null) { throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Policy_BadXml"), "mscorlib")); } SecurityElement elSecurity = elMscorlib.SearchForChildByTag("security"); if (elSecurity == null) { throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Policy_BadXml"), "security")); } SecurityElement elPolicy = elSecurity.SearchForChildByTag("policy"); if (elPolicy == null) { throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Policy_BadXml"), "policy")); } SecurityElement elPolicyLevel = elPolicy.SearchForChildByTag("PolicyLevel"); if (elPolicyLevel != null) { level.FromXml(elPolicyLevel); } else { throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Policy_BadXml"), "PolicyLevel")); } return(level); }
public static PolicyLevel LoadPolicyLevelFromFile(string path, PolicyLevelType type) { PolicyLevel level; if (path == null) { throw new ArgumentNullException("path"); } if (!AppDomain.CurrentDomain.IsLegacyCasPolicyEnabled) { throw new NotSupportedException(Environment.GetResourceString("NotSupported_RequiresCasPolicyExplicit")); } if (!File.InternalExists(path)) { throw new ArgumentException(Environment.GetResourceString("Argument_PolicyFileDoesNotExist")); } string fullPath = Path.GetFullPath(path); FileIOPermission permission = new FileIOPermission(PermissionState.None); permission.AddPathList(FileIOPermissionAccess.Read, fullPath); permission.AddPathList(FileIOPermissionAccess.Write, fullPath); permission.Demand(); using (FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read)) { using (StreamReader reader = new StreamReader(stream)) { level = LoadPolicyLevelFromStringHelper(reader.ReadToEnd(), path, type); } } return level; }
private static PolicyLevel LoadPolicyLevelFromStringHelper(string str, string path, PolicyLevelType type) { if (str == null) { throw new ArgumentNullException("str"); } PolicyLevel level = new PolicyLevel(type, path); SecurityElement topElement = new Parser(str).GetTopElement(); if (topElement == null) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Policy_BadXml"), new object[] { "configuration" })); } SecurityElement element2 = topElement.SearchForChildByTag("mscorlib"); if (element2 == null) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Policy_BadXml"), new object[] { "mscorlib" })); } SecurityElement element3 = element2.SearchForChildByTag("security"); if (element3 == null) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Policy_BadXml"), new object[] { "security" })); } SecurityElement element4 = element3.SearchForChildByTag("policy"); if (element4 == null) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Policy_BadXml"), new object[] { "policy" })); } SecurityElement e = element4.SearchForChildByTag("PolicyLevel"); if (e == null) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Policy_BadXml"), new object[] { "PolicyLevel" })); } level.FromXml(e); return level; }
public static PolicyLevel LoadPolicyLevelFromFile(string path, PolicyLevelType type) { return(default(PolicyLevel)); }
static public PolicyLevel LoadPolicyLevelFromString(String str, PolicyLevelType type) { #if _DEBUG if (debug) { DEBUG_OUT("Input string ="); DEBUG_OUT(str); } #endif if (str == null) { throw new ArgumentNullException("str"); } String name = Enum.GetName(typeof(PolicyLevelType), type); if (name == null) { return(null); } Parser parser = new Parser(str); PolicyLevel level = new PolicyLevel(name, ConfigId.None, type == PolicyLevelType.Machine); SecurityElement elRoot = parser.GetTopElement(); if (elRoot == null) { throw new ArgumentException(String.Format(Environment.GetResourceString("Policy_BadXml"), "configuration")); } SecurityElement elMscorlib = elRoot.SearchForChildByTag("mscorlib"); if (elMscorlib == null) { throw new ArgumentException(String.Format(Environment.GetResourceString("Policy_BadXml"), "mscorlib")); } SecurityElement elSecurity = elMscorlib.SearchForChildByTag("security"); if (elSecurity == null) { throw new ArgumentException(String.Format(Environment.GetResourceString("Policy_BadXml"), "security")); } SecurityElement elPolicy = elSecurity.SearchForChildByTag("policy"); if (elPolicy == null) { throw new ArgumentException(String.Format(Environment.GetResourceString("Policy_BadXml"), "policy")); } SecurityElement elPolicyLevel = elPolicy.SearchForChildByTag("PolicyLevel"); if (elPolicyLevel != null) { level.FromXml(elPolicyLevel); } else { throw new ArgumentException(String.Format(Environment.GetResourceString("Policy_BadXml"), "PolicyLevel")); } level.Loaded = true; return(level); }
internal PolicyLevel(PolicyLevelType type, string path) : this(type, path, System.Security.Policy.ConfigId.None) { }
public static System.Security.Policy.PolicyLevel LoadPolicyLevelFromString(string str, PolicyLevelType type) { Contract.Requires(str != null); return(default(System.Security.Policy.PolicyLevel)); }
public static System.Security.Policy.PolicyLevel LoadPolicyLevelFromFile(string path, PolicyLevelType type) { }
public static System.Security.Policy.PolicyLevel LoadPolicyLevelFromFile(string path, PolicyLevelType type) { Contract.Requires(path != null); return(default(System.Security.Policy.PolicyLevel)); }
internal PolicyLevel (PolicyLevelType type) : this (type, GetLocationFromType(type)) {}
}// WizFinish internal bool CreateMyMSIFile(String sNameOfFileToPackage, String sNameOfMSIFile, PolicyLevelType polType) { int nRet = 0; IntPtr hDatabase = (IntPtr)0; try { // Get the path off of the MSI File to create. int nEndOfDirectory = sNameOfMSIFile.LastIndexOf('\\'); String sDirectory = sNameOfMSIFile.Substring(0, nEndOfDirectory + 1); int nEndOfXMLDirectory = sNameOfFileToPackage.LastIndexOf('\\'); String sFileName = sNameOfFileToPackage.Substring(nEndOfXMLDirectory + 1); // First, create the cab file CreateCab(sNameOfFileToPackage, sDirectory + "SECXML.CAB"); // Ok, now we need to create our MSI file.... ugh IntPtr hView = (IntPtr)0; IntPtr hNewRecord = (IntPtr)0; // Create a GUID unique to this installation package String sMyGuid = "{" + System.Guid.NewGuid().ToString().ToUpper(CultureInfo.InvariantCulture) + "}"; // Copy our template file to the file we want to create byte[] bMSITemplate = null; if (polType == PolicyLevelType.User) { bMSITemplate = CResourceStore.GetMSI("USER_MSI"); } else { bMSITemplate = CResourceStore.GetMSI("MACHINE_MSI"); } // Save this template.... try { FileStream fs = new FileStream(sNameOfMSIFile, FileMode.Create); fs.Write(bMSITemplate, 0, bMSITemplate.Length); fs.Close(); } catch (Exception) { MessageBox(String.Format(CResourceStore.GetString("CCreateDeploymentPackageWizard:ErrorWritingFile"), sNameOfMSIFile), CResourceStore.GetString("CCreateDeploymentPackageWizard:ErrorWritingFileTitle"), MB.ICONEXCLAMATION); return(false); } nRet = MsiOpenDatabase(sNameOfMSIFile, 1, out hDatabase); if (nRet != 0) { throw new Exception("Error opening database file 1"); } //----------------------------------------- // First, add a GUID to this MSI (so we don't need to worry about cached MSIs) //----------------------------------------- IntPtr hSummaryInfo; nRet = MsiGetSummaryInformation(hDatabase, null, 15, out hSummaryInfo); if (nRet != 0) { throw new Exception("MsiGetSummaryInformation failed 2"); } // Place the guid in our table nRet = MsiSummaryInfoSetProperty(hSummaryInfo, PIDSI_REVNUMBER, VT_LPSTR, 0, 0, sMyGuid); if (nRet != 0) { throw new Exception("MsiSummaryInfoSetProperty failed 3"); } // Save this change nRet = MsiSummaryInfoPersist(hSummaryInfo); if (nRet != 0) { throw new Exception("MsiSummaryInfoPersist 4"); } MsiCloseHandle(hSummaryInfo); //----------------------------------------- // Now put this guid in as the product code //----------------------------------------- hNewRecord = MsiCreateRecord(2); nRet = MsiRecordSetString(hNewRecord, 1, "ProductCode"); if (nRet != 0) { throw new Exception("MsiRecordSetString 5"); } nRet = MsiRecordSetString(hNewRecord, 2, sMyGuid); if (nRet != 0) { throw new Exception("MsiRecordSetString 6"); } nRet = MsiDatabaseOpenView(hDatabase, "INSERT INTO Property (Property, Value) VALUES (?, ?)", out hView); if (nRet != 0) { throw new Exception("MsiDatabaseOpenView 7"); } nRet = MsiViewExecute(hView, hNewRecord); if (nRet != 0) { throw new Exception("MsiViewExecute 8"); } MsiCloseHandle(hView); MsiCloseHandle(hNewRecord); //----------------------------------------- // Now put this Product Name in //----------------------------------------- String sProductName; if (polType == PolicyLevelType.User) { sProductName = CResourceStore.GetString("CCreateDeploymentPackageWizard:UserPolicy"); } else if (polType == PolicyLevelType.Machine) { sProductName = CResourceStore.GetString("CCreateDeploymentPackageWizard:MachinePolicy"); } else // an Enterprise level { sProductName = CResourceStore.GetString("CCreateDeploymentPackageWizard:EnterprisePolicy"); } hNewRecord = MsiCreateRecord(2); nRet = MsiRecordSetString(hNewRecord, 1, "ProductName"); if (nRet != 0) { throw new Exception("MsiRecordSetString 5"); } nRet = MsiRecordSetString(hNewRecord, 2, sProductName); if (nRet != 0) { throw new Exception("MsiRecordSetString 6"); } nRet = MsiDatabaseOpenView(hDatabase, "INSERT INTO Property (Property, Value) VALUES (?, ?)", out hView); if (nRet != 0) { throw new Exception("MsiDatabaseOpenView 7"); } nRet = MsiViewExecute(hView, hNewRecord); if (nRet != 0) { throw new Exception("MsiViewExecute 8"); } MsiCloseHandle(hView); MsiCloseHandle(hNewRecord); //----------------------------------------- // Now put in the Version //----------------------------------------- // We'll get the version of mscorlib that we're running with.... // Mscorlib should be providing us with the int type Assembly ast = Assembly.GetAssembly(typeof(object)); // This should give us something like // c:\winnt\complus\v1.x86chk\mscorlib.dll // We need to strip off the version... aka, we're after // v1.x86chk String sBase = ast.Location.Replace('/', '\\'); String[] sPieces = sBase.Split(new char[] { '\\' }); String sVersion = sPieces[sPieces.Length - 2]; hNewRecord = MsiCreateRecord(2); nRet = MsiRecordSetString(hNewRecord, 1, "ProductVersion"); if (nRet != 0) { throw new Exception("MsiRecordSetString 5"); } // The version needs to be a real version, and not something funky, // like v1.x86chk or even v1.2.3.4. Right now, we'll just put in // the version of mscorlib.dll as a hard coded string, and replace it // in RTM when SBS isn't completely screwed up. When everything is working // correctly, we will be able to put in sVersion and we'll be set. nRet = MsiRecordSetString(hNewRecord, 2, "1.0.2411.0"); if (nRet != 0) { throw new Exception("MsiRecordSetString 6"); } nRet = MsiDatabaseOpenView(hDatabase, "INSERT INTO Property (Property, Value) VALUES (?, ?)", out hView); if (nRet != 0) { throw new Exception("MsiDatabaseOpenView 7"); } nRet = MsiViewExecute(hView, hNewRecord); if (nRet != 0) { throw new Exception("MsiViewExecute 8"); } MsiCloseHandle(hView); MsiCloseHandle(hNewRecord); //----------------------------------------- // Now put the file info in.... //----------------------------------------- hNewRecord = MsiCreateRecord(5); // Put in the File "Key" nRet = MsiRecordSetString(hNewRecord, 1, sFileName); if (nRet != 0) { throw new Exception("MsiRecordSetString 9"); } // Put in the Component value nRet = MsiRecordSetString(hNewRecord, 2, "NETSECURITY"); if (nRet != 0) { throw new Exception("MsiRecordSetString 10"); } // Put in the filename nRet = MsiRecordSetString(hNewRecord, 3, sFileName + "|" + sFileName); if (nRet != 0) { throw new Exception("MsiRecordSetString 11"); } // Put in the file length nRet = MsiRecordSetInteger(hNewRecord, 4, (int)(new FileInfo(sNameOfFileToPackage).Length)); if (nRet != 0) { throw new Exception("MsiRecordSetString 12"); } // Put in the sequence number nRet = MsiRecordSetInteger(hNewRecord, 5, 1); if (nRet != 0) { throw new Exception("MsiRecordSetString"); } nRet = MsiDatabaseOpenView(hDatabase, "INSERT INTO File (File, Component_, FileName, FileSize, Sequence) VALUES (?, ?, ?, ?, ?)", out hView); if (nRet != 0) { throw new Exception("MsiDatabaseOpenView 13"); } nRet = MsiViewExecute(hView, hNewRecord); if (nRet != 0) { throw new Exception("MsiViewExecute 14"); } MsiCloseHandle(hView); MsiCloseHandle(hNewRecord); //----------------------------------------- // MSI has this nasty habit in that it won't write // over a pre-existing file if that pre-existing file // is newer than the file that we're trying to install. // We'll get around that by having MSI delete any file // that might exist before we try and install our packaged one //----------------------------------------- hNewRecord = MsiCreateRecord(5); // Put in the FileKey nRet = MsiRecordSetString(hNewRecord, 1, sFileName); if (nRet != 0) { throw new Exception("MsiRecordSetString 9"); } // Put in the Component value nRet = MsiRecordSetString(hNewRecord, 2, "NETSECURITY"); if (nRet != 0) { throw new Exception("MsiRecordSetString 10"); } // Put in the filename nRet = MsiRecordSetString(hNewRecord, 3, sFileName); if (nRet != 0) { throw new Exception("MsiRecordSetString 11"); } // Put in the Directory if (polType == PolicyLevelType.User) { nRet = MsiRecordSetString(hNewRecord, 4, "VERSIONDIRECTORY"); } else { nRet = MsiRecordSetString(hNewRecord, 4, "CONFIGDIRECTORY"); } if (nRet != 0) { throw new Exception("MsiRecordSetString 12"); } // Put in the install mode // We'll put in an install mode of '1'. That means that this // file will only be removed when we are installing a package. nRet = MsiRecordSetInteger(hNewRecord, 5, 1); if (nRet != 0) { throw new Exception("MsiRecordSetString"); } nRet = MsiDatabaseOpenView(hDatabase, "INSERT INTO RemoveFile (FileKey, Component_, FileName, DirProperty, InstallMode) VALUES (?, ?, ?, ?, ?)", out hView); if (nRet != 0) { throw new Exception("MsiDatabaseOpenView 13"); } nRet = MsiViewExecute(hView, hNewRecord); if (nRet != 0) { throw new Exception("MsiViewExecute 14"); } MsiCloseHandle(hView); MsiCloseHandle(hNewRecord); //----------------------------------------- // Now put the directory entry.... //----------------------------------------- hNewRecord = MsiCreateRecord(3); // Put in the Directory "Key" nRet = MsiRecordSetString(hNewRecord, 1, "VERSIONDIRECTORY"); if (nRet != 0) { throw new Exception("MsiRecordSetString 9"); } // Put in the Display Parent value if (polType == PolicyLevelType.User) { nRet = MsiRecordSetString(hNewRecord, 2, "CLRSECURITYCONFIG"); } else { nRet = MsiRecordSetString(hNewRecord, 2, "CLRINSTALLROOT"); } if (nRet != 0) { throw new Exception("MsiRecordSetString 10"); } // Put in the filename nRet = MsiRecordSetString(hNewRecord, 3, sVersion + "|" + sVersion); if (nRet != 0) { throw new Exception("MsiRecordSetString 11"); } nRet = MsiDatabaseOpenView(hDatabase, "INSERT INTO Directory (Directory, Directory_Parent, DefaultDir) VALUES (?, ?, ?)", out hView); if (nRet != 0) { throw new Exception("MsiDatabaseOpenView 13"); } nRet = MsiViewExecute(hView, hNewRecord); if (nRet != 0) { throw new Exception("MsiViewExecute 14"); } MsiCloseHandle(hView); MsiCloseHandle(hNewRecord); //----------------------------------------- // Now add the new cab to the MSI file //----------------------------------------- hNewRecord = MsiCreateRecord(2); if (hNewRecord == (IntPtr)0) { throw new Exception("MsiCreateRecord failed 15"); } nRet = MsiRecordSetString(hNewRecord, 1, "SECXML.CAB"); if (nRet != 0) { throw new Exception("MsiRecordSetString failed 16"); } nRet = MsiRecordSetStream(hNewRecord, 2, sDirectory + "SECXML.CAB"); if (nRet != 0) { throw new Exception("MsiRecordSetStream failed 17"); } nRet = MsiDatabaseOpenView(hDatabase, "INSERT INTO `_Streams` (Name, Data) VALUES (?, ?)", out hView); if (nRet != 0) { throw new Exception("MsiDatabaseOpenView failed 19"); } nRet = MsiViewExecute(hView, hNewRecord); if (nRet != 0) { throw new Exception("MsiViewExecute failed 20"); } MsiCloseHandle(hView); MsiCloseHandle(hNewRecord); //----------------------------------------- // Now put in the error message we'll display // if the .NET framework isn't installed on the machine // the user tries to deploy this package to. But, we'll only // do this if we're dealing with a machine or enterprise policy // deployment //----------------------------------------- if (polType != PolicyLevelType.User) { hNewRecord = MsiCreateRecord(3); if (hNewRecord == (IntPtr)0) { throw new Exception("MsiCreateRecord failed"); } nRet = MsiRecordSetString(hNewRecord, 1, "VERIFYINSTALLROOT"); if (nRet != 0) { throw new Exception("MsiRecordSetString failed"); } nRet = MsiRecordSetInteger(hNewRecord, 2, 19); if (nRet != 0) { throw new Exception("MsiRecordSetInteger"); } nRet = MsiRecordSetString(hNewRecord, 3, CResourceStore.GetString("CCreateDeploymentPackageWizard:FrameworkNotExist")); if (nRet != 0) { throw new Exception("MsiRecordSetString"); } nRet = MsiDatabaseOpenView(hDatabase, "INSERT INTO `CustomAction` (Action, Type, Target) VALUES (?, ?, ?)", out hView); if (nRet != 0) { throw new Exception("MsiDatabaseOpenView failed"); } nRet = MsiViewExecute(hView, hNewRecord); if (nRet != 0) { throw new Exception("MsiViewExecute failed"); } MsiCloseHandle(hView); MsiCloseHandle(hNewRecord); } //----------------------------------------- // Update the LockPermissions table // // We only need to worry about this if we're working with either the // machine policy or the enterprise policy //----------------------------------------- if (polType != PolicyLevelType.User) { nRet = MsiDatabaseOpenView(hDatabase, "SELECT * FROM `LockPermissions`", out hView); if (nRet != 0) { throw new Exception("MsiDatabaseOpenView failed " + nRet.ToString()); } nRet = MsiViewExecute(hView, (IntPtr)0); if (nRet != 0) { throw new Exception("MsiViewExecute failed"); } IntPtr hRecord; nRet = MsiViewFetch(hView, out hRecord); if (nRet != 0) { throw new Exception("MsiViewFetch failed " + nRet.ToString()); } nRet = MsiRecordSetString(hRecord, 1, sFileName); if (nRet != 0) { throw new Exception("MsiRecordSetString failed " + nRet.ToString()); } /*nRet = MsiViewModify(hView, 2, hRecord); * if (nRet != 0) * throw new Exception("MsiRecordSetStream failed"); */ MsiCloseHandle(hView); MsiCloseHandle(hRecord); } //----------------------------------------- // Commit the change to the MSI file //----------------------------------------- MsiDatabaseCommit(hDatabase); MsiCloseHandle(hDatabase); //----------------------------------------- // Now remove the cab file we created on the disk //----------------------------------------- File.Delete(sDirectory + "SECXML.CAB"); return(true); } catch (Exception) { MsiCloseHandle(hDatabase); MessageBox(String.Format(CResourceStore.GetString("CCreateDeploymentPackageWizard:ErrorEditingFile"), sNameOfMSIFile), CResourceStore.GetString("CCreateDeploymentPackageWizard:ErrorEditingFileTitle"), MB.ICONEXCLAMATION); // Try and delete the file we were creating. File.Delete(sNameOfMSIFile); return(false); } }// CreateMyMSIFile
internal PolicyLevel (PolicyLevelType type, string path, ConfigId configId) { m_type = type; m_path = path; m_loaded = (path == null); if (m_path == null) { m_rootCodeGroup = CreateDefaultAllGroup(); SetFactoryPermissionSets(); SetDefaultFullTrustAssemblies(); } m_configId = configId; }
public static PolicyLevel LoadPolicyLevelFromString(string str, PolicyLevelType type) { return(LoadPolicyLevelFromStringHelper(str, null, type)); }
private void DeriveTypeFromLabel() { if(m_label.Equals(Environment.GetResourceString("Policy_PL_User"))) m_type = System.Security.PolicyLevelType.User; else if(m_label.Equals(Environment.GetResourceString("Policy_PL_Machine"))) m_type = System.Security.PolicyLevelType.Machine; else if(m_label.Equals(Environment.GetResourceString("Policy_PL_Enterprise"))) m_type = System.Security.PolicyLevelType.Enterprise; else if(m_label.Equals(Environment.GetResourceString("Policy_PL_AppDomain"))) m_type = System.Security.PolicyLevelType.AppDomain; else throw new ArgumentException(Environment.GetResourceString("Policy_Default")); }
private static PolicyLevel LoadPolicyLevelFromStringHelper(string str, string path, PolicyLevelType type) { if (str == null) { throw new ArgumentNullException("str"); } PolicyLevel level = new PolicyLevel(type, path); SecurityElement topElement = new Parser(str).GetTopElement(); if (topElement == null) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Policy_BadXml"), new object[] { "configuration" })); } SecurityElement element2 = topElement.SearchForChildByTag("mscorlib"); if (element2 == null) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Policy_BadXml"), new object[] { "mscorlib" })); } SecurityElement element3 = element2.SearchForChildByTag("security"); if (element3 == null) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Policy_BadXml"), new object[] { "security" })); } SecurityElement element4 = element3.SearchForChildByTag("policy"); if (element4 == null) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Policy_BadXml"), new object[] { "policy" })); } SecurityElement e = element4.SearchForChildByTag("PolicyLevel"); if (e == null) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Policy_BadXml"), new object[] { "PolicyLevel" })); } level.FromXml(e); return(level); }
static public PolicyLevel LoadPolicyLevelFromString(string str, PolicyLevelType type) { return LoadPolicyLevelFromStringHelper(str, null, type); }
public static PolicyLevel LoadPolicyLevelFromString(string str, PolicyLevelType type) { return(default(PolicyLevel)); }
private PolicyLevel Load (string xml, PolicyLevelType type) { return SecurityManager.LoadPolicyLevelFromString (xml, type); // return SecurityManager.LoadPolicyLevelFromFile (@"C:\WINDOWS\Microsoft.NET\Framework\v1.0.3705\CONFIG\minimal.config", type); }
public static System.Security.Policy.PolicyLevel LoadPolicyLevelFromString (string str, PolicyLevelType type) { Contract.Requires(str != null); return default(System.Security.Policy.PolicyLevel); }
public static PolicyLevel LoadPolicyLevelFromString (string str, PolicyLevelType type) { if (null == str) throw new ArgumentNullException ("str"); PolicyLevel pl = null; try { pl = new PolicyLevel (type.ToString (), type); pl.LoadFromString (str); } catch (Exception e) { throw new ArgumentException (Locale.GetText ("Invalid policy XML"), e); } return pl; }
private static PolicyLevel LoadPolicyLevelFromStringHelper(string str, string path, PolicyLevelType type) { if (str == null) { throw new ArgumentNullException("str"); } PolicyLevel policyLevel = new PolicyLevel(type, path); SecurityElement topElement = new Parser(str).GetTopElement(); if (topElement == null) { throw new ArgumentException(string.Format((IFormatProvider)CultureInfo.CurrentCulture, Environment.GetResourceString("Policy_BadXml"), (object)"configuration")); } string tag1 = "mscorlib"; SecurityElement securityElement1 = topElement.SearchForChildByTag(tag1); if (securityElement1 == null) { throw new ArgumentException(string.Format((IFormatProvider)CultureInfo.CurrentCulture, Environment.GetResourceString("Policy_BadXml"), (object)"mscorlib")); } string tag2 = "security"; SecurityElement securityElement2 = securityElement1.SearchForChildByTag(tag2); if (securityElement2 == null) { throw new ArgumentException(string.Format((IFormatProvider)CultureInfo.CurrentCulture, Environment.GetResourceString("Policy_BadXml"), (object)"security")); } string tag3 = "policy"; SecurityElement securityElement3 = securityElement2.SearchForChildByTag(tag3); if (securityElement3 == null) { throw new ArgumentException(string.Format((IFormatProvider)CultureInfo.CurrentCulture, Environment.GetResourceString("Policy_BadXml"), (object)"policy")); } string tag4 = "PolicyLevel"; SecurityElement e = securityElement3.SearchForChildByTag(tag4); if (e == null) { throw new ArgumentException(string.Format((IFormatProvider)CultureInfo.CurrentCulture, Environment.GetResourceString("Policy_BadXml"), (object)"PolicyLevel")); } policyLevel.FromXml(e); return(policyLevel); }