]> git.alsa-project.org Git - alsa-lib.git/commitdiff
ucm: fix Path condition - substitute Path and Mode fields
authorJaroslav Kysela <perex@perex.cz>
Wed, 24 Apr 2024 11:01:04 +0000 (13:01 +0200)
committerJaroslav Kysela <perex@perex.cz>
Wed, 24 Apr 2024 11:01:04 +0000 (13:01 +0200)
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>
src/ucm/ucm_cond.c

index 985a366bffabf0dd09c53980e83027354deeb961..70effda03f06620fcc76c718734144aad8fb2441 100644 (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 = "";
        int err, amode = F_OK;
+       char *s;
 
        if (uc_mgr->conf_format < 4) {
                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;
        }
 
-       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;
-       } else if (strcasecmp(mode, "read") == 0) {
+       } else if (strcasecmp(s, "read") == 0) {
                amode = R_OK;
-       } else if (strcasecmp(mode, "write") == 0) {
+       } else if (strcasecmp(s, "write") == 0) {
                amode = W_OK;
-       } else if (strcasecmp(mode, "exec") == 0) {
+       } else if (strcasecmp(s, "exec") == 0) {
                amode = X_OK;
        } else {
-               uc_error("Path unknown mode (If.Condition.Mode)");
+               uc_error("Path unknown mode '%s' (If.Condition.Mode)", s);
+               free(s);
                return -EINVAL;
        }
+       free(s);
 
+       err = uc_mgr_get_substituted_value(uc_mgr, &s, path);
+       if (err < 0)
+               return err;
 #ifdef HAVE_EACCESS
-       if (eaccess(path, amode))
+       err = eaccess(path, amode);
 #else
-       if (access(path, amode))
+       err = access(path, amode);
 #endif
-               return 0;
-
-       return 1;
+       free(s);
+       return err ? 0 : 1;
 }
 
 static int if_eval(snd_use_case_mgr_t *uc_mgr, snd_config_t *eval)