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

Commit 580cae7

Browse files
committed
Prevent service dbname from defaulting to service name, per bug report
from Michael Fuhr
1 parent cb95ec2 commit 580cae7

File tree

2 files changed

+9
-23
lines changed

2 files changed

+9
-23
lines changed

src/interfaces/libpq/fe-connect.c

+7-21
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.264 2003/11/29 19:52:11 pgsql Exp $
11+
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.265 2003/12/19 21:50:54 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -2367,7 +2367,7 @@ parseServiceInfo(PQconninfoOption *options, PQExpBuffer errorMessage)
23672367
{
23682368
char *service = conninfo_getval(options, "service");
23692369
char *serviceFile = SYSCONFDIR "/pg_service.conf";
2370-
int group_found = 0;
2370+
bool group_found = false;
23712371
int linenr = 0,
23722372
i;
23732373

@@ -2431,9 +2431,9 @@ parseServiceInfo(PQconninfoOption *options, PQExpBuffer errorMessage)
24312431

24322432
if (strncmp(line + 1, service, strlen(service)) == 0 &&
24332433
line[strlen(service) + 1] == ']')
2434-
group_found = 1;
2434+
group_found = true;
24352435
else
2436-
group_found = 0;
2436+
group_found = false;
24372437
}
24382438
else
24392439
{
@@ -2445,7 +2445,7 @@ parseServiceInfo(PQconninfoOption *options, PQExpBuffer errorMessage)
24452445
*/
24462446
char *key,
24472447
*val;
2448-
int found_keyword;
2448+
bool found_keyword;
24492449

24502450
key = line;
24512451
val = strchr(line, '=');
@@ -2460,32 +2460,18 @@ parseServiceInfo(PQconninfoOption *options, PQExpBuffer errorMessage)
24602460
}
24612461
*val++ = '\0';
24622462

2463-
/*
2464-
* If not already set, set the database name to the
2465-
* name of the service
2466-
*/
2467-
for (i = 0; options[i].keyword; i++)
2468-
{
2469-
if (strcmp(options[i].keyword, "dbname") == 0)
2470-
{
2471-
if (options[i].val == NULL)
2472-
options[i].val = strdup(service);
2473-
break;
2474-
}
2475-
}
2476-
24772463
/*
24782464
* Set the parameter --- but don't override any
24792465
* previous explicit setting.
24802466
*/
2481-
found_keyword = 0;
2467+
found_keyword = false;
24822468
for (i = 0; options[i].keyword; i++)
24832469
{
24842470
if (strcmp(options[i].keyword, key) == 0)
24852471
{
24862472
if (options[i].val == NULL)
24872473
options[i].val = strdup(val);
2488-
found_keyword = 1;
2474+
found_keyword = true;
24892475
break;
24902476
}
24912477
}

src/interfaces/libpq/pg_service.conf.sample

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
# multiple services in this file. Each starts with a service name in
66
# brackets. Subsequent lines have connection configuration parameters of
77
# the pattern "param=value". A sample configuration for template1 is
8-
# included in this file. If no database name is specified, it is assumed
9-
# to match the service name. Lines beginning with '#' are comments.
8+
# included in this file. Lines beginning with '#' are comments.
109
#
1110
# Copy this to your sysconf directory (typically /usr/local/pgsql/etc) and
1211
# rename it pg_service.conf.
1312
#
1413
#
1514
#[template1]
15+
#dbname=template1
1616
#user=postgres

0 commit comments

Comments
 (0)