Add escape function to xlat_register
authorAlan T. DeKok <aland@freeradius.org>
Wed, 10 Apr 2013 12:23:50 +0000 (08:23 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Wed, 10 Apr 2013 14:43:22 +0000 (10:43 -0400)
Update the xlat expansion so that expanding a module's RHS
calls xlat_process, not xlat_aprint.  That allows for ALL
of the xlat chain to be printed, not just part of it.

Update various modules to use the new xlat_register API

Update the modules to *not* call radius_xlat() from their
mod_xlat() function.

We still need to fix some modules:

perl / sql: we can now write to "fmt", so various code
needs to be changed

perl: strtok() in a thread-safe function is horrible.  Use
str2argv() instead

redis: calls radius_xlat(), in a function which is also
called from the main redis query routines.  And calls
rad_xlat_argv(), which splits the string before xlat'ing it.
That's now wrong.  Instead, the redis_xlat function should
supply an escape function (for spaces) and then rely on
str2argv()  (or similar) to chop on real spaces, and not
on escaped spaces

Also fixed a memory leak in the yubikey module

16 files changed:
src/include/radiusd.h
src/main/listen.c
src/main/mainconfig.c
src/main/realms.c
src/main/xlat.c
src/modules/proto_dhcp/rlm_dhcp.c
src/modules/rlm_cache/rlm_cache.c
src/modules/rlm_exec/rlm_exec.c
src/modules/rlm_expr/rlm_expr.c
src/modules/rlm_ldap/rlm_ldap.c
src/modules/rlm_mschap/rlm_mschap.c
src/modules/rlm_perl/rlm_perl.c
src/modules/rlm_redis/rlm_redis.c
src/modules/rlm_soh/rlm_soh.c
src/modules/rlm_sql/rlm_sql.c
src/modules/rlm_yubikey/rlm_yubikey.c

index 8fa6018..5e54dbf 100644 (file)
@@ -751,7 +751,7 @@ ssize_t radius_axlat(char **out, REQUEST *request, const char *fmt, RADIUS_ESCAP
                          void *escape_ctx);
                    
 typedef size_t (*RAD_XLAT_FUNC)(void *instance, REQUEST *, const char *, char *, size_t);
-int            xlat_register(const char *module, RAD_XLAT_FUNC func,
+int            xlat_register(const char *module, RAD_XLAT_FUNC func, RADIUS_ESCAPE_STRING escape,
                              void *instance);
 void           xlat_unregister(const char *module, RAD_XLAT_FUNC func,
                                void *instance);
index 52b63ec..836fe45 100644 (file)
@@ -3062,7 +3062,7 @@ add_sockets:
         */
        if (!*head) return -1;
 
-       xlat_register("listen", xlat_listen, NULL);
+       xlat_register("listen", xlat_listen, NULL, NULL);
 
        return 0;
 }
index 3508e6f..8faf4b3 100644 (file)
@@ -936,8 +936,8 @@ int read_mainconfig(int reload)
        /*
         *  Register the %{config:section.subsection} xlat function.
         */
-       xlat_register("config", xlat_config, NULL);
-       xlat_register("client", xlat_client, NULL);
+       xlat_register("config", xlat_config, NULL, NULL);
+       xlat_register("client", xlat_client, NULL, NULL);
 
        /*
         *      Starting the server, WITHOUT "-x" on the
index 2f860a8..fd61090 100644 (file)
@@ -1968,8 +1968,8 @@ int realms_init(CONF_SECTION *config)
 
 
 #ifdef WITH_PROXY
-       xlat_register("home_server", xlat_home_server, NULL);
-       xlat_register("home_server_pool", xlat_server_pool, NULL);
+       xlat_register("home_server", xlat_home_server, NULL, NULL);
+       xlat_register("home_server_pool", xlat_server_pool, NULL, NULL);
 #endif
 
        /*
index 178ea65..51a0f59 100644 (file)
@@ -37,7 +37,8 @@ typedef struct xlat_t {
        char            module[MAX_STRING_LEN];
        int             length;
        void            *instance;
-       RAD_XLAT_FUNC   do_xlat;
+       RAD_XLAT_FUNC   func;
+       RADIUS_ESCAPE_STRING  escape;
        int             internal;       /* not allowed to re-define these */
 } xlat_t;
 
