def _pkt_make_command(self, command, argument=None):
     """Make a MySQL packet containing a command"""
     data = utils.int1store(command)
     if argument is not None:
         data += str(argument)
     header = self._pkt_make_header(len(data))
     return header + data
Beispiel #2
0
 def make_auth_ssl(self, charset=33, client_flags=0,
                   max_allowed_packet=1073741824):
     """Make a SSL authentication packet"""
     return utils.int4store(client_flags) +\
            utils.int4store(max_allowed_packet) +\
            utils.int1store(charset) +\
            '\x00' * 23
    def _pkt_make_auth(self,
                       username=None,
                       password=None,
                       database=None,
                       seed=None,
                       charset=33,
                       client_flags=0):
        """Make a MySQL Authentication packet"""
        try:
            seed = seed or self.scramble
        except:
            raise errors.ProgrammingError('Seed missing')

        (_username, _password,
         _database) = self._prepare_auth(username, password, database,
                                         client_flags, seed)
        data =  utils.int4store(client_flags) +\
                utils.int4store(10 * 1024 * 1024) +\
                utils.int1store(charset) +\
                '\x00'*23 +\
                _username +\
                _password +\
                _database

        header = self._pkt_make_header(len(data))
        return header + data
Beispiel #4
0
 def _pkt_make_command(self, command, argument=None):
     """Make a MySQL packet containing a command"""
     data = utils.int1store(command)
     if argument is not None:
         data += str(argument)
     header = self._pkt_make_header(len(data))
     return header+data
Beispiel #5
0
 def make_auth_ssl(self,
                   charset=33,
                   client_flags=0,
                   max_allowed_packet=1073741824):
     """Make a SSL authentication packet"""
     return utils.int4store(client_flags) +\
            utils.int4store(max_allowed_packet) +\
            utils.int1store(charset) +\
            '\x00' * 23
Beispiel #6
0
    def make_change_user(self, seed, username=None, password=None,
                         database=None, charset=33, client_flags=0):
        """Make a MySQL packet with the Change User command"""
        if not seed:
            raise errors.ProgrammingError('Seed missing')

        auth = self._prepare_auth(username, password, database,
                                  client_flags, seed)
        data =  utils.int1store(ServerCmd.CHANGE_USER) +\
                auth[0] + auth[1] + auth[2] + utils.int2store(charset)
        return data
Beispiel #7
0
    def make_auth(self, seed, username=None, password=None, database=None,
                  charset=33, client_flags=0,
                  max_allowed_packet=1073741824):
        """Make a MySQL Authentication packet"""
        if not seed:
            raise errors.ProgrammingError('Seed missing')

        auth = self._prepare_auth(username, password, database,
                                  client_flags, seed)
        return utils.int4store(client_flags) +\
               utils.int4store(max_allowed_packet) +\
               utils.int1store(charset) +\
               '\x00' * 23 + auth[0] + auth[1] + auth[2]
Beispiel #8
0
    def make_change_user(self,
                         seed,
                         username=None,
                         password=None,
                         database=None,
                         charset=33,
                         client_flags=0):
        """Make a MySQL packet with the Change User command"""
        if not seed:
            raise errors.ProgrammingError('Seed missing')

        auth = self._prepare_auth(username, password, database, client_flags,
                                  seed)
        data =  utils.int1store(ServerCmd.CHANGE_USER) +\
                auth[0] + auth[1] + auth[2] + utils.int2store(charset)
        return data
 def _pkt_make_changeuser(self, username=None, password=None,
     database=None, charset=8, seed=None):
     """Make a MySQL packet with the Change User command"""
     try:
         seed = seed or self.scramble
     except:
         raise errors.ProgrammingError('Seed missing')
     
     (_username, _password, _database) = self._prepare_auth(
         username, password, database, self.client_flags, seed)
     data =  utils.int1store(ServerCmd.CHANGE_USER) +\
             _username +\
             _password +\
             _database +\
             utils.int2store(charset)
     return data
    def _pkt_make_auth_ssl(self, username=None, password=None, database=None,
            seed=None, charset=33, client_flags=0, max_allowed_packet=None):
        try:
            seed = seed or self.scramble
        except:
            raise errors.ProgrammingError('Seed missing')
        
        if max_allowed_packet is None:
            max_allowed_packet = 1073741824 # 1Gb

        (_username, _password, _database) = self._prepare_auth(
                username, password, database, client_flags, seed)
        data =  utils.int4store(client_flags) +\
                    utils.int4store(max_allowed_packet) +\
                    utils.int1store(charset) +\
                    '\x00'*23
        return data
