~ubuntu-branches/ubuntu/maverick/openldap/maverick-proposed

« back to all changes in this revision

Viewing changes to servers/slapd/syntax.c

  • Committer: Bazaar Package Importer
  • Author(s): Mathias Gug, Steve Langasek, Mathias Gug
  • Date: 2009-02-18 18:44:00 UTC
  • mfrom: (1.1.2 upstream) (0.1.2 lenny)
  • Revision ID: james.westby@ubuntu.com-20090218184400-zw4mjse9eywt5566
Tags: 2.4.14-0ubuntu1
[ Steve Langasek ]
* New upstream version
  - Fixes a bug with the pcache overlay not returning cached entries
    (closes: #497697)
  - Update evolution-ntlm patch to apply to current Makefiles.
  - (tentatively) drop gnutls-ciphers, since this bug was reported to be
    fixed upstream in 2.4.8.  The fix applied in 2.4.8 didn't match the
    patch from the bug report, so this should be watched for regressions.
* Build against db4.7 instead of db4.2 at last!  Closes: #421946.
* Build with --disable-ndb, to avoid a misbuild when libmysqlclient is
  installed in the build environment.
* New patch, no-crlcheck-for-gnutls, to fix a build failure when using
  --with-tls=gnutls.

[ Mathias Gug ]
* Merge from debian unstable, remaining changes:
  - debian/apparmor-profile: add AppArmor profile
  - debian/slapd.postinst: Reload AA profile on configuration
  - updated debian/slapd.README.Debian for note on AppArmor
  - debian/control: Recommends apparmor >= 2.1+1075-0ubuntu6
  - debian/control: Conflicts with apparmor-profiles << 2.1+1075-0ubuntu4
    to make sure that if earlier version of apparmour-profiles gets
    installed it won't overwrite our profile.
  - Modify Maintainer value to match the DebianMaintainerField
    speficication.
  - follow ApparmorProfileMigration and force apparmor compalin mode on 
    some upgrades (LP: #203529)
  - debian/slapd.dirs: add etc/apparmor.d/force-complain
  - debian/slapd.preinst: create symlink for force-complain on pre-feisty
    upgrades, upgrades where apparmor-profiles profile is unchanged (ie
    non-enforcing) and upgrades where apparmor profile does not exist.
  - debian/slapd.postrm: remove symlink in force-complain/ on purge
  - debian/patches/fix-ucred-libc due to changes how newer glibc handle
    the ucred struct now.
  - debian/control:
    - Build-depend on libltdl7-dev rather then libltdl3-dev.
  - debian/patches/autogen.sh:
    - Call libtoolize with the --install option to install config.{guess,sub}
      files.
  - Don't use local statement in config script as it fails if /bin/sh
    points to bash (LP: #286063).
  - Disable the testsuite on hppa. Allows building of packages on this
    architecture again, once this package is in the archive.
    LP: #288908.
  - debian/slapd.postinst, debian/slapd.script-common: set correct ownership
    and permissions on /var/lib/ldap, /etc/ldap/slapd.d (group readable) and
    /var/run/slapd (world readable). (LP: #257667).
  - debian/patches/nssov-build, debian/rules: 
    Build and package the nss overlay.
    debian/schema/misc.ldif: add ldif file for the misc schema, which defines
    rfc822MailMember (required by the nss overlay).
  - debian/{control,rules}: enable PIE hardening
  - Use cn=config as the default configuration backend instead of 
    slapd.conf. Migrate slapd.conf  file to /etc/ldap/slapd.d/ on upgrade
    asking the end user to enter a new password to control the access to the
    cn=config tree.
* debian/patches/corrupt-contextCSN: The contextCSN can get corrupted at
  times. (ITS: #5947)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* syntax.c - routines to manage syntax definitions */
2
 
/* $OpenLDAP: pkg/ldap/servers/slapd/syntax.c,v 1.43.2.3 2008/02/11 23:26:45 kurt Exp $ */
 
2
/* $OpenLDAP: pkg/ldap/servers/slapd/syntax.c,v 1.43.2.6 2009/01/22 00:01:04 kurt Exp $ */
3
3
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4
4
 *
5
 
 * Copyright 1998-2008 The OpenLDAP Foundation.
 
5
 * Copyright 1998-2009 The OpenLDAP Foundation.
6
6
 * All rights reserved.
7
7
 *
8
8
 * Redistribution and use in source and binary forms, with or without
30
30
};
31
31
 
32
32
static Avlnode  *syn_index = NULL;
33
 
static LDAP_SLIST_HEAD(SyntaxList, Syntax) syn_list
34
 
        = LDAP_SLIST_HEAD_INITIALIZER(&syn_list);
 
33
static LDAP_STAILQ_HEAD(SyntaxList, Syntax) syn_list
 
34
        = LDAP_STAILQ_HEAD_INITIALIZER(syn_list);
 
35
 
 
36
/* Last hardcoded attribute registered */
 
37
Syntax *syn_sys_tail;
35
38
 
36
39
static int
37
40
syn_index_cmp(
68
71
{
69
72
        Syntax          *synp;
70
73
 
71
 
        LDAP_SLIST_FOREACH(synp, &syn_list, ssyn_next) {
 
74
        LDAP_STAILQ_FOREACH(synp, &syn_list, ssyn_next) {
72
75
                if ((*len = dscompare( synp->ssyn_syn.syn_desc, syndesc, '{' /*'}'*/ ))) {
73
76
                        return synp;
74
77
                }
111
114
        Syntax  *s;
112
115
 
113
116
        avl_free( syn_index, ldap_memfree );
114
 
        while( !LDAP_SLIST_EMPTY( &syn_list ) ) {
115
 
                s = LDAP_SLIST_FIRST( &syn_list );
116
 
                LDAP_SLIST_REMOVE_HEAD( &syn_list, ssyn_next );
 
117
        while( !LDAP_STAILQ_EMPTY( &syn_list ) ) {
 
118
                s = LDAP_STAILQ_FIRST( &syn_list );
 
119
                LDAP_STAILQ_REMOVE_HEAD( &syn_list, ssyn_next );
117
120
                if ( s->ssyn_sups ) {
118
121
                        SLAP_FREE( s->ssyn_sups );
119
122
                }
123
126
 
124
127
static int
125
128
syn_insert(
126
 
    Syntax              *ssyn,
127
 
    const char          **err
128
 
)
 
129
        Syntax          *ssyn,
 
130
        Syntax          *prev,
 
131
        const char      **err )
129
132
{
130
133
        struct sindexrec        *sir;
131
134
 
132
 
        LDAP_SLIST_NEXT( ssyn, ssyn_next ) = NULL;
133
 
        LDAP_SLIST_INSERT_HEAD( &syn_list, ssyn, ssyn_next );
 
135
        LDAP_STAILQ_NEXT( ssyn, ssyn_next ) = NULL;
134
136
 
135
137
        if ( ssyn->ssyn_oid ) {
136
138
                sir = (struct sindexrec *)
150
152
                /* FIX: temporal consistency check */
151
153
                syn_find(sir->sir_name);
152
154
        }
 
155
 
 
156
        if ( ssyn->ssyn_flags & SLAP_AT_HARDCODE ) {
 
157
                prev = syn_sys_tail;
 
158
                syn_sys_tail = ssyn;
 
159
        }
 
160
 
 
161
        if ( prev ) {
 
162
                LDAP_STAILQ_INSERT_AFTER( &syn_list, prev, ssyn, ssyn_next );
 
163
        } else {
 
164
                LDAP_STAILQ_INSERT_TAIL( &syn_list, ssyn, ssyn_next );
 
165
        }
153
166
        return 0;
154
167
}
155
168
 
156
169
int
157
170
syn_add(
158
 
    LDAPSyntax          *syn,
159
 
    slap_syntax_defs_rec *def,
160
 
    const char          **err
161
 
)
 
171
        LDAPSyntax              *syn,
 
172
        int                     user,
 
173
        slap_syntax_defs_rec    *def,
 
174
        Syntax                  **ssynp,
 
175
        Syntax                  *prev,
 
176
        const char              **err )
162
177
{
163
178
        Syntax          *ssyn;
164
179
        int             code = 0;
165
180
 
 
181
        if ( ssynp != NULL ) {
 
182
                *ssynp = NULL;
 
183
        }
 
184
 
166
185
        ssyn = (Syntax *) SLAP_CALLOC( 1, sizeof(Syntax) );
167
186
        if ( ssyn == NULL ) {
168
187
                Debug( LDAP_DEBUG_ANY, "SLAP_CALLOC Error\n", 0, 0, 0 );
171
190
 
172
191
        AC_MEMCPY( &ssyn->ssyn_syn, syn, sizeof(LDAPSyntax) );
173
192
 
174
 
        LDAP_SLIST_NEXT(ssyn,ssyn_next) = NULL;
 
193
        LDAP_STAILQ_NEXT(ssyn,ssyn_next) = NULL;
175
194
 
176
195
        /*
177
196
         * note: ssyn_bvoid uses the same memory of ssyn_syn.syn_oid;
190
209
        ssyn->ssyn_str2ber = def->sd_str2ber;
191
210
#endif
192
211
 
 
212
        if ( def->sd_validate == NULL && def->sd_pretty == NULL && syn->syn_extensions != NULL ) {
 
213
                LDAPSchemaExtensionItem **lsei;
 
214
                Syntax *subst = NULL;
 
215
 
 
216
                for ( lsei = syn->syn_extensions; *lsei != NULL; lsei++) {
 
217
                        if ( strcmp( (*lsei)->lsei_name, "X-SUBST" ) != 0 ) {
 
218
                                continue;
 
219
                        }
 
220
 
 
221
                        assert( (*lsei)->lsei_values != NULL );
 
222
                        if ( (*lsei)->lsei_values[0] == '\0'
 
223
                                || (*lsei)->lsei_values[1] != '\0' )
 
224
                        {
 
225
                                Debug( LDAP_DEBUG_ANY, "syn_add(%s): exactly one substitute syntax must be present\n",
 
226
                                        ssyn->ssyn_syn.syn_oid, 0, 0 );
 
227
                                return SLAP_SCHERR_SYN_SUBST_NOT_SPECIFIED;
 
228
                        }
 
229
 
 
230
                        subst = syn_find( (*lsei)->lsei_values[0] );
 
231
                        if ( subst == NULL ) {
 
232
                                Debug( LDAP_DEBUG_ANY, "syn_add(%s): substitute syntax %s not found\n",
 
233
                                        ssyn->ssyn_syn.syn_oid, (*lsei)->lsei_values[0], 0 );
 
234
                                return SLAP_SCHERR_SYN_SUBST_NOT_FOUND;
 
235
                        }
 
236
                        break;
 
237
                }
 
238
 
 
239
                if ( subst != NULL ) {
 
240
                        ssyn->ssyn_flags = subst->ssyn_flags;
 
241
                        ssyn->ssyn_validate = subst->ssyn_validate;
 
242
                        ssyn->ssyn_pretty = subst->ssyn_pretty;
 
243
 
 
244
                        ssyn->ssyn_sups = NULL;
 
245
 
 
246
#ifdef SLAPD_BINARY_CONVERSION
 
247
                        ssyn->ssyn_ber2str = subst->ssyn_ber2str;
 
248
                        ssyn->ssyn_str2ber = subst->ssyn_str2ber;
 
249
#endif
 
250
                }
 
251
        }
 
252
 
193
253
        if ( def->sd_sups != NULL ) {
194
254
                int     cnt;
195
255
 
213
273
                }
214
274
        }
215
275
 
 
276
        if ( !user )
 
277
                ssyn->ssyn_flags |= SLAP_SYNTAX_HARDCODE;
 
278
 
216
279
        if ( code == 0 ) {
217
 
                code = syn_insert( ssyn, err );
218
 
 
 
280
                code = syn_insert( ssyn, prev, err );
219
281
        }
220
282
 
221
283
        if ( code != 0 && ssyn != NULL ) {
223
285
                        SLAP_FREE( ssyn->ssyn_sups );
224
286
                }
225
287
                SLAP_FREE( ssyn );
 
288
                ssyn = NULL;
 
289
        }
 
290
 
 
291
        if (ssynp ) {
 
292
                *ssynp = ssyn;
226
293
        }
227
294
 
228
295
        return code;
244
311
                return( -1 );
245
312
        }
246
313
 
247
 
        code = syn_add( syn, def, &err );
 
314
        code = syn_add( syn, 0, def, NULL, NULL, &err );
248
315
 
249
316
        if ( code ) {
250
317
                Debug( LDAP_DEBUG_ANY, "Error in register_syntax: %s %s in %s\n",
267
334
        struct berval   val;
268
335
        struct berval   nval;
269
336
 
270
 
        LDAP_SLIST_FOREACH(syn, &syn_list, ssyn_next ) {
 
337
        LDAP_STAILQ_FOREACH(syn, &syn_list, ssyn_next ) {
271
338
                if ( ! syn->ssyn_validate ) {
272
339
                        /* skip syntaxes without validators */
273
340
                        continue;
297
364
        return 0;
298
365
}
299
366
 
 
367
void
 
368
syn_delete( Syntax *syn )
 
369
{
 
370
        LDAP_STAILQ_REMOVE(&syn_list, syn, Syntax, ssyn_next);
 
371
}
 
372
 
 
373
int
 
374
syn_start( Syntax **syn )
 
375
{
 
376
        assert( syn != NULL );
 
377
 
 
378
        *syn = LDAP_STAILQ_FIRST(&syn_list);
 
379
 
 
380
        return (*syn != NULL);
 
381
}
 
382
 
 
383
int
 
384
syn_next( Syntax **syn )
 
385
{
 
386
        assert( syn != NULL );
 
387
 
 
388
#if 0   /* pedantic check: don't use this */
 
389
        {
 
390
                Syntax *tmp = NULL;
 
391
 
 
392
                LDAP_STAILQ_FOREACH(tmp,&syn_list,ssyn_next) {
 
393
                        if ( tmp == *syn ) {
 
394
                                break;
 
395
                        }
 
396
                }
 
397
 
 
398
                assert( tmp != NULL );
 
399
        }
 
400
#endif
 
401
 
 
402
        *syn = LDAP_STAILQ_NEXT(*syn,ssyn_next);
 
403
 
 
404
        return (*syn != NULL);
 
405
}
 
406
 
 
407
void
 
408
syn_unparse( BerVarray *res, Syntax *start, Syntax *end, int sys )
 
409
{
 
410
        Syntax *syn;
 
411
        int i, num;
 
412
        struct berval bv, *bva = NULL, idx;
 
413
        char ibuf[32];
 
414
 
 
415
        if ( !start )
 
416
                start = LDAP_STAILQ_FIRST( &syn_list );
 
417
 
 
418
        /* count the result size */
 
419
        i = 0;
 
420
        for ( syn = start; syn; syn = LDAP_STAILQ_NEXT( syn, ssyn_next ) ) {
 
421
                if ( sys && !( syn->ssyn_flags & SLAP_SYNTAX_HARDCODE ) ) break;
 
422
                i++;
 
423
                if ( syn == end ) break;
 
424
        }
 
425
        if ( !i ) return;
 
426
 
 
427
        num = i;
 
428
        bva = ch_malloc( (num+1) * sizeof(struct berval) );
 
429
        BER_BVZERO( bva );
 
430
        idx.bv_val = ibuf;
 
431
        if ( sys ) {
 
432
                idx.bv_len = 0;
 
433
                ibuf[0] = '\0';
 
434
        }
 
435
        i = 0;
 
436
        for ( syn = start; syn; syn = LDAP_STAILQ_NEXT( syn, ssyn_next ) ) {
 
437
                if ( sys && !( syn->ssyn_flags & SLAP_SYNTAX_HARDCODE ) ) break;
 
438
                if ( ldap_syntax2bv( &syn->ssyn_syn, &bv ) == NULL ) {
 
439
                        ber_bvarray_free( bva );
 
440
                }
 
441
                if ( !sys ) {
 
442
                        idx.bv_len = sprintf(idx.bv_val, "{%d}", i);
 
443
                }
 
444
                bva[i].bv_len = idx.bv_len + bv.bv_len;
 
445
                bva[i].bv_val = ch_malloc( bva[i].bv_len + 1 );
 
446
                strcpy( bva[i].bv_val, ibuf );
 
447
                strcpy( bva[i].bv_val + idx.bv_len, bv.bv_val );
 
448
                i++;
 
449
                bva[i].bv_val = NULL;
 
450
                ldap_memfree( bv.bv_val );
 
451
                if ( syn == end ) break;
 
452
        }
 
453
        *res = bva;
 
454
}
 
455