diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2024-04-10 10:11:30 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2024-04-10 13:15:49 -0400 |
commit | 35656951c896281a1ca581fdc63daecb1681a2d4 (patch) | |
tree | 70e4a769204c998e1c2603c4365ebeca4caf164d /src | |
parent | 8f6b0c1b360f2fea3f7f6563808513cbdd51df80 (diff) | |
download | bfs-35656951c896281a1ca581fdc63daecb1681a2d4.tar.xz |
printf: Implement %Z
Diffstat (limited to 'src')
-rw-r--r-- | src/printf.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/printf.c b/src/printf.c index 487f039..3b8269e 100644 --- a/src/printf.c +++ b/src/printf.c @@ -12,6 +12,7 @@ #include "dir.h" #include "dstring.h" #include "expr.h" +#include "fsade.h" #include "mtab.h" #include "pwcache.h" #include "stat.h" @@ -571,6 +572,19 @@ static int bfs_printf_Y(CFILE *cfile, const struct bfs_fmt *fmt, const struct BF return ret; } +/** %Z: SELinux context */ +attr(maybe_unused) +static int bfs_printf_Z(CFILE *cfile, const struct bfs_fmt *fmt, const struct BFTW *ftwbuf) { + char *con = bfs_getfilecon(ftwbuf); + if (!con) { + return -1; + } + + int ret = dyn_fprintf(cfile->file, fmt, con); + bfs_freecon(con); + return ret; +} + /** * Append a literal string to the chain. */ @@ -840,6 +854,15 @@ int bfs_printf_parse(const struct bfs_ctx *ctx, struct bfs_expr *expr, const cha case 'Y': fmt.fn = bfs_printf_Y; break; + case 'Z': +#if BFS_CAN_CHECK_CONTEXT + fmt.fn = bfs_printf_Z; + break; +#else + bfs_expr_error(ctx, expr); + bfs_error(ctx, "Missing platform support for '%%%c'.\n", c); + goto fmt_error; +#endif case 'A': fmt.stat_field = BFS_STAT_ATIME; |