Commit 194c8f71 authored by Robert Haas's avatar Robert Haas

First round of cleanup of sepgsql code and documentation.

Robert Haas, with a few suggestions from Thom Brown
parent 968bc6fa
/sepgsql.sql /sepgsql.sql
/sepgsql-regtest.fc
/sepgsql-regtest.if
/sepgsql-regtest.pp
/tmp
...@@ -171,12 +171,12 @@ check_relation_privileges(Oid relOid, ...@@ -171,12 +171,12 @@ check_relation_privileges(Oid relOid,
SEPG_DB_TABLE__DELETE)) != 0) SEPG_DB_TABLE__DELETE)) != 0)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("selinux: hardwired security policy violation"))); errmsg("SELinux: hardwired security policy violation")));
if (relkind == RELKIND_TOASTVALUE) if (relkind == RELKIND_TOASTVALUE)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("selinux: hardwired security policy violation"))); errmsg("SELinux: hardwired security policy violation")));
} }
/* /*
......
...@@ -91,7 +91,7 @@ sepgsql_client_auth(Port *port, int status) ...@@ -91,7 +91,7 @@ sepgsql_client_auth(Port *port, int status)
if (getpeercon_raw(port->sock, &context) < 0) if (getpeercon_raw(port->sock, &context) < 0)
ereport(FATAL, ereport(FATAL,
(errcode(ERRCODE_INTERNAL_ERROR), (errcode(ERRCODE_INTERNAL_ERROR),
errmsg("selinux: failed to get the peer label"))); errmsg("SELinux: unable to get peer label")));
sepgsql_set_client_label(context); sepgsql_set_client_label(context);
...@@ -318,7 +318,7 @@ sepgsql_utility_command(Node *parsetree, ...@@ -318,7 +318,7 @@ sepgsql_utility_command(Node *parsetree,
{ {
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("SELinux: LOAD is not allowed anyway."))); errmsg("SELinux: LOAD is not permitted")));
} }
break; break;
default: default:
...@@ -352,8 +352,8 @@ _PG_init(void) ...@@ -352,8 +352,8 @@ _PG_init(void)
*/ */
if (IsUnderPostmaster) if (IsUnderPostmaster)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
errmsg("Not allowed to load SE-PostgreSQL now"))); errmsg("sepgsql must be loaded via shared_preload_libraries")));
/* /*
* Check availability of SELinux on the platform. * Check availability of SELinux on the platform.
...@@ -414,7 +414,7 @@ _PG_init(void) ...@@ -414,7 +414,7 @@ _PG_init(void)
if (getcon_raw(&context) < 0) if (getcon_raw(&context) < 0)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INTERNAL_ERROR), (errcode(ERRCODE_INTERNAL_ERROR),
errmsg("selinux: unable to get security label of server"))); errmsg("SELinux: failed to get server security label")));
sepgsql_set_client_label(context); sepgsql_set_client_label(context);
/* Security label provider hook */ /* Security label provider hook */
......
...@@ -81,7 +81,7 @@ sepgsql_get_label(Oid classId, Oid objectId, int32 subId) ...@@ -81,7 +81,7 @@ sepgsql_get_label(Oid classId, Oid objectId, int32 subId)
if (security_get_initial_context_raw("unlabeled", &unlabeled) < 0) if (security_get_initial_context_raw("unlabeled", &unlabeled) < 0)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INTERNAL_ERROR), (errcode(ERRCODE_INTERNAL_ERROR),
errmsg("selinux: unable to get initial security label"))); errmsg("SELinux: failed to get initial security label")));
PG_TRY(); PG_TRY();
{ {
label = pstrdup(unlabeled); label = pstrdup(unlabeled);
...@@ -114,7 +114,7 @@ sepgsql_object_relabel(const ObjectAddress *object, const char *seclabel) ...@@ -114,7 +114,7 @@ sepgsql_object_relabel(const ObjectAddress *object, const char *seclabel)
security_check_context_raw((security_context_t) seclabel) < 0) security_check_context_raw((security_context_t) seclabel) < 0)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INVALID_NAME), (errcode(ERRCODE_INVALID_NAME),
errmsg("invalid security label: \"%s\"", seclabel))); errmsg("SELinux: invalid security label: \"%s\"", seclabel)));
/* /*
* Do actual permission checks for each object classes * Do actual permission checks for each object classes
*/ */
...@@ -154,13 +154,11 @@ sepgsql_getcon(PG_FUNCTION_ARGS) ...@@ -154,13 +154,11 @@ sepgsql_getcon(PG_FUNCTION_ARGS)
char *client_label; char *client_label;
if (!sepgsql_is_enabled()) if (!sepgsql_is_enabled())
ereport(ERROR, PG_RETURN_NULL();
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("SELinux: now disabled")));
client_label = sepgsql_get_client_label(); client_label = sepgsql_get_client_label();
PG_RETURN_POINTER(cstring_to_text(client_label)); PG_RETURN_TEXT_P(cstring_to_text(client_label));
} }
/* /*
...@@ -179,14 +177,14 @@ sepgsql_mcstrans_in(PG_FUNCTION_ARGS) ...@@ -179,14 +177,14 @@ sepgsql_mcstrans_in(PG_FUNCTION_ARGS)
if (!sepgsql_is_enabled()) if (!sepgsql_is_enabled())
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
errmsg("SELinux: now disabled"))); errmsg("sepgsql is not enabled")));
if (selinux_trans_to_raw_context(text_to_cstring(label), if (selinux_trans_to_raw_context(text_to_cstring(label),
&raw_label) < 0) &raw_label) < 0)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INTERNAL_ERROR), (errcode(ERRCODE_INTERNAL_ERROR),
errmsg("SELinux: internal error on mcstrans"))); errmsg("SELinux: could not translate security label")));
PG_TRY(); PG_TRY();
{ {
...@@ -200,7 +198,7 @@ sepgsql_mcstrans_in(PG_FUNCTION_ARGS) ...@@ -200,7 +198,7 @@ sepgsql_mcstrans_in(PG_FUNCTION_ARGS)
PG_END_TRY(); PG_END_TRY();
freecon(raw_label); freecon(raw_label);
PG_RETURN_POINTER(cstring_to_text(result)); PG_RETURN_TEXT_P(cstring_to_text(result));
} }
/* /*
...@@ -219,14 +217,14 @@ sepgsql_mcstrans_out(PG_FUNCTION_ARGS) ...@@ -219,14 +217,14 @@ sepgsql_mcstrans_out(PG_FUNCTION_ARGS)
if (!sepgsql_is_enabled()) if (!sepgsql_is_enabled())
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
errmsg("SELinux: now disabled"))); errmsg("sepgsql is not currently enabled")));
if (selinux_raw_to_trans_context(text_to_cstring(label), if (selinux_raw_to_trans_context(text_to_cstring(label),
&qual_label) < 0) &qual_label) < 0)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INTERNAL_ERROR), (errcode(ERRCODE_INTERNAL_ERROR),
errmsg("SELinux: internal error on mcstrans"))); errmsg("SELinux: could not translate security label")));
PG_TRY(); PG_TRY();
{ {
...@@ -240,7 +238,7 @@ sepgsql_mcstrans_out(PG_FUNCTION_ARGS) ...@@ -240,7 +238,7 @@ sepgsql_mcstrans_out(PG_FUNCTION_ARGS)
PG_END_TRY(); PG_END_TRY();
freecon(qual_label); freecon(qual_label);
PG_RETURN_POINTER(cstring_to_text(result)); PG_RETURN_TEXT_P(cstring_to_text(result));
} }
/* /*
...@@ -360,8 +358,7 @@ exec_object_restorecon(struct selabel_handle *sehnd, Oid catalogId) ...@@ -360,8 +358,7 @@ exec_object_restorecon(struct selabel_handle *sehnd, Oid catalogId)
break; break;
default: default:
elog(ERROR, "Bug? %u is not supported to set initial labels", elog(ERROR, "unexpected catalog id: %u", catalogId);
catalogId);
break; break;
} }
...@@ -387,12 +384,12 @@ exec_object_restorecon(struct selabel_handle *sehnd, Oid catalogId) ...@@ -387,12 +384,12 @@ exec_object_restorecon(struct selabel_handle *sehnd, Oid catalogId)
} }
else if (errno == ENOENT) else if (errno == ENOENT)
ereport(WARNING, ereport(WARNING,
(errmsg("no valid initial label on %s (type=%d), skipped", (errmsg("SELinux: no initial label assigned for %s (type=%d), skipping",
objname, objtype))); objname, objtype)));
else else
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INTERNAL_ERROR), (errcode(ERRCODE_INTERNAL_ERROR),
errmsg("libselinux: internal error"))); errmsg("SELinux: could not determine initial security label for %s (type=%d)", objname, objtype)));
} }
systable_endscan(sscan); systable_endscan(sscan);
...@@ -422,8 +419,8 @@ sepgsql_restorecon(PG_FUNCTION_ARGS) ...@@ -422,8 +419,8 @@ sepgsql_restorecon(PG_FUNCTION_ARGS)
*/ */
if (!sepgsql_is_enabled()) if (!sepgsql_is_enabled())
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
errmsg("SELinux: now disabled"))); errmsg("sepgsql is not currently enabled")));
/* /*
* Check DAC permission. Only superuser can set up initial * Check DAC permission. Only superuser can set up initial
* security labels, like root-user in filesystems * security labels, like root-user in filesystems
...@@ -431,7 +428,7 @@ sepgsql_restorecon(PG_FUNCTION_ARGS) ...@@ -431,7 +428,7 @@ sepgsql_restorecon(PG_FUNCTION_ARGS)
if (!superuser()) if (!superuser())
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("must be superuser to restore initial contexts"))); errmsg("SELinux: must be superuser to restore initial contexts")));
/* /*
* Open selabel_lookup(3) stuff. It provides a set of mapping * Open selabel_lookup(3) stuff. It provides a set of mapping
...@@ -452,7 +449,7 @@ sepgsql_restorecon(PG_FUNCTION_ARGS) ...@@ -452,7 +449,7 @@ sepgsql_restorecon(PG_FUNCTION_ARGS)
if (!sehnd) if (!sehnd)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INTERNAL_ERROR), (errcode(ERRCODE_INTERNAL_ERROR),
errmsg("SELinux internal error"))); errmsg("SELinux: failed to initialize labeling handle")));
PG_TRY(); PG_TRY();
{ {
/* /*
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment