mirror of
https://github.com/samba-team/samba.git
synced 2025-11-16 20:23:50 +03:00
- moved the knowledge of attribute types out of ldb_tdb and into the generic ldb code. This allows the ldb_match() message match logic to be generic, so it can be used by other backend - added the generic ability to load attribute handlers, for canonicalisation, compare, ldif read and ldif write. In the future this will be used by the schema module to allow us to correctly obey the attributetype schema elements - added attribute handlers for some of the core ldap attribute types, Integer, DirectoryString, DN, ObjectClass etc - added automatic registration of attribute handlers for well-known attribute names 'cn', 'dc', 'dn', 'ou' and 'objectClass' - converted the objectSid special handlers for Samba to the new system - added more correct handling of indexing in tdb backend based on the attribute canonicalisation function - added generic support for subclasses, moving it out of the tdb backend. This will be used in future by the schema module - fixed several bugs in the dn_explode code. It still needs more work, but doesn't corrupt ldb dbs any more.
92 lines
2.1 KiB
C
92 lines
2.1 KiB
C
/*
|
|
ldb database library
|
|
|
|
Copyright (C) Andrew Tridgell 2004
|
|
|
|
** NOTE! The following LGPL license applies to the ldb
|
|
** library. This does NOT imply that all of Samba is released
|
|
** under the LGPL
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU Lesser General Public
|
|
License as published by the Free Software Foundation; either
|
|
version 2 of the License, or (at your option) any later version.
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Lesser General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
License along with this library; if not, write to the Free Software
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
*/
|
|
|
|
/*
|
|
* Name: ldb
|
|
*
|
|
* Component: ldb utf8 handling
|
|
*
|
|
* Description: case folding and case comparison for UTF8 strings
|
|
*
|
|
* Author: Andrew Tridgell
|
|
*/
|
|
|
|
#include "includes.h"
|
|
#include "ldb/include/ldb.h"
|
|
#include "ldb/include/ldb_private.h"
|
|
#include <ctype.h>
|
|
|
|
/*
|
|
TODO:
|
|
a simple case folding function - will be replaced by a UTF8 aware function later
|
|
*/
|
|
char *ldb_casefold(void *mem_ctx, const char *s)
|
|
{
|
|
int i;
|
|
char *ret = talloc_strdup(mem_ctx, s);
|
|
if (!s) {
|
|
errno = ENOMEM;
|
|
return NULL;
|
|
}
|
|
for (i=0;ret[i];i++) {
|
|
ret[i] = toupper(ret[i]);
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
/*
|
|
a caseless compare, optimised for 7 bit
|
|
TODO: doesn't yet handle UTF8
|
|
*/
|
|
int ldb_caseless_cmp(const char *s1, const char *s2)
|
|
{
|
|
int i;
|
|
for (i=0;s1[i] != 0;i++) {
|
|
int c1 = toupper(s1[i]), c2 = toupper(s2[i]);
|
|
if (c1 != c2) {
|
|
return c1 - c2;
|
|
}
|
|
}
|
|
return s2[i];
|
|
}
|
|
|
|
/*
|
|
compare two basedn fields
|
|
return 0 for match
|
|
*/
|
|
int ldb_dn_cmp(const char *dn1, const char *dn2)
|
|
{
|
|
return ldb_caseless_cmp(dn1, dn2);
|
|
}
|
|
|
|
/*
|
|
compare two attributes
|
|
return 0 for match
|
|
*/
|
|
int ldb_attr_cmp(const char *attr1, const char *attr2)
|
|
{
|
|
return ldb_caseless_cmp(attr1, attr2);
|
|
}
|
|
|