mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-25 10:23:43 +03:00
Password scrubbing refactored in a separate function
This commit is contained in:
parent
cc047a445a
commit
103655d670
|
@ -1248,10 +1248,25 @@ static struct PyGetSetDef connectionObject_getsets[] = {
|
||||||
|
|
||||||
/* initialization and finalization methods */
|
/* initialization and finalization methods */
|
||||||
|
|
||||||
|
static void
|
||||||
|
obscure_password(connectionObject *conn)
|
||||||
|
{
|
||||||
|
char *pos;
|
||||||
|
|
||||||
|
if (!conn || !conn->dsn) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
pos = strstr(conn->dsn, "password");
|
||||||
|
if (pos != NULL) {
|
||||||
|
for (pos = pos+9 ; *pos != '\0' && *pos != ' '; pos++)
|
||||||
|
*pos = 'x';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
connection_setup(connectionObject *self, const char *dsn, long int async)
|
connection_setup(connectionObject *self, const char *dsn, long int async)
|
||||||
{
|
{
|
||||||
char *pos;
|
|
||||||
int res = -1;
|
int res = -1;
|
||||||
|
|
||||||
Dprintf("connection_setup: init connection object at %p, "
|
Dprintf("connection_setup: init connection object at %p, "
|
||||||
|
@ -1288,15 +1303,11 @@ connection_setup(connectionObject *self, const char *dsn, long int async)
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
/* here we obfuscate the password even if there was a connection error */
|
/* here we obfuscate the password even if there was a connection error */
|
||||||
pos = strstr(self->dsn, "password");
|
obscure_password(self);
|
||||||
if (pos != NULL) {
|
|
||||||
for (pos = pos+9 ; *pos != '\0' && *pos != ' '; pos++)
|
|
||||||
*pos = 'x';
|
|
||||||
}
|
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
connection_clear(connectionObject *self)
|
connection_clear(connectionObject *self)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user