[node-patches] Change in ovirt-node[master]: Add console.size, and shorten the password message on a smal...

rbarry at redhat.com rbarry at redhat.com
Fri Aug 28 15:43:52 UTC 2015


Ryan Barry has uploaded a new change for review.

Change subject: Add console.size, and shorten the password message on a small term
......................................................................

Add console.size, and shorten the password message on a small term

If we don't have enough rows, keep the message shorter, but still
warn that it's a weak password.

Also add a convenience function to check the rows/columns of the
terminal in case it's useful anywhere else.

Change-Id: Ifa580235f545e41dd25236b5dca2e6310b68ccca
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1214611
Signed-off-by: Ryan Barry <rbarry at redhat.com>
---
M src/ovirt/node/utils/console.py
M src/ovirt/node/utils/security.py
2 files changed, 23 insertions(+), 7 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/57/45457/1

diff --git a/src/ovirt/node/utils/console.py b/src/ovirt/node/utils/console.py
old mode 100644
new mode 100755
index 672571b..8e97e5d
--- a/src/ovirt/node/utils/console.py
+++ b/src/ovirt/node/utils/console.py
@@ -20,6 +20,7 @@
 # also available at http://www.gnu.org/copyleft/gpl.html.
 from ovirt.node import base
 from ovirt.node.utils import Transaction, process
+from collections import namedtuple
 import StringIO
 import sys
 import os
@@ -69,6 +70,18 @@
     process.call(["reset"])
 
 
+def size():
+    """Returns the size of the console as a tuple
+    """
+
+    size = namedtuple("consolesize", ["rows", "columns"])
+
+    rows, cols = ([int(x) for x in process.check_output(['stty',
+                                                         'size']).split()])
+
+    return size(rows, cols)
+
+
 def writeln(txts):
     """Write something to stdout
     A wrapper if we want to do this differently in future
diff --git a/src/ovirt/node/utils/security.py b/src/ovirt/node/utils/security.py
index 1a22bc1..f5bf4f2 100644
--- a/src/ovirt/node/utils/security.py
+++ b/src/ovirt/node/utils/security.py
@@ -19,7 +19,7 @@
 # MA  02110-1301, USA.  A copy of the GNU General Public License is
 # also available at http://www.gnu.org/copyleft/gpl.html.
 from ovirt.node import base, valid, utils
-from ovirt.node.utils import system
+from ovirt.node.utils import console, system
 from ovirt.node.utils.fs import File
 import PAM as _PAM  # @UnresolvedImport
 import cracklib
@@ -84,12 +84,15 @@
         try:
             cracklib.FascistCheck(password)
         except ValueError as e:
-            message = "You have provided a weak password! "
-            message += "Strong passwords contain a mix of uppercase, "
-            message += "lowercase, numeric and punctuation characters. "
-            message += "They are six or more characters long and "
-            message += "do not contain dictionary words. "
-            message += "Reason: %s" % e
+            console_size = console.size()
+            message = "You have provided a weak password!"
+
+            if console_size.rows > 24:
+                message += "Strong passwords contain a mix of uppercase, "
+                message += "lowercase, numeric and punctuation characters. "
+                message += "They are six or more characters long and "
+                message += "do not contain dictionary words. "
+                message += "Reason: %s" % e
 
     return message
 


-- 
To view, visit https://gerrit.ovirt.org/45457
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifa580235f545e41dd25236b5dca2e6310b68ccca
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: master
Gerrit-Owner: Ryan Barry <rbarry at redhat.com>



More information about the node-patches mailing list