summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 38b0405)
raw | patch | inline | side by side (parent: 38b0405)
author | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Thu, 29 Jul 2010 07:14:40 +0000 (07:14 +0000) | ||
committer | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Thu, 29 Jul 2010 07:14:40 +0000 (07:14 +0000) |
git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.6@19194 594d385d-05f5-0310-b6e9-bd551577e9d8
gosa-core/include/class_ldap.inc | patch | blob | history |
index d75f800b42443a3ffe4c4d92c146aaeeaf5ea445..e12a5478a1e1c75a54f93567312020b53730119e 100644 (file)
}
- function gen_ldif ($srp, $dn, $filter= "(objectClass=*)", $attributes= array('*'), $recursive= TRUE)
+ /*! \brief Generates an ldif for all entries matching the filter settings, scope and limit.
+ * @param $dn The entry to export.
+ * @param $filter Limit the exported object to those maching this filter.
+ * @param $attributes Specify the attributes to export here, empty means all.
+ * @param $scope 'base', 'sub' .. see manpage for 'ldapmodify' for details.
+ * @param $limit Limits the result.
+ */
+ function generateLdif ($dn, $filter= "(objectClass=*)", $attributes= array(), $scope = 'sub', $limit=0)
{
- $display= "";
-
- if ($recursive){
- $this->cd($dn);
- $this->ls($srp, $filter,$dn, array('dn','objectClass'));
- $deps = array();
-
- $display .= $this->gen_one_entry($dn)."\n";
-
- while ($attrs= $this->fetch($srp)){
- $deps[] = $attrs['dn'];
- }
- foreach($deps as $dn){
- $display .= $this->gen_ldif($srp, $dn, $filter,$attributes,$recursive);
- }
- } else {
- $display.= $this->gen_one_entry($dn);
- }
- return ($display);
+ $attrs = (count($attributes))?implode($attributes,' '):'';
+ $scope = (!empty($scope))?' -s '.$scope: '';
+ $limit = (!$limit)?'':' -z '.$limit;
+ $dn = escapeshellarg($dn);
+ $admin = escapeshellarg($this->binddn);
+ $pwd = escapeshellarg($this->bindpw);
+ $filter = escapeshellarg($filter);
+ $host = escapeshellarg($this->hostname);
+ $cmd = "ldapsearch -x -LLLL -D {$admin} -w {$pwd} {$filter} {$limit} {$scope} -H {$host} -b {$dn} $attrs ";
+ ob_start();
+ passthru($cmd);
+ $res=ob_get_contents();
+ ob_end_clean();
+ return($res);
}
return ($display);
}
-
-
- function gen_one_entry($dn, $filter= "(objectClass=*)" , $name= array("*"))
- {
- $ret = "";
- $data = "";
- if($this->reconnect){
- $this->connect();
- }
-
- /* Searching Ldap Tree */
- $sr= @ldap_read($this->cid, LDAP::fix($dn), $filter, $name);
-
- /* Get the first entry */
- $entry= @ldap_first_entry($this->cid, $sr);
-
- /* Get all attributes related to that Objekt */
- $atts = array();
- /* Assemble dn */
- $atts[0]['name'] = "dn";
- $atts[0]['value'] = array('count' => 1, 0 => $dn);
-
- /* Reset index */
- $i = 1 ;
- $identifier = array();
- $attribute= @ldap_first_attribute($this->cid,$entry,$identifier);
- while ($attribute) {
- $i++;
- $atts[$i]['name'] = $attribute;
- $atts[$i]['value'] = @ldap_get_values_len($this->cid, $entry, "$attribute");
-
- /* Next one */
- $attribute= @ldap_next_attribute($this->cid,$entry,$identifier);
- }
-
- foreach($atts as $at)
- {
- for ($i= 0; $i<$at['value']['count']; $i++){
-
- /* Check if we must encode the data */
- if(!preg_match('/^[a-z0-9+@#.=, \/ -]+$/i', $at['value'][$i])) {
- $ret .= $at['name'].":: ".base64_encode($at['value'][$i])."\n";
- } else {
- $ret .= $at['name'].": ".$at['value'][$i]."\n";
- }
- }
- }
-
- return($ret);
- }
-
function dn_exists($dn)
{