<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.kde.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.6"
          urlbase="https://bugs.kde.org/"
          
          maintainer="sysadmin@kde.org"
>

    <bug>
          <bug_id>99847</bug_id>
          
          <creation_ts>2005-02-20 11:41:05 +0000</creation_ts>
          <short_desc>Trashing from a USB key doesn&apos;t work</short_desc>
          <delta_ts>2005-04-07 01:24:43 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>10</classification_id>
          <classification>Unmaintained</classification>
          <product>kio</product>
          <component>trash</component>
          <version>unspecified</version>
          <rep_platform>Compiled Sources</rep_platform>
          <op_sys>Linux</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>NOR</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Ivor Ibbotson">bowler</reporter>
          <assigned_to name="David Faure">faure</assigned_to>
          <cc>tpowa</cc>
    
    <cc>wendigo3</cc>
          
          <cf_commitlink></cf_commitlink>
          <cf_versionfixedin></cf_versionfixedin>
          <cf_sentryurl></cf_sentryurl>
          <votes>0</votes>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>316153</commentid>
    <comment_count>0</comment_count>
    <who name="Ivor Ibbotson">bowler</who>
    <bug_when>2005-02-20 11:41:05 +0000</bug_when>
    <thetext>Version:            (using KDE Devel)
Installed from:    Compiled sources
OS:                Linux

Attempting to Move to Wastebin a file residing on a USB memorystick fails. File remains on USB memory. Deleting this file does work.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>316168</commentid>
    <comment_count>1</comment_count>
    <who name="Ivor Ibbotson">bowler</who>
    <bug_when>2005-02-20 12:21:16 +0000</bug_when>
    <thetext>Version: kbase3  3.3.92-2005021814-1</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>318379</commentid>
    <comment_count>2</comment_count>
    <who name="David Faure">faure</who>
    <bug_when>2005-02-25 18:53:30 +0000</bug_when>
    <thetext>CVS commit by faure: 

Check the permissions and ownership of the directory we just created, to see
if it will pass the security checks; otherwise trashing will just fail.
I hate FAT, it breaks all the Unix semantics :)
This fixes &quot;trashing from a USB key fails&quot;.
BUG: 99847


  M +53 -25    trashimpl.cpp   1.35


