|
1 | 1 | #!/usr/bin/env python |
2 | 2 |
|
3 | | -""" |
4 | | -$Id$ |
5 | | -
|
6 | | -Copyright (c) 2006-2011 sqlmap developers (http://sqlmap.sourceforge.net/) |
7 | | -See the file 'doc/COPYING' for copying permission |
8 | | -""" |
9 | 3 |
|
10 | 4 | try: |
11 | | - import ibm_db |
| 5 | + import ibm_db_dbi |
12 | 6 | except ImportError, _: |
13 | 7 | pass |
14 | 8 |
|
15 | 9 | from lib.core.data import logger |
16 | 10 | from lib.core.exception import sqlmapConnectionException |
17 | | -from lib.core.exception import sqlmapUnsupportedFeatureException |
18 | 11 |
|
19 | 12 | from plugins.generic.connector import Connector as GenericConnector |
20 | 13 |
|
21 | 14 | class Connector(GenericConnector): |
22 | 15 | """ |
23 | 16 | Homepage: http://code.google.com/p/ibm-db/ |
24 | | - User guide: http://code.google.com/p/ibm-db/wiki/ibm_db_README |
25 | | - API: http://code.google.com/p/ibm-db/wiki/APIs |
26 | | - Debian package: <none> |
27 | | - License: Apache |
| 17 | + User guide: http://code.google.com/p/ibm-db/wiki/README |
| 18 | + API: http://www.python.org/dev/peps/pep-0249/ |
| 19 | + License: Apache License 2.0 |
28 | 20 | """ |
29 | 21 |
|
30 | 22 | def __init__(self): |
31 | 23 | GenericConnector.__init__(self) |
| 24 | + |
| 25 | + def connect(self): |
| 26 | + self.initConnection() |
| 27 | + |
| 28 | + try: |
| 29 | + database = "DRIVER={IBM DB2 ODBC DRIVER};DATABASE=%s;HOSTNAME=%s;PORT=%s;PROTOCOL=TCPIP;" % (self.db, self.hostname, self.port) |
| 30 | + self.connector = ibm_db_dbi.connect(database, self.user, self.password) |
| 31 | + except ibm_db_dbi.OperationalError, msg: |
| 32 | + raise sqlmapConnectionException, msg |
| 33 | + |
| 34 | + |
| 35 | + self.setCursor() |
| 36 | + self.connected() |
| 37 | + |
| 38 | + def fetchall(self): |
| 39 | + try: |
| 40 | + return self.cursor.fetchall() |
| 41 | + except ibm_db_dbi.ProgrammingError, msg: |
| 42 | + logger.warn(msg[1]) |
| 43 | + return None |
| 44 | + |
| 45 | + def execute(self, query): |
| 46 | + try: |
| 47 | + self.cursor.execute(query) |
| 48 | + except (ibm_db_dbi.OperationalError, ibm_db_dbi.ProgrammingError), msg: |
| 49 | + logger.warn(msg[1]) |
| 50 | + except ibm_db_dbi.InternalError, msg: |
| 51 | + raise sqlmapConnectionException, msg[1] |
| 52 | + |
| 53 | + self.connector.commit() |
| 54 | + |
| 55 | + def select(self, query): |
| 56 | + self.execute(query) |
| 57 | + return self.fetchall() |
0 commit comments