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

Function sepgsql_restorecon

contrib/sepgsql/label.c:880–937  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

878 */
879PG_FUNCTION_INFO_V1(sepgsql_restorecon);
880Datum
881sepgsql_restorecon(PG_FUNCTION_ARGS)
882{
883 struct selabel_handle *sehnd;
884 struct selinux_opt seopts;
885
886 /*
887 * SELinux has to be enabled on the running platform.
888 */
889 if (!sepgsql_is_enabled())
890 ereport(ERROR,
891 (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
892 errmsg("sepgsql is not currently enabled")));
893
894 /*
895 * Check DAC permission. Only superuser can set up initial security
896 * labels, like root-user in filesystems
897 */
898 if (!superuser())
899 ereport(ERROR,
900 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
901 errmsg("SELinux: must be superuser to restore initial contexts")));
902
903 /*
904 * Open selabel_lookup(3) stuff. It provides a set of mapping between an
905 * initial security label and object class/name due to the system setting.
906 */
907 if (PG_ARGISNULL(0))
908 {
909 seopts.type = SELABEL_OPT_UNUSED;
910 seopts.value = NULL;
911 }
912 else
913 {
914 seopts.type = SELABEL_OPT_PATH;
915 seopts.value = TextDatumGetCString(PG_GETARG_DATUM(0));
916 }
917 sehnd = selabel_open(SELABEL_CTX_DB, &seopts, 1);
918 if (!sehnd)
919 ereport(ERROR,
920 (errcode(ERRCODE_INTERNAL_ERROR),
921 errmsg("SELinux: failed to initialize labeling handle: %m")));
922 PG_TRY();
923 {
924 exec_object_restorecon(sehnd, DatabaseRelationId);
925 exec_object_restorecon(sehnd, NamespaceRelationId);
926 exec_object_restorecon(sehnd, RelationRelationId);
927 exec_object_restorecon(sehnd, AttributeRelationId);
928 exec_object_restorecon(sehnd, ProcedureRelationId);
929 }
930 PG_FINALLY();
931 {
932 selabel_close(sehnd);
933 }
934 PG_END_TRY();
935
936 PG_RETURN_BOOL(true);
937}

Callers

nothing calls this directly

Calls 5

sepgsql_is_enabledFunction · 0.85
superuserFunction · 0.85
exec_object_restoreconFunction · 0.85
errcodeFunction · 0.50
errmsgFunction · 0.50

Tested by

no test coverage detected