lib/selinux-utils: tiny cleanup

Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2021-01-13 15:04:02 +01:00
parent b105446e69
commit 0735d0efe1
2 changed files with 12 additions and 5 deletions

View File

@ -14,16 +14,21 @@
#include "selinux-utils.h"
/* set the SELinux security context used for _creating_ a new file system object
*
* returns 0 on success,
* or <0 on error
*/
int ul_setfscreatecon_from_file(char *orig_file)
{
if (is_selinux_enabled() > 0) {
char *scontext = NULL;
if (getfilecon(orig_file, &scontext) < 0)
return 1;
return -1;
if (setfscreatecon(scontext) < 0) {
freecon(scontext);
return 1;
return -1;
}
freecon(scontext);
}
@ -54,8 +59,10 @@ int ul_selinux_has_access(const char *classstr, const char *perm, char **user_cx
return rc == 0 ? 1 : 0;
}
/* return 0 on success, 0 on error; @cxt returns the default context for @path
* and @st_mode (stat())
/* Gets the default context for @path and @st_mode.
*
* returns 0 on success,
* or <0 on error
*/
int ul_selinux_get_default_context(const char *path, int st_mode, char **cxt)
{

View File

@ -447,7 +447,7 @@ int main(int argc, char **argv)
user_cxt ? : _("Unknown user context"),
ctl.username);
if (ul_setfscreatecon_from_file(_PATH_PASSWD))
if (ul_setfscreatecon_from_file(_PATH_PASSWD) != 0)
errx(EXIT_FAILURE,
_("can't set default context for %s"), _PATH_PASSWD);
}