示例#1
0
        /// <summary>
        /// Derive a package sid from a name.
        /// </summary>
        /// <param name="name">The name of the package.</param>
        /// <returns>The derived Sid</returns>
        public static Sid DerivePackageSidFromName(string name)
        {
            int hr = Win32NativeMethods.DeriveAppContainerSidFromAppContainerName(name, out SafeSidBufferHandle sid);

            if (hr != 0)
            {
                Marshal.ThrowExceptionForHR(hr);
            }

            using (sid)
            {
                return(new Sid(sid));
            }
        }
示例#2
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)
                {
                    return(new Sid(sid).CreateResult());
                }
            }

            return(((NtStatus)hr).CreateResultFromError <Sid>(throw_on_error));
        }
示例#3
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);
                    return(NtSecurity.CacheSidName(result, string.Empty, name,
                                                   SidNameSource.Package, SidNameUse.User).CreateResult());
                }
            }

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