-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpam.py
executable file
·58 lines (42 loc) · 1.56 KB
/
pam.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# PAM interface in python, launches compare.py
# Import required modules
import subprocess
import sys
import os
import glob
# pam-python is running python 2, so we use the old module here
import ConfigParser
# Read config from disk
config = ConfigParser.ConfigParser()
config.read(os.path.dirname(os.path.abspath(__file__)) + "/config.ini")
def doAuth(pamh):
"""Starts authentication in a seperate process"""
print('called third eye')
# Abort if third_eye is disabled
if config.getboolean("core", "disabled"):
sys.exit(0)
if "SSH_CONNECTION" in os.environ or "SSH_CLIENT" in os.environ or "SSHD_OPTS" in os.environ:
sys.exit(0)
pamh.conversation(pamh.Message(pamh.PAM_TEXT_INFO, "Attempting a face detection"))
# Run compare as python3 subprocess to circumvent python version and import issues
status = subprocess.call(["/usr/bin/python3", os.path.dirname(os.path.abspath(__file__)) + "/new_compare.py", pamh.get_user()])
# Status 12 means we aborted
if status == 12:
return pamh.PAM_AUTH_ERR
# Status 0 is a successful exit
elif status == 0:
# Show the success message if it isn't suppressed
pamh.conversation(pamh.Message(pamh.PAM_TEXT_INFO, "Identified face as " + pamh.get_user()))
return pamh.PAM_SUCCESS
#unknown err
return pamh.PAM_SYSTEM_ERR
def pam_sm_authenticate(pamh, flags, args):
#main function called by pam
return doAuth(pamh)
def pam_sm_open_session(pamh, flags, args):
#for su
return doAuth(pamh)
def pam_sm_close_session(pamh, flags, argv):
return pamh.PAM_SUCCESS
def pam_sm_setcred(pamh, flags, argv):
return pamh.PAM_SUCCESS