From 0cb64e5f7b3fc0d037d029075a75624417c0a43a Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Wed, 1 Sep 2004 20:53:06 +0000 Subject: [PATCH] moved var $base to baseModule, added init() to baseModule, removed several checks from modules init() function --- lam/lib/baseModule.inc | 13 +++++++++++++ lam/lib/modules/account.inc | 10 ++-------- lam/lib/modules/inetOrgPerson.inc | 10 ++-------- lam/lib/modules/posixAccount.inc | 17 ++--------------- lam/lib/modules/posixGroup.inc | 13 ++----------- lam/lib/modules/quota.inc | 14 ++------------ lam/lib/modules/sambaAccount.inc | 16 ++-------------- lam/lib/modules/sambaGroupMapping.inc | 12 ++---------- lam/lib/modules/sambaSamAccount.inc | 16 ++-------------- lam/lib/modules/shadowAccount.inc | 12 ++---------- 10 files changed, 31 insertions(+), 102 deletions(-) diff --git a/lam/lib/baseModule.inc b/lam/lib/baseModule.inc index 17800976..ff6d02f6 100644 --- a/lam/lib/baseModule.inc +++ b/lam/lib/baseModule.inc @@ -48,6 +48,9 @@ class baseModule { /** configuration settings of all modules */ var $moduleSettings; + /** name of parent accountContainer ($_SESSION[$base]) */ + var $base; + /** * Creates a new base module class * @@ -59,6 +62,16 @@ class baseModule { if (isset($_SESSION['config'])) $this->moduleSettings = $_SESSION['config']->get_moduleSettings(); } + /** + * Initializes the module after it became part of an accountContainer + * + * @param string $base the name of the accountContainer object ($_SESSION[$base]) + */ + function init($base) { + $this->base = $base; + } + + /** * Dummy function, meta data is provided by sub classes. * diff --git a/lam/lib/modules/account.inc b/lam/lib/modules/account.inc index ff99774f..e2086ef4 100644 --- a/lam/lib/modules/account.inc +++ b/lam/lib/modules/account.inc @@ -59,12 +59,8 @@ class account extends baseModule { // Constructor function init($base) { - // Get local copy of name of account_container in session - $this->base = $base; - // Do some error checks - if (!$base) trigger_error(_('Please create a base object with $var = new accountContainer();'), E_USER_ERROR); - if (!is_string($base)) trigger_error(_('Please create a new module object in an accountContainer object first.'), E_USER_ERROR); - if ($_SESSION[$this->base]->get_type() != 'host') trigger_error(_('account can only be used for hosts.'), E_USER_WARNING); + // call parent init + parent::init($base); // load attribtues which are used in account objectClass $this->orig = $_SESSION[$this->base]->get_module_attributes('account'); $this->attributes = $_SESSION[$this->base]->get_module_attributes('account'); @@ -73,8 +69,6 @@ class account extends baseModule { } // Variables - // name of account_container in session so we can read other classes in account_container - var $base; // This variable contains all account attributes var $attributes; /* If an account was loaded all attributes are kept in this array diff --git a/lam/lib/modules/inetOrgPerson.inc b/lam/lib/modules/inetOrgPerson.inc index 298963ba..3d44d721 100644 --- a/lam/lib/modules/inetOrgPerson.inc +++ b/lam/lib/modules/inetOrgPerson.inc @@ -111,12 +111,8 @@ class inetOrgPerson extends baseModule { * @param string $base the name of account_container in session */ function init($base) { - // Get local copy of name of account_container in session - $this->base = $base; - // Do some error checks - if (!$base) trigger_error(_('Please create a base object with $var = new accountContainer();'), E_USER_ERROR); - if (!is_string($base)) trigger_error(_('Please create a new module in an accountContainer object first.'), E_USER_ERROR); - if ($_SESSION[$this->base]->type != 'user') trigger_error(_('inetOrgPerson can only be used for users.'), E_USER_WARNING); + // call parent init + parent::init($base); // load attribtues which are used in inetOrgPerson objectClass // unset attributes which are "must" but not in this module // cn will be set to uid in module posixAccount @@ -129,8 +125,6 @@ class inetOrgPerson extends baseModule { } // Variables - /** name of account_container in session so we can read other classes in account_container */ - var $base; /** This variable contains all inetOrgPerson attributes */ var $attributes; /** diff --git a/lam/lib/modules/posixAccount.inc b/lam/lib/modules/posixAccount.inc index ed0ee7b5..97d1e5c6 100644 --- a/lam/lib/modules/posixAccount.inc +++ b/lam/lib/modules/posixAccount.inc @@ -154,19 +154,8 @@ class posixAccount extends baseModule { // Constructor function init($base) { - /* Return an error if posixAccount should be created without - * base container - */ - if (!$base) trigger_error(_('Please create a base object with $var = new accountContainer();'), E_USER_ERROR); - if (!is_string($base)) trigger_error(_('Please create a new module object in an accountContainer object first.'), E_USER_ERROR); - $this->base = $base; - // posixAccount is only a valid objectClass for user and host - if (!($_SESSION[$this->base]->get_type() == 'user') && !($_SESSION[$this->base]->get_type() == 'host')) trigger_error(_('posixAccount can only be used for users or hosts.'), E_USER_WARNING); - /* Check if ldap conatiner is in array and set type - * users are using inetOrgPerson-, hosts account-container - */ - if (!isset($_SESSION[$this->base]->module['inetOrgPerson']) && $_SESSION[$this->base]->type=='user') $_SESSION[$this->base]->modules['inetOrgPerson'] = new inetOrgPerson($this->base); - if (!isset($_SESSION[$this->base]->module['account']) && $_SESSION[$this->base]->type=='host') $_SESSION[$this->base]->modules['account'] = new account($this->base); + // call parent init + parent::init($base); // Add Array with all attributes and type $this->orig = $_SESSION[$this->base]->get_module_attributes('posixAccount'); $this->attributes = $_SESSION[$this->base]->get_module_attributes('posixAccount'); @@ -186,8 +175,6 @@ class posixAccount extends baseModule { } // Variables - // name of accountContainer so we can read other classes in accuontArray - var $base; // Use a unix password? var $userPassword_no; // Lock account? diff --git a/lam/lib/modules/posixGroup.inc b/lam/lib/modules/posixGroup.inc index b7a64e81..d5db31b5 100644 --- a/lam/lib/modules/posixGroup.inc +++ b/lam/lib/modules/posixGroup.inc @@ -169,18 +169,11 @@ class posixGroup extends baseModule { // Constructor function init($base) { - /* Return an error if posixGroup should be created without - * base container - */ - if (!$base) trigger_error(_('Please create a base object with $var = new accountContainer();'), E_USER_ERROR); - if (!is_string($base)) trigger_error(_('Please create a new module object in an accountContainer object first.'), E_USER_ERROR); - $this->base = $base; - // posixGroup is only a valid objectClass for user and host - if ($_SESSION[$this->base]->get_type() != 'group') trigger_error(_('posixGroup can only be used for groups.'), E_USER_WARNING); + // call parent init + parent::init($base); // Add Array with all attributes and type $this->attributes = $_SESSION[$this->base]->get_module_attributes('posixGroup'); $_SESSION[$this->base]->add_attributes ('posixGroup'); - $this->alias = _('posixGroup'); // Make references to attributes which already esists in ldap $newattributes = array_keys($this->attributes); $module = array_keys($_SESSION[$this->base]->module); @@ -196,8 +189,6 @@ class posixGroup extends baseModule { // Variables - // name of accountContainer so we can read other classes in accuontArray - var $base; // Use a unix password? var $userPassword_no; // Lock account? diff --git a/lam/lib/modules/quota.inc b/lam/lib/modules/quota.inc index f6796d48..e1f5c401 100644 --- a/lam/lib/modules/quota.inc +++ b/lam/lib/modules/quota.inc @@ -64,16 +64,8 @@ class quota extends baseModule { // Constructor function init($base) { - $this->base = $base; - if (!$base) trigger_error(_('Please create a base object with $var = new accountContainer();'), E_USER_ERROR); - if (!is_string($base)) trigger_error(_('Please create a new module in an accountContainer object first.'), E_USER_ERROR); - // quota is only a valid objectClass for user and host - if (!($_SESSION[$this->base]->get_type() == 'user') && !($_SESSION[$this->base]->get_type() == 'group')) trigger_error(_('quota can only be used for users or groups.'), E_USER_WARNING); - /* Check if ldap conatiner is in array and set type - * users are using inetOrgPerson-, hosts account-container - */ - if (!isset($_SESSION[$this->base]->module['posixAccount']) && $_SESSION[$this->base]->type=='user') $_SESSION[$this->base]->modules['posixAccount'] = new posixGroup($this->base); - if (!isset($_SESSION[$this->base]->module['posixGroup']) && $_SESSION[$this->base]->type=='group') $_SESSION[$this->base]->modules['posixGroup'] = new posixGroup($this->base); + // call parent init + parent::init($base); // Get basic quotas for new account $output_array = $_SESSION[$this->base]->lamdaemon(array("+ quota get " . $_SESSION[$this->base]->type)); // process quotas @@ -102,8 +94,6 @@ class quota extends baseModule { } // Variables - // name of accountContainer so we can read other classes in accuontArray - var $base; var $quota; diff --git a/lam/lib/modules/sambaAccount.inc b/lam/lib/modules/sambaAccount.inc index 2394dc95..f71e061e 100644 --- a/lam/lib/modules/sambaAccount.inc +++ b/lam/lib/modules/sambaAccount.inc @@ -180,18 +180,8 @@ class sambaAccount extends baseModule { // Constructor function init($base) { - /* Return an error if sambaAccount should be created without - * base container - */ - if (!$base) trigger_error(_('Please create a base object with $var = new accountContainer();'), E_USER_ERROR); - if (!is_string($base)) trigger_error(_('Please create a new module object in an accountContainer object first.'), E_USER_ERROR); - $this->base = $base; - // sambaAccount is only a valid objectClass for user and host - if (!($_SESSION[$this->base]->get_type() == 'user') && !($_SESSION[$this->base]->get_type() == 'host')) trigger_error(_('sambaAccount can only be used for users or hosts.'), E_USER_WARNING); - /* Check if ldap conatiner is in array and set type - * users are using inetOrgPerson-, hosts account-container - */ - if (!isset($_SESSION[$this->base]->module['posixAccount'])) $_SESSION[$this->base]->modules['posixAccount'] = new posixAccount($this->base); + // call parent init + parent::init($base); // Add Array with all attributes and type $this->attributes = $_SESSION[$this->base]->get_module_attributes('sambaAccount'); $_SESSION[$this->base]->add_attributes ('sambaAccount'); @@ -211,8 +201,6 @@ class sambaAccount extends baseModule { } // Variables - // name of accountContainer so we can read other classes in accuontArray - var $base; // This variable contains all inetOrgPerson attributes var $attributes; /* If an account was loaded all attributes are kept in this array diff --git a/lam/lib/modules/sambaGroupMapping.inc b/lam/lib/modules/sambaGroupMapping.inc index a530cc2b..0448fe5d 100644 --- a/lam/lib/modules/sambaGroupMapping.inc +++ b/lam/lib/modules/sambaGroupMapping.inc @@ -102,14 +102,8 @@ class sambaGroupMapping extends baseModule { // Constructor function init($base) { - /* Return an error if sambaGroupMapping should be created without - * base container - */ - if (!$base) trigger_error(_('Please create a base object with $var = new accountContainer();'), E_USER_ERROR); - if (!is_string($base)) trigger_error(_('Please create a new module object in an accountContainer object first.'), E_USER_ERROR); - $this->base = $base; - // sambaGroupMapping is only a valid objectClass for user and host - if ($_SESSION[$this->base]->get_type() != 'group') trigger_error(_('sambaGroupMapping can only be used for groups.'), E_USER_WARNING); + // call parent init + parent::init($base); // Add Array with all attributes and type $this->attributes = $_SESSION[$this->base]->get_module_attributes('sambaGroupMapping'); $_SESSION[$this->base]->add_attributes ('sambaGroupMapping'); @@ -128,8 +122,6 @@ class sambaGroupMapping extends baseModule { } // Variables - // name of accountContainer so we can read other classes in accuontArray - var $base; // This variable contains all inetOrgPerson attributes var $attributes; diff --git a/lam/lib/modules/sambaSamAccount.inc b/lam/lib/modules/sambaSamAccount.inc index 29d25ee1..17232587 100644 --- a/lam/lib/modules/sambaSamAccount.inc +++ b/lam/lib/modules/sambaSamAccount.inc @@ -113,18 +113,8 @@ class sambaSamAccount extends baseModule { // Constructor function init($base) { - /* Return an error if sambaSamAccount should be created without - * base container - */ - if (!$base) trigger_error(_('Please create a base object with $var = new accountContainer();'), E_USER_ERROR); - if (!is_string($base)) trigger_error(_('Please create a new module object in an accountContainer object first.'), E_USER_ERROR); - $this->base = $base; - // sambaSamAccount is only a valid objectClass for user and host - if (!($_SESSION[$this->base]->get_type() == 'user') && !($_SESSION[$this->base]->get_type() == 'host')) trigger_error(_('sambaSamAccount can only be used for users or hosts.'), E_USER_WARNING); - /* Check if ldap conatiner is in array and set type - * users are using inetOrgPerson-, hosts account-container - */ - if (!isset($_SESSION[$this->base]->module['posixAccount'])) $_SESSION[$this->base]->modules['posixAccount'] = new posixAccount($this->base); + // call parent init + parent::init($base); // Add Array with all attributes and type $this->attributes = $_SESSION[$this->base]->get_module_attributes('sambaSamAccount'); $_SESSION[$this->base]->add_attributes ('sambaSamAccount'); @@ -144,8 +134,6 @@ class sambaSamAccount extends baseModule { } // Variables - // name of accountContainer so we can read other classes in accuontArray - var $base; // This variable contains all inetOrgPerson attributes var $attributes; /* If an account was loaded all attributes are kept in this array diff --git a/lam/lib/modules/shadowAccount.inc b/lam/lib/modules/shadowAccount.inc index 8323a9e0..7a10259f 100644 --- a/lam/lib/modules/shadowAccount.inc +++ b/lam/lib/modules/shadowAccount.inc @@ -147,14 +147,8 @@ class shadowAccount extends baseModule { // Constructor function init($base) { - /* Return an error if shadowAccount should be created without - * base container - */ - if (!$base) trigger_error(_('Please create a base object with $var = new accountContainer();'), E_USER_ERROR); - if (!is_string($base)) trigger_error(_('Please create a new module object in an accountContainer object first.'), E_USER_ERROR); - $this->base = $base; - // shadowAccount is only a valid objectClass for user and host - if (!($_SESSION[$this->base]->get_type() == 'user')) trigger_error(_('shadowAccount can only be used for users.'), E_USER_WARNING); + // call parent init + parent::init($base); // Add Array with all attributes and type $this->attributes = $_SESSION[$this->base]->get_module_attributes('shadowAccount'); $_SESSION[$this->base]->add_attributes ('shadowAccount'); @@ -170,8 +164,6 @@ class shadowAccount extends baseModule { } // Variables - // name of accountContainer so we can read other classes in accuontArray - var $base; // This variable contains all inetOrgPerson attributes var $attributes; /* If an account was loaded all attributes are kept in this array