From 91c498557c70882107dba7308fabd176cf62fa3c Mon Sep 17 00:00:00 2001 From: Alexandre Garnier Date: Sat, 17 Sep 2016 08:26:52 +0200 Subject: [PATCH] Fix mixed type comparison resulting in wrong `changed` (#2772) When using `use_max` or `use_min` in `pam_limits`, the new value is an integer compared with the actual_value which is a string, so they are always different and the module reports a changed but none occurred. --- system/pam_limits.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/system/pam_limits.py b/system/pam_limits.py index 30a31b01b9d..8e6bdbe9695 100644 --- a/system/pam_limits.py +++ b/system/pam_limits.py @@ -212,7 +212,7 @@ def main(): if use_max: if value.isdigit() and actual_value.isdigit(): - new_value = max(int(value), int(actual_value)) + new_value = str(max(int(value), int(actual_value))) elif actual_value_unlimited: new_value = actual_value else: @@ -220,7 +220,7 @@ def main(): if use_min: if value.isdigit() and actual_value.isdigit(): - new_value = min(int(value), int(actual_value)) + new_value = str(min(int(value), int(actual_value))) elif value_unlimited: new_value = actual_value else: @@ -229,7 +229,7 @@ def main(): # Change line only if value has changed if new_value != actual_value: changed = True - new_limit = domain + "\t" + limit_type + "\t" + limit_item + "\t" + str(new_value) + new_comment + "\n" + new_limit = domain + "\t" + limit_type + "\t" + limit_item + "\t" + new_value + new_comment + "\n" message = new_limit nf.write(new_limit) else: @@ -240,7 +240,7 @@ def main(): if not found: changed = True - new_limit = domain + "\t" + limit_type + "\t" + limit_item + "\t" + str(new_value) + new_comment + "\n" + new_limit = domain + "\t" + limit_type + "\t" + limit_item + "\t" + new_value + new_comment + "\n" message = new_limit nf.write(new_limit)