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

Commit11def69

Browse files
committed
Missed some corner cases (PGSERVICE mostly)...
1 parent092133b commit11def69

File tree

1 file changed

+30
-16
lines changed

1 file changed

+30
-16
lines changed

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

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.238 2003/04/28 04:29:12 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.239 2003/04/28 04:52:13 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -107,7 +107,7 @@ static const PQconninfoOption PQconninfoOptions[] = {
107107
{"user","PGUSER",NULL,NULL,
108108
"Database-User","",20},
109109

110-
{"password","PGPASSWORD",DefaultPassword,NULL,
110+
{"password","PGPASSWORD",NULL,NULL,
111111
"Database-Password","*",20},
112112

113113
{"connect_timeout","PGCONNECT_TIMEOUT",NULL,NULL,
@@ -1976,6 +1976,14 @@ parseServiceInfo(PQconninfoOption *options, PQExpBuffer errorMessage)
19761976
intlinenr=0,
19771977
i;
19781978

1979+
/*
1980+
* We have to special-case the environment variable PGSERVICE here,
1981+
* since this is and should be called before inserting environment
1982+
* defaults for other connection options.
1983+
*/
1984+
if (service==NULL)
1985+
service=getenv("PGSERVICE");
1986+
19791987
if (service!=NULL)
19801988
{
19811989
FILE*f;
@@ -2060,21 +2068,30 @@ parseServiceInfo(PQconninfoOption *options, PQExpBuffer errorMessage)
20602068
*name of the service
20612069
*/
20622070
for (i=0;options[i].keyword;i++)
2071+
{
20632072
if (strcmp(options[i].keyword,"dbname")==0)
2073+
{
20642074
if (options[i].val==NULL)
20652075
options[i].val=strdup(service);
2076+
break;
2077+
}
2078+
}
20662079

20672080
val=line+strlen(line)+1;
20682081

2082+
/*
2083+
* Set the parameter --- but don't override any
2084+
* previous explicit setting.
2085+
*/
20692086
found_keyword=0;
20702087
for (i=0;options[i].keyword;i++)
20712088
{
20722089
if (strcmp(options[i].keyword,key)==0)
20732090
{
2074-
if (options[i].val!=NULL)
2075-
free(options[i].val);
2076-
options[i].val=strdup(val);
2091+
if (options[i].val==NULL)
2092+
options[i].val=strdup(val);
20772093
found_keyword=1;
2094+
break;
20782095
}
20792096
}
20802097

@@ -2273,7 +2290,10 @@ conninfo_parse(const char *conninfo, PQExpBuffer errorMessage)
22732290
/* Done with the modifiable input string */
22742291
free(buf);
22752292

2276-
/* Now check for service info */
2293+
/*
2294+
* If there's a service spec, use it to obtain any not-explicitly-given
2295+
* parameters.
2296+
*/
22772297
if (parseServiceInfo(options,errorMessage))
22782298
{
22792299
PQconninfoFree(options);
@@ -2282,12 +2302,12 @@ conninfo_parse(const char *conninfo, PQExpBuffer errorMessage)
22822302

22832303
/*
22842304
* Get the fallback resources for parameters not specified in the
2285-
* conninfo string.
2305+
* conninfo string nor the service.
22862306
*/
22872307
for (option=options;option->keyword!=NULL;option++)
22882308
{
22892309
if (option->val!=NULL)
2290-
continue;/* Value was in conninfo */
2310+
continue;/* Value was in conninfoor service*/
22912311

22922312
/*
22932313
* Try to get the environment variable fallback
@@ -2322,15 +2342,9 @@ conninfo_parse(const char *conninfo, PQExpBuffer errorMessage)
23222342
}
23232343

23242344
/*
2325-
* Special handling for dbname
2345+
* We used to special-case dbname too, but it's easier to let the
2346+
* backend handle the fallback for that.
23262347
*/
2327-
if (strcmp(option->keyword,"dbname")==0)
2328-
{
2329-
tmp=conninfo_getval(options,"user");
2330-
if (tmp)
2331-
option->val=strdup(tmp);
2332-
continue;
2333-
}
23342348
}
23352349

23362350
returnoptions;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp