MCPcopy Create free account
hub / github.com/apache/cloudberry / sepgsql_compute_create

Function sepgsql_compute_create

contrib/sepgsql/selinux.c:835–882  ·  view source on GitHub ↗

* sepgsql_compute_create * * It returns a default security context to be assigned on a new database * object. SELinux compute it based on a combination of client, upper object * which owns the new object and object class. * * For example, when a client (staff_u:staff_r:staff_t:s0) tries to create * a new table within a schema (system_u:object_r:sepgsql_schema_t:s0), * SELinux looks-up its

Source from the content-addressed store, hash-verified

833 * tclass: class code (SEPG_CLASS_*) of the new object in creation
834 */
835char *
836sepgsql_compute_create(const char *scontext,
837 const char *tcontext,
838 uint16 tclass,
839 const char *objname)
840{
841 char *ncontext;
842 security_class_t tclass_ex;
843 const char *tclass_name;
844 char *result;
845
846 /* Get external code of the object class */
847 Assert(tclass < SEPG_CLASS_MAX);
848
849 tclass_name = selinux_catalog[tclass].class_name;
850 tclass_ex = string_to_security_class(tclass_name);
851
852 /*
853 * Ask SELinux what is the default context for the given object class on a
854 * pair of security contexts
855 */
856 if (security_compute_create_name_raw(scontext,
857 tcontext,
858 tclass_ex,
859 objname,
860 &ncontext) < 0)
861 ereport(ERROR,
862 (errcode(ERRCODE_INTERNAL_ERROR),
863 errmsg("SELinux could not compute a new context: "
864 "scontext=%s tcontext=%s tclass=%s: %m",
865 scontext, tcontext, tclass_name)));
866
867 /*
868 * libselinux returns malloc()'ed string, so we need to copy it on the
869 * palloc()'ed region.
870 */
871 PG_TRY();
872 {
873 result = pstrdup(ncontext);
874 }
875 PG_FINALLY();
876 {
877 freecon(ncontext);
878 }
879 PG_END_TRY();
880
881 return result;
882}
883
884/*
885 * sepgsql_check_perms

Callers 6

sepgsql_avc_computeFunction · 0.85
sepgsql_proc_post_createFunction · 0.85

Calls 3

errcodeFunction · 0.50
errmsgFunction · 0.50
pstrdupFunction · 0.50

Tested by

no test coverage detected