2020#include "catalog/pg_class.h"
2121#include "catalog/pg_namespace.h"
2222#include "commands/seclabel.h"
23+ #include "lib/stringinfo.h"
24+ #include "utils/builtins.h"
2325#include "utils/fmgroids.h"
2426#include "utils/catcache.h"
2527#include "utils/lsyscache.h"
@@ -49,9 +51,9 @@ sepgsql_attribute_post_create(Oid relOid, AttrNumber attnum)
4951char * scontext ;
5052char * tcontext ;
5153char * ncontext ;
52- char audit_name [2 * NAMEDATALEN + 20 ];
5354ObjectAddress object ;
5455Form_pg_attribute attForm ;
56+ StringInfoData audit_name ;
5557
5658/*
5759 * Only attributes within regular relation have individual security
@@ -94,12 +96,18 @@ sepgsql_attribute_post_create(Oid relOid, AttrNumber attnum)
9496/*
9597 * check db_column:{create} permission
9698 */
97- snprintf (audit_name ,sizeof (audit_name ),"table %s column %s" ,
98- get_rel_name (relOid ),NameStr (attForm -> attname ));
99+ object .classId = RelationRelationId ;
100+ object .objectId = relOid ;
101+ object .objectSubId = 0 ;
102+
103+ initStringInfo (& audit_name );
104+ appendStringInfo (& audit_name ,"%s.%s" ,
105+ getObjectIdentity (& object ),
106+ quote_identifier (NameStr (attForm -> attname )));
99107sepgsql_avc_check_perms_label (ncontext ,
100108SEPG_CLASS_DB_COLUMN ,
101109SEPG_DB_COLUMN__CREATE ,
102- audit_name ,
110+ audit_name . data ,
103111 true);
104112
105113/*
@@ -137,7 +145,7 @@ sepgsql_attribute_drop(Oid relOid, AttrNumber attnum)
137145object .classId = RelationRelationId ;
138146object .objectId = relOid ;
139147object .objectSubId = attnum ;
140- audit_name = getObjectDescription (& object );
148+ audit_name = getObjectIdentity (& object );
141149
142150sepgsql_avc_check_perms (& object ,
143151SEPG_CLASS_DB_COLUMN ,
@@ -168,7 +176,7 @@ sepgsql_attribute_relabel(Oid relOid, AttrNumber attnum,
168176object .classId = RelationRelationId ;
169177object .objectId = relOid ;
170178object .objectSubId = attnum ;
171- audit_name = getObjectDescription (& object );
179+ audit_name = getObjectIdentity (& object );
172180
173181/*
174182 * check db_column:{setattr relabelfrom} permission
@@ -211,7 +219,7 @@ sepgsql_attribute_setattr(Oid relOid, AttrNumber attnum)
211219object .classId = RelationRelationId ;
212220object .objectId = relOid ;
213221object .objectSubId = attnum ;
214- audit_name = getObjectDescription (& object );
222+ audit_name = getObjectIdentity (& object );
215223
216224sepgsql_avc_check_perms (& object ,
217225SEPG_CLASS_DB_COLUMN ,
@@ -236,12 +244,12 @@ sepgsql_relation_post_create(Oid relOid)
236244Form_pg_class classForm ;
237245ObjectAddress object ;
238246uint16 tclass ;
239- const char * tclass_text ;
240247char * scontext ;/* subject */
241248char * tcontext ;/* schema */
242249char * rcontext ;/* relation */
243250char * ccontext ;/* column */
244- char audit_name [2 * NAMEDATALEN + 20 ];
251+ char * nsp_name ;
252+ StringInfoData audit_name ;
245253
246254/*
247255 * Fetch catalog record of the new relation. Because pg_class entry is not
@@ -277,22 +285,19 @@ sepgsql_relation_post_create(Oid relOid)
277285sepgsql_avc_check_perms (& object ,
278286SEPG_CLASS_DB_SCHEMA ,
279287SEPG_DB_SCHEMA__ADD_NAME ,
280- getObjectDescription (& object ),
288+ getObjectIdentity (& object ),
281289true);
282290
283291switch (classForm -> relkind )
284292{
285293case RELKIND_RELATION :
286294tclass = SEPG_CLASS_DB_TABLE ;
287- tclass_text = "table" ;
288295break ;
289296case RELKIND_SEQUENCE :
290297tclass = SEPG_CLASS_DB_SEQUENCE ;
291- tclass_text = "sequence" ;
292298break ;
293299case RELKIND_VIEW :
294300tclass = SEPG_CLASS_DB_VIEW ;
295- tclass_text = "view" ;
296301break ;
297302case RELKIND_INDEX :
298303/* deal with indexes specially; no need for tclass */
@@ -316,12 +321,15 @@ sepgsql_relation_post_create(Oid relOid)
316321/*
317322 * check db_xxx:{create} permission
318323 */
319- snprintf (audit_name ,sizeof (audit_name ),"%s %s" ,
320- tclass_text ,NameStr (classForm -> relname ));
324+ nsp_name = get_namespace_name (classForm -> relnamespace );
325+ initStringInfo (& audit_name );
326+ appendStringInfo (& audit_name ,"%s.%s" ,
327+ quote_identifier (nsp_name ),
328+ quote_identifier (NameStr (classForm -> relname )));
321329sepgsql_avc_check_perms_label (rcontext ,
322330tclass ,
323331SEPG_DB_DATABASE__CREATE ,
324- audit_name ,
332+ audit_name . data ,
325333 true);
326334
327335/*
@@ -358,10 +366,11 @@ sepgsql_relation_post_create(Oid relOid)
358366{
359367attForm = (Form_pg_attribute )GETSTRUCT (atup );
360368
361- snprintf (audit_name ,sizeof (audit_name ),"%s %s column %s" ,
362- tclass_text ,
363- NameStr (classForm -> relname ),
364- NameStr (attForm -> attname ));
369+ resetStringInfo (& audit_name );
370+ appendStringInfo (& audit_name ,"%s.%s.%s" ,
371+ quote_identifier (nsp_name ),
372+ quote_identifier (NameStr (classForm -> relname )),
373+ quote_identifier (NameStr (attForm -> attname )));
365374
366375ccontext = sepgsql_compute_create (scontext ,
367376rcontext ,
@@ -374,7 +383,7 @@ sepgsql_relation_post_create(Oid relOid)
374383sepgsql_avc_check_perms_label (ccontext ,
375384SEPG_CLASS_DB_COLUMN ,
376385SEPG_DB_COLUMN__CREATE ,
377- audit_name ,
386+ audit_name . data ,
378387 true);
379388
380389object .classId = RelationRelationId ;
@@ -436,7 +445,7 @@ sepgsql_relation_drop(Oid relOid)
436445object .classId = NamespaceRelationId ;
437446object .objectId = get_rel_namespace (relOid );
438447object .objectSubId = 0 ;
439- audit_name = getObjectDescription (& object );
448+ audit_name = getObjectIdentity (& object );
440449
441450sepgsql_avc_check_perms (& object ,
442451SEPG_CLASS_DB_SCHEMA ,
@@ -458,7 +467,7 @@ sepgsql_relation_drop(Oid relOid)
458467object .classId = RelationRelationId ;
459468object .objectId = relOid ;
460469object .objectSubId = 0 ;
461- audit_name = getObjectDescription (& object );
470+ audit_name = getObjectIdentity (& object );
462471
463472sepgsql_avc_check_perms (& object ,
464473tclass ,
@@ -489,7 +498,7 @@ sepgsql_relation_drop(Oid relOid)
489498object .classId = RelationRelationId ;
490499object .objectId = relOid ;
491500object .objectSubId = attForm -> attnum ;
492- audit_name = getObjectDescription (& object );
501+ audit_name = getObjectIdentity (& object );
493502
494503sepgsql_avc_check_perms (& object ,
495504SEPG_CLASS_DB_COLUMN ,
@@ -531,7 +540,7 @@ sepgsql_relation_relabel(Oid relOid, const char *seclabel)
531540object .classId = RelationRelationId ;
532541object .objectId = relOid ;
533542object .objectSubId = 0 ;
534- audit_name = getObjectDescription (& object );
543+ audit_name = getObjectIdentity (& object );
535544
536545/*
537546 * check db_xxx:{setattr relabelfrom} permission
@@ -641,7 +650,7 @@ sepgsql_relation_setattr(Oid relOid)
641650object .classId = RelationRelationId ;
642651object .objectId = relOid ;
643652object .objectSubId = 0 ;
644- audit_name = getObjectDescription (& object );
653+ audit_name = getObjectIdentity (& object );
645654
646655sepgsql_avc_check_perms (& object ,
647656tclass ,