aboutsummaryrefslogtreecommitdiffstats
path: root/modules/openssh/templates/ldap-sshkey2file.py
diff options
context:
space:
mode:
Diffstat (limited to 'modules/openssh/templates/ldap-sshkey2file.py')
-rwxr-xr-xmodules/openssh/templates/ldap-sshkey2file.py31
1 files changed, 15 insertions, 16 deletions
diff --git a/modules/openssh/templates/ldap-sshkey2file.py b/modules/openssh/templates/ldap-sshkey2file.py
index f01a3fbf..7c41832d 100755
--- a/modules/openssh/templates/ldap-sshkey2file.py
+++ b/modules/openssh/templates/ldap-sshkey2file.py
@@ -5,6 +5,8 @@ import os
import random
import shutil
import tempfile
+import argparse
+import textwrap
try:
import ldap
@@ -29,18 +31,19 @@ nslcd_conf_file="<%= nslcd_conf_file %>"
filter="(&(objectClass=inetOrgPerson)(objectClass=ldapPublicKey)(objectClass=posixAccount)(sshPublicKey=*))"
keypathprefix='/home'
-def usage():
- print "%s" % sys.argv[0]
- print
- print "Will fetch all enabled user accounts under %s" % peopledn
- print "with ssh keys in them and write each one to"
- print "%s/<login>/.ssh/authorized_keys" % keypathprefix
- print
- print "It will return failure when no keys are updated and success"
- print "when one or more keys have changed."
- print
- print "This script is intended to be run from cron as root"
- print
+parser = argparse.ArgumentParser(
+ formatter_class=argparse.RawDescriptionHelpFormatter,
+ description=textwrap.dedent('''\
+ Will fetch all enabled user accounts under %s
+ with ssh keys in them and write each one to
+ %s/<login>/.ssh/authorized_keys
+
+ It will return failure when no keys are updated and success
+ when one or more keys have changed.
+
+ This script is intended to be run from cron as root;
+ ''' % (peopledn, keypathprefix)))
+args = parser.parse_args()
def get_bindpw():
try:
@@ -134,10 +137,6 @@ def write_keys(keys, user, uid, gid):
return True
-if len(sys.argv) != 1:
- usage()
- sys.exit(1)
-
bindpw = get_bindpw()
changed = False