Changeset 2282


Ignore:
Timestamp:
01/04/11 02:42:32 (4 years ago)
Author:
lowjoel
Message:

Prevent recursive folder definitions when users use Secure Move to move a folder to be a subfolder of the source directory.

Location:
trunk/eraser
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/eraser/Eraser.DefaultPlugins/ErasureTargets/SecureMoveErasureTarget.cs

    r2211 r2282  
    149149        private void CopyDirectory(DirectoryInfo info) 
    150150        { 
     151            //Check the the destination is not a subfolder of the source. 
     152            if (Shell.IsRootedAt(info, Destination)) 
     153            { 
     154                Logger.Log(S._("The destination directory cannot be within the source directory."), 
     155                    LogLevel.Error); 
     156                return; 
     157            } 
     158 
    151159            //We need to get the files from the list of streams 
    152160            List<StreamInfo> streams = GetPaths(); 
  • trunk/eraser/Eraser.DefaultPlugins/Strings.en.resx

    r2271 r2282  
    295295    <value>Securely move {0}</value> 
    296296  </data> 
     297  <data name="The destination directory cannot be within the source directory." xml:space="preserve"> 
     298    <value>The destination directory cannot be within the source directory.</value> 
     299  </data> 
    297300  <data name="Securely moving files and folders..." xml:space="preserve"> 
    298301    <value>Securely moving files and folders...</value> 
  • trunk/eraser/Eraser.DefaultPlugins/Strings.it.resx

    r2271 r2282  
    295295    <value>Spostamento sicuro di {0}</value> 
    296296  </data> 
     297  <data name="The destination directory cannot be within the source directory." xml:space="preserve"> 
     298    <value>(Untranslated)</value> 
     299  </data> 
    297300  <data name="Securely moving files and folders..." xml:space="preserve"> 
    298301    <value>(Untranslated)</value> 
  • trunk/eraser/Eraser.DefaultPlugins/Strings.nl.resx

    r2271 r2282  
    295295    <value>(Untranslated)</value> 
    296296  </data> 
     297  <data name="The destination directory cannot be within the source directory." xml:space="preserve"> 
     298    <value>(Untranslated)</value> 
     299  </data> 
    297300  <data name="Securely moving files and folders..." xml:space="preserve"> 
    298301    <value>(Untranslated)</value> 
  • trunk/eraser/Eraser.DefaultPlugins/Strings.pl.resx

    r2271 r2282  
    295295    <value>(Untranslated)</value> 
    296296  </data> 
     297  <data name="The destination directory cannot be within the source directory." xml:space="preserve"> 
     298    <value>(Untranslated)</value> 
     299  </data> 
    297300  <data name="Securely moving files and folders..." xml:space="preserve"> 
    298301    <value>(Untranslated)</value> 
  • trunk/eraser/Eraser.DefaultPlugins/Strings.resx

    r2271 r2282  
    295295    <value>Securely move {0}</value> 
    296296  </data> 
     297  <data name="The destination directory cannot be within the source directory." xml:space="preserve"> 
     298    <value>The destination directory cannot be within the source directory.</value> 
     299  </data> 
    297300  <data name="Securely moving files and folders..." xml:space="preserve"> 
    298301    <value>Securely moving files and folders...</value> 
  • trunk/eraser/Eraser.Util/Shell.cs

    r2112 r2282  
    142142 
    143143        /// <summary> 
     144        /// Verifies if the path given is rooted at the given absolute path. 
     145        /// </summary> 
     146        /// <param name="absolutePath">The root path.</param> 
     147        /// <param name="path">The path to verify.</param> 
     148        /// <returns>True if the path provided is a subfolder/sub-file of the provided root path.</returns> 
     149        public static bool IsRootedAt(FileSystemInfo absolutePath, string path) 
     150        { 
     151            //Convert the path in question to an absolute path 
     152            if (!Path.IsPathRooted(path)) 
     153                path = Path.GetFullPath(path); 
     154 
     155            //Split the directory path to its component folders 
     156            string[] absoluteDirectories = absolutePath.FullName.Split( 
     157                Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); 
     158            string[] relativeDirectories = path.Split( 
     159                Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); 
     160 
     161            //Compare element by element; if the absolute path compares till the end, the 
     162            //provided path is a subdirectory 
     163            for (int i = 0; i < absoluteDirectories.Length; ++i) 
     164                if (absoluteDirectories[i] != relativeDirectories[i]) 
     165                    return false; 
     166 
     167            return true; 
     168        } 
     169 
     170        /// <summary> 
    144171        /// A List of known folder IDs in the shell namespace. 
    145172        /// </summary> 
Note: See TracChangeset for help on using the changeset viewer.