Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autodiscovery fail: Call to dnsapi.dll on Linux #24

Open
ststeiger opened this issue May 16, 2018 · 2 comments
Open

Autodiscovery fail: Call to dnsapi.dll on Linux #24

ststeiger opened this issue May 16, 2018 · 2 comments

Comments

@ststeiger
Copy link

ststeiger commented May 16, 2018

ews-managed-api tries to lookup the _autodiscover._tcp URL from the dns server like
nslookup -type=srv _autodiscover._tcp.my_domain.local
which is fine, except it makes calls to dnsapi.dll on Linux !
Self-evidently, that fails.

Microsoft.Exchange.WebServices.Dns
internal static class DnsNativeMethods
  {

    [DllImport("dnsapi.dll", EntryPoint = "DnsQuery_W", CharSet = CharSet.Unicode, SetLastError = true)]
    private static extern int DnsQuery([In] string pszName, DnsRecordType wType, DnsNativeMethods.DnsQueryOptions options, IntPtr aipServers, ref IntPtr ppQueryResults, int pReserved);

    [DllImport("dnsapi.dll", CharSet = CharSet.Unicode)]
    private static extern void DnsRecordListFree([In] IntPtr ptrRecords, [In] DnsNativeMethods.FreeType freeType);

The solution would be to do this with ArSoft (.NET Core DNS library).

using ARSoft.Tools.Net;
using ARSoft.Tools.Net.Dns;

public static void Test4()
{
    System.Net.NetworkInformation.IPGlobalProperties ipgp = 
        System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties();

    // IDnsResolver resolver = new RecursiveDnsResolver(); // Warning: Doesn't work
    IDnsResolver resolver = new DnsStubResolver();

    // List<SrvRecord> srvRecords = resolver.Resolve<SrvRecord>("_ldap._tcp." + ipgp.DomainName, RecordType.Srv);
    List<SrvRecord> srvRecords = resolver.Resolve<SrvRecord>("_autodiscover._tcp." + ipgp.DomainName, RecordType.Srv);


    foreach (SrvRecord thisRecord in srvRecords)
    {
        // System.Console.WriteLine(thisRecord.Name);
        System.Console.WriteLine(thisRecord.Target);
        System.Console.WriteLine(thisRecord.Port);

        // Note: OR LDAPS:// - but Novell doesn't want these parts anyway 
        string url = "LDAP://" + thisRecord.Target + ":" + thisRecord.Port; 
        System.Console.WriteLine(url);
    } // Next thisRecord

}
@ststeiger
Copy link
Author

Just writing that you can add the (pre-release) nuget-package System.DirectoryServices/4.5.0-rc1 and re-add the file Microsoft.Exchange.WebServices.Data\Autodiscover\DirectoryHelper.cs

And in Microsoft.Exchange.WebServices.Data\Autodiscover\AutodiscoverService.cs modify the function DefaultGetScpUrlsForDomain back to its original state:

      /// <summary>
        /// Defaults the get autodiscover service urls for domain.
        /// </summary>
        /// <param name="domainName">Name of the domain.</param>
        /// <returns></returns>
        private ICollection<string> DefaultGetScpUrlsForDomain(string domainName)
        {
            DirectoryHelper helper = new DirectoryHelper(this);
            return helper.GetAutodiscoverScpUrlsForDomain(domainName);
        }

then it will work (at least on Linux and Windows - tested).

@Dean-ZhenYao-Wang
Copy link

But it doesn't

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants