Code

Some backport from trunk
[gosa.git] / gosa-core / include / functions.inc
index c6e9f25b0b2f1270eb54678a91aa805b0caa0f8f..d14308bcb45988897ccb484c7606655a47c14ebe 100644 (file)
@@ -73,7 +73,7 @@ define('DES3_CBC_MD5',5);
 define('DES3_CBC_SHA1',16);
 
 /* Include required files */
-require_once("class_location.inc");
+include_once("class_location.inc");
 require_once ("functions_debug.inc");
 require_once ("accept-to-gettext.inc");
 
@@ -701,11 +701,21 @@ function ldap_expired_account($config, $userdn, $uid)
 
     // Fetch required attributes
     foreach(array('shadowExpire','shadowLastChange','shadowMax','shadowMin',
-                'shadowInactive','shadowWarning') as $attr){
+                'shadowInactive','shadowWarning','sambaKickoffTime') as $attr){
         $$attr = (isset($attrs[$attr][0]))? $attrs[$attr][0] : null;
     }
 
 
+    // Check if the account has reached its kick off limitations.
+    // ---------------------------------------------------------
+    // Once the accout reaches the kick off limit it has expired.
+    if($sambaKickoffTime !== null){
+        if(time() >= $sambaKickoffTime){
+            return(POSIX_ACCOUNT_EXPIRED);
+        }
+    }
+
+
     // Check if the account has expired.
     // ---------------------------------
     // An account is locked/expired once its expiration date has reached (shadowExpire).
@@ -2880,9 +2890,14 @@ function change_password ($dn, $password, $mode=FALSE, $hash= "", $old_password
         $attrs= array();
         if (!$mode && !empty($tmp)){
             $attrs= generate_smb_nt_hash($password);
-            $shadow = (isset($attrs["shadowLastChange"][0]))?(int)(date("U") / 86400):0;
-            if ($shadow != 0){
-                $attrs['shadowLastChange']= $shadow;
+            if(!count($attrs) || !is_array($attrs)){
+                msg_dialog::display(tr("Error"),tr("Cannot generate SAMBA hash!"),ERROR_DIALOG);
+                return(FALSE);    
+            }else{
+                $shadow = (isset($attrs["shadowLastChange"][0]))?(int)(date("U") / 86400):0;
+                if ($shadow != 0){
+                    $attrs['shadowLastChange']= $shadow;
+                }
             }
         }
 
@@ -3036,7 +3051,7 @@ function generate_smb_nt_hash($password)
     $hash = $rpc->mksmbhash($password);
     if(!$rpc->success()){
         msg_dialog::display(_("Error"),msgPool::rpcError($rpc->get_error()),ERROR_DIALOG);
-        return("");
+        return(array());
     }
 
   }elseif ($config->get_cfg_value("core","gosaSupportURI") != ""){
@@ -3066,7 +3081,7 @@ function generate_smb_nt_hash($password)
 
     if ($hash == "") {
       msg_dialog::display(_("Configuration error"), sprintf(_("Generating SAMBA hash by running %s failed: check %s!"), bold($config->get_cfg_value("core",'sambaHashHook'), bold("sambaHashHook"))), ERROR_DIALOG);
-      return ("");
+      return(array());
     }
   }
 
@@ -3523,6 +3538,9 @@ function image($path, $action= "", $title= "", $align= "middle")
   $label= null;
 
   // Bail out, if there's no style file
+  if(!class_exists('session')){
+    return "";    
+  }
   if(!session::global_is_set("img-styles")){
 
     // Get theme
@@ -3707,11 +3725,14 @@ function fillReplacements($str, $attrs, $shellArg = FALSE, $default = "")
     }
     krsort($hits);
 
+    // Add lower case placeholders to avoid errors
+    foreach($attrs as $key => $attr) $attrs[strtolower($key)] = $attr;
+
     // Replace the placeholder in the given string now.
     foreach($hits as $match){
 
         // Avoid errors about undefined index.
-        $name = $match[2];
+        $name = strtolower($match[2]);
         if(!isset($attrs[$name])) $attrs[$name] = $default;
 
         // Calculate the replacement
@@ -3769,10 +3790,11 @@ function gen_uids($rule, $attributes)
         if(!isset($match[5])){
             $replacements[$match[0]][] = $attributes[$match[2]];
     
-        // Start given but no end, so just add a simple character
+        // Start given but no end, so just add a single character
         }elseif(!isset($match[7])){
             if(isset($attributes[$match[2]][$match[5]])){
-                $replacements[$match[0]][] = $attributes[$match[2]][$match[5]];
+                $tmp = " ".$attributes[$match[2]];
+                $replacements[$match[0]][] = trim($tmp[$match[5]]);
             }
 
         // Add all values in range
@@ -3780,8 +3802,9 @@ function gen_uids($rule, $attributes)
             $str = "";
             for($i=$match[5]; $i<= $match[7]; $i++){
                 if(isset($attributes[$match[2]][$i])){
-                    $str .= $attributes[$match[2]][$i];
-                    $replacements[$match[0]][] = $str;
+                    $tmp = " ".$attributes[$match[2]];
+                    $str .= $tmp[$i];
+                    $replacements[$match[0]][] = trim($str);
                 }
             }
         }