Merge pull request #101 from philmayers/escape-context2
authorAlan DeKok <aland@freeradius.org>
Fri, 5 Oct 2012 12:07:43 +0000 (05:07 -0700)
committerAlan DeKok <aland@freeradius.org>
Fri, 5 Oct 2012 12:07:43 +0000 (05:07 -0700)
Re-work escape functions to have REQUEST* and context variables

46 files changed:
src/include/radiusd.h
src/main/auth.c
src/main/evaluate.c
src/main/exec.c
src/main/listen.c
src/main/log.c
src/main/mainconfig.c
src/main/modcall.c
src/main/radconf2xml.c
src/main/radmin.c
src/main/radwho.c
src/main/realms.c
src/main/tls.c
src/main/valuepair.c
src/main/xlat.c
src/modules/rlm_acctlog/rlm_acctlog.c
src/modules/rlm_attr_filter/rlm_attr_filter.c
src/modules/rlm_attr_rewrite/rlm_attr_rewrite.c
src/modules/rlm_cache/rlm_cache.c
src/modules/rlm_detail/rlm_detail.c
src/modules/rlm_eap/types/rlm_eap_gtc/rlm_eap_gtc.c
src/modules/rlm_exec/rlm_exec.c
src/modules/rlm_expiration/rlm_expiration.c
src/modules/rlm_expr/paircmp.c
src/modules/rlm_expr/rlm_expr.c
src/modules/rlm_fastusers/rlm_fastusers.c
src/modules/rlm_files/rlm_files.c
src/modules/rlm_ippool/rlm_ippool.c
src/modules/rlm_ldap/rlm_ldap.c
src/modules/rlm_linelog/rlm_linelog.c
src/modules/rlm_logintime/rlm_logintime.c
src/modules/rlm_mschap/rlm_mschap.c
src/modules/rlm_pap/rlm_pap.c
src/modules/rlm_perl/rlm_perl.c
src/modules/rlm_policy/evaluate.c
src/modules/rlm_radutmp/rlm_radutmp.c
src/modules/rlm_redis/rlm_redis.c
src/modules/rlm_rediswho/rlm_rediswho.c
src/modules/rlm_rest/rest.c
src/modules/rlm_soh/rlm_soh.c
src/modules/rlm_sql/rlm_sql.c
src/modules/rlm_sql/rlm_sql.h
src/modules/rlm_sql/sql.c
src/modules/rlm_sql_log/rlm_sql_log.c
src/modules/rlm_sqlcounter/rlm_sqlcounter.c
src/modules/rlm_sqlippool/rlm_sqlippool.c

index 553815a..5ca235c 100644 (file)
@@ -712,11 +712,11 @@ VALUE_PAIR *radius_pairmake(REQUEST *request, VALUE_PAIR **vps,
                            int operator);
 
 /* xlat.c */
-typedef size_t (*RADIUS_ESCAPE_STRING)(char *out, size_t outlen, const char *in);
+typedef size_t (*RADIUS_ESCAPE_STRING)(REQUEST *, char *out, size_t outlen, const char *in, void *arg);
 
 int            radius_xlat(char * out, int outlen, const char *fmt,
-                          REQUEST * request, RADIUS_ESCAPE_STRING func);
-typedef size_t (*RAD_XLAT_FUNC)(void *instance, REQUEST *, const char *, char *, size_t, RADIUS_ESCAPE_STRING func);
+                          REQUEST * request, RADIUS_ESCAPE_STRING func, void *funcarg);
+typedef size_t (*RAD_XLAT_FUNC)(void *instance, REQUEST *, const char *, char *, size_t);
 int            xlat_register(const char *module, RAD_XLAT_FUNC func,
                              void *instance);
 void           xlat_unregister(const char *module, RAD_XLAT_FUNC func,
index f55e962..34bd56d 100644 (file)
@@ -140,7 +140,7 @@ static int rad_authlog(const char *msg, REQUEST *request, int goodpass)
        if (extra_msg) {
                extra[0] = ' ';
                radius_xlat(extra + 1, sizeof(extra) - 1, extra_msg, request,
-                           NULL);
+                           NULL, NULL);
        } else {
                *extra = '\0';
        }
index 99fa7a0..c0d23ad 100644 (file)
@@ -101,7 +101,7 @@ static const char *expand_string(char *buffer, size_t sizeof_buffer,
        case T_DOUBLE_QUOTED_STRING:
                if (!strchr(value, '%')) return value;
 
-               radius_xlat(buffer, sizeof_buffer, value, request, NULL);
+               radius_xlat(buffer, sizeof_buffer, value, request, NULL, NULL);
                return buffer;
        }
 
