@@ -81,7 +81,7 @@ sepgsql_get_label(Oid classId, Oid objectId, int32 subId)
81
81
if (security_get_initial_context_raw ("unlabeled" , & unlabeled ) < 0 )
82
82
ereport (ERROR ,
83
83
(errcode (ERRCODE_INTERNAL_ERROR ),
84
- errmsg ("selinux: unable to get initial security label" )));
84
+ errmsg ("SELinux: failed to get initial security label" )));
85
85
PG_TRY ();
86
86
{
87
87
label = pstrdup (unlabeled );
@@ -114,7 +114,7 @@ sepgsql_object_relabel(const ObjectAddress *object, const char *seclabel)
114
114
security_check_context_raw ((security_context_t ) seclabel ) < 0 )
115
115
ereport (ERROR ,
116
116
(errcode (ERRCODE_INVALID_NAME ),
117
- errmsg ("invalid security label: \"%s\"" , seclabel )));
117
+ errmsg ("SELinux: invalid security label: \"%s\"" , seclabel )));
118
118
/*
119
119
* Do actual permission checks for each object classes
120
120
*/
@@ -154,13 +154,11 @@ sepgsql_getcon(PG_FUNCTION_ARGS)
154
154
char * client_label ;
155
155
156
156
if (!sepgsql_is_enabled ())
157
- ereport (ERROR ,
158
- (errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
159
- errmsg ("SELinux: now disabled" )));
157
+ PG_RETURN_NULL ();
160
158
161
159
client_label = sepgsql_get_client_label ();
162
160
163
- PG_RETURN_POINTER (cstring_to_text (client_label ));
161
+ PG_RETURN_TEXT_P (cstring_to_text (client_label ));
164
162
}
165
163
166
164
/*
@@ -179,14 +177,14 @@ sepgsql_mcstrans_in(PG_FUNCTION_ARGS)
179
177
180
178
if (!sepgsql_is_enabled ())
181
179
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 " )));
184
182
185
183
if (selinux_trans_to_raw_context (text_to_cstring (label ),
186
184
& raw_label ) < 0 )
187
185
ereport (ERROR ,
188
186
(errcode (ERRCODE_INTERNAL_ERROR ),
189
- errmsg ("SELinux: internal error on mcstrans " )));
187
+ errmsg ("SELinux: could not translate security label " )));
190
188
191
189
PG_TRY ();
192
190
{
@@ -200,7 +198,7 @@ sepgsql_mcstrans_in(PG_FUNCTION_ARGS)
200
198
PG_END_TRY ();
201
199
freecon (raw_label );
202
200
203
- PG_RETURN_POINTER (cstring_to_text (result ));
201
+ PG_RETURN_TEXT_P (cstring_to_text (result ));
204
202
}
205
203
206
204
/*
@@ -219,14 +217,14 @@ sepgsql_mcstrans_out(PG_FUNCTION_ARGS)
219
217
220
218
if (!sepgsql_is_enabled ())
221
219
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 " )));
224
222
225
223
if (selinux_raw_to_trans_context (text_to_cstring (label ),
226
224
& qual_label ) < 0 )
227
225
ereport (ERROR ,
228
226
(errcode (ERRCODE_INTERNAL_ERROR ),
229
- errmsg ("SELinux: internal error on mcstrans " )));
227
+ errmsg ("SELinux: could not translate security label " )));
230
228
231
229
PG_TRY ();
232
230
{
@@ -240,7 +238,7 @@ sepgsql_mcstrans_out(PG_FUNCTION_ARGS)
240
238
PG_END_TRY ();
241
239
freecon (qual_label );
242
240
243
- PG_RETURN_POINTER (cstring_to_text (result ));
241
+ PG_RETURN_TEXT_P (cstring_to_text (result ));
244
242
}
245
243
246
244
/*
@@ -360,8 +358,7 @@ exec_object_restorecon(struct selabel_handle *sehnd, Oid catalogId)
360
358
break ;
361
359
362
360
default :
363
- elog (ERROR , "Bug? %u is not supported to set initial labels" ,
364
- catalogId );
361
+ elog (ERROR , "unexpected catalog id: %u" , catalogId );
365
362
break ;
366
363
}
367
364
@@ -387,12 +384,12 @@ exec_object_restorecon(struct selabel_handle *sehnd, Oid catalogId)
387
384
}
388
385
else if (errno == ENOENT )
389
386
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 " ,
391
388
objname , objtype )));
392
389
else
393
390
ereport (ERROR ,
394
391
(errcode (ERRCODE_INTERNAL_ERROR ),
395
- errmsg ("libselinux: internal error" )));
392
+ errmsg ("SELinux: could not determine initial security label for %s (type=%d)" , objname , objtype )));
396
393
}
397
394
systable_endscan (sscan );
398
395
@@ -422,16 +419,16 @@ sepgsql_restorecon(PG_FUNCTION_ARGS)
422
419
*/
423
420
if (!sepgsql_is_enabled ())
424
421
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 " )));
427
424
/*
428
425
* Check DAC permission. Only superuser can set up initial
429
426
* security labels, like root-user in filesystems
430
427
*/
431
428
if (!superuser ())
432
429
ereport (ERROR ,
433
430
(errcode (ERRCODE_INSUFFICIENT_PRIVILEGE ),
434
- errmsg ("must be superuser to restore initial contexts" )));
431
+ errmsg ("SELinux: must be superuser to restore initial contexts" )));
435
432
436
433
/*
437
434
* Open selabel_lookup(3) stuff. It provides a set of mapping
@@ -452,7 +449,7 @@ sepgsql_restorecon(PG_FUNCTION_ARGS)
452
449
if (!sehnd )
453
450
ereport (ERROR ,
454
451
(errcode (ERRCODE_INTERNAL_ERROR ),
455
- errmsg ("SELinux internal error " )));
452
+ errmsg ("SELinux: failed to initialize labeling handle " )));
456
453
PG_TRY ();
457
454
{
458
455
/*
0 commit comments