/** * Parse LDIF lines of one entry into an Net_LDAP_Entry object * * @param array $lines LDIF lines for one entry * * @return Net_LDAP_Entry|false Net_LDAP_Entry object for those lines * @todo what about file inclusions and urls? "jpegphoto:< file:///usr/local/directory/photos/fiona.jpg" */ function parseLines($lines) { // parse lines into an array of attributes and build the entry $attributes = array(); $dn = false; foreach ($lines as $line) { if (preg_match('/^(\\w+)(:|::|:<)\\s(.+)$/', $line, $matches)) { $attr =& $matches[1]; $delim =& $matches[2]; $data =& $matches[3]; if ($delim == ':') { // normal data $attributes[$attr][] = $data; } elseif ($delim == '::') { // base64 data $attributes[$attr][] = base64_decode($data); } elseif ($delim == ':<') { // file inclusion // TODO: Is this the job of the LDAP-client or the server? $this->_dropError('File inclusions are currently not supported'); //$attributes[$attr][] = ...; } else { // since the pattern above, the delimeter cannot be something else. $this->_dropError('Net_LDAP_LDIF parsing error: invalid syntax at parsing entry line: ' . $line); continue; } if (strtolower($attr) == 'dn') { // DN line detected $dn = $attributes[$attr][0]; // save possibly decoded DN unset($attributes[$attr]); // remove wrongly added "dn: " attribute } } else { // line not in "attr: value" format -> ignore // maybe we should rise an error here, but this should be covered by // next_lines() already. A problem arises, if users try to feed data of // several entries to this method - the resulting entry will // get wrong attributes. However, this is already mentioned in the // methods documentation above. } } if (false === $dn) { $this->_dropError('Net_LDAP_LDIF parsing error: unable to detect DN for entry'); return false; } else { $newentry = Net_LDAP_Entry::createFresh($dn, $attributes); return $newentry; } }
/** * Copy an entry to a new location * * The entry will be immediately copied. * Please note that only attributes you have * selected will be copied. * * @param Net_LDAP_Entry &$entry Entry object * @param string $newdn New FQF-DN of the entry * * @return Net_LDAP_Error|Net_LDAP_Entry Error Message or reference to the copied entry */ function ©(&$entry, $newdn) { if (!is_a($entry, 'Net_LDAP_Entry')) { return PEAR::raiseError('Parameter $entry is expected to be a Net_LDAP_Entry object!'); } $newentry = Net_LDAP_Entry::createFresh($newdn, $entry->getValues()); $result = $this->add($newentry); if (is_a($result, 'Net_LDAP_Error')) { return $result; } else { return $newentry; } }
/** * Parses the schema of the given Subschema entry * * @access public * @param Net_LDAP_Entry $entry Subschema entry */ function parse(&$entry) { foreach ($this->types as $type => $attr) { // initialize map type to entry $type_var = '_' . $attr; $this->{$type_var} = array(); // get values for this type $values = $entry->get_value($attr); if (is_array($values)) { foreach ($values as $value) { unset($schema_entry); // this was a real mess without it // get the schema entry $schema_entry = $this->_parse_entry($value); // set the type $schema_entry['type'] = $type; // save a ref in $_oids $this->_oids[$schema_entry['oid']] =& $schema_entry; // save refs for all names in type map $names = $schema_entry['aliases']; array_push($names, $schema_entry['name']); foreach ($names as $name) { $this->{$type_var}[strtolower($name)] =& $schema_entry; } } } } }
/** * Copy an entry to a new location * * The entry will be immediately copied. * If you pass an Net_LDAP_Entry object, the source entry is not required * to be existent on this LDAP server, which can be used to * copy between directory servers. * * @param string|Net_LDAP_Entry $entry Entry DN or Entry object * @param string $newdn New location * @return Net_LDAP_Error|Net_LDAP_Entry Error Message or reference to the copied entry */ function ©(&$entry, $newdn) { if (!is_string($entry)) { $entry = new Net_LDAP_Entry($this, $entry); } if (!is_a($entry, 'Net_LDAP_Entry')) { return PEAR::raiseError('Parameter $entry is expected to be a Net_LDAP_Entry object! (If DN was passed, conversion failed)'); } $newentry = Net_LDAP_Entry::createFresh($newdn, $entry->getValues()); $result = $this->add($newentry); if (is_a($result, 'Net_LDAP_Error')) { return $result; } else { return $newentry; } }