server/sources/native.py
changeset 10074 ab956b780d4e
parent 10000 4352b7ccde04
parent 10061 ecbfec2da8a2
child 10086 98bc2ca1a816
equal deleted inserted replaced
10068:1b0cb3c6c95e 10074:ab956b780d4e
  1503                 raise AuthenticationError('bad password')
  1503                 raise AuthenticationError('bad password')
  1504             # passwords are stored using the Bytes type, so we get a StringIO
  1504             # passwords are stored using the Bytes type, so we get a StringIO
  1505             args['pwd'] = Binary(crypt_password(password, pwd.getvalue()))
  1505             args['pwd'] = Binary(crypt_password(password, pwd.getvalue()))
  1506         # get eid from login and (crypted) password
  1506         # get eid from login and (crypted) password
  1507         rset = self.source.syntax_tree_search(cnx, self._auth_rqlst, args)
  1507         rset = self.source.syntax_tree_search(cnx, self._auth_rqlst, args)
       
  1508         pwd = args['pwd']
  1508         try:
  1509         try:
  1509             user = rset[0][0]
  1510             user = rset[0][0]
  1510             # If the stored hash uses a deprecated scheme (e.g. DES or MD5 used
  1511             # If the stored hash uses a deprecated scheme (e.g. DES or MD5 used
  1511             # before 3.14.7), update with a fresh one
  1512             # before 3.14.7), update with a fresh one
  1512             if pwd.getvalue():
  1513             if pwd is not None and pwd.getvalue():
  1513                 verify, newhash = verify_and_update(password, pwd.getvalue())
  1514                 verify, newhash = verify_and_update(password, pwd.getvalue())
  1514                 if not verify: # should not happen, but...
  1515                 if not verify: # should not happen, but...
  1515                     raise AuthenticationError('bad password')
  1516                     raise AuthenticationError('bad password')
  1516                 if newhash:
  1517                 if newhash:
  1517                     cnx.system_sql("UPDATE %s SET %s=%%(newhash)s WHERE %s=%%(login)s" % (
  1518                     cnx.system_sql("UPDATE %s SET %s=%%(newhash)s WHERE %s=%%(login)s" % (
  1562     * a list of rows (as tuples with one element per column)
  1563     * a list of rows (as tuples with one element per column)
  1563 
  1564 
  1564     Tables are saved in chunks in different files in order to prevent
  1565     Tables are saved in chunks in different files in order to prevent
  1565     a too high memory consumption.
  1566     a too high memory consumption.
  1566     """
  1567     """
       
  1568     blocksize = 100
       
  1569 
  1567     def __init__(self, source):
  1570     def __init__(self, source):
  1568         """
  1571         """
  1569         :param: source an instance of the system source
  1572         :param: source an instance of the system source
  1570         """
  1573         """
  1571         self._source = source
  1574         self._source = source
  1645         self.cursor.execute(nb_lines_sql)
  1648         self.cursor.execute(nb_lines_sql)
  1646         rowcount = self.cursor.fetchone()[0]
  1649         rowcount = self.cursor.fetchone()[0]
  1647         sql = 'SELECT * FROM %s' % table
  1650         sql = 'SELECT * FROM %s' % table
  1648         columns, rows_iterator = self._get_cols_and_rows(sql)
  1651         columns, rows_iterator = self._get_cols_and_rows(sql)
  1649         self.logger.info('number of rows: %d', rowcount)
  1652         self.logger.info('number of rows: %d', rowcount)
  1650         if table.startswith('cw_'): # entities
  1653         blocksize = self.blocksize
  1651             blocksize = 2000
       
  1652         else: # relations and metadata
       
  1653             blocksize = 10000
       
  1654         if rowcount > 0:
  1654         if rowcount > 0:
  1655             for i, start in enumerate(xrange(0, rowcount, blocksize)):
  1655             for i, start in enumerate(xrange(0, rowcount, blocksize)):
  1656                 rows = list(itertools.islice(rows_iterator, blocksize))
  1656                 rows = list(itertools.islice(rows_iterator, blocksize))
  1657                 serialized = self._serialize(table, columns, rows)
  1657                 serialized = self._serialize(table, columns, rows)
  1658                 archive.writestr('tables/%s.%04d' % (table, i), serialized)
  1658                 archive.writestr('tables/%s.%04d' % (table, i), serialized)