lib/selinux-utils: tiny cleanup
Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
parent
b105446e69
commit
0735d0efe1
2 changed files with 12 additions and 5 deletions
|
@ -14,16 +14,21 @@
|
||||||
|
|
||||||
#include "selinux-utils.h"
|
#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)
|
int ul_setfscreatecon_from_file(char *orig_file)
|
||||||
{
|
{
|
||||||
if (is_selinux_enabled() > 0) {
|
if (is_selinux_enabled() > 0) {
|
||||||
char *scontext = NULL;
|
char *scontext = NULL;
|
||||||
|
|
||||||
if (getfilecon(orig_file, &scontext) < 0)
|
if (getfilecon(orig_file, &scontext) < 0)
|
||||||
return 1;
|
return -1;
|
||||||
if (setfscreatecon(scontext) < 0) {
|
if (setfscreatecon(scontext) < 0) {
|
||||||
freecon(scontext);
|
freecon(scontext);
|
||||||
return 1;
|
return -1;
|
||||||
}
|
}
|
||||||
freecon(scontext);
|
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 rc == 0 ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* return 0 on success, 0 on error; @cxt returns the default context for @path
|
/* Gets the default context for @path and @st_mode.
|
||||||
* and @st_mode (stat())
|
*
|
||||||
|
* returns 0 on success,
|
||||||
|
* or <0 on error
|
||||||
*/
|
*/
|
||||||
int ul_selinux_get_default_context(const char *path, int st_mode, char **cxt)
|
int ul_selinux_get_default_context(const char *path, int st_mode, char **cxt)
|
||||||
{
|
{
|
||||||
|
|
|
@ -447,7 +447,7 @@ int main(int argc, char **argv)
|
||||||
user_cxt ? : _("Unknown user context"),
|
user_cxt ? : _("Unknown user context"),
|
||||||
ctl.username);
|
ctl.username);
|
||||||
|
|
||||||
if (ul_setfscreatecon_from_file(_PATH_PASSWD))
|
if (ul_setfscreatecon_from_file(_PATH_PASSWD) != 0)
|
||||||
errx(EXIT_FAILURE,
|
errx(EXIT_FAILURE,
|
||||||
_("can't set default context for %s"), _PATH_PASSWD);
|
_("can't set default context for %s"), _PATH_PASSWD);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue