Turn on super pedantic warnings in CLANG
[freeradius.git] / src / modules / rlm_utf8 / rlm_utf8.c
1 /*
2  *   This program is is free software; you can redistribute it and/or modify
3  *   it under the terms of the GNU General Public License, version 2 if the
4  *   License as published by the Free Software Foundation.
5  *
6  *   This program is distributed in the hope that it will be useful,
7  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
8  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9  *   GNU General Public License for more details.
10  *
11  *   You should have received a copy of the GNU General Public License
12  *   along with this program; if not, write to the Free Software
13  *   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
14  */
15
16 /**
17  * $Id$
18  * @file rlm_utf8.c
19  * @brief Enforce UTF8 encoding in strings.
20  *
21  * @copyright 2000,2006  The FreeRADIUS server project
22  */
23 RCSID("$Id$")
24
25 #include <freeradius-devel/radiusd.h>
26 #include <freeradius-devel/modules.h>
27
28 /*
29  *      Reject any non-UTF8 data.
30  */
31 static rlm_rcode_t CC_HINT(nonnull) mod_utf8_clean(UNUSED void *instance, REQUEST *request)
32 {
33         size_t i, len;
34         VALUE_PAIR *vp;
35         vp_cursor_t cursor;
36
37         for (vp = fr_cursor_init(&cursor, &request->packet->vps);
38              vp;
39              vp = fr_cursor_next(&cursor)) {
40                 if (vp->da->type != PW_TYPE_STRING) continue;
41
42                 for (i = 0; i < vp->vp_length; i += len) {
43                         len = fr_utf8_char(&vp->vp_octets[i]);
44                         if (len == 0) return RLM_MODULE_FAIL;
45                 }
46         }
47
48         return RLM_MODULE_NOOP;
49 }
50
51 /*
52  *      The module name should be the only globally exported symbol.
53  *      That is, everything else should be 'static'.
54  *
55  *      If the module needs to temporarily modify it's instantiation
56  *      data, the type should be changed to RLM_TYPE_THREAD_UNSAFE.
57  *      The server will then take care of ensuring that the module
58  *      is single-threaded.
59  */
60 extern module_t rlm_utf8;
61 module_t rlm_utf8 = {
62         RLM_MODULE_INIT,
63         "utf8",
64         RLM_TYPE_THREAD_SAFE,           /* type */
65         0,
66         NULL,                           /* CONF_PARSER */
67         NULL,                           /* instantiation */
68         NULL,                           /* detach */
69         {
70                 NULL,                   /* authentication */
71                 mod_utf8_clean,         /* authorization */
72                 mod_utf8_clean,         /* preaccounting */
73                 NULL,                   /* accounting */
74                 NULL,                   /* checksimul */
75                 NULL,                   /* pre-proxy */
76                 NULL,                   /* post-proxy */
77                 NULL                    /* post-auth */
78 #ifdef WITH_COA
79                 , mod_utf8_clean,
80                 NULL
81 #endif
82         },
83 };