2011-01-24 09:44:48 +08:00
|
|
|
/* -------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* contrib/sepgsql/label.c
|
|
|
|
*
|
|
|
|
* Routines corresponding to relation/attribute objects
|
|
|
|
*
|
2012-01-02 07:01:58 +08:00
|
|
|
* Copyright (c) 2010-2012, PostgreSQL Global Development Group
|
2011-01-24 09:44:48 +08:00
|
|
|
*
|
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#include "postgres.h"
|
|
|
|
|
|
|
|
#include "access/genam.h"
|
|
|
|
#include "access/heapam.h"
|
2012-09-06 02:01:15 +08:00
|
|
|
#include "access/htup_details.h"
|
2011-01-24 09:44:48 +08:00
|
|
|
#include "access/sysattr.h"
|
|
|
|
#include "catalog/indexing.h"
|
2011-02-03 12:39:43 +08:00
|
|
|
#include "catalog/dependency.h"
|
2011-01-24 09:44:48 +08:00
|
|
|
#include "catalog/pg_attribute.h"
|
|
|
|
#include "catalog/pg_class.h"
|
|
|
|
#include "catalog/pg_namespace.h"
|
|
|
|
#include "commands/seclabel.h"
|
|
|
|
#include "utils/fmgroids.h"
|
2012-09-06 02:01:15 +08:00
|
|
|
#include "utils/catcache.h"
|
2011-01-24 09:44:48 +08:00
|
|
|
#include "utils/lsyscache.h"
|
2012-03-10 04:18:45 +08:00
|
|
|
#include "utils/syscache.h"
|
2011-01-24 09:44:48 +08:00
|
|
|
#include "utils/tqual.h"
|
|
|
|
|
|
|
|
#include "sepgsql.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* sepgsql_attribute_post_create
|
|
|
|
*
|
|
|
|
* This routine assigns a default security label on a newly defined
|
|
|
|
* column, using ALTER TABLE ... ADD COLUMN.
|
|
|
|
* Note that this routine is not invoked in the case of CREATE TABLE,
|
|
|
|
* although it also defines columns in addition to table.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
sepgsql_attribute_post_create(Oid relOid, AttrNumber attnum)
|
|
|
|
{
|
2011-12-21 22:12:43 +08:00
|
|
|
Relation rel;
|
|
|
|
ScanKeyData skey[2];
|
|
|
|
SysScanDesc sscan;
|
|
|
|
HeapTuple tuple;
|
|
|
|
char *scontext;
|
2011-04-10 23:42:00 +08:00
|
|
|
char *tcontext;
|
|
|
|
char *ncontext;
|
2012-06-11 03:20:04 +08:00
|
|
|
char audit_name[2 * NAMEDATALEN + 20];
|
2011-04-10 23:42:00 +08:00
|
|
|
ObjectAddress object;
|
2012-06-11 03:20:04 +08:00
|
|
|
Form_pg_attribute attForm;
|
2011-01-24 09:44:48 +08:00
|
|
|
|
|
|
|
/*
|
2011-04-10 23:42:00 +08:00
|
|
|
* Only attributes within regular relation have individual security
|
|
|
|
* labels.
|
2011-01-24 09:44:48 +08:00
|
|
|
*/
|
|
|
|
if (get_rel_relkind(relOid) != RELKIND_RELATION)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
2011-12-21 22:12:43 +08:00
|
|
|
* Compute a default security label of the new column underlying the
|
|
|
|
* specified relation, and check permission to create it.
|
2011-01-24 09:44:48 +08:00
|
|
|
*/
|
2011-12-21 22:12:43 +08:00
|
|
|
rel = heap_open(AttributeRelationId, AccessShareLock);
|
|
|
|
|
|
|
|
ScanKeyInit(&skey[0],
|
|
|
|
Anum_pg_attribute_attrelid,
|
|
|
|
BTEqualStrategyNumber, F_OIDEQ,
|
|
|
|
ObjectIdGetDatum(relOid));
|
|
|
|
ScanKeyInit(&skey[1],
|
|
|
|
Anum_pg_attribute_attnum,
|
|
|
|
BTEqualStrategyNumber, F_INT2EQ,
|
|
|
|
Int16GetDatum(attnum));
|
|
|
|
|
|
|
|
sscan = systable_beginscan(rel, AttributeRelidNumIndexId, true,
|
|
|
|
SnapshotSelf, 2, &skey[0]);
|
|
|
|
|
|
|
|
tuple = systable_getnext(sscan);
|
|
|
|
if (!HeapTupleIsValid(tuple))
|
|
|
|
elog(ERROR, "catalog lookup failed for column %d of relation %u",
|
|
|
|
attnum, relOid);
|
|
|
|
|
|
|
|
attForm = (Form_pg_attribute) GETSTRUCT(tuple);
|
|
|
|
|
2011-01-24 09:44:48 +08:00
|
|
|
scontext = sepgsql_get_client_label();
|
|
|
|
tcontext = sepgsql_get_label(RelationRelationId, relOid, 0);
|
|
|
|
ncontext = sepgsql_compute_create(scontext, tcontext,
|
|
|
|
SEPG_CLASS_DB_COLUMN);
|
2012-06-11 03:20:04 +08:00
|
|
|
|
2011-12-21 22:12:43 +08:00
|
|
|
/*
|
|
|
|
* check db_column:{create} permission
|
|
|
|
*/
|
|
|
|
snprintf(audit_name, sizeof(audit_name), "table %s column %s",
|
|
|
|
get_rel_name(relOid), NameStr(attForm->attname));
|
|
|
|
sepgsql_avc_check_perms_label(ncontext,
|
|
|
|
SEPG_CLASS_DB_COLUMN,
|
|
|
|
SEPG_DB_COLUMN__CREATE,
|
|
|
|
audit_name,
|
|
|
|
true);
|
2011-04-10 23:42:00 +08:00
|
|
|
|
2011-01-24 09:44:48 +08:00
|
|
|
/*
|
|
|
|
* Assign the default security label on a new procedure
|
|
|
|
*/
|
|
|
|
object.classId = RelationRelationId;
|
|
|
|
object.objectId = relOid;
|
|
|
|
object.objectSubId = attnum;
|
|
|
|
SetSecurityLabel(&object, SEPGSQL_LABEL_TAG, ncontext);
|
|
|
|
|
2011-12-21 22:12:43 +08:00
|
|
|
systable_endscan(sscan);
|
|
|
|
heap_close(rel, AccessShareLock);
|
|
|
|
|
2011-01-24 09:44:48 +08:00
|
|
|
pfree(tcontext);
|
|
|
|
pfree(ncontext);
|
|
|
|
}
|
|
|
|
|
2012-03-10 04:18:45 +08:00
|
|
|
/*
|
|
|
|
* sepgsql_attribute_drop
|
|
|
|
*
|
|
|
|
* It checks privileges to drop the supplied column.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
sepgsql_attribute_drop(Oid relOid, AttrNumber attnum)
|
|
|
|
{
|
2012-06-11 03:20:04 +08:00
|
|
|
ObjectAddress object;
|
|
|
|
char *audit_name;
|
2012-03-10 04:18:45 +08:00
|
|
|
|
|
|
|
if (get_rel_relkind(relOid) != RELKIND_RELATION)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* check db_column:{drop} permission
|
|
|
|
*/
|
|
|
|
object.classId = RelationRelationId;
|
|
|
|
object.objectId = relOid;
|
|
|
|
object.objectSubId = attnum;
|
|
|
|
audit_name = getObjectDescription(&object);
|
|
|
|
|
|
|
|
sepgsql_avc_check_perms(&object,
|
|
|
|
SEPG_CLASS_DB_COLUMN,
|
|
|
|
SEPG_DB_COLUMN__DROP,
|
|
|
|
audit_name,
|
|
|
|
true);
|
|
|
|
pfree(audit_name);
|
|
|
|
}
|
|
|
|
|
2011-01-24 09:44:48 +08:00
|
|
|
/*
|
|
|
|
* sepgsql_attribute_relabel
|
|
|
|
*
|
|
|
|
* It checks privileges to relabel the supplied column
|
|
|
|
* by the `seclabel'.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
sepgsql_attribute_relabel(Oid relOid, AttrNumber attnum,
|
|
|
|
const char *seclabel)
|
|
|
|
{
|
2011-04-10 23:42:00 +08:00
|
|
|
ObjectAddress object;
|
2012-06-11 03:20:04 +08:00
|
|
|
char *audit_name;
|
2011-01-24 09:44:48 +08:00
|
|
|
|
|
|
|
if (get_rel_relkind(relOid) != RELKIND_RELATION)
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
|
|
|
|
errmsg("cannot set security label on non-regular columns")));
|
|
|
|
|
2011-02-03 12:39:43 +08:00
|
|
|
object.classId = RelationRelationId;
|
|
|
|
object.objectId = relOid;
|
|
|
|
object.objectSubId = attnum;
|
|
|
|
audit_name = getObjectDescription(&object);
|
2011-01-24 09:44:48 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* check db_column:{setattr relabelfrom} permission
|
|
|
|
*/
|
2011-09-01 20:37:33 +08:00
|
|
|
sepgsql_avc_check_perms(&object,
|
|
|
|
SEPG_CLASS_DB_COLUMN,
|
|
|
|
SEPG_DB_COLUMN__SETATTR |
|
|
|
|
SEPG_DB_COLUMN__RELABELFROM,
|
|
|
|
audit_name,
|
|
|
|
true);
|
2012-06-11 03:20:04 +08:00
|
|
|
|
2011-01-24 09:44:48 +08:00
|
|
|
/*
|
|
|
|
* check db_column:{relabelto} permission
|
|
|
|
*/
|
2011-09-01 20:37:33 +08:00
|
|
|
sepgsql_avc_check_perms_label(seclabel,
|
|
|
|
SEPG_CLASS_DB_COLUMN,
|
|
|
|
SEPG_DB_PROCEDURE__RELABELTO,
|
|
|
|
audit_name,
|
|
|
|
true);
|
2011-02-03 12:39:43 +08:00
|
|
|
pfree(audit_name);
|
2011-01-24 09:44:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* sepgsql_relation_post_create
|
|
|
|
*
|
|
|
|
* The post creation hook of relation/attribute
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
sepgsql_relation_post_create(Oid relOid)
|
|
|
|
{
|
2011-04-10 23:42:00 +08:00
|
|
|
Relation rel;
|
|
|
|
ScanKeyData skey;
|
|
|
|
SysScanDesc sscan;
|
|
|
|
HeapTuple tuple;
|
|
|
|
Form_pg_class classForm;
|
|
|
|
ObjectAddress object;
|
|
|
|
uint16 tclass;
|
2011-12-21 22:12:43 +08:00
|
|
|
const char *tclass_text;
|
2011-04-10 23:42:00 +08:00
|
|
|
char *scontext; /* subject */
|
|
|
|
char *tcontext; /* schema */
|
|
|
|
char *rcontext; /* relation */
|
|
|
|
char *ccontext; /* column */
|
2012-06-11 03:20:04 +08:00
|
|
|
char audit_name[2 * NAMEDATALEN + 20];
|
2011-01-24 09:44:48 +08:00
|
|
|
|
|
|
|
/*
|
2011-04-10 23:42:00 +08:00
|
|
|
* Fetch catalog record of the new relation. Because pg_class entry is not
|
|
|
|
* visible right now, we need to scan the catalog using SnapshotSelf.
|
2011-01-24 09:44:48 +08:00
|
|
|
*/
|
|
|
|
rel = heap_open(RelationRelationId, AccessShareLock);
|
|
|
|
|
|
|
|
ScanKeyInit(&skey,
|
|
|
|
ObjectIdAttributeNumber,
|
|
|
|
BTEqualStrategyNumber, F_OIDEQ,
|
|
|
|
ObjectIdGetDatum(relOid));
|
|
|
|
|
|
|
|
sscan = systable_beginscan(rel, ClassOidIndexId, true,
|
|
|
|
SnapshotSelf, 1, &skey);
|
|
|
|
|
|
|
|
tuple = systable_getnext(sscan);
|
|
|
|
if (!HeapTupleIsValid(tuple))
|
|
|
|
elog(ERROR, "catalog lookup failed for relation %u", relOid);
|
|
|
|
|
|
|
|
classForm = (Form_pg_class) GETSTRUCT(tuple);
|
|
|
|
|
2011-12-21 22:12:43 +08:00
|
|
|
switch (classForm->relkind)
|
|
|
|
{
|
|
|
|
case RELKIND_RELATION:
|
|
|
|
tclass = SEPG_CLASS_DB_TABLE;
|
|
|
|
tclass_text = "table";
|
|
|
|
break;
|
|
|
|
case RELKIND_SEQUENCE:
|
|
|
|
tclass = SEPG_CLASS_DB_SEQUENCE;
|
|
|
|
tclass_text = "sequence";
|
|
|
|
break;
|
|
|
|
case RELKIND_VIEW:
|
|
|
|
tclass = SEPG_CLASS_DB_VIEW;
|
|
|
|
tclass_text = "view";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto out;
|
|
|
|
}
|
2011-01-24 09:44:48 +08:00
|
|
|
|
2011-12-21 22:12:43 +08:00
|
|
|
/*
|
|
|
|
* check db_schema:{add_name} permission of the namespace
|
|
|
|
*/
|
|
|
|
object.classId = NamespaceRelationId;
|
|
|
|
object.objectId = classForm->relnamespace;
|
|
|
|
object.objectSubId = 0;
|
|
|
|
sepgsql_avc_check_perms(&object,
|
|
|
|
SEPG_CLASS_DB_SCHEMA,
|
|
|
|
SEPG_DB_SCHEMA__ADD_NAME,
|
|
|
|
getObjectDescription(&object),
|
|
|
|
true);
|
2012-06-11 03:20:04 +08:00
|
|
|
|
2011-01-24 09:44:48 +08:00
|
|
|
/*
|
2011-04-10 23:42:00 +08:00
|
|
|
* Compute a default security label when we create a new relation object
|
|
|
|
* under the specified namespace.
|
2011-01-24 09:44:48 +08:00
|
|
|
*/
|
|
|
|
scontext = sepgsql_get_client_label();
|
|
|
|
tcontext = sepgsql_get_label(NamespaceRelationId,
|
|
|
|
classForm->relnamespace, 0);
|
|
|
|
rcontext = sepgsql_compute_create(scontext, tcontext, tclass);
|
|
|
|
|
2011-12-21 22:12:43 +08:00
|
|
|
/*
|
|
|
|
* check db_xxx:{create} permission
|
|
|
|
*/
|
|
|
|
snprintf(audit_name, sizeof(audit_name), "%s %s",
|
|
|
|
tclass_text, NameStr(classForm->relname));
|
|
|
|
sepgsql_avc_check_perms_label(rcontext,
|
|
|
|
tclass,
|
|
|
|
SEPG_DB_DATABASE__CREATE,
|
|
|
|
audit_name,
|
|
|
|
true);
|
2012-06-11 03:20:04 +08:00
|
|
|
|
2011-01-24 09:44:48 +08:00
|
|
|
/*
|
|
|
|
* Assign the default security label on the new relation
|
|
|
|
*/
|
|
|
|
object.classId = RelationRelationId;
|
|
|
|
object.objectId = relOid;
|
|
|
|
object.objectSubId = 0;
|
|
|
|
SetSecurityLabel(&object, SEPGSQL_LABEL_TAG, rcontext);
|
|
|
|
|
|
|
|
/*
|
2011-04-10 23:42:00 +08:00
|
|
|
* We also assigns a default security label on columns of the new regular
|
|
|
|
* tables.
|
2011-01-24 09:44:48 +08:00
|
|
|
*/
|
|
|
|
if (classForm->relkind == RELKIND_RELATION)
|
|
|
|
{
|
2011-12-21 22:12:43 +08:00
|
|
|
Relation arel;
|
2012-06-11 03:20:04 +08:00
|
|
|
ScanKeyData akey;
|
|
|
|
SysScanDesc ascan;
|
2011-12-21 22:12:43 +08:00
|
|
|
HeapTuple atup;
|
2012-06-11 03:20:04 +08:00
|
|
|
Form_pg_attribute attForm;
|
2011-12-21 22:12:43 +08:00
|
|
|
|
|
|
|
arel = heap_open(AttributeRelationId, AccessShareLock);
|
2011-01-24 09:44:48 +08:00
|
|
|
|
2011-12-21 22:12:43 +08:00
|
|
|
ScanKeyInit(&akey,
|
|
|
|
Anum_pg_attribute_attrelid,
|
|
|
|
BTEqualStrategyNumber, F_OIDEQ,
|
|
|
|
ObjectIdGetDatum(relOid));
|
|
|
|
|
|
|
|
ascan = systable_beginscan(arel, AttributeRelidNumIndexId, true,
|
|
|
|
SnapshotSelf, 1, &akey);
|
|
|
|
|
|
|
|
while (HeapTupleIsValid(atup = systable_getnext(ascan)))
|
2011-01-24 09:44:48 +08:00
|
|
|
{
|
2011-12-21 22:12:43 +08:00
|
|
|
attForm = (Form_pg_attribute) GETSTRUCT(atup);
|
2011-01-24 09:44:48 +08:00
|
|
|
|
2011-12-21 22:12:43 +08:00
|
|
|
snprintf(audit_name, sizeof(audit_name), "%s %s column %s",
|
|
|
|
tclass_text,
|
|
|
|
NameStr(classForm->relname),
|
|
|
|
NameStr(attForm->attname));
|
|
|
|
|
|
|
|
ccontext = sepgsql_compute_create(scontext,
|
|
|
|
rcontext,
|
|
|
|
SEPG_CLASS_DB_COLUMN);
|
2012-06-11 03:20:04 +08:00
|
|
|
|
2011-12-21 22:12:43 +08:00
|
|
|
/*
|
|
|
|
* check db_column:{create} permission
|
|
|
|
*/
|
|
|
|
sepgsql_avc_check_perms_label(ccontext,
|
|
|
|
SEPG_CLASS_DB_COLUMN,
|
|
|
|
SEPG_DB_COLUMN__CREATE,
|
|
|
|
audit_name,
|
|
|
|
true);
|
2011-01-24 09:44:48 +08:00
|
|
|
|
|
|
|
object.classId = RelationRelationId;
|
|
|
|
object.objectId = relOid;
|
2011-12-21 22:12:43 +08:00
|
|
|
object.objectSubId = attForm->attnum;
|
2011-01-24 09:44:48 +08:00
|
|
|
SetSecurityLabel(&object, SEPGSQL_LABEL_TAG, ccontext);
|
2011-12-21 22:12:43 +08:00
|
|
|
|
|
|
|
pfree(ccontext);
|
2011-01-24 09:44:48 +08:00
|
|
|
}
|
2011-12-21 22:12:43 +08:00
|
|
|
systable_endscan(ascan);
|
|
|
|
heap_close(arel, AccessShareLock);
|
2011-01-24 09:44:48 +08:00
|
|
|
}
|
|
|
|
pfree(rcontext);
|
|
|
|
out:
|
|
|
|
systable_endscan(sscan);
|
|
|
|
heap_close(rel, AccessShareLock);
|
|
|
|
}
|
|
|
|
|
2012-03-10 04:18:45 +08:00
|
|
|
/*
|
|
|
|
* sepgsql_relation_drop
|
|
|
|
*
|
|
|
|
* It checks privileges to drop the supplied relation.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
sepgsql_relation_drop(Oid relOid)
|
|
|
|
{
|
2012-06-11 03:20:04 +08:00
|
|
|
ObjectAddress object;
|
|
|
|
char *audit_name;
|
|
|
|
uint16_t tclass = 0;
|
|
|
|
char relkind;
|
2012-03-10 04:18:45 +08:00
|
|
|
|
|
|
|
relkind = get_rel_relkind(relOid);
|
|
|
|
if (relkind == RELKIND_RELATION)
|
|
|
|
tclass = SEPG_CLASS_DB_TABLE;
|
|
|
|
else if (relkind == RELKIND_SEQUENCE)
|
|
|
|
tclass = SEPG_CLASS_DB_SEQUENCE;
|
|
|
|
else if (relkind == RELKIND_VIEW)
|
|
|
|
tclass = SEPG_CLASS_DB_VIEW;
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* check db_schema:{remove_name} permission
|
|
|
|
*/
|
|
|
|
object.classId = NamespaceRelationId;
|
|
|
|
object.objectId = get_rel_namespace(relOid);
|
|
|
|
object.objectSubId = 0;
|
|
|
|
audit_name = getObjectDescription(&object);
|
|
|
|
|
|
|
|
sepgsql_avc_check_perms(&object,
|
|
|
|
SEPG_CLASS_DB_SCHEMA,
|
|
|
|
SEPG_DB_SCHEMA__REMOVE_NAME,
|
|
|
|
audit_name,
|
|
|
|
true);
|
|
|
|
pfree(audit_name);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* check db_table/sequence/view:{drop} permission
|
|
|
|
*/
|
|
|
|
object.classId = RelationRelationId;
|
|
|
|
object.objectId = relOid;
|
|
|
|
object.objectSubId = 0;
|
|
|
|
audit_name = getObjectDescription(&object);
|
|
|
|
|
|
|
|
sepgsql_avc_check_perms(&object,
|
|
|
|
tclass,
|
|
|
|
SEPG_DB_TABLE__DROP,
|
|
|
|
audit_name,
|
|
|
|
true);
|
|
|
|
pfree(audit_name);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* check db_column:{drop} permission
|
|
|
|
*/
|
|
|
|
if (relkind == RELKIND_RELATION)
|
|
|
|
{
|
2012-06-11 03:20:04 +08:00
|
|
|
Form_pg_attribute attForm;
|
2012-03-10 04:18:45 +08:00
|
|
|
CatCList *attrList;
|
|
|
|
HeapTuple atttup;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
attrList = SearchSysCacheList1(ATTNUM, ObjectIdGetDatum(relOid));
|
2012-06-11 03:20:04 +08:00
|
|
|
for (i = 0; i < attrList->n_members; i++)
|
2012-03-10 04:18:45 +08:00
|
|
|
{
|
|
|
|
atttup = &attrList->members[i]->tuple;
|
|
|
|
attForm = (Form_pg_attribute) GETSTRUCT(atttup);
|
|
|
|
|
|
|
|
if (attForm->attisdropped)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
object.classId = RelationRelationId;
|
|
|
|
object.objectId = relOid;
|
|
|
|
object.objectSubId = attForm->attnum;
|
|
|
|
audit_name = getObjectDescription(&object);
|
|
|
|
|
|
|
|
sepgsql_avc_check_perms(&object,
|
|
|
|
SEPG_CLASS_DB_COLUMN,
|
|
|
|
SEPG_DB_COLUMN__DROP,
|
|
|
|
audit_name,
|
|
|
|
true);
|
|
|
|
pfree(audit_name);
|
|
|
|
}
|
|
|
|
ReleaseCatCacheList(attrList);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-24 09:44:48 +08:00
|
|
|
/*
|
|
|
|
* sepgsql_relation_relabel
|
|
|
|
*
|
|
|
|
* It checks privileges to relabel the supplied relation by the `seclabel'.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
sepgsql_relation_relabel(Oid relOid, const char *seclabel)
|
|
|
|
{
|
2012-06-11 03:20:04 +08:00
|
|
|
ObjectAddress object;
|
2011-01-24 09:44:48 +08:00
|
|
|
char *audit_name;
|
|
|
|
char relkind;
|
|
|
|
uint16_t tclass = 0;
|
|
|
|
|
|
|
|
relkind = get_rel_relkind(relOid);
|
|
|
|
if (relkind == RELKIND_RELATION)
|
|
|
|
tclass = SEPG_CLASS_DB_TABLE;
|
|
|
|
else if (relkind == RELKIND_SEQUENCE)
|
|
|
|
tclass = SEPG_CLASS_DB_SEQUENCE;
|
|
|
|
else if (relkind == RELKIND_VIEW)
|
|
|
|
tclass = SEPG_CLASS_DB_VIEW;
|
|
|
|
else
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
|
|
|
|
errmsg("cannot set security labels on relations except "
|
|
|
|
"for tables, sequences or views")));
|
|
|
|
|
2011-09-01 20:37:33 +08:00
|
|
|
object.classId = RelationRelationId;
|
|
|
|
object.objectId = relOid;
|
|
|
|
object.objectSubId = 0;
|
|
|
|
audit_name = getObjectDescription(&object);
|
2011-01-24 09:44:48 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* check db_xxx:{setattr relabelfrom} permission
|
|
|
|
*/
|
2011-09-01 20:37:33 +08:00
|
|
|
sepgsql_avc_check_perms(&object,
|
|
|
|
tclass,
|
|
|
|
SEPG_DB_TABLE__SETATTR |
|
|
|
|
SEPG_DB_TABLE__RELABELFROM,
|
|
|
|
audit_name,
|
|
|
|
true);
|
2012-06-11 03:20:04 +08:00
|
|
|
|
2011-01-24 09:44:48 +08:00
|
|
|
/*
|
|
|
|
* check db_xxx:{relabelto} permission
|
|
|
|
*/
|
2011-09-01 20:37:33 +08:00
|
|
|
sepgsql_avc_check_perms_label(seclabel,
|
|
|
|
tclass,
|
|
|
|
SEPG_DB_TABLE__RELABELTO,
|
|
|
|
audit_name,
|
|
|
|
true);
|
2011-02-03 12:39:43 +08:00
|
|
|
pfree(audit_name);
|
2011-01-24 09:44:48 +08:00
|
|
|
}
|