]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/attr.c
Add reference to slapd.conf(5) and recommendation to avoid cleartext passwords.
[openldap] / servers / slapd / back-ldbm / attr.c
1 /* attr.c - backend routines for dealing with attributes */
2
3 #include "portable.h"
4
5 #include <stdio.h>
6
7 #include <ac/socket.h>
8 #include <ac/string.h>
9
10 #include "slap.h"
11 #include "back-ldbm.h"
12
13 static int
14 ainfo_type_cmp(
15     char                *type,
16     struct attrinfo     *a
17 )
18 {
19         return( strcasecmp( type, a->ai_type ) );
20 }
21
22 static int
23 ainfo_cmp(
24     struct attrinfo     *a,
25     struct attrinfo     *b
26 )
27 {
28         return( strcasecmp( a->ai_type, b->ai_type ) );
29 }
30
31 /*
32  * Called when a duplicate "index" line is encountered.
33  *
34  * returns 1 => original from init code, indexmask updated
35  *         2 => original not from init code, warn the user
36  */
37
38 static int
39 ainfo_dup(
40     struct attrinfo     *a,
41     struct attrinfo     *b
42 )
43 {
44         /*
45          * if the duplicate definition is because we initialized the attr,
46          * just add what came from the config file. otherwise, complain.
47          */
48         if ( a->ai_indexmask & INDEX_FROMINIT ) {
49                 a->ai_indexmask |= b->ai_indexmask;
50
51                 return( 1 );
52         }
53
54         return( 2 );
55 }
56
57 void
58 attr_masks(
59     struct ldbminfo     *li,
60     char                *type,
61     int                 *indexmask,
62     int                 *syntaxmask
63 )
64 {
65         struct attrinfo *a;
66
67         *indexmask = 0;
68         *syntaxmask = 0;
69         if ( (a = (struct attrinfo *) avl_find( li->li_attrs, type,
70             ainfo_type_cmp )) == NULL ) {
71                 if ( (a = (struct attrinfo *) avl_find( li->li_attrs, "default",
72                     ainfo_type_cmp )) == NULL ) {
73                         return;
74                 }
75         }
76         *indexmask = a->ai_indexmask;
77         if ( strcasecmp( a->ai_type, "default" ) == 0 ) {
78                 *syntaxmask = attr_syntax( type );
79         } else {
80                 *syntaxmask = a->ai_syntaxmask;
81         }
82 }
83
84 void
85 attr_index_config(
86     struct ldbminfo     *li,
87     char                *fname,
88     int                 lineno,
89     int                 argc,
90     char                **argv,
91     int                 init
92 )
93 {
94         int             i, j;
95         char            **attrs, **indexes;
96         struct attrinfo *a;
97
98         attrs = str2charray( argv[0], "," );
99         if ( argc > 1 ) {
100                 indexes = str2charray( argv[1], "," );
101         }
102         for ( i = 0; attrs[i] != NULL; i++ ) {
103                 a = (struct attrinfo *) ch_malloc( sizeof(struct attrinfo) );
104                 a->ai_type = ch_strdup( attrs[i] );
105                 a->ai_syntaxmask = attr_syntax( a->ai_type );
106                 if ( argc == 1 ) {
107                         a->ai_indexmask = (INDEX_PRESENCE | INDEX_EQUALITY |
108                             INDEX_APPROX | INDEX_SUB);
109                 } else {
110                         a->ai_indexmask = 0;
111                         for ( j = 0; indexes[j] != NULL; j++ ) {
112                                 if ( strncasecmp( indexes[j], "pres", 4 )
113                                     == 0 ) {
114                                         a->ai_indexmask |= INDEX_PRESENCE;
115                                 } else if ( strncasecmp( indexes[j], "eq", 2 )
116                                     == 0 ) {
117                                         a->ai_indexmask |= INDEX_EQUALITY;
118                                 } else if ( strncasecmp( indexes[j], "approx",
119                                     6 ) == 0 ) {
120                                         a->ai_indexmask |= INDEX_APPROX;
121                                 } else if ( strncasecmp( indexes[j], "sub", 3 )
122                                     == 0 ) {
123                                         a->ai_indexmask |= INDEX_SUB;
124                                 } else if ( strncasecmp( indexes[j], "none", 4 )
125                                     == 0 ) {
126                                         if ( a->ai_indexmask != 0 ) {
127                                                 fprintf( stderr,
128 "%s: line %d: index type \"none\" cannot be combined with other types\n",
129                                                     fname, lineno );
130                                         }
131                                         a->ai_indexmask = 0;
132                                 } else {
133                                         fprintf( stderr,
134                         "%s: line %d: unknown index type \"%s\" (ignored)\n",
135                                             fname, lineno, indexes[j] );
136                                         fprintf( stderr,
137         "valid index types are \"pres\", \"eq\", \"approx\", or \"sub\"\n" );
138                                 }
139                         }
140                 }
141                 if ( init ) {
142                         a->ai_indexmask |= INDEX_FROMINIT;
143                 }
144
145                 switch (avl_insert( &li->li_attrs, (caddr_t) a, ainfo_cmp, ainfo_dup )) {
146                 case 1:         /* duplicate - updating init version */
147                         free( a->ai_type );
148                         free( (char *) a );
149                         break;
150
151                 case 2:         /* user duplicate - ignore and warn */
152                         fprintf( stderr,
153     "%s: line %d: duplicate index definition for attr \"%s\" (ignored)\n",
154                             fname, lineno, a->ai_type );
155                         free( a->ai_type );
156                         free( (char *) a );
157                         break;
158
159                 default:;       /* inserted ok */
160                         /* FALL */
161                 }
162         }
163         charray_free( attrs );
164         if ( argc > 1 )
165                 charray_free( indexes );
166 }