summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGunnar Wrobel <wrobel@pardus.de>2009-12-03 21:08:43 (GMT)
committerGunnar Wrobel <wrobel@pardus.de>2009-12-03 21:08:43 (GMT)
commit3ccfc7aed621b0c1edce59f61ac66513d58fa396 (patch)
treeafdca436cf1d11908ad0e060cb2ff186214c4074
parent5f2da7b21eedaf7f53173dd25ceee9ee60ffe136 (diff)
downloadkolab-webadmin-3ccfc7aed621b0c1edce59f61ac66513d58fa396.tar.gz
kolab/issue3499 (Kolab web admin does not use LDAP escaping)
-rw-r--r--ChangeLog7
-rw-r--r--php/admin/include/ldap.class.php.in60
-rw-r--r--www/admin/addressbook/addr.php.in6
-rw-r--r--www/admin/administrator/admin.php.in6
-rw-r--r--www/admin/distributionlist/list.php.in6
-rw-r--r--www/admin/domainmaintainer/domainmaintainer.php.in6
-rw-r--r--www/admin/maintainer/maintainer.php.in6
-rw-r--r--www/admin/sharedfolder/sf.php.in6
8 files changed, 71 insertions, 32 deletions
diff --git a/ChangeLog b/ChangeLog
index 7caafc2..4353a90 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2009-12-03 Gunnar Wrobel <p@rdus.de>
+
+ * php/admin/include/ldap.class.php.in:
+ * www/admin/*:
+
+ kolab/issue3499 (Kolab web admin does not use LDAP escaping)
+
2009-11-16 Richard Bos <richard@radoeka.nl>
* php/admin/templates/settings.tpl: Use a table to separate the
checkbox and text, for nicer formatting. kolab/issue3428
diff --git a/php/admin/include/ldap.class.php.in b/php/admin/include/ldap.class.php.in
index 2c63325..48cb1a2 100644
--- a/php/admin/include/ldap.class.php.in
+++ b/php/admin/include/ldap.class.php.in
@@ -96,21 +96,53 @@ class KolabLDAP {
return $str;
}
- function dn_escape( $str ) {
- /*
- DN component escaping as described in RFC-2253
- */
- $str = str_replace( '\\', '\\\\', $str );
- $str = str_replace( ',', '\\,', $str );
- $str = str_replace( '+', '\\,', $str );
- $str = str_replace( '<', '\\<', $str );
- $str = str_replace( '>', '\\>', $str );
- $str = str_replace( ';', '\\;', $str );
- if( $str[0] == '#' ) $str = '\\'.$str;
- // PENDING(steffen): Escape leading/trailing spaces
- return $str;
+ // Taken from PEAR_Net_LDAP2
+ public function dn_escape($val)
+ {
+ // Escaping of filter meta characters
+ $val = str_replace('\\', '\\\\', $val);
+ $val = str_replace(',', '\,', $val);
+ $val = str_replace('+', '\+', $val);
+ $val = str_replace('"', '\"', $val);
+ $val = str_replace('<', '\<', $val);
+ $val = str_replace('>', '\>', $val);
+ $val = str_replace(';', '\;', $val);
+ $val = str_replace('#', '\#', $val);
+ $val = str_replace('=', '\=', $val);
+
+ // ASCII < 32 escaping
+ $val = KolabLDAP::asc2hex32($val);
+
+ // Convert all leading and trailing spaces to sequences of \20.
+ if (preg_match('/^(\s*)(.+?)(\s*)$/', $val, $matches)) {
+ $val = $matches[2];
+ for ($i = 0; $i < strlen($matches[1]); $i++) {
+ $val = '\20'.$val;
+ }
+ for ($i = 0; $i < strlen($matches[3]); $i++) {
+ $val = $val.'\20';
+ }
+ }
+
+ if (null === $val) $val = '\0'; // apply escaped "null" if string is empty
+
+ return $val;
}
-
+
+ // Taken from PEAR_Net_LDAP2
+ public function asc2hex32($string)
+ {
+ for ($i = 0; $i < strlen($string); $i++) {
+ $char = substr($string, $i, 1);
+ if (ord($char) < 32) {
+ $hex = dechex(ord($char));
+ if (strlen($hex) == 1) $hex = '0'.$hex;
+ $string = str_replace($char, '\\'.$hex, $string);
+ }
+ }
+ return $string;
+ }
+
// Taken from PEAR_Net_LDAP2
function unescape_dn_value($val)
diff --git a/www/admin/addressbook/addr.php.in b/www/admin/addressbook/addr.php.in
index 84f0c27..bb70ecf 100644
--- a/www/admin/addressbook/addr.php.in
+++ b/www/admin/addressbook/addr.php.in
@@ -163,7 +163,7 @@ if( !$errors ) {
if ($action == "save") {
if (!$errors) {
- if (!empty($ldap_object['cn'])) $newdn = "cn=".$ldap_object['cn'].",".$addressbook_root;
+ if (!empty($ldap_object['cn'])) $newdn = "cn=".$ldap->dn_escape($ldap_object['cn']).",".$addressbook_root;
else $newdn = $dn;
debug("action=save, dn=$dn, newdn=$newdn<br/>\n");
if (strcmp($dn,$newdn) != 0) {
@@ -185,7 +185,7 @@ if( !$errors ) {
foreach( $ldap_object as $k => $v ) if( $v == array() ) unset( $ldap_object[$k] );
// Try to rename the object
- if (!ldap_rename($ldap->connection, $dn, "cn=" . $ldap_object['cn'], $addressbook_root, true)) {
+ if (!ldap_rename($ldap->connection, $dn, "cn=" . $ldap->dn_escape($ldap_object['cn']), $addressbook_root, true)) {
array_push($errors, sprintf(_("LDAP Error: could not rename %s to %s: %s"), $dn,
$newdn, ldap_error($ldap->connection)));
}
@@ -221,7 +221,7 @@ if( !$errors ) {
}
} else {
if (!$errors) {
- $dn = "cn=".$ldap_object['cn'].",".$addressbook_root;
+ $dn = "cn=".$ldap->dn_escape($ldap_object['cn']).",".$addressbook_root;
foreach( $ldap_object as $k => $v ) if( $v == array() ) unset( $ldap_object[$k] );
if ($dn && !ldap_add($ldap->connection, $dn, $ldap_object)) {
array_push($errors, sprintf(_("LDAP Error: could not add object %s: %s"), $dn,
diff --git a/www/admin/administrator/admin.php.in b/www/admin/administrator/admin.php.in
index 1c2aced..74ed95b 100644
--- a/www/admin/administrator/admin.php.in
+++ b/www/admin/administrator/admin.php.in
@@ -197,7 +197,7 @@ switch( $action ) {
if ($action == "save") {
if (!$errors) {
- if (!empty($ldap_object['cn'])) $newdn = "cn=".$ldap_object['cn'].",cn=internal,".$domain_dn;
+ if (!empty($ldap_object['cn'])) $newdn = "cn=".$ldap->dn_escape($ldap_object['cn']).",cn=internal,".$domain_dn;
else $newdn = $dn;
if (!$visible && !strstr($newdn,$dn_add)) {
list($cn,$rest) = split(',', $newdn, 2);
@@ -212,7 +212,7 @@ switch( $action ) {
$ldap_object['userPassword'] = $oldattrs['userPassword'][0];
// Try to rename the object
- if (!ldap_rename($ldap->connection, $dn, "cn=" . $ldap_object['cn'], "cn=internal,".$domain_dn, true)) {
+ if (!ldap_rename($ldap->connection, $dn, "cn=" . $ldap->dn_escape($ldap_object['cn']), "cn=internal,".$domain_dn, true)) {
array_push($errors, sprintf(_("LDAP Error: could not rename %s to %s: %s"), $dn,
$newdn, ldap_error($ldap->connection)));
}
@@ -249,7 +249,7 @@ switch( $action ) {
} else {
// firstsave
if (!$errors) {
- $dn = "cn=".$ldap_object['cn'].",cn=internal,".$domain_dn;
+ $dn = "cn=".$ldap->dn_escape($ldap_object['cn']).",cn=internal,".$domain_dn;
debug("Calling ldap_add with dn=$dn");
// Add object to db
if ($dn && !ldap_add($ldap->connection, $dn, $ldap_object))
diff --git a/www/admin/distributionlist/list.php.in b/www/admin/distributionlist/list.php.in
index e7c0294..8b38c6b 100644
--- a/www/admin/distributionlist/list.php.in
+++ b/www/admin/distributionlist/list.php.in
@@ -184,7 +184,7 @@ if( !$errors ) {
if ($action == "save") {
if (!$errors) {
- if (!empty($ldap_object['cn'])) $newdn = "cn=".$ldap_object['cn'].",".$dl_root;
+ if (!empty($ldap_object['cn'])) $newdn = "cn=".$ldap->dn_escape($ldap_object['cn']).",".$dl_root;
else $newdn = $dn;
if (strcmp($dn,$newdn) != 0) {
if (($result=ldap_read($ldap->connection,$dn,"(objectclass=*)")) &&
@@ -192,7 +192,7 @@ if( !$errors ) {
($oldattrs=ldap_get_attributes($ldap->connection,$entry))) {
// Try to rename the object
- if (!ldap_rename($ldap->connection, $dn, "cn=" . $ldap_object['cn'], $dl_root, true)) {
+ if (!ldap_rename($ldap->connection, $dn, "cn=" . $ldap->dn_escape($ldap_object['cn']), $dl_root, true)) {
array_push($errors, sprintf(_("LDAP Error: could not rename %s to %s: %s"), $dn,
$newdn, ldap_error($ldap->connection)));
}
@@ -226,7 +226,7 @@ if( !$errors ) {
// firstsave
if (!$errors) {
if( !$ldap_object['member'] ) unset($ldap_object['member']);
- $dn = "cn=".$ldap_object['cn'].",".$dl_root;
+ $dn = "cn=".$ldap->dn_escape($ldap_object['cn']).",".$dl_root;
if ($dn && !ldap_add($ldap->connection, $dn, $ldap_object)) {
array_push($errors, sprintf( _("LDAP Error: Could not add object %s: %s"), $dn,
ldap_error($ldap->connection)));
diff --git a/www/admin/domainmaintainer/domainmaintainer.php.in b/www/admin/domainmaintainer/domainmaintainer.php.in
index a48fb9c..13d7e26 100644
--- a/www/admin/domainmaintainer/domainmaintainer.php.in
+++ b/www/admin/domainmaintainer/domainmaintainer.php.in
@@ -181,7 +181,7 @@ switch( $action ) {
if ($action == "save") {
if (!$errors) {
- if (!empty($ldap_object['cn'])) $newdn = "cn=".$ldap_object['cn'].",cn=internal,".$domain_dn;
+ if (!empty($ldap_object['cn'])) $newdn = "cn=".$ldap->dn_escape($ldap_object['cn']).",cn=internal,".$domain_dn;
else $newdn = $dn;
if (!$visible && !strstr($newdn,$dn_add)) {
list($cn,$rest) = split(',', $newdn, 2);
@@ -196,7 +196,7 @@ switch( $action ) {
$ldap_object['userPassword'] = $oldattrs['userPassword'][0];
// Try to rename the object
- if (!ldap_rename($ldap->connection, $dn, "cn=" . $ldap_object['cn'], "cn=internal,".$domain_dn, true)) {
+ if (!ldap_rename($ldap->connection, $dn, "cn=" . $ldap->dn_escape($ldap_object['cn']), "cn=internal,".$domain_dn, true)) {
array_push($errors, sprintf(_("LDAP Error: could not rename %s to %s: %s"), $dn,
$newdn, ldap_error($ldap->connection)));
}
@@ -255,7 +255,7 @@ switch( $action ) {
} else {
// firstsave
if (!$errors) {
- $dn = "cn=".$ldap_object['cn'].",cn=internal,".$domain_dn;
+ $dn = "cn=".$ldap->dn_escape($ldap_object['cn']).",cn=internal,".$domain_dn;
debug("Calling ldap_add with dn=$dn");
if ($dn && !ldap_add($ldap->connection, $dn, $ldap_object))
array_push($errors, sprintf(_("LDAP Error: could not add object %s: %s"), $dn,
diff --git a/www/admin/maintainer/maintainer.php.in b/www/admin/maintainer/maintainer.php.in
index 853962e..35b521e 100644
--- a/www/admin/maintainer/maintainer.php.in
+++ b/www/admin/maintainer/maintainer.php.in
@@ -194,7 +194,7 @@ switch( $action ) {
if ($action == "save") {
if (!$errors) {
- if (!empty($ldap_object['cn'])) $newdn = "cn=".$ldap_object['cn'].",cn=internal,".$domain_dn;
+ if (!empty($ldap_object['cn'])) $newdn = "cn=".$ldap->dn_escape($ldap_object['cn']).",cn=internal,".$domain_dn;
else $newdn = $dn;
if (!$visible && !strstr($newdn,$dn_add)) {
list($cn,$rest) = split(',', $newdn, 2);
@@ -209,7 +209,7 @@ switch( $action ) {
$ldap_object['userPassword'] = $oldattrs['userPassword'][0];
// Try to rename the object
- if (!ldap_rename($ldap->connection, $dn, "cn=" . $ldap_object['cn'], "cn=internal,".$domain_dn, true)) {
+ if (!ldap_rename($ldap->connection, $dn, "cn=" . $ldap->dn_escape($ldap_object['cn']), "cn=internal,".$domain_dn, true)) {
array_push($errors, sprintf(_("LDAP Error: could not rename %s to %s: %s"), $dn,
$newdn, ldap_error($ldap->connection)));
}
@@ -251,7 +251,7 @@ switch( $action ) {
} else {
// firstsave
if (!$errors) {
- $dn = "cn=".$ldap_object['cn'].",cn=internal,".$domain_dn;
+ $dn = "cn=".$ldap->dn_escape($ldap_object['cn']).",cn=internal,".$domain_dn;
debug("Calling ldap_add with dn=$dn");
if ($dn && !ldap_add($ldap->connection, $dn, $ldap_object))
array_push($errors, sprintf( _("LDAP Error: could not add object %s: %s"), $dn,
diff --git a/www/admin/sharedfolder/sf.php.in b/www/admin/sharedfolder/sf.php.in
index 018726b..38757dc 100644
--- a/www/admin/sharedfolder/sf.php.in
+++ b/www/admin/sharedfolder/sf.php.in
@@ -215,7 +215,7 @@ if( !$errors ) {
if ($action == "save") {
if (!$errors) {
- if (!empty($ldap_object['cn'])) $newdn = "cn=".$ldap_object['cn'].",".$sf_root;
+ if (!empty($ldap_object['cn'])) $newdn = "cn=".$ldap->dn_escape($ldap_object['cn']).",".$sf_root;
else $newdn = $dn;
if (strcmp($dn,$newdn) != 0) {
if (($result=ldap_read($ldap->connection,$dn,"(objectclass=*)")) &&
@@ -223,7 +223,7 @@ if( !$errors ) {
($oldattrs=ldap_get_attributes($ldap->connection,$entry))) {
// Try to rename the object
- if (!ldap_rename($ldap->connection, $dn, "cn=" . $ldap_object['cn'], $sf_root, true)) {
+ if (!ldap_rename($ldap->connection, $dn, "cn=" . $ldap->dn_escape($ldap_object['cn']), $sf_root, true)) {
array_push($errors, sprintf(_("LDAP Error: could not rename %s to %s: %s"), $dn,
$newdn, ldap_error($ldap->connection)));
}
@@ -255,7 +255,7 @@ if( !$errors ) {
}
} else {
if (!$errors) {
- $dn = "cn=".$ldap_object['cn'].",".$sf_root;
+ $dn = "cn=".$ldap->dn_escape($ldap_object['cn']).",".$sf_root;
$ldap_object['kolabHomeServer'] = trim($_POST['kolabhomeserver']);
if ($dn && !ldap_add($ldap->connection, $dn, $ldap_object))
array_push($errors, sprintf(_("LDAP Error: could not add object %s: %s"), $dn,