@@ -399,7 +400,7 @@ static xlat_t *xlat_find(const char *module)
  * @param instance argument to xlat function
  * @return 0 on success, -1 on failure
  */
-int xlat_register(const char *module, RAD_XLAT_FUNC func, void *instance)
+int xlat_register(const char *module, RAD_XLAT_FUNC func, RADIUS_ESCAPE_STRING escape, void *instance)
 {
        xlat_t  *c;
        xlat_t  my_xlat;
@@ -427,14 +428,14 @@ int xlat_register(const char *module, RAD_XLAT_FUNC func, void *instance)
 #ifdef WITH_UNLANG
                for (i = 0; xlat_foreach_names[i] != NULL; i++) {
                        xlat_register(xlat_foreach_names[i],
-                                     xlat_foreach, &xlat_inst[i]);
+                                     xlat_foreach, NULL, &xlat_inst[i]);
                        c = xlat_find(xlat_foreach_names[i]);
                        rad_assert(c != NULL);
                        c->internal = TRUE;
                }
 #endif
 
-#define XLAT_REGISTER(_x) xlat_register(Stringify(_x), xlat_ ## _x, NULL); \
+#define XLAT_REGISTER(_x) xlat_register(Stringify(_x), xlat_ ## _x, NULL, NULL); \
                c = xlat_find(Stringify(_x)); \
                rad_assert(c != NULL); \
                c->internal = TRUE
@@ -446,7 +447,7 @@ int xlat_register(const char *module, RAD_XLAT_FUNC func, void *instance)
                XLAT_REGISTER(xlat);
                XLAT_REGISTER(module);
 
-               xlat_register("debug", xlat_debug, &xlat_inst[0]);
+               xlat_register("debug", xlat_debug, NULL, &xlat_inst[0]);
                c = xlat_find("debug");
                rad_assert(c != NULL);
                c->internal = TRUE;
@@ -464,7 +465,8 @@ int xlat_register(const char *module, RAD_XLAT_FUNC func, void *instance)
                        return -1;
                }
 
-               c->do_xlat = func;
+               c->func = func;
+               c->escape = escape;
                c->instance = instance;
                return 0;
        }
@@ -475,7 +477,8 @@ int xlat_register(const char *module, RAD_XLAT_FUNC func, void *instance)
        c = rad_malloc(sizeof(*c));
        memset(c, 0, sizeof(*c));
 
-       c->do_xlat = func;
+       c->func = func;
+       c->escape = escape;
        strlcpy(c->module, module, sizeof(c->module));
        c->length = strlen(c->module);
        c->instance = instance;
@@ -520,10 +523,18 @@ void xlat_free(void)
        rbtree_free(xlat_root);
 }
 
+#if 0
+#define XLAT_DEBUG DEBUG3
+#else
+#define XLAT_DEBUG(...)
+#endif
+
 static ssize_t xlat_tokenize_expansion(TALLOC_CTX *ctx, char *fmt, xlat_exp_t **head,
                                       const char **error);
 static ssize_t xlat_tokenize_literal(TALLOC_CTX *ctx, char *fmt, xlat_exp_t **head,
                                     int brace, const char **error);
+static size_t xlat_process(char **out, REQUEST *request, const xlat_exp_t * const head,
+                          RADIUS_ESCAPE_STRING escape, void *escape_ctx);
 
 static ssize_t xlat_tokenize_alternation(TALLOC_CTX *ctx, char *fmt, xlat_exp_t **head,
                                         const char **error)
