OSDN Git Service

Remove rel.h from objectaddress.h; only relcache.h is necessary.
[pg-rex/syncrep.git] / contrib / dummy_seclabel / dummy_seclabel.c
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-2011, 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
19 PG_MODULE_MAGIC;
20
21 /* Entrypoint of the module */
22 void            _PG_init(void);
23
24 static void
25 dummy_object_relabel(const ObjectAddress *object, const char *seclabel)
26 {
27         if (seclabel == NULL ||
28                 strcmp(seclabel, "unclassified") == 0 ||
29                 strcmp(seclabel, "classified") == 0)
30                 return;
31
32         if (strcmp(seclabel, "secret") == 0 ||
33                 strcmp(seclabel, "top secret") == 0)
34         {
35                 if (!superuser())
36                         ereport(ERROR,
37                                         (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
38                                          errmsg("only superuser can set '%s' label", seclabel)));
39                 return;
40         }
41         ereport(ERROR,
42                         (errcode(ERRCODE_INVALID_NAME),
43                          errmsg("'%s' is not a valid security label", seclabel)));
44 }
45
46 void
47 _PG_init(void)
48 {
49         register_label_provider("dummy", dummy_object_relabel);
50 }