chattr-util: generalize chattr manipulation for files with secrets from journalctl
This moves the code for setting chattr file attributes appropriate for "secrets" files from journalctl into generic chattr-util.c code so that we can use it elsewhere. Also, let's reuse the "bitwise" logic already implemented in the chattr code, instead of doing it again.
This commit is contained in:
+18
-3
@@ -34,13 +34,28 @@
|
||||
FS_NOCOW_FL | \
|
||||
FS_PROJINHERIT_FL)
|
||||
|
||||
int chattr_full(const char *path, int fd, unsigned value, unsigned mask, unsigned *ret_previous, unsigned *ret_final, bool fallback);
|
||||
typedef enum ChattrApplyFlags {
|
||||
CHATTR_FALLBACK_BITWISE = 1 << 0,
|
||||
CHATTR_WARN_UNSUPPORTED_FLAGS = 1 << 1,
|
||||
} ChattrApplyFlags;
|
||||
|
||||
int chattr_full(const char *path, int fd, unsigned value, unsigned mask, unsigned *ret_previous, unsigned *ret_final, ChattrApplyFlags flags);
|
||||
|
||||
static inline int chattr_fd(int fd, unsigned value, unsigned mask, unsigned *previous) {
|
||||
return chattr_full(NULL, fd, value, mask, previous, NULL, false);
|
||||
return chattr_full(NULL, fd, value, mask, previous, NULL, 0);
|
||||
}
|
||||
static inline int chattr_path(const char *path, unsigned value, unsigned mask, unsigned *previous) {
|
||||
return chattr_full(path, -1, value, mask, previous, NULL, false);
|
||||
return chattr_full(path, -1, value, mask, previous, NULL, 0);
|
||||
}
|
||||
|
||||
int read_attr_fd(int fd, unsigned *ret);
|
||||
int read_attr_path(const char *p, unsigned *ret);
|
||||
|
||||
/* Combination of chattr flags, that should be appropriate for secrets stored on disk: Secure Remove +
|
||||
* Exclusion from Dumping + Synchronous Writing (i.e. not caching in memory) + In-Place Updating (i.e. not
|
||||
* spurious copies). */
|
||||
#define CHATTR_SECRET_FLAGS (FS_SECRM_FL|FS_NODUMP_FL|FS_SYNC_FL|FS_NOCOW_FL)
|
||||
|
||||
static inline int chattr_secret(int fd, ChattrApplyFlags flags) {
|
||||
return chattr_full(NULL, fd, CHATTR_SECRET_FLAGS, CHATTR_SECRET_FLAGS, NULL, NULL, flags|CHATTR_FALLBACK_BITWISE);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user