[PATCH] mounting encrypted devices

Tobias Koenig tokoe at kde.org
Tue Apr 6 15:39:10 BST 2004


Hi,

here is the first patch which allows you to mark devices as encrypted,
so when you click at the icon on the desktop a password dialog will
popup and ask you for the password.
This is a first proof of concept, in later version maybe we can
integrate kwallet support and also support for autodetection of
encrypted devices in the devices io-slave.

The 'concept' of this patch is to put a helper application between the
file io-slave and the mount tool. This helper application checks whether
the device is encrypted, popups the password dialog in this case and
passes this password to mount.

Ok for commit?

Ciao,
Tobias
-- 
Separate politics from religion and economy!
-------------- next part --------------
? patchme
? kssl/keygenwizard.cpp
? kssl/keygenwizard2.cpp
Index: kfile/kpropertiesdialog.cpp
===================================================================
RCS file: /home/kde/kdelibs/kio/kfile/kpropertiesdialog.cpp,v
retrieving revision 1.305
diff -p -u -b -r1.305 kpropertiesdialog.cpp
--- kfile/kpropertiesdialog.cpp	6 Apr 2004 14:15:27 -0000	1.305
+++ kfile/kpropertiesdialog.cpp	6 Apr 2004 14:38:54 -0000
@@ -2617,15 +2617,19 @@ KDevicePropsPlugin::KDevicePropsPlugin( 
   readonly->setText(  i18n("Read only") );
   layout->addWidget(readonly, 1, 1);
 
+  encrypted = new QCheckBox( d->m_frame, "CheckBox_encrypted" );
+  encrypted->setText( i18n("Encrypted") );
+  layout->addWidget(encrypted, 2, 1);
+
   label = new QLabel( d->m_frame );
   label->setText( devices.count()==0 ?
                       i18n("Mount point (/mnt/floppy):") : // old style
                       i18n("Mount point:")); // new style (combobox)
-  layout->addWidget(label, 2, 0);
+  layout->addWidget(label, 3, 0);
 
   mountpoint = new QLabel( d->m_frame, "LineEdit_mountpoint" );
 
-  layout->addWidget(mountpoint, 2, 1);
+  layout->addWidget(mountpoint, 3, 1);
 
   KSeparator* sep = new KSeparator( KSeparator::HLine, d->m_frame);
   layout->addMultiCellWidget(sep, 4, 4, 0, 2);
@@ -2653,6 +2657,7 @@ KDevicePropsPlugin::KDevicePropsPlugin( 
   QString deviceStr = config.readEntry( "Dev" );
   QString mountPointStr = config.readEntry( "MountPoint" );
   bool ro = config.readBoolEntry( "ReadOnly", false );
+  bool enc = config.readBoolEntry( "Encrypted", false );
   QString unmountedStr = config.readEntry( "UnmountIcon" );
 
   device->setEditText( deviceStr );
@@ -2670,6 +2675,7 @@ KDevicePropsPlugin::KDevicePropsPlugin( 
     mountpoint->setText( mountPointStr );
 
   readonly->setChecked( ro );
+  encrypted->setChecked( enc );
 
   if ( unmountedStr.isEmpty() )
     unmountedStr = KMimeType::mimeType(QString::fromLatin1("application/octet-stream"))->KServiceType::icon(); // default icon
@@ -2682,6 +2688,8 @@ KDevicePropsPlugin::KDevicePropsPlugin( 
            this, SIGNAL( changed() ) );
   connect( readonly, SIGNAL( toggled( bool ) ),
            this, SIGNAL( changed() ) );
+  connect( encrypted, SIGNAL( toggled( bool ) ),
+           this, SIGNAL( changed() ) );
   connect( unmounted, SIGNAL( iconChanged( QString ) ),
            this, SIGNAL( changed() ) );
 
@@ -2752,6 +2760,7 @@ void KDevicePropsPlugin::applyChanges()
   kdDebug(250) << "unmounted->icon() = " << unmounted->icon() << endl;
 
   config.writeEntry( "ReadOnly", readonly->isChecked() );
+  config.writeEntry( "Encrypted", encrypted->isChecked() );
 
   config.sync();
 }
Index: kfile/kpropertiesdialog.h
===================================================================
RCS file: /home/kde/kdelibs/kio/kfile/kpropertiesdialog.h,v
retrieving revision 1.102
diff -p -u -b -r1.102 kpropertiesdialog.h
--- kfile/kpropertiesdialog.h	4 Mar 2004 15:02:10 -0000	1.102
+++ kfile/kpropertiesdialog.h	6 Apr 2004 14:38:55 -0000
@@ -650,7 +650,7 @@ private:
   QComboBox* device;
   QLabel* mountpoint;
   QCheckBox* readonly;
-  void* unused;
+  QCheckBox* encrypted;
   //KIconButton* mounted;
   KIconButton* unmounted;
 
Index: kio/job.cpp
===================================================================
RCS file: /home/kde/kdelibs/kio/kio/job.cpp,v
retrieving revision 1.380
diff -p -u -b -r1.380 job.cpp
--- kio/job.cpp	5 Apr 2004 16:17:36 -0000	1.380
+++ kio/job.cpp	6 Apr 2004 14:39:04 -0000
@@ -652,6 +652,17 @@ SimpleJob *KIO::mount( bool ro, const ch
     return job;
 }
 
+SimpleJob *KIO::mount( bool ro, bool encrypt,  const char *fstype, const QString& dev,
+                       const QString& point, bool showProgressInfo )
+{
+    KIO_ARGS << int(4) << Q_INT8( ro ? 1 : 0 )
+             << QString::fromLatin1(fstype) << dev << point << Q_INT8( encrypt ? 1 : 0 );
+    SimpleJob *job = special( KURL("file:/"), packedArgs, showProgressInfo );
+    if ( showProgressInfo )
+         Observer::self()->mounting( job, dev, point );
+    return job;
+}
+
 SimpleJob *KIO::unmount( const QString& point, bool showProgressInfo )
 {
     KIO_ARGS << int(2) << point;
Index: kio/job.h
===================================================================
RCS file: /home/kde/kdelibs/kio/kio/job.h,v
retrieving revision 1.96
diff -p -u -b -r1.96 job.h
--- kio/job.h	20 Aug 2003 08:01:43 -0000	1.96
+++ kio/job.h	6 Apr 2004 14:39:05 -0000
@@ -118,6 +118,24 @@ namespace KIO {
     SimpleJob *mount( bool ro, const char *fstype, const QString& dev, const QString& point, bool showProgressInfo = true );
 
     /**
+     * Mount filesystem.
+     * Same like above method, but it additionally supports mounting
+     * of encrypted filesystems.
+     *
+     * Special job for @p kio_file.
+     *
+     * @param ro Mount read-only if @p true.
+     * @param encrypt Ask for password if @p true
+     * @param fstype File system type (e.g. "ext2", can be 0L).
+     * @param dev Device (e.g. /dev/sda0).
+     * @param point Mount point, can be @p null.
+     * @param showProgressInfo true to show progress information
+     * @return the job handling the operation.
+     */
+    SimpleJob *mount( bool ro, bool encrypt, const char *fstype, const QString& dev, const QString& point, 
+                      bool showProgressInfo = true );
+
+    /**
      * Unmount filesystem.
      *
      * Special job for @p kio_file.
Index: kio/kautomount.cpp
===================================================================
RCS file: /home/kde/kdelibs/kio/kio/kautomount.cpp,v
retrieving revision 1.30
diff -p -u -b -r1.30 kautomount.cpp
--- kio/kautomount.cpp	21 Mar 2004 18:40:25 -0000	1.30
+++ kio/kautomount.cpp	6 Apr 2004 14:39:05 -0000
@@ -42,6 +42,19 @@ KAutoMount::KAutoMount( bool _readonly, 
   connect( job, SIGNAL( result( KIO::Job * ) ), this, SLOT( slotResult( KIO::Job * ) ) );
 }
 
+KAutoMount::KAutoMount( bool _readonly, const QString& _format, const QString& _device,
+                        const QString&  _mountpoint, bool _encrypted, const QString & _desktopFile,
+                        bool _show_filemanager_window )
+  : m_strDevice( _device ),
+    m_desktopFile( _desktopFile )
+{
+  //kdDebug(7015) << "KAutoMount device=" << _device << " mountpoint=" << _mountpoint << endl;
+  m_bShowFilemanagerWindow = _show_filemanager_window;
+
+  KIO::Job* job = KIO::mount( _readonly, _encrypted, _format.ascii(), _device, _mountpoint );
+  connect( job, SIGNAL( result( KIO::Job * ) ), this, SLOT( slotResult( KIO::Job * ) ) );
+}
+
 void KAutoMount::slotResult( KIO::Job * job )
 {
   if ( job->error() ) {
Index: kio/kautomount.h
===================================================================
RCS file: /home/kde/kdelibs/kio/kio/kautomount.h,v
retrieving revision 1.18
diff -p -u -b -r1.18 kautomount.h
--- kio/kautomount.h	16 Aug 2003 19:45:09 -0000	1.18
+++ kio/kautomount.h	6 Apr 2004 14:39:06 -0000
@@ -52,6 +52,21 @@ public:
   KAutoMount( bool readonly, const QString& format, const QString& device, const QString& mountpoint,
               const QString & desktopFile, bool show_filemanager_window = true );
 
+  /**
+   * Mounts a device.
+   * @param readonly if true, the device is mounted read-only
+   * @param format the file system (e.g. vfat, ext2...) [optional, fstab is used otherwise]
+   * @param device the path to the device (e.g. /dev/fd0)
+   * @param mountpoint the directory where to mount the device [optional, fstab is used otherwise]
+   * @param encrypted if true, a password dialog will pop up, the password will be forwarded to mount
+   * @param desktopFile the file the user clicked on - to notify KDirWatch of the fact that
+   * it should emit fileDirty for it (to have the icon change)
+   * @param show_filemanager_window if true, a file-manager window for that mountpoint is shown after
+   * the mount, if successful.
+   */
+  KAutoMount( bool readonly, const QString& format, const QString& device, const QString& mountpoint,
+              bool encrypted, const QString & desktopFile, bool show_filemanager_window = true );
+
 signals:
   /** Emitted when the directory has been mounted */
   void finished();
Index: kio/kmimetype.cpp
===================================================================
RCS file: /home/kde/kdelibs/kio/kio/kmimetype.cpp,v
retrieving revision 1.187
diff -p -u -b -r1.187 kmimetype.cpp
--- kio/kmimetype.cpp	29 Mar 2004 09:43:34 -0000	1.187
+++ kio/kmimetype.cpp	6 Apr 2004 14:39:08 -0000
@@ -810,11 +810,12 @@ pid_t KDEDesktopMimeType::runFSDevice( c
   else
   {
     bool ro = cfg.readBoolEntry( "ReadOnly", false );
+    bool encrypt = cfg.readBoolEntry( "Encrypted", false );
     QString fstype = cfg.readEntry( "FSType" );
     if ( fstype == "Default" ) // KDE-1 thing
       fstype = QString::null;
     QString point = cfg.readEntry( "MountPoint" );
-    (void) new KAutoMount( ro, fstype, dev, point, _url.path() );
+    (void) new KAutoMount( ro, fstype, dev, point, encrypt, _url.path() );
     retval = -1; // we don't want to return 0, but we don't want to return a pid
   }
 
@@ -1055,11 +1056,12 @@ void KDEDesktopMimeType::executeService(
       }
 
       bool ro = cfg.readBoolEntry( "ReadOnly", false );
+      bool encrypted = cfg.readBoolEntry( "Encrypted", false );
       QString fstype = cfg.readEntry( "FSType" );
       if ( fstype == "Default" ) // KDE-1 thing
           fstype = QString::null;
       QString point = cfg.readEntry( "MountPoint" );
-      (void)new KAutoMount( ro, fstype, dev, point, path, false );
+      (void)new KAutoMount( ro, fstype, dev, point, encrypted, path, false );
     }
     else if ( _service.m_type == ST_UNMOUNT )
     {
-------------- next part --------------
? kmountwrapper.cpp
? kmountwrapper.h
? main.cpp
? patchme
Index: .cvsignore
===================================================================
RCS file: /home/kde/kdelibs/kioslave/file/.cvsignore,v
retrieving revision 1.5
diff -p -u -b -r1.5 .cvsignore
--- .cvsignore	28 May 2002 18:22:45 -0000	1.5
+++ .cvsignore	6 Apr 2004 14:40:34 -0000
@@ -4,3 +4,4 @@ Makefile.rules.in
 SunWS_cache
 ir.out
 kio_file
+kmountwrapper
Index: Makefile.am
===================================================================
RCS file: /home/kde/kdelibs/kioslave/file/Makefile.am,v
retrieving revision 1.24
diff -p -u -b -r1.24 Makefile.am
--- Makefile.am	25 May 2002 18:00:10 -0000	1.24
+++ Makefile.am	6 Apr 2004 14:40:34 -0000
@@ -20,3 +20,9 @@ METASOURCES = AUTO
 
 kdelnkdir = $(kde_servicesdir)
 kdelnk_DATA = file.protocol
+
+bin_PROGRAMS = kmountwrapper
+
+kmountwrapper_SOURCES = main.cpp kmountwrapper.cpp
+kmountwrapper_LDFLAGS = $(all_libraries) $(KDE_RPATH)
+kmountwrapper_LDADD = $(LIB_KDEUI)
Index: file.cc
===================================================================
RCS file: /home/kde/kdelibs/kioslave/file/file.cc,v
retrieving revision 1.147
diff -p -u -b -r1.147 file.cc
--- file.cc	15 Feb 2004 20:25:24 -0000	1.147
+++ file.cc	6 Apr 2004 14:40:37 -0000
@@ -1108,6 +1108,21 @@ void FileProtocol::special( const QByteA
           finished();
       break;
     }
+    case 4:
+    {
+      QString fstype, dev, point;
+      Q_INT8 iRo, iEncrypt;
+
+      stream >> iRo >> fstype >> dev >> point >> iEncrypt;
+
+      bool ro = ( iRo != 0 );
+      bool encrypted = ( iEncrypt != 0 );
+
+      kdDebug(7101) << "MOUNTING fstype=" << fstype << " dev=" << dev <<
+                       " point=" << point << " ro=" << ro << " encrypted=" << encrypted << endl;
+      mount( ro, fstype.ascii(), dev, point, encrypted );
+    }
+    break;
     default:
       break;
     }
@@ -1129,6 +1144,12 @@ void FileProtocol::slotInfoMessage( cons
 
 void FileProtocol::mount( bool _ro, const char *_fstype, const QString& _dev, const QString& _point )
 {
+  mount( _ro, _fstype, _dev, _point, false );
+}
+
+void FileProtocol::mount( bool _ro, const char *_fstype, const QString& _dev,
+                          const QString& _point, bool _encrypted )
+{
     kdDebug(7101) << "FileProtocol::mount _fstype=" << _fstype << endl;
     QCString buffer;
 
@@ -1176,6 +1197,8 @@ void FileProtocol::mount( bool _ro, cons
     if (mountProg.isEmpty())
         mountProg = "mount";
 
+    mountProg = QString( "kmountwrapper" ) + (_encrypted ? " --encrypted " : " ") + mountProg;
+
     // Two steps, in case mount doesn't like it when we pass all options
     for ( int step = 0 ; step <= 1 ; step++ )
     {
@@ -1208,10 +1231,10 @@ void FileProtocol::mount( bool _ro, cons
 
         kdDebug(7101) << buffer << endl;
 
-        system( buffer.data() );
+        int result = system( buffer.data() );
 
         QString err = testLogFile( tmp );
-        if ( err.isEmpty() )
+        if ( result == 0 )
         {
             finished();
             return;
Index: file.h
===================================================================
RCS file: /home/kde/kdelibs/kioslave/file/file.h,v
retrieving revision 1.31
diff -p -u -b -r1.31 file.h
--- file.h	28 Nov 2002 00:10:32 -0000	1.31
+++ file.h	6 Apr 2004 14:40:37 -0000
@@ -68,10 +68,13 @@ public:
    * 1 - mount
    * 2 - unmount
    * 3 - shred
+   * 4 - mount with encryption
    */
   virtual void special( const QByteArray &data);
   void unmount( const QString& point );
   void mount( bool _ro, const char *_fstype, const QString& dev, const QString& point );
+  void mount( bool _ro, const char *_fstype, const QString& dev,
+              const QString& point, bool encrypted );
 
 protected slots:
   void slotProcessedSize( KIO::filesize_t _bytes );
-------------- next part --------------
A non-text attachment was scrubbed...
Name: kmountwrapper.cpp
Type: text/x-c++src
Size: 3740 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20040406/7c84e357/attachment.cpp>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: kmountwrapper.h
Type: text/x-chdr
Size: 1381 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20040406/7c84e357/attachment.h>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: main.cpp
Type: text/x-c++src
Size: 1166 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20040406/7c84e357/attachment-0001.cpp>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20040406/7c84e357/attachment.sig>


More information about the kde-core-devel mailing list