user is now defined in terms of the user id, the user name is only computed upon request (for display purposes). This is kind of the opposite of the previous state, which would maintain the user name and compute the user id for permission checks. Besides perhaps saving a few cycles (integer vs string), this now creates a single point of attack for changing the user id during a connection, for purposes of "setuid" functions, etc.
39 lines
1.1 KiB
C
39 lines
1.1 KiB
C
/*-------------------------------------------------------------------------
|
|
*
|
|
* superuser.c
|
|
*
|
|
* The superuser() function. Determines if user has superuser privilege.
|
|
*
|
|
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
*
|
|
*
|
|
* IDENTIFICATION
|
|
* $Header: /cvsroot/pgsql/src/backend/utils/misc/superuser.c,v 1.15 2000/09/06 14:15:22 petere Exp $
|
|
*
|
|
* DESCRIPTION
|
|
* See superuser().
|
|
*-------------------------------------------------------------------------
|
|
*/
|
|
|
|
#include "postgres.h"
|
|
#include "catalog/pg_shadow.h"
|
|
#include "utils/syscache.h"
|
|
#include "miscadmin.h"
|
|
|
|
bool
|
|
superuser(void)
|
|
{
|
|
/*--------------------------------------------------------------------------
|
|
The Postgres user running this command has Postgres superuser
|
|
privileges.
|
|
--------------------------------------------------------------------------*/
|
|
HeapTuple utup;
|
|
|
|
utup = SearchSysCacheTuple(SHADOWSYSID,
|
|
ObjectIdGetDatum(GetUserId()),
|
|
0, 0, 0);
|
|
Assert(utup != NULL);
|
|
return ((Form_pg_shadow) GETSTRUCT(utup))->usesuper;
|
|
}
|