The DB contexts backend maps from a pair of object name and class into security contexts. It is used to find the appropriate context for database objects when relabeling a certain database. The returned \fIcontext\fR must be freed using \fBfreecon\fR(3).
.br
\fBselabel_lookup\fR(3) describes the function with its return and error codes.
.sp
The \fIobject_name\fR should be a fully qualified name using the hierarchy of database objects. For example, the \fBpg_class\fR table in the \fBpostgres\fR database and \fBpg_catalog\fR schema should be qualified as:
.RS
.BBpostgres.pg_catalog.pg_class
.RE
.sp
The \fBNOTES\fR section has further information on database support for namespace hierarchies.
.sp
The \fIobject_type\fR argument should be set to one of the following values:
argument specifies the name of a database itself, such as "postgres".
.TP
.BSELABEL_DB_SCHEMA
The
.Iobject_name
argument specifies the name of a schema object, such as "postgres.public".
.TP
.BSELABEL_DB_TABLE
The
.Iobject_name
argument specifies the name of a table object, such as "postgres.public.my_table"
.TP
.BSELABEL_DB_COLUMN
The
.Iobject_name
argument specifies the name of a column object, such as "postgres.public.my_table.user_id"
.TP
.BSELABEL_DB_TUPLE
The
.Iobject_name
argument specifies the name of a table object which contains the tuples to be relabeled, such as "postgresql.public.my_table". Note that we have no way to identify individual tuple objects, except for WHERE clause on DML statements, because it has no name.
argument specifies the name of a procedure object, such as "postgres.public.my_func". Note that we don't support lookup of individual security contexts for procedures which have the same name but different arguments.
It tries to open the specfile designed for SE-PostgreSQL as default, so if another RDBMS uses this interface, it needs to give an explicit specfile designed for that RDBMS (see the \fBFILES\fR section for details).
The database context file used to retrieve a context depends on the \fBSELABEL_OPT_PATH\fR parameter passed to \fBselabel_open\fR(3). If \fINULL\fR, then the \fBSELABEL_OPT_PATH\fR value will default to the active policy database contexts location (as returned by \fBselinux_sepgsql_context_path\fR(3)), otherwise the actual \fBSELABEL_OPT_PATH\fR value specified is used (this option must be used to support databases other than SE-PostgreSQL).
Each line within the database contexts file is as follows:
.RS
.Iobject_typeobject_namecontext
.RE
.sp
Where:
.RS
.Iobject_type
.RS
This is the string representation of the object type shown in the \fBObject Name String Values\fR section.
.RE
.Iobject_name
.RS
The key used to obtain the context based on the \fIobject_type\fR.
.sp
The entry can contain '*' for wildcard matching or '?' for substitution.
.sp
Note that if the '*' is used, then be aware that the order of entries in the file is important. The '*' on its own is used to ensure a default fallback context is assigned and should be the last entry in the \fIobject_type\fR block.
.RE
.Icontext
.RS
The security context that will be applied to the object.
A suitable database contexts file needs to be written for the target RDBMS and the \fBSELABEL_OPT_PATH\fR option must be used in \fBselabel_open\fR(3) to load it.
.IP"2."4
The hierarchy of the namespace for database objects depends on the RDBMS, however the \fIselabel*\fR interfaces do not have any specific support for a namespace hierarchy.
.sp
SE-PostgreSQL has a namespace hierarchy where a database is the top level object with the schema being the next level. Under the schema object there can be other types of objects such as tables and procedures. This hierarchy is supported as follows:
If contexts are to be validated, then the global option \fBSELABEL_OPT_VALIDATE\fR must be set before calling \fBselabel_open\fR(3). If this is not set, then it is possible for an invalid context to be returned.