Package flumotion :: Package component :: Package bouncers :: Module htpasswdcrypt
[hide private]

Source Code for Module flumotion.component.bouncers.htpasswdcrypt

 1  # -*- Mode: Python; test-case-name: flumotion.test.test_htpasswdcrypt -*- 
 2  # vi:si:et:sw=4:sts=4:ts=4 
 3   
 4  # Flumotion - a streaming media server 
 5  # Copyright (C) 2004,2005,2006,2007,2008,2009 Fluendo, S.L. 
 6  # Copyright (C) 2010,2011 Flumotion Services, S.A. 
 7  # All rights reserved. 
 8  # 
 9  # This file may be distributed and/or modified under the terms of 
10  # the GNU Lesser General Public License version 2.1 as published by 
11  # the Free Software Foundation. 
12  # This file is distributed without any warranty; without even the implied 
13  # warranty of merchantability or fitness for a particular purpose. 
14  # See "LICENSE.LGPL" in the source distribution for more information. 
15  # 
16  # Headers in this file shall remain intact. 
17   
18  """ 
19  an htpasswd-backed bouncer with crypt passwords 
20  """ 
21   
22  import random 
23   
24  from twisted.internet import defer 
25   
26  from flumotion.common import keycards, log, errors 
27  from flumotion.component.bouncers import component as bcomponent 
28  from flumotion.twisted import credentials, checkers 
29   
30  __all__ = ['HTPasswdCrypt'] 
31  __version__ = "$Rev$" 
32   
33   
34 -class HTPasswdCrypt(bcomponent.ChallengeResponseBouncer):
35 36 logCategory = 'htpasswdcrypt' 37 # challenger type first, because it's more secure thus preferable 38 keycardClasses = (keycards.KeycardUACPCC, keycards.KeycardUACPP) 39 challengeResponseClasses = (keycards.KeycardUACPCC, ) 40
41 - def do_setup(self):
42 conf = self.config 43 44 # we need either a filename or data 45 filename = None 46 data = None 47 props = conf['properties'] 48 if 'filename' in props: 49 filename = props['filename'] 50 self.debug('using file %s for passwords', filename) 51 elif 'data' in props: 52 data = props['data'] 53 self.debug('using in-line data for passwords') 54 else: 55 return defer.fail(errors.ConfigError( 56 'HTPasswdCrypt needs either a <data> or <filename> entry')) 57 # FIXME: generalize to a start method, possibly linked to mood 58 if filename: 59 try: 60 lines = open(filename).readlines() 61 except IOError, e: 62 return defer.fail(errors.ConfigError(str(e))) 63 else: 64 lines = data.split("\n") 65 66 self.setChecker(checkers.CryptChecker()) 67 for line in lines: 68 if not ':' in line: 69 continue 70 # when coming from a file, it ends in \n, so strip. 71 # for data, we already splitted, so no \n, but strip is fine. 72 name, cryptPassword = line.strip().split(':') 73 self.addUser(name, cryptPassword[:2], cryptPassword) 74 75 self.debug('parsed %s, %d lines' % (filename or '<memory>', 76 len(lines))) 77 78 return defer.succeed(None)
79