werty1st
11/14/2014 - 4:41 PM

use android device to authenticate

use android device to authenticate

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()