@@ -81,7 +81,7 @@ sepgsql_get_label(Oid classId, Oid objectId, int32 subId)
8181 if (security_get_initial_context_raw ("unlabeled" , & unlabeled ) < 0 )
8282 ereport (ERROR ,
8383 (errcode (ERRCODE_INTERNAL_ERROR ),
84- errmsg ("selinux: unable to get initial security label" )));
84+ errmsg ("SELinux: failed to get initial security label" )));
8585 PG_TRY ();
8686 {
8787 label = pstrdup (unlabeled );
@@ -114,7 +114,7 @@ sepgsql_object_relabel(const ObjectAddress *object, const char *seclabel)
114114 security_check_context_raw ((security_context_t ) seclabel ) < 0 )
115115 ereport (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)
154154 char * client_label ;
155155
156156 if (!sepgsql_is_enabled ())
157- ereport (ERROR ,
158- (errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
159- errmsg ("SELinux: now disabled" )));
157+ PG_RETURN_NULL ();
160158
161159 client_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
180178 if (!sepgsql_is_enabled ())
181179 ereport (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
185183 if (selinux_trans_to_raw_context (text_to_cstring (label ),
186184 & raw_label ) < 0 )
187185 ereport (ERROR ,
188186 (errcode (ERRCODE_INTERNAL_ERROR ),
189- errmsg ("SELinux: internal error on mcstrans " )));
187+ errmsg ("SELinux: could not translate security label " )));
190188
191189 PG_TRY ();
192190 {
@@ -200,7 +198,7 @@ sepgsql_mcstrans_in(PG_FUNCTION_ARGS)
200198 PG_END_TRY ();
201199 freecon (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
220218 if (!sepgsql_is_enabled ())
221219 ereport (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
225223 if (selinux_raw_to_trans_context (text_to_cstring (label ),
226224 & qual_label ) < 0 )
227225 ereport (ERROR ,
228226 (errcode (ERRCODE_INTERNAL_ERROR ),
229- errmsg ("SELinux: internal error on mcstrans " )));
227+ errmsg ("SELinux: could not translate security label " )));
230228
231229 PG_TRY ();
232230 {
@@ -240,7 +238,7 @@ sepgsql_mcstrans_out(PG_FUNCTION_ARGS)
240238 PG_END_TRY ();
241239 freecon (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)
360358 break ;
361359
362360 default :
363- elog (ERROR , "Bug? %u is not supported to set initial labels" ,
364- catalogId );
361+ elog (ERROR , "unexpected catalog id: %u" , catalogId );
365362 break ;
366363 }
367364
@@ -387,12 +384,12 @@ exec_object_restorecon(struct selabel_handle *sehnd, Oid catalogId)
387384 }
388385 else if (errno == ENOENT )
389386 ereport (WARNING ,
390- (errmsg ("no valid initial label on %s (type=%d), skipped " ,
387+ (errmsg ("SELinux: no initial label assigned for %s (type=%d), skipping " ,
391388 objname , objtype )));
392389 else
393390 ereport (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 }
397394 systable_endscan (sscan );
398395
@@ -422,16 +419,16 @@ sepgsql_restorecon(PG_FUNCTION_ARGS)
422419 */
423420 if (!sepgsql_is_enabled ())
424421 ereport (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 */
431428 if (!superuser ())
432429 ereport (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)
452449 if (!sehnd )
453450 ereport (ERROR ,
454451 (errcode (ERRCODE_INTERNAL_ERROR ),
455- errmsg ("SELinux internal error " )));
452+ errmsg ("SELinux: failed to initialize labeling handle " )));
456453 PG_TRY ();
457454 {
458455 /*
0 commit comments