@@ -81,7 +81,7 @@ sepgsql_get_label(Oid classId, Oid objectId, int32 subId)
8181if (security_get_initial_context_raw ("unlabeled" ,& unlabeled )< 0 )
8282ereport (ERROR ,
8383(errcode (ERRCODE_INTERNAL_ERROR ),
84- errmsg ("selinux: unable to get initial security label" )));
84+ errmsg ("SELinux: failed to get initial security label" )));
8585PG_TRY ();
8686{
8787label = pstrdup (unlabeled );
@@ -114,7 +114,7 @@ sepgsql_object_relabel(const ObjectAddress *object, const char *seclabel)
114114security_check_context_raw ((security_context_t )seclabel )< 0 )
115115ereport (ERROR ,
116116(errcode (ERRCODE_INVALID_NAME ),
117- errmsg ("invalid security label: \"%s\"" ,seclabel )));
117+ errmsg ("SELinux: invalid security label: \"%s\"" ,seclabel )));
118118/*
119119 * Do actual permission checks for each object classes
120120 */
@@ -154,13 +154,11 @@ sepgsql_getcon(PG_FUNCTION_ARGS)
154154char * client_label ;
155155
156156if (!sepgsql_is_enabled ())
157- ereport (ERROR ,
158- (errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
159- errmsg ("SELinux: now disabled" )));
157+ PG_RETURN_NULL ();
160158
161159client_label = sepgsql_get_client_label ();
162160
163- PG_RETURN_POINTER (cstring_to_text (client_label ));
161+ PG_RETURN_TEXT_P (cstring_to_text (client_label ));
164162}
165163
166164/*
@@ -179,14 +177,14 @@ sepgsql_mcstrans_in(PG_FUNCTION_ARGS)
179177
180178if (!sepgsql_is_enabled ())
181179ereport (ERROR ,
182- (errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
183- errmsg ("SELinux: now disabled " )));
180+ (errcode (ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE ),
181+ errmsg ("sepgsql is not enabled " )));
184182
185183if (selinux_trans_to_raw_context (text_to_cstring (label ),
186184& raw_label )< 0 )
187185ereport (ERROR ,
188186(errcode (ERRCODE_INTERNAL_ERROR ),
189- errmsg ("SELinux:internal error on mcstrans " )));
187+ errmsg ("SELinux:could not translate security label " )));
190188
191189PG_TRY ();
192190{
@@ -200,7 +198,7 @@ sepgsql_mcstrans_in(PG_FUNCTION_ARGS)
200198PG_END_TRY ();
201199freecon (raw_label );
202200
203- PG_RETURN_POINTER (cstring_to_text (result ));
201+ PG_RETURN_TEXT_P (cstring_to_text (result ));
204202}
205203
206204/*
@@ -219,14 +217,14 @@ sepgsql_mcstrans_out(PG_FUNCTION_ARGS)
219217
220218if (!sepgsql_is_enabled ())
221219ereport (ERROR ,
222- (errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
223- errmsg ("SELinux: now disabled " )));
220+ (errcode (ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE ),
221+ errmsg ("sepgsql is not currently enabled " )));
224222
225223if (selinux_raw_to_trans_context (text_to_cstring (label ),
226224& qual_label )< 0 )
227225ereport (ERROR ,
228226(errcode (ERRCODE_INTERNAL_ERROR ),
229- errmsg ("SELinux:internal error on mcstrans " )));
227+ errmsg ("SELinux:could not translate security label " )));
230228
231229PG_TRY ();
232230{
@@ -240,7 +238,7 @@ sepgsql_mcstrans_out(PG_FUNCTION_ARGS)
240238PG_END_TRY ();
241239freecon (qual_label );
242240
243- PG_RETURN_POINTER (cstring_to_text (result ));
241+ PG_RETURN_TEXT_P (cstring_to_text (result ));
244242}
245243
246244/*
@@ -360,8 +358,7 @@ exec_object_restorecon(struct selabel_handle *sehnd, Oid catalogId)
360358break ;
361359
362360default :
363- elog (ERROR ,"Bug? %u is not supported to set initial labels" ,
364- catalogId );
361+ elog (ERROR ,"unexpected catalog id: %u" ,catalogId );
365362break ;
366363}
367364
@@ -387,12 +384,12 @@ exec_object_restorecon(struct selabel_handle *sehnd, Oid catalogId)
387384}
388385else if (errno == ENOENT )
389386ereport (WARNING ,
390- (errmsg ("novalid initial labelon %s (type=%d),skipped " ,
387+ (errmsg ("SELinux: no initial labelassigned for %s (type=%d),skipping " ,
391388objname ,objtype )));
392389else
393390ereport (ERROR ,
394391(errcode (ERRCODE_INTERNAL_ERROR ),
395- errmsg ("libselinux: internal error" )));
392+ errmsg ("SELinux: could not determine initial security label for %s (type=%d)" , objname , objtype )));
396393}
397394systable_endscan (sscan );
398395
@@ -422,16 +419,16 @@ sepgsql_restorecon(PG_FUNCTION_ARGS)
422419 */
423420if (!sepgsql_is_enabled ())
424421ereport (ERROR ,
425- (errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
426- errmsg ("SELinux: now disabled " )));
422+ (errcode (ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE ),
423+ errmsg ("sepgsql is not currently enabled " )));
427424/*
428425 * Check DAC permission. Only superuser can set up initial
429426 * security labels, like root-user in filesystems
430427 */
431428if (!superuser ())
432429ereport (ERROR ,
433430(errcode (ERRCODE_INSUFFICIENT_PRIVILEGE ),
434- errmsg ("must be superuser to restore initial contexts" )));
431+ errmsg ("SELinux: must be superuser to restore initial contexts" )));
435432
436433/*
437434 * Open selabel_lookup(3) stuff. It provides a set of mapping
@@ -452,7 +449,7 @@ sepgsql_restorecon(PG_FUNCTION_ARGS)
452449if (!sehnd )
453450ereport (ERROR ,
454451(errcode (ERRCODE_INTERNAL_ERROR ),
455- errmsg ("SELinux internal error " )));
452+ errmsg ("SELinux: failed to initialize labeling handle " )));
456453PG_TRY ();
457454{
458455/*