Exemple #1
0
        protected override void ProcessRecord()
        {
            using (RegistryKey regKey = RegistryControl.GetRegistryKey(RegistryPath, false, false))
            {
                if (regKey != null)
                {
                    return;
                }
            }

            //  テスト自動生成
            _generator.RegistryPath(RegistryPath);

            using (RegistryKey regKey = RegistryControl.GetRegistryKey(RegistryPath, true, true))
            {
                RegistrySecurity security = null;

                //  Access文字列からの設定
                if (!string.IsNullOrEmpty(Access))
                {
                    if (security == null)
                    {
                        security = regKey.GetAccessControl();
                    }

                    //  テスト自動生成
                    _generator.RegistryAccess(RegistryPath, Access, false);

                    foreach (RegistryAccessRule rule in RegistryControl.StringToAccessRules(Access))
                    {
                        security.AddAccessRule(rule);
                    }
                }

                //  上位からのアクセス権継承の設定変更
                if (Inherited != Item.NONE)
                {
                    if (security == null)
                    {
                        security = regKey.GetAccessControl();
                    }

                    //  テスト自動生成
                    _generator.RegistryInherited(RegistryPath, Inherited == Item.ENABLE);

                    switch (Inherited)
                    {
                    case Item.ENABLE:
                        security.SetAccessRuleProtection(false, false);
                        break;

                    case Item.DISABLE:
                        security.SetAccessRuleProtection(true, true);
                        break;

                    case Item.REMOVE:
                        security.SetAccessRuleProtection(true, false);
                        break;
                    }
                }

                if (security != null)
                {
                    regKey.SetAccessControl(security);
                }
            }

            //  所有者変更
            if (Owner != null)
            {
                //  埋め込みのsubinacl.exeを展開
                string subinacl = EmbeddedResource.GetSubinacl(Item.APPLICATION_NAME);

                //  管理者実行確認
                Functions.CheckAdmin();

                //  テスト自動生成
                _generator.RegistryOwner(RegistryPath, Owner);

                using (Process proc = new Process())
                {
                    proc.StartInfo.FileName    = subinacl;
                    proc.StartInfo.Arguments   = $"/subkeyreg \"{RegistryPath}\" /owner=\"{Owner}\"";
                    proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                    proc.Start();
                    proc.WaitForExit();
                }
            }

            using (RegistryKey regKey = RegistryControl.GetRegistryKey(RegistryPath, false, false))
            {
                WriteObject(new RegistrySummary(regKey, true));
            }
        }
