refresh-auth
changeset 3 7e659a6870de
parent 1 5bc7446cd2d1
child 4 dcd195f3e52c
equal deleted inserted replaced
2:a69f7bea408c 3:7e659a6870de
     1 #!/usr/bin/python
     1 #!/usr/bin/python
       
     2 
       
     3 # WARNING
       
     4 # This script completely destroys your .ssh/authorized_keys
       
     5 # file every time it is run
       
     6 # WARNING
     2 
     7 
     3 import os
     8 import os
     4 import os.path
     9 import os.path
     5 
    10 import re
     6 # THIS SCRIPT COMPLETELY DESTROYS YOUR .ssh/authorized_keys FILE EVERY TIME IT IS RUN
       
     7 
       
     8 #command='cd %s && ../path/bin/hg-ssh %s' % (repos, " ".join(projects))
       
     9 
    11 
    10 akeyfile = os.path.expanduser("~/.ssh/authorized_keys")
    12 akeyfile = os.path.expanduser("~/.ssh/authorized_keys")
    11 
    13 
       
    14 allowedchars = "A-Za-z0-9_.-"
       
    15 goodpathre = re.compile("([%s]+/)*[%s]+$" % (allowedchars, allowedchars))
    12 akeys = open(akeyfile + "_new", "w")
    16 akeys = open(akeyfile + "_new", "w")
    13 for root, dirs, files in os.walk("keys"):
    17 for root, dirs, files in os.walk("keys"):
    14     for fn in files:
    18     for fn in files:
    15         ffn = os.path.join(root, fn)
    19         ffn = os.path.join(root, fn)
    16         # FIXME: should ignore any path that contains dodgy characters
    20         if goodpathre.match(ffn) is None:
       
    21             # ignore any path that contains dodgy characters
       
    22             continue
    17         keyname = ffn[5:]
    23         keyname = ffn[5:]
       
    24         prefix=('command="%s",no-pty,no-port-forwarding,no-X11-forwarding,no-agent-forwarding'
       
    25             % ('./.hg-ssh-wrapper %s' % keyname))
    18         kf = open(ffn)
    26         kf = open(ffn)
    19         try:
    27         try:
    20             for l in kf:
    28             for l in kf:
    21                 command='./.hg-ssh-wrapper %s' % keyname
       
    22                 prefix=('command="%s",no-pty,no-port-forwarding,no-X11-forwarding,no-agent-forwarding'
       
    23                     % command)
       
    24                 #prefix='no-port-forwarding,no-X11-forwarding,no-agent-forwarding'
    29                 #prefix='no-port-forwarding,no-X11-forwarding,no-agent-forwarding'
    25                 akeys.write("%s %s\n" % (prefix, l.strip()))
    30                 akeys.write("%s %s\n" % (prefix, l.strip()))
    26         finally:
    31         finally:
    27             kf.close()
    32             kf.close()
    28 
    33