2
# -*- coding: utf-8 -*-
3
# Author: Manuel de la Pena <manuel@canonical.com>
5
# Copyright 2011 Canonical Ltd.
7
# This program is free software: you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License version 3, as published
9
# by the Free Software Foundation.
11
# This program is distributed in the hope that it will be useful, but
12
# WITHOUT ANY WARRANTY; without even the implied warranties of
13
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
14
# PURPOSE. See the GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License along
17
# with this program. If not, see <http://www.gnu.org/licenses/>.
18
"""Start the sso service on a windows machine."""
20
# disable the name warning and complains about twisted
21
# pylint: disable=C0103, E1101
24
# pylint: disable=F0401
25
from win32api import GetUserNameEx
26
from win32con import NameSamCompatible
27
# pylint: enable=F0401
29
from threading import Thread
30
from twisted.internet import reactor
31
from twisted.spread.pb import PBServerFactory
33
from ubuntu_sso.main.windows import (
34
CredentialsManagement,
36
ListeningPortPipeService,
42
if __name__ == '__main__':
43
# check if the service is running by calling the named pipe, if not
45
port = get_service_port()
47
login = SSOLogin('ignored')
48
creds = SSOCredentials()
49
creds_management = CredentialsManagement(lambda:None, sys.exit)
50
root = UbuntuSSORoot(login, creds, creds_management)
51
listener = reactor.listenTCP(0, PBServerFactory(root))
52
username = GetUserNameEx(NameSamCompatible)
53
named_pipe_service = ListeningPortPipeService(username,
54
listener.getHost().port)
55
service_thread = Thread(name='Ubuntu SSO Port Broadcaster',
56
target=named_pipe_service.start)
57
service_thread.start()
60
print >> sys.stderr, 'The service is already running.'