Exemplo n.º 1
0
        internal static string ConvertSidToSDDL(byte[] sid)
        {
            string sddlSid = null;

            // To put the byte[] SID into SDDL, we use ConvertSidToStringSid.
            // Calling that requires we first copy the SID into native memory.
            IntPtr pSid = IntPtr.Zero;

            try
            {
                pSid = ConvertByteArrayToIntPtr(sid);

                if (UnsafeNativeMethods.ConvertSidToStringSid(pSid, ref sddlSid))
                {
                    return(sddlSid);
                }
                else
                {
                    int lastErrorCode = Marshal.GetLastWin32Error();

                    GlobalDebug.WriteLineIf(
                        GlobalDebug.Warn,
                        "Utils",
                        "ConvertSidToSDDL: ConvertSidToStringSid failed, " + lastErrorCode);
                    return(null);
                }
            }
            finally
            {
                if (pSid != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(pSid);
                }
            }
        }
Exemplo n.º 2
0
        internal static string ConvertSidToSDDL(byte[] sid)
        {
            string str;
            string str1 = null;
            IntPtr zero = IntPtr.Zero;

            try
            {
                zero = Utils.ConvertByteArrayToIntPtr(sid);
                if (!UnsafeNativeMethods.ConvertSidToStringSid(zero, ref str1))
                {
                    Marshal.GetLastWin32Error();
                    str = null;
                }
                else
                {
                    str = str1;
                }
            }
            finally
            {
                if (zero != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(zero);
                }
            }
            return(str);
        }