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 */
122123switch (object -> classId )
123124{
125+ case DatabaseRelationId :
126+ sepgsql_database_relabel (object -> objectId ,seclabel );
127+ break ;
128+
124129case NamespaceRelationId :
125130sepgsql_schema_relabel (object -> objectId ,seclabel );
126131break ;
132+
127133case RelationRelationId :
128134if (object -> objectSubId == 0 )
129135sepgsql_relation_relabel (object -> objectId ,
@@ -133,6 +139,7 @@ sepgsql_object_relabel(const ObjectAddress *object, const char *seclabel)
133139object -> objectSubId ,
134140seclabel );
135141break ;
142+
136143case ProcedureRelationId :
137144sepgsql_proc_relabel (object -> objectId ,seclabel );
138145break ;
@@ -315,6 +322,7 @@ exec_object_restorecon(struct selabel_handle * sehnd, Oid catalogId)
315322SnapshotNow ,0 ,NULL );
316323while (HeapTupleIsValid (tuple = systable_getnext (sscan )))
317324{
325+ Form_pg_database datForm ;
318326Form_pg_namespace nspForm ;
319327Form_pg_class relForm ;
320328Form_pg_attribute attForm ;
@@ -330,6 +338,19 @@ exec_object_restorecon(struct selabel_handle * sehnd, Oid catalogId)
330338 */
331339switch (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+
333354case NamespaceRelationId :
334355nspForm = (Form_pg_namespace )GETSTRUCT (tuple );
335356
@@ -506,10 +527,7 @@ sepgsql_restorecon(PG_FUNCTION_ARGS)
506527errmsg ("SELinux: failed to initialize labeling handle: %m" )));
507528PG_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 );
513531exec_object_restorecon (sehnd ,NamespaceRelationId );
514532exec_object_restorecon (sehnd ,RelationRelationId );
515533exec_object_restorecon (sehnd ,AttributeRelationId );