/
extauth.py
executable file
·58 lines (52 loc) · 1.44 KB
/
extauth.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
"""extauth dummy script for ejabberd testing."""
import sys
import struct
def read_from_stdin(read_bytes):
"""Read buffer from standard input."""
if hasattr(sys.stdin, 'buffer'):
return sys.stdin.buffer.read(read_bytes)
return sys.stdin.read(read_bytes)
def read():
"""Read input and process the command."""
(pkt_size,) = struct.unpack('>H', read_from_stdin(2))
pkt = sys.stdin.read(pkt_size)
cmd = pkt.split(':')[0]
if cmd == 'auth':
user, _, _ = pkt.split(':', 3)[1:]
if user == "wrong":
write(False)
else:
write(True)
elif cmd == 'isuser':
user, _ = pkt.split(':', 2)[1:]
if user == "wrong":
write(False)
else:
write(True)
elif cmd == 'setpass':
user, _, _ = pkt.split(':', 3)[1:]
write(True)
elif cmd == 'tryregister':
user, _, _ = pkt.split(':', 3)[1:]
write(True)
elif cmd == 'removeuser':
user, _ = pkt.split(':', 2)[1:]
write(True)
elif cmd == 'removeuser3':
user, _, _ = pkt.split(':', 3)[1:]
write(True)
else:
write(False)
read()
def write(result):
"""write result to standard output."""
if result:
sys.stdout.write('\x00\x02\x00\x01')
else:
sys.stdout.write('\x00\x02\x00\x00')
sys.stdout.flush()
if __name__ == "__main__":
try:
read()
except struct.error:
pass