Esempio n. 1
0
        internal static NtStatus SamConnect(string serverName, out SafeSamHandle serverHandle, SamServerAccessMask accessMask)
        {
            IntPtr        objectAttributes  = IntPtr.Zero;
            UnicodeString unicodeServerName = new UnicodeString(serverName);

            return(SamConnect(ref unicodeServerName, out serverHandle, accessMask, objectAttributes));
        }
Esempio n. 2
0
 public void ReleaseHandle()
 {
     if (this.Handle != null)
     {
         this.Handle.Dispose();
         this.Handle = null;
     }
 }
Esempio n. 3
0
        /// <summary>
        /// The SamQueryInformationDomain method obtains attributes from a domain object.
        /// </summary>
        /// <param name="domainHandle">An RPC context handle, representing a domain object.</param>
        /// <param name="domainPasswordInformation">The requested attributes on output.</param>
        internal static NtStatus SamQueryInformationDomain(SafeSamHandle domainHandle, out SamDomainPasswordInformation domainPasswordInformation)
        {
            SafeSamPointer buffer;
            NtStatus       result = SamQueryInformationDomain(domainHandle, SamDomainInformationClass.PasswordInformation, out buffer);

            domainPasswordInformation = buffer != null?Marshal.PtrToStructure <SamDomainPasswordInformation>(buffer.DangerousGetHandle()) : new SamDomainPasswordInformation();

            return(result);
        }
Esempio n. 4
0
        internal static NtStatus SamLookupDomainInSamServer(SafeSamHandle serverHandle, string domainName, out SecurityIdentifier domainSid)
        {
            UnicodeString unicodeDomainName = new UnicodeString(domainName);

            byte[]   domainIdBinary;
            NtStatus result = SamLookupDomainInSamServer(serverHandle, ref unicodeDomainName, out domainIdBinary);

            if (domainIdBinary != null)
            {
                domainSid = new SecurityIdentifier(domainIdBinary, 0);
            }
            else
            {
                domainSid = null;
            }
            return(result);
        }
Esempio n. 5
0
        internal static NtStatus SamLookupNameInDomain(SafeSamHandle domainHandle, string name, out int relativeId, out SamSidType sidType)
        {
            string[]     names = new string[] { name };
            int[]        relativeIds;
            SamSidType[] use;
            NtStatus     result = SamLookupNamesInDomain(domainHandle, names, out relativeIds, out use);

            if (result == NtStatus.Success)
            {
                relativeId = relativeIds[0];
                sidType    = use[0];
            }
            else
            {
                relativeId = -1;
                sidType    = SamSidType.Unknown;
            }
            return(result);
        }
Esempio n. 6
0
        internal static NtStatus SamConnectWithCreds(string serverName, out SafeSamHandle serverHandle, SamServerAccessMask accessMask, SafeRpcAuthIdentityHandle authIdentity)
        {
            uint          unknown              = 0;
            IntPtr        objectAttributes     = IntPtr.Zero;
            UnicodeString unicodeServerName    = new UnicodeString(serverName);
            string        servicePrincipalName = spnPrefix + serverName;
            NtStatus      result = SamConnectWithCreds(ref unicodeServerName, out serverHandle, accessMask, objectAttributes, authIdentity, servicePrincipalName, out unknown);

            if (result == NtStatus.RpcUnknownAuthenticationService)
            {
                // Try it again, but without the SPN
                servicePrincipalName = null;
                return(SamConnectWithCreds(ref unicodeServerName, out serverHandle, accessMask, objectAttributes, authIdentity, servicePrincipalName, out unknown));
            }
            else
            {
                return(result);
            }
        }
Esempio n. 7
0
        internal static NtStatus SamLookupNamesInDomain(SafeSamHandle domainHandle, string[] names, out int[] relativeIds, out SamSidType[] use)
        {
            Validator.AssertNotNull(names, "names");
            int count = names.Length;

            if (count > 1000)
            {
                // TODO: Extract as resource
                throw new ArgumentOutOfRangeException("names", count, "Cannot translate more than 1000 names at once.");
            }
            // Prepare parameters
            UnicodeString[] unicodeNames = new UnicodeString[count];
            for (int i = 0; i < count; i++)
            {
                unicodeNames[i] = new UnicodeString(names[i]);
            }
            // TODO: SamFreeMemory
            // Call the native function
            return(SamLookupNamesInDomain(domainHandle, count, unicodeNames, out relativeIds, out use));
        }
