]> git.sur5r.net Git - openldap/blob - servers/slapd/suffixalias.c
Support attribute types list and only parameters on cn=config
[openldap] / servers / slapd / suffixalias.c
1 /*
2  * Copyright 1999 The OpenLDAP Foundation, All Rights Reserved.
3  *
4  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file in the top level
5  * directory of this package.
6  */
7 /* Portions
8  * Copyright (c) 1998 Will Ballantyne, ITSD, Government of BC
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms are permitted
12  * provided that this notice is preserved and that due credit is given
13  * to ITSD, Government of BC. The name of ITSD
14  * may not be used to endorse or promote products derived from this
15  * software without specific prior written permission. This software
16  * is provided ``as is'' without express or implied warranty.
17  */
18
19 #include "portable.h"
20
21 #include <stdio.h>
22 #include <string.h>
23 #include <ac/socket.h>          /* Get struct sockaddr for slap.h */
24 #include "slap.h"
25
26 /* 
27  * given a normalized uppercased dn (or root part), return an aliased dn if any of the 
28  * alias suffixes match
29  */
30 char *suffixAlias (char *dn, Operation *op, Backend *be)
31 {
32         int     i, dnLength;
33
34         if(dn == NULL) return NULL;
35
36         dnLength = strlen ( dn );
37         for ( i = 0;
38               be->be_suffixAlias != NULL && be->be_suffixAlias[i] != NULL;
39               i += 2) {
40                 int aliasLength = strlen (be->be_suffixAlias[i]);
41                 int diff = dnLength - aliasLength;
42
43                 if ( diff < 0 ) {
44                         /* alias is longer than dn */
45                         continue;
46                 } else if ( diff > 0 ) {
47                         if ( ! DNSEPARATOR(dn[diff-1]) ) {
48                                 /* boundary is not at a DN separator */
49                                 continue;
50                         }
51                         /* At a DN Separator */
52                         /* XXX or an escaped separator... oh well */
53                 }
54
55                 if (!strcmp(be->be_suffixAlias[i], &dn[diff])) {
56                         char *oldDN = dn;
57                         dn = ch_malloc( diff + strlen(be->be_suffixAlias[i+1]) + 1 );
58                         strncpy( dn, oldDN, diff );
59                         strcpy( &dn[diff], be->be_suffixAlias[i+1] );
60                         Debug( LDAP_DEBUG_ARGS, "SuffixAlias: converted \"%s\" to \"%s\"",
61                                 oldDN, dn, 0);
62                         free (oldDN);
63                         break;
64                 }
65         }
66         return dn;
67 }