]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/schema_init.c
ITS#2864 don't use sl_mark/release.
[openldap] / servers / slapd / schema_init.c
index ee09d0d515d9962110b5933d7e36b7121d4f7a10..8369a43204a121943b7c366f538d7e1168b5e2fe 100644 (file)
@@ -1,8 +1,17 @@
 /* schema_init.c - init builtin schema */
 /* $OpenLDAP$ */
-/*
- * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
- * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
+ *
+ * Copyright 1998-2003 The OpenLDAP Foundation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted only as authorized by the OpenLDAP
+ * Public License.
+ *
+ * A copy of this license is available in the file LICENSE in the
+ * top-level directory of the distribution or, alternatively, at
+ * <http://www.OpenLDAP.org/license.html>.
  */
 
 #include "portable.h"
@@ -1714,7 +1723,7 @@ IA5StringNormalize(
        void *ctx )
 {
        char *p, *q;
-       int casefold = SLAP_MR_ASSOCIATED(mr, slap_schema.si_mr_caseExactIA5Match);
+       int casefold = !SLAP_MR_ASSOCIATED(mr, slap_schema.si_mr_caseExactIA5Match);
 
        assert( val->bv_len );
 
@@ -1770,6 +1779,86 @@ IA5StringNormalize(
        return LDAP_SUCCESS;
 }
 
+static int
+UUIDValidate(
+       Syntax *syntax,
+       struct berval *in )
+{
+       int i;
+       if( in->bv_len != 36 ) {
+               assert(0);
+               return LDAP_INVALID_SYNTAX;
+       }
+
+       for( i=0; i<36; i++ ) {
+               switch(i) {
+                       case 8:
+                       case 13:
+                       case 18:
+                       case 23:
+                               if( in->bv_val[i] != '-' ) {
+                                       return LDAP_INVALID_SYNTAX;
+                               }
+                               break;
+                       default:
+                               if( !ASCII_HEX( in->bv_val[i]) ) {
+                                       return LDAP_INVALID_SYNTAX;
+                               }
+               }
+       }
+       
+       return LDAP_SUCCESS;
+}
+
+static int
+UUIDNormalize(
+       slap_mask_t usage,
+       Syntax *syntax,
+       MatchingRule *mr,
+       struct berval *val,
+       struct berval *normalized,
+       void *ctx )
+{
+       unsigned char octet;
+       int i;
+       int j;
+       normalized->bv_len = 16;
+       normalized->bv_val = sl_malloc( normalized->bv_len+1, ctx );
+
+       for( i=0, j=0; i<36; i++ ) {
+               unsigned char nibble;
+               if( val->bv_val[i] == '-' ) {
+                       continue;
+
+               } else if( ASCII_DIGIT( val->bv_val[i] ) ) {
+                       nibble = val->bv_val[i] - '0';
+
+               } else if( ASCII_HEXLOWER( val->bv_val[i] ) ) {
+                       nibble = val->bv_val[i] - ('a'-10);
+
+               } else if( ASCII_HEXUPPER( val->bv_val[i] ) ) {
+                       nibble = val->bv_val[i] - ('A'-10);
+
+               } else {
+                       sl_free( normalized->bv_val, ctx );
+                       return LDAP_INVALID_SYNTAX;
+               }
+
+               if( j & 1 ) {
+                       octet |= nibble;
+                       normalized->bv_val[j>>1] = octet;
+               } else {
+                       octet = nibble << 4;
+               }
+               j++;
+       }
+
+       normalized->bv_val[normalized->bv_len] = 0;
+       return LDAP_SUCCESS;
+}
+
+
+
 static int
 numericStringValidate(
        Syntax *syntax,
@@ -2761,6 +2850,9 @@ static slap_syntax_defs_rec syntax_defs[] = {
                SLAP_SYNTAX_HIDE, NULL, NULL},
 #endif
 
+       {"( 1.3.6.1.4.1.4203.666.2.6 DESC 'UUID' )",
+               SLAP_SYNTAX_HIDE, UUIDValidate, NULL},
+
        /* OpenLDAP Void Syntax */
        {"( 1.3.6.1.4.1.4203.1.1.1 DESC 'OpenLDAP void' )" ,
                SLAP_SYNTAX_HIDE, inValidate, NULL},
@@ -3109,6 +3201,20 @@ static slap_mrule_defs_rec mrule_defs[] = {
                NULL, NULL,
                "integerMatch" },
 
+       {"( 1.3.6.1.4.1.4203.666.4.6 NAME 'UUIDMatch' "
+               "SYNTAX 1.3.6.1.4.1.4203.666.2.6 )",
+               SLAP_MR_HIDE | SLAP_MR_EQUALITY, NULL,
+               NULL, UUIDNormalize, octetStringMatch,
+               octetStringIndexer, octetStringFilter,
+               NULL},
+
+       {"( 1.3.6.1.4.1.4203.666.4.7 NAME 'UUIDOrderingMatch' "
+               "SYNTAX 1.3.6.1.4.1.4203.666.2.6 )",
+               SLAP_MR_HIDE | SLAP_MR_ORDERING, NULL,
+               NULL, UUIDNormalize, octetStringOrderingMatch,
+               octetStringIndexer, octetStringFilter,
+               "UUIDMatch"},
+
        {NULL, SLAP_MR_NONE, NULL,
                NULL, NULL, NULL, NULL, NULL,
                NULL }