16 include_once (
"Class.DbObj.php");
37 if (!$this->useldap)
false;
40 $orgldap[
"objectClass"] =
"organization";
41 if (preg_match(
"/.*o=(.*),.*/", $this->
racine, $reg)) $orgldap[
"o"] = $reg[1];
42 else $orgldap[
"o"] =
"unknown";
45 $ds = ldap_connect($this->serveur, $this->port);
48 ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
49 if (@ldap_bind($ds, $this->rootdn, $this->rootpw)) {
51 if (@ldap_search($ds,
"dc=users," . $dn,
"", array()))
return true;
53 if (!@ldap_search($ds,
"dc=users," . $dn,
"", array())) {
54 ldap_add($ds, $dn, $orgldap);
83 $this->serveur = $action->GetParam(
"LDAP_SERVEUR");
84 $this->port = $action->GetParam(
"LDAP_PORT");
85 $this->
racine = $action->GetParam(
"LDAP_ROOT");
86 $this->rootdn = $action->GetParam(
"LDAP_ROOTDN");
87 $this->rootpw = $action->GetParam(
"LDAP_ROOTPW");
88 $this->useldap = ($action->GetParam(
"LDAP_ENABLED",
"no") ==
"yes");
98 if ($this->ldapdn ==
"")
return array();
112 foreach ($toldn as $k => $dn) {
113 if (!in_array($dn, $tdn)) {
114 if (!@ldap_delete($ds, $dn)) {
115 $err.= sprintf(
"cannot delete LDAP entry [%s]", $dn);
119 $this->ldapdn = $this->_array2val($tdn);
120 $this->
modify(
true, array(
138 if (!$this->
UseLdap())
return false;
140 if (!$this->useldap)
return false;
157 if (!$this->
UseLdap())
return '';
158 if (!$this->useldap)
return '';
160 if (($this->serveur !=
"") && ($this->
id > 0)) {
161 $ds = ldap_connect($this->serveur, $this->port);
165 ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
166 if (@ldap_bind($ds, $this->rootdn, $this->rootpw)) {
180 if (!$rdn)
return false;
182 if (!$vdn)
return false;
193 include_once (
"FDL/Class.DocAttrLDAP.php");
194 $fids = $this->GetFromDoc();
195 if (!$fids)
return array();
196 include_once (
"Class.QueryDb.php");
197 $q =
new QueryDb($this->dbaccess,
"DocAttrLDAP");
199 $q->AddQuery(getSqlCond($fids,
"famid"));
200 $q->order_by =
"famid,index";
201 $l =
$q->Query(0, 0,
"TABLE");
202 $this->ldapmap = array();
203 if ($l && is_array($l)) {
205 $this->ldapmap[$v[
"ldapname"] . $v[
"index"]] = $v;
216 $this->infoldap = array();
220 foreach ($tmap as $ki => $v) {
222 $map = $v[
"ldapmap"];
223 $index = $v[
"index"];
225 if (substr($map, 0, 2) ==
"::") {
227 $this->cindex = $index;
228 $value = $this->ApplyMethod($map);
230 $this->infoldap[$index][$k] =
$value;
231 if ((!isset($this->infoldap[$index][
"objectClass"])) || (!in_array($v[
"ldapclass"], $this->infoldap[$index][
"objectClass"]))) $this->infoldap[$index][
"objectClass"][] = $v[
"ldapclass"];
236 $this->infoldap[$index][$k] = $this->initid;
244 $oa = $this->getAttribute($map);
245 $value = $this->getValue($map);
248 if ((!isset($this->infoldap[$index][
"objectClass"])) || (!in_array($v[
"ldapclass"], $this->infoldap[$index][
"objectClass"]))) $this->infoldap[$index][
"objectClass"][] = $v[
"ldapclass"];
255 if (
$vf->Retrieve($reg[2],
$info) ==
"") {
256 $fd = fopen(
$info->path,
"r");
258 $contents = @fread($fd, filesize(
$info->path));
259 $this->infoldap[$index][$k] = ($contents);
267 $this->infoldap[$index][$k] =
"{CRYPT}" . (
$value);
271 $this->infoldap[$index][$k] =
$value;
288 if (!isset($this->infoldap)) {
292 if ($index ==
"") $tldap = current($this->infoldap);
293 elseif (!isset($this->infoldap[$index]))
return null;
294 else $tldap = $this->infoldap[$index];
296 return isset($tldap[$idattr]) ? $tldap[$idattr] : null;
303 if (!$this->
UseLdap())
return false;
304 if (!$this->useldap)
return false;
306 if ($this->serveur !=
"") {
311 $ds = ldap_connect($this->serveur, $this->port);
315 ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
317 if (@ldap_bind($ds, $this->rootdn, $this->rootpw)) {
319 foreach ($tinfoldap as $k =>
$infoldap) {
322 if (!is_array($tdn)) $tdn = array(
325 foreach ($tdn as $dn) {
327 $sr = @ldap_read($ds, $dn,
"objectClass=*");
330 $attrs = ldap_get_attributes($ds, ldap_first_entry($ds, $sr));
333 for ($i = 0; $i < $attrs[
"count"]; $i++) {
334 if (!isset(
$infoldap[$attrs[$i]])) $delldap[$attrs[$i]] = array();
336 if (count($delldap) > 0) {
337 ldap_mod_del($ds, $dn, $delldap);
343 $retour.= sprintf(_(
"errldapadd:%s\n%s\n%d\n") , $dn, ldap_error($ds) , ldap_errno($ds));
351 $this->
setDNs($ds, $tnewdn);
356 $retour = _(
"errldapconnect");
359 $retour = _(
"errldaporginit");
371 if (!@ldap_add($ds,
"dc=$n," . $this->
racine, array(
372 "objectClass" => array(
378 )))
return ldap_error($ds);
ModifyLdapCard($tinfoldap)
newFreeVaultFile($dbaccess)
static rawValueToArray($v)
getLDAPValue($idattr, $index="")
modify($nopost=false, $sfields="", $nopre=false)
getLDAPDN($rdn, $path="")
if($file) if($subject==""&&$file) if($subject=="") $err