Esempio n. 8
0
        internal static NtStatus SamLookupNamesInDomain(SafeSamHandle domainHandle, string[] names, out int[] relativeIds, out SamSidType[] use)
        {
            Validator.AssertNotNull(names, "names");
            int count = names.Length;

            if (count > MaxNamesToLookup)
            {
                // TODO: Extract as resource
                throw new ArgumentOutOfRangeException("names", count, "Cannot translate more than 1000 names at once.");
            }

            // Prepare parameters
            SafeSamPointer relativeIdsPointer;
            SafeSamPointer usePointer;

            UnicodeString[] unicodeNames = new UnicodeString[count];
            for (int i = 0; i < count; i++)
            {
                unicodeNames[i] = new UnicodeString(names[i]);
            }

            // Call the native function
            NtStatus result = SamLookupNamesInDomain(domainHandle, count, unicodeNames, out relativeIdsPointer, out usePointer);

            if (result == NtStatus.Success)
            {
                // Marshal pointers into arrays
                relativeIds = new int[count];
                use         = new SamSidType[count];
                Marshal.Copy(relativeIdsPointer.DangerousGetHandle(), relativeIds, 0, count);
                Marshal.Copy(usePointer.DangerousGetHandle(), (int[])(object)use, 0, count);
            }
            else
            {
                relativeIds = null;
                use         = null;
            }

            return(result);
        }
Esempio n. 9
0
 private static extern NtStatus SamLookupNamesInDomain(SafeSamHandle domainHandle, int count, UnicodeString[] names, out SafeSamPointer relativeIds, out SafeSamPointer use);
Esempio n. 10
0
 private static extern NtStatus SamOpenDomain(SafeSamHandle serverHandle, SamDomainAccessMask desiredAccess, [MarshalAs(UnmanagedType.LPArray)] byte[] domainId, out SafeSamHandle domainHandle);
Esempio n. 11
0
 private static extern NtStatus SamQueryInformationDomain(SafeSamHandle domainHandle, SamDomainInformationClass domainInformationClass, out SafeSamPointer buffer);
Esempio n. 12
0
 internal SamUser(SafeSamHandle handle) : base(handle)
 {
 }
Esempio n. 13
0
 internal SamDomain(SafeSamHandle handle) : base(handle)
 {
 }
Esempio n. 14
0
 protected SamObject(SafeSamHandle handle)
 {
     this.Handle = handle;
 }
Esempio n. 15
0
 internal static NtStatus SamSetInformationUser(SafeSamHandle userHandle, ref SamUserInternal1Information passwordInformation)
 {
     return(SamSetInformationUser(userHandle, SamUserInformationClass.Internal1Information, ref passwordInformation));
 }
Esempio n. 16
0
 private static extern NtStatus SamConnect([In] ref UnicodeString serverName, out SafeSamHandle serverHandle, SamServerAccessMask accessMask, IntPtr objectAttributes);
Esempio n. 17
0
 internal static extern NtStatus SamOpenUser(SafeSamHandle domainHandle, SamUserAccessMask desiredAccess, int userId, out SafeSamHandle userHandle);
Esempio n. 18
0
 private static extern NtStatus SamConnectWithCreds([In] ref UnicodeString serverName, out SafeSamHandle serverHandle, SamServerAccessMask accessMask, IntPtr objectAttributes, SafeRpcAuthIdentityHandle authIdentity, [MarshalAs(UnmanagedType.LPWStr)] string servicePrincipalName, out uint unknown);
Esempio n. 19
0
 private static extern NtStatus SamSetInformationUser(SafeSamHandle userHandle, SamUserInformationClass userInformationClass, [In] ref SamUserInternal1Information buffer);
Esempio n. 20
0
 internal static extern NtStatus SamEnumerateDomainsInSamServer(SafeSamHandle serverHandle, ref uint enumerationContext, out SafeSamEnumerationBufferPointer buffer, uint preferedMaximumLength, out uint countReturned);
Esempio n. 21
0
 private static extern NtStatus SamLookupDomainInSamServer(SafeSamHandle serverHandle, [In] ref UnicodeString domainName, [MarshalAs(UnmanagedType.LPArray, SizeConst = 24)] out byte[] domainId);
Esempio n. 22
0
 internal static NtStatus SamOpenDomain(SafeSamHandle serverHandle, SamDomainAccessMask desiredAccess, SecurityIdentifier domainSid, out SafeSamHandle domainHandle)
 {
     byte[] binarySid = domainSid.GetBinaryForm();
     return(SamOpenDomain(serverHandle, desiredAccess, binarySid, out domainHandle));
 }
Esempio n. 23
0
 private static extern NtStatus SamLookupNamesInDomain(SafeSamHandle domainHandle, int count, UnicodeString[] names, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] out int[] relativeIds, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] out SamSidType[] use);