--- kdebase/kioslave/trash/trashimpl.cpp  #1.34:1.35
@@ -200,6 +200,8 @@ bool TrashImpl::createInfo( const QStrin
     // Choose destination trash
     trashId = findTrashDirectory( origPath );
-    if ( trashId &lt; 0 )
+    if ( trashId &lt; 0 ) {
+        kdWarning() &lt;&lt; &quot;OUCH - internal error, TrashImpl::createInfo got &quot; &lt;&lt; trashId &lt;&lt; endl;
         return false; // ### error() needed?
+    }
 
     // Grab original filename
@@ -541,7 +543,8 @@ TrashImpl::TrashedFileInfoList TrashImpl
             if ( fileName == &quot;.&quot; || fileName == &quot;..&quot; )
                 continue;
-            Q_ASSERT( fileName.endsWith( &quot;.trashinfo&quot; ) );
-            if ( !fileName.endsWith( &quot;.trashinfo&quot; ) )
+            if ( !fileName.endsWith( &quot;.trashinfo&quot; ) ) {
+                kdWarning() &lt;&lt; &quot;Invalid info file found in &quot; &lt;&lt; infoPath &lt;&lt; &quot; : &quot; &lt;&lt; fileName &lt;&lt; endl;
                 continue;
+            }
             fileName.truncate( fileName.length() - 10 );
 
@@ -755,6 +758,6 @@ QString TrashImpl::trashForMountPoint( c
     // Minimum permissions required: write+execute for &apos;others&apos;, and sticky bit
     int requiredBits = S_IWOTH | S_IXOTH | S_ISVTX;
-    if ( KDE_lstat( QFile::encodeName( rootTrashDir ), &amp;buff ) == 0
-         &amp;&amp; (buff.st_uid == 0) // must be owned by root
+    if ( KDE_lstat( QFile::encodeName( rootTrashDir ), &amp;buff ) == 0 ) {
+        if ( (buff.st_uid == 0) // must be owned by root
          &amp;&amp; (S_ISDIR(buff.st_mode)) // must be a dir
          &amp;&amp; (!S_ISLNK(buff.st_mode)) // not a symlink
@@ -770,8 +773,12 @@ QString TrashImpl::trashForMountPoint( c
                 return trashDir;
             }
+                kdDebug() &lt;&lt; &quot;Directory &quot; &lt;&lt; trashDir &lt;&lt; &quot; exists but didn&apos;t pass the security checks, can&apos;t use it&quot; &lt;&lt; endl;
         }
         else if ( createIfNeeded &amp;&amp; initTrashDirectory( trashDir_c ) ) {
             return trashDir;
         }
+        } else {
+            kdDebug() &lt;&lt; &quot;Root trash dir &quot; &lt;&lt; rootTrashDir &lt;&lt; &quot; exists but didn&apos;t pass the security checks, can&apos;t use it&quot; &lt;&lt; endl;
+        }
     }
 
@@ -787,4 +794,5 @@ QString TrashImpl::trashForMountPoint( c
             return trashDir;
         }
+        kdDebug() &lt;&lt; &quot;Directory &quot; &lt;&lt; trashDir &lt;&lt; &quot; exists but didn&apos;t pass the security checks, can&apos;t use it&quot; &lt;&lt; endl;
         // Exists, but not useable
         return QString::null;
@@ -801,7 +809,8 @@ int TrashImpl::idForTrashDirectory( cons
     TrashDirMap::ConstIterator it = m_trashDirectories.begin();
     for ( ; it != m_trashDirectories.end() ; ++it ) {
-        if ( it.data() == trashDir )
+        if ( it.data() == trashDir ) {
             return it.key();
     }
+    }
     return -1;
 }
@@ -811,4 +820,13 @@ bool TrashImpl::initTrashDirectory( cons
     if ( ::mkdir( trashDir_c, 0700 ) != 0 )
         return false;
+    // This trash dir will be useable only if the directory is owned by user.
+    // In theory this is the case, but not on e.g. USB keys...
+    uid_t uid = getuid();
+    KDE_struct_stat buff;
+    if ( KDE_lstat( trashDir_c, &amp;buff ) != 0 )
+        return false; // huh?
+    if ( (buff.st_uid == uid) // must be owned by user
+         &amp;&amp; (buff.st_mode &amp; S_IRWXU) ) { // rwx for user
+
     QCString info_c = trashDir_c + &quot;/info&quot;;
     if ( ::mkdir( info_c, 0700 ) != 0 )
@@ -817,4 +835,14 @@ bool TrashImpl::initTrashDirectory( cons
     if ( ::mkdir( files_c, 0700 ) != 0 )
         return false;
+    } else {
+        kdDebug() &lt;&lt; trashDir_c &lt;&lt; &quot; just created, by it doesn&apos;t have the right permissions, must be a FAT partition. Removing it again.&quot; &lt;&lt; endl;
+        // Not good, e.g. USB key. Delete again.
+        // I&apos;m paranoid, it would be better to find a solution that allows
+        // to trash directly onto the USB key, but I don&apos;t see how that would
+        // pass the security checks. It would also make the USB key appears as
+        // empty when it&apos;s in fact full...
+        ::rmdir( trashDir_c );
+        return false;
+    }
     return true;
 }


</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>320372</commentid>
    <comment_count>3</comment_count>
    <who name="David Faure">faure</who>
    <bug_when>2005-03-02 22:07:14 +0000</bug_when>
    <thetext>*** Bug 100669 has been marked as a duplicate of this bug. ***</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>332433</commentid>
    <comment_count>4</comment_count>
    <who name="David Faure">faure</who>
    <bug_when>2005-04-07 01:24:43 +0000</bug_when>
    <thetext>*** Bug 103385 has been marked as a duplicate of this bug. ***</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>