|
8 | 8 | * |
9 | 9 | * |
10 | 10 | * IDENTIFICATION |
11 | | - * $PostgreSQL: pgsql/src/backend/utils/init/postinit.c,v 1.162 2006/03/29 21:17:39 tgl Exp $ |
| 11 | + * $PostgreSQL: pgsql/src/backend/utils/init/postinit.c,v 1.163 2006/04/30 02:09:07 momjian Exp $ |
12 | 12 | * |
13 | 13 | * |
14 | 14 | *------------------------------------------------------------------------- |
|
51 | 51 |
|
52 | 52 |
|
53 | 53 | static bool FindMyDatabase(const char *name, Oid *db_id, Oid *db_tablespace); |
54 | | -static void ReverifyMyDatabase(const char *name); |
| 54 | +static void ReverifyMyDatabase(const char *name, const char *user_name); |
55 | 55 | static void InitCommunication(void); |
56 | 56 | static void ShutdownPostgres(int code, Datum arg); |
57 | 57 | static bool ThereIsAtLeastOneRole(void); |
@@ -130,8 +130,9 @@ FindMyDatabase(const char *name, Oid *db_id, Oid *db_tablespace) |
130 | 130 | * during session startup, this place is also fitting to set up any |
131 | 131 | * database-specific configuration variables. |
132 | 132 | */ |
| 133 | + |
133 | 134 | static void |
134 | | -ReverifyMyDatabase(const char *name) |
| 135 | +ReverifyMyDatabase(const char *name, const char *user_name) |
135 | 136 | { |
136 | 137 | Relation pgdbrel; |
137 | 138 | SysScanDesc pgdbscan; |
@@ -211,6 +212,23 @@ ReverifyMyDatabase(const char *name) |
211 | 212 | (errcode(ERRCODE_TOO_MANY_CONNECTIONS), |
212 | 213 | errmsg("too many connections for database \"%s\"", |
213 | 214 | name))); |
| 215 | + |
| 216 | + /* |
| 217 | + * Checking for privilege to connect to the database |
| 218 | + * We want to bypass the test if we are running in bootstrap mode |
| 219 | + */ |
| 220 | + if (!IsBootstrapProcessingMode()) |
| 221 | + { |
| 222 | + if(pg_database_aclcheck(MyDatabaseId,GetUserId() |
| 223 | + ,ACL_CONNECT) != ACLCHECK_OK ) |
| 224 | + { |
| 225 | + ereport(FATAL, |
| 226 | + (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), |
| 227 | + errmsg("couldn't connect to database %s", NameStr(dbform->datname)), |
| 228 | + errdetail("User %s doesn't have the CONNECTION privilege for database %s.", |
| 229 | + user_name, NameStr(dbform->datname)))); |
| 230 | + } |
| 231 | + } |
214 | 232 | } |
215 | 233 |
|
216 | 234 | /* |
@@ -487,7 +505,7 @@ InitPostgres(const char *dbname, const char *username) |
487 | 505 | * superuser, so the above stuff has to happen first.) |
488 | 506 | */ |
489 | 507 | if (!bootstrap) |
490 | | - ReverifyMyDatabase(dbname); |
| 508 | + ReverifyMyDatabase(dbname,username); |
491 | 509 |
|
492 | 510 | /* |
493 | 511 | * Final phase of relation cache startup: write a new cache file if |
|
0 commit comments