@@ -537,6 +548,8 @@ static ssize_t xlat_tokenize_alternation(TALLOC_CTX *ctx, char *fmt, xlat_exp_t
        rad_assert(fmt[2] == '%');
        rad_assert(fmt[3] == '{');
 
+       XLAT_DEBUG("ALTERNATE: %s", fmt);
+
        node = talloc_zero(ctx, xlat_exp_t);
        node->type = XLAT_ALTERNATE;
 
@@ -591,6 +604,7 @@ static ssize_t xlat_tokenize_expansion(TALLOC_CTX *ctx, char *fmt, xlat_exp_t **
                return xlat_tokenize_alternation(ctx, fmt, head, error);
        }
 
+       XLAT_DEBUG("EXPANSION: %s", fmt);
        node = talloc_zero(ctx, xlat_exp_t);
        attrname = node->fmt = fmt + 2;
        node->len = 0;
@@ -606,6 +620,7 @@ static ssize_t xlat_tokenize_expansion(TALLOC_CTX *ctx, char *fmt, xlat_exp_t **
                        return -2;
                }
 
+               XLAT_DEBUG("REGEX: %s", fmt);
                fmt[3] = '\0';
                node->num = fmt[2] - '0'; /* ASCII */
 
@@ -615,7 +630,6 @@ static ssize_t xlat_tokenize_expansion(TALLOC_CTX *ctx, char *fmt, xlat_exp_t **
        }
 #endif /* HAVE_REGEX_H */
 
-
        p = strchr(node->fmt, ':');
        if (p) {
                *(p++) = '\0';
@@ -627,6 +641,7 @@ static ssize_t xlat_tokenize_expansion(TALLOC_CTX *ctx, char *fmt, xlat_exp_t **
                if (node->xlat) {
                        node->type = XLAT_MODULE;
 
+                       XLAT_DEBUG("MOD: %s --> %s", node->fmt, p);
                        slen = xlat_tokenize_literal(node, p, &node->child, TRUE, error);
                        if (slen < 0) {
                                talloc_free(node);
@@ -784,6 +799,8 @@ static ssize_t xlat_tokenize_literal(TALLOC_CTX *ctx, char *fmt, xlat_exp_t **he
 
        if (!*fmt) return 0;
 
+       XLAT_DEBUG("LITERAL: %s", fmt);
+
        node = talloc_zero(ctx, xlat_exp_t);
        node->fmt = fmt;
        node->len = 0;
@@ -851,11 +868,13 @@ static ssize_t xlat_tokenize_literal(TALLOC_CTX *ctx, char *fmt, xlat_exp_t **he
                if ((p[0] == '%') && (p[1] == '{')) {
                        ssize_t slen;
 
+                       XLAT_DEBUG("LITERAL: %s --> %s", node->fmt, p);
                        slen = xlat_tokenize_expansion(node, p, &node->next, error);
                        if (slen < 0) {
                                talloc_free(node);
                                return slen - (p - fmt);
                        }
+                       *p = '\0'; /* end the literal */
                        p += slen;
 
                        rad_assert(node->next != NULL);
@@ -943,11 +962,11 @@ static void xlat_tokenize_debug(const xlat_exp_t *node, int lvl)
        while (node) {
                switch (node->type) {
                case XLAT_LITERAL:
-                       DEBUG("%.*sliteral: %s", lvl, xlat_tabs, node->fmt);
+                       DEBUG("%.*sliteral: '%s'", lvl, xlat_tabs, node->fmt);
                        break;
 
                case XLAT_PERCENT:
-                       DEBUG("%.*sliteral (with %%): %s", lvl, xlat_tabs, node->fmt);
+                       DEBUG("%.*sliteral (with %%): '%s'", lvl, xlat_tabs, node->fmt);
                        break;
 
                case XLAT_ATTRIBUTE:
@@ -1281,16 +1300,21 @@ static char *xlat_getvp(TALLOC_CTX *ctx, REQUEST *request, pair_lists_t list, co
        return vp_asprintf(ctx, vp);
 }
 
-static char *xlat_aprint(TALLOC_CTX *ctx, REQUEST *request, const xlat_exp_t * const node)
+static char *xlat_aprint(TALLOC_CTX *ctx, REQUEST *request, const xlat_exp_t * const node,
+                        RADIUS_ESCAPE_STRING escape, void *escape_ctx, int lvl)
 {
        size_t rcode;
        char *str, *child;
        REQUEST *ref;
 
+       XLAT_DEBUG("%.*sxlat aprint %d", lvl, xlat_spaces, node->type);
+
        switch (node->type) {
+               /*
+                *      Don't escape this
+                */
        case XLAT_LITERAL:
-               str = talloc_strdup(ctx, node->fmt);
-               break;
+               return talloc_strdup(ctx, node->fmt);
 
        case XLAT_PERCENT: {
                const char *p;
@@ -1399,18 +1423,23 @@ static char *xlat_aprint(TALLOC_CTX *ctx, REQUEST *request, const xlat_exp_t * c
                 *      Some attributes are virtual <sigh>
                 */
                str = xlat_getvp(ctx, ref, node->list, node->da, node->tag);
+               XLAT_DEBUG("expand attr %s --> '%s'", node->da->name, str);
                break;
 
        case XLAT_MODULE:
                rad_assert(node->child != NULL);
 
-               child = xlat_aprint(ctx, request, node->child);
-               if (!child) return NULL;
+               if (xlat_process(&child, request, node->child, node->xlat->escape, node->xlat->instance) == 0) {
+                       rad_assert(child == NULL);
+                       return NULL;
+               }
+
+               XLAT_DEBUG("%.*sexpand mod %s --> '%s'", lvl, xlat_spaces, node->fmt, child);
 
                str = talloc_array(ctx, char, 1024); /* FIXME: have the module call talloc_asprintf */
                rad_assert(node->child != NULL);
 
-               rcode = node->xlat->do_xlat(node->xlat->instance, request, child, str, 1024);
+               rcode = node->xlat->func(node->xlat->instance, request, child, str, 1024);
                talloc_free(child);
                if (rcode == 0) {
                        talloc_free(str);
@@ -1432,21 +1461,39 @@ static char *xlat_aprint(TALLOC_CTX *ctx, REQUEST *request, const xlat_exp_t * c
                rad_assert(node->child != NULL);
                rad_assert(node->alternate != NULL);
 
-               str = xlat_aprint(ctx, request, node->child);
+               str = xlat_aprint(ctx, request, node->child, node->xlat->escape, node->xlat->instance, lvl);
                if (str) break;
 
-               str = xlat_aprint(ctx, request, node->alternate);
+               str = xlat_aprint(ctx, request, node->alternate, node->xlat->escape, node->xlat->instance, lvl);
                break;
 
        }
 
+       /*
+        *      Escape the non-literals we found above.
+        */
+       if (escape) {
+               size_t esclen;
+               char *escaped;
+
+               escaped = talloc_array(ctx, char, 1024); /* FIXME: do something intelligent */
+               esclen = escape(request, escaped, 1024, str, escape_ctx);
+               talloc_free(str);
+               if (esclen == 0) {
+                       talloc_free(escaped);
+                       return NULL;
+               }
+
+               str = escaped;
+       }
+
        rad_assert(str != NULL);
        return str;
 }
 
 
-static size_t xlat_process(char **out, REQUEST *request, const xlat_exp_t * const head)
-
+static size_t xlat_process(char **out, REQUEST *request, const xlat_exp_t * const head,
+                          RADIUS_ESCAPE_STRING escape, void *escape_ctx)
 {
        int i, list;
        size_t total;
@@ -1461,7 +1508,12 @@ static size_t xlat_process(char **out, REQUEST *request, const xlat_exp_t * cons
         *      array.
         */
        if (!head->next) {
-               answer = xlat_aprint(request, request, head);
+               /*
+                *      Pass the MAIN escape function.  Recursive
+                *      calls will call node-specific escape
+                *      functions.
+                */
+               answer = xlat_aprint(request, request, head, escape, escape_ctx, 0);
                if (!answer) return 0;
                *out = answer;
                return strlen(answer);
@@ -1476,7 +1528,7 @@ static size_t xlat_process(char **out, REQUEST *request, const xlat_exp_t * cons
        if (!array) return -1;
 
        for (node = head, i = 0; node != NULL; node = node->next, i++) {
-               array[i] = xlat_aprint(array, request, node); /* may be NULL */
+               array[i] = xlat_aprint(array, request, node, escape, escape_ctx, 0); /* may be NULL */
        }
 
        total = 0;
@@ -1522,7 +1574,7 @@ static size_t xlat_process(char **out, REQUEST *request, const xlat_exp_t * cons
  * @return length of string written @bug should really have -1 for failure
  */
 static ssize_t xlat_expand(char **out, size_t outlen, REQUEST *request, const char *fmt,
-                          UNUSED RADIUS_ESCAPE_STRING escape, UNUSED void *escape_ctx)
+                          RADIUS_ESCAPE_STRING escape, void *escape_ctx)
 {
        char *buff;
        ssize_t len;
@@ -1539,7 +1591,7 @@ static ssize_t xlat_expand(char **out, size_t outlen, REQUEST *request, const ch
                return -1;
        }
 
-       len = xlat_process(&buff, request, node);
+       len = xlat_process(&buff, request, node, escape, escape_ctx);
        talloc_free(node);
 
        if (len <= 0) {
index 753d4be..da8a80f 100644 (file)
@@ -105,7 +105,7 @@ static int mod_instantiate(UNUSED CONF_SECTION *conf, void *instance)
 {
        rlm_dhcp_t *inst = instance;
        
-       xlat_register("dhcp_options", dhcp_options_xlat, inst);
+       xlat_register("dhcp_options", dhcp_options_xlat, NULL, inst);
 
        return 0;
 }
index d6edcc0..49dee1a 100644 (file)
@@ -606,13 +606,8 @@ static size_t cache_xlat(void *instance, REQUEST *request,
        pair_lists_t list;
        const DICT_ATTR *target;
        const char *p = fmt;
-       char buffer[1024];
        int ret = 0;
 
-       if (radius_xlat(buffer, sizeof(buffer), request, inst->key, NULL, NULL) < 0) {
-               return 0;
-       }
-
        list = radius_list_name(&p, PAIR_LIST_REQUEST);
        
        target = dict_attrbyname(p);
@@ -622,10 +617,10 @@ static size_t cache_xlat(void *instance, REQUEST *request,
        }
        
        PTHREAD_MUTEX_LOCK(&inst->cache_mutex);
-       c = cache_find(inst, request, buffer);
+       c = cache_find(inst, request, fmt);
        
        if (!c) {
-               RDEBUG("No cache entry for key \"%s\"", buffer);
+               RDEBUG("No cache entry for key \"%s\"", fmt);
                goto done;
        }
 
@@ -729,7 +724,7 @@ static int mod_instantiate(CONF_SECTION *conf, void *instance)
        /*
         *      Register the cache xlat function
         */
-       xlat_register(inst->xlat_name, cache_xlat, inst);
+       xlat_register(inst->xlat_name, cache_xlat, NULL, inst);
 
        rad_assert(inst->key && *inst->key);
 
index b2d8bcb..3061cc9 100644 (file)
@@ -154,6 +154,34 @@ static size_t exec_xlat(void *instance, REQUEST *request,
 }
 
 
+static const char special[] = "\\'\"`<>|; \t\r\n()[]?#$^&*=";
+
+/*
+ *     Escape special characters
+ */
+static size_t shell_escape(UNUSED REQUEST *request, char *out, size_t outlen, const char *in, UNUSED void *inst)
+{
+       char *q, *end;
+       const char *p;
+
+       q = out;
+       end = out + outlen;
+       p = in;
+
+       while (*p) {
+               if ((q + 3) >= end) break;
+
+               if (strchr(special, *p) != NULL) {
+                       *(q++) = '\\';
+               }
+               *(q++) = *(p++);
+       }
+
+       *q = '\0';
+       return q - out;
+}
+
+
 /*
  *     Do any per-module initialization that is separate to each
  *     configured instance of the module.  e.g. set up connections
@@ -174,7 +202,7 @@ static int mod_instantiate(CONF_SECTION *conf, void *instance)
                inst->bare = 1;
        }
 
-       xlat_register(inst->xlat_name, exec_xlat, inst);
+       xlat_register(inst->xlat_name, exec_xlat, shell_escape, inst);
 
        /*
         *      No input pairs defined.  Why are we executing a program?
index 21e9bc9..38de613 100644 (file)
@@ -250,17 +250,8 @@ static size_t expr_xlat(UNUSED void *instance, REQUEST *request, const char *fmt
        int             rcode;
        int64_t         result;
        const           char *p;
-       char            buffer[256];
-
-       /*
-        * Do an xlat on the provided string (nice recursive operation).
-        */
-       if (radius_xlat(buffer, sizeof(buffer), request, fmt, NULL, NULL) < 0) {
-               *out = '\0';
-               return 0;
-       }
 
-       p = buffer;
+       p = fmt;
        rcode = get_number(request, &p, &result);
        if (rcode < 0) {
                return 0;
@@ -714,20 +705,20 @@ static int mod_instantiate(CONF_SECTION *conf, void *instance)
                inst->xlat_name = cf_section_name1(conf);
        }
 
-       xlat_register(inst->xlat_name, expr_xlat, inst);
+       xlat_register(inst->xlat_name, expr_xlat, NULL, inst);
 
        /*
         *      FIXME: unregister these, too
         */
-       xlat_register("rand", rand_xlat, inst);
-       xlat_register("randstr", randstr_xlat, inst);
-       xlat_register("urlquote", urlquote_xlat, inst);
-       xlat_register("escape", escape_xlat, inst);
-       xlat_register("tolower", lc_xlat, inst);
-       xlat_register("toupper", uc_xlat, inst);
-       xlat_register("md5", md5_xlat, inst);
-       xlat_register("tobase64", base64_xlat, inst);
-       xlat_register("base64tohex", base64_to_hex_xlat, inst);
+       xlat_register("rand", rand_xlat, NULL, inst);
+       xlat_register("randstr", randstr_xlat, NULL, inst);
+       xlat_register("urlquote", urlquote_xlat, NULL, inst);
+       xlat_register("escape", escape_xlat, NULL, inst);
+       xlat_register("tolower", lc_xlat, NULL, inst);
+       xlat_register("toupper", uc_xlat, NULL, inst);
+       xlat_register("md5", md5_xlat, NULL, inst);
+       xlat_register("tobase64", base64_xlat, NULL, inst);
+       xlat_register("base64tohex", base64_to_hex_xlat, NULL, inst);
 
        /*
         *      Initialize various paircompare functions
index 8103b79..99f1cf1 100644 (file)
@@ -198,17 +198,8 @@ static size_t ldap_xlat(void *instance, REQUEST *request, const char *fmt,
        int ldap_errno;
        const char *url;
        const char **attrs;
-       char buffer[LDAP_MAX_DN_STR_LEN + LDAP_MAX_FILTER_STR_LEN];
 
-       if (strchr(fmt, '%') != NULL) {
-               if (!radius_xlat(buffer, sizeof(buffer), request, fmt, rlm_ldap_escape_func, NULL)) {
-                       RDEBUGE("Unable to create LDAP URL");
-                       return 0;
-               }
-               url = buffer;
-       } else {
-               url = fmt;
-       }
+       url = fmt;
 
        if (!ldap_is_ldap_url(url)) {
                RDEBUGE("String passed does not look like an LDAP URL");
@@ -600,7 +591,7 @@ static int mod_instantiate(CONF_SECTION *conf, void *instance)
                paircompare_register(inst->group_da->attr, PW_USER_NAME, rlm_ldap_groupcmp, inst);
        }
 
-       xlat_register(inst->xlat_name, ldap_xlat, inst);
+       xlat_register(inst->xlat_name, ldap_xlat, rlm_ldap_escape_func, inst);
 
        /*
         *      Initialize the socket pool.
index 9a67f05..cb1b63a 100644 (file)
@@ -575,7 +575,7 @@ static int mod_instantiate(CONF_SECTION *conf, void *instance)
        name = cf_section_name2(conf);
        if (!name) name = cf_section_name1(conf);
        inst->xlat_name = name;
-       xlat_register(inst->xlat_name, mschap_xlat, inst);
+       xlat_register(inst->xlat_name, mschap_xlat, NULL, inst);
 
        /*
         *      For backwards compatibility
index e5f110b..d2bb365 100644 (file)
@@ -319,12 +319,7 @@ static size_t perl_xlat(void *instance, REQUEST *request, const char *fmt,
        size_t          ret = 0;
        STRLEN          n_a;
 
-       /*
-        *      Do an xlat on the provided string (nice recursive operation).
-        */
-       if (radius_axlat(&expanded, request, fmt, NULL, NULL) < 0) {
-               return 0;
-       }
+       expanded = fmt;         /* FIXME */
 
 #ifndef WITH_ITHREADS
        perl = inst->perl;
@@ -471,7 +466,7 @@ static int mod_instantiate(CONF_SECTION *conf, void *instance)
        if (!xlat_name)
                xlat_name = cf_section_name1(conf);
        if (xlat_name) {
-               xlat_register(xlat_name, perl_xlat, inst);
+               xlat_register(xlat_name, perl_xlat, NULL, inst);
        }
 
        return 0;
index e93db09..e3b101f 100644 (file)
@@ -285,7 +285,7 @@ static int mod_instantiate(CONF_SECTION *conf, void *instance)
        if (!inst->xlat_name)
                inst->xlat_name = cf_section_name1(conf);
 
-       xlat_register(inst->xlat_name, redis_xlat, inst);
+       xlat_register(inst->xlat_name, redis_xlat, NULL, inst); /* FIXME! */
 
        inst->pool = fr_connection_pool_init(conf, inst,
                                             conn_create, NULL,
index 77c2841..92721bd 100644 (file)
@@ -113,7 +113,7 @@ static int mod_instantiate(CONF_SECTION *conf, void *instance)
        if (!name) name = cf_section_name1(conf);
        inst->xlat_name = name;
        if (!inst->xlat_name) return -1;
-       xlat_register(inst->xlat_name, soh_xlat, inst);
+       xlat_register(inst->xlat_name, soh_xlat, NULL, inst);
 
        return 0;
 }
index 063adde..e1fb28a 100644 (file)
@@ -132,8 +132,7 @@ static size_t sql_xlat(void *instance, REQUEST *request, const char *fmt, char *
        rlm_sql_row_t row;
        rlm_sql_t *inst = instance;
        size_t ret = 0;
-       
-       char *expanded = NULL;
+       char *query = fmt;      /* FIXME: */
 
        /*
         *      Add SQL-User-Name attribute just in case it is needed
@@ -142,31 +141,24 @@ static size_t sql_xlat(void *instance, REQUEST *request, const char *fmt, char *
         */
        sql_set_user(inst, request, NULL);
        
-       /*
-        *      Do an xlat on the provided string (nice recursive operation).
-        */
-       if (radius_axlat(&expanded, request, fmt, sql_escape_func, inst) < 0) {
-               return 0;
-       }
-
        handle = sql_get_socket(inst);
        if (!handle) {
                return 0;
        }
        
-       rlm_sql_query_log(inst, request, NULL, expanded);
+       rlm_sql_query_log(inst, request, NULL, query);
 
        /*
         *      If the query starts with any of the following prefixes,
         *      then return the number of rows affected
         */
-       if ((strncasecmp(expanded, "insert", 6) == 0) ||
-           (strncasecmp(expanded, "update", 6) == 0) ||
-           (strncasecmp(expanded, "delete", 6) == 0)) {
+       if ((strncasecmp(query, "insert", 6) == 0) ||
+           (strncasecmp(query, "update", 6) == 0) ||
+           (strncasecmp(query, "delete", 6) == 0)) {
                int numaffected;
                char buffer[21]; /* 64bit max is 20 decimal chars + null byte */
 
-               if (rlm_sql_query(&handle, inst, expanded)) {
+               if (rlm_sql_query(&handle, inst, query)) {
                        goto finish;
                }
        
@@ -204,7 +196,7 @@ static size_t sql_xlat(void *instance, REQUEST *request, const char *fmt, char *
                goto finish;
        } /* else it's a SELECT statement */
 
-       if (rlm_sql_select_query(&handle, inst, expanded)){
+       if (rlm_sql_select_query(&handle, inst, query)){
                goto finish;
        }
 
@@ -247,7 +239,6 @@ static size_t sql_xlat(void *instance, REQUEST *request, const char *fmt, char *
        (inst->module->sql_finish_select_query)(handle, inst->config);
        
        finish:
-       talloc_free(expanded);
        sql_release_socket(inst, handle);
        
        return ret;
@@ -853,7 +844,7 @@ static int mod_instantiate(CONF_SECTION *conf, void *instance)
         *      Register the SQL xlat function
         */
        inst->config->xlat_name = talloc_strdup(inst->config, xlat_name);
-       xlat_register(xlat_name, sql_xlat, inst);
+       xlat_register(xlat_name, sql_xlat, sql_escape_func, inst);
 
        /*
         *      Sanity check for crazy people.
index 4ee9eb2..9b927d2 100644 (file)
@@ -111,27 +111,22 @@ static size_t modhex_to_hex_xlat(UNUSED void *instance, REQUEST *request, const
 {      
        ssize_t len;
 
-       char *expanded = NULL;
-       len = radius_axlat(&expanded, request, fmt, NULL, NULL);
-       if (len < 0) {
-               return len;
+       if (outlen < strlen(fmt)) {
+               *out = '\0';
+               return 0;
        }
-       
+
        /*
         *      mod2hex allows conversions in place
         */
-       len = modhex2hex(expanded, (uint8_t *) expanded, strlen(expanded));
+       len = modhex2hex(fmt, (uint8_t *) out, strlen(fmt));
        if (len <= 0) {
-               talloc_free(expanded);
                *out = '\0';
-               
                RDEBUGE("Modhex string invalid");
                
-               return len;
+               return 0;
        }
        
-       strlcpy(out, expanded, outlen);
-       
        return len;
 }