]> git.sur5r.net Git - openldap/blob - servers/slapd/tools/slapindex.c
New slapindex framework (no meat)
[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_reindex )
35         {
36                 fprintf( stderr, "%s: database doesn't support necessary operations.\n",
37                         progname );
38                 exit( EXIT_FAILURE );
39         }
40
41         type = argv[argc - 1];
42
43         rc = slap_str2ad( type, &desc, &text );
44
45         if( rc != LDAP_SUCCESS ) {
46                 fprintf( stderr, "%s: unrecognized attribute type: %s\n",
47                         progname, text );
48                 exit( EXIT_FAILURE );
49         }
50
51         if( be->be_entry_open( be, 0 ) != 0 ) {
52                 fprintf( stderr, "%s: could not open database.\n",
53                         progname );
54                 exit( EXIT_FAILURE );
55         }
56
57         for ( id = be->be_entry_first( be );
58                 id != NOID;
59                 id = be->be_entry_next( be ) )
60         {
61                 int rtn;
62
63                 if( verbose ) {
64                         printf("indexing id=%08lx\n", (long) id );
65                 }
66
67                 rtn =  be->be_entry_reindex( be, id );
68
69                 if( rtn != LDAP_SUCCESS ) {
70                         rc = EXIT_FAILURE;
71                         if( continuemode ) continue;
72                         break;
73                 }
74         }
75
76 done:
77         (void) be->be_entry_close( be );
78
79         slap_tool_destroy();
80
81         return( rc );
82 }