The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
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: 69406dc9abe314ec133c174395203e5b7575dfa8 $
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: 69406dc9abe314ec133c174395203e5b7575dfa8 $")
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  */
32 static 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  */
57 extern module_rlm_t rlm_utf8;
59  .common = {
60  .magic = MODULE_MAGIC_INIT,
61  .name = "utf8",
63  },
64  .method_names = (module_method_name_t[]){
65  { .name1 = CF_IDENT_ANY, .name2 = CF_IDENT_ANY, .method = mod_utf8_clean },
67  }
68 };
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:444
#define UNUSED
Definition: build.h:313
#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:65
@ FR_TYPE_STRING
String of printable characters.
Definition: merged_model.c:83
Temporary structure to hold arguments for module calls.
Definition: module_ctx.h:41
Specifies a module method identifier.
Definition: module_method.c:36
module_t common
Common fields presented by all modules.
Definition: module_rlm.h:37
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
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
@ MODULE_TYPE_THREAD_SAFE
Module is threadsafe.
Definition: module.h:49
#define MODULE_NAME_TERMINATOR
Definition: module.h:135
RETURN_MODULE_FAIL
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:260
int nonnull(2, 5))