1717#include "catalog/indexing.h"
1818#include "catalog/pg_attribute.h"
1919#include "catalog/pg_class.h"
20+ #include "catalog/pg_database.h"
2021#include "catalog/pg_namespace.h"
2122#include "catalog/pg_proc.h"
2223#include "commands/dbcommands.h"
@@ -121,9 +122,14 @@ sepgsql_object_relabel(const ObjectAddress *object, const char *seclabel)
121122 */
122123 switch (object -> classId )
123124 {
125+ case DatabaseRelationId :
126+ sepgsql_database_relabel (object -> objectId , seclabel );
127+ break ;
128+
124129 case NamespaceRelationId :
125130 sepgsql_schema_relabel (object -> objectId , seclabel );
126131 break ;
132+
127133 case RelationRelationId :
128134 if (object -> objectSubId == 0 )
129135 sepgsql_relation_relabel (object -> objectId ,
@@ -133,6 +139,7 @@ sepgsql_object_relabel(const ObjectAddress *object, const char *seclabel)
133139 object -> objectSubId ,
134140 seclabel );
135141 break ;
142+
136143 case ProcedureRelationId :
137144 sepgsql_proc_relabel (object -> objectId , seclabel );
138145 break ;
@@ -315,6 +322,7 @@ exec_object_restorecon(struct selabel_handle * sehnd, Oid catalogId)
315322 SnapshotNow , 0 , NULL );
316323 while (HeapTupleIsValid (tuple = systable_getnext (sscan )))
317324 {
325+ Form_pg_database datForm ;
318326 Form_pg_namespace nspForm ;
319327 Form_pg_class relForm ;
320328 Form_pg_attribute attForm ;
@@ -330,6 +338,19 @@ exec_object_restorecon(struct selabel_handle * sehnd, Oid catalogId)
330338 */
331339 switch (catalogId )
332340 {
341+ case DatabaseRelationId :
342+ datForm = (Form_pg_database ) GETSTRUCT (tuple );
343+
344+ objtype = SELABEL_DB_DATABASE ;
345+
346+ objname = quote_object_name (NameStr (datForm -> datname ),
347+ NULL , NULL , NULL );
348+
349+ object .classId = DatabaseRelationId ;
350+ object .objectId = HeapTupleGetOid (tuple );
351+ object .objectSubId = 0 ;
352+ break ;
353+
333354 case NamespaceRelationId :
334355 nspForm = (Form_pg_namespace ) GETSTRUCT (tuple );
335356
@@ -506,10 +527,7 @@ sepgsql_restorecon(PG_FUNCTION_ARGS)
506527 errmsg ("SELinux: failed to initialize labeling handle: %m" )));
507528 PG_TRY ();
508529 {
509- /*
510- * Right now, we have no support labeling on the shared database
511- * objects, such as database, role, or tablespace.
512- */
530+ exec_object_restorecon (sehnd , DatabaseRelationId );
513531 exec_object_restorecon (sehnd , NamespaceRelationId );
514532 exec_object_restorecon (sehnd , RelationRelationId );
515533 exec_object_restorecon (sehnd , AttributeRelationId );
0 commit comments