Skip to content

Instantly share code, notes, and snippets.

@codekidX
Last active January 28, 2019 13:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codekidX/37455098e70f6d71a9cbbea3871f5fa1 to your computer and use it in GitHub Desktop.
Save codekidX/37455098e70f6d71a9cbbea3871f5fa1 to your computer and use it in GitHub Desktop.
Example of external authentication script for ejabberd server
#!/usr/bin/env python
import sys
import logging
from struct import pack, unpack
logging.basicConfig(level=logging.INFO,
format='%(asctime)s %(levelname)s %(message)s',
filename='/var/log/ejabberd/extauth.log',
filemode='a')
def input_from_ejabberd():
iplen = sys.stdin.read(2)
(count,) = unpack('>h', iplen)
input = sys.stdin.read(iplen)
logging.info("Incoming input from ejabberd: %s", input)
return input
def done(is_authenticated=False):
result = 0
if is_authenticated:
result = 1
op = pack('>hh', 2, result)
sys.stdout.write(op)
sys.stdout.flush()
while True:
user_pass = input_from_ejabberd()
if len(user_pass) > 1:
done(True)
else:
done(False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment