From 359720e566ae9f0a7f8c40ab46e97be93f0c22e8 Mon Sep 17 00:00:00 2001 From: boltgolt Date: Wed, 5 Dec 2018 12:23:07 +0100 Subject: [PATCH] Switched to pam-auth-update for debian installs as per #107 --- debian/install | 1 + debian/postinst | 71 ++------------------------------------------ debian/prerm | 23 +++++++------- src/pam-config/howdy | 6 ++++ 4 files changed, 19 insertions(+), 82 deletions(-) create mode 100644 src/pam-config/howdy diff --git a/debian/install b/debian/install index c35719b..b4e148f 100644 --- a/debian/install +++ b/debian/install @@ -1,2 +1,3 @@ src/. lib/security/howdy +src/pam-config/. /usr/share/pam-configs autocomplete/. usr/share/bash-completion/completions diff --git a/debian/postinst b/debian/postinst index dffcc5d..c2035b4 100755 --- a/debian/postinst +++ b/debian/postinst @@ -140,75 +140,8 @@ print("Howdy command installed") log("Adding howdy as PAM module") -# Will be filled with the actual output lines -outlines = [] -# Will be fillled with lines that contain coloring -printlines = [] -# Track if the new lines have been insterted yet -inserted = False - -# Open the PAM config file -with open("/etc/pam.d/common-auth") as fp: - # Read the first line - line = fp.readline() - - while line: - # Add the line to the output directly, we're not deleting anything - outlines.append(line) - - # Print the comments in gray and don't insert into comments - if line[:1] == "#": - printlines.append("\033[37m" + line + "\033[0m") - else: - printlines.append(line) - - # If it's not a comment and we haven't inserted yet - if not inserted: - # Set both the comment and the linking line - line_comment = "# Howdy IR face recognition\n" - line_link = "auth sufficient pam_python.so /lib/security/howdy/pam.py\n\n" - - # Add them to the output without any markup - outlines.append(line_comment) - outlines.append(line_link) - - # Make the print orange to make it clear what's being added - printlines.append("\033[33m" + line_comment + "\033[0m") - printlines.append("\033[33m" + line_link + "\033[0m") - - # Mark as inserted - inserted = True - - # Go to the next line - line = fp.readline() - -# Print a file Header -print("\033[33m" + ">>> START OF /etc/pam.d/common-auth" + "\033[0m") - -# Loop though all printing lines and use the enters from the file -for line in printlines: - print(line, end="") - -# Print a footer -print("\033[33m" + ">>> END OF /etc/pam.d/common-auth" + "\033[0m" + "\n") - -# Do not prompt for a yes if we're in no promt mode -if "HOWDY_NO_PROMPT" not in os.environ: - # Ask the user if this change is okay - print("Lines will be insterted in /etc/pam.d/common-auth as shown above") - ans = input("Apply this change? [y/N]: ") - - # Abort the whole thing if it's not - if ans.lower().strip() != "y" or ans.lower().strip() == "yes": - print("Interpreting as a \"NO\", aborting") - sys.exit(1) - -print("Adding lines to PAM\n") - -# Write to PAM -common_auth = open("/etc/pam.d/common-auth", "w") -common_auth.write("".join(outlines)) -common_auth.close() +# Activate the pam-config file +handleStatus(subprocess.call(["pam-auth-update --package"], shell=True)) # Sign off print("Installation complete.") diff --git a/debian/prerm b/debian/prerm index e0c5126..319be6e 100755 --- a/debian/prerm +++ b/debian/prerm @@ -2,13 +2,6 @@ # Executed on deinstallation # Completely remove howdy from the system -def col(id): - """Add color escape sequences""" - if id == 1: return "\033[32m" - if id == 2: return "\033[33m" - if id == 3: return "\033[31m" - return "\033[0m" - # Import required modules import subprocess import sys @@ -31,6 +24,16 @@ try: subprocess.call(["rm /usr/share/bash-completion/completions/howdy"], shell=True) except e: print("Can't remove autocompletion script") + +# Refresh and remove howdy from pam-config +try: + subprocess.call(["pam-auth-update --package"], shell=True) + subprocess.call(["rm /usr/share/pam-configs/howdy"], shell=True) + subprocess.call(["pam-auth-update --package"], shell=True) +except e: + print("Can't remove pam module") + +# Remove full installation folder, just to be sure try: subprocess.call(["rm -rf /lib/security/howdy"], shell=True) except e: @@ -39,9 +42,3 @@ except e: # Remove face_recognition and dlib subprocess.call(["pip3 uninstall face_recognition face_recognition_models dlib -y --no-cache-dir"], shell=True) - -# Print a tearbending message -print(col(2) + """ -There are still lines in /etc/pam.d/common-auth that can't be removed automatically -Run "nano /etc/pam.d/common-auth" to remove them by hand\ -""" + col(0)) diff --git a/src/pam-config/howdy b/src/pam-config/howdy new file mode 100644 index 0000000..28fb6b1 --- /dev/null +++ b/src/pam-config/howdy @@ -0,0 +1,6 @@ +Name: Howdy +Default: yes +Priority: 512 +Auth-Type: Primary +Auth: + [success=end default=ignore] pam_python.so /lib/security/howdy/pam.py