]> git.nothing2do.fr Git - get-hack-src.git/commitdiff
Additional fixes to pysudo
authorallfro <ndouba@gmail.com>
Wed, 20 Mar 2013 00:52:47 +0000 (20:52 -0400)
committerallfro <ndouba@gmail.com>
Wed, 20 Mar 2013 00:52:47 +0000 (20:52 -0400)
src/canari/commands/run_transform.py
src/scripts/pysudo

index 86963112d2e6cc1368025579ea05af6e699c4b2e..d063b37ee6ae0b7098939bab9a55f088fc8a8e5c 100644 (file)
@@ -2,12 +2,12 @@
 
 import os
 import sys
+from traceback import format_exc
 
 from argparse import ArgumentParser
-from traceback import format_exc
 
 from canari.maltego.message import MaltegoException, MaltegoTransformResponseMessage, UIMessage
-from common import cmd_name, import_transform, fix_binpath, get_bin_dir, sudo
+from common import cmd_name, import_transform, fix_binpath, sudo
 from canari.maltego.utils import onterminate, parseargs, croak, message
 from canari.config import config
 
@@ -66,7 +66,6 @@ def run(args):
     [transform, params, value, fields] = parseargs(['canari %s' % cmd_name(__name__)] + args)
 
     m = None
-    pysudo = os.path.join(get_bin_dir(), 'pysudo')
 
     fix_binpath(config['default/path'])
     try:
index 3954341c2b2e1e6c3f4507d4bcc58a68bcba4b42..7185a7e70601a4c1f301e87dc73c552d11ee575e 100755 (executable)
@@ -24,25 +24,42 @@ def main():
         print 'usage: %s <command>' % sys.argv[0]
         exit(-1)
 
-
+    # Let's try and run it right away and see what happens
     p = subprocess.Popen(['sudo', '-S'] + sys.argv[1:], stdin=subprocess.PIPE, stderr=subprocess.PIPE)
     p.communicate()
 
+    # It ran!
     if not p.returncode:
         exit(0)
 
+    # It didn't :( - let's lock this region now to avoid having multiple password boxes pop-up
     l = fmutex('pysudo.%s.lock' % getpass.getuser())
+
+    # Try running it again (maybe another process authenticated... why ask for a password again?)
+    p = subprocess.Popen(['sudo', '-S'] + sys.argv[1:], stdin=subprocess.PIPE, stderr=subprocess.PIPE)
+    p.communicate()
+
+    if not p.returncode:
+        l.unlock()
+        exit(0)
+
+    # No we really need to ask for a password :(
     for i in range(0, 3):
         password = passwordbox('Please enter your password.', 'sudo', '')
         if password is None:
             exit(1)
+
+        # Try it out with a password now!
         p = subprocess.Popen(['sudo', '-S', 'true'], stdin=subprocess.PIPE, stderr=subprocess.PIPE)
         p.communicate(input='%s\n' % password)
+
+        # Did it work? Yes: let's do it!
         if not p.returncode:
             l.unlock()
             p = subprocess.Popen(['sudo', '-S'] + sys.argv[1:])
             p.communicate(input='%s\n' % password)
             exit(p.returncode)
+
     exit(2)
 
 if __name__ == '__main__':