4
Copyright (C) Andrew Tridgell 2004
6
** NOTE! The following LGPL license applies to the ldb
7
** library. This does NOT imply that all of Samba is released
10
This library is free software; you can redistribute it and/or
11
modify it under the terms of the GNU Lesser General Public
12
License as published by the Free Software Foundation; either
13
version 3 of the License, or (at your option) any later version.
15
This library is distributed in the hope that it will be useful,
16
but WITHOUT ANY WARRANTY; without even the implied warranty of
17
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18
Lesser General Public License for more details.
20
You should have received a copy of the GNU Lesser General Public
21
License along with this library; if not, see <http://www.gnu.org/licenses/>.
27
* Component: ldb utf8 handling
29
* Description: case folding and case comparison for UTF8 strings
31
* Author: Andrew Tridgell
35
#include "ldb/include/includes.h"
36
#include "system/locale.h"
40
this allow the user to pass in a caseless comparison
41
function to handle utf8 caseless comparisons
43
void ldb_set_utf8_fns(struct ldb_context *ldb,
45
char *(*casefold)(void *, void *, const char *))
48
ldb->utf8_fns.context = context;
50
ldb->utf8_fns.casefold = casefold;
54
a simple case folding function
55
NOTE: does not handle UTF8
57
char *ldb_casefold_default(void *context, void *mem_ctx, const char *s)
60
char *ret = talloc_strdup(mem_ctx, s);
65
for (i=0;ret[i];i++) {
66
ret[i] = toupper((unsigned char)ret[i]);
71
void ldb_set_utf8_default(struct ldb_context *ldb)
73
ldb_set_utf8_fns(ldb, NULL, ldb_casefold_default);
76
char *ldb_casefold(struct ldb_context *ldb, void *mem_ctx, const char *s)
78
return ldb->utf8_fns.casefold(ldb->utf8_fns.context, mem_ctx, s);
82
check the attribute name is valid according to rfc2251
83
returns 1 if the name is ok
86
int ldb_valid_attr_name(const char *s)
93
/* handle special ldb_tdb wildcard */
94
if (strcmp(s, "*") == 0) return 1;
96
for (i = 0; s[i]; i++) {
97
if (! isascii(s[i])) {
100
if (i == 0) { /* first char must be an alpha (or our special '@' identifier) */
101
if (! (isalpha(s[i]) || (s[i] == '@'))) {
105
if (! (isalnum(s[i]) || (s[i] == '-'))) {
114
compare two attribute names
115
attribute names are restricted by rfc2251 so using
116
strcasecmp and toupper here is ok.
119
int ldb_attr_cmp(const char *attr1, const char *attr2)
121
return strcasecmp(attr1, attr2);
124
char *ldb_attr_casefold(void *mem_ctx, const char *s)
127
char *ret = talloc_strdup(mem_ctx, s);
132
for (i = 0; ret[i]; i++) {
133
ret[i] = toupper((unsigned char)ret[i]);
139
we accept either 'dn' or 'distinguishedName' for a distinguishedName
141
int ldb_attr_dn(const char *attr)
143
if (ldb_attr_cmp(attr, "dn") == 0 ||
144
ldb_attr_cmp(attr, "distinguishedName") == 0) {