|
|
1756dc |
From 474404051fe461a1be5d175b3f13da54ddbe0a37 Mon Sep 17 00:00:00 2001
|
|
|
1756dc |
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina@redhat.com>
|
|
|
1756dc |
Date: Tue, 4 Sep 2018 11:36:43 +0200
|
|
|
1756dc |
Subject: [PATCH 04/16] compat: write only options set on command line to
|
|
|
1756dc |
pwquality.conf
|
|
|
1756dc |
|
|
|
1756dc |
This will not overwrite pwquality.conf if for exapmle "authconfig --update"
|
|
|
1756dc |
is called. Without this patch the values would get overriden with empty
|
|
|
1756dc |
values.
|
|
|
1756dc |
---
|
|
|
1756dc |
src/compat/authcompat.py.in.in | 36 ++++++++++++++++++++++------------
|
|
|
1756dc |
1 file changed, 24 insertions(+), 12 deletions(-)
|
|
|
1756dc |
|
|
|
1756dc |
diff --git a/src/compat/authcompat.py.in.in b/src/compat/authcompat.py.in.in
|
|
|
1756dc |
index 1b4f531b021c1e2e8fd99bd081094da365c0c64e..4fa9a6afc1d62aa9dde41b525d473168e6dc2901 100755
|
|
|
1756dc |
--- a/src/compat/authcompat.py.in.in
|
|
|
1756dc |
+++ b/src/compat/authcompat.py.in.in
|
|
|
1756dc |
@@ -166,7 +166,10 @@ class Configuration:
|
|
|
1756dc |
def getBool(self, name):
|
|
|
1756dc |
return self.options.getBool(name)
|
|
|
1756dc |
|
|
|
1756dc |
- def getBoolAsValue(self, name, if_true, if_false):
|
|
|
1756dc |
+ def getBoolAsValue(self, name, if_true, if_false, AllowNone=False):
|
|
|
1756dc |
+ if AllowNone and not self.isset(name):
|
|
|
1756dc |
+ return None
|
|
|
1756dc |
+
|
|
|
1756dc |
value = self.getBool(name)
|
|
|
1756dc |
if value:
|
|
|
1756dc |
return if_true
|
|
|
1756dc |
@@ -318,19 +321,28 @@ class Configuration:
|
|
|
1756dc |
|
|
|
1756dc |
def write(self):
|
|
|
1756dc |
config = EnvironmentFile(Path.System('pwquality.conf'))
|
|
|
1756dc |
+ value_set = False
|
|
|
1756dc |
|
|
|
1756dc |
- # for each if these options, we want to write a line to the config
|
|
|
1756dc |
- # *only if* it is set to an actual value, see
|
|
|
1756dc |
- # https://bugzilla.redhat.com/show_bug.cgi?id=1618865
|
|
|
1756dc |
- for pwval in ["minlen", "minclass", "maxrepeat", "maxclassrepeat"]:
|
|
|
1756dc |
- if self.isset("pass{0}".format(pwval)):
|
|
|
1756dc |
- config.set(pwval, self.get("pass{0}".format(pwval)))
|
|
|
1756dc |
+ pwopts = {
|
|
|
1756dc |
+ "minlen" : self.get("passminlen"),
|
|
|
1756dc |
+ "minclass" : self.get("passminclass"),
|
|
|
1756dc |
+ "maxrepeat" : self.get("passmaxrepeat"),
|
|
|
1756dc |
+ "maxclassrepeat" : self.get("passmaxclassrepeat"),
|
|
|
1756dc |
+ "lcredit" : self.getBoolAsValue("reqlower", -1, 0, AllowNone=True),
|
|
|
1756dc |
+ "ucredit" : self.getBoolAsValue("requpper", -1, 0, AllowNone=True),
|
|
|
1756dc |
+ "dcredit" : self.getBoolAsValue("reqdigit", -1, 0, AllowNone=True),
|
|
|
1756dc |
+ "ocredit" : self.getBoolAsValue("reqother", -1, 0, AllowNone=True)
|
|
|
1756dc |
+ }
|
|
|
1756dc |
|
|
|
1756dc |
- config.set("lcredit", self.getBoolAsValue("reqlower", -1, 0))
|
|
|
1756dc |
- config.set("ucredit", self.getBoolAsValue("requpper", -1, 0))
|
|
|
1756dc |
- config.set("dcredit", self.getBoolAsValue("reqdigit", -1, 0))
|
|
|
1756dc |
- config.set("ocredit", self.getBoolAsValue("reqother", -1, 0))
|
|
|
1756dc |
- config.write()
|
|
|
1756dc |
+ # Write options only if their are actually set
|
|
|
1756dc |
+ for opt, value in pwopts.items():
|
|
|
1756dc |
+ if value is not None:
|
|
|
1756dc |
+ print(opt + "=" + str(value))
|
|
|
1756dc |
+ config.set(opt, value)
|
|
|
1756dc |
+ value_set = True
|
|
|
1756dc |
+
|
|
|
1756dc |
+ if value_set:
|
|
|
1756dc |
+ config.write()
|
|
|
1756dc |
|
|
|
1756dc |
class MakeHomedir(Base):
|
|
|
1756dc |
def __init__(self, options):
|
|
|
1756dc |
--
|
|
|
1756dc |
2.17.1
|
|
|
1756dc |
|