Bug 54459 - Security: backup files get different permissions
Summary: Security: backup files get different permissions
Status: RESOLVED FIXED
Alias: None
Product: koffice
Classification: Applications
Component: general (show other bugs)
Version: 1.2.1
Platform: RedHat Enterprise Linux Linux
: NOR normal
Target Milestone: ---
Assignee: KOffice Bug Wranglers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-02-11 10:25 UTC by Dirk Heinrichs
Modified: 2004-05-11 16:47 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dirk Heinrichs 2003-02-11 10:25:59 UTC
Version:           1.2.1 (using KDE KDE 3.1)
Installed from:    RedHat RPMs
OS:          Linux

When setting permissions of a kspread file (maybe this applies to other koffice components also) to 600 and saving the file again, the backup file has different permissions (644), thus is world readeable. IMHO, it should have the same permissions as the original.
Comment 1 Philipp Müller 2003-02-11 16:30:22 UTC
This applies to all KOffice programs.
Comment 2 Nicolas Goutte 2003-02-12 12:42:12 UTC
I think that the problem is that the backup file is copied instead of being 
moved. 
 
Have a nice day/evening/night! 
Comment 3 David Faure 2003-04-11 11:22:20 UTC
Subject: koffice/lib/kofficecore

CVS commit by faure: 

Preserve permissions when creating backup file (only for local files currently)
CCMAIL: 54459-done@bugs.kde.org


  M +17 -9     koDocument.cc   1.268


--- koffice/lib/kofficecore/koDocument.cc  #1.267:1.268
@@ -53,4 +53,5 @@
 #include <qimage.h>
 #include <kiconloader.h>
+#include <kfileitem.h>
 #include <qdir.h>
 #include <qfileinfo.h>
@@ -298,14 +299,21 @@ bool KoDocument::saveFile()
     QApplication::setOverrideCursor( waitCursor );
 
-    if ( KIO::NetAccess::exists( url() ) ) { // this file exists => backup
+    if ( backupFile() ) {
+        KIO::UDSEntry entry;
+        if ( KIO::NetAccess::stat( url(), entry ) ) { // this file exists => backup
+            KFileItem item( entry, url() );
+            Q_ASSERT( item.name() == url().fileName() );
         KURL backup;
         if ( d->m_backupPath.isEmpty())
-            backup= url();
+                backup = url();
         else
             backup = d->m_backupPath +"/"+url().fileName();
         backup.setPath( backup.path() + QString::fromLatin1("~") );
-        if ( backupFile() ) {
             KIO::NetAccess::del( backup ); // Copy does not remove existing destination file
             KIO::NetAccess::copy( url(), backup );
+            // Not network transparent. TODO: use NetAccess::file_copy once KDE-3.2 is required,
+            // or implement KIO::NetAccess::chmod (or fire an async ChmodJob?).
+            if ( backup.isLocalFile() )
+                ::chmod( QFile::encodeName( backup.path() ), item.permissions() );
         }
     }


Comment 4 Dirk Heinrichs 2003-12-17 13:42:47 UTC
Please reopen. I found the same behaviour again in Koffice 1.3_rc1 (used with KDE 3.2.0 Beta2).
Comment 5 Stephan Binner 2003-12-19 23:25:00 UTC
As per comment 4.
Comment 6 Dirk Heinrichs 2004-05-11 13:13:28 UTC
Still valid for 1.3.1.
Comment 7 Nicolas Goutte 2004-05-11 15:46:36 UTC
Which KDE version?
Comment 8 Dirk Heinrichs 2004-05-11 16:19:03 UTC
I'm on 3.2.2 now.
Comment 9 David Faure 2004-05-11 16:47:33 UTC
CVS commit by faure: 

Oh well, I suck. Now this should fix 54459 again. I'll backport.
CCMAIL: 54459-done@bugs.kde.org


  M +4 -4      koDocument.cc   1.308


--- koffice/lib/kofficecore/koDocument.cc  #1.307:1.308
@@ -48,7 +48,7 @@
 #include <kmessagebox.h>
 #include <kdeversion.h>
+#include <kfileitem.h>
 #if ! KDE_IS_VERSION(3,1,90)
 #include <kdebugclasses.h>
-#include <kfileitem.h>
 #endif
 
@@ -383,9 +383,9 @@ bool KoDocument::saveFile()
                 backup = d->m_backupPath +"/"+url().fileName();
             backup.setPath( backup.path() + QString::fromLatin1("~") );
-#if KDE_IS_VERSION(3,1,90)
-            KIO::NetAccess::file_copy( url(), backup, -1, true /*overwrite*/, false /*resume*/, shells().current() );
-#else
             KFileItem item( entry, url() );
             Q_ASSERT( item.name() == url().fileName() );
+#if KDE_IS_VERSION(3,1,90)
+            KIO::NetAccess::file_copy( url(), backup, item.permissions(), true /*overwrite*/, false /*resume*/, shells().current() );
+#else
             KIO::NetAccess::del( backup ); // Copy does not remove existing destination file
             KIO::NetAccess::copy( url(), backup );