[virt-tools-list] [virt-manager PATCH 2/2] console: add support to forget password

Pavel Hrdina phrdina at redhat.com
Tue Jun 7 14:21:09 UTC 2016


If password for console is saved currently there is no way how to tell
virt-manager to forget that password.  This patch improves the authentication
page in order to provide a way how to forget password simply by unchecking the
"Save this password in your keyring".

Signed-off-by: Pavel Hrdina <phrdina at redhat.com>
---
 ui/details.ui          |  1 +
 virtManager/config.py  | 13 +++++++++++++
 virtManager/console.py |  2 ++
 virtManager/domain.py  |  4 ++++
 virtManager/keyring.py | 10 ++++++++++
 5 files changed, 30 insertions(+)

diff --git a/ui/details.ui b/ui/details.ui
index 95aa6a4..4159f1d 100644
--- a/ui/details.ui
+++ b/ui/details.ui
@@ -5906,6 +5906,7 @@ if you know what you are doing.</small></property>
                         <property name="label" translatable="yes">_Save this password in your keyring</property>
                         <property name="visible">True</property>
                         <property name="can_focus">True</property>
+                        <property name="tooltip_text" translatable="yes">Check to save password, uncheck to forget password.</property>
                         <property name="receives_default">False</property>
                         <property name="use_underline">True</property>
                         <property name="xalign">0</property>
diff --git a/virtManager/config.py b/virtManager/config.py
index 9d394ca..865fa2f 100644
--- a/virtManager/config.py
+++ b/virtManager/config.py
@@ -708,3 +708,16 @@ class vmmConfig(object):
             return
 
         vm.set_console_password(username, keyid)
+
+    def del_console_password(self, vm):
+        if not self.has_keyring():
+            return
+
+        username, keyid = vm.get_console_password()
+
+        if keyid == -1:
+            return
+
+        self.keyring.del_secret(keyid)
+
+        vm.del_console_password()
diff --git a/virtManager/console.py b/virtManager/console.py
index 66e89d8..bd8b188 100644
--- a/virtManager/console.py
+++ b/virtManager/console.py
@@ -749,6 +749,8 @@ class vmmConsolePages(vmmGObjectUI):
         if self.widget("console-auth-remember").get_active():
             self.config.set_console_password(self.vm, passwd.get_text(),
                                              username.get_text())
+        else:
+            self.config.del_console_password(self.vm)
 
 
     ##########################
diff --git a/virtManager/domain.py b/virtManager/domain.py
index f6cb40c..575f86a 100644
--- a/virtManager/domain.py
+++ b/virtManager/domain.py
@@ -1706,6 +1706,10 @@ class vmmDomain(vmmLibvirtObject):
     def set_console_password(self, username, keyid):
         return self.config.set_pervm(self.get_uuid(), "/console-password",
                                      (username, keyid))
+    def del_console_password(self):
+        return self.config.set_pervm(self.get_uuid(), "/console-password",
+                                     ("", -1))
+
 
     def _on_config_sample_network_traffic_changed(self, ignore=None):
         self._enable_net_poll = self.config.get_stats_enable_net_poll()
diff --git a/virtManager/keyring.py b/virtManager/keyring.py
index 0f758e0..d3a300a 100644
--- a/virtManager/keyring.py
+++ b/virtManager/keyring.py
@@ -88,6 +88,16 @@ class vmmKeyring(object):
 
         return ret
 
+    def del_secret(self, _id):
+        try:
+            path = self._collection.get_object_path() + "/" + str(_id)
+            iface = Gio.DBusProxy.new_sync(self._dbus, 0, None,
+                                           "org.freedesktop.secrets", path,
+                                           "org.freedesktop.Secret.Item", None)
+            iface.Delete("(s)", "/")
+        except:
+            logging.exception("Failed to delete keyring secret")
+
     def get_secret(self, _id):
         ret = None
         try:
-- 
2.8.3




More information about the virt-tools-list mailing list