OSDN Git Service

Update copyright to 2004.
[pg-rex/syncrep.git] / src / backend / utils / misc / superuser.c
1 /*-------------------------------------------------------------------------
2  *
3  * superuser.c
4  *        The superuser() function.  Determines if user has superuser privilege.
5  *        Also, a function to check for the owner (datdba) of a database.
6  *
7  *
8  * Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
9  * Portions Copyright (c) 1994, Regents of the University of California
10  *
11  *
12  * IDENTIFICATION
13  *        $PostgreSQL: pgsql/src/backend/utils/misc/superuser.c,v 1.29 2004/08/29 04:13:00 momjian Exp $
14  *
15  *-------------------------------------------------------------------------
16  */
17 #include "postgres.h"
18
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"
24
25
26 /*
27  * The Postgres user running this command has Postgres superuser privileges
28  *
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.
33  */
34 bool
35 superuser(void)
36 {
37         return superuser_arg(GetUserId());
38 }
39
40
41 bool
42 superuser_arg(AclId userid)
43 {
44         bool            result = false;
45         HeapTuple       utup;
46
47         /* Special escape path in case you deleted all your users. */
48         if (!IsUnderPostmaster && userid == BOOTSTRAP_USESYSID)
49                 return true;
50
51         utup = SearchSysCache(SHADOWSYSID,
52                                                   Int32GetDatum(userid),
53                                                   0, 0, 0);
54         if (HeapTupleIsValid(utup))
55         {
56                 result = ((Form_pg_shadow) GETSTRUCT(utup))->usesuper;
57                 ReleaseSysCache(utup);
58         }
59         return result;
60 }