LCOV - differential code coverage report
Current view: top level - src/backend/catalog - pg_parameter_acl.c (source / functions) Coverage Total Hit UBC GNC CBC DCB
Current: Differential Code Coverage 16@8cea358b128 vs 17@8cea358b128 Lines: 95.8 % 24 23 1 1 22 2
Current Date: 2024-04-14 14:21:10 Functions: 100.0 % 2 2 1 1
Baseline: 16@8cea358b128 Branches: 50.0 % 6 3 3 3
Baseline Date: 2024-04-14 14:21:09 Line coverage date bins:
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed (120,180] days: 100.0 % 1 1 1
(240..) days: 95.7 % 23 22 1 22
Function coverage date bins:
(240..) days: 100.0 % 2 2 1 1
Branch coverage date bins:
(240..) days: 50.0 % 6 3 3 3

 Age         Owner                    Branch data    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-2024, 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/pg_parameter_acl.h"
                                 21                 :                : #include "utils/builtins.h"
                                 22                 :                : #include "utils/guc.h"
                                 23                 :                : #include "utils/rel.h"
                                 24                 :                : #include "utils/syscache.h"
                                 25                 :                : 
                                 26                 :                : 
                                 27                 :                : /*
                                 28                 :                :  * ParameterAclLookup - Given a configuration parameter name,
                                 29                 :                :  * look up the associated configuration parameter ACL's OID.
                                 30                 :                :  *
                                 31                 :                :  * If missing_ok is false, throw an error if ACL entry not found.  If
                                 32                 :                :  * true, just return InvalidOid.
                                 33                 :                :  */
                                 34                 :                : Oid
  739 tgl@sss.pgh.pa.us          35                 :CBC          63 : ParameterAclLookup(const char *parameter, bool missing_ok)
                                 36                 :                : {
                                 37                 :                :     Oid         oid;
                                 38                 :                :     char       *parname;
                                 39                 :                : 
                                 40                 :                :     /* Convert name to the form it should have in pg_parameter_acl... */
                                 41                 :             63 :     parname = convert_GUC_name_for_parameter_acl(parameter);
                                 42                 :                : 
                                 43                 :                :     /* ... and look it up */
                                 44                 :             63 :     oid = GetSysCacheOid1(PARAMETERACLNAME, Anum_pg_parameter_acl_oid,
                                 45                 :                :                           PointerGetDatum(cstring_to_text(parname)));
                                 46                 :                : 
                                 47   [ +  +  -  + ]:             63 :     if (!OidIsValid(oid) && !missing_ok)
  739 tgl@sss.pgh.pa.us          48         [ #  # ]:UBC           0 :         ereport(ERROR,
                                 49                 :                :                 (errcode(ERRCODE_UNDEFINED_OBJECT),
                                 50                 :                :                  errmsg("parameter ACL \"%s\" does not exist", parameter)));
                                 51                 :                : 
  739 tgl@sss.pgh.pa.us          52                 :CBC          63 :     pfree(parname);
                                 53                 :                : 
                                 54                 :             63 :     return oid;
                                 55                 :                : }
                                 56                 :                : 
                                 57                 :                : /*
                                 58                 :                :  * ParameterAclCreate
                                 59                 :                :  *
                                 60                 :                :  * Add a new tuple to pg_parameter_acl.
                                 61                 :                :  *
                                 62                 :                :  * parameter: the parameter name to create an entry for.
                                 63                 :                :  * Caller should have verified that there's no such entry already.
                                 64                 :                :  *
                                 65                 :                :  * Returns the new entry's OID.
                                 66                 :                :  */
                                 67                 :                : Oid
                                 68                 :             34 : ParameterAclCreate(const char *parameter)
                                 69                 :                : {
                                 70                 :                :     Oid         parameterId;
                                 71                 :                :     char       *parname;
                                 72                 :                :     Relation    rel;
                                 73                 :                :     TupleDesc   tupDesc;
                                 74                 :                :     HeapTuple   tuple;
  638 peter@eisentraut.org       75                 :             34 :     Datum       values[Natts_pg_parameter_acl] = {0};
                                 76                 :             34 :     bool        nulls[Natts_pg_parameter_acl] = {0};
                                 77                 :                : 
                                 78                 :                :     /*
                                 79                 :                :      * To prevent cluttering pg_parameter_acl with useless entries, insist
                                 80                 :                :      * that the name be valid.
                                 81                 :                :      */
  176 tgl@sss.pgh.pa.us          82                 :GNC          34 :     check_GUC_name_for_parameter_acl(parameter);
                                 83                 :                : 
                                 84                 :                :     /* Convert name to the form it should have in pg_parameter_acl. */
  739 tgl@sss.pgh.pa.us          85                 :CBC          33 :     parname = convert_GUC_name_for_parameter_acl(parameter);
                                 86                 :                : 
                                 87                 :                :     /*
                                 88                 :                :      * Create and insert a new record containing a null ACL.
                                 89                 :                :      *
                                 90                 :                :      * We don't take a strong enough lock to prevent concurrent insertions,
                                 91                 :                :      * relying instead on the unique index.
                                 92                 :                :      */
                                 93                 :             33 :     rel = table_open(ParameterAclRelationId, RowExclusiveLock);
                                 94                 :             33 :     tupDesc = RelationGetDescr(rel);
                                 95                 :             33 :     parameterId = GetNewOidWithIndex(rel,
                                 96                 :                :                                      ParameterAclOidIndexId,
                                 97                 :                :                                      Anum_pg_parameter_acl_oid);
                                 98                 :             33 :     values[Anum_pg_parameter_acl_oid - 1] = ObjectIdGetDatum(parameterId);
                                 99                 :             33 :     values[Anum_pg_parameter_acl_parname - 1] =
                                100                 :             33 :         PointerGetDatum(cstring_to_text(parname));
                                101                 :             33 :     nulls[Anum_pg_parameter_acl_paracl - 1] = true;
                                102                 :             33 :     tuple = heap_form_tuple(tupDesc, values, nulls);
                                103                 :             33 :     CatalogTupleInsert(rel, tuple);
                                104                 :                : 
                                105                 :                :     /* Close pg_parameter_acl, but keep lock till commit. */
                                106                 :             33 :     heap_freetuple(tuple);
                                107                 :             33 :     table_close(rel, NoLock);
                                108                 :                : 
                                109                 :             33 :     return parameterId;
                                110                 :                : }
        

Generated by: LCOV version 2.1-beta2-3-g6141622