index 16155d8..eecec14 100644 (file)
@@ -215,7 +215,7 @@ pid_t radius_start_program(const char *cmd, REQUEST *request,
 
                if (!request) continue;
 
-               sublen = radius_xlat(to, left - 1, argv[i], request, NULL);
+               sublen = radius_xlat(to, left - 1, argv[i], request, NULL, NULL);
                if (sublen <= 0) {
                        /*
                         *      Fail to be backwards compatible.
index 11bca64..2624f42 100644 (file)
@@ -94,8 +94,7 @@ static int command_write_magic(int newfd, listen_socket_t *sock);
  */
 static size_t xlat_listen(UNUSED void *instance, REQUEST *request,
                       const char *fmt, char *out,
-                      size_t outlen,
-                      UNUSED RADIUS_ESCAPE_STRING func)
+                      size_t outlen)
 {
        const char *value = NULL;
        CONF_PAIR *cp;
index 6a20fd9..61ed1e3 100644 (file)
@@ -257,7 +257,7 @@ void radlog_request(int lvl, int priority, REQUEST *request, const char *msg, ..
                 */
                
                radius_xlat(buffer, sizeof(buffer), filename,
-                           request, NULL); /* FIXME: escape chars! */
+                           request, NULL, NULL); /* FIXME: escape chars! */
                request->radlog = rl;
                
                p = strrchr(buffer, FR_DIR_SEP);
index 78d58ce..b5fc646 100644 (file)
@@ -296,7 +296,7 @@ static const CONF_PARSER bootstrap_config[] = {
 #define MAX_ARGV (256)
 
 
-static size_t config_escape_func(char *out, size_t outlen, const char *in)
+static size_t config_escape_func(UNUSED REQUEST *request, char *out, size_t outlen, const char *in, UNUSED void *arg)
 {
        size_t len = 0;
        static const char *disallowed = "%{}\\'\"`";
@@ -353,8 +353,7 @@ static size_t config_escape_func(char *out, size_t outlen, const char *in)
  */
 static size_t xlat_config(void *instance, REQUEST *request,
                          const char *fmt, char *out,
-                         size_t outlen,
-                         RADIUS_ESCAPE_STRING func)
+                         size_t outlen)
 {
        const char *value;
        CONF_PAIR *cp;
@@ -367,7 +366,7 @@ static size_t xlat_config(void *instance, REQUEST *request,
        /*
         *      Expand it safely.
         */
-       if (!radius_xlat(buffer, sizeof(buffer), fmt, request, config_escape_func)) {
+       if (!radius_xlat(buffer, sizeof(buffer), fmt, request, config_escape_func, NULL)) {
                return 0;
        }
 
@@ -392,7 +391,9 @@ static size_t xlat_config(void *instance, REQUEST *request,
                }
        }
 
-       return func(out, outlen, value);
+       strlcpy(out, value, outlen);
+
+       return strlen(out);
 }
 
 
@@ -401,8 +402,7 @@ static size_t xlat_config(void *instance, REQUEST *request,
  */
 static size_t xlat_client(UNUSED void *instance, REQUEST *request,
                       const char *fmt, char *out,
-                      size_t outlen,
-                      UNUSED RADIUS_ESCAPE_STRING func)
+                      size_t outlen)
 {
        const char *value = NULL;
        CONF_PAIR *cp;
index 5e74334..3c6ad42 100644 (file)
@@ -627,7 +627,7 @@ int modcall(int component, modcallable *c, REQUEST *request)
 
                        if (!mx->exec) {
                                radius_xlat(buffer, sizeof(buffer),
-                                           mx->xlat_name, request, NULL);
+                                           mx->xlat_name, request, NULL, NULL);
                        } else {
                                RDEBUG("`%s`", mx->xlat_name);
                                radius_exec_program(mx->xlat_name, request,
@@ -730,7 +730,7 @@ int modcall(int component, modcallable *c, REQUEST *request)
                                        }
                                } else {
                                        radius_xlat(buffer, sizeof(buffer),
-                                                   child->name, request, NULL);
+                                                   child->name, request, NULL, NULL);
                                }
                                null_case = q = NULL;
                                for(p = g->children; p; p = p->next) {
index 7f192e4..30f319d 100644 (file)
@@ -47,7 +47,8 @@ struct main_config_t mainconfig;
 char *request_log_file = NULL;
 char *debug_log_file = NULL;
 int radius_xlat(UNUSED char *out, UNUSED int outlen, UNUSED const char *fmt,
-               UNUSED REQUEST *request, UNUSED RADIUS_ESCAPE_STRING func)
+               UNUSED REQUEST *request,
+               UNUSED RADIUS_ESCAPE_STRING func, UNUSED void *arg)
 {
        return -1;
 }
index ad3ba83..613d0e2 100644 (file)
@@ -89,7 +89,8 @@ struct main_config_t mainconfig;
 char *request_log_file = NULL;
 char *debug_log_file = NULL;
 int radius_xlat(UNUSED char *out, UNUSED int outlen, UNUSED const char *fmt,
-               UNUSED REQUEST *request, UNUSED RADIUS_ESCAPE_STRING func)
+               UNUSED REQUEST *request,
+               UNUSED RADIUS_ESCAPE_STRING func, UNUSED void *arg)
 {
        return -1;
 }
index 4bb804e..81d1eb0 100644 (file)
@@ -81,7 +81,8 @@ struct main_config_t mainconfig;
 char *request_log_file = NULL;
 char *debug_log_file = NULL;
 int radius_xlat(char *out, UNUSED int outlen, UNUSED const char *fmt,
-               UNUSED REQUEST *request, UNUSED RADIUS_ESCAPE_STRING func)
+               UNUSED REQUEST *request,
+               UNUSED RADIUS_ESCAPE_STRING func, UNUSED void *arg)
 {
        *out = 0;
        return 0;
index c2a1af6..ff74aa6 100644 (file)
@@ -230,8 +230,7 @@ static size_t xlat_cs(CONF_SECTION *cs, const char *fmt, char *out, size_t outle
  *     Xlat for %{home_server:foo}
  */
 static size_t xlat_home_server(UNUSED void *instance, REQUEST *request,
-                              const char *fmt, char *out, size_t outlen,
-                              UNUSED RADIUS_ESCAPE_STRING func)
+                              const char *fmt, char *out, size_t outlen)
 {
        if (!fmt || !out || (outlen < 1)) return 0;
 
@@ -248,8 +247,7 @@ static size_t xlat_home_server(UNUSED void *instance, REQUEST *request,
  *     Xlat for %{home_server_pool:foo}
  */
 static size_t xlat_server_pool(UNUSED void *instance, REQUEST *request,
-                              const char *fmt, char *out, size_t outlen,
-                              UNUSED RADIUS_ESCAPE_STRING func)
+                              const char *fmt, char *out, size_t outlen)
 {
        if (!fmt || !out || (outlen < 1)) return 0;
 
index 0650e3b..3ae5414 100644 (file)
@@ -1696,7 +1696,7 @@ int cbtls_verify(int ok, X509_STORE_CTX *ctx)
                 *      previous checks passed.
                 */
                if (my_ok && conf->check_cert_cn) {
-                       if (!radius_xlat(cn_str, sizeof(cn_str), conf->check_cert_cn, request, NULL)) {
+                       if (!radius_xlat(cn_str, sizeof(cn_str), conf->check_cert_cn, request, NULL, NULL)) {
                                radlog(L_ERR, "rlm_eap_tls (%s): xlat failed.",
                                       conf->check_cert_cn);
                                /* if this fails, fail the verification */
index c5f0060..e1df052 100644 (file)
@@ -109,7 +109,7 @@ int radius_compare_vps(REQUEST *request, VALUE_PAIR *check, VALUE_PAIR *vp)
                regmatch_t rxmatch[REQUEST_MAX_REGEX + 1];
 
                snprintf(name, sizeof(name), "%%{%s}", check->name);
-               radius_xlat(value, sizeof(value), name, request, NULL);
+               radius_xlat(value, sizeof(value), name, request, NULL, NULL);
 
                /*
                 *      Include substring matches.
@@ -186,7 +186,7 @@ int radius_compare_vps(REQUEST *request, VALUE_PAIR *check, VALUE_PAIR *vp)
                regmatch_t rxmatch[REQUEST_MAX_REGEX + 1];
 
                snprintf(name, sizeof(name), "%%{%s}", check->name);
-               radius_xlat(value, sizeof(value), name, request, NULL);
+               radius_xlat(value, sizeof(value), name, request, NULL, NULL);
 
                /*
                 *      Include substring matches.
@@ -568,7 +568,7 @@ int paircompare(REQUEST *req, VALUE_PAIR *request, VALUE_PAIR *check,
                        check_item->flags.do_xlat = 0;
                        rcode = radius_xlat(buffer, sizeof(buffer),
                                            check_item->vp_strvalue,
-                                           req, NULL);
+                                           req, NULL, NULL);
 
                        /*
                         *      Parse the string into a new value.
@@ -680,7 +680,7 @@ void pairxlatmove(REQUEST *req, VALUE_PAIR **to, VALUE_PAIR **from)
                        i->flags.do_xlat = 0;
                        rcode = radius_xlat(buffer, sizeof(buffer),
                                            i->vp_strvalue,
-                                           req, NULL);
+                                           req, NULL, NULL);
 
                        /*
                         *      Parse the string into a new value.
index 942d891..68b62ae 100644 (file)
@@ -74,14 +74,11 @@ static int xlat_inst[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 };     /* up to 8 for regex */
 /**
  * @brief Convert the value on a VALUE_PAIR to string
  */
-static int valuepair2str(char * out,int outlen,VALUE_PAIR * pair,
-                        int type, RADIUS_ESCAPE_STRING func)
+static int valuepair2str(char * out,int outlen,VALUE_PAIR * pair, int type)
 {
-       char buffer[MAX_STRING_LEN * 4];
-
        if (pair != NULL) {
-               vp_prints_value(buffer, sizeof(buffer), pair, -1);
-               return func(out, outlen, buffer);
+               vp_prints_value(out, outlen, pair, -1);
+               return strlen(out);
        }
 
        switch (type) {
@@ -130,8 +127,7 @@ redo:
  *     Dynamically translate for check:, request:, reply:, etc.
  */
 static size_t xlat_packet(void *instance, REQUEST *request,
-                         const char *fmt, char *out, size_t outlen,
-                         RADIUS_ESCAPE_STRING func)
+                         const char *fmt, char *out, size_t outlen)
 {
        DICT_ATTR       *da;
        VALUE_PAIR      *vp;
@@ -297,7 +293,7 @@ static size_t xlat_packet(void *instance, REQUEST *request,
                        for (vp = pairfind_tag(vps, da, tag);
                             vp != NULL;
                             vp = pairfind_tag(vp->next, da, tag)) {
-                               count = valuepair2str(out, outlen - 1, vp, da->type, func);
+                               count = valuepair2str(out, outlen - 1, vp, da->type);
                                rad_assert(count <= outlen);
                                total += count + 1;
                                outlen -= (count + 1);
@@ -345,7 +341,7 @@ static size_t xlat_packet(void *instance, REQUEST *request,
                        return snprintf(out, outlen, "%u", vp->vp_integer);
                }
 
-               return valuepair2str(out, outlen, vp, da->type, func);
+               return valuepair2str(out, outlen, vp, da->type);
        }
 
        vp = pairfind(vps, da->attr, da->vendor);
@@ -472,8 +468,7 @@ static size_t xlat_packet(void *instance, REQUEST *request,
                        }
 
                        localvp.type = da->type;
-                       return valuepair2str(out, outlen, &localvp,
-                                            da->type, func);
+                       return valuepair2str(out, outlen, &localvp, da->type);
                }
 
                /*
@@ -487,15 +482,14 @@ static size_t xlat_packet(void *instance, REQUEST *request,
        /*
         *      Convert the VP to a string, and return it.
         */
-       return valuepair2str(out, outlen, vp, da->type, func);
+       return valuepair2str(out, outlen, vp, da->type);
 }
 
 /**
  * @brief Print data as integer, not as VALUE.
  */
 static size_t xlat_integer(UNUSED void *instance, REQUEST *request,
-                          const char *fmt, char *out, size_t outlen,
-                          UNUSED RADIUS_ESCAPE_STRING func)
+                          const char *fmt, char *out, size_t outlen)
 {
        VALUE_PAIR *vp;
 
@@ -527,8 +521,7 @@ static size_t xlat_integer(UNUSED void *instance, REQUEST *request,
  * @brief Print data as hex, not as VALUE.
  */
 static size_t xlat_hex(UNUSED void *instance, REQUEST *request,
-                      const char *fmt, char *out, size_t outlen,
-                      UNUSED RADIUS_ESCAPE_STRING func)
+                      const char *fmt, char *out, size_t outlen)
 {
        size_t i;
        uint8_t *p;
@@ -562,8 +555,7 @@ static size_t xlat_hex(UNUSED void *instance, REQUEST *request,
  * @brief Prints the current module processing the request
  */
 static size_t xlat_module(UNUSED void *instance, REQUEST *request,
-                         UNUSED const char *fmt, char *out, size_t outlen,
-                         UNUSED RADIUS_ESCAPE_STRING func)
+                         UNUSED const char *fmt, char *out, size_t outlen)
 {
        strlcpy(out, request->module, outlen);
 
@@ -577,8 +569,7 @@ static size_t xlat_module(UNUSED void *instance, REQUEST *request,
  * @see modcall()
  */
 static size_t xlat_foreach(void *instance, REQUEST *request,
-                          UNUSED const char *fmt, char *out, size_t outlen,
-                          RADIUS_ESCAPE_STRING func)
+                          UNUSED const char *fmt, char *out, size_t outlen)
 {
        VALUE_PAIR      **pvp;
 
@@ -592,7 +583,7 @@ static size_t xlat_foreach(void *instance, REQUEST *request,
                return 0;
        }
 
-       return valuepair2str(out, outlen, (*pvp), (*pvp)->type, func);  
+       return valuepair2str(out, outlen, (*pvp), (*pvp)->type);
 }
 #endif
 
@@ -604,8 +595,7 @@ static size_t xlat_foreach(void *instance, REQUEST *request,
  * expand to "\n\n\n"
  */
 static size_t xlat_string(UNUSED void *instance, REQUEST *request,
-                         const char *fmt, char *out, size_t outlen,
-                         UNUSED RADIUS_ESCAPE_STRING func)
+                         const char *fmt, char *out, size_t outlen)
 {
        int len;
        VALUE_PAIR *vp;
@@ -635,8 +625,7 @@ static size_t xlat_string(UNUSED void *instance, REQUEST *request,
  * @brief Expand regexp matches %{0} to %{8}
  */
 static size_t xlat_regex(void *instance, REQUEST *request,
-                        const char *fmt, char *out, size_t outlen,
-                        RADIUS_ESCAPE_STRING func)
+                        const char *fmt, char *out, size_t outlen)
 {
        char *regex;
 
@@ -645,7 +634,6 @@ static size_t xlat_regex(void *instance, REQUEST *request,
         *      are already in the "instance".
         */
        fmt = fmt;              /* -Wunused */
-       func = func;            /* -Wunused FIXME: do escaping? */
 
        regex = request_data_reference(request, request,
                                 REQUEST_DATA_REGEX | *(int *)instance);
@@ -666,8 +654,7 @@ static size_t xlat_regex(void *instance, REQUEST *request,
  * Example %{debug:3}
  */
 static size_t xlat_debug(UNUSED void *instance, REQUEST *request,
-                        const char *fmt, char *out, size_t outlen,
-                        UNUSED RADIUS_ESCAPE_STRING func)
+                        const char *fmt, char *out, size_t outlen)
 {
        int level = 0;
        
@@ -910,7 +897,7 @@ void xlat_free(void)
  */
 static int decode_attribute(const char **from, char **to, int freespace,
                             REQUEST *request,
-                            RADIUS_ESCAPE_STRING func)
+                            RADIUS_ESCAPE_STRING func, void *funcarg)
 {
        int     do_length = 0;
        const char *module_name, *xlat_str;
@@ -1011,7 +998,7 @@ static int decode_attribute(const char **from, char **to, int freespace,
                 *      Expand the first one.  If we did, exit the
                 *      conditional.
                 */
-               retlen = radius_xlat(q, freespace, buffer, request, func);
+               retlen = radius_xlat(q, freespace, buffer, request, func, funcarg);
                if (retlen) {
                        q += retlen;
                        goto done;
@@ -1023,7 +1010,7 @@ static int decode_attribute(const char **from, char **to, int freespace,
                 */
                if (expand2) {
                        retlen = radius_xlat(q, freespace, l,
-                                           request, func);
+                                           request, func, funcarg);
                        if (retlen) {
                                q += retlen;
                        }
@@ -1119,8 +1106,21 @@ do_xlat:
 
        if (!c->internal) RDEBUG3("radius_xlat: Running registered xlat function of module %s for string \'%s\'",
                                  c->module, xlat_str);
-       retlen = c->do_xlat(c->instance, request, xlat_str,
-                           q, freespace, func);
+       if (func) {
+               /* xlat to a temporary buffer, then escape */
+               char tmpbuf[8192];
+               retlen = c->do_xlat(c->instance, request, xlat_str, tmpbuf, sizeof(tmpbuf));
+               if (retlen > 0) {
+                       retlen = func(request, q, freespace, tmpbuf, funcarg);
+                       if (retlen > 0) {
+                               RDEBUG2("string escaped from \'%s\' to \'%s\'", tmpbuf, q);
+                       } else if (retlen < 0) {
+                               RDEBUG2("string escape failed");
+                       }
+               }
+       } else {
+               retlen = c->do_xlat(c->instance, request, xlat_str, q, freespace);
+       }
        if (retlen > 0) {
                if (do_length) {
                        snprintf(q, freespace, "%d", retlen);
@@ -1132,7 +1132,7 @@ do_xlat:
                 *      Expand the second bit.
                 */
                RDEBUG2("\t... expanding second conditional");
-               retlen = radius_xlat(q, freespace, next, request, func);
+               retlen = radius_xlat(q, freespace, next, request, func, funcarg);
        }
        q += retlen;
 
@@ -1141,32 +1141,6 @@ done:
        return 0;
 }
 
-/*
- *  If the caller doesn't pass xlat an escape function, then
- *  we use this one.  It simplifies the coding, as the check for
- *  func == NULL only happens once.
- */
-static size_t xlat_copy(char *out, size_t outlen, const char *in)
-{
-       int freespace = outlen;
-
-       if (outlen < 1) return 0;
-
-       while ((*in) && (freespace > 1)) {
-               /*
-                *  Copy data.
-                *
-                *  FIXME: Do escaping of bad stuff!
-                */
-               *(out++) = *(in++);
-
-               freespace--;
-       }
-       *out = '\0';
-
-       return (outlen - freespace); /* count does not include NUL */
-}
-
 /**
  * @brief Replace %whatever in a string.
  *
@@ -1180,7 +1154,8 @@ static size_t xlat_copy(char *out, size_t outlen, const char *in)
  * @return length of string written @bug should really have -1 for failure
  */
 int radius_xlat(char *out, int outlen, const char *fmt,
-               REQUEST *request, RADIUS_ESCAPE_STRING func)
+               REQUEST *request,
+               RADIUS_ESCAPE_STRING func, void *funcarg)
 {
        int c, len, freespace;
        const char *p;
@@ -1189,20 +1164,12 @@ int radius_xlat(char *out, int outlen, const char *fmt,
        VALUE_PAIR *tmp;
        struct tm *TM, s_TM;
        char tmpdt[40]; /* For temporary storing of dates */
-       int openbraces=0;
 
        /*
         *      Catch bad modules.
         */
        if (!fmt || !out || !request) return 0;
 
-       /*
-        *  Ensure that we always have an escaping function.
-        */
-       if (func == NULL) {
-               func = xlat_copy;
-       }
-
                q = out;
        p = fmt;
        while (*p) {
@@ -1218,11 +1185,6 @@ int radius_xlat(char *out, int outlen, const char *fmt,
                         * then we assume this brace is NOT literal, but is
                         * a closing brace and apply it
                         */
-                       if ((c == '}') && openbraces) {
-                               openbraces--;
-                               p++; /* skip it */
-                               continue;
-                       }
                        *q++ = *p++;
                        continue;
                }
@@ -1258,7 +1220,7 @@ int radius_xlat(char *out, int outlen, const char *fmt,
                } else if (c == '%') switch(*p) {
                        case '{':
                                p--;
-                               if (decode_attribute(&p, &q, freespace, request, func) < 0) return 0;
+                               if (decode_attribute(&p, &q, freespace, request, func, funcarg) < 0) return 0;
                                break;
 
                        case '%':
index 86374a4..c7dc1b2 100644 (file)
@@ -88,26 +88,26 @@ static int do_acctlog_acct(void *instance, REQUEST *request)
     if ((pair = pairfind(request->packet->vps, PW_ACCT_STATUS_TYPE, 0)) != NULL) {
         acctstatustype = pair->vp_integer;
     } else {
-        radius_xlat(logstr, sizeof(logstr), "packet has no accounting status type. [user '%{User-Name}', nas '%{NAS-IP-Address}']", request, NULL);
+        radius_xlat(logstr, sizeof(logstr), "packet has no accounting status type. [user '%{User-Name}', nas '%{NAS-IP-Address}']", request, NULL, NULL);
         radlog(L_ERR, "rlm_acctlog (%s)", logstr);
         return RLM_MODULE_INVALID;
     }
 
        switch (acctstatustype) {
                case PW_STATUS_START:
-                       radius_xlat(logstr, sizeof(logstr), inst->acctstart, request, NULL);
+                       radius_xlat(logstr, sizeof(logstr), inst->acctstart, request, NULL, NULL);
                break;
                case PW_STATUS_STOP:
-                       radius_xlat(logstr, sizeof(logstr), inst->acctstop, request, NULL);
+                       radius_xlat(logstr, sizeof(logstr), inst->acctstop, request, NULL, NULL);
                break;
                case PW_STATUS_ALIVE:
-                       radius_xlat(logstr, sizeof(logstr), inst->acctupdate, request, NULL);
+                       radius_xlat(logstr, sizeof(logstr), inst->acctupdate, request, NULL, NULL);
                break;
                case PW_STATUS_ACCOUNTING_ON:
-                       radius_xlat(logstr, sizeof(logstr), inst->accton, request, NULL);
+                       radius_xlat(logstr, sizeof(logstr), inst->accton, request, NULL, NULL);
                break;
                case PW_STATUS_ACCOUNTING_OFF:
-                       radius_xlat(logstr, sizeof(logstr), inst->acctoff, request, NULL);
+                       radius_xlat(logstr, sizeof(logstr), inst->acctoff, request, NULL, NULL);
                break;
 
        default:
index 35a6d52..46f85ef 100644 (file)
@@ -199,7 +199,7 @@ static int attr_filter_common(void *instance, REQUEST *request,
                int len;
 
                len = radius_xlat(buffer, sizeof(buffer), inst->key,
-                                 request, NULL);
+                                 request, NULL, NULL);
                if (!len) {
                        return RLM_MODULE_NOOP;
                }
index fd47702..78754a4 100644 (file)
@@ -178,7 +178,7 @@ static int do_attr_rewrite(void *instance, REQUEST *request)
 
        if (data->new_attr){
                /* new_attribute = yes */
-               if (!radius_xlat(replace_STR, sizeof(replace_STR), data->replace, request, NULL)) {
+               if (!radius_xlat(replace_STR, sizeof(replace_STR), data->replace, request, NULL, NULL)) {
                        DEBUG2("%s: xlat on replace string failed.", data->name);
                        return ret;
                }
@@ -274,7 +274,7 @@ do_again:
                if (data->nocase)
                        cflags |= REG_ICASE;
 
-               if (!radius_xlat(search_STR, sizeof(search_STR), data->search, request, NULL) && data->search_len != 0) {
+               if (!radius_xlat(search_STR, sizeof(search_STR), data->search, request, NULL, NULL) && data->search_len != 0) {
                        DEBUG2("%s: xlat on search string failed.", data->name);
                        return ret;
                }
@@ -367,7 +367,7 @@ do_again:
 
                        if (!done_xlat){
                                if (data->replace_len != 0 &&
-                               radius_xlat(replace_STR, sizeof(replace_STR), data->replace, request, NULL) == 0) {
+                               radius_xlat(replace_STR, sizeof(replace_STR), data->replace, request, NULL, NULL) == 0) {
                                        DEBUG2("%s: xlat on replace string failed.", data->name);
                                        return ret;
                                }
index e3923a1..1499cae 100644 (file)
@@ -279,7 +279,7 @@ static rlm_cache_entry_t *cache_add(rlm_cache_t *inst, REQUEST *request,
                 *      I don't want to make that change for 2.0.
                 */
                radius_xlat(buffer, sizeof(buffer), cf_pair_value(cp),
-                           request, NULL);
+                           request, NULL, NULL);
 
                vp = pairmake(p, buffer, cf_pair_operator(cp));
                pairadd(vps, vp);
@@ -361,9 +361,8 @@ static int cache_verify(rlm_cache_t *inst)
 /*
  *     Allow single attribute values to be retrieved from the cache.
  */
-static int cache_xlat(void *instance, REQUEST *request,
-                     char *fmt, char *out, size_t freespace,
-                     UNUSED RADIUS_ESCAPE_STRING func)
+static size_t cache_xlat(void *instance, REQUEST *request,
+                     const char *fmt, char *out, size_t freespace)
 {
        rlm_cache_entry_t *c;
        rlm_cache_t *inst = instance;
@@ -373,7 +372,7 @@ static int cache_xlat(void *instance, REQUEST *request,
        const char *p = fmt;
        char buffer[1024];
 
-       radius_xlat(buffer, sizeof(buffer), inst->key, request, NULL);
+       radius_xlat(buffer, sizeof(buffer), inst->key, request, NULL, NULL);
 
        c = cache_find(inst, request, buffer);
        
@@ -500,7 +499,7 @@ static int cache_instantiate(CONF_SECTION *conf, void **instance)
         *      Register the cache xlat function
         */
        inst->xlat_name = strdup(xlat_name);
-       xlat_register(xlat_name, (RAD_XLAT_FUNC)cache_xlat, inst);
+       xlat_register(xlat_name, cache_xlat, inst);
 
        if (!inst->key || !*inst->key) {
                radlog(L_ERR, "rlm_cache: You must specify a key");
@@ -576,7 +575,7 @@ static int cache_it(void *instance, REQUEST *request)
        VALUE_PAIR *vp;
        char buffer[1024];
 
-       radius_xlat(buffer, sizeof(buffer), inst->key, request, NULL);
+       radius_xlat(buffer, sizeof(buffer), inst->key, request, NULL, NULL);
 
        c = cache_find(inst, request, buffer);
        
index 81b5352..dffaac0 100644 (file)
@@ -223,7 +223,7 @@ static int do_detail(void *instance, REQUEST *request, RADIUS_PACKET *packet,
         *      feed it through radius_xlat() to expand the
         *      variables.
         */
-       if (radius_xlat(buffer, sizeof(buffer), inst->detailfile, request, NULL) == 0) {
+       if (radius_xlat(buffer, sizeof(buffer), inst->detailfile, request, NULL, NULL) == 0) {
                radlog_request(L_ERR, 0, request, "rlm_detail: Failed to expand detail file %s",
                    inst->detailfile);
            return RLM_MODULE_FAIL;
@@ -368,7 +368,7 @@ static int do_detail(void *instance, REQUEST *request, RADIUS_PACKET *packet,
                return RLM_MODULE_FAIL;
        }
 
-       if (radius_xlat(timestamp, sizeof(timestamp), inst->header, request, NULL) == 0) {
+       if (radius_xlat(timestamp, sizeof(timestamp), inst->header, request, NULL, NULL) == 0) {
                radlog_request(L_ERR, 0, request, "rlm_detail: Unable to expand detail header format %s",
                        inst->header);
                close(outfd);
index af28e90..fd6ec41 100644 (file)
@@ -115,7 +115,7 @@ static int gtc_initiate(void *type_data, EAP_HANDLER *handler)
        EAP_DS *eap_ds = handler->eap_ds;
        rlm_eap_gtc_t *inst = (rlm_eap_gtc_t *) type_data;
 
-       if (!radius_xlat(challenge_str, sizeof(challenge_str), inst->challenge, handler->request, NULL)) {
+       if (!radius_xlat(challenge_str, sizeof(challenge_str), inst->challenge, handler->request, NULL, NULL)) {
                radlog(L_ERR, "rlm_eap_gtc: xlat of \"%s\" failed", inst->challenge);
                return 0;
        }
index 5f16319..adf8dbc 100644 (file)
@@ -118,8 +118,7 @@ static VALUE_PAIR **decode_string(REQUEST *request, const char *string)
  *     Do xlat of strings.
  */
 static size_t exec_xlat(void *instance, REQUEST *request,
-                    const char *fmt, char *out, size_t outlen,
-                    UNUSED RADIUS_ESCAPE_STRING func)
+                    const char *fmt, char *out, size_t outlen)
 {
        int             result;
        rlm_exec_t      *inst = instance;
index 247e480..0f2cda0 100644 (file)
@@ -80,7 +80,7 @@ static int expiration_authorize(void *instance, REQUEST *request)
                        RDEBUG("Account has expired");
 
                        if (data->msg && data->msg[0]){
-                               if (!radius_xlat(msg, sizeof(msg), data->msg, request, NULL)) {
+                               if (!radius_xlat(msg, sizeof(msg), data->msg, request, NULL, NULL)) {
                                        radlog(L_ERR, "rlm_expiration: xlat failed.");
                                        return RLM_MODULE_FAIL;
                                }
index 52aec03..6923a21 100644 (file)
@@ -228,7 +228,7 @@ static int genericcmp(void *instance UNUSED,
 
                snprintf(name, sizeof(name), "%%{%s}", check->name);
 
-               radius_xlat(value, sizeof(value), name, req, NULL);
+               radius_xlat(value, sizeof(value), name, req, NULL, NULL);
                vp = pairmake(check->name, value, check->operator);
 
                /*
index f209268..401084b 100644 (file)
@@ -235,7 +235,7 @@ static int get_number(REQUEST *request, const char **string, int64_t *answer)
  *  Do xlat of strings!
  */
 static size_t expr_xlat(void *instance, REQUEST *request, const char *fmt,
-                       char *out, size_t outlen, RADIUS_ESCAPE_STRING func)
+                       char *out, size_t outlen)
 {
        int             rcode;
        int64_t         result;
@@ -248,7 +248,7 @@ static size_t expr_xlat(void *instance, REQUEST *request, const char *fmt,
        /*
         * Do an xlat on the provided string (nice recursive operation).
         */
-       if (!radius_xlat(buffer, sizeof(buffer), fmt, request, func)) {
+       if (!radius_xlat(buffer, sizeof(buffer), fmt, request, NULL, NULL)) {
                radlog(L_ERR, "rlm_expr: xlat failed.");
                *out = '\0';
                return 0;
@@ -277,8 +277,7 @@ static size_t expr_xlat(void *instance, REQUEST *request, const char *fmt,
  *
  */
 static size_t rand_xlat(UNUSED void *instance, REQUEST *request, const char *fmt,
-                       char *out, size_t outlen,
-                       RADIUS_ESCAPE_STRING func)
+                       char *out, size_t outlen)
 {
        int64_t         result;
        char            buffer[256];
@@ -286,7 +285,7 @@ static size_t rand_xlat(UNUSED void *instance, REQUEST *request, const char *fmt
        /*
         * Do an xlat on the provided string (nice recursive operation).
         */
-       if (!radius_xlat(buffer, sizeof(buffer), fmt, request, func)) {
+       if (!radius_xlat(buffer, sizeof(buffer), fmt, request, NULL, NULL)) {
                radlog(L_ERR, "rlm_expr: xlat failed.");
                *out = '\0';
                return 0;
@@ -314,8 +313,7 @@ static size_t rand_xlat(UNUSED void *instance, REQUEST *request, const char *fmt
  *  Format identical to String::Random.
  */
 static size_t randstr_xlat(UNUSED void *instance, REQUEST *request,
-                          const char *fmt, char *out, size_t outlen,
-                          RADIUS_ESCAPE_STRING func)
+                          const char *fmt, char *out, size_t outlen)
 {
        char            *p;
        char            buffer[1024];
@@ -328,7 +326,7 @@ static size_t randstr_xlat(UNUSED void *instance, REQUEST *request,
        /*
         * Do an xlat on the provided string (nice recursive operation).
         */
-       len = radius_xlat(buffer, sizeof(buffer), fmt, request, func);
+       len = radius_xlat(buffer, sizeof(buffer), fmt, request, NULL, NULL);
        if (!len) {
                radlog(L_ERR, "rlm_expr: xlat failed.");
                *out = '\0';
@@ -426,8 +424,7 @@ static size_t randstr_xlat(UNUSED void *instance, REQUEST *request,
  * Example: "%{urlquote:http://example.org/}" == "http%3A%47%47example.org%47"
  */
 static size_t urlquote_xlat(UNUSED void *instance, REQUEST *request,
-                           const char *fmt, char *out, size_t outlen,
-                           UNUSED RADIUS_ESCAPE_STRING func)
+                           const char *fmt, char *out, size_t outlen)
 {
        char    *p;
        char    buffer[1024];
@@ -436,7 +433,7 @@ static size_t urlquote_xlat(UNUSED void *instance, REQUEST *request,
        
        if (outlen <= 1) return 0;
 
-       len = radius_xlat(buffer, sizeof(buffer), fmt, request, func);
+       len = radius_xlat(buffer, sizeof(buffer), fmt, request, NULL, NULL);
        if (!len) {
                radlog(L_ERR, "rlm_expr: xlat failed.");
                *out = '\0';
@@ -480,8 +477,7 @@ static size_t urlquote_xlat(UNUSED void *instance, REQUEST *request,
  * Example: "%{escape:<img>foo.jpg</img>}" == "=60img=62foo.jpg=60=/img=62"
  */
 static size_t escape_xlat(UNUSED void *instance, REQUEST *request,
-                         const char *fmt, char *out, size_t outlen,
-                         UNUSED RADIUS_ESCAPE_STRING func)
+                         const char *fmt, char *out, size_t outlen)
 {
        rlm_expr_t *inst = instance;
        char    *p;
@@ -491,7 +487,7 @@ static size_t escape_xlat(UNUSED void *instance, REQUEST *request,
        
        if (outlen <= 1) return 0;
 
-       len = radius_xlat(buffer, sizeof(buffer), fmt, request, func);
+       len = radius_xlat(buffer, sizeof(buffer), fmt, request, NULL, NULL);
        if (!len) {
                radlog(L_ERR, "rlm_expr: xlat failed.");
                *out = '\0';
@@ -532,15 +528,14 @@ static size_t escape_xlat(UNUSED void *instance, REQUEST *request,
  * Probably only works for ASCII
  */
 static size_t lc_xlat(UNUSED void *instance, REQUEST *request,
-                     const char *fmt, char *out, size_t outlen,
-                     UNUSED RADIUS_ESCAPE_STRING func)
+                     const char *fmt, char *out, size_t outlen)
 {
        char *p, *q;
        char buffer[1024];
 
        if (outlen <= 1) return 0;
 
-       if (!radius_xlat(buffer, sizeof(buffer), fmt, request, func)) {
+       if (!radius_xlat(buffer, sizeof(buffer), fmt, request, NULL, NULL)) {
                *out = '\0';
                return 0;
        }
@@ -564,15 +559,14 @@ static size_t lc_xlat(UNUSED void *instance, REQUEST *request,
  * Probably only works for ASCII
  */
 static size_t uc_xlat(UNUSED void *instance, REQUEST *request,
-                     const char *fmt, char *out, size_t outlen,
-                     UNUSED RADIUS_ESCAPE_STRING func)
+                     const char *fmt, char *out, size_t outlen)
 {
        char *p, *q;
        char buffer[1024];
 
        if (outlen <= 1) return 0;
 
-       if (!radius_xlat(buffer, sizeof(buffer), fmt, request, func)) {
+       if (!radius_xlat(buffer, sizeof(buffer), fmt, request, NULL, NULL)) {
                *out = '\0';
                return 0;
        }
@@ -594,15 +588,14 @@ static size_t uc_xlat(UNUSED void *instance, REQUEST *request,
  * Example: "%{md5:foo}" == "acbd18db4cc2f85cedef654fccc4a4d8"
  */
 static size_t md5_xlat(UNUSED void *instance, REQUEST *request,
-                      const char *fmt, char *out, size_t outlen,
-                      UNUSED RADIUS_ESCAPE_STRING func)
+                      const char *fmt, char *out, size_t outlen)
 {
        char buffer[1024];
        uint8_t digest[16];
        int i;
        FR_MD5_CTX ctx;
 
-       if (!radius_xlat(buffer, sizeof(buffer), fmt, request, func)) {
+       if (!radius_xlat(buffer, sizeof(buffer), fmt, request, NULL, NULL)) {
                *out = '\0';
                return 0;
        }
index 31e0b07..edfd57b 100644 (file)
@@ -564,7 +564,7 @@ static int fastuser_authorize(void *instance, REQUEST *request)
                int len;
 
                len = radius_xlat(buffer, sizeof(buffer), inst->key,
-                                 request, NULL);
+                                 request, NULL, NULL);
                if (len) name = buffer;
                else name = "NONE";
        }
@@ -721,7 +721,7 @@ static int fastuser_preacct(void *instance, REQUEST *request)
                int len;
 
                len = radius_xlat(buffer, sizeof(buffer), inst->key,
-                                 request, NULL);
+                                 request, NULL, NULL);
                if (len) name = buffer;
                else name = "NONE";
        }
index e0bc59a..b44b686 100644 (file)
@@ -431,7 +431,7 @@ static int file_common(struct file_instance *inst, REQUEST *request,
                int len;
 
                len = radius_xlat(buffer, sizeof(buffer), inst->key,
-                                 request, NULL);
+                                 request, NULL, NULL);
                if (len) name = buffer;
                else name = "NONE";
        }
index 2033d2b..cedf923 100644 (file)
@@ -337,7 +337,7 @@ static int ippool_accounting(void *instance, REQUEST *request)
        }
        switch(acctstatustype){
                case PW_STATUS_STOP:
-                       if (!radius_xlat(xlat_str,MAX_STRING_LEN,data->key, request, NULL)){
+                       if (!radius_xlat(xlat_str,MAX_STRING_LEN,data->key, request, NULL, NULL)){
                                RDEBUG("xlat on the 'key' directive failed");
                                return RLM_MODULE_NOOP;
                        }
@@ -495,7 +495,7 @@ static int ippool_postauth(void *instance, REQUEST *request)
        }
 #endif
 
-       if (!radius_xlat(xlat_str,MAX_STRING_LEN,data->key, request, NULL)){
+       if (!radius_xlat(xlat_str,MAX_STRING_LEN,data->key, request, NULL, NULL)){
                RDEBUG("xlat on the 'key' directive failed");
                return RLM_MODULE_NOOP;
        }
index 92377f9..7dc3ba3 100644 (file)
@@ -362,7 +362,7 @@ static void     fieldcpy(char *, char **);
 #endif
 static VALUE_PAIR *ldap_pairget(LDAP *, LDAPMessage *, TLDAP_RADIUS *,VALUE_PAIR **,int, ldap_instance *);
 static int ldap_groupcmp(void *, REQUEST *, VALUE_PAIR *, VALUE_PAIR *, VALUE_PAIR *, VALUE_PAIR **);
-static size_t ldap_xlat(void *, REQUEST *, const char *, char *, size_t, RADIUS_ESCAPE_STRING);
+static size_t ldap_xlat(void *, REQUEST *, const char *, char *, size_t);
 static LDAP    *ldap_connect(void *instance, const char *, const char *, int, int *, char **);
 static int     read_mappings(ldap_instance* inst);
 
@@ -957,8 +957,9 @@ retry:
 /*
  *     Translate the LDAP queries.
  */
-static size_t ldap_escape_func(char *out, size_t outlen, const char *in)
+static size_t ldap_escape_func(UNUSED REQUEST *request, char *out, size_t outlen, const char *in, void *arg)
 {
+        ldap_instance   *inst = arg;
        size_t len = 0;
 
        while (in[0]) {
@@ -1042,7 +1043,7 @@ static int ldap_groupcmp(void *instance, REQUEST *req,
                 return 1;
         }
 
-        if (!radius_xlat(basedn, sizeof(basedn), inst->basedn, req, ldap_escape_func)) {
+        if (!radius_xlat(basedn, sizeof(basedn), inst->basedn, req, ldap_escape_func, inst)) {
                 DEBUG("rlm_ldap::ldap_groupcmp: unable to create basedn.");
                 return 1;
         }
@@ -1051,7 +1052,7 @@ static int ldap_groupcmp(void *instance, REQUEST *req,
                 char            *user_dn = NULL;
 
                 if (!radius_xlat(filter, sizeof(filter), inst->filter,
-                                       req, ldap_escape_func)){
+                                       req, ldap_escape_func, inst)){
                         DEBUG("rlm_ldap::ldap_groupcmp: unable to create filter");
                         return 1;
                 }
@@ -1090,7 +1091,7 @@ static int ldap_groupcmp(void *instance, REQUEST *req,
         }
 
         if(!radius_xlat(gr_filter, sizeof(gr_filter),
-                       inst->groupmemb_filt, req, ldap_escape_func)) {
+                       inst->groupmemb_filt, req, ldap_escape_func, inst)) {
                 DEBUG("rlm_ldap::ldap_groupcmp: unable to create filter.");
                 return 1;
         }
@@ -1214,8 +1215,7 @@ static int ldap_groupcmp(void *instance, REQUEST *req,
  * Do an xlat on an LDAP URL
  */
 static size_t ldap_xlat(void *instance, REQUEST *request, const char *fmt,
-                    char *out, size_t freespace,
-                    UNUSED RADIUS_ESCAPE_STRING func)
+                    char *out, size_t freespace)
 {
        char url[MAX_FILTER_STR_LEN];
        int res;
@@ -1229,7 +1229,7 @@ static size_t ldap_xlat(void *instance, REQUEST *request, const char *fmt,
        LDAP_CONN *conn;
 
        DEBUG("  [%s] - ldap_xlat", inst->xlat_name);
-       if (!radius_xlat(url, sizeof(url), fmt, request, ldap_escape_func)) {
+       if (!radius_xlat(url, sizeof(url), fmt, request, ldap_escape_func, inst)) {
                radlog (L_ERR, "  [%s] Unable to create LDAP URL.\n", inst->xlat_name);
                return 0;
        }
@@ -1377,13 +1377,13 @@ static int ldap_authorize(void *instance, REQUEST * request)
               request->username->vp_strvalue);
 
        if (!radius_xlat(filter, sizeof(filter), inst->filter,
-                        request, ldap_escape_func)) {
+                        request, ldap_escape_func, inst)) {
                radlog(L_ERR, "  [%s] unable to create filter.\n", inst->xlat_name);
                return RLM_MODULE_INVALID;
        }
 
        if (!radius_xlat(basedn, sizeof(basedn), inst->basedn,
-                        request, ldap_escape_func)) {
+                        request, ldap_escape_func, inst)) {
                radlog(L_ERR, "  [%s] unable to create basedn.\n", inst->xlat_name);
                return RLM_MODULE_INVALID;
        }
@@ -1855,13 +1855,13 @@ static int ldap_authenticate(void *instance, REQUEST * request)
        while ((vp_user_dn = pairfind(request->config_items,
                                      PW_LDAP_USERDN, 0)) == NULL) {
                if (!radius_xlat(filter, sizeof(filter), inst->filter,
-                               request, ldap_escape_func)) {
+                               request, ldap_escape_func, inst)) {
                        radlog(L_ERR, "  [%s] unable to create filter.\n", inst->xlat_name);
                        return RLM_MODULE_INVALID;
                }
 
                if (!radius_xlat(basedn, sizeof(basedn), inst->basedn,
-                               request, ldap_escape_func)) {
+                               request, ldap_escape_func, inst)) {
                        radlog(L_ERR, "  [%s] unable to create basedn.\n", inst->xlat_name);
                        return RLM_MODULE_INVALID;
                }
index 6f228a2..111f770 100644 (file)
@@ -165,7 +165,9 @@ static int linelog_instantiate(CONF_SECTION *conf, void **instance)
 /*
  *     Escape unprintable characters.
  */
-static size_t linelog_escape_func(char *out, size_t outlen, const char *in)
+static size_t linelog_escape_func(UNUSED REQUEST *request,
+               char *out, size_t outlen, const char *in,
+               UNUSED void *arg)
 {
        int len = 0;
 
@@ -243,7 +245,7 @@ static int do_linelog(void *instance, REQUEST *request)
                CONF_PAIR *cp;
 
                radius_xlat(line + 1, sizeof(line) - 2, inst->reference,
-                           request, linelog_escape_func);
+                           request, linelog_escape_func, NULL);
                line[0] = '.';  /* force to be in current section */
 
                /*
@@ -281,7 +283,7 @@ static int do_linelog(void *instance, REQUEST *request)
         */
        if (strcmp(inst->filename, "syslog") != 0) {
                radius_xlat(buffer, sizeof(buffer), inst->filename, request,
-                           NULL);
+                           NULL, NULL);
                
                /* check path and eventually create subdirs */
                p = strrchr(buffer,'/');
@@ -326,7 +328,7 @@ static int do_linelog(void *instance, REQUEST *request)
         *      FIXME: Check length.
         */
        radius_xlat(line, sizeof(line) - 1, value, request,
-                   linelog_escape_func);
+                   linelog_escape_func, NULL);
 
        if (fd >= 0) {
                strcat(line, "\n");
index fd69109..3f915a2 100644 (file)
@@ -197,7 +197,7 @@ static int logintime_authorize(void *instance, REQUEST *request)
                                char msg[MAX_STRING_LEN];
                                VALUE_PAIR *tmp;
 
-                               if (!radius_xlat(msg, sizeof(msg), data->msg, request, NULL)) {
+                               if (!radius_xlat(msg, sizeof(msg), data->msg, request, NULL, NULL)) {
                                        radlog(L_ERR, "rlm_logintime: xlat failed.");
                                        return RLM_MODULE_FAIL;
                                }
index d56636b..0a315f1 100644 (file)
@@ -165,8 +165,7 @@ typedef struct rlm_mschap_t {
  *     attributes.
  */
 static size_t mschap_xlat(void *instance, REQUEST *request,
-                      const char *fmt, char *out, size_t outlen,
-                      RADIUS_ESCAPE_STRING func)
+                      const char *fmt, char *out, size_t outlen)
 {
        size_t          i, data_len;
        uint8_t         *data = NULL;
@@ -177,8 +176,6 @@ static size_t mschap_xlat(void *instance, REQUEST *request,
 
        response = NULL;
 
-       func = func;            /* -Wunused */
-
        /*
         *      Challenge means MS-CHAPv1 challenge, or
         *      hash of MS-CHAPv2 challenge, and peer challenge.
@@ -463,7 +460,7 @@ static size_t mschap_xlat(void *instance, REQUEST *request,
 
                while (isspace(*p)) p++;
 
-               if (!radius_xlat(buf2, sizeof(buf2),p,request,NULL)) {
+               if (!radius_xlat(buf2, sizeof(buf2),p,request,NULL,NULL)) {
                        RDEBUG("xlat failed");
                        *buffer = '\0';
                        return 0;
@@ -489,7 +486,7 @@ static size_t mschap_xlat(void *instance, REQUEST *request,
 
                while (isspace(*p)) p++;
 
-               if (!radius_xlat(buf2, sizeof(buf2),p,request,NULL)) {
+               if (!radius_xlat(buf2, sizeof(buf2),p,request,NULL,NULL)) {
                        RDEBUG("xlat failed");
                        *buffer = '\0';
                        return 0;
@@ -750,7 +747,7 @@ static int do_mschap_cpw(rlm_mschap_t *inst,
                 */
 
                if (inst->ntlm_cpw_username) {
-                       len = radius_xlat(buf, sizeof(buf) - 2, inst->ntlm_cpw_username, request, NULL);
+                       len = radius_xlat(buf, sizeof(buf) - 2, inst->ntlm_cpw_username, request, NULL, NULL);
                        strcat(buf, "\n");
                        len++;
 
@@ -763,7 +760,7 @@ static int do_mschap_cpw(rlm_mschap_t *inst,
                }
 
                if (inst->ntlm_cpw_domain) {
-                       len = radius_xlat(buf, sizeof(buf) - 2, inst->ntlm_cpw_domain, request, NULL);
+                       len = radius_xlat(buf, sizeof(buf) - 2, inst->ntlm_cpw_domain, request, NULL, NULL);
                        strcat(buf, "\n");
                        len++;
 
@@ -1005,7 +1002,7 @@ ntlm_auth_err:
                /*
                 * perform the xlat
                 */
-               result_len = radius_xlat(result, sizeof(result), inst->local_cpw, request, NULL);
+               result_len = radius_xlat(result, sizeof(result), inst->local_cpw, request, NULL, NULL);
                if (!result_len) {
                        RDEBUG("Local MS-CHAPv2 password change - xlat didn't give any result, assuming failure");
                        return -1;
index 7828606..8a7a93a 100644 (file)
@@ -730,7 +730,7 @@ static int pap_auth_nt(REQUEST *request, VALUE_PAIR *vp, char *fmsg)
        }
 
        strlcpy(buff2, "%{mschap:NT-Hash %{User-Password}}", sizeof(buff2));
-       if (!radius_xlat(charbuf, sizeof(charbuf),buff2,request,NULL)){
+       if (!radius_xlat(charbuf, sizeof(charbuf),buff2,request,NULL,NULL)){
                RDEBUG("mschap xlat failed");
                snprintf(fmsg, sizeof(char[MAX_STRING_LEN]),
                        "rlm_pap: mschap xlat failed");
@@ -765,7 +765,7 @@ static int pap_auth_lm(REQUEST *request, VALUE_PAIR *vp, char *fmsg)
        }
 
        strlcpy(buff2, "%{mschap:LM-Hash %{User-Password}}", sizeof(buff2));
-       if (!radius_xlat(charbuf,sizeof(charbuf),buff2,request,NULL)){
+       if (!radius_xlat(charbuf,sizeof(charbuf),buff2,request,NULL,NULL)){
                RDEBUG("mschap xlat failed");
                snprintf(fmsg, sizeof(char[MAX_STRING_LEN]),
                        "rlm_pap: mschap xlat failed");
index 1b410b2..6de2205 100644 (file)
@@ -321,7 +321,7 @@ static XS(XS_radiusd_radlog)
  * The xlat function
  */
 static size_t perl_xlat(void *instance, REQUEST *request, char *fmt, char *out,
-                       size_t freespace, RADIUS_ESCAPE_STRING func)
+                       size_t freespace)
 {
 
        PERL_INST       *inst= (PERL_INST *) instance;
@@ -334,7 +334,7 @@ static size_t perl_xlat(void *instance, REQUEST *request, char *fmt, char *out,
        /*
         * Do an xlat on the provided string (nice recursive operation).
        */
-       if (!radius_xlat(params, sizeof(params), fmt, request, func)) {
+       if (!radius_xlat(params, sizeof(params), fmt, request, NULL, NULL)) {
                radlog(L_ERR, "rlm_perl: xlat failed.");
                return 0;
        }
index 69650ef..3b211fb 100644 (file)
@@ -401,7 +401,7 @@ static int evaluate_print(policy_state_t *state, const policy_item_t *item)
                char buffer[1024];
 
                radius_xlat(buffer, sizeof(buffer), this->rhs,
-                           state->request, NULL);
+                           state->request, NULL, NULL);
                fprintf(fr_log_fp, "%s", buffer);
                if (!strchr(buffer, '\n')) fprintf(fr_log_fp, "\n");
        }
@@ -533,7 +533,7 @@ static int evaluate_condition(policy_state_t *state, const policy_item_t *item)
                        strlcpy(lhs_buffer, data, sizeof(lhs_buffer)); /* FIXME: yuck */
                } else if (this->lhs_type == POLICY_LEX_DOUBLE_QUOTED_STRING) {
                        if (radius_xlat(lhs_buffer, sizeof(lhs_buffer), this->lhs,
-                                       state->request, NULL) > 0) {
+                                       state->request, NULL, NULL) > 0) {
                                data = lhs_buffer;
                        }
                }
@@ -824,7 +824,7 @@ static VALUE_PAIR *assign2vp(REQUEST *request,
        if ((assign->rhs_type == POLICY_LEX_DOUBLE_QUOTED_STRING) &&
            (strchr(assign->rhs, '%') != NULL)) {
                radius_xlat(buffer, sizeof(buffer), assign->rhs,
-                           request, NULL);
+                           request, NULL, NULL);
                value = buffer;
        }
 
index 2192c39..96bca72 100644 (file)
@@ -342,7 +342,7 @@ static int radutmp_accounting(void *instance, REQUEST *request)
        /*
         *      Get the utmp filename, via xlat.
         */
-       radius_xlat(filename, sizeof(filename), inst->filename, request, NULL);
+       radius_xlat(filename, sizeof(filename), inst->filename, request, NULL, NULL);
 
        /*
         *      See if this was a reboot.
@@ -383,7 +383,7 @@ static int radutmp_accounting(void *instance, REQUEST *request)
         *      they told us to use.
         */
        *buffer = '\0';
-       radius_xlat(buffer, sizeof(buffer), inst->username, request, NULL);
+       radius_xlat(buffer, sizeof(buffer), inst->username, request, NULL, NULL);
 
        /*
         *  Copy the previous translated user name.
@@ -574,7 +574,7 @@ static int radutmp_checksimul(void *instance, REQUEST *request)
        /*
         *      Get the filename, via xlat.
         */
-       radius_xlat(filename, sizeof(filename), inst->filename, request, NULL);
+       radius_xlat(filename, sizeof(filename), inst->filename, request, NULL, NULL);
 
        if ((fd = open(filename, O_RDWR)) < 0) {
                /*
@@ -595,7 +595,7 @@ static int radutmp_checksimul(void *instance, REQUEST *request)
        }
 
        *login = '\0';
-       radius_xlat(login, sizeof(login), inst->username, request, NULL);
+       radius_xlat(login, sizeof(login), inst->username, request, NULL, NULL);
        if (!*login) {
                close(fd);
                return RLM_MODULE_NOOP;
index 82a4bf4..695d724 100644 (file)
@@ -137,7 +137,8 @@ static void *redis_create_conn(void *ctx)
        return dissocket;
 }
 
-static size_t redis_escape_func(char *out, size_t outlen, const char *in)
+static size_t redis_escape_func(UNUSED REQUEST *request,
+       char *out, size_t outlen, const char *in, UNUSED void *arg)
 {
 
        size_t len = 0;
@@ -184,9 +185,8 @@ static size_t redis_escape_func(char *out, size_t outlen, const char *in)
 
 }
 
-static int redis_xlat(void *instance, REQUEST *request,
-                     char *fmt, char *out, size_t freespace,
-                     UNUSED RADIUS_ESCAPE_STRING func)
+static size_t redis_xlat(void *instance, REQUEST *request,
+                     const char *fmt, char *out, size_t freespace)
 {
        REDIS_INST *inst = instance;
        REDISSOCK *dissocket;
@@ -196,7 +196,7 @@ static int redis_xlat(void *instance, REQUEST *request,
        char querystr[MAX_QUERY_LEN];
 
        if (!radius_xlat(querystr, sizeof(querystr), fmt, request,
-                   redis_escape_func)) {
+                   redis_escape_func, inst)) {
                radlog(L_ERR, "rlm_redis (%s): xlat failed.",
                       inst->xlat_name);
 
@@ -263,7 +263,7 @@ static int redis_detach(void *instance)
        fr_connection_pool_delete(inst->pool);
 
        if (inst->xlat_name) {
-               xlat_unregister(inst->xlat_name, (RAD_XLAT_FUNC)redis_xlat, instance);
+               xlat_unregister(inst->xlat_name, redis_xlat, instance);
                free(inst->xlat_name);
        }
        free(inst->xlat_name);
@@ -366,7 +366,7 @@ static int redis_instantiate(CONF_SECTION *conf, void **instance)
                xlat_name = cf_section_name1(conf);
 
        inst->xlat_name = strdup(xlat_name);
-       xlat_register(inst->xlat_name, (RAD_XLAT_FUNC)redis_xlat, inst);
+       xlat_register(inst->xlat_name, redis_xlat, inst);
 
        inst->pool = fr_connection_pool_init(conf, inst,
                                             redis_create_conn, NULL,
index d517c29..73659f2 100644 (file)
@@ -68,7 +68,7 @@ static int rediswho_command(const char *fmt, REDISSOCK **dissocket_p,
         *      Do an xlat on the provided string
         */
        if (request) {
-               if (!radius_xlat(query, sizeof (query), fmt, request, NULL)) {
+               if (!radius_xlat(query, sizeof (query), fmt, request, NULL, NULL)) {
                        radlog(L_ERR, "rediswho_command: xlat failed on: '%s'", query);
                        return 0;
                }
index 3abaeb8..87dc9f6 100644 (file)
@@ -1987,7 +1987,7 @@ int rest_request_config(rlm_rest_t *instance, rlm_rest_section_t *section,
                        
                        if (section->username) {
                                radius_xlat(buffer, sizeof(buffer),
-                                           section->username, request, NULL);
+                                           section->username, request, NULL, NULL);
                                            
                                ret = curl_easy_setopt(candle, CURLOPT_USERNAME,
                                                       buffer);
@@ -1995,7 +1995,7 @@ int rest_request_config(rlm_rest_t *instance, rlm_rest_section_t *section,
                        }
                        if (section->password) {
                                radius_xlat(buffer, sizeof(buffer),
-                                           section->password, request, NULL);
+                                           section->password, request, NULL, NULL);
                                            
                                ret = curl_easy_setopt(candle, CURLOPT_PASSWORD,
                                                       buffer);
@@ -2009,7 +2009,7 @@ int rest_request_config(rlm_rest_t *instance, rlm_rest_section_t *section,
                
                        if (section->username) {
                                radius_xlat(buffer, sizeof(buffer),
-                                           section->username, request, NULL);
+                                           section->username, request, NULL, NULL);
                                            
                                ret = curl_easy_setopt(candle,
                                                       CURLOPT_TLSAUTH_USERNAME,
@@ -2018,7 +2018,7 @@ int rest_request_config(rlm_rest_t *instance, rlm_rest_section_t *section,
                        }
                        if (section->password) {
                                radius_xlat(buffer, sizeof(buffer),
-                                           section->password, request, NULL);
+                                           section->password, request, NULL, NULL);
                                            
                                ret = curl_easy_setopt(candle,
                                                       CURLOPT_TLSAUTH_PASSWORD,
@@ -2373,12 +2373,12 @@ ssize_t rest_uri_build(rlm_rest_t *instance, rlm_rest_section_t *section,
        path = (q + 1);
 
        out = buffer;
-       out += radius_xlat(out, bufsize, scheme, request, NULL);
+       out += radius_xlat(out, bufsize, scheme, request, NULL, NULL);
 
        free(scheme);
 
        out += radius_xlat(out, (bufsize - (buffer - out)), path, request,
-                        rest_uri_escape);
+                        rest_uri_escape, NULL);
 
        return (buffer - out);
 }
index 1e459f9..69e6835 100644 (file)
@@ -30,7 +30,7 @@ RCSID("$Id$")
 
 
 typedef struct rlm_soh_t {
-       const char *xlat_name;
+       char *xlat_name;
        int dhcp;
 } rlm_soh_t;
 
@@ -38,7 +38,7 @@ typedef struct rlm_soh_t {
 /*
  * Not sure how to make this useful yet...
  */
-static size_t soh_xlat(UNUSED void *instance, REQUEST *request, char *fmt, char *out, size_t outlen, UNUSED RADIUS_ESCAPE_STRING func) {
+static size_t soh_xlat(UNUSED void *instance, REQUEST *request, const char *fmt, char *out, size_t outlen) {
 
        VALUE_PAIR* vp[6];
        const char *osname;
@@ -116,6 +116,7 @@ static int soh_detach(void *instance) {
 }
 
 static int soh_instantiate(CONF_SECTION *conf, void **instance) {
+       const char *name;
        rlm_soh_t *inst;
 
        inst = *instance = rad_malloc(sizeof(*inst));
@@ -129,9 +130,9 @@ static int soh_instantiate(CONF_SECTION *conf, void **instance) {
                return -1;
        }
 
-       inst->xlat_name = cf_section_name2(conf);
-       if (!inst->xlat_name) inst->xlat_name = cf_section_name1(conf);
-       inst->xlat_name = strdup(inst->xlat_name);
+       name = cf_section_name2(conf);
+       if (!name) name = cf_section_name1(conf);
+       inst->xlat_name = strdup(name);
        xlat_register(inst->xlat_name, soh_xlat, inst);
 
        return 0;
index 480c25c..2dee3ff 100644 (file)
@@ -39,8 +39,6 @@ RCSID("$Id$")
 
 #include "rlm_sql.h"
 
-static char *allowed_chars = NULL;
-
 static const CONF_PARSER section_config[] = {
        { "reference",  PW_TYPE_STRING_PTR,
          offsetof(rlm_sql_config_section_t, reference), NULL, ".query"},
@@ -125,7 +123,7 @@ static int fallthrough(VALUE_PAIR *vp)
  *     Yucky prototype.
  */
 static int generate_sql_clients(SQL_INST *inst);
-static size_t sql_escape_func(char *out, size_t outlen, const char *in);
+static size_t sql_escape_func(REQUEST *, char *out, size_t outlen, const char *in, void *arg);
 
 /*
  *                     SQL xlat function
@@ -134,9 +132,8 @@ static size_t sql_escape_func(char *out, size_t outlen, const char *in);
  *  for inserts, updates and deletes the number of rows afftected will be
  *  returned instead.
  */
-static int sql_xlat(void *instance, REQUEST *request,
-                   char *fmt, char *out, size_t freespace,
-                   UNUSED RADIUS_ESCAPE_STRING func)
+static size_t sql_xlat(void *instance, REQUEST *request,
+                   const char *fmt, char *out, size_t freespace)
 {
        SQLSOCK *sqlsocket;
        SQL_ROW row;
@@ -156,7 +153,7 @@ static int sql_xlat(void *instance, REQUEST *request,
        /*
         * Do an xlat on the provided string (nice recursive operation).
         */
-       if (!radius_xlat(querystr, sizeof(querystr), fmt, request, sql_escape_func)) {
+       if (!radius_xlat(querystr, sizeof(querystr), fmt, request, sql_escape_func, inst)) {
                radlog(L_ERR, "rlm_sql (%s): xlat failed.",
                       inst->config->xlat_name);
                return 0;
@@ -404,8 +401,9 @@ static int generate_sql_clients(SQL_INST *inst)
 /*
  *     Translate the SQL queries.
  */
-static size_t sql_escape_func(char *out, size_t outlen, const char *in)
+static size_t sql_escape_func(UNUSED REQUEST *request, char *out, size_t outlen, const char *in, void *arg)
 {
+       SQL_INST *inst = arg;
        size_t len = 0;
 
        while (in[0]) {
@@ -414,7 +412,7 @@ static size_t sql_escape_func(char *out, size_t outlen, const char *in)
                 *      mime-encoded equivalents.
                 */
                if ((in[0] < 32) ||
-                   strchr(allowed_chars, *in) == NULL) {
+                   strchr(inst->config->allowed_chars, *in) == NULL) {
                        /*
                         *      Only 3 or less bytes available.
                         */
@@ -472,7 +470,7 @@ int sql_set_user(SQL_INST *inst, REQUEST *request, char *sqlusername, const char
        if (username != NULL) {
                strlcpy(tmpuser, username, sizeof(tmpuser));
        } else if (strlen(inst->config->query_user)) {
-               radius_xlat(tmpuser, sizeof(tmpuser), inst->config->query_user, request, NULL);
+               radius_xlat(tmpuser, sizeof(tmpuser), inst->config->query_user, request, NULL, NULL);
        } else {
                return 0;
        }
@@ -521,7 +519,7 @@ static int sql_get_grouplist (SQL_INST *inst, SQLSOCK *sqlsocket, REQUEST *reque
            (inst->config->groupmemb_query[0] == 0))
                return 0;
 
-       if (!radius_xlat(querystr, sizeof(querystr), inst->config->groupmemb_query, request, sql_escape_func)) {
+       if (!radius_xlat(querystr, sizeof(querystr), inst->config->groupmemb_query, request, sql_escape_func, inst)) {
                radlog_request(L_ERR, 0, request, "xlat \"%s\" failed.",
                               inst->config->groupmemb_query);
                return -1;
@@ -672,7 +670,7 @@ static int rlm_sql_process_groups(SQL_INST *inst, REQUEST *request, SQLSOCK *sql
                        return -1;
                }
                pairadd(&request->packet->vps, sql_group);
-               if (!radius_xlat(querystr, sizeof(querystr), inst->config->authorize_group_check_query, request, sql_escape_func)) {
+               if (!radius_xlat(querystr, sizeof(querystr), inst->config->authorize_group_check_query, request, sql_escape_func, inst)) {
                        radlog_request(L_ERR, 0, request,
                                       "Error generating query; rejecting user");
                        /* Remove the grouup we added above */
@@ -700,7 +698,7 @@ static int rlm_sql_process_groups(SQL_INST *inst, REQUEST *request, SQLSOCK *sql
                                /*
                                 *      Now get the reply pairs since the paircompare matched
                                 */
-                               if (!radius_xlat(querystr, sizeof(querystr), inst->config->authorize_group_reply_query, request, sql_escape_func)) {
+                               if (!radius_xlat(querystr, sizeof(querystr), inst->config->authorize_group_reply_query, request, sql_escape_func, inst)) {
                                        radlog_request(L_ERR, 0, request, "Error generating query; rejecting user");
                                        /* Remove the grouup we added above */
                                        pairdelete(&request->packet->vps, PW_SQL_GROUP, 0);
@@ -735,7 +733,7 @@ static int rlm_sql_process_groups(SQL_INST *inst, REQUEST *request, SQLSOCK *sql
                        /*
                         *      Now get the reply pairs since the paircompare matched
                         */
-                       if (!radius_xlat(querystr, sizeof(querystr), inst->config->authorize_group_reply_query, request, sql_escape_func)) {
+                       if (!radius_xlat(querystr, sizeof(querystr), inst->config->authorize_group_reply_query, request, sql_escape_func, inst)) {
                                radlog_request(L_ERR, 0, request, "Error generating query; rejecting user");
                                /* Remove the grouup we added above */
                                pairdelete(&request->packet->vps, PW_SQL_GROUP, 0);
@@ -784,7 +782,7 @@ static int rlm_sql_detach(void *instance)
                if (inst->pool) sql_poolfree(inst);
 
                if (inst->config->xlat_name) {
-                       xlat_unregister(inst->config->xlat_name,(RAD_XLAT_FUNC)sql_xlat, instance);
+                       xlat_unregister(inst->config->xlat_name, sql_xlat, instance);
                        free(inst->config->xlat_name);
                }
 
@@ -810,12 +808,6 @@ static int rlm_sql_detach(void *instance)
                        free(*p);
                        *p = NULL;
                }
-               /*
-                *      Catch multiple instances of the module.
-                */
-               if (allowed_chars == inst->config->allowed_chars) {
-                       allowed_chars = NULL;
-               }
                free(inst->config);
                inst->config = NULL;
        }
@@ -942,7 +934,7 @@ static int rlm_sql_instantiate(CONF_SECTION * conf, void **instance)
         *      Register the SQL xlat function
         */
        inst->config->xlat_name = strdup(xlat_name);
-       xlat_register(xlat_name, (RAD_XLAT_FUNC)sql_xlat, inst);
+       xlat_register(xlat_name, sql_xlat, inst);
                
        /*
         *      Sanity check for crazy people.
@@ -1004,7 +996,6 @@ static int rlm_sql_instantiate(CONF_SECTION * conf, void **instance)
                        goto error;
                }
        }
-       allowed_chars = inst->config->allowed_chars;
 
        *instance = inst;
 
@@ -1061,7 +1052,7 @@ static int rlm_sql_authorize(void *instance, REQUEST * request)
        /*
         * Alright, start by getting the specific entry for the user
         */
-       if (!radius_xlat(querystr, sizeof(querystr), inst->config->authorize_check_query, request, sql_escape_func)) {
+       if (!radius_xlat(querystr, sizeof(querystr), inst->config->authorize_check_query, request, sql_escape_func, inst)) {
                radlog_request(L_ERR, 0, request, "Error generating query; rejecting user");
                sql_release_socket(inst, sqlsocket);
                /* Remove the username we (maybe) added above */
@@ -1090,7 +1081,7 @@ static int rlm_sql_authorize(void *instance, REQUEST * request)
                        /*
                         *      Now get the reply pairs since the paircompare matched
                         */
-                       if (!radius_xlat(querystr, sizeof(querystr), inst->config->authorize_reply_query, request, sql_escape_func)) {
+                       if (!radius_xlat(querystr, sizeof(querystr), inst->config->authorize_reply_query, request, sql_escape_func, inst)) {
                                radlog_request(L_ERR, 0, request, "Error generating query; rejecting user");
                                sql_release_socket(inst, sqlsocket);
                                /* Remove the username we (maybe) added above */
@@ -1238,7 +1229,7 @@ static int rlm_sql_redundant(SQL_INST *inst, REQUEST *request,
                *p++ = '.';
        
        if (radius_xlat(p, (sizeof(path) - (p - path)) - 1,
-                       section->reference, request, NULL) < 0)
+                       section->reference, request, NULL, NULL) < 0)
                return RLM_MODULE_FAIL;
 
        item = cf_reference_item(NULL, section->cs, path);
@@ -1266,7 +1257,7 @@ static int rlm_sql_redundant(SQL_INST *inst, REQUEST *request,
                        goto null_query;
                
                radius_xlat(querystr, sizeof(querystr), value, request,
-                           sql_escape_func);
+                           sql_escape_func, inst);
                if (!*querystr)
                        goto null_query;
                
@@ -1380,7 +1371,7 @@ static int rlm_sql_checksimul(void *instance, REQUEST * request) {
        if(sql_set_user(inst, request, sqlusername, NULL) < 0)
                return RLM_MODULE_FAIL;
 
-       radius_xlat(querystr, sizeof(querystr), inst->config->simul_count_query, request, sql_escape_func);
+       radius_xlat(querystr, sizeof(querystr), inst->config->simul_count_query, request, sql_escape_func, inst);
 
        /* initialize the sql socket */
        sqlsocket = sql_get_socket(inst);
@@ -1424,7 +1415,7 @@ static int rlm_sql_checksimul(void *instance, REQUEST * request) {
                return RLM_MODULE_OK;
        }
 
-       radius_xlat(querystr, sizeof(querystr), inst->config->simul_verify_query, request, sql_escape_func);
+       radius_xlat(querystr, sizeof(querystr), inst->config->simul_verify_query, request, sql_escape_func, inst);
        if(rlm_sql_select_query(&sqlsocket, inst, querystr)) {
                sql_release_socket(inst, sqlsocket);
                return RLM_MODULE_FAIL;
index ee140ff..4255718 100644 (file)
@@ -106,7 +106,7 @@ struct sql_inst {
        int (*sql_set_user)(SQL_INST *inst, REQUEST *request, char *sqlusername, const char *username);
        SQLSOCK *(*sql_get_socket)(SQL_INST * inst);
        int (*sql_release_socket)(SQL_INST * inst, SQLSOCK * sqlsocket);
-       size_t (*sql_escape_func)(char *out, size_t outlen, const char *in);
+       size_t (*sql_escape_func)(REQUEST *, char *out, size_t outlen, const char *in, void *arg);
        int (*sql_query)(SQLSOCK **sqlsocket, SQL_INST *inst, char *query);
        int (*sql_select_query)(SQLSOCK **sqlsocket, SQL_INST *inst, char *query);
        int (*sql_fetch_row)(SQLSOCK **sqlsocket, SQL_INST *inst);
index cd47a61..4959390 100644 (file)
@@ -424,7 +424,7 @@ void rlm_sql_query_log(SQL_INST *inst, REQUEST *request,
 
        if (!filename) return;
 
-       if (!radius_xlat(buffer, sizeof(buffer), filename, request, NULL)) {
+       if (!radius_xlat(buffer, sizeof(buffer), filename, request, NULL, NULL)) {
                radlog(L_ERR, "rlm_sql (%s): xlat failed.",
                       inst->config->xlat_name);
                return;
index 0aca3d4..12ca7ad 100644 (file)
@@ -72,7 +72,6 @@ static const CONF_PARSER module_config[] = {
        { NULL, -1, 0, NULL, NULL }     /* end the list */
 };
 
-static char *allowed_chars = NULL;
 
 /*
  *     Do any per-module initialization that is separate to each
@@ -108,7 +107,6 @@ static int sql_log_instantiate(CONF_SECTION *conf, void **instance)
        }
 
        inst->conf_section = conf;
-       allowed_chars = inst->allowed_chars;
        *instance = inst;
        return 0;
 }
@@ -143,7 +141,6 @@ static int sql_log_detach(void *instance)
                free(*p);
                *p = NULL;
        }
-       allowed_chars = NULL;
        free(inst);
        return 0;
 }
@@ -151,8 +148,9 @@ static int sql_log_detach(void *instance)
 /*
  *     Translate the SQL queries.
  */
-static size_t sql_escape_func(char *out, size_t outlen, const char *in)
+static size_t sql_escape_func(UNUSED REQUEST *request, char *out, size_t outlen, const char *in, void *arg)
 {
+       rlm_sql_log_t   *inst = (rlm_sql_log_t *)arg;
        int len = 0;
 
        while (in[0]) {
@@ -161,7 +159,7 @@ static size_t sql_escape_func(char *out, size_t outlen, const char *in)
                 *      mime-encoded equivalents.
                 */
                if ((in[0] < 32) ||
-                   strchr(allowed_chars, *in) == NULL) {
+                   strchr(inst->allowed_chars, *in) == NULL) {
                        /*
                         *      Only 3 or less bytes available.
                         */
@@ -197,8 +195,9 @@ static size_t sql_escape_func(char *out, size_t outlen, const char *in)
        return len;
 }
 
-static size_t sql_utf8_escape_func(char *out, size_t outlen, const char *in)
+static size_t sql_utf8_escape_func(UNUSED REQUEST *request, char *out, size_t outlen, const char *in, void *arg)
 {
+       rlm_sql_log_t   *inst = (rlm_sql_log_t *)arg;
        size_t len = 0;
        size_t utf8 = 0;
 
@@ -226,7 +225,7 @@ static size_t sql_utf8_escape_func(char *out, size_t outlen, const char *in)
                 *      mime-encoded equivalents.
                 */
                if ((in[0] < 32) ||
-                   strchr(allowed_chars, *in) == NULL) {
+                   strchr(inst->allowed_chars, *in) == NULL) {
                        /*
                         *      Only 3 or less bytes available.
                         */
@@ -283,7 +282,7 @@ static int sql_set_user(rlm_sql_log_t *inst, REQUEST *request, char *sqlusername
                strlcpy(tmpuser, username, MAX_STRING_LEN);
        } else if (inst->sql_user_name[0] != '\0') {
                radius_xlat(tmpuser, sizeof(tmpuser), inst->sql_user_name,
-                           request, NULL);
+                           request, NULL, NULL);
        } else {
                return 0;
        }
@@ -324,7 +323,7 @@ static int sql_xlat_query(rlm_sql_log_t *inst, REQUEST *request, const char *que
        /* Expand variables in the query */
        xlat_query[0] = '\0';
        radius_xlat(xlat_query, len, query, request,
-                   inst->utf8 ? sql_utf8_escape_func : sql_escape_func);
+                   inst->utf8 ? sql_utf8_escape_func : sql_escape_func, inst);
        if (xlat_query[0] == '\0') {
                radlog_request(L_ERR, 0, request, "Couldn't xlat the query %s",
                       query);
@@ -364,7 +363,7 @@ static int sql_log_write(rlm_sql_log_t *inst, REQUEST *request, const char *line
        char *p, path[1024];
 
        path[0] = '\0';
-       radius_xlat(path, sizeof(path), inst->path, request, NULL);
+       radius_xlat(path, sizeof(path), inst->path, request, NULL, NULL);
        if (path[0] == '\0') {
                return RLM_MODULE_FAIL;
        }
index f8e15f9..9cb6c1d 100644 (file)
@@ -69,7 +69,6 @@ typedef struct rlm_sqlcounter_t {
        char *sqlmod_inst;      /* instance of SQL module to use, usually just 'sql' */
        char *query;            /* SQL query to retrieve current session time */
        char *reset;            /* daily, weekly, monthly, never or user defined */
-       char *allowed_chars;    /* safe characters list for SQL queries */
        time_t reset_time;
        time_t last_reset;
        DICT_ATTR *key_attr;            /* attribute number for key field */
@@ -94,61 +93,9 @@ static const CONF_PARSER module_config[] = {
   { "sqlmod-inst", PW_TYPE_STRING_PTR, offsetof(rlm_sqlcounter_t,sqlmod_inst), NULL, NULL },
   { "query", PW_TYPE_STRING_PTR, offsetof(rlm_sqlcounter_t,query), NULL, NULL },
   { "reset", PW_TYPE_STRING_PTR, offsetof(rlm_sqlcounter_t,reset), NULL,  NULL },
-  { "safe-characters", PW_TYPE_STRING_PTR, offsetof(rlm_sqlcounter_t,allowed_chars), NULL, "@abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-_: /"},
   { NULL, -1, 0, NULL, NULL }
 };
 
-static char *allowed_chars = NULL;
-
-/*
- *     Translate the SQL queries.
- */
-static size_t sql_escape_func(char *out, size_t outlen, const char *in)
-{
-       int len = 0;
-
-       while (in[0]) {
-               /*
-                *      Non-printable characters get replaced with their
-                *      mime-encoded equivalents.
-                */
-               if ((in[0] < 32) ||
-                   strchr(allowed_chars, *in) == NULL) {
-                       /*
-                        *      Only 3 or less bytes available.
-                        */
-                       if (outlen <= 3) {
-                               break;
-                       }
-
-                       snprintf(out, outlen, "=%02X", (unsigned char) in[0]);
-                       in++;
-                       out += 3;
-                       outlen -= 3;
-                       len += 3;
-                       continue;
-               }
-
-               /*
-                *      Only one byte left.
-                */
-               if (outlen <= 1) {
-                       break;
-               }
-
-               /*
-                *      Allowed character.
-                */
-               *out = *in;
-               out++;
-               in++;
-               outlen--;
-               len++;
-       }
-       *out = '\0';
-       return len;
-}
-
 static int find_next_reset(rlm_sqlcounter_t *data, time_t timeval)
 {
        int ret = 0;
@@ -353,11 +300,6 @@ static int sqlcounter_expand(char *out, int outlen, const char *fmt, void *insta
                                strlcpy(q, data->key_name, freespace);
                                q += strlen(q);
                                break;
-                       case 'S': /* SQL module instance */
-                               DEBUG2("WARNING: Please replace '%%S' with '${sqlmod-inst}'");
-                               strlcpy(q, data->sqlmod_inst, freespace);
-                               q += strlen(q);
-                               break;
                        default:
                                *q++ = '%';
                                *q++ = *p;
@@ -382,7 +324,7 @@ static int sqlcounter_cmp(void *instance, REQUEST *req,
        rlm_sqlcounter_t *data = (rlm_sqlcounter_t *) instance;
        int counter;
        char querystr[MAX_QUERY_LEN];
-       char responsestr[MAX_QUERY_LEN];
+       char sqlxlat[MAX_QUERY_LEN];
 
        check_pairs = check_pairs; /* shut the compiler up */
        reply_pairs = reply_pairs;
@@ -390,15 +332,11 @@ static int sqlcounter_cmp(void *instance, REQUEST *req,
        /* first, expand %k, %b and %e in query */
        sqlcounter_expand(querystr, MAX_QUERY_LEN, data->query, instance);
 
-       /* second, xlat any request attribs in query */
-       radius_xlat(responsestr, MAX_QUERY_LEN, querystr, req, sql_escape_func);
-
        /* third, wrap query with sql module call & expand */
-       snprintf(querystr, sizeof(querystr), "%%{%%S:%s}", responsestr);
-       sqlcounter_expand(responsestr, MAX_QUERY_LEN, querystr, instance);
+       snprintf(sqlxlat, sizeof(sqlxlat), "%%{%s:%s}", data->sqlmod_inst, querystr);
 
        /* Finally, xlat resulting SQL query */
-       radius_xlat(querystr, MAX_QUERY_LEN, responsestr, req, sql_escape_func);
+       radius_xlat(querystr, MAX_QUERY_LEN, sqlxlat, req, NULL, NULL);
 
        counter = atoi(querystr);
 
@@ -422,7 +360,6 @@ static int sqlcounter_instantiate(CONF_SECTION *conf, void **instance)
        DICT_ATTR *dattr;
        ATTR_FLAGS flags;
        time_t now;
-       char buffer[MAX_STRING_LEN];
 
        /*
         *      Set up a storage area for instance data
@@ -454,12 +391,6 @@ static int sqlcounter_instantiate(CONF_SECTION *conf, void **instance)
        }
 
        /*
-        *      Safe characters list for sql queries. Everything else is
-        *      replaced with their mime-encoded equivalents.
-        */
-       allowed_chars = data->allowed_chars;
-
-       /*
         *      Discover the attribute number of the key.
         */
        if (data->key_name == NULL) {
@@ -467,12 +398,6 @@ static int sqlcounter_instantiate(CONF_SECTION *conf, void **instance)
                sqlcounter_detach(data);
                return -1;
        }
-       sql_escape_func(buffer, sizeof(buffer), data->key_name);
-       if (strcmp(buffer, data->key_name) != 0) {
-               radlog(L_ERR, "rlm_sqlcounter: The value for option 'key' is too long or contains unsafe characters.");
-               sqlcounter_detach(data);
-               return -1;
-       }
        dattr = dict_attrbyname(data->key_name);
        if (dattr == NULL) {
                radlog(L_ERR, "rlm_sqlcounter: No such attribute %s",
@@ -501,12 +426,6 @@ static int sqlcounter_instantiate(CONF_SECTION *conf, void **instance)
                sqlcounter_detach(data);
                return -1;
        }
-       sql_escape_func(buffer, sizeof(buffer), data->sqlmod_inst);
-       if (strcmp(buffer, data->sqlmod_inst) != 0) {
-               radlog(L_ERR, "rlm_sqlcounter: The value for option 'sqlmod-inst' is too long or contains unsafe characters.");
-               sqlcounter_detach(data);
-               return -1;
-       }
 
        /*
         *  Create a new attribute for the counter.
@@ -606,7 +525,7 @@ static int sqlcounter_authorize(void *instance, REQUEST *request)
        VALUE_PAIR *reply_item;
        char msg[128];
        char querystr[MAX_QUERY_LEN];
-       char responsestr[MAX_QUERY_LEN];
+       char sqlxlat[MAX_QUERY_LEN];
 
        /* quiet the compiler */
        instance = instance;
@@ -652,15 +571,11 @@ static int sqlcounter_authorize(void *instance, REQUEST *request)
        /* first, expand %k, %b and %e in query */
        sqlcounter_expand(querystr, MAX_QUERY_LEN, data->query, instance);
 
-       /* second, xlat any request attribs in query */
-       radius_xlat(responsestr, MAX_QUERY_LEN, querystr, request, sql_escape_func);
-
-       /* third, wrap query with sql module & expand */
-       snprintf(querystr, sizeof(querystr), "%%{%%S:%s}", responsestr);
-       sqlcounter_expand(responsestr, MAX_QUERY_LEN, querystr, instance);
+       /* next, wrap query with sql module & expand */
+       snprintf(sqlxlat, sizeof(sqlxlat), "%%{%s:%s}", data->sqlmod_inst, querystr);
 
        /* Finally, xlat resulting SQL query */
-       radius_xlat(querystr, MAX_QUERY_LEN, responsestr, request, sql_escape_func);
+       radius_xlat(querystr, MAX_QUERY_LEN, sqlxlat, request, NULL, NULL);
 
        if (sscanf(querystr, "%u", &counter) != 1) {
                DEBUG2("rlm_sqlcounter: No integer found in string \"%s\"",
@@ -751,7 +666,6 @@ static int sqlcounter_detach(void *instance)
        char **p;
        rlm_sqlcounter_t *inst = (rlm_sqlcounter_t *)instance;
 
-       allowed_chars = NULL;
        paircompare_unregister(inst->dict_attr->attr, sqlcounter_cmp);
 
        /*
index 5574060..d3772fd 100644 (file)
@@ -307,7 +307,7 @@ static int sqlippool_command(const char * fmt, SQLSOCK * sqlsocket,
         * Do an xlat on the provided string
         */
        if (request) {
-               if (!radius_xlat(query, sizeof(query), expansion, request, data->sql_inst->sql_escape_func)) {
+               if (!radius_xlat(query, sizeof(query), expansion, request, data->sql_inst->sql_escape_func, data->sql_inst)) {
                        radlog(L_ERR, "sqlippool_command: xlat failed on: '%s'", query);
                        return 0;
                }
@@ -346,7 +346,7 @@ static int sqlippool_query1(char * out, int outlen, const char * fmt,
         * Do an xlat on the provided string
         */
        if (request) {
-               if (!radius_xlat(query, sizeof(query), expansion, request, data->sql_inst->sql_escape_func)) {
+               if (!radius_xlat(query, sizeof(query), expansion, request, data->sql_inst->sql_escape_func, data->sql_inst)) {
                        radlog(L_ERR, "sqlippool_command: xlat failed.");
                        out[0] = '\0';
                        return 0;
@@ -547,7 +547,7 @@ static int sqlippool_postauth(void *instance, REQUEST * request)
        if (pairfind(request->reply->vps, PW_FRAMED_IP_ADDRESS, 0) != NULL) {
                /* We already have a Framed-IP-Address */
                radius_xlat(logstr, sizeof(logstr), data->log_exists,
-                           request, NULL);
+                           request, NULL, NULL);
                RDEBUG("Framed-IP-Address already exists");
 
                return do_logging(logstr, RLM_MODULE_NOOP);
@@ -556,7 +556,7 @@ static int sqlippool_postauth(void *instance, REQUEST * request)
        if (pairfind(request->config_items, PW_POOL_NAME, 0) == NULL) {
                RDEBUG("No Pool-Name defined.");
                radius_xlat(logstr, sizeof(logstr), data->log_nopool,
-                           request, NULL);
+                           request, NULL, NULL);
 
                return do_logging(logstr, RLM_MODULE_NOOP);
        }
@@ -626,7 +626,7 @@ static int sqlippool_postauth(void *instance, REQUEST * request)
                                 *      NOTFOUND
                                 */
                                RDEBUG("pool appears to be full");
-                               radius_xlat(logstr, sizeof(logstr), data->log_failed, request, NULL);
+                               radius_xlat(logstr, sizeof(logstr), data->log_failed, request, NULL, NULL);
                                return do_logging(logstr, RLM_MODULE_NOTFOUND);
 
                        }
@@ -646,7 +646,7 @@ static int sqlippool_postauth(void *instance, REQUEST * request)
 
                RDEBUG("IP address could not be allocated.");
                radius_xlat(logstr, sizeof(logstr), data->log_failed,
-                           request, NULL);
+                           request, NULL, NULL);
 
                return do_logging(logstr, RLM_MODULE_NOOP);
        }
@@ -666,7 +666,7 @@ static int sqlippool_postauth(void *instance, REQUEST * request)
                RDEBUG("Invalid IP number [%s] returned from database query.", allocation);
                data->sql_inst->sql_release_socket(data->sql_inst, sqlsocket);
                radius_xlat(logstr, sizeof(logstr), data->log_failed,
-                           request, NULL);
+                           request, NULL, NULL);
 
                return do_logging(logstr, RLM_MODULE_NOOP);
        }
@@ -690,7 +690,7 @@ static int sqlippool_postauth(void *instance, REQUEST * request)
                          (char *) NULL, 0);
 
        data->sql_inst->sql_release_socket(data->sql_inst, sqlsocket);
-       radius_xlat(logstr, sizeof(logstr), data->log_success, request, NULL);
+       radius_xlat(logstr, sizeof(logstr), data->log_success, request, NULL, NULL);
 
        return do_logging(logstr, RLM_MODULE_OK);
 }
@@ -766,7 +766,7 @@ static int sqlippool_accounting_stop(SQLSOCK * sqlsocket,
        sqlippool_command(data->stop_commit, sqlsocket, data, request,
                          (char *) NULL, 0);
 
-       radius_xlat(logstr, sizeof(logstr), data->log_clear, request, NULL);
+       radius_xlat(logstr, sizeof(logstr), data->log_clear, request, NULL, NULL);
 
        return do_logging(logstr, RLM_MODULE_OK);
 }