zoukankan      html  css  js  c++  java
  • 设置服务器文件的访问权限


            /// <summary>
            /// 为创建的临时文件分配权限
            /// </summary>
            /// <param name="pathname">文件路径</param>
            /// 如:D:\aqi\Aqioo.Apps\Aqioo.Apps\Aqioo.Apps.Web\xml\constellation.xml
            /// <param name="username">用户名(一般用:ASPNET)</param>
            /// <param name="power">权限</param>
            /// <remarks>SKY 2007-8-6</remarks>
            public static void AddpathPower(string pathname, string username, string power)
            {

                DirectoryInfo dirinfo = new DirectoryInfo(pathname);

                if ((dirinfo.Attributes & FileAttributes.ReadOnly) != 0)
                {
                    dirinfo.Attributes = FileAttributes.Normal;
                }

                //取得访问控制列表
                DirectorySecurity dirsecurity = dirinfo.GetAccessControl();

                switch (power)
                {
                    case "FullControl":
                        dirsecurity.AddAccessRule(new FileSystemAccessRule(username, FileSystemRights.FullControl, InheritanceFlags.ContainerInherit, PropagationFlags.InheritOnly, AccessControlType.Allow));
                        break;
                    case "ReadOnly":
                        dirsecurity.AddAccessRule(new FileSystemAccessRule(username, FileSystemRights.Read, AccessControlType.Allow));
                        break;
                    case "Write":
                        dirsecurity.AddAccessRule(new FileSystemAccessRule(username, FileSystemRights.Write, AccessControlType.Allow));
                        break;
                    case "Modify":
                        dirsecurity.AddAccessRule(new FileSystemAccessRule(username, FileSystemRights.Modify, AccessControlType.Allow));
                        break;
                }
            }

  • 相关阅读:
    Ubuntu下安装KVM
    Ubuntu下配置libvirt环境
    漏洞复现-Flask-SSTI服务端模板注入
    CTF-杂项笔记
    Tomcat后台爆破指南
    漏洞复现-CVE-2018-15473-ssh用户枚举漏洞
    漏洞复现-CVE-2018-8715-Appweb
    漏洞复现-CVE-2016-4437-Shiro反序列化
    漏洞复现-fastjson1.2.24-RCE
    漏洞复现-CVE-2017-4971-Spring Web Flow 远程代码执行
  • 原文地址:https://www.cnblogs.com/yonsy/p/2652636.html
Copyright © 2011-2022 走看看