* sepgsql_database_post_create * * This routine assigns a default security label on a newly defined * database, and check permission needed for its creation. */
| 30 | * database, and check permission needed for its creation. |
| 31 | */ |
| 32 | void |
| 33 | sepgsql_database_post_create(Oid databaseId, const char *dtemplate) |
| 34 | { |
| 35 | Relation rel; |
| 36 | ScanKeyData skey; |
| 37 | SysScanDesc sscan; |
| 38 | HeapTuple tuple; |
| 39 | char *tcontext; |
| 40 | char *ncontext; |
| 41 | ObjectAddress object; |
| 42 | Form_pg_database datForm; |
| 43 | StringInfoData audit_name; |
| 44 | |
| 45 | /* |
| 46 | * Oid of the source database is not saved in pg_database catalog, so we |
| 47 | * collect its identifier using contextual information. If NULL, its |
| 48 | * default is "template1" according to createdb(). |
| 49 | */ |
| 50 | if (!dtemplate) |
| 51 | dtemplate = "template1"; |
| 52 | |
| 53 | object.classId = DatabaseRelationId; |
| 54 | object.objectId = get_database_oid(dtemplate, false); |
| 55 | object.objectSubId = 0; |
| 56 | |
| 57 | tcontext = sepgsql_get_label(object.classId, |
| 58 | object.objectId, |
| 59 | object.objectSubId); |
| 60 | |
| 61 | /* |
| 62 | * check db_database:{getattr} permission |
| 63 | */ |
| 64 | initStringInfo(&audit_name); |
| 65 | appendStringInfoString(&audit_name, quote_identifier(dtemplate)); |
| 66 | sepgsql_avc_check_perms_label(tcontext, |
| 67 | SEPG_CLASS_DB_DATABASE, |
| 68 | SEPG_DB_DATABASE__GETATTR, |
| 69 | audit_name.data, |
| 70 | true); |
| 71 | |
| 72 | /* |
| 73 | * Compute a default security label of the newly created database based on |
| 74 | * a pair of security label of client and source database. |
| 75 | * |
| 76 | * XXX - upcoming version of libselinux supports to take object name to |
| 77 | * handle special treatment on default security label. |
| 78 | */ |
| 79 | rel = table_open(DatabaseRelationId, AccessShareLock); |
| 80 | |
| 81 | ScanKeyInit(&skey, |
| 82 | Anum_pg_database_oid, |
| 83 | BTEqualStrategyNumber, F_OIDEQ, |
| 84 | ObjectIdGetDatum(databaseId)); |
| 85 | |
| 86 | sscan = systable_beginscan(rel, DatabaseOidIndexId, true, |
| 87 | SnapshotSelf, 1, &skey); |
| 88 | tuple = systable_getnext(sscan); |
| 89 | if (!HeapTupleIsValid(tuple)) |
no test coverage detected