1
0
mirror of https://github.com/postgres/postgres.git synced 2025-08-19 23:22:23 +03:00
Files
postgres/src/backend/utils/misc/superuser.c
PostgreSQL Daemon 2ff501590b Tag appropriate files for rc3
Also performed an initial run through of upgrading our Copyright date to
extend to 2005 ... first run here was very simple ... change everything
where: grep 1996-2004 && the word 'Copyright' ... scanned through the
generated list with 'less' first, and after, to make sure that I only
picked up the right entries ...
2004-12-31 22:04:05 +00:00

61 lines
1.5 KiB
C

/*-------------------------------------------------------------------------
*
* superuser.c
* The superuser() function. Determines if user has superuser privilege.
* Also, a function to check for the owner (datdba) of a database.
*
*
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/misc/superuser.c,v 1.30 2004/12/31 22:02:45 pgsql Exp $
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include "access/heapam.h"
#include "catalog/pg_shadow.h"
#include "commands/dbcommands.h"
#include "utils/syscache.h"
#include "miscadmin.h"
/*
* The Postgres user running this command has Postgres superuser privileges
*
* All code should use either of these two functions to find out
* whether a given user is a superuser, rather than evaluating
* pg_shadow.usesuper directly, so that the escape hatch built in for
* the single-user case works.
*/
bool
superuser(void)
{
return superuser_arg(GetUserId());
}
bool
superuser_arg(AclId userid)
{
bool result = false;
HeapTuple utup;
/* Special escape path in case you deleted all your users. */
if (!IsUnderPostmaster && userid == BOOTSTRAP_USESYSID)
return true;
utup = SearchSysCache(SHADOWSYSID,
Int32GetDatum(userid),
0, 0, 0);
if (HeapTupleIsValid(utup))
{
result = ((Form_pg_shadow) GETSTRUCT(utup))->usesuper;
ReleaseSysCache(utup);
}
return result;
}