The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
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: 2b4c50b4f7faff8ce2658265ff1265913cd00f71 $
19 * @file rlm_utf8.c
20 * @brief Enforce UTF8 encoding in strings.
21 *
22 * @copyright 2000,2006 The FreeRADIUS server project
23 */
24RCSID("$Id: 2b4c50b4f7faff8ce2658265ff1265913cd00f71 $")
25
26#include <freeradius-devel/server/base.h>
27#include <freeradius-devel/server/module_rlm.h>
28
29/*
30 * Reject any non-UTF8 data.
31 */
32static unlang_action_t CC_HINT(nonnull) mod_utf8_clean(rlm_rcode_t *p_result, UNUSED module_ctx_t const *mctx, request_t *request)
33{
34 size_t i, len;
35
36 fr_pair_list_foreach(&request->request_pairs, vp) {
37 if (vp->vp_type != FR_TYPE_STRING) continue;
38
39 for (i = 0; i < vp->vp_length; i += len) {
40 len = fr_utf8_char(&vp->vp_octets[i], -1);
41 if (len == 0) RETURN_MODULE_FAIL;
42 }
43 }
44
46}
47
48/*
49 * The module name should be the only globally exported symbol.
50 * That is, everything else should be 'static'.
51 *
52 * If the module needs to temporarily modify it's instantiation
53 * data, the type should be changed to MODULE_TYPE_THREAD_UNSAFE.
54 * The server will then take care of ensuring that the module
55 * is single-threaded.
56 */
59 .common = {
60 .magic = MODULE_MAGIC_INIT,
61 .name = "utf8"
62 },
63 .method_group = {
64 .bindings = (module_method_binding_t[]){
65 { .section = SECTION_NAME(CF_IDENT_ANY, CF_IDENT_ANY), .method = mod_utf8_clean },
67 }
68 }
69};
unlang_action_t
Returned by unlang_op_t calls, determine the next action of the interpreter.
Definition action.h:35
#define RCSID(id)
Definition build.h:483
#define UNUSED
Definition build.h:315
#define CF_IDENT_ANY
Definition cf_util.h:78
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
Definition dl_module.h:63
@ FR_TYPE_STRING
String of printable characters.
Temporary structure to hold arguments for module calls.
Definition module_ctx.h:41
module_t common
Common fields presented by all modules.
Definition module_rlm.h:39
size_t 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:39
#define RETURN_MODULE_NOOP
Definition rcode.h:62
#define RETURN_MODULE_FAIL
Definition rcode.h:56
rlm_rcode_t
Return codes indicating the result of the module call.
Definition rcode.h:40
module_rlm_t rlm_utf8
Definition rlm_utf8.c:58
static unlang_action_t mod_utf8_clean(rlm_rcode_t *p_result, UNUSED module_ctx_t const *mctx, request_t *request)
Definition rlm_utf8.c:32
#define SECTION_NAME(_name1, _name2)
Define a section name consisting of a verb and a noun.
Definition section.h:40
#define MODULE_BINDING_TERMINATOR
Terminate a module binding list.
Definition module.h:151
Named methods exported by a module.
Definition module.h:173
fr_pair_t * vp
#define fr_pair_list_foreach(_list_head, _iter)
Iterate over the contents of a fr_pair_list_t.
Definition pair.h:261
int nonnull(2, 5))