* 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. */
| 40 | * although it also defines columns in addition to table. |
| 41 | */ |
| 42 | void |
| 43 | sepgsql_attribute_post_create(Oid relOid, AttrNumber attnum) |
| 44 | { |
| 45 | Relation rel; |
| 46 | ScanKeyData skey[2]; |
| 47 | SysScanDesc sscan; |
| 48 | HeapTuple tuple; |
| 49 | char *scontext; |
| 50 | char *tcontext; |
| 51 | char *ncontext; |
| 52 | ObjectAddress object; |
| 53 | Form_pg_attribute attForm; |
| 54 | StringInfoData audit_name; |
| 55 | char relkind = get_rel_relkind(relOid); |
| 56 | |
| 57 | /* |
| 58 | * Only attributes within regular relations or partition relations have |
| 59 | * individual security labels. |
| 60 | */ |
| 61 | if (relkind != RELKIND_RELATION && relkind != RELKIND_PARTITIONED_TABLE) |
| 62 | return; |
| 63 | |
| 64 | /* |
| 65 | * Compute a default security label of the new column underlying the |
| 66 | * specified relation, and check permission to create it. |
| 67 | */ |
| 68 | rel = table_open(AttributeRelationId, AccessShareLock); |
| 69 | |
| 70 | ScanKeyInit(&skey[0], |
| 71 | Anum_pg_attribute_attrelid, |
| 72 | BTEqualStrategyNumber, F_OIDEQ, |
| 73 | ObjectIdGetDatum(relOid)); |
| 74 | ScanKeyInit(&skey[1], |
| 75 | Anum_pg_attribute_attnum, |
| 76 | BTEqualStrategyNumber, F_INT2EQ, |
| 77 | Int16GetDatum(attnum)); |
| 78 | |
| 79 | sscan = systable_beginscan(rel, AttributeRelidNumIndexId, true, |
| 80 | SnapshotSelf, 2, &skey[0]); |
| 81 | |
| 82 | tuple = systable_getnext(sscan); |
| 83 | if (!HeapTupleIsValid(tuple)) |
| 84 | elog(ERROR, "could not find tuple for column %d of relation %u", |
| 85 | attnum, relOid); |
| 86 | |
| 87 | attForm = (Form_pg_attribute) GETSTRUCT(tuple); |
| 88 | |
| 89 | scontext = sepgsql_get_client_label(); |
| 90 | tcontext = sepgsql_get_label(RelationRelationId, relOid, 0); |
| 91 | ncontext = sepgsql_compute_create(scontext, tcontext, |
| 92 | SEPG_CLASS_DB_COLUMN, |
| 93 | NameStr(attForm->attname)); |
| 94 | |
| 95 | /* |
| 96 | * check db_column:{create} permission |
| 97 | */ |
| 98 | object.classId = RelationRelationId; |
| 99 | object.objectId = relOid; |
no test coverage detected