LCOV - code coverage report
Current view: top level - src/test/modules/dummy_seclabel - dummy_seclabel.c (source / functions) Hit Total Coverage
Test: PostgreSQL 13devel Lines: 16 18 88.9 %
Date: 2019-10-18 16:07:03 Functions: 4 5 80.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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-2019, 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 "fmgr.h"
      17             : #include "miscadmin.h"
      18             : #include "utils/rel.h"
      19             : 
      20           2 : PG_MODULE_MAGIC;
      21             : 
      22             : /* Entrypoint of the module */
      23             : void        _PG_init(void);
      24             : 
      25           2 : PG_FUNCTION_INFO_V1(dummy_seclabel_dummy);
      26             : 
      27             : static void
      28          36 : dummy_object_relabel(const ObjectAddress *object, const char *seclabel)
      29             : {
      30          72 :     if (seclabel == NULL ||
      31          64 :         strcmp(seclabel, "unclassified") == 0 ||
      32          28 :         strcmp(seclabel, "classified") == 0)
      33          26 :         return;
      34             : 
      35          16 :     if (strcmp(seclabel, "secret") == 0 ||
      36           6 :         strcmp(seclabel, "top secret") == 0)
      37             :     {
      38           6 :         if (!superuser())
      39           4 :             ereport(ERROR,
      40             :                     (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
      41             :                      errmsg("only superuser can set '%s' label", seclabel)));
      42           2 :         return;
      43             :     }
      44           4 :     ereport(ERROR,
      45             :             (errcode(ERRCODE_INVALID_NAME),
      46             :              errmsg("'%s' is not a valid security label", seclabel)));
      47             : }
      48             : 
      49             : void
      50           2 : _PG_init(void)
      51             : {
      52           2 :     register_label_provider("dummy", dummy_object_relabel);
      53           2 : }
      54             : 
      55             : /*
      56             :  * This function is here just so that the extension is not completely empty
      57             :  * and the dynamic library is loaded when CREATE EXTENSION runs.
      58             :  */
      59             : Datum
      60           0 : dummy_seclabel_dummy(PG_FUNCTION_ARGS)
      61             : {
      62           0 :     PG_RETURN_VOID();
      63             : }

Generated by: LCOV version 1.13