Пример #1
0
        private ShareSecurity TranslateShareACL(ShareSecurity sourceSecurity)
        {
            ShareSecurity destSecurity = new ShareSecurity();
            Dictionary <string, string> danglingSids = new Dictionary <string, string>();

            // 1. Get sddl string
            string sourceSDDL = sourceSecurity.GetSecurityDescriptorSddlForm(AccessControlSections.All);

            // 2. Gather table of sid translations
            List <AuthorizationRule> authorizationRules = new List <AuthorizationRule>();

            authorizationRules.AddRange(sourceSecurity.GetAccessRules(true, false, typeof(NTAccount)).Cast <AuthorizationRule>().ToArray());
            authorizationRules.AddRange(sourceSecurity.GetAuditRules(true, false, typeof(NTAccount)).Cast <AuthorizationRule>().ToArray());
            danglingSids = AssembleSidTranslationTable(authorizationRules);

            // apply dest sid on new file
            string destSDDL = sourceSDDL;

            foreach (string danglingSID in danglingSids.Keys)
            {
                destSDDL = destSDDL.Replace(danglingSID, danglingSids[danglingSID]);
            }

            destSecurity.SetSecurityDescriptorSddlForm(destSDDL);

            return(destSecurity);
        }
Пример #2
0
 public void CopyShareSecurity(NTShare sourceShare, NTShare destShare)
 {
     ActionObserver.NotifyAction("Copying", "Share Security", sourceShare.FullName, destShare.FullName);
     try {
         ShareSecurity sourceSecurity = sourceShare.GetAccessControl();
         NTShare.SetAccessControl(
             destShare.FullName,
             TranslateShareACL(
                 sourceShare.GetAccessControl()
                 )
             );
     } catch (Exception error) {
         ActionObserver.NotifyActionFailed("Copying", "Share Security", sourceShare.FullName, destShare.FullName, error.Message);
     }
 }
Пример #3
0
 public static void SetAccessControl(string path, ShareSecurity security)
 {
     security.Persist(path);
 }
Пример #4
0
 public void SetAccessControl(ShareSecurity security)
 {
     SetAccessControl(FullName, security);
 }