Beispiel #11
0
    def cmd_shutdown(self, shutdown_type=None):
        """Shut down the MySQL Server

        This method sends the SHUTDOWN command to the MySQL server and is only
        possible if the current user has SUPER privileges. The result is a
        dictionary containing the OK packet information.

        Note: Most applications and scripts do not the SUPER privilege.

        Returns a dict()
        """
        atype = None
        if shutdown_type:
            if not ShutdownType.get_info(shutdown_type):
                raise errors.InterfaceError("Invalid shutdown type")
            atype = int1store(shutdown_type)
        return self._handle_eof(self._send_cmd(ServerCmd.SHUTDOWN, atype))
Beispiel #12
0
    def make_auth(self,
                  seed,
                  username=None,
                  password=None,
                  database=None,
                  charset=33,
                  client_flags=0,
                  max_allowed_packet=1073741824):
        """Make a MySQL Authentication packet"""
        if not seed:
            raise errors.ProgrammingError('Seed missing')

        auth = self._prepare_auth(username, password, database, client_flags,
                                  seed)
        return utils.int4store(client_flags) +\
               utils.int4store(max_allowed_packet) +\
               utils.int1store(charset) +\
               '\x00' * 23 + auth[0] + auth[1] + auth[2]
Beispiel #13
0
    def _prepare_auth(self, usr, pwd, db, flags, seed):
        """Prepare elements of the authentication packet"""
        if usr is not None and len(usr) > 0:
            _username = usr + '\x00'
        else:
            _username = '******'

        if pwd is not None and len(pwd) > 0:
            _password = utils.int1store(20) +\
                self._scramble_password(pwd,seed)
        else:
            _password = '******'

        if db is not None and len(db):
            _database = db + '\x00'
        else:
            _database = '\x00'

        return (_username, _password, _database)
Beispiel #14
0
 def _prepare_auth(self, usr, pwd, db, flags, seed):
     
     if usr is not None and len(usr) > 0:
         _username = usr + '\x00'
     else:
         _username = '******'
     
     if pwd is not None and len(pwd) > 0:
         _password = utils.int1store(20) +\
             self._scramble_password(pwd,seed)
     else:
         _password = '******'
     
     if db is not None and len(db):
         _database = db + '\x00'
     else:
         _database = '\x00'
     
     return (_username, _password, _database)
Beispiel #15
0
 def _pkt_make_auth(self, username=None, password=None, database=None,
     seed=None, charset=33, client_flags=0):
     """Make a MySQL Authentication packet"""
     try:
         seed = seed or self.scramble
     except:
         raise errors.ProgrammingError('Seed missing')
     
     (_username, _password, _database) = self._prepare_auth(
         username, password, database, client_flags, seed)
     data =  utils.int4store(client_flags) +\
             utils.int4store(10 * 1024 * 1024) +\
             utils.int1store(charset) +\
             '\x00'*23 +\
             _username +\
             _password +\
             _database
         
     header = self._pkt_make_header(len(data))
     return header+data
Beispiel #16
0
    def _prepare_auth(self, usr, pwd, db, flags, seed):
        """Prepare elements of the authentication packet"""

        if usr is not None and len(usr) > 0:
            if isinstance(usr, unicode):
                usr = usr.encode('utf8')
            _username = usr + '\x00'
        else:
            _username = '******'

        if pwd is not None and len(pwd) > 0:
            if isinstance(pwd, unicode):
                pwd = pwd.encode('utf8')
            _password = utils.int1store(20) +\
                self._scramble_password(pwd,seed)
        else:
            _password = '******'

        if db is not None and len(db):
            _database = db + '\x00'
        else:
            _database = '\x00'

        return (_username, _password, _database)
Beispiel #17
0
 def _pkt_make_header(self, pktlength, pktnr=None):
     """Make the header for a MySQL packet"""
     pktnr = pktnr or self.pktnr+1
     return utils.int3store(pktlength) + utils.int1store(pktnr)
Beispiel #18
0
 def add_1_int(self, i):
     self.add(utils.int1store(i))
Beispiel #19
0
 def _make_header(self):
     h = utils.int3store(len(self)) + utils.int1store(self.pktnr)
     return h
Beispiel #20
0
 def _pkt_make_header(self, pktlength, pktnr=None):
     """Make the header for a MySQL packet"""
     pktnr = pktnr or self.pktnr + 1
     return utils.int3store(pktlength) + utils.int1store(pktnr)
Beispiel #21
0
 def make_command(self, command, argument=None):
     """Make a MySQL packet containing a command"""
     data = utils.int1store(command)
     if argument is not None:
         data += str(argument)
     return data
Beispiel #22
0
 def _pkt_make_command(self, command, argument=None):
     """Make a MySQL packet containing a command"""
     data = utils.int1store(command)
     if argument is not None:
         data += str(argument)
     return data