Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 48638eb

Browse files
committed
Code refactoring ocerl libpq
1 parent df33edc commit 48638eb

File tree

3 files changed

+13
-17
lines changed

3 files changed

+13
-17
lines changed

src/interfaces/libpq/fe-auth.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -950,29 +950,26 @@ pg_fe_sendauth(AuthRequest areq, int payloadlen, PGconn *conn)
950950
conn->password_needed = true;
951951
/* Get password from .pgpass */
952952
password = conn->connhost[conn->whichhost].password;
953-
/* Get password from ppassword prompt */
954-
if (password == NULL) {
953+
/* Get password from password prompt */
954+
if (password == NULL)
955955
password = conn->pgpass;
956-
/* Get password from PGPASSWORD environment */
957-
if ((password == NULL) &&
958-
(conn->pgpassenv != NULL && conn->pgpassenv[0] != '\0'))
959-
password = conn->pgpassenv;
960-
}
961956

962957
if (password == NULL || password[0] == '\0')
963958
{
964959
printfPQExpBuffer(&conn->errorMessage,
965960
PQnoPasswordSupplied);
966961
return STATUS_ERROR;
967962
}
963+
968964
if (pg_password_sendauth(conn, password, areq) != STATUS_OK)
969965
{
970966
printfPQExpBuffer(&conn->errorMessage,
971967
"fe_sendauth: error sending password authentication\n");
972968
return STATUS_ERROR;
973969
}
974-
/* Clean prompted passwored if we dont want to reuse password */
975-
if (!conn->reusepass && conn->pgpass != NULL)
970+
971+
/* Clean prompted password if reusepass is set and not env password */
972+
if (conn->pgpass && !conn->reusepass && !conn->pgpassenv_used)
976973
{
977974
memset(conn->pgpass, 0, strlen(conn->pgpass));
978975
free(conn->pgpass);

src/interfaces/libpq/fe-connect.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,14 +199,10 @@ static const internalPQconninfoOption PQconninfoOptions[] = {
199199
"Database-Reuse-Password", "D", 4,
200200
offsetof(struct pg_conn, reusepass_str)},
201201

202-
{"password", NULL, NULL, NULL,
202+
{"password", "PGPASSWORD", NULL, NULL,
203203
"Database-Password", "*", 20,
204204
offsetof(struct pg_conn, pgpass)},
205205

206-
{"pgpassword", "PGPASSWORD", NULL, NULL,
207-
"Database-Password-env", "*", 20,
208-
offsetof(struct pg_conn, pgpassenv)},
209-
210206
{"passfile", "PGPASSFILE", NULL, NULL,
211207
"Database-Password-File", "", 64,
212208
offsetof(struct pg_conn, pgpassfile)},
@@ -790,6 +786,10 @@ fillPGconn(PGconn *conn, PQconninfoOption *connOptions)
790786
libpq_gettext("out of memory\n"));
791787
return false;
792788
}
789+
/* Catch case environment PGPASSWORD use*/
790+
if (option->envvar && getenv(option->envvar)
791+
&& strcmp(option->envvar, "PGPASSWORD") == 0)
792+
conn->pgpassenv_used = true;
793793
}
794794
}
795795
}
@@ -3703,6 +3703,7 @@ makeEmptyPGconn(void)
37033703
conn->auth_req_received = false;
37043704
conn->password_needed = false;
37053705
conn->pgpassfile_used = false;
3706+
conn->pgpassenv_used = false;
37063707
#ifdef USE_SSL
37073708
conn->allow_ssl_try = true;
37083709
conn->wait_ssl_try = false;
@@ -3815,8 +3816,6 @@ freePGconn(PGconn *conn)
38153816
free(conn->reusepass_str);
38163817
if (conn->pgpass)
38173818
free(conn->pgpass);
3818-
if (conn->pgpassenv)
3819-
free(conn->pgpassenv);
38203819
if (conn->pgpassfile)
38213820
free(conn->pgpassfile);
38223821
if (conn->keepalives)

src/interfaces/libpq/libpq-int.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,6 @@ struct pg_conn
348348
and save password after connection established.
349349
Default is "yes".*/
350350
char *pgpass;
351-
char *pgpassenv;
352351
char *pgpassfile; /* path to a file containing password(s) */
353352
char *keepalives; /* use TCP keepalives? */
354353
char *keepalives_idle; /* time between TCP keepalives */
@@ -420,6 +419,7 @@ struct pg_conn
420419
ie read from PGPASSWORD, pgpassfile,
421420
and not cleared after disconnect */
422421
bool pgpassfile_used; /* true if password is from pgpassfile */
422+
bool pgpassenv_used; /* true if password if from env PGPASSWORD */
423423
bool sigpipe_so; /* have we masked SIGPIPE via SO_NOSIGPIPE? */
424424
bool sigpipe_flag; /* can we mask SIGPIPE via MSG_NOSIGNAL? */
425425

0 commit comments

Comments
 (0)