ucm: fix Path condition - substitute Path and Mode fields

The Path and Mode fields should be also substituted for
the runtime evaluation. See Fixes.

Fixes: https://github.com/alsa-project/alsa-lib/issues/395
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
Jaroslav Kysela 2024-04-24 13:01:04 +02:00
parent de529410da
commit ef6463a209

View file

@ -274,6 +274,7 @@ static int if_eval_path(snd_use_case_mgr_t *uc_mgr, snd_config_t *eval)
{ {
const char *path, *mode = ""; const char *path, *mode = "";
int err, amode = F_OK; int err, amode = F_OK;
char *s;
if (uc_mgr->conf_format < 4) { if (uc_mgr->conf_format < 4) {
uc_error("Path condition is supported in v4+ syntax"); uc_error("Path condition is supported in v4+ syntax");
@ -292,27 +293,34 @@ static int if_eval_path(snd_use_case_mgr_t *uc_mgr, snd_config_t *eval)
return -EINVAL; return -EINVAL;
} }
if (strncasecmp(mode, "exist", 5) == 0) { err = uc_mgr_get_substituted_value(uc_mgr, &s, mode);
if (err < 0)
return err;
if (strncasecmp(s, "exist", 5) == 0) {
amode = F_OK; amode = F_OK;
} else if (strcasecmp(mode, "read") == 0) { } else if (strcasecmp(s, "read") == 0) {
amode = R_OK; amode = R_OK;
} else if (strcasecmp(mode, "write") == 0) { } else if (strcasecmp(s, "write") == 0) {
amode = W_OK; amode = W_OK;
} else if (strcasecmp(mode, "exec") == 0) { } else if (strcasecmp(s, "exec") == 0) {
amode = X_OK; amode = X_OK;
} else { } else {
uc_error("Path unknown mode (If.Condition.Mode)"); uc_error("Path unknown mode '%s' (If.Condition.Mode)", s);
free(s);
return -EINVAL; return -EINVAL;
} }
free(s);
err = uc_mgr_get_substituted_value(uc_mgr, &s, path);
if (err < 0)
return err;
#ifdef HAVE_EACCESS #ifdef HAVE_EACCESS
if (eaccess(path, amode)) err = eaccess(path, amode);
#else #else
if (access(path, amode)) err = access(path, amode);
#endif #endif
return 0; free(s);
return err ? 0 : 1;
return 1;
} }
static int if_eval(snd_use_case_mgr_t *uc_mgr, snd_config_t *eval) static int if_eval(snd_use_case_mgr_t *uc_mgr, snd_config_t *eval)