/// <summary> /// アクセス権チェック /// </summary> /// <param name="regKey"></param> private void CheckAccess(RegistryKey regKey) { string tempAccess = new RegistrySummary(regKey, false, true).Access; if (Access == string.Empty) { retValue = string.IsNullOrEmpty(tempAccess); if (!retValue) { Console.Error.WriteLine("指定のアクセス権無し: \"{0}\" / \"{1}\"", Access, tempAccess); } } else if (TestMode == Item.CONTAIN) { // Accessパラメータで指定したAccess文字列が、対象のレジストリキーに含まれているかチェック // Access文字列は複数の場合は、全て対象のレジストリキーに含まれているかをチェック //string tempAccess = new RegistrySummary(regKey, false, true).Access; string[] tempAccessArray = tempAccess.Split('/'); foreach (string accessString in Access.Split('/')) { retValue = tempAccessArray.Any(x => RegistryControl.IsMatchAccess(x, accessString)); if (!retValue) { Console.Error.WriteLine("指定のアクセス権無し: {0} / {1}", Access, tempAccess); break; } } } else { List <string> accessListA = new List <string>(); accessListA.AddRange(tempAccess.Split('/')); List <string> accessListB = new List <string>(); accessListB.AddRange(Access.Split('/')); if (accessListA.Count == accessListB.Count) { for (int i = accessListA.Count - 1; i >= 0; i--) { string matchString = accessListB.FirstOrDefault(x => RegistryControl.IsMatchAccess(x, accessListA[i])); if (matchString != null) { accessListB.Remove(matchString); } } retValue = accessListB.Count == 0; } else { retValue = false; } if (!retValue) { Console.Error.WriteLine("アクセス権不一致: {0} / {1}", Access, tempAccess); } } }
/// <summary> /// RegistrySummaryリストを取得 /// </summary> /// <param name="path">レジストリキーのパス</param> /// <param name="ignoreSecurity">セキュリティ情報を除外して比較</param> /// <param name="ignoreValues">レジストリ値を場外して比較</param> /// <returns></returns> private List <RegistrySummary> GetSummaryList(string path, bool ignoreSecurity, bool ignoreValues) { int startLength = 0; List <RegistrySummary> summaryList = new List <RegistrySummary>(); Action <RegistryKey> getSummary = null; getSummary = (targetPath) => { RegistrySummary summary = new RegistrySummary(targetPath, startLength, ignoreSecurity, ignoreValues); summary.Name = ""; summaryList.Add(summary); //summaryList.Add(new RegistrySummary(targetPath, startLength, ignoreSecurity, ignoreValues)); foreach (string keyName in targetPath.GetSubKeyNames()) { using (RegistryKey subTargetKey = targetPath.OpenSubKey(keyName, false)) { getSummary(subTargetKey); } } }; using (RegistryKey startKey = RegistryControl.GetRegistryKey(path, false, false)) { startLength = startKey.Name.Length; getSummary(startKey); } return(summaryList); }
/// <summary> /// 所有者チェック /// </summary> /// <param name="regKey"></param> private void CheckOwner(RegistryKey regKey) { string tempOwner = new RegistrySummary(regKey, false, true).Owner; retValue = tempOwner == Owner; if (!retValue) { Console.Error.WriteLine("所有者名不一致: {0} / {1}", Owner, tempOwner); } }
/// <summary> /// Accountチェック /// </summary> /// <param name="regKey"></param> private void CheckAccount(RegistryKey regKey) { string tempAccess = new RegistrySummary(regKey, false, true).Access; foreach (string tempAccessString in tempAccess.Split('/')) { string tempAccount = tempAccessString.Split(';')[0]; retValue = Account.Contains("\\") && tempAccount.Equals(Account, StringComparison.OrdinalIgnoreCase) || !Account.Contains("\\") && tempAccount.EndsWith("\\" + Account, StringComparison.OrdinalIgnoreCase); if (retValue) { break; } } if (!retValue) { Console.Error.WriteLine("対象アカウントのアクセス権無し: {0} / {1}", Account, tempAccess); } }