]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Added simple module to "clean" the request of non-UTF-8 data
authorAlan T. DeKok <aland@freeradius.org>
Tue, 4 Oct 2011 14:20:42 +0000 (16:20 +0200)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 4 Oct 2011 14:20:42 +0000 (16:20 +0200)
raddb/modules/utf8 [new file with mode: 0644]
src/modules/rlm_utf8/Makefile [new file with mode: 0644]
src/modules/rlm_utf8/rlm_utf8.c [new file with mode: 0644]

diff --git a/raddb/modules/utf8 b/raddb/modules/utf8
new file mode 100644 (file)
index 0000000..00812fa
--- /dev/null
@@ -0,0 +1,14 @@
+#
+#  Enforces UTF-8 on strings coming in from the NAS.
+#
+#  An attribute of type "string" containing UTF-8 makes
+#  the module return NOOP.
+#
+#  An attribute of type "string" containing non-UTF-8 data
+#  makes the module return FAIL.
+#
+#  This module takes no configuration.
+#
+utf8 {
+
+}
diff --git a/src/modules/rlm_utf8/Makefile b/src/modules/rlm_utf8/Makefile
new file mode 100644 (file)
index 0000000..48b374b
--- /dev/null
@@ -0,0 +1,11 @@
+TARGET         = rlm_utf8
+SRCS           = rlm_utf8.c
+HEADERS                = 
+RLM_CFLAGS     =
+RLM_LIBS       = 
+
+include ../rules.mak
+
+$(STATIC_OBJS): $(HEADERS)
+
+$(DYNAMIC_OBJS): $(HEADERS)
diff --git a/src/modules/rlm_utf8/rlm_utf8.c b/src/modules/rlm_utf8/rlm_utf8.c
new file mode 100644 (file)
index 0000000..7c58c52
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ * rlm_utf8.c
+ *
+ * Version:    $Id$
+ *
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ *
+ * Copyright 2000,2006  The FreeRADIUS server project
+ * Copyright 2000  your name <your address>
+ */
+
+#include <freeradius-devel/ident.h>
+RCSID("$Id$")
+
+#include <freeradius-devel/radiusd.h>
+#include <freeradius-devel/modules.h>
+
+/*
+ *     Reject any non-UTF8 data.
+ */
+static int utf8_clean(void *instance, REQUEST *request)
+{
+       size_t i, len;
+       VALUE_PAIR *vp, *next;
+
+       /* quiet the compiler */
+       instance = instance;
+
+       for (vp = request->packet->vps; vp != NULL; vp = next) {
+               next = vp->next;
+
+               if (vp->type != PW_TYPE_STRING) continue;
+
+               for (i = 0; i < vp->length; i += len) {
+                       len = fr_utf8_char(&vp->vp_octets[i]);
+                       if (len == 0) return RLM_MODULE_FAIL;
+               }
+       }
+
+       return RLM_MODULE_NOOP;
+}
+
+/*
+ *     The module name should be the only globally exported symbol.
+ *     That is, everything else should be 'static'.
+ *
+ *     If the module needs to temporarily modify it's instantiation
+ *     data, the type should be changed to RLM_TYPE_THREAD_UNSAFE.
+ *     The server will then take care of ensuring that the module
+ *     is single-threaded.
+ */
+module_t rlm_utf8 = {
+       RLM_MODULE_INIT,
+       "utf8",
+       RLM_TYPE_THREAD_SAFE,           /* type */
+       NULL,                           /* instantiation */
+       NULL,                           /* detach */
+       {
+               NULL,                   /* authentication */
+               utf8_clean,             /* authorization */
+               utf8_clean,             /* preaccounting */
+               NULL,                   /* accounting */
+               NULL,                   /* checksimul */
+               NULL,                   /* pre-proxy */
+               NULL,                   /* post-proxy */
+               NULL                    /* post-auth */
+#ifdef WITH_COA
+               , utf8_clean,
+               NULL
+#endif
+       },
+};