Created
November 14, 2014 16:41
-
-
Save werty1st/c7fcc5a5363bb4ddc8cd to your computer and use it in GitHub Desktop.
use android device to authenticate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
common_auth: | |
auth sufficient pam_exec.so quiet /root/pam.py | |
pam.py: | |
#!/usr/bin/python2.7 | |
from subprocess import Popen, PIPE | |
import re | |
import string | |
from array import array | |
def main(): | |
devices = getdevices() | |
allowed = getallowed() | |
#print "found", devices | |
#print "allow", allowed | |
rt = compare(devices, allowed) | |
exit(rt) | |
def compare(d,a): | |
f = list(set(d) & set(a)) | |
if ( len(f) > 0 ): | |
#print "ok" | |
return 0 | |
else: | |
#print "error" | |
return 9 | |
def getallowed(): | |
return ["XXX"]; | |
def getdevices(): | |
#List of devices attached | |
p = Popen(['adb', 'devices'], stdin=PIPE, stdout=PIPE, stderr=PIPE) | |
output, err = p.communicate() | |
rc = p.returncode | |
p = re.compile( '^List of devices attached\s\n') | |
devices = p.sub("", output) | |
p = re.compile( '\sdevice\s\n') | |
devices = p.sub("", devices) | |
devices = string.split(devices, '\n') | |
return devices | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment