PostgreSQL Source Code  git master
dummy_seclabel.c
Go to the documentation of this file.
1 /*
2  * dummy_seclabel.c
3  *
4  * Dummy security label provider.
5  *
6  * This module does not provide anything worthwhile from a security
7  * perspective, but allows regression testing independent of platform-specific
8  * features like SELinux.
9  *
10  * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
11  * Portions Copyright (c) 1994, Regents of the University of California
12  */
13 #include "postgres.h"
14 
15 #include "commands/seclabel.h"
16 #include "miscadmin.h"
17 #include "utils/rel.h"
18 
20 
21 /* Entrypoint of the module */
22 void _PG_init(void);
23 
25 
26 static void
27 dummy_object_relabel(const ObjectAddress *object, const char *seclabel)
28 {
29  if (seclabel == NULL ||
30  strcmp(seclabel, "unclassified") == 0 ||
31  strcmp(seclabel, "classified") == 0)
32  return;
33 
34  if (strcmp(seclabel, "secret") == 0 ||
35  strcmp(seclabel, "top secret") == 0)
36  {
37  if (!superuser())
38  ereport(ERROR,
39  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
40  errmsg("only superuser can set '%s' label", seclabel)));
41  return;
42  }
43  ereport(ERROR,
44  (errcode(ERRCODE_INVALID_NAME),
45  errmsg("'%s' is not a valid security label", seclabel)));
46 }
47 
48 void
49 _PG_init(void)
50 {
52 }
53 
54 /*
55  * This function is here just so that the extension is not completely empty
56  * and the dynamic library is loaded when CREATE EXTENSION runs.
57  */
58 Datum
60 {
62 }
int errcode(int sqlerrcode)
Definition: elog.c:575
bool superuser(void)
Definition: superuser.c:47
void _PG_init(void)
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
uintptr_t Datum
Definition: postgres.h:372
Datum dummy_seclabel_dummy(PG_FUNCTION_ARGS)
void register_label_provider(const char *provider_name, check_object_relabel_type hook)
Definition: seclabel.c:493
#define PG_RETURN_VOID()
Definition: fmgr.h:309
PG_FUNCTION_INFO_V1(dummy_seclabel_dummy)
PG_MODULE_MAGIC
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define PG_FUNCTION_ARGS
Definition: fmgr.h:158
static void dummy_object_relabel(const ObjectAddress *object, const char *seclabel)