mirror of
https://github.com/postgres/postgres.git
synced 2025-06-23 14:01:44 +03:00
Convenience routine for checking superuser status.
This commit is contained in:
37
src/backend/utils/misc/Makefile
Normal file
37
src/backend/utils/misc/Makefile
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
#-------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# Makefile--
|
||||||
|
# Makefile for utils/misc
|
||||||
|
#
|
||||||
|
# IDENTIFICATION
|
||||||
|
# $Header: /cvsroot/pgsql/src/backend/utils/misc/Makefile,v 1.1 1996/11/02 02:06:46 bryanh Exp $
|
||||||
|
#
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
SRCDIR = ../../..
|
||||||
|
include ../../../Makefile.global
|
||||||
|
|
||||||
|
INCLUDE_OPT = \
|
||||||
|
-I../../port/$(PORTNAME) \
|
||||||
|
-I../../include \
|
||||||
|
-I../../../include
|
||||||
|
|
||||||
|
CFLAGS += $(INCLUDE_OPT)
|
||||||
|
|
||||||
|
OBJS = superuser.o
|
||||||
|
|
||||||
|
all: SUBSYS.o
|
||||||
|
|
||||||
|
SUBSYS.o: $(OBJS)
|
||||||
|
$(LD) -r -o SUBSYS.o $(OBJS)
|
||||||
|
|
||||||
|
depend dep:
|
||||||
|
$(CC) -MM $(INCLUDE_OPT) *.c >depend
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f SUBSYS.o $(OBJS)
|
||||||
|
|
||||||
|
ifeq (depend,$(wildcard depend))
|
||||||
|
include depend
|
||||||
|
endif
|
||||||
|
|
43
src/backend/utils/misc/superuser.c
Normal file
43
src/backend/utils/misc/superuser.c
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
/*-------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* superuser.c--
|
||||||
|
*
|
||||||
|
* The superuser() function. Determines if user has superuser privilege.
|
||||||
|
*
|
||||||
|
* Copyright (c) 1994, Regents of the University of California
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* IDENTIFICATION
|
||||||
|
* $Header: /cvsroot/pgsql/src/backend/utils/misc/superuser.c,v 1.1 1996/11/02 02:06:47 bryanh Exp $
|
||||||
|
*
|
||||||
|
* DESCRIPTION
|
||||||
|
* See superuser().
|
||||||
|
*-------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <c.h>
|
||||||
|
#include <postgres.h>
|
||||||
|
#include <access/htup.h>
|
||||||
|
#include <utils/syscache.h>
|
||||||
|
#include <catalog/pg_user.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
superuser(void) {
|
||||||
|
/*--------------------------------------------------------------------------
|
||||||
|
The Postgres user running this command has Postgres superuser
|
||||||
|
privileges.
|
||||||
|
--------------------------------------------------------------------------*/
|
||||||
|
extern char *UserName; /* defined in global.c */
|
||||||
|
|
||||||
|
HeapTuple utup;
|
||||||
|
|
||||||
|
utup = SearchSysCacheTuple(USENAME, PointerGetDatum(UserName),
|
||||||
|
0,0,0);
|
||||||
|
Assert(utup != NULL);
|
||||||
|
return ((Form_pg_user)GETSTRUCT(utup))->usesuper;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in New Issue
Block a user