Exemple #2
0
        protected override void ProcessRecord()
        {
            if (Directory.Exists(DirectoryPath)) { return; }

            //  テスト自動生成
            _generator.DirectoryPath(DirectoryPath);

            Directory.CreateDirectory(DirectoryPath);

            DirectorySecurity security = null;

            //  Access設定
            if (!string.IsNullOrEmpty(Access))
            {
                if (security == null) { security = Directory.GetAccessControl(DirectoryPath); }

                //  テスト自動生成
                _generator.DirectoryAccess(DirectoryPath, Access, false);

                foreach (FileSystemAccessRule addRule in DirectoryControl.StringToAccessRules(Access))
                {
                    security.AddAccessRule(addRule);
                }
            }

            //  Owner設定
            if (!string.IsNullOrEmpty(Owner))
            {
                //  埋め込みのsubinacl.exeを展開
                string subinacl = EmbeddedResource.GetSubinacl(Item.APPLICATION_NAME);

                //  管理者実行確認
                Functions.CheckAdmin();

                //  テスト自動生成
                _generator.DirectoryOwner(DirectoryPath, Owner);

                using (Process proc = new Process())
                {
                    proc.StartInfo.FileName = subinacl;
                    proc.StartInfo.Arguments = $"/subdirectories \"{DirectoryPath}\" /setowner=\"{Owner}\"";
                    proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                    proc.Start();
                    proc.WaitForExit();
                }
            }

            //  Inherited設定
            if (Inherited != Item.NONE)
            {
                if (security == null) { security = Directory.GetAccessControl(DirectoryPath); }

                //  テスト自動生成
                _generator.DirectoryInherited(DirectoryPath, Inherited == Item.ENABLE);

                switch (Inherited)
                {
                    case Item.ENABLE:
                        security.SetAccessRuleProtection(false, false);
                        break;
                    case Item.DISABLE:
                        security.SetAccessRuleProtection(true, true);
                        break;
                    case Item.REMOVE:
                        security.SetAccessRuleProtection(true, false);
                        break;
                }
            }

            if (security != null) { Directory.SetAccessControl(DirectoryPath, security); }

            //  作成日時
            if (CreationTime != null)
            {
                //  テスト自動生成
                _generator.DirectoryCreationTime(DirectoryPath, (DateTime)CreationTime);

                Directory.SetCreationTime(DirectoryPath, (DateTime)CreationTime);
            }

            //  更新一時
            if (LastWriteTime != null)
            {
                //  テスト自動生成
                _generator.DirectoryLastWriteTime(DirectoryPath, (DateTime)LastWriteTime);

                Directory.SetLastWriteTime(DirectoryPath, (DateTime)LastWriteTime);
            }

            //  フォルダー属性
            if (!string.IsNullOrEmpty(_Attributes))
            {
                //  テスト自動生成
                _generator.DirectoryAttributes(DirectoryPath, _Attributes, false);

                if (!_Attributes.Contains(Item.DIRECTORY))
                {
                    _Attributes += ", " + Item.DIRECTORY;
                }
                File.SetAttributes(DirectoryPath, (FileAttributes)Enum.Parse(typeof(FileAttributes), _Attributes));
            }

            WriteObject(new DirectorySummary(DirectoryPath, true));
        }
Exemple #3
0
        protected override void ProcessRecord()
        {
            using (RegistryKey regKey = RegistryControl.GetRegistryKey(RegistryPath, true, true))
            {
                if (regKey == null)
                {
                    return;
                }

                RegistrySecurity security = null;

                //  Access文字列からの設定
                //  ""で全アクセス権設定を削除
                if (Access != null)
                {
                    if (security == null)
                    {
                        security = regKey.GetAccessControl();
                    }
                    foreach (RegistryAccessRule removeRule in security.GetAccessRules(true, false, typeof(NTAccount)))
                    {
                        security.RemoveAccessRule(removeRule);
                    }

                    //  テスト自動生成
                    _generator.RegistryAccess(RegistryPath, Access, false);

                    if (Access != string.Empty)     //  このif文分岐が無くても同じ挙動するけれど、一応記述
                    {
                        foreach (RegistryAccessRule addRule in RegistryControl.StringToAccessRules(Access))
                        {
                            security.AddAccessRule(addRule);
                        }
                    }
                }

                //  上位からのアクセス権継承の設定変更
                if (Inherited != Item.NONE)
                {
                    if (security == null)
                    {
                        security = regKey.GetAccessControl();
                    }

                    //  テスト自動生成
                    _generator.RegistryInherited(RegistryPath, Inherited == Item.ENABLE);

                    switch (Inherited)
                    {
                    case Item.ENABLE:
                        security.SetAccessRuleProtection(false, false);
                        break;

                    case Item.DISABLE:
                        security.SetAccessRuleProtection(true, true);
                        break;

                    case Item.REMOVE:
                        security.SetAccessRuleProtection(true, false);
                        break;
                    }
                }

                if (security != null)
                {
                    regKey.SetAccessControl(security);
                }
            }

            //  所有者変更
            if (Owner != null)
            {
                string subinacl = EmbeddedResource.GetSubinacl(Item.APPLICATION_NAME);

                //  管理者実行確認
                Functions.CheckAdmin();

                //  テスト自動生成
                _generator.RegistryOwner(RegistryPath, Owner);

                using (Process proc = new Process())
                {
                    proc.StartInfo.FileName    = subinacl;
                    proc.StartInfo.Arguments   = $"/subkeyreg \"{RegistryPath}\" /owner=\"{Owner}\"";
                    proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                    proc.Start();
                    proc.WaitForExit();
                }
            }

            //  レジストリ値の設定
            if (Name != null)
            {
                //  テスト自動生成
                _generator.RegistryType(RegistryPath, Name, Type);
                _generator.RegistryValue(RegistryPath, Name, Value);

                switch (Type)
                {
                case Item.REG_SZ:
                    Registry.SetValue(RegistryPath, Name, Value, RegistryValueKind.String);
                    break;

                case Item.REG_BINARY:
                    Registry.SetValue(RegistryPath, Name, RegistryControl.StringToRegBinary(Value), RegistryValueKind.Binary);
                    break;

                case Item.REG_DWORD:
                    Registry.SetValue(RegistryPath, Name, int.Parse(Value), RegistryValueKind.DWord);
                    break;

                case Item.REG_QWORD:
                    Registry.SetValue(RegistryPath, Name, long.Parse(Value), RegistryValueKind.QWord);
                    break;

                case Item.REG_MULTI_SZ:
                    Registry.SetValue(RegistryPath, Name, Functions.SplitBQt0(Value), RegistryValueKind.MultiString);
                    break;

                case Item.REG_EXPAND_SZ:
                    Registry.SetValue(RegistryPath, Name, Value, RegistryValueKind.ExpandString);
                    break;

                case Item.REG_NONE:
                    Registry.SetValue(RegistryPath, Name, new byte[2] {
                        0, 0
                    }, RegistryValueKind.None);
                    break;
                }
            }

            /*  実行していて結構うっとおしいので、出力しないことにします。
             * using (RegistryKey regKey = RegistryControl.GetRegistryKey(Path, false, false))
             * {
             *  WriteObject(new RegistrySummary(regKey, true));
             * }
             */
        }
