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-07-19 13:07:20 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 "miscadmin.h"
      17             : #include "utils/rel.h"
      18             : 
      19           2 : PG_MODULE_MAGIC;
      20             : 
      21             : /* Entrypoint of the module */
      22             : void        _PG_init(void);
      23             : 
      24           2 : PG_FUNCTION_INFO_V1(dummy_seclabel_dummy);
      25             : 
      26             : static void
      27          36 : dummy_object_relabel(const ObjectAddress *object, const char *seclabel)
      28             : {
      29          72 :     if (seclabel == NULL ||
      30          64 :         strcmp(seclabel, "unclassified") == 0 ||
      31          28 :         strcmp(seclabel, "classified") == 0)
      32          26 :         return;
      33             : 
      34          16 :     if (strcmp(seclabel, "secret") == 0 ||
      35           6 :         strcmp(seclabel, "top secret") == 0)
      36             :     {
      37           6 :         if (!superuser())
      38           4 :             ereport(ERROR,
      39             :                     (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
      40             :                      errmsg("only superuser can set '%s' label", seclabel)));
      41           2 :         return;
      42             :     }
      43           4 :     ereport(ERROR,
      44             :             (errcode(ERRCODE_INVALID_NAME),
      45             :              errmsg("'%s' is not a valid security label", seclabel)));
      46             : }
      47             : 
      48             : void
      49           2 : _PG_init(void)
      50             : {
      51           2 :     register_label_provider("dummy", dummy_object_relabel);
      52           2 : }
      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
      59           0 : dummy_seclabel_dummy(PG_FUNCTION_ARGS)
      60             : {
      61           0 :     PG_RETURN_VOID();
      62             : }

Generated by: LCOV version 1.13