Unbreak getting password from UI

Commit 9239a2d326 broke getting the password from the UI. This
unbreaks the change and adds some extended documentation and cleanups in
the functino en-passent.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
Sebastian 2010-12-13 11:45:42 -06:00 committed by Nicolas Sebrecht
parent 62712cbe15
commit b853b58578
2 changed files with 23 additions and 9 deletions

View File

@ -176,7 +176,7 @@ class IMAPServer:
challenge = response.strip()
ui.debug('imap', 'md5handler: got challenge %s' % challenge)
passwd = self.repos.getpassword()
passwd = self.getpassword()
retval = self.username + ' ' + hmac.new(passwd, challenge).hexdigest()
ui.debug('imap', 'md5handler: returning %s' % retval)
return retval
@ -184,7 +184,7 @@ class IMAPServer:
def plainauth(self, imapobj):
UIBase.getglobalui().debug('imap',
'Attempting plain authentication')
imapobj.login(self.username, self.repos.getpassword())
imapobj.login(self.username, self.getpassword())
def gssauth(self, response):
data = base64.b64encode(response)

View File

@ -152,24 +152,35 @@ class IMAPRepository(BaseRepository):
return self.getconfboolean('expunge', 1)
def getpassword(self):
passwd = None
localeval = self.localeval
"""Return the IMAP password for this repository.
if self.config.has_option(self.getsection(), 'remotepasseval'):
passwd = self.getconf('remotepasseval')
It tries to get passwords in the following order:
1. evaluate Repository 'remotepasseval'
2. read password from Repository 'remotepass'
3. read password from file specified in Repository 'remotepassfile'
4. read password from ~/.netrc
5. read password from /etc/netrc
On success we return the password.
If all strategies fail we return None.
"""
# 1. evaluate Repository 'remotepasseval'
passwd = self.getconf('remotepasseval', None)
if passwd != None:
return localeval.eval(passwd)
return self.localeval.eval(passwd)
# 2. read password from Repository 'remotepass'
password = self.getconf('remotepass', None)
if password != None:
return password
# 3. read password from file specified in Repository 'remotepassfile'
passfile = self.getconf('remotepassfile', None)
if passfile != None:
fd = open(os.path.expanduser(passfile))
password = fd.readline().strip()
fd.close()
return password
# 4. read password from ~/.netrc
try:
netrcentry = netrc.netrc().authenticators(self.gethost())
except IOError, inst:
@ -180,6 +191,7 @@ class IMAPRepository(BaseRepository):
user = self.getconf('remoteuser')
if user == None or user == netrcentry[0]:
return netrcentry[2]
# 5. read password from /etc/netrc
try:
netrcentry = netrc.netrc('/etc/netrc').authenticators(self.gethost())
except IOError, inst:
@ -190,8 +202,10 @@ class IMAPRepository(BaseRepository):
user = self.getconf('remoteuser')
if user == None or user == netrcentry[0]:
return netrcentry[2]
# no strategy yielded a password!
return None
def getfolder(self, foldername):
return self.getfoldertype()(self.imapserver, foldername,
self.nametrans(foldername),