All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
rlm_utf8.c
Go to the documentation of this file.
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 as published by
4  * the Free Software Foundation; either version 2 of the License, or (at
5  * your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
15  */
16 
17 /**
18  * $Id: d2031c650c6520f0b480c7f0ba55e54f838e90e4 $
19  * @file rlm_utf8.c
20  * @brief Enforce UTF8 encoding in strings.
21  *
22  * @copyright 2000,2006 The FreeRADIUS server project
23  */
24 RCSID("$Id: d2031c650c6520f0b480c7f0ba55e54f838e90e4 $")
25 
26 #include <freeradius-devel/radiusd.h>
27 #include <freeradius-devel/modules.h>
28 
29 /*
30  * Reject any non-UTF8 data.
31  */
32 static rlm_rcode_t CC_HINT(nonnull) mod_utf8_clean(UNUSED void *instance, REQUEST *request)
33 {
34  size_t i, len;
35  VALUE_PAIR *vp;
36  vp_cursor_t cursor;
37 
38  for (vp = fr_cursor_init(&cursor, &request->packet->vps);
39  vp;
40  vp = fr_cursor_next(&cursor)) {
41  if (vp->da->type != PW_TYPE_STRING) continue;
42 
43  for (i = 0; i < vp->vp_length; i += len) {
44  len = fr_utf8_char(&vp->vp_octets[i], -1);
45  if (len == 0) return RLM_MODULE_FAIL;
46  }
47  }
48 
49  return RLM_MODULE_NOOP;
50 }
51 
52 /*
53  * The module name should be the only globally exported symbol.
54  * That is, everything else should be 'static'.
55  *
56  * If the module needs to temporarily modify it's instantiation
57  * data, the type should be changed to RLM_TYPE_THREAD_UNSAFE.
58  * The server will then take care of ensuring that the module
59  * is single-threaded.
60  */
61 extern module_t rlm_utf8;
62 module_t rlm_utf8 = {
64  .name = "utf8",
65  .type = RLM_TYPE_THREAD_SAFE,
66  .methods = {
67  [MOD_AUTHORIZE] = mod_utf8_clean,
68  [MOD_PREACCT] = mod_utf8_clean,
69 #ifdef WITH_COA
70  [MOD_RECV_COA] = mod_utf8_clean
71 #endif
72  },
73 };
Metadata exported by the module.
Definition: modules.h:134
#define RLM_TYPE_THREAD_SAFE
Module is threadsafe.
Definition: modules.h:75
#define UNUSED
Definition: libradius.h:134
#define RLM_MODULE_INIT
Definition: modules.h:86
static rlm_rcode_t CC_HINT(nonnull)
Definition: rlm_utf8.c:32
VALUE_PAIR * fr_cursor_init(vp_cursor_t *cursor, VALUE_PAIR *const *node)
Setup a cursor to iterate over attribute pairs.
Definition: cursor.c:60
Abstraction to allow iterating over different configurations of VALUE_PAIRs.
Definition: pair.h:144
module_t rlm_utf8
Definition: rlm_utf8.c:62
Stores an attribute, a value and various bits of other data.
Definition: pair.h:112
enum rlm_rcodes rlm_rcode_t
Return codes indicating the result of the module call.
Module succeeded without doing anything.
Definition: radiusd.h:96
uint64_t magic
Used to validate module struct.
Definition: modules.h:135
Module failed, don't reply.
Definition: radiusd.h:90
VALUE_PAIR * fr_cursor_next(vp_cursor_t *cursor)
Advanced the cursor to the next VALUE_PAIR.
Definition: cursor.c:263
2 methods index for preacct section.
Definition: modules.h:43
8 methods index for recvcoa section.
Definition: modules.h:50
fr_dict_attr_t const * da
Dictionary attribute defines the attribute.
Definition: pair.h:113
int fr_utf8_char(uint8_t const *str, ssize_t inlen)
Checks for utf-8, taken from http://www.w3.org/International/questions/qa-forms-utf-8.
Definition: print.c:34
String of printable characters.
Definition: radius.h:33
PW_TYPE type
Value type.
Definition: dict.h:80
1 methods index for authorize section.
Definition: modules.h:42
#define RCSID(id)
Definition: build.h:135