@@ -474,6 +474,7 @@ InitializeSessionUserId(const char *rolename, Oid roleid)
474
474
{
475
475
HeapTuple roleTup ;
476
476
Form_pg_authid rform ;
477
+ char * rname ;
477
478
478
479
/*
479
480
* Don't do scans if we're bootstrapping, none of the system catalogs
@@ -485,16 +486,25 @@ InitializeSessionUserId(const char *rolename, Oid roleid)
485
486
AssertState (!OidIsValid (AuthenticatedUserId ));
486
487
487
488
if (rolename != NULL )
489
+ {
488
490
roleTup = 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
+ }
489
496
else
497
+ {
490
498
roleTup = 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
+ }
495
504
496
505
rform = (Form_pg_authid ) GETSTRUCT (roleTup );
497
506
roleid = HeapTupleGetOid (roleTup );
507
+ rname = NameStr (rform -> rolname );
498
508
499
509
AuthenticatedUserId = roleid ;
500
510
AuthenticatedUserIsSuperuser = rform -> rolsuper ;
@@ -520,7 +530,7 @@ InitializeSessionUserId(const char *rolename, Oid roleid)
520
530
ereport (FATAL ,
521
531
(errcode (ERRCODE_INVALID_AUTHORIZATION_SPECIFICATION ),
522
532
errmsg ("role \"%s\" is not permitted to log in" ,
523
- rolename )));
533
+ rname )));
524
534
525
535
/*
526
536
* Check connection limit for this role.
@@ -538,11 +548,11 @@ InitializeSessionUserId(const char *rolename, Oid roleid)
538
548
ereport (FATAL ,
539
549
(errcode (ERRCODE_TOO_MANY_CONNECTIONS ),
540
550
errmsg ("too many connections for role \"%s\"" ,
541
- rolename )));
551
+ rname )));
542
552
}
543
553
544
554
/* Record username and superuser status as GUC settings too */
545
- SetConfigOption ("session_authorization" , rolename ,
555
+ SetConfigOption ("session_authorization" , rname ,
546
556
PGC_BACKEND , PGC_S_OVERRIDE );
547
557
SetConfigOption ("is_superuser" ,
548
558
AuthenticatedUserIsSuperuser ? "on" : "off" ,
0 commit comments