Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
453d74b9
Commit
453d74b9
authored
Jun 10, 2005
by
Bruce Momjian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add the "PGPASSFILE" environment variable to specify to the password
file. Andrew Dunstan
parent
3b167a40
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
12 deletions
+47
-12
doc/src/sgml/libpq.sgml
doc/src/sgml/libpq.sgml
+19
-7
src/interfaces/libpq/fe-connect.c
src/interfaces/libpq/fe-connect.c
+28
-5
No files found.
doc/src/sgml/libpq.sgml
View file @
453d74b9
<!--
<!--
$PostgreSQL: pgsql/doc/src/sgml/libpq.sgml,v 1.18
3 2005/06/09 19:08:28 tgl
Exp $
$PostgreSQL: pgsql/doc/src/sgml/libpq.sgml,v 1.18
4 2005/06/10 03:02:01 momjian
Exp $
-->
-->
<chapter id="libpq">
<chapter id="libpq">
...
@@ -3712,6 +3712,17 @@ allow non-root users to see process environment variables via
...
@@ -3712,6 +3712,17 @@ allow non-root users to see process environment variables via
</listitem>
</listitem>
<listitem>
<listitem>
<para>
<para>
<indexterm>
<primary><envar>PGPASSFILE</envar></primary>
</indexterm>
<envar>PGPASSFILE</envar>
specifies the name of the password file to use for lookups.
If not set, it defaults to <filename>~/.pgpass</>
(see <xref linkend="libpq-pgpass">).
</para>
</listitem>
<listitem>
<para>
<indexterm>
<indexterm>
<primary><envar>PGSERVICE</envar></primary>
<primary><envar>PGSERVICE</envar></primary>
</indexterm>
</indexterm>
...
@@ -3902,12 +3913,13 @@ internationalization.
...
@@ -3902,12 +3913,13 @@ internationalization.
</indexterm>
</indexterm>
<para>
<para>
The file <filename>.pgpass</filename> in a user's home directory is a file
The file <filename>.pgpass</filename> in a user's home directory or the
that can contain passwords to be used if the connection requires a
file referenced by <envar>PGPASSFILE</envar> can contain passwords to
password (and no password has been specified otherwise).
be used if the connection requires a password (and no password has been
On Microsoft Windows the file is named
specified otherwise). On Microsoft Windows the file is named
<filename>%APPDATA%\postgresql\pgpass.conf</> (where <filename>%APPDATA%</>
<filename>%APPDATA%\postgresql\pgpass.conf</> (where
refers to the Application Data subdirectory in the user's profile).
<filename>%APPDATA%</> refers to the Application Data subdirectory in
the user's profile).
</para>
</para>
<para>
<para>
...
...
src/interfaces/libpq/fe-connect.c
View file @
453d74b9
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.30
7 2005/06/04 20:42:43
momjian Exp $
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.30
8 2005/06/10 03:02:30
momjian Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -3217,9 +3217,9 @@ static char *
...
@@ -3217,9 +3217,9 @@ static char *
PasswordFromFile
(
char
*
hostname
,
char
*
port
,
char
*
dbname
,
char
*
username
)
PasswordFromFile
(
char
*
hostname
,
char
*
port
,
char
*
dbname
,
char
*
username
)
{
{
FILE
*
fp
;
FILE
*
fp
;
char
homedir
[
MAXPGPATH
];
char
pgpassfile
[
MAXPGPATH
];
char
pgpassfile
[
MAXPGPATH
];
struct
stat
stat_buf
;
struct
stat
stat_buf
;
char
*
passfile_env
;
#define LINELEN NAMEDATALEN*5
#define LINELEN NAMEDATALEN*5
char
buf
[
LINELEN
];
char
buf
[
LINELEN
];
...
@@ -3236,15 +3236,38 @@ PasswordFromFile(char *hostname, char *port, char *dbname, char *username)
...
@@ -3236,15 +3236,38 @@ PasswordFromFile(char *hostname, char *port, char *dbname, char *username)
if
(
port
==
NULL
)
if
(
port
==
NULL
)
port
=
DEF_PGPORT_STR
;
port
=
DEF_PGPORT_STR
;
if
(
!
pqGetHomeDirectory
(
homedir
,
sizeof
(
homedir
)))
if
((
passfile_env
=
getenv
(
"PGPASSFILE"
))
!=
NULL
)
{
/* use the literal path from the environment, if set */
StrNCpy
(
pgpassfile
,
passfile_env
,
MAXPGPATH
);
if
(
!
pgpassfile
)
{
fprintf
(
stderr
,
libpq_gettext
(
"out of memory
\n
"
));
return
NULL
;
return
NULL
;
}
}
else
{
char
homedir
[
MAXPGPATH
];
if
(
!
pqGetHomeDirectory
(
homedir
,
sizeof
(
homedir
)))
return
NULL
;
snprintf
(
pgpassfile
,
sizeof
(
pgpassfile
),
"%s/%s"
,
homedir
,
PGPASSFILE
);
snprintf
(
pgpassfile
,
sizeof
(
pgpassfile
),
"%s/%s"
,
homedir
,
PGPASSFILE
);
}
/* If password file cannot be opened, ignore it. */
/* If password file cannot be opened, ignore it. */
if
(
stat
(
pgpassfile
,
&
stat_buf
)
==
-
1
)
if
(
stat
(
pgpassfile
,
&
stat_buf
)
==
-
1
)
return
NULL
;
return
NULL
;
if
(
!
S_ISREG
(
stat_buf
.
st_mode
))
{
fprintf
(
stderr
,
libpq_gettext
(
"WARNING: Password file %s is not a plain file.
\n
"
),
pgpassfile
);
free
(
pgpassfile
);
return
NULL
;
}
#ifndef WIN32
#ifndef WIN32
/* If password file is insecure, alert the user and ignore it. */
/* If password file is insecure, alert the user and ignore it. */
if
(
stat_buf
.
st_mode
&
(
S_IRWXG
|
S_IRWXO
))
if
(
stat_buf
.
st_mode
&
(
S_IRWXG
|
S_IRWXO
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment