示例#1
0
# Output format, table or list?
$result_formats = array('list', 'table');
$format = isset($_GET['format']) ? $_GET['format'] : $config->GetValue('search', 'display');
if (!in_array($format, $result_formats)) {
    $format = 'list';
}
# build the server drop-down html and JavaScript array (for base_dns)
$js_on_change_string = '';
if (isset($_GET['form']) && $_GET['form'] == 'advanced') {
    $js_on_change_string = 'onChange="document.forms[0].base_dn.value=servers[document.forms[0].server_id.value].base_dn"';
}
if (isset($ldapserver)) {
    $server_menu_html = server_select_list($ldapserver->server_id, true, 'server_id', $js_on_change_string);
    $server_info_list = server_info_list();
}
$filter = isset($_GET['filter']) ? clean_search_vals($_GET['filter']) : null;
$attr = isset($_GET['attribute']) ? $_GET['attribute'] : null;
# grab the base dn for the search
if (isset($_GET['base_dn']) && $_GET['base_dn']) {
    $base_dn = $_GET['base_dn'];
    $base_dn_is_invalid = false;
    $base_dn_does_not_exist = false;
    if (trim($base_dn)) {
        if (!is_dn_string($base_dn)) {
            $base_dn_is_invalid = true;
        } elseif (!$ldapserver->dnExists($base_dn)) {
            $base_dn_does_not_exist = true;
        }
    }
    $base_dns = array($base_dn);
} else {
 /**
  * This function will check whether the value for an attribute being changed
  * is already assigned to another DN.
  *
  * Inputs:
  * @param dn $dn DN that is being changed
  * @param string $attr_name Attribute being changed
  * @param string|array $new values New values for the attribute
  *
  * Returns the bad value, or null if all values are OK
  */
 function checkUniqueAttr($dn, $attr_name, $new_value)
 {
     if (DEBUG_ENABLED) {
         debug_log('%s:checkUniqueAttr(): Entered with (%s,%s,%s)', 17, get_class($this), $dn, $attr_name, count($new_value));
     }
     global $ldapservers;
     # Is this attribute in the unique_attrs list?
     if ($this->isUniqueAttr($attr_name)) {
         $con = $this->connect(false, 'unique_attr', false, $ldapservers->GetValue($this->server_id, 'unique_attrs', 'dn'), $ldapservers->GetValue($this->server_id, 'unique_attrs', 'pass'));
         if (!$con) {
             pla_error(sprintf(_('Unable to bind to <b>%s</b> with your with unique_attrs credentials. Please check your configuration file.'), $this->name));
         }
         # Build our search filter to double check each attribute.
         $searchfilter = '(|';
         if (is_array($new_value)) {
             foreach ($new_value as $val) {
                 $searchfilter .= sprintf('(%s=%s)', $attr_name, clean_search_vals($val));
             }
         } elseif ($new_value) {
             $searchfilter .= sprintf('(%s=%s)', $attr_name, clean_search_vals($new_value));
         }
         $searchfilter .= ')';
         # Do we need a sanity check to just in case $new_value was null and hence the search string is bad?
         foreach ($this->getBaseDN() as $base_dn) {
             # Do the search
             $search = $this->search($con, $base_dn, $searchfilter, array('dn', $attr_name), 'sub', false, LDAP_DEREF_ALWAYS);
             foreach ($search as $searchdn => $result) {
                 # If one of the attributes is owned to somebody else, then we may as well die here.
                 if ($result['dn'] != $dn) {
                     if (is_array($result[$attr_name])) {
                         foreach ($result[$attr_name] as $attr) {
                             foreach ($new_value as $new_value_attr) {
                                 if ($new_value_attr == $attr) {
                                     return $attr;
                                 }
                             }
                         }
                     } else {
                         foreach ($new_value as $new_value_attr) {
                             if ($new_value_attr == $result[$attr_name]) {
                                 return $result[$attr_name];
                             }
                         }
                     }
                 }
             }
         }
         # If we get here, then it must be OK?
         return;
     } else {
         return;
     }
 }