[imp] virtual hosting based on ldap info

Caylan Van Larson caylan at cs.und.edu
Tue Jul 29 12:34:02 PDT 2003


Hi,

Here at school we have user at cs.und.edu and user at aero.und.edu accounts.  
The previous two addresses are identical and mail is accepted for both 
addresses and delivered to "user."

Most users dont care to understand this concept and think that their email 
address is "wrong" when the domain is not as expected.  Thus, I have to 
come up with a way to have their from address (maildomain/realm) change 
based on some ldap information, easiest being their home directories 
because of how we split compsci and avit students.

Code placed in imp/config/servers.php will allow me to change 
maildomain/realm based on variables available *before* a user ever types 
in their username.

Here is my code:
--SNIP
// Connect to the ldap server.
....

// Identifiers and vdomains.
$vdomains['Sirius'] = 'aero.und.edu';
$vdomains['Agassiz'] = 'cs.und.edu';

// Default vdomain
$vdomain = 'aero.und.edu';

if( $hack_ldap_resource )
{
    $hack_ldap_user = $_REQUEST['imapuser'];
    $hack_ldap_basedn = 'ou=people,dc=aero,dc=und,dc=edu';
    $hack_ldap_search = 'uid='.$hack_ldap_user;
    $hack_ldap_results = ldap_search($hack_ldap, $hack_ldap_basedn, $hack_ldap_search);
    $hack_ldap_info = ldap_get_entries($hack_ldap, $hack_ldap_results);
    $hack_ldap_homedir = $hack_ldap_info[0]['homedirectory'][0];

    foreach( $vdomains as $vdomain_key => $vdomain_value )
    {
        //echo "Searching for $vdomain_key in $hack_ldap_homedir...";
        if( preg_match("/$vdomain_key/", $hack_ldap_homedir) )
        {
            //echo "FOUND!<br>";
            $vdomain = $vdomains[$vdomain_key];
            //echo "Vdomain set to $vdomain<br>";
            break;
        }
        //echo "<br>";
    }
}
--SNAP

So here are two questions:

1) Where can I put this code so I can effectively change maildomain/realm 
while still being able to access the username provided at the initial form?

2) Instead, is there a configuration that will only allow usernames in the 
form "username at example.com" then set the maildomain/realm according to the 
address provided?  (And only allow a certain set of domains?)

The trouble with #2 is students will have access to both type of accounts 
because horde/imp stores them under different accounts thus different 
preferences for the same email address.

Thanks,



Caylan Van Larson
Unix Administrator - Systems Team Member
University of North Dakota (Aerospace College)
caylan at cs.und.edu
701-777-6151 (work)



More information about the imp mailing list