コード例 #1
0
        /// <summary>Converts a FQDN to an LDAP connection string.</summary>
        /// <param name="domainFqdn">The domain FQDN.</param>
        /// <param name="domainControllerFqdn">The domain controller FQDN to use in this domain. (NOTE: this can be an IP address).</param>
        /// <returns>An LDAP formatted connection string.</returns>
        public static string ToLdapConnectionString(this Fqdn domainFqdn, string domainControllerFqdn)
        {
            if (!IPAddress.TryParse(domainControllerFqdn, out IPAddress ip) && !domainControllerFqdn.ContainsCaseInsensitive(domainFqdn.ToString()))
            {
                throw new ArgumentException($"The {nameof(domainControllerFqdn)} must be in the same domain as the {nameof(domainFqdn)}", nameof(domainControllerFqdn));
            }

            return($"LDAP://{domainControllerFqdn}/{domainFqdn.ToDistinguishedName()}");
        }
コード例 #2
0
        /// <summary>Converts an FQDN and distinguished name to an LDAP connection string.</summary>
        /// <param name="domainFqdn">The domain FQDN.</param>
        /// <param name="dn">The distinguished name.</param>
        /// <returns>An LDAP connection string.</returns>
        /// <exception cref="System.ArgumentException">If the <paramref name="domainFqdn"/>is not a valid FQDN.</exception>
        public static string ToLdapDNConnectionString(this string domainFqdn, string dn)
        {
            var fqdnResult = Fqdn.Create(domainFqdn);

            if (fqdnResult.IsFailure)
            {
                throw new ArgumentException(fqdnResult.Error, nameof(domainFqdn));
            }

            return(fqdnResult.Value.ToLdapDNConnectionString(dn));
        }
コード例 #3
0
        /// <summary>Converts a FQDN and SID to a LDAP connection string.</summary>
        /// <param name="domainFqdn">The domain FQDN.</param>
        /// <param name="sid">The SID.</param>
        /// <returns>An LDAP connection string.</returns>
        /// <exception cref="System.ArgumentException">
        /// If <paramref name="domainFqdn"/>is not a valid FQDN, or
        /// if <paramref name="sid"/> is not a valid SID.
        /// </exception>
        public static string ToLdapSidConnectionString(this string domainFqdn, string sid)
        {
            var fqdnResult = Fqdn.Create(domainFqdn);
            var sidResult  = AccountSid.Create(sid);

            if (fqdnResult.IsFailure)
            {
                throw new ArgumentException(fqdnResult.Error, nameof(domainFqdn));
            }

            if (sidResult.IsFailure)
            {
                throw new ArgumentException(sidResult.Error, nameof(sid));
            }

            return(fqdnResult.Value.ToLdapSidConnectionString(sidResult.Value));
        }
コード例 #4
0
 /// <summary>Converts a domain FQDN to a distinguished.</summary>
 /// <param name="domainFqdn">The domain FQDN.</param>
 /// <returns>The distinguished name representation of the <see cref="Fqdn"/>.</returns>
 private static string ToDistinguishedName(this Fqdn domainFqdn)
 {
     return($"DC={domainFqdn.ToString().Replace(".", ",DC=")}");
 }
コード例 #5
0
 /// <summary>Convert a FQDN and SID to a LDAP connection string.</summary>
 /// <param name="domainFqdn">The domain FQDN.</param>
 /// <param name="accountSid">The SID to connect to.</param>
 /// <returns>An LDAP formatted connection string to the SID.</returns>
 public static string ToLdapSidConnectionString(this Fqdn domainFqdn, AccountSid accountSid)
 {
     return($"LDAP://{domainFqdn}/<SID={accountSid}>");
 }
コード例 #6
0
 /// <summary>Converts a FQDN and distinguished name to a LDAP connection string.</summary>
 /// <param name="domainFqdn">The domain FQDN.</param>
 /// <param name="dn">The distinguished name.</param>
 /// <returns>An LDAP formatted connection string to the distinguished name.</returns>
 public static string ToLdapDNConnectionString(this Fqdn domainFqdn, string dn)
 {
     // Note: it seems to be very difficult to use a regex to validate a DN.
     // TODO: validate the DN format
     return($"LDAP://{domainFqdn}/{dn}");
 }
コード例 #7
0
 /// <summary>Converts a FQDN to an LDAP connection string.</summary>
 /// <param name="domainFqdn">The domain FQDN.</param>
 /// <returns>An LDAP formatted connection string.</returns>
 public static string ToLdapConnectionString(this Fqdn domainFqdn)
 {
     return($"LDAP://{domainFqdn}/{domainFqdn.ToDistinguishedName()}");
 }