diff --git a/lib/Net/LDAP3.php b/lib/Net/LDAP3.php index e68fac75604188a8eda75448e6d20dd56fa164e0..f8887de2830a50f5da2dda69556249568431532b 100644 --- a/lib/Net/LDAP3.php +++ b/lib/Net/LDAP3.php @@ -1326,8 +1326,10 @@ class Net_LDAP3 // This is me cheating. Remove this special attribute. if (array_key_exists('ou', $old_attrs) || array_key_exists('ou', $new_attrs)) { - $old_ou = is_array($old_attrs['ou']) ? array_shift($old_attrs['ou']) : $old_attrs['ou']; - $new_ou = is_array($new_attrs['ou']) ? array_shift($new_attrs['ou']) : $new_attrs['ou']; + $old_ou = isset($old_attrs['ou']) && is_array($old_attrs['ou']) + ? array_shift($old_attrs['ou']) : (isset($old_attrs['ou']) ? $old_attrs['ou'] : null); + $new_ou = isset($new_attrs['ou']) && is_array($new_attrs['ou']) + ? array_shift($new_attrs['ou']) : (isset($new_attrs['ou']) ? $new_attrs['ou'] : null); unset($old_attrs['ou']); unset($new_attrs['ou']); } @@ -1819,8 +1821,9 @@ class Net_LDAP3 foreach ((array) $search['params'] as $field => $param) { $value = (array) $param['value']; + $type = isset($param['type']) ? strval($param['type']) : null; - switch ((string)$param['type']) { + switch ($type) { case 'prefix': $prefix = ''; $suffix = '*'; @@ -1860,7 +1863,7 @@ class Net_LDAP3 break; } - $operator = $param['type'] && in_array($param['type'], $operators) ? $param['type'] : '='; + $operator = $type && in_array($type, $operators) ? $type : '='; if (count($value) < 2) { $value = array_pop($value); @@ -1881,8 +1884,9 @@ class Net_LDAP3 } // join search parameters with specified operator ('OR' or 'AND') - if (count($search['params']) > 1) { - $filter = '(' . ($search['operator'] == 'AND' ? '&' : '|') . $filter . ')'; + if (!empty($search['params']) && count($search['params']) > 1) { + $operator = !empty($search['operator']) && $search['operator'] == 'AND' ? '&' : '|'; + $filter = '(' . $operator . $filter . ')'; } return $filter; @@ -2729,7 +2733,7 @@ class Net_LDAP3 $result = array(); foreach (explode(',', $str) as $token) { - list($attr, $value) = explode('=', $token, 2); + list($attr, $value) = strpos($token, '=') !== false ? explode('=', $token, 2) : array($token, ''); $pos = 0; while (preg_match('/\\\\[0-9a-fA-F]{2}/', $value, $matches, PREG_OFFSET_CAPTURE, $pos)) {