Wednesday, April 1, 2015

Microsofts autodiscover feature in linux

Just a short hint for anybody who wants to make Microsofts autodiscover-feature work in linux environment. Also this is a special case as I needed to make the autodiscover work with another domain. By this I mean if the domain in question is: mydomain.fi and you have a webhosting company: hosting.fi, then you will need to insert a DNS entry for the mydomain.fi which points to hosting.fis general autosdiscover DNS-entry. As:
mydomain.fi -> autodiscover.hosting.fi
autodiscover.mydomain.fi. IN CNAME autodiscover.hosting.fi.

This special need came when I worked at a hosting company and required just couple special alterations.

The only real script you need for that is here: http://0wned.it/wp-content/uploads/2011/09/autodiscover.php_.txt

Though the crappy part is that Microsoft wants to make everybody else's life hard, you might have to make more adjustments to the autodiscover, to make it work.

First I had htaccess redirect all the traffic to a php-file. So it doesn't matter which way the autodiscover is called it always works (e.g. some implementations call it with capitalizez (AUTODISCOVER) and some with lowercase (autodiscover).

.htaccess
RewriteEngine On
RewriteRule ^.*$ autodiscover.php [NC,L]

Then you want to redirect the http requests to SSL-site:

Top of autodiscover.php:
if (empty($_SERVER['HTTPS']) ||  $_SERVER['HTTPS'] == 'off') {
    header("Location: https://autodiscovered.company.com".$_SERVER['REDIRECT_URL']);
}

From here you might realize that you need at least 2 DNS-entries:
autodiscover.domain.fi. IN CNAME autodiscover.anotherdomain.fi.
And in the anotherdomain.fi zone:
autodiscovered.anotherdomain.fi. IN A [IP ADDRESS]

The way autodiscover works is it asks for certain file for the email address. If the email address is person@mydomain.fi, then autodiscover asks for autodiscover.mydomain.fi/autodiscover (actually I probably don't remember the correct path now, as it was some while back, but you get the idea). When it finds this it will use several methods to retrieve the data, in order. You can actually find the methods just by testing autodiscover on some domain here: https://testconnectivity.microsoft.com/ , but this method works on the HTTP redirect method.

The autodiscover.mydomain.fi should be redirected to SSL-site, otherwise autodiscover rejects the redirection.

No comments:

Post a Comment