public System.IntPtr MarshalManagedToNative(object ManagedObj)
        {
            IntPtr memory = Marshal.AllocHGlobal(nativeSize);

            _myAllocated[memory] = memory;
            //Console.WriteLine("MarshalManagedToNative");
            var lus = new LSA_UNICODE_STRING();

            lus.Set(((string)ManagedObj));
            Marshal.StructureToPtr(lus, memory, true);
            return(memory);
        }
Beispiel #2
0
        public IEnumerable <string> EnumerateAllowLogonLocalSids()
        {
            // You should already have the HPolicy and SID ready
            IntPtr rightsPtr;
            int    countOfRights;

            var right = new LSA_UNICODE_STRING();

            right.Set(_seInteractiveLogonRight);

            LsaEnumerateAccountsWithUserRight(_policy, new[] { right }, out rightsPtr, out countOfRights);
            try
            {
                for (Int32 i = 0; i < countOfRights; i++)
                {
                    var structure = rightsPtr.ElementAt <LSA_ENUMERATION_INFORMATION>(i);

                    /*
                     * var name = new StringBuilder();
                     * uint cchName = 0;
                     * uint cchName2 = 0;
                     * var domainName = new StringBuilder();
                     * SID_NAME_USE use;
                     *
                     * LookupAccountSid(null, structure.Sid, name, ref cchName, domainName, ref cchName2, out use);
                     */
                    var str = ConvertSidToStringSid(structure.Sid);
                    // var bytes = ConvertStringSidToSid(str);
                    yield return(str);
                }
            }
            finally
            {
                LsaFreeMemory(rightsPtr);
            }
        }