From 35656951c896281a1ca581fdc63daecb1681a2d4 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Wed, 10 Apr 2024 10:11:30 -0400 Subject: printf: Implement %Z --- src/printf.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src') 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; -- cgit v1.2.3