]> git.sur5r.net Git - openldap/blob - servers/slapd/tools/slapindex.c
DirectoryString syntaxes must have one or more octets to be valid.
[openldap] / servers / slapd / tools / slapindex.c
1 /* $OpenLDAP$ */
2 /*
3  * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
4  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
5  */
6 #include "portable.h"
7
8 #include <stdio.h>
9
10 #include <ac/stdlib.h>
11
12 #include <ac/ctype.h>
13 #include <ac/string.h>
14 #include <ac/socket.h>
15 #include <ac/unistd.h>
16
17 #include "slapcommon.h"
18
19 int
20 main( int argc, char **argv )
21 {
22         char            *type;
23         AttributeDescription *desc;
24         const char *text;
25         ID id;
26         int rc = EXIT_SUCCESS;
27
28         slap_tool_init( "slapindex", SLAPINDEX, argc, argv );
29
30         if( !be->be_entry_open &&
31                 !be->be_entry_close &&
32                 !be->be_entry_first &&
33                 !be->be_entry_next &&
34                 !be->be_entry_get &&
35                 !be->be_index_attr &&
36                 !be->be_index_change )
37         {
38                 fprintf( stderr, "%s: database doesn't support necessary operations.\n",
39                         progname );
40                 exit( EXIT_FAILURE );
41         }
42
43         type = argv[argc - 1];
44
45         rc = slap_str2ad( type, &desc, &text );
46
47         if( rc != LDAP_SUCCESS ) {
48                 fprintf( stderr, "%s: unrecognized attribute type: %s\n",
49                         progname, text );
50                 exit( EXIT_FAILURE );
51         }
52
53         if ( !be->be_index_attr( be, desc ) ) {
54                 fprintf( stderr, "attribute type \"%s\": no indices to generate\n",
55                         type );
56                 exit( EXIT_FAILURE );
57         }
58
59         if( be->be_entry_open( be, 0 ) != 0 ) {
60                 fprintf( stderr, "%s: could not open database.\n",
61                         progname );
62                 exit( EXIT_FAILURE );
63         }
64
65         for ( id = be->be_entry_first( be );
66                 id != NOID;
67                 id = be->be_entry_next( be ) )
68         {
69                 Entry* e = be->be_entry_get( be, id );
70
71                 if ( e == NULL ) {
72                         fprintf( stderr,
73                                 "entry id=%08lx: no data\n", (long) id );
74                         rc = EXIT_FAILURE;
75                         if( continuemode ) continue;
76                         break;
77                 }
78
79                 if( verbose ) {
80                         printf("indexing id=%08lx dn=\"%s\"\n",
81                                 id, e->e_dn );
82                 }
83
84                 {
85                         Attribute *attr;
86                         
87                         for( attr = attrs_find( e->e_attrs, desc );
88                                 attr != NULL;
89                                 attr = attrs_find( attr->a_next, desc ) )
90                         {
91
92                                 if ( be->be_index_change( be,
93                                         desc, attr->a_vals, id, SLAP_INDEX_ADD_OP ) )
94                                 {
95                                         rc = EXIT_FAILURE;
96
97                                         if( !continuemode ) {
98                                                 entry_free( e );
99                                                 goto done;
100                                         }
101                                 }
102                         }
103                 }
104
105                 entry_free( e );
106         }
107
108 done:
109         (void) be->be_entry_close( be );
110
111         slap_tool_destroy();
112
113         return( rc );
114 }