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

Function sepgsql_check_perms

contrib/sepgsql/selinux.c:898–945  ·  view source on GitHub ↗

* sepgsql_check_perms * * It makes access control decision without userspace caching mechanism. * If SELinux denied the required accesses on the pair of security labels, * it raises an error or returns false. * * scontext: security label of the subject (mostly, peer process) * tcontext: security label of the object being referenced * tclass: class code (SEPG_CLASS_*) of the object being re

Source from the content-addressed store, hash-verified

896 * abort_on_violation: true, if error shall be raised on access violation
897 */
898bool
899sepgsql_check_perms(const char *scontext,
900 const char *tcontext,
901 uint16 tclass,
902 uint32 required,
903 const char *audit_name,
904 bool abort_on_violation)
905{
906 struct av_decision avd;
907 uint32 denied;
908 uint32 audited;
909 bool result = true;
910
911 sepgsql_compute_avd(scontext, tcontext, tclass, &avd);
912
913 denied = required & ~avd.allowed;
914
915 if (sepgsql_get_debug_audit())
916 audited = (denied ? denied : required);
917 else
918 audited = (denied ? (denied & avd.auditdeny)
919 : (required & avd.auditallow));
920
921 if (denied &&
922 sepgsql_getenforce() > 0 &&
923 (avd.flags & SELINUX_AVD_FLAGS_PERMISSIVE) == 0)
924 result = false;
925
926 /*
927 * It records a security audit for the request, if needed. But, when
928 * SE-PgSQL performs 'internal' mode, it needs to keep silent.
929 */
930 if (audited && sepgsql_mode != SEPGSQL_MODE_INTERNAL)
931 {
932 sepgsql_audit_log(denied,
933 scontext,
934 tcontext,
935 tclass,
936 audited,
937 audit_name);
938 }
939
940 if (!result && abort_on_violation)
941 ereport(ERROR,
942 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
943 errmsg("SELinux: security policy violation")));
944 return result;
945}

Callers

nothing calls this directly

Calls 6

sepgsql_compute_avdFunction · 0.85
sepgsql_get_debug_auditFunction · 0.85
sepgsql_getenforceFunction · 0.85
sepgsql_audit_logFunction · 0.85
errcodeFunction · 0.50
errmsgFunction · 0.50

Tested by

no test coverage detected