[PATCH] mounting encrypted devices infrastructure

Tobias Koenig tokoe at kde.org
Mon Feb 16 15:11:10 GMT 2004


Hi,

the attached patches are the first step for mounting encrypted
partitions with the icons on the desktop.
It adds an additional checkbox 'Encrypted' to the KDevicePropsPlugin
and passes this boolean down to the file kioslave.

The next step would be a wrapper application which is called by the file
kioslave with all cmdline args for 'mount' and this wrapper app asks the
user for a password and executes the real 'mount' application as sub
process.

Can I commit the patches?

Ciao,
Tobias
-- 
Separate politics from religion and economy!
-------------- next part --------------
? kio/kssl/keygenwizard.cpp
? kio/kssl/keygenwizard2.cpp
Index: kio/kfile/kpropertiesdialog.cpp
===================================================================
RCS file: /home/kde/kdelibs/kio/kfile/kpropertiesdialog.cpp,v
retrieving revision 1.295
diff -p -u -b -r1.295 kpropertiesdialog.cpp
--- kio/kfile/kpropertiesdialog.cpp	28 Jan 2004 06:08:56 -0000	1.295
+++ kio/kfile/kpropertiesdialog.cpp	16 Feb 2004 15:03:45 -0000
@@ -2601,15 +2601,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);
@@ -2636,6 +2640,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 );
@@ -2653,6 +2658,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
@@ -2665,6 +2671,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() ) );
 
@@ -2735,6 +2743,7 @@ void KDevicePropsPlugin::applyChanges()
   kdDebug(250) << "unmounted->icon() = " << unmounted->icon() << endl;
 
   config.writeEntry( "ReadOnly", readonly->isChecked() );
+  config.writeEntry( "Encrypted", encrypted->isChecked() );
 
   config.sync();
 }
Index: kio/kfile/kpropertiesdialog.h
===================================================================
RCS file: /home/kde/kdelibs/kio/kfile/kpropertiesdialog.h,v
retrieving revision 1.101
diff -p -u -b -r1.101 kpropertiesdialog.h
--- kio/kfile/kpropertiesdialog.h	21 Dec 2003 16:29:14 -0000	1.101
+++ kio/kfile/kpropertiesdialog.h	16 Feb 2004 15:03:47 -0000
@@ -650,7 +650,7 @@ private:
   QComboBox* device;
   QLabel* mountpoint;
   QCheckBox* readonly;
-  void* unused;
+  QCheckBox* encrypted;
   //KIconButton* mounted;
   KIconButton* unmounted;
 
Index: kio/kio/job.cpp
===================================================================
RCS file: /home/kde/kdelibs/kio/kio/job.cpp,v
retrieving revision 1.372
diff -p -u -b -r1.372 job.cpp
--- kio/kio/job.cpp	14 Feb 2004 23:42:24 -0000	1.372
+++ kio/kio/job.cpp	16 Feb 2004 15:03:55 -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/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/kio/job.h	20 Aug 2003 08:01:43 -0000	1.96
+++ kio/kio/job.h	16 Feb 2004 15:03:56 -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/kio/kautomount.cpp
===================================================================
RCS file: /home/kde/kdelibs/kio/kio/kautomount.cpp,v
retrieving revision 1.29
diff -p -u -b -r1.29 kautomount.cpp
--- kio/kio/kautomount.cpp	12 Jan 2004 19:03:08 -0000	1.29
+++ kio/kio/kautomount.cpp	16 Feb 2004 15:03:56 -0000
@@ -41,6 +41,18 @@ 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 _encrypt, const QString & _desktopFile,
+                        bool _show_filemanager_window )
+  : m_strDevice( _device ),
+    m_desktopFile( _desktopFile )
+{
+  m_bShowFilemanagerWindow = _show_filemanager_window;
+
+  KIO::Job* job = KIO::mount( _readonly, _encrypt, _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/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/kio/kautomount.h	16 Aug 2003 19:45:09 -0000	1.18
+++ kio/kio/kautomount.h	16 Feb 2004 15:03:57 -0000
@@ -52,6 +52,9 @@ public:
   KAutoMount( bool readonly, const QString& format, const QString& device, const QString& mountpoint,
               const QString & desktopFile, bool show_filemanager_window = true );
 
+  KAutoMount( bool readonly, const QString& format, const QString& device, const QString& mountpoint,
+              bool encrypt, const QString & desktopFile, bool show_filemanager_window = true );
+
 signals:
   /** Emitted when the directory has been mounted */
   void finished();
Index: kio/kio/kmimetype.cpp
===================================================================
RCS file: /home/kde/kdelibs/kio/kio/kmimetype.cpp,v
retrieving revision 1.183
diff -p -u -b -r1.183 kmimetype.cpp
--- kio/kio/kmimetype.cpp	12 Jan 2004 19:11:14 -0000	1.183
+++ kio/kio/kmimetype.cpp	16 Feb 2004 15:03:59 -0000
@@ -795,11 +795,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
   }
 
@@ -1040,11 +1041,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 --------------
Index: kioslave/file/file.cc
===================================================================
RCS file: /home/kde/kdelibs/kioslave/file/file.cc,v
retrieving revision 1.147
diff -p -u -b -r1.147 file.cc
--- kioslave/file/file.cc	15 Feb 2004 20:25:24 -0000	1.147
+++ kioslave/file/file.cc	16 Feb 2004 15:03:22 -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;
 
Index: kioslave/file/file.h
===================================================================
RCS file: /home/kde/kdelibs/kioslave/file/file.h,v
retrieving revision 1.31
diff -p -u -b -r1.31 file.h
--- kioslave/file/file.h	28 Nov 2002 00:10:32 -0000	1.31
+++ kioslave/file/file.h	16 Feb 2004 15:03:22 -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: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20040216/d7afdb87/attachment.sig>


More information about the kde-core-devel mailing list