Exemple #4
0
        protected override void ProcessRecord()
        {
            if (Directory.Exists(DirectoryPath))
            {
                DirectorySecurity security = null;

                //  Access設定
                //  ""で全アクセス権設定を削除
                if (Access != null)
                {
                    if (security == null)
                    {
                        security = Directory.GetAccessControl(DirectoryPath);
                    }

                    //  テスト自動生成
                    _generator.DirectoryAccess(DirectoryPath, Access, false);

                    foreach (FileSystemAccessRule removeRule in security.GetAccessRules(true, false, typeof(NTAccount)))
                    {
                        security.RemoveAccessRule(removeRule);
                    }
                    if (Access != string.Empty)     //  このif文分岐が無くても同じ挙動するけれど、一応記述
                    {
                        foreach (FileSystemAccessRule addRule in DirectoryControl.StringToAccessRules(Access))
                        {
                            security.AddAccessRule(addRule);
                        }
                    }
                }

                //  Owner設定
                if (!string.IsNullOrEmpty(Owner))
                {
                    //  埋め込みのsubinacl.exeを展開
                    string subinacl = EmbeddedResource.GetSubinacl(Item.APPLICATION_NAME);

                    //  管理者実行確認
                    Functions.CheckAdmin();

                    //  テスト自動生成
                    _generator.DirectoryOwner(DirectoryPath, Owner);

                    using (Process proc = new Process())
                    {
                        proc.StartInfo.FileName    = subinacl;
                        proc.StartInfo.Arguments   = $"/subdirectories \"{DirectoryPath}\" /setowner=\"{Owner}\"";
                        proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                        proc.Start();
                        proc.WaitForExit();
                    }
                }

                //  Inherited設定
                if (Inherited != Item.NONE)
                {
                    if (security == null)
                    {
                        security = Directory.GetAccessControl(DirectoryPath);
                    }

                    //  テスト自動生成
                    _generator.DirectoryInherited(DirectoryPath, Inherited == Item.ENABLE);

                    switch (Inherited)
                    {
                    case Item.ENABLE:
                        security.SetAccessRuleProtection(false, false);
                        break;

                    case Item.DISABLE:
                        security.SetAccessRuleProtection(true, true);
                        break;

                    case Item.REMOVE:
                        security.SetAccessRuleProtection(true, false);
                        break;
                    }
                }

                if (security != null)
                {
                    Directory.SetAccessControl(DirectoryPath, security);
                }

                //  作成日時
                if (CreationTime != null)
                {
                    //  テスト自動生成
                    _generator.DirectoryCreationTime(DirectoryPath, (DateTime)CreationTime);

                    Directory.SetCreationTime(DirectoryPath, (DateTime)CreationTime);
                }

                //  更新一時
                if (LastWriteTime != null)
                {
                    //  テスト自動生成
                    _generator.DirectoryLastWriteTime(DirectoryPath, (DateTime)LastWriteTime);

                    Directory.SetLastWriteTime(DirectoryPath, (DateTime)LastWriteTime);
                }

                //  フォルダー属性
                if (!string.IsNullOrEmpty(_Attributes))
                {
                    //  テスト自動生成
                    _generator.DirectoryAttributes(DirectoryPath, _Attributes, false);

                    if (!_Attributes.Contains(Item.DIRECTORY))
                    {
                        _Attributes += ", " + Item.DIRECTORY;
                    }
                    File.SetAttributes(DirectoryPath, (FileAttributes)Enum.Parse(typeof(FileAttributes), _Attributes));
                }

                //  セキュリティブロックの解除
                if (RemoveSecurityBlock)
                {
                    foreach (string fileName in Directory.GetFiles(DirectoryPath, "*", SearchOption.AllDirectories))
                    {
                        //  テスト自動生成
                        _generator.FileSecurityBlock(fileName, false);

                        FileControl.RemoveSecurityBlock(fileName);
                    }
                }

                /*  実行していて結構うっとおしいので、出力しないことにします。
                 * WriteObject(new DirectorySummary(Path, true));
                 */
            }
        }
