return outlen - freespace;
}
+/** URLencode special characters
+ *
+ * Example: "%{urlunquote:http%3A%47%47example.org%47}" == "http://example.org/"
+ */
+static ssize_t urlunquote_xlat(UNUSED void *instance, UNUSED REQUEST *request,
+ char const *fmt, char *out, size_t outlen)
+{
+ static char const *hextab = "0123456789abcdef";
+
+ char const *p;
+ char *c1, *c2;
+ size_t freespace = outlen;
+
+ if (outlen <= 1) return 0;
+
+ p = fmt;
+ while (*p && (--freespace > 0)) {
+ if (*p != '%') {
+ *out++ = *p++;
+ continue;
+ }
+ /* Is a % char */
+
+ if (!*p || !(c1 = memchr(hextab, tolower(*++p), 16)) ||
+ !*p || !(c2 = memchr(hextab, tolower(*++p), 16))) {
+ REMARKER(fmt, p - fmt, "None hex char in % sequence");
+ return -1;
+ }
+ p++;
+ *out++ = ((c1 - hextab) << 4) + (c2 - hextab);
+ }
+
+ *out = '\0';
+
+ return outlen - freespace;
+}
+
/** Equivalent to the old safe_characters functionality in rlm_sql
*
* @verbatim Example: "%{escape:<img>foo.jpg</img>}" == "=60img=62foo.jpg=60/img=62" @endverbatim
xlat_register("rand", rand_xlat, NULL, inst);
xlat_register("randstr", randstr_xlat, NULL, inst);
xlat_register("urlquote", urlquote_xlat, NULL, inst);
+ xlat_register("urlunquote", urlunquote_xlat, NULL, inst);
xlat_register("escape", escape_xlat, NULL, inst);
xlat_register("tolower", lc_xlat, NULL, inst);
xlat_register("toupper", uc_xlat, NULL, inst);
request:Tmp-String-0 := '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_.~'
request:Tmp-String-1 := '±§!@#$%^&*()+={[}]:;"'|\<,>?/`'
request:Tmp-String-2 := '™œ¥¤'
+ request:Tmp-String-3 := '%C2%B1%C2%A7%21%40%23%24%25%5E%26%2A%28%29%2B%3D%7B%5B%7D%5D%3A%3B%5C%22'
+ request:Tmp-String-4 := '%E2%84%A2%C5%93%C2%A5%C2%A4'
reply:Filter-ID := 'filter'
}
}
}
-if ("%{urlquote:%{request:Tmp-String-1}}" != '%C2%B1%C2%A7%21%40%23%24%25%5E%26%2A%28%29%2B%3D%7B%5B%7D%5D%3A%3B%5C%22') {
+if (<string>"%{urlquote:%{request:Tmp-String-1}}" != &Tmp-String-3) {
update reply {
Filter-Id += 'Fail 2'
}
}
-if ("%{urlquote:%{request:Tmp-String-2}}" != '%E2%84%A2%C5%93%C2%A5%C2%A4') {
+if (<string>"%{urlquote:%{request:Tmp-String-2}}" != &Tmp-String-4) {
update reply {
Filter-Id += 'Fail 3'
}
}
+
+if (<string>"%{urlunquote:%{request:Tmp-String-0}}" != &Tmp-String-0) {
+ update reply {
+ Filter-Id += 'Fail 4'
+ }
+}
+
+if (<string>"%{urlunquote:%{request:Tmp-String-3}}" != &Tmp-String-1) {
+ update reply {
+ Filter-Id += 'Fail 5'
+ }
+}
+
+if (<string>"%{urlunquote:%{request:Tmp-String-4}}" != &Tmp-String-2) {
+ update reply {
+ Filter-Id += 'Fail 6'
+ }
+}