Example #1
0
        // this method is called by SecurityInfoCCW.SetSecurity in order to handle
        // security information saving process
        // it stores the data into the registry
        // [saves data from UI to registry]
        public void SetSecurity(
            SecurityInfos providedInformation,
            IntPtr pSecurityDescriptor
            )
        {
            string             stringSecurityDescriptor = "";
            SecurityIdentifier sid;

            IntPtr pszSD;
            int    size = 0;

#pragma warning suppress 56523
            bool ret = SafeNativeMethods.ConvertSecurityDescriptorToStringSecurityDescriptorW(
                pSecurityDescriptor,
                1 /* SDDL_REVISION_1 == 1 (according to specs, this should always be 1 */,
                providedInformation,
                out pszSD,
                out size
                );
            if (!ret)
            {
                current.KerberosGlobalAcl = new string[] { "" };
                return;
            }

            stringSecurityDescriptor = Marshal.PtrToStringUni(pszSD);
#pragma warning suppress 56523
            SafeNativeMethods.LocalFree(pszSD);

            ArrayList        allowed = new ArrayList();
            RawAcl           rawDacl = new RawSecurityDescriptor(stringSecurityDescriptor).DiscretionaryAcl;
            DiscretionaryAcl dacl    = new DiscretionaryAcl(false, false, rawDacl);

            for (int i = 0; i < dacl.Count; i++)
            {
                if (((CommonAce)dacl[i]).AceType == AceType.AccessAllowed)
                {
                    sid = ((CommonAce)dacl[i]).SecurityIdentifier;
                    allowed.Add(sid.Translate(typeof(NTAccount)).Value);
                }
            }

            current.KerberosGlobalAcl = (string[])allowed.ToArray(typeof(string));
        }