Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6dd7a12

Browse files
committed
Fix libpq to not require user's home directory to exist.
Some people like to run libpq-using applications in environments wherethere's no home directory. We've broken that scenario before (cf commits5b40677 andbd58d9d), and commitba005f1 broke it again, by makingit a hard error if we fail to get the home directory name while lookingfor ~/.pgpass. The previous precedent is that if we can't get the homedirectory name, we should just silently act as though the file we hopedto find there doesn't exist. Rearrange the new code to honor that.Looking around, the service-file code added by commit41a4e45 had thesame disease. Apparently, that escaped notice because it only runs whena service name has been specified, which I guess the people who use thisscenario don't do. Nonetheless, it's wrong too, so fix that case as well.Add a comment about this policy to pqGetHomeDirectory, in the probablyvain hope of forestalling the same error in future. And upgrade therather miserable commenting in parseServiceInfo, too.In passing, also back off parseServiceInfo's assumption that only ENOENTis an ignorable error from stat() when checking a service file. We wouldneed to ignore at least ENOTDIR as well (cf5b40677), and seeing thatthe far-better-tested code for ~/.pgpass treats all stat() failures alike,I think this code ought to as well.Per bug #14872 from Dan Watson. Back-patch the .pgpass change to v10whereba005f1 came in. The service-file bugs are far older, soback-patch the other changes to all supported branches.Discussion:https://postgr.es/m/20171025200457.1471.34504@wrigleys.postgresql.org
1 parentda82bb1 commit6dd7a12

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

‎src/interfaces/libpq/fe-connect.c

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3897,6 +3897,16 @@ ldapServiceLookup(const char *purl, PQconninfoOption *options,
38973897

38983898
#defineMAXBUFSIZE 256
38993899

3900+
/*
3901+
* parseServiceInfo: if a service name has been given, look it up and absorb
3902+
* connection options from it into *options.
3903+
*
3904+
* Returns 0 on success, nonzero on failure. On failure, if errorMessage
3905+
* isn't null, also store an error message there. (Note: the only reason
3906+
* this function and related ones don't dump core on errorMessage == NULL
3907+
* is the undocumented fact that printfPQExpBuffer does nothing when passed
3908+
* a null PQExpBuffer pointer.)
3909+
*/
39003910
staticint
39013911
parseServiceInfo(PQconninfoOption*options,PQExpBuffererrorMessage)
39023912
{
@@ -3915,23 +3925,24 @@ parseServiceInfo(PQconninfoOption *options, PQExpBuffer errorMessage)
39153925
if (service==NULL)
39163926
service=getenv("PGSERVICE");
39173927

3928+
/* If no service name given, nothing to do */
39183929
if (service==NULL)
39193930
return0;
39203931

3932+
/*
3933+
* Try PGSERVICEFILE if specified, else try ~/.pg_service.conf (if that
3934+
* exists).
3935+
*/
39213936
if ((env=getenv("PGSERVICEFILE"))!=NULL)
39223937
strlcpy(serviceFile,env,sizeof(serviceFile));
39233938
else
39243939
{
39253940
charhomedir[MAXPGPATH];
39263941

39273942
if (!pqGetHomeDirectory(homedir,sizeof(homedir)))
3928-
{
3929-
printfPQExpBuffer(errorMessage,libpq_gettext("could not get home directory to locate service definition file"));
3930-
return1;
3931-
}
3943+
gotonext_file;
39323944
snprintf(serviceFile,MAXPGPATH,"%s/%s",homedir,".pg_service.conf");
3933-
errno=0;
3934-
if (stat(serviceFile,&stat_buf)!=0&&errno==ENOENT)
3945+
if (stat(serviceFile,&stat_buf)!=0)
39353946
gotonext_file;
39363947
}
39373948

@@ -3947,8 +3958,7 @@ parseServiceInfo(PQconninfoOption *options, PQExpBuffer errorMessage)
39473958
*/
39483959
snprintf(serviceFile,MAXPGPATH,"%s/pg_service.conf",
39493960
getenv("PGSYSCONFDIR") ?getenv("PGSYSCONFDIR") :SYSCONFDIR);
3950-
errno=0;
3951-
if (stat(serviceFile,&stat_buf)!=0&&errno==ENOENT)
3961+
if (stat(serviceFile,&stat_buf)!=0)
39523962
gotolast_file;
39533963

39543964
status=parseServiceFile(serviceFile,service,options,errorMessage,&group_found);
@@ -5892,7 +5902,15 @@ dot_pg_pass_warning(PGconn *conn)
58925902
*
58935903
* This is essentially the same as get_home_path(), but we don't use that
58945904
* because we don't want to pull path.c into libpq (it pollutes application
5895-
* namespace)
5905+
* namespace).
5906+
*
5907+
* Returns true on success, false on failure to obtain the directory name.
5908+
*
5909+
* CAUTION: although in most situations failure is unexpected, there are users
5910+
* who like to run applications in a home-directory-less environment. On
5911+
* failure, you almost certainly DO NOT want to report an error. Just act as
5912+
* though whatever file you were hoping to find in the home directory isn't
5913+
* there (which it isn't).
58965914
*/
58975915
bool
58985916
pqGetHomeDirectory(char*buf,intbufsize)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp