2018-01-05 16:37:00 +01:00
|
|
|
# PAM interface in python, launches compair.py
|
|
|
|
|
|
|
|
# Import required modules
|
2018-01-05 01:59:44 +01:00
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
|
2018-01-17 21:28:10 +01:00
|
|
|
# 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(__file__) + "/config.ini")
|
|
|
|
|
2018-01-05 02:41:56 +01:00
|
|
|
def doAuth(pamh):
|
2018-01-05 16:37:00 +01:00
|
|
|
"""Start authentication in a seperate process"""
|
|
|
|
|
|
|
|
# Run compair as python3 subprocess to circumvent python version and import issues
|
2018-01-05 14:34:18 +01:00
|
|
|
status = subprocess.call(["python3", os.path.dirname(__file__) + "/compair.py", pamh.get_user()])
|
2018-01-05 01:59:44 +01:00
|
|
|
|
2018-01-05 16:37:00 +01:00
|
|
|
# Status 10 means we couldn't find any face models
|
2018-01-05 02:41:56 +01:00
|
|
|
if status == 10:
|
2018-01-17 21:28:10 +01:00
|
|
|
if config.get("core", "supress_unknown") != "true":
|
|
|
|
pamh.conversation(pamh.Message(pamh.PAM_ERROR_MSG, "No face model known"))
|
|
|
|
return pamh.PAM_USER_UNKNOWN
|
2018-01-05 16:37:00 +01:00
|
|
|
# Status 11 means we exceded the maximum retry count
|
2018-01-05 02:41:56 +01:00
|
|
|
if status == 11:
|
2018-01-17 21:28:10 +01:00
|
|
|
pamh.conversation(pamh.Message(pamh.PAM_ERROR_MSG, "Face detection timeout reached"))
|
|
|
|
return pamh.PAM_AUTH_ERR
|
2018-01-05 16:37:00 +01:00
|
|
|
# Status 0 is a successful exit
|
2018-01-05 01:59:44 +01:00
|
|
|
if status == 0:
|
2018-01-17 21:28:10 +01:00
|
|
|
if config.get("core", "no_confirmation") != "true":
|
|
|
|
pamh.conversation(pamh.Message(pamh.PAM_TEXT_INFO, "Identified face as " + pamh.get_user()))
|
2018-01-05 01:59:44 +01:00
|
|
|
return pamh.PAM_SUCCESS
|
|
|
|
|
2018-01-05 16:37:00 +01:00
|
|
|
# Otherwise, we can't discribe what happend but it wasn't successful
|
2018-01-17 21:28:10 +01:00
|
|
|
pamh.conversation(pamh.Message(pamh.PAM_ERROR_MSG, "Unknown error: " + str(status)))
|
2018-01-05 01:59:44 +01:00
|
|
|
return pamh.PAM_SYSTEM_ERR
|
2018-01-05 02:41:56 +01:00
|
|
|
|
|
|
|
def pam_sm_authenticate(pamh, flags, args):
|
2018-01-05 16:37:00 +01:00
|
|
|
"""Called by PAM when the user wants to authenticate, in sudo for example"""
|
2018-01-05 02:41:56 +01:00
|
|
|
return doAuth(pamh)
|
|
|
|
|
|
|
|
def pam_sm_open_session(pamh, flags, args):
|
2018-01-05 16:37:00 +01:00
|
|
|
"""Called when starting a session, such as su"""
|
2018-01-05 02:41:56 +01:00
|
|
|
return doAuth(pamh)
|
|
|
|
|
|
|
|
def pam_sm_close_session(pamh, flags, argv):
|
2018-01-05 16:37:00 +01:00
|
|
|
"""We don't need to clean anyting up at the end of a session, so return true"""
|
2018-01-05 02:41:56 +01:00
|
|
|
return pamh.PAM_SUCCESS
|
|
|
|
|
|
|
|
def pam_sm_setcred(pamh, flags, argv):
|
2018-01-05 16:37:00 +01:00
|
|
|
"""We don't need set any credentials, so return true"""
|
2018-01-05 02:41:56 +01:00
|
|
|
return pamh.PAM_SUCCESS
|