20
20
#include "catalog/pg_class.h"
21
21
#include "catalog/pg_namespace.h"
22
22
#include "commands/seclabel.h"
23
+ #include "lib/stringinfo.h"
24
+ #include "utils/builtins.h"
23
25
#include "utils/fmgroids.h"
24
26
#include "utils/catcache.h"
25
27
#include "utils/lsyscache.h"
@@ -49,9 +51,9 @@ sepgsql_attribute_post_create(Oid relOid, AttrNumber attnum)
49
51
char * scontext ;
50
52
char * tcontext ;
51
53
char * ncontext ;
52
- char audit_name [2 * NAMEDATALEN + 20 ];
53
54
ObjectAddress object ;
54
55
Form_pg_attribute attForm ;
56
+ StringInfoData audit_name ;
55
57
56
58
/*
57
59
* Only attributes within regular relation have individual security
@@ -94,12 +96,18 @@ sepgsql_attribute_post_create(Oid relOid, AttrNumber attnum)
94
96
/*
95
97
* check db_column:{create} permission
96
98
*/
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 )));
99
107
sepgsql_avc_check_perms_label (ncontext ,
100
108
SEPG_CLASS_DB_COLUMN ,
101
109
SEPG_DB_COLUMN__CREATE ,
102
- audit_name ,
110
+ audit_name . data ,
103
111
true);
104
112
105
113
/*
@@ -137,7 +145,7 @@ sepgsql_attribute_drop(Oid relOid, AttrNumber attnum)
137
145
object .classId = RelationRelationId ;
138
146
object .objectId = relOid ;
139
147
object .objectSubId = attnum ;
140
- audit_name = getObjectDescription (& object );
148
+ audit_name = getObjectIdentity (& object );
141
149
142
150
sepgsql_avc_check_perms (& object ,
143
151
SEPG_CLASS_DB_COLUMN ,
@@ -168,7 +176,7 @@ sepgsql_attribute_relabel(Oid relOid, AttrNumber attnum,
168
176
object .classId = RelationRelationId ;
169
177
object .objectId = relOid ;
170
178
object .objectSubId = attnum ;
171
- audit_name = getObjectDescription (& object );
179
+ audit_name = getObjectIdentity (& object );
172
180
173
181
/*
174
182
* check db_column:{setattr relabelfrom} permission
@@ -211,7 +219,7 @@ sepgsql_attribute_setattr(Oid relOid, AttrNumber attnum)
211
219
object .classId = RelationRelationId ;
212
220
object .objectId = relOid ;
213
221
object .objectSubId = attnum ;
214
- audit_name = getObjectDescription (& object );
222
+ audit_name = getObjectIdentity (& object );
215
223
216
224
sepgsql_avc_check_perms (& object ,
217
225
SEPG_CLASS_DB_COLUMN ,
@@ -236,12 +244,12 @@ sepgsql_relation_post_create(Oid relOid)
236
244
Form_pg_class classForm ;
237
245
ObjectAddress object ;
238
246
uint16 tclass ;
239
- const char * tclass_text ;
240
247
char * scontext ; /* subject */
241
248
char * tcontext ; /* schema */
242
249
char * rcontext ; /* relation */
243
250
char * ccontext ; /* column */
244
- char audit_name [2 * NAMEDATALEN + 20 ];
251
+ char * nsp_name ;
252
+ StringInfoData audit_name ;
245
253
246
254
/*
247
255
* Fetch catalog record of the new relation. Because pg_class entry is not
@@ -277,22 +285,19 @@ sepgsql_relation_post_create(Oid relOid)
277
285
sepgsql_avc_check_perms (& object ,
278
286
SEPG_CLASS_DB_SCHEMA ,
279
287
SEPG_DB_SCHEMA__ADD_NAME ,
280
- getObjectDescription (& object ),
288
+ getObjectIdentity (& object ),
281
289
true);
282
290
283
291
switch (classForm -> relkind )
284
292
{
285
293
case RELKIND_RELATION :
286
294
tclass = SEPG_CLASS_DB_TABLE ;
287
- tclass_text = "table" ;
288
295
break ;
289
296
case RELKIND_SEQUENCE :
290
297
tclass = SEPG_CLASS_DB_SEQUENCE ;
291
- tclass_text = "sequence" ;
292
298
break ;
293
299
case RELKIND_VIEW :
294
300
tclass = SEPG_CLASS_DB_VIEW ;
295
- tclass_text = "view" ;
296
301
break ;
297
302
case RELKIND_INDEX :
298
303
/* deal with indexes specially; no need for tclass */
@@ -316,12 +321,15 @@ sepgsql_relation_post_create(Oid relOid)
316
321
/*
317
322
* check db_xxx:{create} permission
318
323
*/
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 )));
321
329
sepgsql_avc_check_perms_label (rcontext ,
322
330
tclass ,
323
331
SEPG_DB_DATABASE__CREATE ,
324
- audit_name ,
332
+ audit_name . data ,
325
333
true);
326
334
327
335
/*
@@ -358,10 +366,11 @@ sepgsql_relation_post_create(Oid relOid)
358
366
{
359
367
attForm = (Form_pg_attribute ) GETSTRUCT (atup );
360
368
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 )));
365
374
366
375
ccontext = sepgsql_compute_create (scontext ,
367
376
rcontext ,
@@ -374,7 +383,7 @@ sepgsql_relation_post_create(Oid relOid)
374
383
sepgsql_avc_check_perms_label (ccontext ,
375
384
SEPG_CLASS_DB_COLUMN ,
376
385
SEPG_DB_COLUMN__CREATE ,
377
- audit_name ,
386
+ audit_name . data ,
378
387
true);
379
388
380
389
object .classId = RelationRelationId ;
@@ -436,7 +445,7 @@ sepgsql_relation_drop(Oid relOid)
436
445
object .classId = NamespaceRelationId ;
437
446
object .objectId = get_rel_namespace (relOid );
438
447
object .objectSubId = 0 ;
439
- audit_name = getObjectDescription (& object );
448
+ audit_name = getObjectIdentity (& object );
440
449
441
450
sepgsql_avc_check_perms (& object ,
442
451
SEPG_CLASS_DB_SCHEMA ,
@@ -458,7 +467,7 @@ sepgsql_relation_drop(Oid relOid)
458
467
object .classId = RelationRelationId ;
459
468
object .objectId = relOid ;
460
469
object .objectSubId = 0 ;
461
- audit_name = getObjectDescription (& object );
470
+ audit_name = getObjectIdentity (& object );
462
471
463
472
sepgsql_avc_check_perms (& object ,
464
473
tclass ,
@@ -489,7 +498,7 @@ sepgsql_relation_drop(Oid relOid)
489
498
object .classId = RelationRelationId ;
490
499
object .objectId = relOid ;
491
500
object .objectSubId = attForm -> attnum ;
492
- audit_name = getObjectDescription (& object );
501
+ audit_name = getObjectIdentity (& object );
493
502
494
503
sepgsql_avc_check_perms (& object ,
495
504
SEPG_CLASS_DB_COLUMN ,
@@ -531,7 +540,7 @@ sepgsql_relation_relabel(Oid relOid, const char *seclabel)
531
540
object .classId = RelationRelationId ;
532
541
object .objectId = relOid ;
533
542
object .objectSubId = 0 ;
534
- audit_name = getObjectDescription (& object );
543
+ audit_name = getObjectIdentity (& object );
535
544
536
545
/*
537
546
* check db_xxx:{setattr relabelfrom} permission
@@ -641,7 +650,7 @@ sepgsql_relation_setattr(Oid relOid)
641
650
object .classId = RelationRelationId ;
642
651
object .objectId = relOid ;
643
652
object .objectSubId = 0 ;
644
- audit_name = getObjectDescription (& object );
653
+ audit_name = getObjectIdentity (& object );
645
654
646
655
sepgsql_avc_check_perms (& object ,
647
656
tclass ,
0 commit comments