[dev] cyrsql.php vs cyrus.php
Ilya
mail at krel.org
Thu Aug 28 21:17:54 PDT 2003
Ive decided to combine on cyrus.php, if the patches attached are commited then
cyrsql.php can be removed from cvs.
I modified sql.php to be able to handle domains field. It only kicks off if
'domain_field' is set. Every user function is tested against cyrus
2.2b/virtual domains/sql backend.
I think its nice that ldap folks will be able to extend ldap backend if they
want and stay with one cyrus.php file. I also added some description in
cyrus.php regarding virtual domain support.
On Thu, Aug 28, 2003 at 11:33:32AM +0200, Jan Schneider wrote:
> Zitat von Ilya <mail at krel.org>:
>
> > and the patch is attached
>
> Committed, thanks.
>
> > > On Wed, Aug 27, 2003 at 11:19:57PM -0400, Ilya wrote:
> > > > Hi guys, I'd like to update the driver for cyrus/sql to again work
> > with virtual
> > > > domains, there were a lot of changes since i last looked at it. But
> > there is a
> > > > cyrus.php now which seems to be base on cyrsql.php and independent of
> > backend for user storage.
> > > > I was wondering if i should make changes to cyrus.php instead of
> > cyrsql.php
> > > > right now when i use cyrsql as admin driver i get that all features
> > are disabled
> > > > and with cyrus i get listing of users but without their virtual
> > domains, i
> > > > havent tried adding/removing users yet. I want to get virtual domain
> > supported
> > > > first.
> > > >
> > > > please let me know which way to go ;)
>
> I don't think any of the current core developers use these drivers, so it's
> up to you if you want to merge their features into one sole driver.
>
> You may also want to take a look at the mailing list archives where you
> should find some historical information about the new driver, and why it
> was necessary for the one who added it.
>
> Jan.
>
> --
> http://www.horde.org - The Horde Project
> http://www.ammma.de - discover your knowledge
> http://www.tip4all.de - Deine private Tippgemeinschaft
>
> --
> Horde developers mailing list
> Frequently Asked Questions: http://horde.org/faq/
> To unsubscribe, mail: dev-unsubscribe at lists.horde.org
-------------- next part --------------
--- cyrus.php.old Wed Aug 27 23:49:19 2003
+++ cyrus.php Fri Aug 29 00:08:43 2003
@@ -3,7 +3,12 @@
/**
* The Auth_cyrus class provides horde with the ability of administrating
* a Cyrus mail server authentications against another backend that Horde
- * can update (eg SQL or LDAP).
+ * can update (eg SQL or LDAP).
+ * Virtual domains (cyrus 2.2b) are supported with SQL backend.
+ * 'domain_field' must be set to field name where domain is held to enable
+ * support.
+ * If you keep users in user at domain.com form, then you dont need to
+ * enable 'domain'. It has not been tested it, but it should work.
*
* Required values for $params:
* 'cyradmin' The username of the cyrus administrator
@@ -40,6 +47,7 @@
* 'table' => 'accountuser',
* 'encryption' => 'md5-hex',
* 'username_field' => 'username',
+ * 'username_domain' => 'domain',
* 'password_field' => 'password'));
*
* if (!function_exists('_horde_select_loginscreen')) {
-------------- next part --------------
--- sql.php.old Thu Aug 28 22:22:58 2003
+++ sql.php Thu Aug 28 23:55:27 2003
@@ -27,6 +27,8 @@
* DEFAULT: 'horde_users'
* 'username_field' -- The name of the username field in the auth table.
* DEFAULT: 'user_uid'
+ * 'domain_field' -- The name of the domain field in the auth table.
+ * DEFAULT: not set
*
* Required by some database implementations:
* ==========================================
@@ -117,11 +119,22 @@
$this->_connect();
/* Build the SQL query. */
- $query = sprintf('SELECT %s FROM %s WHERE %s = %s',
- $this->_params['password_field'],
- $this->_params['table'],
- $this->_params['username_field'],
- $this->_db->quote($userID));
+ if (!isset($this->_params['domain_field'])){
+ $query = sprintf('SELECT %s FROM %s WHERE %s = %s',
+ $this->_params['password_field'],
+ $this->_params['table'],
+ $this->_params['username_field'],
+ $this->_db->quote($userID));
+ } else {
+ list($name,$domain)=explode('@',$userID);
+ $query = sprintf('SELECT %s FROM %s WHERE %s = %s and %s = %s',
+ $this->_params['password_field'],
+ $this->_params['table'],
+ $this->_params['username_field'],
+ $this->_db->quote($name),
+ $this->_params['domain_field'],
+ $this->_db->quote($domain));
+ }
$result = $this->_db->query($query);
if (!is_a($result, 'PEAR_Error')) {
@@ -157,12 +170,25 @@
$this->_connect();
/* Build the SQL query. */
- $query = sprintf('INSERT INTO %s (%s, %s) VALUES (%s, %s)',
- $this->_params['table'],
- $this->_params['username_field'],
- $this->_params['password_field'],
- $this->_db->quote($userID),
- $this->_db->quote($this->_encryptPassword($credentials['password'])));
+ if (!isset($this->_params['domain_field'])){
+ $query = sprintf('INSERT INTO %s (%s, %s) VALUES (%s, %s)',
+ $this->_params['table'],
+ $this->_params['username_field'],
+ $this->_params['password_field'],
+ $this->_db->quote($userID),
+ $this->_db->quote($this->_encryptPassword($credentials['password'])));
+ } else {
+ list($name,$domain)=explode('@',$userID);
+ $query = sprintf('INSERT INTO %s (%s, %s, %s) VALUES (%s, %s, %s)',
+ $this->_params['table'],
+ $this->_params['username_field'],
+ $this->_params['domain_field'],
+ $this->_params['password_field'],
+ $this->_db->quote($name),
+ $this->_db->quote($domain),
+ $this->_db->quote($this->_encryptPassword($credentials['password'])));
+ }
+
$result = $this->_db->query($query);
@@ -190,14 +216,26 @@
$this->_connect();
/* Build the SQL query. */
- $query = sprintf('UPDATE %s SET %s = %s, %s = %s WHERE %s = %s',
- $this->_params['table'],
- $this->_params['username_field'],
- $this->_db->quote($newID),
- $this->_params['password_field'],
- $this->_db->quote($this->_encryptPassword($credentials['password'])),
- $this->_params['username_field'],
- $this->_db->quote($oldID));
+ if (!isset($this->_params['domain_field'])){
+ $query = sprintf('UPDATE %s SET %s = %s, %s = %s WHERE %s = %s',
+ $this->_params['table'],
+ $this->_params['username_field'],
+ $this->_db->quote($newID),
+ $this->_params['password_field'],
+ $this->_db->quote($this->_encryptPassword($credentials['password'])),
+ $this->_params['username_field'],
+ $this->_db->quote($oldID));
+ } else {
+ list($name,$domain)=explode('@',$oldID);
+ $query = sprintf('UPDATE %s SET %s = %s WHERE %s = %s and %s = %s',
+ $this->_params['table'],
+ $this->_params['password_field'],
+ $this->_db->quote($this->_encryptPassword($credentials['password'])),
+ $this->_params['username_field'],
+ $this->_db->quote($name),
+ $this->_params['domain_field'],
+ $this->_db->quote($domain));
+ }
$result = $this->_db->query($query);
if (is_a($result, 'PEAR_Error')) {
@@ -222,10 +260,21 @@
$this->_connect();
/* Build the SQL query. */
- $query = sprintf('DELETE FROM %s WHERE %s = %s',
- $this->_params['table'],
- $this->_params['username_field'],
- $this->_db->quote($userID));
+ if (!isset($this->_params['domain_field'])){
+ $query = sprintf('DELETE FROM %s WHERE %s = %s',
+ $this->_params['table'],
+ $this->_params['username_field'],
+ $this->_db->quote($userID));
+ } else {
+ list($name,$domain)=explode('@',$userID);
+ $query = sprintf('DELETE FROM %s WHERE %s = %s and %s = %s',
+ $this->_params['table'],
+ $this->_params['username_field'],
+ $this->_db->quote($name),
+ $this->_params['domain_field'],
+ $this->_db->quote($domain));
+ }
+
$result = $this->_db->query($query);
if (is_a($result, 'PEAR_Error')) {
@@ -248,10 +297,20 @@
$this->_connect();
/* Build the SQL query. */
- $query = sprintf('SELECT %s FROM %s ORDER BY %s',
- $this->_params['username_field'],
- $this->_params['table'],
- $this->_params['username_field']);
+ if (!isset($this->_params['domain_field'])){
+ $query = sprintf('SELECT %s FROM %s ORDER BY %s',
+ $this->_params['username_field'],
+ $this->_params['table'],
+ $this->_params['username_field']);
+ } else {
+ $query = sprintf('SELECT %s, %s FROM %s ORDER BY %s, %s',
+ $this->_params['username_field'],
+ $this->_params['domain_field'],
+ $this->_params['table'],
+ $this->_params['username_field'],
+ $this->_params['domain_field']);
+ }
+
$result = $this->_db->getAll($query, null, DB_FETCHMODE_ORDERED);
if (is_a($result, 'PEAR_Error')) {
@@ -260,8 +319,14 @@
/* Loop through and build return array. */
$users = array();
- foreach ($result as $ar) {
- $users[] = $ar[0];
+ if (!isset($this->_params['domain_field'])){
+ foreach ($result as $ar) {
+ $users[] = $ar[0];
+ }
+ } else {
+ foreach ($result as $ar) {
+ $users[] = $ar[0] . '@' . $ar[1];
+ }
}
return $users;
@@ -280,11 +345,22 @@
$this->_connect();
/* Build the SQL query. */
- $query = sprintf('SELECT %s FROM %s WHERE %s = %s',
- $this->_params['username_field'],
- $this->_params['table'],
- $this->_params['username_field'],
- $this->_db->quote($userID));
+ if (!isset($this->_params['domain_field'])){
+ $query = sprintf('SELECT %s FROM %s WHERE %s = %s',
+ $this->_params['username_field'],
+ $this->_params['table'],
+ $this->_params['username_field'],
+ $this->_db->quote($userID));
+ } else {
+ list($name,$domain)=explode('@',$userID);
+ $query = sprintf('SELECT %s FROM %s WHERE %s = %s and %s = %s',
+ $this->_params['username_field'],
+ $this->_params['table'],
+ $this->_params['username_field'],
+ $this->_db->quote($name),
+ $this->_params['domain_field'],
+ $this->_db->quote($domain));
+ }
return $this->_db->getOne($query);
}
More information about the dev
mailing list