File: authcli.py

package info (click to toggle)
synce-sync-engine 0.11.1-2
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 996 kB
  • ctags: 923
  • sloc: python: 8,586; xml: 949; makefile: 51; sh: 7
file content (62 lines) | stat: -rwxr-xr-x 1,417 bytes parent folder | download
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
###############################################################################
# authgui.py
#
# Helper tool for authorization in sync-engine. Run as a stand-alone unit - it
# is not bound to sync-engine in case gtk is not available
#
###############################################################################

import dbus
import dbus.glib
import sys
import getpass

ODCCM_DEVICE_PASSWORD_FLAG_SET     = 1
ODCCM_DEVICE_PASSWORD_FLAG_PROVIDE = 2

# 
# AuthCli
#
# Application class.

class AuthCli:
	
	def __init__(self,objpath):

		bus = dbus.SystemBus()
		self.deviceObject = bus.get_object("org.synce.odccm", objpath)
		self.device = dbus.Interface(self.deviceObject, "org.synce.odccm.Device")
		self.deviceName = self.device.GetName()
	
	def Authorize(self):
		
		# no need to run if for some reason we are called on a 
		# device that is not blocked
		
		flags = self.device.GetPasswordFlags()
		rc=1
		if flags & ODCCM_DEVICE_PASSWORD_FLAG_PROVIDE:
			
			print
			print "Authorization required for device %s." % self.deviceName
			
			rc = 0
			cnt = 3
			while not rc and cnt:
				rc = self.device.ProvidePassword(getpass.getpass("Password:"))
				cnt -= 1
		return rc

#
# main
#
# Get the objpath from the command line, then authorize

if len(sys.argv) > 1:
	devobjpath = sys.argv[1]
	app = AuthCli(devobjpath)
	sys.exit(app.Authorize())
else:
	sys.exit(0)