Exemple #5
0
        private void SetFileProcess()
        {
            FileSecurity security = null;

            //  Access設定
            //  ""で全アクセス権設定を削除
            if (Access != null)
            {
                if (security == null)
                {
                    security = File.GetAccessControl(FilePath);
                }

                //  テスト自動生成
                _generator.FileAccess(FilePath, Access, false);

                foreach (FileSystemAccessRule removeRule in security.GetAccessRules(true, false, typeof(NTAccount)))
                {
                    security.RemoveAccessRule(removeRule);
                }
                if (Access != string.Empty)     //  このif文分岐が無くても同じ挙動するけれど、一応記述
                {
                    foreach (FileSystemAccessRule addRule in FileControl.StringToAccessRules(Access))
                    {
                        security.AddAccessRule(addRule);
                    }
                }
            }

            //  Owner設定
            if (!string.IsNullOrEmpty(Owner))
            {
                //  埋め込みのsubinacl.exeを展開
                string subinacl = EmbeddedResource.GetSubinacl(Item.APPLICATION_NAME);

                //  管理者実行確認
                Functions.CheckAdmin();

                //  テスト自動生成
                _generator.FileOwner(FilePath, Owner);

                using (Process proc = new Process())
                {
                    proc.StartInfo.FileName    = subinacl;
                    proc.StartInfo.Arguments   = $"/file \"{FilePath}\" /setowner=\"{Owner}\"";
                    proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                    proc.Start();
                    proc.WaitForExit();
                }
            }

            //  Inherited設定
            if (Inherited != Item.NONE)
            {
                if (security == null)
                {
                    security = File.GetAccessControl(FilePath);
                }

                //  テスト自動生成
                _generator.FileInherited(FilePath, Inherited == Item.ENABLE);

                switch (Inherited)
                {
                case Item.ENABLE:
                    security.SetAccessRuleProtection(false, false);
                    break;

                case Item.DISABLE:
                    security.SetAccessRuleProtection(true, true);
                    break;

                case Item.REMOVE:
                    security.SetAccessRuleProtection(true, false);
                    break;
                }
            }

            if (security != null)
            {
                File.SetAccessControl(FilePath, security);
            }

            //  作成日時
            if (CreationTime != null)
            {
                //  テスト自動生成
                _generator.FileCreationTime(FilePath, (DateTime)CreationTime);

                File.SetCreationTime(FilePath, (DateTime)CreationTime);
            }

            //  更新一時
            if (LastWriteTime != null)
            {
                //  テスト自動生成
                _generator.FileLastWriteTime(FilePath, (DateTime)LastWriteTime);

                File.SetLastWriteTime(FilePath, (DateTime)LastWriteTime);
            }

            //  ファイル属性
            //if (!string.IsNullOrEmpty(Attributes))
            if (!string.IsNullOrEmpty(_Attributes))
            {
                //  テスト自動生成
                _generator.FileAttributes(FilePath, _Attributes, false);

                File.SetAttributes(FilePath, (FileAttributes)Enum.Parse(typeof(FileAttributes), _Attributes));
            }

            //  セキュリティブロックの解除
            if (RemoveSecurityBlock)
            {
                //  テスト自動生成
                _generator.FileSecurityBlock(FilePath, false);

                FileControl.RemoveSecurityBlock(FilePath);
            }

            /*  実行していて結構うっとおしいので、出力しないことにします。
             * WriteObject(new FileSummary(Path, true));
             */
        }
