Index: inc/class.accounts_ldap.inc.php =================================================================== RCS file: /cvsroot/phpgwapi/phpgwapi/inc/Attic/class.accounts_ldap.inc.php,v retrieving revision 1.101.2.13.2.41 diff -u -d -r1.101.2.13.2.41 class.accounts_ldap.inc.php --- inc/class.accounts_ldap.inc.php 18 Dec 2005 08:43:55 -0000 1.101.2.13.2.41 +++ inc/class.accounts_ldap.inc.php 12 Mar 2006 12:09:18 -0000 @@ -57,6 +57,15 @@ { $GLOBALS['phpgw_info']['server']['ldap_structural_objectclass'] = 'account'; } + //XXX Caeies this should be modified in setup !!! (that's next step) + if(!isset($GLOBALS['phpgw_info']['server']['ldap_group_number'])) + { + $GLOBALS['phpgw_info']['server']['ldap_group_number'] = 'gidnumber'; //else 'phpgwgroupid' + } + if(!isset($GLOBALS['phpgw_info']['server']['ldap_user_number'])) + { + $GLOBALS['phpgw_info']['server']['ldap_user_number'] = 'uidnumber'; //else 'phpgwaccountid' + } if($GLOBALS['phpgw_info']['server']['account_repository'] == 'ldap') { $this->ds = $GLOBALS['phpgw']->common->ldapConnect(); @@ -74,18 +83,18 @@ /* search the dn for the given uid */ if ( ($acct_type == 'g') && $this->group_context ) { - $sri = ldap_search($this->ds, $this->group_context, 'gidnumber='.$this->account_id); + $sri = ldap_search($this->ds, $this->group_context, $GLOBALS['phpgw_info']['server']['ldap_group_number'].'='.$this->account_id); } else { - $sri = ldap_search($this->ds, $this->user_context, 'uidnumber='.$this->account_id); + $sri = ldap_search($this->ds, $this->user_context, $GLOBALS['phpgw_info']['server']['ldap_user_number'].'='.$this->account_id); } $allValues = ldap_get_entries($this->ds, $sri); /* Now dump it into the array; take first entry found */ if($acct_type == 'g') { - $this->data['account_id'] = $allValues[0]['gidnumber'][0]; + $this->data['account_id'] = $allValues[0][$GLOBALS['phpgw_info']['server']['ldap_group_number']][0]; $this->data['account_lid'] = $allValues[0]['cn'][0]; $this->data['account_firstname'] = utf8_decode($allValues[0]['cn'][0]); $this->data['account_lastname'] = 'Group'; @@ -93,7 +102,7 @@ } else { - $this->data['account_id'] = $allValues[0]['uidnumber'][0]; + $this->data['account_id'] = $allValues[0][$GLOBALS['phpgw_info']['server']['ldap_user_number']][0]; $this->data['account_lid'] = $allValues[0]['uid'][0]; $this->data['account_firstname'] = utf8_decode($allValues[0]['givenname'][0]); $this->data['account_lastname'] = utf8_decode($allValues[0]['sn'][0]); @@ -153,12 +162,12 @@ if ($type == 'g') { - $sri = ldap_search($this->ds, $this->group_context, '(&(objectclass=phpgwgroup)(gidnumber='.$id.'))'); + $sri = ldap_search($this->ds, $this->group_context, '(&(objectclass=phpgwgroup)('.$GLOBALS['phpgw_info']['server']['ldap_group_number'].'='.$id.'))'); $allValues = ldap_get_entries($this->ds, $sri); } else { - $sri = ldap_search($this->ds, $this->user_context, '(&(objectclass=phpgwaccount)(uidnumber='.$id.'))'); + $sri = ldap_search($this->ds, $this->user_context, '(&(objectclass=phpgwaccount)('.$GLOBALS['phpgw_info']['server']['ldap_user_number'].'='.$id.'))'); $allValues = ldap_get_entries($this->ds, $sri); } @@ -252,11 +261,11 @@ { if(empty($query) || $query == "*") { - $filter = '(&(uidnumber=*)(objectclass=phpgwaccount))'; + $filter = '(&('.$GLOBALS['phpgw_info']['server']['ldap_user_number'].'=*)(objectclass=phpgwaccount))'; } else { - $filter = "(&(uidnumber=*)(objectclass=phpgwaccount)(|(uid=*$query*)(sn=*$query*)(cn=*$query*)(givenname=*$query*)))"; + $filter = '(&('.$GLOBALS['phpgw_info']['server']['ldap_user_number']."=*)(objectclass=phpgwaccount)(|(uid=*$query*)(sn=*$query*)(cn=*$query*)(givenname=*$query*)))"; } $sri = ldap_search($this->ds, $this->user_context, $filter); $allValues = ldap_get_entries($this->ds, $sri); @@ -267,7 +276,7 @@ if (!$GLOBALS['phpgw_info']['server']['global_denied_users'][$test] && $allVals['uid'][0]) { $accounts[] = Array( - 'account_id' => $allVals['uidnumber'][0], + 'account_id' => $allVals[$GLOBALS['phpgw_info']['server']['ldap_user_number']][0], 'account_lid' => $allVals['uid'][0], 'account_type' => 'u', 'account_firstname' => utf8_decode($allVals['givenname'][0]), @@ -289,11 +298,11 @@ { if(empty($query) || $query == "*") { - $filter = '(&(gidnumber=*)(objectclass=phpgwgroup))'; + $filter = '(&('.$GLOBALS['phpgw_info']['server']['ldap_group_number'].'=*)(objectclass=phpgwgroup))'; } else { - $filter = "(&(gidnumber=*)(objectclass=phpgwgroup)(|(uid=*$query*)(sn=*$query*)(cn=*$query*)(givenname=*$query*)))"; + $filter = '(&('.$GLOBALS['phpgw_info']['server']['ldap_group_number']."=*)(objectclass=phpgwgroup)(|(uid=*$query*)(sn=*$query*)(cn=*$query*)(givenname=*$query*)))"; } $sri = ldap_search($this->ds, $this->group_context, $filter); $allValues = ldap_get_entries($this->ds, $sri); @@ -304,7 +313,7 @@ if (!$GLOBALS['phpgw_info']['server']['global_denied_groups'][$test] && $allVals['cn'][0]) { $groups[] = Array( - 'account_id' => $allVals['gidnumber'][0], + 'account_id' => $allVals[$GLOBALS['phpgw_info']['server']['ldap_group_number']][0], 'account_lid' => $allVals['cn'][0], 'account_firstname' => utf8_decode($allVals['cn'][0]), 'account_lastname' => ucfirst(lang('group')), @@ -354,9 +363,9 @@ $sri = ldap_search($this->ds, $this->group_context, '(&(cn='. $name .')(objectclass=phpgwgroup))'); $allValues = ldap_get_entries($this->ds, $sri); - if (@$allValues[0]['gidnumber'][0]) + if (@$allValues[0][$GLOBALS['phpgw_info']['server']['ldap_group_number']][0]) { - return intval($allValues[0]['gidnumber'][0]); + return intval($allValues[0][$GLOBALS['phpgw_info']['server']['ldap_group_number']][0]); } else { @@ -375,9 +384,9 @@ $sri = ldap_search($this->ds, $this->user_context, '(&(uid='. $name .')(objectclass=phpgwaccount))'); $allValues = ldap_get_entries($this->ds, $sri); - if (@$allValues[0]['uidnumber'][0]) + if (@$allValues[0][$GLOBALS['phpgw_info']['server']['ldap_user_number']][0]) { - return intval($allValues[0]['uidnumber'][0]); + return intval($allValues[0][$GLOBALS['phpgw_info']['server']['ldap_user_number']][0]); } else { @@ -422,6 +431,7 @@ return $name; } + //XXX Obsolete but should work ... Caeies function search_person($person_id) { static $person_list; @@ -432,22 +442,22 @@ $allValues = array(); // Groups are person? are you sure? - $sri = ldap_search($this->ds, $this->group_context, "(&(person_id=$person_id)(phpgwaccounttype=g))"); + $sri = ldap_search($this->ds, $this->group_context, "(&(phpgwcontactid=$person_id)(phpgwaccounttype=g))"); $allValues = ldap_get_entries($this->ds, $sri); - if (@$allValues[0]['gidnumber'][0]) + if (@$allValues[0][$GLOBALS['phpgw_info']['server']['ldap_group_number']][0]) { - $person_list[$person_id] = intval($allValues[0]['gidnumber'][0]); + $person_list[$person_id] = intval($allValues[0][$GLOBALS['phpgw_info']['server']['ldap_group_number']][0]); return $person_list[$person_id]; } $allValues = array(); - $sri = ldap_search($this->ds, $this->user_context, "(&(person_id=$person_id)(phpgwaccounttype=u))"); + $sri = ldap_search($this->ds, $this->user_context, "(&(phpgwcontactid=$person_id)(phpgwaccounttype=u))"); $allValues = ldap_get_entries($this->ds, $sri); - if (@$allValues[0]['uidnumber'][0]) + if (@$allValues[0][$GLOBALS['phpgw_info']['server']['ldap_user_number']][0]) { - $person_list[$person_id] = intval($allValues[0]['uidnumber'][0]); + $person_list[$person_id] = intval($allValues[0][$GLOBALS['phpgw_info']['server']['ldap_user_number']][0]); return $person_list[$person_id]; } @@ -519,7 +529,7 @@ function get_nextAccountID() { $filter = '(|(objectclass=posixaccount)(objectclass=phpgwaccount))'; - $result = ldap_search($this->ds, $this->user_context, $filter, array('uidnumber')); + $result = ldap_search($this->ds, $this->user_context, $filter, array($GLOBALS['phpgw_info']['server']['ldap_user_number'])); $allValues = ldap_get_entries($this->ds, $result); // parse all LDAP uidnumbers in a single array '$IDs' @@ -527,7 +537,7 @@ { if (is_int($key)) { - $IDs[] = $allValues[$key]['uidnumber'][0]; + $IDs[] = $allValues[$key][$GLOBALS['phpgw_info']['server']['ldap_user_number']][0]; } } return $this->idTester($IDs, $GLOBALS['phpgw_info']['server']['account_min_id'], $GLOBALS['phpgw_info']['server']['account_max_id'] ); @@ -541,14 +551,14 @@ function get_nextGroupID() { $filter = '(|(objectclass=posixgroup)(objectclass=phpgwgroup))'; - $result = ldap_search($this->ds, $this->group_context, $filter, array('gidnumber')); + $result = ldap_search($this->ds, $this->group_context, $filter, array($GLOBALS['phpgw_info']['server']['ldap_group_number'])); $allValues = ldap_get_entries($this->ds, $result); while (list($key,$val) = each($allValues)) { if (is_int($key)) { - $IDs[] = $allValues[$key]['gidnumber'][0]; + $IDs[] = $allValues[$key][$GLOBALS['phpgw_info']['server']['ldap_group_number']][0]; } } return $this->idTester($IDs, $GLOBALS['phpgw_info']['server']['group_min_id'], $GLOBALS['phpgw_info']['server']['group_max_id'] ); @@ -565,7 +575,7 @@ { if ($id) { - $result = ldap_search($this->ds, $this->group_context, '(&(phpgwGroupID='.$id.')(objectclass=phpgwGroup))'); + $result = ldap_search($this->ds, $this->group_context, '(&('.$GLOBALS['phpgw_info']['server']['ldap_group_number'].'='.$id.')(objectclass=phpgwGroup))'); $allValues = ldap_get_entries($this->ds, $result); if ($allValues[0]['dn']) { @@ -590,7 +600,7 @@ { if ($id) { - $result = ldap_search($this->ds, $this->user_context, '(&(phpgwAccountID='.$id.')(objectclass=phpgwAccount))'); + $result = ldap_search($this->ds, $this->user_context, '(&('.$GLOBALS['phpgw_info']['server']['ldap_user_number'].'='.$id.')(objectclass=phpgwAccount))'); $allValues = ldap_get_entries($this->ds, $result); if ($allValues[0]['dn']) { @@ -771,7 +781,6 @@ $entry['objectclass'][] = 'posixAccount'; $entry['objectclass'][] = $GLOBALS['phpgw_info']['server']['ldap_structural_objectclass']; //'account'; $entry['cn'] = utf8_encode($this->get_fullname($account_info['account_firstname'], $account_info['account_lastname'])); - $entry['uidnumber'] = $account_info['account_id']; $entry['uid'] = $account_info['account_lid']; $entry['description'] = utf8_encode(str_replace('*','',lang('phpgw-created account'))); if ( $account_info['account_firstname'] ) @@ -804,6 +813,21 @@ if ($this->createMode == 'replace') { ldap_delete($this->ds, $oldEntry['dn']); + if($GLOBALS['phpgw_info']['server']['ldap_user_number'] != 'uidnumber') + { + if(isset($oldEntry['uidnumber'])) + { + $entry['uidnumber'] = $oldEntry['uidnumber']; //XXX Not tested, hope this works ! + } + else + { + $entry['uidnumber'] = $account_info['account_id']; + } + } + else + { + $entry['uidnumber'] = $account_info['account_id']; + } $this->add_LDAP_Entry($dn, $entry); } elseif ($this->createMode == 'extend') @@ -912,8 +936,10 @@ } else { - $entry['gidnumber'] = $account_info['account_id']; + $entry['gidnumber'] = $account_info['account_id']; } + //XXX same for the uidnumber + $entry['uidnumber'] = $account_info['account_id']; $this->add_LDAP_Entry($dn, $entry); } } @@ -931,8 +957,12 @@ // phpgw needed attributes $entry['objectclass'][] = 'phpgwGroup'; - $entry['phpgwgroupID'] = $account_info['account_id']; - $entry['gidnumber'] = $account_info['account_id']; + if(!is_numeric($account_info['account_id'])) + { + _debug_array(debug_backtrace()); + die('You spotted a bug, please give us the backtrace of this and post it in savannah !'); + } + $entry['phpgwgroupid'] = $account_info['account_id']; // additional attributes from the phpgw for groups $entry['objectclass'][] = 'posixGroup'; @@ -950,6 +980,21 @@ { if ($this->createMode == 'replace') { + if($GLOBALS['phpgw_info']['server']['ldap_group_number'] != 'gidnumber') + { + if(isset($oldEntry['gidnumber'])) + { + $entry['gidnumber'] = $oldEntry['gidnumber']; + } + else + { + $entry['gidnumber'] = $account_info['account_id']; + } + } + else + { + $entry['gidnumber'] = $account_info['account_id']; + } ldap_delete($this->ds, $oldEntry['dn']); $this->add_LDAP_Entry($dn, $entry); } @@ -1006,6 +1051,8 @@ } else // entry not yet in LDAP { + //touch the gidnumber ONLY if we create the account ... + $entry['gidnumber'] = $account_info['account_id']; $this->add_LDAP_Entry($dn, $entry); } } @@ -1188,11 +1235,11 @@ /* search the dn for the given uid */ if ( ($acct_type == 'g') && $this->group_context ) { - $sri = ldap_search($this->ds, $this->group_context, "phpgwGroupID={$account_id}"); + $sri = ldap_search($this->ds, $this->group_context, "{$GLOBALS['phpgw_info']['server']['ldap_group_number']}={$account_id}"); } else { - $sri = ldap_search($this->ds, $this->user_context, "phpgwAccountID={$account_id}"); + $sri = ldap_search($this->ds, $this->user_context, "{$GLOBALS['phpgw_info']['server']['ldap_user_number']}={$account_id}"); } $allValues = ldap_get_entries($this->ds, $sri); @@ -1249,7 +1296,7 @@ { $_account_id = get_account_id($id); - $sri = ldap_search($this->ds, $this->user_context, 'uidnumber='.$id, array('dn')); + $sri = ldap_search($this->ds, $this->user_context, $GLOBALS['phpgw_info']['server']['ldap_user_number'].'='.$id, array('dn')); $allValues = ldap_get_entries($this->ds, $sri); if ($allValues[0]['dn']) { @@ -1263,7 +1310,7 @@ function get_account_with_contact() { - $sri = ldap_search($this->ds, $this->user_context, "(&(phpgwaccounttype=u)(phpgwpersonid=*))", array('uidnumber', 'phpgwpersonid')); + $sri = ldap_search($this->ds, $this->user_context, "(&(phpgwaccounttype=u)(phpgwcontactid=*))", array($GLOBALS['phpgw_info']['server']['ldap_user_number'], 'phpgwcontactid')); $allValues = ldap_get_entries($this->ds, $sri); if(is_array($allValues)) { @@ -1271,7 +1318,7 @@ for($i=0;$i<$count; $i++) { $value = &$allValue[$i]; - $accounts[$value['uidnumber'][0]] = $value['phpgwpersonid'][0]; + $accounts[$value[$GLOBALS['phpgw_info']['server']['ldap_user_number']][0]] = $value['phpgwcontactid'][0]; } } @@ -1280,7 +1327,7 @@ function get_account_without_contact() { - $sri = ldap_search($this->ds, $this->user_context, "(&(phpgwaccounttype=u)(!(phpgwpersonid=*)))", array('uidnumber')); + $sri = ldap_search($this->ds, $this->user_context, "(&(phpgwaccounttype=u)(!(phpgwcontactid=*)))", array($GLOBALS['phpgw_info']['server']['ldap_user_number'])); $allValues = ldap_get_entries($this->ds, $sri); if(is_array($allValues)) { @@ -1288,7 +1335,7 @@ for($i=0;$i<$count;$i++)//foreach(allValues as $value) { $value = &$allValue[$i]; - $accounts[] = $value['uidnumber'][0]; + $accounts[] = $value[$GLOBALS['phpgw_info']['server']['ldap_user_number']][0]; } } return $accounts;