Exemplo n.º 1
0
        private static int TryBind(string server, string domain, SafeDsCredentialsHandle credentials, out SafeDsHandle handle)
        {
            if (credentials != null)
            {
                return(NativeMethods.DsBindWithCred(server, domain, credentials, out handle));
            }

            return(NativeMethods.DsBind(server, domain, out handle));
        }
Exemplo n.º 2
0
        public string CanonicalToDistinguishedName(string cn)
        {
            using (SafeDsCredentialsHandle cred = MakeCredentials())
            {
                using (SafeDsHandle handle = Bind(cred))
                {
                    DsNameResultItem[] items = CrackNames(
                        handle,
                        DsNameFlags.None,
                        DsNameFormat.CanonicalName,
                        DsNameFormat.DistinguishedName,
                        new string[] { cn });

                    foreach (DsNameResultItem item in items)
                    {
                        return(item.pName);
                    }
                }
            }

            return(null);
        }
Exemplo n.º 3
0
        private static SafeDsHandle Bind(string server, string domain, SafeDsCredentialsHandle credentials)
        {
            SafeDsHandle handle;
            int          retval = TryBind(server, domain, credentials, out handle);

            if (retval == NativeMethods.ERROR_INVALID_PARAMETER)
            {
                // HACK: you must specify port number for AD LDS instances, but you MUST NOT
                // specify it when connecting to AD DS domain

                int colon = server.LastIndexOf(':');
                if (colon > -1)
                {
                    server = server.Substring(0, colon);
                }

                retval = TryBind(server, domain, credentials, out handle);
            }

            NativeMethods.EnforceSuccess(retval);

            return(handle);
        }
Exemplo n.º 4
0
 private SafeDsHandle Bind(SafeDsCredentialsHandle credential)
 {
     return(Bind(_serverName, _domainName, credential));
 }