1 /*-------------------------------------------------------------------------
4 * The superuser() function. Determines if user has superuser privilege.
5 * Also, a function to check for the owner (datdba) of a database.
8 * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
9 * Portions Copyright (c) 1994, Regents of the University of California
13 * $Header: /cvsroot/pgsql/src/backend/utils/misc/superuser.c,v 1.26 2003/06/27 14:45:31 petere Exp $
15 *-------------------------------------------------------------------------
19 #include "access/heapam.h"
20 #include "catalog/pg_shadow.h"
21 #include "commands/dbcommands.h"
22 #include "utils/syscache.h"
23 #include "miscadmin.h"
27 * The Postgres user running this command has Postgres superuser privileges
29 * All code should use either of these two functions to find out
30 * whether a given user is a superuser, rather than evaluating
31 * pg_shadow.usesuper directly, so that the escape hatch built in for
32 * the single-user case works.
37 return superuser_arg(GetUserId());
42 superuser_arg(AclId userid)
47 /* Special escape path in case you deleted all your users. */
48 if (!IsUnderPostmaster && userid == BOOTSTRAP_USESYSID)
51 utup = SearchSysCache(SHADOWSYSID,
52 Int32GetDatum(userid),
54 if (HeapTupleIsValid(utup))
56 result = ((Form_pg_shadow) GETSTRUCT(utup))->usesuper;
57 ReleaseSysCache(utup);