[Pkg-privacy-commits] [libgsecuredelete] 28/168: Add support for SwapOperation (sswap).

Ulrike Uhlig u-guest at moszumanska.debian.org
Thu Jul 7 20:06:34 UTC 2016


This is an automated email from the git hooks/post-receive script.

u-guest pushed a commit to branch master
in repository libgsecuredelete.

commit b0624008895f0ea096eedb361fac2b2c344236fd
Author: Colomban Wendling <ban at herbesfolles.org>
Date:   Mon Oct 5 18:16:36 2009 +0200

    Add support for SwapOperation (sswap).
---
 gsecuredelete/Makefile.am          |   1 +
 gsecuredelete/async-operation.vala |   3 +-
 gsecuredelete/swap-operation.vala  | 146 +++++++++++++++++++++++++++++++++++++
 3 files changed, 149 insertions(+), 1 deletion(-)

diff --git a/gsecuredelete/Makefile.am b/gsecuredelete/Makefile.am
index 0b3cf43..cc2e2a0 100644
--- a/gsecuredelete/Makefile.am
+++ b/gsecuredelete/Makefile.am
@@ -14,6 +14,7 @@ libgsecuredelete_la_SOURCES = async-operation.vala \
                               delete-operation.vala \
                               fill-operation.vala \
                               mem-operation.vala \
+                              swap-operation.vala \
                               utils.vala
 libgsecuredelete_la_include_HEADERS = libgsecuredelete.h \
                                       libgsecuredelete.vapi
diff --git a/gsecuredelete/async-operation.vala b/gsecuredelete/async-operation.vala
index b15dda0..f77d31a 100644
--- a/gsecuredelete/async-operation.vala
+++ b/gsecuredelete/async-operation.vala
@@ -23,7 +23,8 @@ namespace SecureDelete
 {
   public errordomain AsyncOperationError {
     ARGS_ERROR,
-    CHILD_FAILED
+    CHILD_FAILED,
+    SUBCLASS_ERROR /* workaround the miss of error subclassing */
   }
   
   /* 
diff --git a/gsecuredelete/swap-operation.vala b/gsecuredelete/swap-operation.vala
new file mode 100644
index 0000000..cba5879
--- /dev/null
+++ b/gsecuredelete/swap-operation.vala
@@ -0,0 +1,146 @@
+/* 
+ * 
+ * Copyright (C) 2009 Colomban Wendling <ban at herbesfolles.org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ * 
+ */
+
+namespace SecureDelete
+{
+  public class SwapOperation : ZeroableOperation
+  {
+    /** SwapOperation:device:
+     * The swap device to wipe
+     */
+    public string device {
+      get;
+      set;
+      default = null;
+    }
+    /**
+     * Whether to throw an error if the swap is detected as being currently
+     * used.
+     * This may be useless as doing the operation on a in-use swap may crash the
+     * system.
+     */
+    public bool check_device {
+      get;
+      set;
+      default = true;
+    }
+    
+    /* check whether a swap device is currently in use by the system or not.
+     * TODO: For now we parse /proc/swaps to know it.. is this portable and/or
+     * the correct way to proceed? */
+    private bool swap_is_in_use (string swapdev)
+    {
+      bool    in_use = false;
+      /* cache variable, only not for computing the size more than once */
+      size_t  swapdev_len = swapdev.size ();
+      
+      var file = FileStream.open ("/proc/swaps", "r");
+      if (file != null) {
+        string? line = null;
+        
+        file.read_line (); /* skip header */
+        do {
+          line = file.read_line ();
+          if (line != null) {
+            in_use = line.has_prefix (swapdev) &&
+                     /* We don't want to match only the start but the whole
+                      * device name, then check the next character for
+                      * separator.
+                      * No risk of overflow as if we are here @line has the
+                      * @swapdev prefix, and the character at
+                      * line[swapdev.size()] must be at least the string-ending
+                      * character (0) */
+                     " \t".chr (-1, ((char[])line)[swapdev_len]) != null;
+          }
+        } while (line != null && ! in_use);
+      }
+      
+      return in_use;
+    }
+    
+    /* builds the argument vector */
+    private override List<string> build_args ()
+      throws AsyncOperationError
+    {
+      List<string> args = null;
+      
+      if (this.device == null) {
+        throw new AsyncOperationError.ARGS_ERROR ("Missing device to wipe");
+      }
+      /* no really clean to throw AsyncOperationError.SUBCLASS_ERROR, but
+       * there's no clean way to do that.. */
+      if (this.check_device && this.swap_is_in_use (this.device)) {
+        throw new AsyncOperationError.SUBCLASS_ERROR ("The swap device \"%s\" is in use",
+                                                      this.device);
+      }
+      
+      args.append ("sswap");
+      args.append ("-v");
+      this.add_mode_argument (ref args);
+      this.add_zeroise_argument (ref args);
+      args.append (this.device);
+      
+      return args;
+    }
+    
+    /* cleans up after subprocess termination */
+    private override void cleanup ()
+    {
+      this.device = null;
+    }
+    
+    /** run_sync:
+     * @device: the swap device to wipe. It is exactly the same as setting the
+     *          the SwapOperation:device property, just a convenience shortcut.
+     * @watch_interval: See AsyncOperation.run()
+     * 
+     * Launches a secure wiping of a swap device asynchronously.
+     * 
+     * Returns: whether subprocess started successfully.
+     */
+    public new bool run (string? device = null,
+                         uint watch_interval = 100)
+      throws SpawnError, AsyncOperationError
+      requires (! this.busy)
+    {
+      if (device != null) {
+        this.device = device;
+      }
+      return base.run (watch_interval);
+    }
+    
+    /** run_sync:
+     * @device: the swap device to wipe. It is exactly the same as setting the
+     *          the SwapOperation:device property, just a convenience shortcut.
+     * 
+     * Launches a secure wiping of a swap device synchronously.
+     * 
+     * Returns: whether wiping of the swap device succeed.
+     */
+    public new bool run_sync (string? device = null)
+      throws SpawnError, AsyncOperationError
+      requires (! this.busy)
+    {
+      if (device != null) {
+        this.device = device;
+      }
+      return base.run_sync ();
+    }
+  }
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/libgsecuredelete.git



More information about the Pkg-privacy-commits mailing list