From 6b54a29ac73fe2e972e23acbcb2d53ad0f5ec775 Mon Sep 17 00:00:00 2001 From: Jason Ertel Date: Wed, 3 Feb 2021 15:23:58 -0500 Subject: [PATCH 1/2] Remove 'new user' references from so-user --- salt/common/tools/sbin/so-user | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/salt/common/tools/sbin/so-user b/salt/common/tools/sbin/so-user index b918ff173..b97cc8a8b 100755 --- a/salt/common/tools/sbin/so-user +++ b/salt/common/tools/sbin/so-user @@ -26,9 +26,9 @@ if [[ $# -lt 1 || $# -gt 2 ]]; then echo " update: Updates a user's password; requires 'email' parameter" echo " enable: Enables a user; requires 'email' parameter" echo " disable: Disables a user; requires 'email' parameter" - echo " validate: Validates that the given email address and password are acceptable for defining a new user; requires 'email' parameter" - echo " valemail: Validates that the given email address is acceptable for defining a new user; requires 'email' parameter" - echo " valpass: Validates that a password is acceptable for defining a new user" + echo " validate: Validates that the given email address and password are acceptable; requires 'email' parameter" + echo " valemail: Validates that the given email address is acceptable; requires 'email' parameter" + echo " valpass: Validates that a password is acceptable" echo "" echo " Note that the password can be piped into STDIN to avoid prompting for it" exit 1 From e427f8178d88e96685fcda92c14d338752a65144 Mon Sep 17 00:00:00 2001 From: Jason Ertel Date: Thu, 4 Feb 2021 16:06:11 -0500 Subject: [PATCH 2/2] Implement locking to so-firewall script --- salt/common/tools/sbin/so-firewall | 31 +++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/salt/common/tools/sbin/so-firewall b/salt/common/tools/sbin/so-firewall index d16550c54..86387fc24 100755 --- a/salt/common/tools/sbin/so-firewall +++ b/salt/common/tools/sbin/so-firewall @@ -15,10 +15,13 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +import os import subprocess import sys +import time import yaml +lockFile = "/tmp/so-firewall.lock" hostgroupsFilename = "/opt/so/saltstack/local/salt/firewall/hostgroups.local.yaml" portgroupsFilename = "/opt/so/saltstack/local/salt/firewall/portgroups.local.yaml" defaultPortgroupsFilename = "/opt/so/saltstack/default/salt/firewall/portgroups.yaml" @@ -329,7 +332,7 @@ def apply(): proc = subprocess.run(['salt-call', 'state.apply', 'firewall', 'queue=True']) return proc.returncode -def main(): +def main(): options = [] args = sys.argv[1:] for option in args: @@ -356,8 +359,30 @@ def main(): "addportgroup": addportgroup } - cmd = commands.get(args[0], showUsage) - code = cmd(options, args[1:]) + code=1 + + try: + lockAttempts = 0 + maxAttempts = 30 + while lockAttempts < maxAttempts: + lockAttempts = lockAttempts + 1 + try: + f = open(lockFile, "x") + f.close() + break + except: + time.sleep(2) + + if lockAttempts == maxAttempts: + print("Lock file (" + lockFile + ") could not be created; proceeding without lock.") + + cmd = commands.get(args[0], showUsage) + code = cmd(options, args[1:]) + finally: + try: + os.remove(lockFile) + except: + print("Lock file (" + lockFile + ") already removed") sys.exit(code)