Welcome to mirror list, hosted at ThFree Co, Russian Federation.

testauth.py « scripts - github.com/mumble-voip/mumble.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a49a59a7bc74a5dea6cd9fd0c89c5f7e4bd6e886 (plain)
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env python
# -*- coding: utf-8
import Ice, sys
from M2Crypto import X509;
Ice.loadSlice('Murmur.ice')
import Murmur

class ServerAuthenticatorI(Murmur.ServerUpdatingAuthenticator):
    def __init__(self, server, adapter):
      self.server = server

    def authenticate(self, name, pw, certlist, certhash, strong, current=None):
      print certhash, strong
      for cert in certlist:
        cert = X509.load_cert_der_string(cert)
        print cert.get_subject(), "issued by", cert.get_issuer()
      if (name == "One"):
        if (pw == "Magic"):
          return (1, "One", None)
        else:
          return (-1, None, None)
      elif (name == "Two"):
        if (pw == "Mushroom"):
          return (2, "twO", None)
        else:
          return (-1, None, None)
      return (-2, None, None)

    def getInfo(self, id, current=None):
      print "getInfo ", id
      name = self.idToName(id);
      if (name == None):
        return (False, {})
      map = {}
      map[Murmur.UserInfo.UserName]=name
      return (True, map)

    def nameToId(self, name, current=None):
      if (name == "One"):
        return 1
      elif (name == "Twoer"):
        return 2
      else:
        return -2;

    def idToName(self, id, current=None):
      if (id == 1):
        return "One"
      elif (id == 2):
        return "Two"
      else:
        return None

    def idToTexture(self, id, current=None):
      return None

    # The expanded methods from UpdatingAuthenticator. We only implement a subset for this example, but
    # a valid implementation has to define all of them
    def registerUser(self, name, current=None):
      print "Someone tried to register " + name[Murmur.UserInfo.UserName]
      return -2

    def unregisterUser(self, id, current=None):
      print "Unregister ", id
      return -2

    def getRegistration(self, id, current=None):
      return (-2, None, None)
    
    def setInfo(self, id, info, current=None):
      print "Set", id, info
      return -1

if __name__ == "__main__":
    global contextR

    print "Creating callbacks...",
    ice = Ice.initialize(sys.argv)

    meta = Murmur.MetaPrx.checkedCast(ice.stringToProxy('Meta:tcp -h 127.0.0.1 -p 6502'))

    adapter = ice.createObjectAdapterWithEndpoints("Callback.Client", "tcp -h 127.0.0.1")
    adapter.activate()

    for server in meta.getBootedServers():
      serverR=Murmur.ServerUpdatingAuthenticatorPrx.uncheckedCast(adapter.addWithUUID(ServerAuthenticatorI(server, adapter)))
      server.setAuthenticator(serverR)
#      server.registerUser("TestUser")

    print "Done"
    
    map = {};
    map[Murmur.UserInfo.UserName] = 'TestUser';

    for server in meta.getBootedServers():
      ids= server.getUserIds(["TestUser"])
      for name,id in ids.iteritems():
        if (id > 0):
          print "Will unregister ", id
          server.unregisterUser(id)
      server.registerUser(map)

    print 'Script running (press CTRL-C to abort)';
    try:
        ice.waitForShutdown()
    except KeyboardInterrupt:
        print 'CTRL-C caught, aborting'

    meta.removeCallback(metaR)
    ice.shutdown()
    print "Goodbye"