-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpam.py
More file actions
39 lines (32 loc) · 1.09 KB
/
pam.py
File metadata and controls
39 lines (32 loc) · 1.09 KB
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
# PAM interface in python
# sudo apt-get install libpam-python bluetooth libbluetooth-dev gobject
# sudo pip install pybluez
# Import required modules
import subprocess
import sys
import os
import bluetooth, time
def doAuth(pamh):
"""Do Authentication here"""
search_time = 10
# Hardcoded the data for now
addr = "Bluetooth_Device_ID_Here"
state = bluetooth.lookup_name(addr, timeout=20)
services = bluetooth.find_service(address=addr)
if state == None and services == []:
return pamh.PAM_SYSTEM_ERR
else:
return pamh.PAM_SUCCESS
return pamh.PAM_SYSTEM_ERR
def pam_sm_authenticate(pamh, flags, args):
"""Called by PAM when the user wants to authenticate, in sudo for example"""
return doAuth(pamh)
def pam_sm_open_session(pamh, flags, args):
"""Called when starting a session, such as su"""
return doAuth(pamh)
def pam_sm_close_session(pamh, flags, argv):
"""We don't need to clean anyting up at the end of a session, so return true"""
return pamh.PAM_SUCCESS
def pam_sm_setcred(pamh, flags, argv):
"""We don't need set any credentials, so return true"""
return pamh.PAM_SUCCESS