[horde] Re: vdomain login hook

Niels Fröhling niels.froehling at premper.com
Fri Mar 11 10:30:19 PST 2005


Martin Friedrich schrieb:

> I appreciate your help but after some research I am postitive that I won't need any changes on the database/imap mechanism. My answer lies in the vinfo hook; only problem is that I can't figure out how to make it work. Currently I use an ugly bypass in /imp/lib/Session.php (I add the domain name to $_SESSION['imp']['user']) while dealing with the hook and the proper solution.

I don't understand you completly, I think:

1) You can't change the authentication front-end (imp, horde, ...)?
2a) If false, you can't implement your own authentication module for horde?
2b) If true, you have an IMAP server with the complete email-address as username
	   + you have a mysql-table with mappings from alias to email-address?

Maybe this code helps you:

/* ---- hier abbeissen ------------------------------------------------------------------------------------------- */

if (!function_exists('_imp_hook_vinfo')) {
	function _imp_hook_vinfo($type = 'username')
	{
		$vdomain = getenv('HTTP_HOST');
		$vdomain = preg_replace('|^mail\.|i', '', $vdomain);
		$vdomain = preg_replace('|^www\.|i', '', $vdomain);
		$vdomain = String::lower($vdomain);

		if ($type == 'username') {
			/* put a default username for failure here,
			 * be sure that login really fails with this
			 */
			$return = 'failure';

			/* if you have confixx in another database, you have to
			 * protect the default database-connection of horde!!!
			 *
			 * also you must have at least read access to the 'confixx'
			 * database and the 'email' table.
			 *
			 * NOTE: sockets are generaly ways faster!
			 */
//			if (($mydb = mysql_connect(':/var/lib/mysql/mysql.sock', 'root', '********'))) {
				/* confixx-aliasing works like:
				 *  inbox-username (pop3) = email-user (prefix) @ domain (domain)
				 *
				 * multiple mapping is possible:
				 *  1) multiple email-adresses to the same inbox
				 *  2) the same email-adress to multiple inboxes (may be security problem for someone)
				 */
				if (mysql_select_db('confixx' /*, $mydb*/)) {
					$query =
					'SELECT pop3' .
					' FROM email' .
					' WHERE prefix = \'' . $_SESSION['imp']['user'] . '\'' .
					' AND domain = \'' . $vdomain . '\'';

					/* we don't have mappings of type 2)
					 * so we don't have to choose a specific
					 * inbox (no security problem)
					 */
					if (($result = mysql_query($query /*, $mydb*/))) {
						if (($row = mysql_fetch_row($result)))
							$return = $row[0];

						mysql_free_result($result);
					}
				}

				mysql_select_db('horde' /*, $mydb*/);
//			}

			return $return;
		} elseif ($type == 'vdomain') {
			return $vdomain;
		} else {
			return PEAR::raiseError('invalid type: ' . $type);
		}
	}
}

/* ---- und runterschlucken ------------------------------------------------------------------------------------------- */

Like I've said, quick and dirty.

Ciao
	Niels


More information about the horde mailing list