~mandel/ubuntu-sso-client/ping_url_issues_windows

« back to all changes in this revision

Viewing changes to bin/windows-ubuntu-sso-login

Fixes lp:742583

This branch adds two fundamental things:

1. A namedpipe server that will return in which port is the daemon currently running.
2. A scrip that will start the daemon if not already running that will start the named pipe service in a separated thread.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
# -*- coding: utf-8 -*-
 
3
# Author: Manuel de la Pena <manuel@canonical.com>
 
4
#
 
5
# Copyright 2011 Canonical Ltd.
 
6
#
 
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.
 
10
#
 
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.
 
15
#
 
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."""
 
19
 
 
20
# disable the name warning and complains about twisted
 
21
# pylint: disable=C0103, E1101
 
22
import sys
 
23
 
 
24
# pylint: disable=F0401
 
25
from win32api import GetUserNameEx
 
26
from win32con import NameSamCompatible
 
27
# pylint: enable=F0401
 
28
 
 
29
from threading import Thread
 
30
from twisted.internet import reactor
 
31
from twisted.spread.pb import PBServerFactory
 
32
 
 
33
from ubuntu_sso.main.windows import (
 
34
    CredentialsManagement,
 
35
    get_service_port,
 
36
    ListeningPortPipeService,
 
37
    SSOCredentials,
 
38
    SSOLogin,
 
39
    UbuntuSSORoot)
 
40
 
 
41
 
 
42
if __name__ == '__main__':
 
43
    # check if the service is running by calling the named pipe, if not
 
44
    # start it.
 
45
    port = get_service_port()
 
46
    if port is None:
 
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()
 
58
        reactor.run()
 
59
    else:
 
60
        print >> sys.stderr, 'The service is already running.'
 
61
        sys.exit(1)