[f22-branch 5/7] Add pwpolicy support to TUI interface

bcl installerbot-noreply at redhat.com
Tue Mar 17 23:09:19 UTC 2015


From: "Brian C. Lane" <bcl at redhat.com>

This adds a new argument to EditTUIDialog so that the policy details can
be shared between the places that need it. root password and user entry
now support pwpolicy user and pwpolicy root settings.
---
 pyanaconda/ui/tui/spokes/__init__.py | 38 ++++++++++++++++++++++++++----------
 pyanaconda/ui/tui/spokes/password.py |  4 ++--
 pyanaconda/ui/tui/spokes/user.py     |  5 +++--
 3 files changed, 33 insertions(+), 14 deletions(-)

diff --git a/pyanaconda/ui/tui/spokes/__init__.py b/pyanaconda/ui/tui/spokes/__init__.py
index 8b1769f..651e23b 100644
--- a/pyanaconda/ui/tui/spokes/__init__.py
+++ b/pyanaconda/ui/tui/spokes/__init__.py
@@ -19,7 +19,7 @@
 # Red Hat Author(s): Martin Sivak <msivak at redhat.com>
 #
 from pyanaconda.ui.tui import simpleline as tui
-from pyanaconda.ui.tui.tuiobject import TUIObject
+from pyanaconda.ui.tui.tuiobject import TUIObject, YesNoDialog
 from pyanaconda.ui.common import Spoke, StandaloneSpoke, NormalSpoke
 from pyanaconda.users import validatePassword, cryptPassword
 import re
@@ -27,6 +27,7 @@
 from pyanaconda.iutil import setdeepattr, getdeepattr
 from pyanaconda.i18n import N_, _
 from pyanaconda.constants import PASSWORD_CONFIRM_ERROR_TUI, PW_ASCII_CHARS
+from pyanaconda.constants import PASSWORD_WEAK, PASSWORD_WEAK_WITH_ERROR
 
 __all__ = ["TUISpoke", "EditTUISpoke", "EditTUIDialog", "EditTUISpokeEntry",
            "StandaloneSpoke", "NormalTUISpoke"]
@@ -102,13 +103,18 @@ class EditTUIDialog(NormalTUISpoke):
     title = N_("New value")
     PASSWORD = re.compile(".*")
 
-    def __init__(self, app, data, storage, payload, instclass):
+    def __init__(self, app, data, storage, payload, instclass, policy_name=""):
         if self.__class__ is EditTUIDialog:
             raise TypeError("EditTUIDialog is an abstract class")
 
         NormalTUISpoke.__init__(self, app, data, storage, payload, instclass)
         self.value = None
 
+        # Configure the password policy, if available. Otherwise use defaults.
+        self.policy = self.data.pwpolicy.get_policy(policy_name)
+        if not self.policy:
+            self.policy = self.data.pwpolicy.handler.PwPolicyData()
+
     def refresh(self, args = None):
         self._window = []
         self.value = None
@@ -135,19 +141,31 @@ def prompt(self, entry = None):
                 self.value = ""
                 return None
 
-            valid, strength, message = validatePassword(pw, user=None)
+            valid, strength, message = validatePassword(pw, user=None, minlen=self.policy.minlen)
 
             if not valid:
                 print(message)
                 return None
 
-            if strength < 50:
+            if strength < self.policy.minquality:
+                if self.policy.strict:
+                    done_msg = ""
+                else:
+                    done_msg = _("\nWould you like to use it anyway?")
+
                 if message:
-                    error = _("You have provided a weak password: %s\n") % message
+                    error = _(PASSWORD_WEAK_WITH_ERROR) % (message, done_msg)
                 else:
-                    error = _("You have provided a weak password.")
-                print(error)
-                return None
+                    error = _(PASSWORD_WEAK) % done_msg
+
+                if not self.policy.strict:
+                    question_window = YesNoDialog(self._app, error)
+                    self._app.switch_screen_modal(question_window)
+                    if not question_window.answer:
+                        return None
+                else:
+                    print(error)
+                    return None
 
             if any(char not in PW_ASCII_CHARS for char in pw):
                 print(_("You have provided a password containing non-ASCII characters.\n"
@@ -218,12 +236,12 @@ class EditTUISpoke(NormalTUISpoke):
     edit_fields = [
     ]
 
-    def __init__(self, app, data, storage, payload, instclass):
+    def __init__(self, app, data, storage, payload, instclass, policy_name=""):
         if self.__class__ is EditTUISpoke:
             raise TypeError("EditTUISpoke is an abstract class")
 
         NormalTUISpoke.__init__(self, app, data, storage, payload, instclass)
-        self.dialog = OneShotEditTUIDialog(app, data, storage, payload, instclass)
+        self.dialog = OneShotEditTUIDialog(app, data, storage, payload, instclass, policy_name=policy_name)
 
         # self.args should hold the object this Spoke is supposed
         # to edit
diff --git a/pyanaconda/ui/tui/spokes/password.py b/pyanaconda/ui/tui/spokes/password.py
index 4fe971a..2478d8d 100644
--- a/pyanaconda/ui/tui/spokes/password.py
+++ b/pyanaconda/ui/tui/spokes/password.py
@@ -33,7 +33,7 @@ class PasswordSpoke(FirstbootSpokeMixIn, EditTUIDialog):
     category = UserSettingsCategory
 
     def __init__(self, app, data, storage, payload, instclass):
-        EditTUIDialog.__init__(self, app, data, storage, payload, instclass)
+        EditTUIDialog.__init__(self, app, data, storage, payload, instclass, "root")
         self._password = None
 
     @property
@@ -42,7 +42,7 @@ def completed(self):
 
     @property
     def showable(self):
-        return not (self.completed and flags.automatedInstall)
+        return not (self.completed and flags.automatedInstall and not self.policy.changesok)
 
     @property
     def mandatory(self):
diff --git a/pyanaconda/ui/tui/spokes/user.py b/pyanaconda/ui/tui/spokes/user.py
index 1c24d6d..68a27ad 100644
--- a/pyanaconda/ui/tui/spokes/user.py
+++ b/pyanaconda/ui/tui/spokes/user.py
@@ -66,7 +66,7 @@ def should_run(cls, environment, data):
 
     def __init__(self, app, data, storage, payload, instclass):
         FirstbootSpokeMixIn.__init__(self)
-        EditTUISpoke.__init__(self, app, data, storage, payload, instclass)
+        EditTUISpoke.__init__(self, app, data, storage, payload, instclass, "user")
 
         if self.data.user.userList:
             self.args = self.data.user.userList[0]
@@ -99,7 +99,8 @@ def completed(self):
 
     @property
     def showable(self):
-        return not (self.completed and flags.automatedInstall)
+        return not (self.completed and flags.automatedInstall
+                    and self.data.user.seen and not self.dialog.policy.changesok)
 
     @property
     def mandatory(self):


-- 
To view this commit on github, visit https://github.com/rhinstaller/anaconda/commit/5b3506f9db037868c8f65248e4d32eb4ed158016


More information about the anaconda-patches mailing list