LCOV - differential code coverage report
Current view: top level - src/backend/catalog - pg_parameter_acl.c (source / functions) Coverage Total Hit LBC GIC GNC CBC EUB ECB DCB
Current: Differential Code Coverage HEAD vs 15 Lines: 96.0 % 25 24 1 14 2 8 1 12 3
Current Date: 2023-04-08 15:15:32 Functions: 100.0 % 2 2 2 2
Baseline: 15
Baseline Date: 2023-04-08 15:09:40
Legend: Lines: hit not hit

           TLA  Line data    Source code
       1                 : /*-------------------------------------------------------------------------
       2                 :  *
       3                 :  * pg_parameter_acl.c
       4                 :  *    routines to support manipulation of the pg_parameter_acl relation
       5                 :  *
       6                 :  * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
       7                 :  * Portions Copyright (c) 1994, Regents of the University of California
       8                 :  *
       9                 :  *
      10                 :  * IDENTIFICATION
      11                 :  *    src/backend/catalog/pg_parameter_acl.c
      12                 :  *
      13                 :  *-------------------------------------------------------------------------
      14                 :  */
      15                 : #include "postgres.h"
      16                 : 
      17                 : #include "access/table.h"
      18                 : #include "catalog/catalog.h"
      19                 : #include "catalog/indexing.h"
      20                 : #include "catalog/objectaccess.h"
      21                 : #include "catalog/pg_namespace.h"
      22                 : #include "catalog/pg_parameter_acl.h"
      23                 : #include "utils/builtins.h"
      24                 : #include "utils/guc.h"
      25                 : #include "utils/pg_locale.h"
      26                 : #include "utils/rel.h"
      27                 : #include "utils/syscache.h"
      28                 : 
      29                 : 
      30                 : /*
      31                 :  * ParameterAclLookup - Given a configuration parameter name,
      32                 :  * look up the associated configuration parameter ACL's OID.
      33                 :  *
      34                 :  * If missing_ok is false, throw an error if ACL entry not found.  If
      35                 :  * true, just return InvalidOid.
      36                 :  */
      37                 : Oid
      38 GIC          64 : ParameterAclLookup(const char *parameter, bool missing_ok)
      39 ECB             : {
      40                 :     Oid         oid;
      41                 :     char       *parname;
      42                 : 
      43                 :     /* Convert name to the form it should have in pg_parameter_acl... */
      44 GIC          64 :     parname = convert_GUC_name_for_parameter_acl(parameter);
      45 ECB             : 
      46                 :     /* ... and look it up */
      47 GIC          64 :     oid = GetSysCacheOid1(PARAMETERACLNAME, Anum_pg_parameter_acl_oid,
      48 ECB             :                           PointerGetDatum(cstring_to_text(parname)));
      49                 : 
      50 GIC          64 :     if (!OidIsValid(oid) && !missing_ok)
      51 LBC           0 :         ereport(ERROR,
      52 EUB             :                 (errcode(ERRCODE_UNDEFINED_OBJECT),
      53                 :                  errmsg("parameter ACL \"%s\" does not exist", parameter)));
      54                 : 
      55 GIC          64 :     pfree(parname);
      56 ECB             : 
      57 GIC          64 :     return oid;
      58 ECB             : }
      59                 : 
      60                 : /*
      61                 :  * ParameterAclCreate
      62                 :  *
      63                 :  * Add a new tuple to pg_parameter_acl.
      64                 :  *
      65                 :  * parameter: the parameter name to create an entry for.
      66                 :  * Caller should have verified that there's no such entry already.
      67                 :  *
      68                 :  * Returns the new entry's OID.
      69                 :  */
      70                 : Oid
      71 GIC          35 : ParameterAclCreate(const char *parameter)
      72 ECB             : {
      73                 :     Oid         parameterId;
      74                 :     char       *parname;
      75                 :     Relation    rel;
      76                 :     TupleDesc   tupDesc;
      77                 :     HeapTuple   tuple;
      78 GNC          35 :     Datum       values[Natts_pg_parameter_acl] = {0};
      79              35 :     bool        nulls[Natts_pg_parameter_acl] = {0};
      80 ECB             : 
      81                 :     /*
      82                 :      * To prevent cluttering pg_parameter_acl with useless entries, insist
      83                 :      * that the name be valid.
      84                 :      */
      85 GIC          35 :     if (!check_GUC_name_for_parameter_acl(parameter))
      86 CBC           1 :         ereport(ERROR,
      87 ECB             :                 (errcode(ERRCODE_INVALID_NAME),
      88                 :                  errmsg("invalid parameter name \"%s\"",
      89                 :                         parameter)));
      90                 : 
      91                 :     /* Convert name to the form it should have in pg_parameter_acl. */
      92 GIC          34 :     parname = convert_GUC_name_for_parameter_acl(parameter);
      93 ECB             : 
      94                 :     /*
      95                 :      * Create and insert a new record containing a null ACL.
      96                 :      *
      97                 :      * We don't take a strong enough lock to prevent concurrent insertions,
      98                 :      * relying instead on the unique index.
      99                 :      */
     100 GIC          34 :     rel = table_open(ParameterAclRelationId, RowExclusiveLock);
     101 CBC          34 :     tupDesc = RelationGetDescr(rel);
     102 GIC          34 :     parameterId = GetNewOidWithIndex(rel,
     103                 :                                      ParameterAclOidIndexId,
     104 ECB             :                                      Anum_pg_parameter_acl_oid);
     105 CBC          34 :     values[Anum_pg_parameter_acl_oid - 1] = ObjectIdGetDatum(parameterId);
     106              34 :     values[Anum_pg_parameter_acl_parname - 1] =
     107              34 :         PointerGetDatum(cstring_to_text(parname));
     108              34 :     nulls[Anum_pg_parameter_acl_paracl - 1] = true;
     109              34 :     tuple = heap_form_tuple(tupDesc, values, nulls);
     110 GIC          34 :     CatalogTupleInsert(rel, tuple);
     111                 : 
     112 ECB             :     /* Close pg_parameter_acl, but keep lock till commit. */
     113 CBC          34 :     heap_freetuple(tuple);
     114 GIC          34 :     table_close(rel, NoLock);
     115 ECB             : 
     116 GIC          34 :     return parameterId;
     117                 : }
        

Generated by: LCOV version v1.16-55-g56c0a2a