]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add async_safe to tokenized xlat
authorAlan T. DeKok <aland@freeradius.org>
Wed, 6 Sep 2017 18:37:40 +0000 (14:37 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Wed, 6 Sep 2017 18:37:40 +0000 (14:37 -0400)
so we can track if an expansion is async-safe

src/main/xlat.h
src/main/xlat_tokenize.c

index d7bf1a6324f0ee7a95a628827ecba0b569fb9370..61a7dfb5afce26194ae6281e4abb811455b457ef 100644 (file)
@@ -61,6 +61,8 @@ struct xlat_exp {
        char const      *fmt;           //!< The format string.
        size_t          len;            //!< Length of the format string.
 
+       bool            async_safe;     //!< carried from all of the children
+
        xlat_state_t    type;           //!< type of this expansion.
        xlat_exp_t      *next;          //!< Next in the list.
 
index af2517f35ff3777bab44679a1682293268da3a48..344292baea4d0504843426b41aa27d0f59a9fbd2 100644 (file)
@@ -161,6 +161,8 @@ static ssize_t xlat_tokenize_alternation(TALLOC_CTX *ctx, char *fmt, xlat_exp_t
                p += slen;
        }
 
+       node->async_safe = (node->child->async_safe && node->alternate->async_safe);
+
        *head = node;
        return p - fmt;
 }
@@ -271,6 +273,7 @@ static ssize_t xlat_tokenize_expansion(TALLOC_CTX *ctx, char *fmt, xlat_exp_t **
                        }
                        p += slen;
 
+                       node->async_safe = (node->xlat->async_safe && node->child->async_safe);
                        *head = node;
                        rad_assert(node->next == NULL);
 
@@ -318,6 +321,7 @@ static ssize_t xlat_tokenize_expansion(TALLOC_CTX *ctx, char *fmt, xlat_exp_t **
                        node->fmt = node->attr->tmpl_unknown_name;
 
                        XLAT_DEBUG("VIRTUAL <-- %s", node->fmt);
+                       node->async_safe = node->xlat->async_safe;
                        *head = node;
                        rad_assert(node->next == NULL);
                        q++;
@@ -338,6 +342,7 @@ static ssize_t xlat_tokenize_expansion(TALLOC_CTX *ctx, char *fmt, xlat_exp_t **
                return -1;      /* second character of format string */
        }
        *p++ = '\0';
+       node->async_safe = true; /* attribute expansions are always async-safe */
        *head = node;
        rad_assert(node->next == NULL);
 
@@ -502,6 +507,7 @@ static ssize_t xlat_tokenize_literal(TALLOC_CTX *ctx, char *fmt, xlat_exp_t **he
         *      Squash zero-width literals
         */
        if (node->len > 0) {
+               node->async_safe = true; /* literals are always true */
                *head = node;
 
        } else {
@@ -747,7 +753,10 @@ ssize_t xlat_tokenize_request(TALLOC_CTX *ctx, REQUEST *request, char const *fmt
        /*
         *      Zero length expansion, return a zero length node.
         */
-       if (slen == 0) *head = talloc_zero(ctx, xlat_exp_t);
+       if (slen == 0) {
+               MEM(*head = talloc_zero(ctx, xlat_exp_t));
+               (*head)->async_safe = true;
+       }
 
        /*
         *      Output something like: