Code

Use lowercase values to update krb principals
[gosa.git] / gosa-core / include / functions.inc
index 7675ff23e7d502e8c01a834a67a6a615eb9915ef..736db99cf295c868f0089ad5ae7d1cded0446568 100644 (file)
@@ -1093,6 +1093,10 @@ function convert_department_dn($dn)
 
   /* Build a sub-directory style list of the tree level
      specified in $dn */
+  global $config;
+  $dn = preg_replace("/".normalizePreg($config->current['BASE'])."$/i","",$dn);
+  if(empty($dn)) return("/");
+
   foreach (split(',', $dn) as $rdn){
 
     /* We're only interested in organizational units... */
@@ -2454,9 +2458,9 @@ function change_password ($dn, $password, $mode=0, $hash= "")
 
     /* Extract used hash */
     if ($hash == ""){
-      $test = passwordMethod::get_method($attrs['userPassword'][0]);
+      $test = passwordMethod::get_method($attrs['userPassword'][0],$dn);
     } else {
-      $test = new $available[$hash]($config);
+      $test = new $available[$hash]($config,$dn);
       $test->set_hash($hash);
     }
 
@@ -2696,7 +2700,7 @@ function update_accessTo($from,$to)
   $ldap->cd($config->current['BASE']);
   $ldap->search("(&(objectClass=trustAccount)(accessTo=".$from."))",array("objectClass","accessTo"));
   while($attrs = $ldap->fetch()){
-    $new_attrs = array();
+    $new_attrs = array("accessTo" => array());
     $dn = $attrs['dn'];
     for($i = 0 ; $i < $attrs['objectClass']['count']; $i++){
       $new_attrs['objectClass'][] =  $attrs['objectClass'][$i];
@@ -2729,7 +2733,25 @@ function get_random_char () {
      } else {
          return (chr ($randno + 59)); // Lowercase
      }
-  }
+}
+
+
+function cred_encrypt($input, $password) {
+
+  $size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
+  $iv = mcrypt_create_iv($size, MCRYPT_DEV_RANDOM);
+
+  return bin2hex(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $password, $input, MCRYPT_MODE_ECB, $iv));
+
+}
+
+function cred_decrypt($input,$password) {
+  $size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
+  $iv = mcrypt_create_iv($size, MCRYPT_DEV_RANDOM);
+
+  return mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $password, pack("H*", $input), MCRYPT_MODE_ECB, $iv);
+}
+
 
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
 ?>