diff options
author | Ronan Pigott <ronan@rjp.ie> | 2022-12-16 01:26:25 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-16 10:26:25 +0200 |
commit | b4e81ca17240281fc802a662f5ce4e78a767c2b9 (patch) | |
tree | e8b622bdcce814fa82ba885512074ca2a5cc12f0 /src/context-priv.c | |
parent | 9d1043dcb5c698c5d9615b1b8d76a190f73d57bb (diff) | |
download | libxkbcommon-b4e81ca17240281fc802a662f5ce4e78a767c2b9.tar.gz libxkbcommon-b4e81ca17240281fc802a662f5ce4e78a767c2b9.tar.bz2 libxkbcommon-b4e81ca17240281fc802a662f5ce4e78a767c2b9.zip |
context: add XKB_CONTEXT_NO_SECURE_GETENV flag (#312)
This flag is useful for clients that may have relatively benign capabilities
set, like CAP_SYS_NICE, that also want to use the xkb configuration from the
environment and user configs in XDG_CONFIG_HOME.
Fixes: https://github.com/xkbcommon/libxkbcommon/issues/308
Fixes: https://github.com/xkbcommon/libxkbcommon/issues/129
Signed-off-by: Ran Benita <ran@unusedvar.com>
Diffstat (limited to 'src/context-priv.c')
-rw-r--r-- | src/context-priv.c | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/src/context-priv.c b/src/context-priv.c index 8eaa579..e94385f 100644 --- a/src/context-priv.c +++ b/src/context-priv.c @@ -34,6 +34,16 @@ #include "utils.h" #include "context.h" +char * +xkb_context_getenv(struct xkb_context *ctx, const char *name) +{ + if (ctx->use_secure_getenv) { + return secure_getenv(name); + } else { + return getenv(name); + } +} + unsigned int xkb_context_num_failed_include_paths(struct xkb_context *ctx) { @@ -105,7 +115,7 @@ xkb_context_get_default_rules(struct xkb_context *ctx) const char *env = NULL; if (ctx->use_environment_names) - env = secure_getenv("XKB_DEFAULT_RULES"); + env = xkb_context_getenv(ctx, "XKB_DEFAULT_RULES"); return env ? env : DEFAULT_XKB_RULES; } @@ -116,7 +126,7 @@ xkb_context_get_default_model(struct xkb_context *ctx) const char *env = NULL; if (ctx->use_environment_names) - env = secure_getenv("XKB_DEFAULT_MODEL"); + env = xkb_context_getenv(ctx, "XKB_DEFAULT_MODEL"); return env ? env : DEFAULT_XKB_MODEL; } @@ -127,7 +137,7 @@ xkb_context_get_default_layout(struct xkb_context *ctx) const char *env = NULL; if (ctx->use_environment_names) - env = secure_getenv("XKB_DEFAULT_LAYOUT"); + env = xkb_context_getenv(ctx, "XKB_DEFAULT_LAYOUT"); return env ? env : DEFAULT_XKB_LAYOUT; } @@ -136,12 +146,12 @@ static const char * xkb_context_get_default_variant(struct xkb_context *ctx) { const char *env = NULL; - const char *layout = secure_getenv("XKB_DEFAULT_LAYOUT"); + const char *layout = xkb_context_getenv(ctx, "XKB_DEFAULT_LAYOUT"); /* We don't want to inherit the variant if they haven't also set a * layout, since they're so closely paired. */ if (layout && ctx->use_environment_names) - env = secure_getenv("XKB_DEFAULT_VARIANT"); + env = xkb_context_getenv(ctx, "XKB_DEFAULT_VARIANT"); return env ? env : DEFAULT_XKB_VARIANT; } @@ -152,7 +162,7 @@ xkb_context_get_default_options(struct xkb_context *ctx) const char *env = NULL; if (ctx->use_environment_names) - env = secure_getenv("XKB_DEFAULT_OPTIONS"); + env = xkb_context_getenv(ctx, "XKB_DEFAULT_OPTIONS"); return env ? env : DEFAULT_XKB_OPTIONS; } |