From: Zbigniew Jędrzejewski-Szmek Date: Tue, 21 Sep 2021 16:29:23 +0000 (+0200) Subject: smack: move helper function to smack-util.c X-Git-Tag: v250-rc1~618^2~5 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ce0458be09911e75bfd3b4d802c9594c55a9c98d;p=thirdparty%2Fsystemd.git smack: move helper function to smack-util.c The function was in basic/fileio.c, but it's more appropriate to keep it out of src/basic. Fixes compilation with -Dsmack-run-label= set. --- diff --git a/src/basic/fileio.c b/src/basic/fileio.c index 60a98851082..6a4a65723f0 100644 --- a/src/basic/fileio.c +++ b/src/basic/fileio.c @@ -1434,16 +1434,3 @@ int warn_file_is_world_accessible(const char *filename, struct stat *st, const c filename, st->st_mode & 07777); return 0; } - -int rename_and_apply_smack_floor_label(const char *from, const char *to) { - int r = 0; - if (rename(from, to) < 0) - return -errno; - -#if HAVE_SMACK_RUN_LABEL - r = mac_smack_apply(to, SMACK_ATTR_ACCESS, SMACK_FLOOR_LABEL); - if (r < 0) - return r; -#endif - return r; -} diff --git a/src/basic/fileio.h b/src/basic/fileio.h index 4295b84a85c..9defa4e6bc0 100644 --- a/src/basic/fileio.h +++ b/src/basic/fileio.h @@ -124,5 +124,3 @@ static inline int read_nul_string(FILE *f, size_t limit, char **ret) { int safe_fgetc(FILE *f, char *ret); int warn_file_is_world_accessible(const char *filename, struct stat *st, const char *unit, unsigned line); - -int rename_and_apply_smack_floor_label(const char *temp_path, const char *dest_path); diff --git a/src/firstboot/firstboot.c b/src/firstboot/firstboot.c index 93ce800bd7b..6fdba66f578 100644 --- a/src/firstboot/firstboot.c +++ b/src/firstboot/firstboot.c @@ -32,6 +32,7 @@ #include "proc-cmdline.h" #include "pwquality-util.h" #include "random-util.h" +#include "smack-util.h" #include "string-util.h" #include "strv.h" #include "terminal-util.h" diff --git a/src/shared/smack-util.c b/src/shared/smack-util.c index 2ae11e7f9a7..01958f0b0d9 100644 --- a/src/shared/smack-util.c +++ b/src/shared/smack-util.c @@ -284,3 +284,16 @@ int mac_smack_copy(const char *dest, const char *src) { return 0; } #endif + +int rename_and_apply_smack_floor_label(const char *from, const char *to) { + int r = 0; + if (rename(from, to) < 0) + return -errno; + +#if HAVE_SMACK_RUN_LABEL + r = mac_smack_apply(to, SMACK_ATTR_ACCESS, SMACK_FLOOR_LABEL); + if (r < 0) + return r; +#endif + return r; +} diff --git a/src/shared/smack-util.h b/src/shared/smack-util.h index 36fdc720839..df91c89e01b 100644 --- a/src/shared/smack-util.h +++ b/src/shared/smack-util.h @@ -44,3 +44,5 @@ int mac_smack_apply(const char *path, SmackAttr attr, const char *label); int mac_smack_apply_fd(int fd, SmackAttr attr, const char *label); int mac_smack_apply_pid(pid_t pid, const char *label); int mac_smack_copy(const char *dest, const char *src); + +int rename_and_apply_smack_floor_label(const char *temp_path, const char *dest_path);