@@ -474,6 +474,7 @@ InitializeSessionUserId(const char *rolename, Oid roleid)
474474{
475475HeapTuple roleTup ;
476476Form_pg_authid rform ;
477+ char * rname ;
477478
478479/*
479480 * Don't do scans if we're bootstrapping, none of the system catalogs
@@ -485,16 +486,25 @@ InitializeSessionUserId(const char *rolename, Oid roleid)
485486AssertState (!OidIsValid (AuthenticatedUserId ));
486487
487488if (rolename != NULL )
489+ {
488490roleTup = SearchSysCache1 (AUTHNAME ,PointerGetDatum (rolename ));
491+ if (!HeapTupleIsValid (roleTup ))
492+ ereport (FATAL ,
493+ (errcode (ERRCODE_INVALID_AUTHORIZATION_SPECIFICATION ),
494+ errmsg ("role \"%s\" does not exist" ,rolename )));
495+ }
489496else
497+ {
490498roleTup = SearchSysCache1 (AUTHOID ,ObjectIdGetDatum (roleid ));
491- if (!HeapTupleIsValid (roleTup ))
492- ereport (FATAL ,
493- (errcode (ERRCODE_INVALID_AUTHORIZATION_SPECIFICATION ),
494- errmsg ("role \"%s\" does not exist" ,rolename )));
499+ if (!HeapTupleIsValid (roleTup ))
500+ ereport (FATAL ,
501+ (errcode (ERRCODE_INVALID_AUTHORIZATION_SPECIFICATION ),
502+ errmsg ("role with OID %u does not exist" ,roleid )));
503+ }
495504
496505rform = (Form_pg_authid )GETSTRUCT (roleTup );
497506roleid = HeapTupleGetOid (roleTup );
507+ rname = NameStr (rform -> rolname );
498508
499509AuthenticatedUserId = roleid ;
500510AuthenticatedUserIsSuperuser = rform -> rolsuper ;
@@ -520,7 +530,7 @@ InitializeSessionUserId(const char *rolename, Oid roleid)
520530ereport (FATAL ,
521531(errcode (ERRCODE_INVALID_AUTHORIZATION_SPECIFICATION ),
522532errmsg ("role \"%s\" is not permitted to log in" ,
523- rolename )));
533+ rname )));
524534
525535/*
526536 * Check connection limit for this role.
@@ -538,11 +548,11 @@ InitializeSessionUserId(const char *rolename, Oid roleid)
538548ereport (FATAL ,
539549(errcode (ERRCODE_TOO_MANY_CONNECTIONS ),
540550errmsg ("too many connections for role \"%s\"" ,
541- rolename )));
551+ rname )));
542552}
543553
544554/* Record username and superuser status as GUC settings too */
545- SetConfigOption ("session_authorization" ,rolename ,
555+ SetConfigOption ("session_authorization" ,rname ,
546556PGC_BACKEND ,PGC_S_OVERRIDE );
547557SetConfigOption ("is_superuser" ,
548558AuthenticatedUserIsSuperuser ?"on" :"off" ,