示例#1
0
            public SafeDsHandle(SafeDsPasswordCredentialsHandle authIdentity, string dnsDomainName = null, string domainControllerName = null) : base(true)
            {
                var res = DsBindWithCred(domainControllerName, dnsDomainName, authIdentity, out handle);

                if (res != NO_ERROR)
                {
                    throw new Win32Exception((int)res);
                }
            }
示例#2
0
            /// <summary>Initializes a new instance of the <see cref="SafeDsHandle"/> class from a user credential and then bound to a domain and/or DC.</summary>
            /// <remarks>
            /// The behavior of the constructor is determined by the contents of the domainControllerName and dnsDomainName parameters. The following list
            /// describes the behavior of this constructor based on the contents of these parameters.
            /// <list type="table">
            /// <listheader><description>domainControllerName</description><description>dnsDomainName</description><description>Description</description></listheader>
            /// <item><description><c>NULL</c></description><description><c>NULL</c></description><description>Will attempt to bind to a global catalog server in the forest of the local computer.</description></item>
            /// <item><description>(value)</description><description><c>NULL</c></description><description>Will attempt to bind to the domain controller specified by the domainControllerName parameter.</description></item>
            /// <item><description><c>NULL</c></description><description>(value)</description><description>Will attempt to bind to any domain controller in the domain specified by dnsDomainName parameter.</description></item>
            /// <item><description>(value)</description><description>(value)</description><description>The domainControllerName parameter takes precedence. Will attempt to bind to the domain controller specified by the domainControllerName parameter.</description></item>
            /// </list>
            /// </remarks>
            /// <param name="authIdentity">
            /// Contains an <see cref="SafeDsPasswordCredentialsHandle"/> value that represents the credentials to be used for the bind.
            /// </param>
            /// <param name="dnsDomainName">
            /// A string that contains the fully qualified DNS name of the domain to bind to. This parameter can be NULL. For more information, see Remarks.
            /// </param>
            /// <param name="domainControllerName">
            /// A string that contains the name of the domain controller to bind to. This name can be the name of the domain controller or the fully qualified
            /// DNS name of the domain controller. Either name type can, optionally, be preceded by two backslash characters. All of the following examples
            /// represent correctly formatted domain controller names:
            /// <list type="bullet">
            /// <item><definition>"FAB-DC-01"</definition></item>
            /// <item><definition>"\\FAB-DC-01"</definition></item>
            /// <item><definition>"FAB-DC-01.fabrikam.com"</definition></item>
            /// <item><definition>"\\FAB-DC-01.fabrikam.com"</definition></item>
            /// </list>
            /// <para>This parameter can be NULL. For more information, see Remarks.</para>
            /// </param>
            public SafeDsHandle(SafeDsPasswordCredentialsHandle authIdentity, string dnsDomainName, string domainControllerName) : base(Release)
            {
                var res = DsBindWithCred(domainControllerName, dnsDomainName, authIdentity, out handle);

                if (res != NO_ERROR)
                {
                    new Win32Error((int)res).ThrowIfFailed();
                }
            }
示例#3
0
        public void DsBindWithCredTest(bool validUser, bool validCred, string urn, string dn, string dc, string domain, string un, string pwd, string notes)
        {
            void Meth()
            {
                SafeDsHandle dsb;

                using (var cred = new SafeDsPasswordCredentialsHandle(un, dn, pwd))
                    using (dsb = new SafeDsHandle(cred, dn, dc))
                        Assert.That(dsb.IsInvalid, Is.False);
                Assert.That(dsb.IsInvalid);
            }

            if (!validUser || !validCred)
            {
                Assert.That(Meth, Throws.Exception);
            }
            else
            {
                Assert.That(Meth, Throws.Nothing);
            }
        }
示例#4
0
 public static extern uint DsBindWithCred(
     string DomainControllerName,                  // in, optional
     string DnsDomainName,                         // in, optional
     SafeDsPasswordCredentialsHandle AuthIdentity, // in, optional
     out IntPtr phDS);