added ldap.inc to includes, removed $ldap variable from accountContainer which is always 'ldap'

This commit is contained in:
Roland Gruber 2004-09-01 20:48:29 +00:00
parent 2166492b51
commit 1ea3ab8ca1
1 changed files with 41 additions and 40 deletions

View File

@ -37,6 +37,8 @@ include_once("cache.inc");
include_once("account.inc"); include_once("account.inc");
/** parent class of account modules */ /** parent class of account modules */
include_once("baseModule.inc"); include_once("baseModule.inc");
/** access to LDAP server */
include_once("ldap.inc");
/** /**
* This includes all module files. * This includes all module files.
@ -355,7 +357,7 @@ function getAvailableScopes() {
* @param string $scope account type * @param string $scope account type
* @return array column list * @return array column list
*/ */
function get_uploadColumns($scope) { function getUploadColumns($scope) {
// create new account container if needed // create new account container if needed
if (! isset($_SESSION["profile_account_$scope"])) { if (! isset($_SESSION["profile_account_$scope"])) {
$_SESSION["profile_account_$scope"] = new accountContainer($scope, "profile_account_$scope"); $_SESSION["profile_account_$scope"] = new accountContainer($scope, "profile_account_$scope");
@ -386,7 +388,6 @@ class accountContainer {
$this->type = $type; $this->type = $type;
$this->base = $base; $this->base = $base;
// Name of variables in session // Name of variables in session
$this->ldap = 'ldap';
$this->config = 'config'; $this->config = 'config';
$this->cache = 'cache'; $this->cache = 'cache';
$this->header2 = 'header'; $this->header2 = 'header';
@ -616,15 +617,15 @@ class accountContainer {
function add_attributes($objectClass) { function add_attributes($objectClass) {
// loop through every existing objectlass and select current objectClass // loop through every existing objectlass and select current objectClass
$line=-1; $line=-1;
for ($i=0; $i<count($_SESSION[$this->ldap]->objectClasses) || $i==-1; $i++) { for ($i=0; $i<count($_SESSION['ldap']->objectClasses) || $i==-1; $i++) {
if (strpos($_SESSION[$this->ldap]->objectClasses[$i], "NAME '$objectClass'")) $line = $i; if (strpos($_SESSION['ldap']->objectClasses[$i], "NAME '$objectClass'")) $line = $i;
} }
// Return error if objectClass isn't found // Return error if objectClass isn't found
if ($line==-1) trigger_error (sprintf(_("objectClass %s required but not defined in ldap."), $objectClass), E_USER_WARNING); if ($line==-1) trigger_error (sprintf(_("objectClass %s required but not defined in ldap."), $objectClass), E_USER_WARNING);
// create array with must-attributes // create array with must-attributes
// Get startposition in string // Get startposition in string
if (strpos($_SESSION[$this->ldap]->objectClasses[$line], 'MUST (')) { if (strpos($_SESSION['ldap']->objectClasses[$line], 'MUST (')) {
$string_withtail = substr($_SESSION[$this->ldap]->objectClasses[$line], strpos($_SESSION[$this->ldap]->objectClasses[$line], 'MUST (')+6); $string_withtail = substr($_SESSION['ldap']->objectClasses[$line], strpos($_SESSION['ldap']->objectClasses[$line], 'MUST (')+6);
// Now we have a string with all must-attributes // Now we have a string with all must-attributes
$string = substr($string_withtail, 0, strpos($string_withtail, ')')); $string = substr($string_withtail, 0, strpos($string_withtail, ')'));
$string = trim($string); $string = trim($string);
@ -637,8 +638,8 @@ class accountContainer {
} }
// create array with may-attributes // create array with may-attributes
// Get startposition in string // Get startposition in string
if (strpos($_SESSION[$this->ldap]->objectClasses[$line], 'MAY (')) { if (strpos($_SESSION['ldap']->objectClasses[$line], 'MAY (')) {
$string_withtail = substr($_SESSION[$this->ldap]->objectClasses[$line], strpos($_SESSION[$this->ldap]->objectClasses[$line], 'MAY (')+5); $string_withtail = substr($_SESSION['ldap']->objectClasses[$line], strpos($_SESSION['ldap']->objectClasses[$line], 'MAY (')+5);
// Now we have a string with all must-attributes // Now we have a string with all must-attributes
$string = substr($string_withtail, 0, strpos($string_withtail, ')')); $string = substr($string_withtail, 0, strpos($string_withtail, ')'));
$string = trim($string); $string = trim($string);
@ -650,19 +651,19 @@ class accountContainer {
} }
} }
// Get attributes of subclasses // Get attributes of subclasses
while (strpos($_SESSION[$this->ldap]->objectClasses[$line], "SUP ")) { while (strpos($_SESSION['ldap']->objectClasses[$line], "SUP ")) {
$string_withtail = substr($_SESSION[$this->ldap]->objectClasses[$line], strpos($_SESSION[$this->ldap]->objectClasses[$line], 'SUP ')+4); $string_withtail = substr($_SESSION['ldap']->objectClasses[$line], strpos($_SESSION['ldap']->objectClasses[$line], 'SUP ')+4);
$subclass = substr($string_withtail, 0, strpos($string_withtail, ' ')); $subclass = substr($string_withtail, 0, strpos($string_withtail, ' '));
// Add account type to object // Add account type to object
for ($i=0; $i<count($_SESSION[$this->ldap]->objectClasses) || $i==-1; $i++) { for ($i=0; $i<count($_SESSION['ldap']->objectClasses) || $i==-1; $i++) {
if (strpos($_SESSION[$this->ldap]->objectClasses[$i], "NAME '$subclass'")) $line = $i; if (strpos($_SESSION['ldap']->objectClasses[$i], "NAME '$subclass'")) $line = $i;
} }
// Return error if objectClass isn't found // Return error if objectClass isn't found
if ($line==-1) trigger_error (sprintf(_("objectClass %s required but not defined in ldap."), $objectClass), E_USER_WARNING); if ($line==-1) trigger_error (sprintf(_("objectClass %s required but not defined in ldap."), $objectClass), E_USER_WARNING);
// create array with must-attributes // create array with must-attributes
// Get startposition in string // Get startposition in string
if (strpos($_SESSION[$this->ldap]->objectClasses[$line], 'MUST (')) { if (strpos($_SESSION['ldap']->objectClasses[$line], 'MUST (')) {
$string_withtail = substr($_SESSION[$this->ldap]->objectClasses[$line], strpos($_SESSION[$this->ldap]->objectClasses[$line], 'MUST (')+6); $string_withtail = substr($_SESSION['ldap']->objectClasses[$line], strpos($_SESSION['ldap']->objectClasses[$line], 'MUST (')+6);
// Now we have a string with all must-attributes // Now we have a string with all must-attributes
$string = substr($string_withtail, 0, strpos($string_withtail, ')')); $string = substr($string_withtail, 0, strpos($string_withtail, ')'));
$string = trim($string); $string = trim($string);
@ -675,8 +676,8 @@ class accountContainer {
} }
// create array with may-attributes // create array with may-attributes
// Get startposition in string // Get startposition in string
if (strpos($_SESSION[$this->ldap]->objectClasses[$line], 'MAY (')) { if (strpos($_SESSION['ldap']->objectClasses[$line], 'MAY (')) {
$string_withtail = substr($_SESSION[$this->ldap]->objectClasses[$line], strpos($_SESSION[$this->ldap]->objectClasses[$line], 'MAY (')+5); $string_withtail = substr($_SESSION['ldap']->objectClasses[$line], strpos($_SESSION['ldap']->objectClasses[$line], 'MAY (')+5);
// Now we have a string with all must-attributes // Now we have a string with all must-attributes
$string = substr($string_withtail, 0, strpos($string_withtail, ')')); $string = substr($string_withtail, 0, strpos($string_withtail, ')'));
$string = trim($string); $string = trim($string);
@ -715,13 +716,13 @@ class accountContainer {
function get_module_attributes($objectClass) { function get_module_attributes($objectClass) {
// Add account type to object // Add account type to object
$line=-1; $line=-1;
for ($i=0; $i<count($_SESSION[$this->ldap]->objectClasses) || $i==-1; $i++) { for ($i=0; $i<count($_SESSION['ldap']->objectClasses); $i++) {
if (strpos($_SESSION[$this->ldap]->objectClasses[$i], "NAME '$objectClass'")) $line = $i; if (strpos($_SESSION['ldap']->objectClasses[$i], "NAME '$objectClass'")) $line = $i;
} }
// Return error if objectClass isn't found // Return error if objectClass isn't found
if ($line==-1) trigger_error (sprintf(_("ObjectClass %s required but not defined in ldap."), $objectClass), E_USER_WARNING); if ($line==-1) trigger_error (sprintf(_("ObjectClass %s required but not defined in ldap."), $objectClass), E_USER_WARNING);
if (strpos($_SESSION[$this->ldap]->objectClasses[$line], 'MUST (')) { if (strpos($_SESSION['ldap']->objectClasses[$line], 'MUST (')) {
$string_withtail = substr($_SESSION[$this->ldap]->objectClasses[$line], strpos($_SESSION[$this->ldap]->objectClasses[$line], 'MUST (')+6); $string_withtail = substr($_SESSION['ldap']->objectClasses[$line], strpos($_SESSION['ldap']->objectClasses[$line], 'MUST (')+6);
// Now we have a string with all must-attributes // Now we have a string with all must-attributes
$string = substr($string_withtail, 0, strpos($string_withtail, ')')); $string = substr($string_withtail, 0, strpos($string_withtail, ')'));
$string = trim($string); $string = trim($string);
@ -732,8 +733,8 @@ class accountContainer {
} }
// create array with may-attributes // create array with may-attributes
// Get startposition in string // Get startposition in string
if (strpos($_SESSION[$this->ldap]->objectClasses[$line], 'MAY (')) { if (strpos($_SESSION['ldap']->objectClasses[$line], 'MAY (')) {
$string_withtail = substr($_SESSION[$this->ldap]->objectClasses[$line], strpos($_SESSION[$this->ldap]->objectClasses[$line], 'MAY (')+5); $string_withtail = substr($_SESSION['ldap']->objectClasses[$line], strpos($_SESSION['ldap']->objectClasses[$line], 'MAY (')+5);
// Now we have a string with all must-attributes // Now we have a string with all must-attributes
$string = substr($string_withtail, 0, strpos($string_withtail, ')')); $string = substr($string_withtail, 0, strpos($string_withtail, ')'));
$string = trim($string); $string = trim($string);
@ -743,19 +744,19 @@ class accountContainer {
} }
} }
// Get attributes of subclasses // Get attributes of subclasses
while (strpos($_SESSION[$this->ldap]->objectClasses[$line], "SUP ")) { while (strpos($_SESSION['ldap']->objectClasses[$line], "SUP ")) {
$string_withtail = substr($_SESSION[$this->ldap]->objectClasses[$line], strpos($_SESSION[$this->ldap]->objectClasses[$line], 'SUP ')+4); $string_withtail = substr($_SESSION['ldap']->objectClasses[$line], strpos($_SESSION['ldap']->objectClasses[$line], 'SUP ')+4);
$subclass = substr($string_withtail, 0, strpos($string_withtail, ' ')); $subclass = substr($string_withtail, 0, strpos($string_withtail, ' '));
// Add account type to object // Add account type to object
for ($i=0; $i<count($_SESSION[$this->ldap]->objectClasses) || $i==-1; $i++) { for ($i=0; $i<count($_SESSION['ldap']->objectClasses) || $i==-1; $i++) {
if (strpos($_SESSION[$this->ldap]->objectClasses[$i], "NAME '$subclass'")) $line = $i; if (strpos($_SESSION['ldap']->objectClasses[$i], "NAME '$subclass'")) $line = $i;
} }
// Return error if objectClass isn't found // Return error if objectClass isn't found
if ($line==-1) trigger_error (sprintf(_("ObjectClass %s required but not defined in ldap."), $subclass), E_USER_WARNING); if ($line==-1) trigger_error (sprintf(_("ObjectClass %s required but not defined in ldap."), $subclass), E_USER_WARNING);
// create array with must-attributes // create array with must-attributes
// Get startposition in string // Get startposition in string
if (strpos($_SESSION[$this->ldap]->objectClasses[$line], 'MUST (')) { if (strpos($_SESSION['ldap']->objectClasses[$line], 'MUST (')) {
$string_withtail = substr($_SESSION[$this->ldap]->objectClasses[$line], strpos($_SESSION[$this->ldap]->objectClasses[$line], 'MUST (')+6); $string_withtail = substr($_SESSION['ldap']->objectClasses[$line], strpos($_SESSION['ldap']->objectClasses[$line], 'MUST (')+6);
// Now we have a string with all must-attributes // Now we have a string with all must-attributes
$string = substr($string_withtail, 0, strpos($string_withtail, ')')); $string = substr($string_withtail, 0, strpos($string_withtail, ')'));
$string = trim($string); $string = trim($string);
@ -766,8 +767,8 @@ class accountContainer {
} }
// create array with may-attributes // create array with may-attributes
// Get startposition in string // Get startposition in string
if (strpos($_SESSION[$this->ldap]->objectClasses[$line], 'MAY (')) { if (strpos($_SESSION['ldap']->objectClasses[$line], 'MAY (')) {
$string_withtail = substr($_SESSION[$this->ldap]->objectClasses[$line], strpos($_SESSION[$this->ldap]->objectClasses[$line], 'MAY (')+5); $string_withtail = substr($_SESSION['ldap']->objectClasses[$line], strpos($_SESSION['ldap']->objectClasses[$line], 'MAY (')+5);
// Now we have a string with all must-attributes // Now we have a string with all must-attributes
$string = substr($string_withtail, 0, strpos($string_withtail, ')')); $string = substr($string_withtail, 0, strpos($string_withtail, ')'));
$string = trim($string); $string = trim($string);
@ -867,11 +868,11 @@ class accountContainer {
$function = '$modules = $_SESSION[$this->config]->get_'.ucfirst($this->type).'Modules();'; $function = '$modules = $_SESSION[$this->config]->get_'.ucfirst($this->type).'Modules();';
eval ($function); eval ($function);
$search = substr($dn, 0, strpos($dn, ',')); $search = substr($dn, 0, strpos($dn, ','));
$result = ldap_search($_SESSION[$this->ldap]->server(), $dn, $search); $result = ldap_search($_SESSION['ldap']->server(), $dn, $search);
$entry = ldap_first_entry($_SESSION[$this->ldap]->server(), $result); $entry = ldap_first_entry($_SESSION['ldap']->server(), $result);
$this->dn = substr($dn, strpos($dn, ',')+1); $this->dn = substr($dn, strpos($dn, ',')+1);
$this->dn_orig = $dn; $this->dn_orig = $dn;
$attr = ldap_get_attributes($_SESSION[$this->ldap]->server(), $entry); $attr = ldap_get_attributes($_SESSION['ldap']->server(), $entry);
foreach ($modules as $module) { foreach ($modules as $module) {
if (!isset($this->module[$module])) { if (!isset($this->module[$module])) {
@ -1058,10 +1059,10 @@ class accountContainer {
if ($this->dn_orig!='') { if ($this->dn_orig!='') {
// merge attributes together // merge attributes together
$attr = array_merge_recursive($attributes[$this->dn]['add'], $attributes[$this->dn]['notchanged'], $attributes[$this->dn]['modify']); $attr = array_merge_recursive($attributes[$this->dn]['add'], $attributes[$this->dn]['notchanged'], $attributes[$this->dn]['modify']);
$success = @ldap_add($_SESSION[$this->ldap]->server(), $this->dn, $attr); $success = @ldap_add($_SESSION['ldap']->server(), $this->dn, $attr);
if ($success) { if ($success) {
$_SESSION[$this->cache]->update_cache($this->$dn, 'add', $attr); $_SESSION[$this->cache]->update_cache($this->$dn, 'add', $attr);
$success = @ldap_delete($_SESSION[$this->ldap]->server(), $this->dn_orig); $success = @ldap_delete($_SESSION['ldap']->server(), $this->dn_orig);
if (!$success) { if (!$success) {
$errors[] = array('ERROR', 'LDAP', sprintf(_('Was unable to delete dn: %s.'), $this->dn_orig)); $errors[] = array('ERROR', 'LDAP', sprintf(_('Was unable to delete dn: %s.'), $this->dn_orig));
$stopprocessing = true; $stopprocessing = true;
@ -1077,7 +1078,7 @@ class accountContainer {
// create complete new dn // create complete new dn
else { else {
$attr = array_merge_recursive($attributes[$this->dn]['add'], $attributes[$this->dn]['notchanged'], $attributes[$this->dn]['modify']); $attr = array_merge_recursive($attributes[$this->dn]['add'], $attributes[$this->dn]['notchanged'], $attributes[$this->dn]['modify']);
$success = @ldap_add($_SESSION[$this->ldap]->server(), $this->dn, $attributes[$this->dn]['add']); $success = @ldap_add($_SESSION['ldap']->server(), $this->dn, $attributes[$this->dn]['add']);
if (!$success) { if (!$success) {
$errors[] = array('ERROR', 'LDAP', sprintf(_('Was unable to create dn: %s. This is possible a bug. Please check your ldap logs and send a bug report if it is a possible bug.'), $this->dn)); $errors[] = array('ERROR', 'LDAP', sprintf(_('Was unable to create dn: %s. This is possible a bug. Please check your ldap logs and send a bug report if it is a possible bug.'), $this->dn));
$stopprocessing = true; $stopprocessing = true;
@ -1093,7 +1094,7 @@ class accountContainer {
if (!$stopprocessing) { if (!$stopprocessing) {
// modify attributes // modify attributes
if (isset($attributes[$DNs[$i]]['modify']) && !$stopprocessing) { if (isset($attributes[$DNs[$i]]['modify']) && !$stopprocessing) {
$success = @ldap_mod_replace($_SESSION[$this->ldap]->server(), $DNs[$i], $attributes[$DNs[$i]]['modify']); $success = @ldap_mod_replace($_SESSION['ldap']->server(), $DNs[$i], $attributes[$DNs[$i]]['modify']);
if (!$success) { if (!$success) {
$errors[] = array('ERROR', 'LDAP', sprintf(_('Was unable to modify attribtues from dn: %s. This is possible a bug. Please check your ldap logs and send a bug report if it is a possible bug.'), $DNs[$i])); $errors[] = array('ERROR', 'LDAP', sprintf(_('Was unable to modify attribtues from dn: %s. This is possible a bug. Please check your ldap logs and send a bug report if it is a possible bug.'), $DNs[$i]));
$stopprocessing = true; $stopprocessing = true;
@ -1103,7 +1104,7 @@ class accountContainer {
} }
// add attributes // add attributes
if (isset($attributes[$DNs[$i]]['add']) && !$stopprocessing) { if (isset($attributes[$DNs[$i]]['add']) && !$stopprocessing) {
$success = @ldap_mod_add($_SESSION[$this->ldap]->server(), $DNs[$i], $attributes[$DNs[$i]]['add']); $success = @ldap_mod_add($_SESSION['ldap']->server(), $DNs[$i], $attributes[$DNs[$i]]['add']);
if (!$success) { if (!$success) {
$errors[] = array('ERROR', 'LDAP', sprintf(_('Was unable to add attribtues to dn: %s. This is possible a bug. Please check your ldap logs and send a bug report if it is a possible bug.'), $DNs[$i])); $errors[] = array('ERROR', 'LDAP', sprintf(_('Was unable to add attribtues to dn: %s. This is possible a bug. Please check your ldap logs and send a bug report if it is a possible bug.'), $DNs[$i]));
$stopprocessing = true; $stopprocessing = true;
@ -1113,7 +1114,7 @@ class accountContainer {
} }
// removce attributes // removce attributes
if (isset($attributes[$DNs[$i]]['remove']) && !$stopprocessing) { if (isset($attributes[$DNs[$i]]['remove']) && !$stopprocessing) {
$success = @ldap_mod_del($_SESSION[$this->ldap]->server(), $DNs[$i], $attributes[$DNs[$i]]['remove']); $success = @ldap_mod_del($_SESSION['ldap']->server(), $DNs[$i], $attributes[$DNs[$i]]['remove']);
if (!$success) { if (!$success) {
$errors[] = array('ERROR', 'LDAP', sprintf(_('Was unable to remove attribtues from dn: %s. This is possible a bug. Please check your ldap logs and send a bug report if it is a possible bug.'), $DNs[$i])); $errors[] = array('ERROR', 'LDAP', sprintf(_('Was unable to remove attribtues from dn: %s. This is possible a bug. Please check your ldap logs and send a bug report if it is a possible bug.'), $DNs[$i]));
$stopprocessing = true; $stopprocessing = true;
@ -1145,7 +1146,7 @@ class accountContainer {
function lamdaemon($commands) { function lamdaemon($commands) {
// get username and password of the current lam-admin // get username and password of the current lam-admin
$ldap_q = $_SESSION[$this->ldap]->decrypt_login(); $ldap_q = $_SESSION['ldap']->decrypt_login();
/* $towrite has the following syntax: /* $towrite has the following syntax:
* admin-username, admin-password, owner of homedir, 'home', operation='add' * admin-username, admin-password, owner of homedir, 'home', operation='add'
* use escapeshellarg to make exec() shell-safe * use escapeshellarg to make exec() shell-safe