Exemple #6
0
        protected override void ProcessRecord()
        {
            if (Directory.Exists(FilePath) || File.Exists(FilePath))
            {
                return;
            }

            //  テスト自動生成
            _generator.FilePath(FilePath);

            File.CreateText(FilePath).Close();

            FileSecurity security = null;

            //  Access設定
            if (!string.IsNullOrEmpty(Access))
            {
                if (security == null)
                {
                    security = File.GetAccessControl(FilePath);
                }

                /*
                 * foreach (FileSystemAccessRule removeRule in security.GetAccessRules(true, false, typeof(NTAccount)))
                 * {
                 *  security.RemoveAccessRule(removeRule);
                 * }
                 */

                //  テスト自動生成
                _generator.FileAccess(FilePath, Access, false);

                foreach (FileSystemAccessRule addRule in FileControl.StringToAccessRules(Access))
                {
                    security.AddAccessRule(addRule);
                }
            }

            //  Owner設定
            if (!string.IsNullOrEmpty(Owner))
            {
                string subinacl = EmbeddedResource.GetSubinacl(Item.APPLICATION_NAME);

                //  管理者実行確認
                Functions.CheckAdmin();

                //  テスト自動生成
                _generator.FileOwner(FilePath, Owner);

                using (Process proc = new Process())
                {
                    proc.StartInfo.FileName    = subinacl;
                    proc.StartInfo.Arguments   = $"/file \"{FilePath}\" /setowner=\"{Owner}\"";
                    proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                    proc.Start();
                    proc.WaitForExit();
                }
            }

            //  Inherited設定
            if (Inherited != Item.NONE)
            {
                if (security == null)
                {
                    security = File.GetAccessControl(FilePath);
                }

                //  テスト自動生成
                _generator.FileInherited(FilePath, Inherited == Item.ENABLE);

                switch (Inherited)
                {
                case Item.ENABLE:
                    security.SetAccessRuleProtection(false, false);
                    break;

                case Item.DISABLE:
                    security.SetAccessRuleProtection(true, true);
                    break;

                case Item.REMOVE:
                    security.SetAccessRuleProtection(true, false);
                    break;
                }
            }

            if (security != null)
            {
                File.SetAccessControl(FilePath, security);
            }

            //  作成日時
            if (CreationTime != null)
            {
                //  テスト自動生成
                _generator.FileCreationTime(FilePath, (DateTime)CreationTime);

                File.SetCreationTime(FilePath, (DateTime)CreationTime);
            }

            //  更新一時
            if (LastWriteTime != null)
            {
                //  テスト自動生成
                _generator.FileLastWriteTime(FilePath, (DateTime)LastWriteTime);

                File.SetLastWriteTime(FilePath, (DateTime)LastWriteTime);
            }

            //  ファイル属性
            if (!string.IsNullOrEmpty(_Attributes))
            {
                //  テスト自動生成
                _generator.FileAttributes(FilePath, _Attributes, false);

                File.SetAttributes(FilePath, (FileAttributes)Enum.Parse(typeof(FileAttributes), _Attributes));
            }

            WriteObject(new FileSummary(FilePath, true));
        }