##// END OF EJS Templates
factotum: add man reference to help output
Steven Stallion -
r16582:cbb916e2 stable
parent child Browse files
Show More
@@ -1,120 +1,120 b''
1 # factotum.py - Plan 9 factotum integration for Mercurial
1 # factotum.py - Plan 9 factotum integration for Mercurial
2 #
2 #
3 # Copyright (C) 2012 Steven Stallion <sstallion@gmail.com>
3 # Copyright (C) 2012 Steven Stallion <sstallion@gmail.com>
4 #
4 #
5 # This program is free software; you can redistribute it and/or modify it
5 # This program is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by the
6 # under the terms of the GNU General Public License as published by the
7 # Free Software Foundation; either version 2 of the License, or (at your
7 # Free Software Foundation; either version 2 of the License, or (at your
8 # option) any later version.
8 # option) any later version.
9 #
9 #
10 # This program is distributed in the hope that it will be useful, but
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
13 # Public License for more details.
13 # Public License for more details.
14 #
14 #
15 # You should have received a copy of the GNU General Public License along
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
18
19 '''http authentication with factotum
19 '''http authentication with factotum
20
20
21 This extension allows the factotum facility on Plan 9 from Bell Labs platforms
21 This extension allows the factotum(4) facility on Plan 9 from Bell Labs
22 to provide authentication information for HTTP access. Configuration entries
22 platforms to provide authentication information for HTTP access. Configuration
23 specified in the auth section as well as authentication information provided
23 entries specified in the auth section as well as authentication information
24 in the repository URL are fully supported. If no prefix is specified, a value
24 provided in the repository URL are fully supported. If no prefix is specified,
25 of ``*`` will be assumed.
25 a value of "*" will be assumed.
26
26
27 By default, keys are specified as::
27 By default, keys are specified as::
28
28
29 proto=pass service=hg prefix=<prefix> user=<username> !password=<password>
29 proto=pass service=hg prefix=<prefix> user=<username> !password=<password>
30
30
31 If the factotum extension is unable to read the required key, one will be
31 If the factotum extension is unable to read the required key, one will be
32 requested interactively.
32 requested interactively.
33
33
34 A configuration section is available to customize runtime behavior. By
34 A configuration section is available to customize runtime behavior. By
35 default, these entries are::
35 default, these entries are::
36
36
37 [factotum]
37 [factotum]
38 executable = /bin/auth/factotum
38 executable = /bin/auth/factotum
39 mountpoint = /mnt/factotum
39 mountpoint = /mnt/factotum
40 service = hg
40 service = hg
41
41
42 The executable entry defines the full path to the factotum binary. The
42 The executable entry defines the full path to the factotum binary. The
43 mountpoint entry defines the path to the factotum file service. Lastly, the
43 mountpoint entry defines the path to the factotum file service. Lastly, the
44 service entry controls the service name used when reading keys.
44 service entry controls the service name used when reading keys.
45
45
46 '''
46 '''
47
47
48 from mercurial.i18n import _
48 from mercurial.i18n import _
49 from mercurial.url import passwordmgr
49 from mercurial.url import passwordmgr
50 from mercurial import httpconnection, urllib2, util
50 from mercurial import httpconnection, urllib2, util
51 import os
51 import os
52
52
53 ERRMAX = 128
53 ERRMAX = 128
54
54
55 def auth_getkey(self, params):
55 def auth_getkey(self, params):
56 if not self.ui.interactive():
56 if not self.ui.interactive():
57 raise util.Abort(_('factotum not interactive'))
57 raise util.Abort(_('factotum not interactive'))
58 if 'user=' not in params:
58 if 'user=' not in params:
59 params = '%s user?' % params
59 params = '%s user?' % params
60 params = '%s !password?' % params
60 params = '%s !password?' % params
61 os.system("%s -g '%s'" % (_executable, params))
61 os.system("%s -g '%s'" % (_executable, params))
62
62
63 def auth_getuserpasswd(self, getkey, params):
63 def auth_getuserpasswd(self, getkey, params):
64 params = 'proto=pass %s' % params
64 params = 'proto=pass %s' % params
65 while True:
65 while True:
66 fd = os.open('%s/rpc' % _mountpoint, os.O_RDWR)
66 fd = os.open('%s/rpc' % _mountpoint, os.O_RDWR)
67 try:
67 try:
68 try:
68 try:
69 os.write(fd, 'start %s' % params)
69 os.write(fd, 'start %s' % params)
70 l = os.read(fd, ERRMAX).split()
70 l = os.read(fd, ERRMAX).split()
71 if l[0] == 'ok':
71 if l[0] == 'ok':
72 os.write(fd, 'read')
72 os.write(fd, 'read')
73 l = os.read(fd, ERRMAX).split()
73 l = os.read(fd, ERRMAX).split()
74 if l[0] == 'ok':
74 if l[0] == 'ok':
75 return l[1:]
75 return l[1:]
76 except (OSError, IOError):
76 except (OSError, IOError):
77 raise util.Abort(_('factotum not responding'))
77 raise util.Abort(_('factotum not responding'))
78 finally:
78 finally:
79 os.close(fd)
79 os.close(fd)
80 getkey(self, params)
80 getkey(self, params)
81
81
82 def monkeypatch_method(cls):
82 def monkeypatch_method(cls):
83 def decorator(func):
83 def decorator(func):
84 setattr(cls, func.__name__, func)
84 setattr(cls, func.__name__, func)
85 return func
85 return func
86 return decorator
86 return decorator
87
87
88 @monkeypatch_method(passwordmgr)
88 @monkeypatch_method(passwordmgr)
89 def find_user_password(self, realm, authuri):
89 def find_user_password(self, realm, authuri):
90 user, passwd = urllib2.HTTPPasswordMgrWithDefaultRealm.find_user_password(
90 user, passwd = urllib2.HTTPPasswordMgrWithDefaultRealm.find_user_password(
91 self, realm, authuri)
91 self, realm, authuri)
92 if user and passwd:
92 if user and passwd:
93 self._writedebug(user, passwd)
93 self._writedebug(user, passwd)
94 return (user, passwd)
94 return (user, passwd)
95
95
96 prefix = ''
96 prefix = ''
97 res = httpconnection.readauthforuri(self.ui, authuri, user)
97 res = httpconnection.readauthforuri(self.ui, authuri, user)
98 if res:
98 if res:
99 _, auth = res
99 _, auth = res
100 prefix = auth.get('prefix')
100 prefix = auth.get('prefix')
101 user, passwd = auth.get('username'), auth.get('password')
101 user, passwd = auth.get('username'), auth.get('password')
102 if not user or not passwd:
102 if not user or not passwd:
103 if not prefix:
103 if not prefix:
104 prefix = '*'
104 prefix = '*'
105 params = 'service=%s prefix=%s' % (_service, prefix)
105 params = 'service=%s prefix=%s' % (_service, prefix)
106 if user:
106 if user:
107 params = '%s user=%s' % (params, user)
107 params = '%s user=%s' % (params, user)
108 user, passwd = auth_getuserpasswd(self, auth_getkey, params)
108 user, passwd = auth_getuserpasswd(self, auth_getkey, params)
109
109
110 self.add_password(realm, authuri, user, passwd)
110 self.add_password(realm, authuri, user, passwd)
111 self._writedebug(user, passwd)
111 self._writedebug(user, passwd)
112 return (user, passwd)
112 return (user, passwd)
113
113
114 def uisetup(ui):
114 def uisetup(ui):
115 global _executable
115 global _executable
116 _executable = ui.config('factotum', 'executable', '/bin/auth/factotum')
116 _executable = ui.config('factotum', 'executable', '/bin/auth/factotum')
117 global _mountpoint
117 global _mountpoint
118 _mountpoint = ui.config('factotum', 'mountpoint', '/mnt/factotum')
118 _mountpoint = ui.config('factotum', 'mountpoint', '/mnt/factotum')
119 global _service
119 global _service
120 _service = ui.config('factotum', 'service', 'hg')
120 _service = ui.config('factotum', 'service', 'hg')
General Comments 0
You need to be logged in to leave comments. Login now