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

Commit7dc66a2

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 parent98efa5e commit7dc66a2

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
@@ -3906,6 +3906,16 @@ ldapServiceLookup(const char *purl, PQconninfoOption *options,
39063906

39073907
#defineMAXBUFSIZE 256
39083908

3909+
/*
3910+
* parseServiceInfo: if a service name has been given, look it up and absorb
3911+
* connection options from it into *options.
3912+
*
3913+
* Returns 0 on success, nonzero on failure. On failure, if errorMessage
3914+
* isn't null, also store an error message there. (Note: the only reason
3915+
* this function and related ones don't dump core on errorMessage == NULL
3916+
* is the undocumented fact that printfPQExpBuffer does nothing when passed
3917+
* a null PQExpBuffer pointer.)
3918+
*/
39093919
staticint
39103920
parseServiceInfo(PQconninfoOption*options,PQExpBuffererrorMessage)
39113921
{
@@ -3924,23 +3934,24 @@ parseServiceInfo(PQconninfoOption *options, PQExpBuffer errorMessage)
39243934
if (service==NULL)
39253935
service=getenv("PGSERVICE");
39263936

3937+
/* If no service name given, nothing to do */
39273938
if (service==NULL)
39283939
return0;
39293940

3941+
/*
3942+
* Try PGSERVICEFILE if specified, else try ~/.pg_service.conf (if that
3943+
* exists).
3944+
*/
39303945
if ((env=getenv("PGSERVICEFILE"))!=NULL)
39313946
strlcpy(serviceFile,env,sizeof(serviceFile));
39323947
else
39333948
{
39343949
charhomedir[MAXPGPATH];
39353950

39363951
if (!pqGetHomeDirectory(homedir,sizeof(homedir)))
3937-
{
3938-
printfPQExpBuffer(errorMessage,libpq_gettext("could not get home directory to locate service definition file"));
3939-
return1;
3940-
}
3952+
gotonext_file;
39413953
snprintf(serviceFile,MAXPGPATH,"%s/%s",homedir,".pg_service.conf");
3942-
errno=0;
3943-
if (stat(serviceFile,&stat_buf)!=0&&errno==ENOENT)
3954+
if (stat(serviceFile,&stat_buf)!=0)
39443955
gotonext_file;
39453956
}
39463957

@@ -3956,8 +3967,7 @@ parseServiceInfo(PQconninfoOption *options, PQExpBuffer errorMessage)
39563967
*/
39573968
snprintf(serviceFile,MAXPGPATH,"%s/pg_service.conf",
39583969
getenv("PGSYSCONFDIR") ?getenv("PGSYSCONFDIR") :SYSCONFDIR);
3959-
errno=0;
3960-
if (stat(serviceFile,&stat_buf)!=0&&errno==ENOENT)
3970+
if (stat(serviceFile,&stat_buf)!=0)
39613971
gotolast_file;
39623972

39633973
status=parseServiceFile(serviceFile,service,options,errorMessage,&group_found);
@@ -5922,7 +5932,15 @@ dot_pg_pass_warning(PGconn *conn)
59225932
*
59235933
* This is essentially the same as get_home_path(), but we don't use that
59245934
* because we don't want to pull path.c into libpq (it pollutes application
5925-
* namespace)
5935+
* namespace).
5936+
*
5937+
* Returns true on success, false on failure to obtain the directory name.
5938+
*
5939+
* CAUTION: although in most situations failure is unexpected, there are users
5940+
* who like to run applications in a home-directory-less environment. On
5941+
* failure, you almost certainly DO NOT want to report an error. Just act as
5942+
* though whatever file you were hoping to find in the home directory isn't
5943+
* there (which it isn't).
59265944
*/
59275945
bool
59285946
pqGetHomeDirectory(char*buf,intbufsize)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp