| 1 | --- /home/zmousm/amavis/maia/maia/php/auth.php 2004-03-03 13:21:20.000000000 +0200 |
|---|
| 2 | +++ /var/www/html/maia/auth.php 2004-06-12 02:59:52.000000000 +0300 |
|---|
| 3 | @@ -164,12 +164,90 @@ |
|---|
| 4 | } |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | +/* |
|---|
| 8 | + * exchange_ldap_get_email(): Find or make a best effort guess for a user's |
|---|
| 9 | + * primary e-mail address using a Microsoft |
|---|
| 10 | + * Exchange Server and a Windows Domain Active |
|---|
| 11 | + * Directory. |
|---|
| 12 | + * Code contributed by Zenon Mousmoulas |
|---|
| 13 | + * <zmousm@grnet.gr> or <zenon@mousmoulas.gr>. |
|---|
| 14 | + */ |
|---|
| 15 | +function exchange_ldap_get_email($user_name) |
|---|
| 16 | +{ |
|---|
| 17 | + global $lang_error_ldap_connect; |
|---|
| 18 | + global $lang_error_ldap_bind; |
|---|
| 19 | + global $auth_ldap_server; |
|---|
| 20 | + global $auth_ldap_bind_dn; |
|---|
| 21 | + global $auth_ldap_password; |
|---|
| 22 | + global $auth_ldap_base_dn; |
|---|
| 23 | + |
|---|
| 24 | + $ldap_conn = ldap_connect($auth_ldap_server) |
|---|
| 25 | + or die($lang_error_ldap_connect); |
|---|
| 26 | + |
|---|
| 27 | + @ldap_bind($ldap_conn, $auth_ldap_bind_dn, $auth_ldap_password) |
|---|
| 28 | + or die($lang_error_ldap_bind); |
|---|
| 29 | + |
|---|
| 30 | + $filter = "(sAMAccountName=" . $user_name . ")"; |
|---|
| 31 | + |
|---|
| 32 | + $sr = ldap_search($ldap_conn, $auth_ldap_base_dn, $filter, |
|---|
| 33 | + array("dn", "proxyAddresses", "mail")); |
|---|
| 34 | + |
|---|
| 35 | + if (ldap_count_entries($ldap_conn, $sr) == 1) { // only expect to find one entry |
|---|
| 36 | + $entries = ldap_get_entries($ldap_conn, $sr); |
|---|
| 37 | + $entries = $entries[0]; |
|---|
| 38 | + |
|---|
| 39 | + if (array_key_exists("proxyaddresses", $entries)) { // the proxyAddresses attribute takes precedence |
|---|
| 40 | + $i = 0; |
|---|
| 41 | + foreach ($entries["proxyaddresses"] as $praddr) { // store the proxyAddresses values of type SMTP: |
|---|
| 42 | + if (eregi("^smtp:", $praddr)) |
|---|
| 43 | + $proxyaddresses[$i++] = substr($praddr, 5); |
|---|
| 44 | + } |
|---|
| 45 | + if ($i == 1) { |
|---|
| 46 | + ldap_close($ldap_conn); |
|---|
| 47 | + return $proxyaddresses[0]; |
|---|
| 48 | + } |
|---|
| 49 | + } |
|---|
| 50 | + if (array_key_exists("mail", $entries)) { // find the mail attribute |
|---|
| 51 | + if ($entries["mail"]["count"] == 1) { |
|---|
| 52 | + $mailattr = $entries["mail"][0]; |
|---|
| 53 | + } else { // too many mail attribute entries |
|---|
| 54 | + ldap_close($ldap_conn); |
|---|
| 55 | + return ""; |
|---|
| 56 | + } |
|---|
| 57 | + } |
|---|
| 58 | + // compare SMTP proxyAddresses values with mail value |
|---|
| 59 | + if (is_array($proxyaddresses)) { |
|---|
| 60 | + if (isset($mailattr)) { |
|---|
| 61 | + foreach ($proxyaddresses as $praddr) { |
|---|
| 62 | + if (strtolower($mailattr) == strtolower($praddr)) { // try to find the SMTP proxyAddresses value that matches that of the mail attribute |
|---|
| 63 | + ldap_close($ldap_conn); |
|---|
| 64 | + return $praddr; |
|---|
| 65 | + } |
|---|
| 66 | + } |
|---|
| 67 | + // mail attribute value doesnt match any SMTP proxyAddresses value |
|---|
| 68 | + ldap_close($ldap_conn); |
|---|
| 69 | + return ""; |
|---|
| 70 | + } else { // if mail attribute not set, give up and return the first SMTP proxyAddresses value |
|---|
| 71 | + ldap_close($ldap_conn); |
|---|
| 72 | + return $proxyaddresses[0]; |
|---|
| 73 | + } |
|---|
| 74 | + } else { // no SMTP proxyAddresses value was found |
|---|
| 75 | + ldap_close($ldap_conn); |
|---|
| 76 | + return ""; |
|---|
| 77 | + } |
|---|
| 78 | + } else { // found too many or too few entries! |
|---|
| 79 | + ldap_close($ldap_conn); |
|---|
| 80 | + return ""; |
|---|
| 81 | + } |
|---|
| 82 | +} |
|---|
| 83 | + |
|---|
| 84 | + |
|---|
| 85 | /* |
|---|
| 86 | * auth_exchange(): Authenticate against Microsoft Exchange Server |
|---|
| 87 | * Code based on information provided by |
|---|
| 88 | * Matt Linzbach <MLinzbach@Merchant-Gould.com>. |
|---|
| 89 | */ |
|---|
| 90 | - function auth_exchange($user, $pass, $domain, $alias) |
|---|
| 91 | + function auth_exchange($user, $pass, $domain, $alias = "") |
|---|
| 92 | { |
|---|
| 93 | global $dbh; |
|---|
| 94 | global $auth_exchange_params; |
|---|
| 95 | @@ -327,6 +405,7 @@ |
|---|
| 96 | if (!empty($user_name) && !empty($pwd)) { |
|---|
| 97 | $authenticated = auth_exchange($user_name, $pwd, $nt_domain); |
|---|
| 98 | // BROKEN! No idea what e-mail address to return here. |
|---|
| 99 | + $email = exchange_ldap_get_email($user_name); |
|---|
| 100 | } |
|---|
| 101 | } elseif ($auth_method == "sql") { |
|---|
| 102 | if (!empty($user_name) && !empty($pwd)) { |
|---|
| 103 | @@ -342,4 +421,4 @@ |
|---|
| 104 | |
|---|
| 105 | return array($authenticated, $email); |
|---|
| 106 | } |
|---|
| 107 | -?> |
|---|
| 108 | \ No newline at end of file |
|---|
| 109 | +?> |
|---|