Revision 8d766971

b/vncauthproxy/proxy.py
72 72
import random
73 73
import daemon.runner
74 74
import hashlib
75
import re
75 76

  
76 77
import rfb
77 78

  
......
617 618

  
618 619

  
619 620
def parse_auth_file(auth_file):
620
    supported_ciphers = ('cleartext', 'HA1')
621
    supported_ciphers = ('cleartext', 'HA1', None)
622
    regexp = re.compile(r'^\s*(?P<user>\S+)\s+({(?P<cipher>\S+)})?'
623
                         '(?P<pass>\S+)\s*$')
621 624

  
622 625
    users = {}
623 626
    try:
624 627
        with open(auth_file) as f:
625
            lines = [l.strip().split() for l in f.readlines()]
628
            lines = [l.strip() for l in f.readlines()]
626 629

  
627 630
            for line in lines:
628
                if not line or line[0][0] == '#':
631
                if not line or line.startswith('#'):
629 632
                    continue
630 633

  
631
                if len(line) != 2:
632
                    raise InternalError("Invaild user entry in auth file")
634
                m = regexp.match(line)
635
                if not m:
636
                    raise InternalError("Invaild entry in auth file: %s"
637
                                        % line)
633 638

  
634
                user = line[0]
635
                password = line[1]
639
                user = m.group('user')
640
                cipher = m.group('cipher')
641
                if cipher not in supported_ciphers:
642
                    raise InternalError("Unsupported cipher in auth file: "
643
                                        "%s" % line)
636 644

  
637
                split_password = ('{cleartext}', password)
638
                if password[0] == '{':
639
                    split_password = password[1:].split('}', 2)
640
                    if len(split_password) != 2 or not split_password[1] \
641
                            or split_password[0] not in supported_ciphers:
642
                        raise InternalError("Invalid password format "
643
                                            "in auth file")
645
                password = (cipher, m.group('pass'))
644 646

  
645 647
                if user in users:
646 648
                    raise InternalError("Duplicate user entry in auth file")
647 649

  
648
                users[user] = split_password
650
                users[user] = password
649 651
    except IOError as err:
650 652
        logger.error("Couldn't read auth file")
651 653
        raise InternalError(err)

Also available in: Unified diff