OSDN Git Service

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