diff options
Diffstat (limited to 'psycopg/connection_type.c')
-rw-r--r-- | psycopg/connection_type.c | 60 |
1 files changed, 2 insertions, 58 deletions
diff --git a/psycopg/connection_type.c b/psycopg/connection_type.c index f472c4b..b94dd8b 100644 --- a/psycopg/connection_type.c +++ b/psycopg/connection_type.c @@ -1297,55 +1297,6 @@ static struct PyGetSetDef connectionObject_getsets[] = { /* initialization and finalization methods */ -RAISES_NEG static int -obscure_password(connectionObject *conn) -{ - PQconninfoOption *options; - PyObject *d = NULL, *v = NULL, *dsn = NULL; - char *tmp; - int rv = -1; - - if (!conn || !conn->dsn) { - return 0; - } - - if (!(options = PQconninfoParse(conn->dsn, NULL))) { - /* unlikely: the dsn was already tested valid */ - return 0; - } - - if (!(d = psyco_dict_from_conninfo_options( - options, /* include_password = */ 1))) { - goto exit; - } - if (NULL == PyDict_GetItemString(d, "password")) { - /* the dsn doesn't have a password */ - rv = 0; - goto exit; - } - - /* scrub the password and put back the connection string together */ - if (!(v = Text_FromUTF8("xxx"))) { goto exit; } - if (0 > PyDict_SetItemString(d, "password", v)) { goto exit; } - if (!(dsn = psyco_make_dsn(Py_None, d))) { goto exit; } - if (!(dsn = psyco_ensure_bytes(dsn))) { goto exit; } - - /* Replace the connection string on the connection object */ - tmp = conn->dsn; - psyco_strdup(&conn->dsn, Bytes_AS_STRING(dsn), -1); - PyMem_Free(tmp); - - rv = 0; - -exit: - PQconninfoFree(options); - Py_XDECREF(v); - Py_XDECREF(d); - Py_XDECREF(dsn); - - return rv; -} - static int connection_setup(connectionObject *self, const char *dsn, long int async) { @@ -1356,7 +1307,7 @@ connection_setup(connectionObject *self, const char *dsn, long int async) self, async, Py_REFCNT(self) ); - if (0 > psyco_strdup(&self->dsn, dsn, -1)) { goto exit; } + if (!(self->dsn = conn_obscure_password(dsn))) { goto exit; } if (!(self->notice_list = PyList_New(0))) { goto exit; } if (!(self->notifies = PyList_New(0))) { goto exit; } self->async = async; @@ -1378,7 +1329,7 @@ connection_setup(connectionObject *self, const char *dsn, long int async) goto exit; } - if (conn_connect(self, async) != 0) { + if (conn_connect(self, dsn, async) != 0) { Dprintf("connection_init: FAILED"); goto exit; } @@ -1390,13 +1341,6 @@ connection_setup(connectionObject *self, const char *dsn, long int async) self, Py_REFCNT(self)); exit: - /* here we obfuscate the password even if there was a connection error */ - { - PyObject *ptype = NULL, *pvalue = NULL, *ptb = NULL; - PyErr_Fetch(&ptype, &pvalue, &ptb); - obscure_password(self); - PyErr_Restore(ptype, pvalue, ptb); - } return rv; } |