Exemplo n.º 1
0
        /// <summary>
        /// Derive a package sid from a name.
        /// </summary>
        /// <param name="name">The name of the package.</param>
        /// <param name="throw_on_error">True to throw on error.</param>
        /// <returns>The derived Sid</returns>
        public static NtResult <Sid> DerivePackageSidFromName(string name, bool throw_on_error)
        {
            int hr = Win32NativeMethods.DeriveAppContainerSidFromAppContainerName(name, out SafeSidBufferHandle sid);

            if (hr == 0)
            {
                using (sid)
                {
                    Sid result = new Sid(sid);
                    NtSecurity.CachePackageName(result, name);
                    return(NtSecurity.CacheSidName(result, string.Empty, name,
                                                   SidNameSource.Package, SidNameUse.User).CreateResult());
                }
            }

            return(((NtStatus)hr).CreateResultFromError <Sid>(throw_on_error));
        }