Code

Moved up the revision definition
[gosa.git] / gosa-core / include / functions.inc
index 805acec79ea562593927625ec8e82db762fa72cd..1ec22f9c8ed277d71848605817745c0a5ada8a34 100644 (file)
 /*! \file
  * Common functions and named definitions. */
 
+/* Define globals for revision comparing */
+$svn_path = '$HeadURL$';
+$svn_revision = '$Revision$';
+
 /* Configuration file location */
 if(!isset($_SERVER['CONFIG_DIR'])){
   define ("CONFIG_DIR", "/etc/gosa");
@@ -68,10 +72,6 @@ define('DES_CBC_MD5',3);
 define('DES3_CBC_MD5',5);
 define('DES3_CBC_SHA1',16);
 
-/* Define globals for revision comparing */
-$svn_path = '$HeadURL$';
-$svn_revision = '$Revision$';
-
 /* Include required files */
 require_once("class_location.inc");
 require_once ("functions_debug.inc");
@@ -732,6 +732,15 @@ function ldap_expired_account($config, $userdn, $uid)
         }
     }
 
+    // -- I guess this is the correct detection, isn't it?
+    if($shadowLastChange != null && $shadowWarning != null && $shadowMax != null){
+        $daysRemaining = ($shadowLastChange + $shadowMax) - $current ;
+        if($daysRemaining > 0 && $daysRemaining <= $shadowWarning){
+                return(POSIX_WARN_ABOUT_EXPIRATION);
+        }
+    }
+
+
 
     // Check if we've to force the user to change his password.
     // --------------------------------------------------------
@@ -2094,6 +2103,13 @@ function gen_uids($rule, $attributes)
 {
   global $config;
 
+  // Strip out non ascii chars                                    
+  foreach($attributes as $name => $value){                        
+      $value = iconv('UTF-8', 'US-ASCII//TRANSLIT', $value);      
+      $value = preg_replace('/[^(\x20-\x7F)]*/','',$value);       
+      $attributes[$name] = $value;                                
+  }                                                               
+
   /* Search for keys and fill the variables array with all 
      possible values for that key. */
   $part= "";
@@ -2405,10 +2421,6 @@ function clean_smarty_compile_dir($directory)
               msg_dialog::display(_("Internal error"), sprintf(_("File '%s' could not be deleted."), $directory."/".$file), ERROR_DIALOG);
               // This should never be reached
             }
-          } elseif(is_dir($directory."/".$file) &&
-              is_writable($directory."/".$file)) {
-            // Just recursively delete it
-            rmdirRecursive($directory."/".$file);
           }
         }
         // We should now create a fresh revision file
@@ -2667,7 +2679,7 @@ function get_base_from_hook($dn, $attrib)
     $command= $config->get_cfg_value("baseIdHook");
 
     if ($command != ""){
-      $command.= " '".LDAP::fix($dn)."' $attrib";
+      $command.= " ".escapeshellarg(LDAP::fix($dn))." ".escapeshellarg($attrib);
       if (check_command($command)){
         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute");
         exec($command, $output);
@@ -3013,12 +3025,15 @@ function change_password ($dn, $password, $mode=0, $hash= "")
 
     // Not for groups
     if ($mode == 0){
-      // Create SMB Password
-      $attrs= generate_smb_nt_hash($password);
 
-      if ($shadow != 0){
-        $attrs['shadowLastChange']= $shadow;
-      }
+        // Create SMB Password
+        if ($config->get_cfg_value('sambaHashHook', NULL)) { 
+            $attrs= generate_smb_nt_hash($password);
+
+            if ($shadow != 0){
+                $attrs['shadowLastChange']= $shadow;
+            }
+        }
     }
 
     $attrs['userPassword']= array();
@@ -3047,8 +3062,8 @@ function change_password ($dn, $password, $mode=0, $hash= "")
 
       if ($command != ""){
         /* Walk through attribute list */
-        $command= preg_replace("/%userPassword/", $password, $command);
-        $command= preg_replace("/%dn/", $dn, $command);
+        $command= preg_replace("/%userPassword/", escapeshellarg($password), $command);
+        $command= preg_replace("/%dn/", escapeshellarg($dn), $command);
 
         if (check_command($command)){
           @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute");