]> git.sur5r.net Git - openldap/blob - servers/slapd/tools/slapindex.c
Happy new year
[openldap] / servers / slapd / tools / slapindex.c
1 /* $OpenLDAP$ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3  *
4  * Copyright 1998-2004 The OpenLDAP Foundation.
5  * Portions Copyright 1998-2003 Kurt D. Zeilenga.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted only as authorized by the OpenLDAP
10  * Public License.
11  *
12  * A copy of this license is available in file LICENSE in the
13  * top-level directory of the distribution or, alternatively, at
14  * <http://www.OpenLDAP.org/license.html>.
15  */
16 /* ACKNOWLEDGEMENTS:
17  * This work was initially developed by Kurt Zeilenga for inclusion
18  * in OpenLDAP Software.
19  */
20
21 #include "portable.h"
22
23 #include <stdio.h>
24
25 #include <ac/stdlib.h>
26
27 #include <ac/ctype.h>
28 #include <ac/string.h>
29 #include <ac/socket.h>
30 #include <ac/unistd.h>
31
32 #include "slapcommon.h"
33
34 int
35 main( int argc, char **argv )
36 {
37         ID id;
38         int rc = EXIT_SUCCESS;
39
40         slap_tool_init( "slapindex", SLAPINDEX, argc, argv );
41
42         if( !be->be_entry_open ||
43                 !be->be_entry_close ||
44                 !be->be_entry_first ||
45                 !be->be_entry_next  ||
46                 !be->be_entry_reindex )
47         {
48                 fprintf( stderr, "%s: database doesn't support necessary operations.\n",
49                         progname );
50                 exit( EXIT_FAILURE );
51         }
52
53         if( be->be_entry_open( be, 0 ) != 0 ) {
54                 fprintf( stderr, "%s: could not open database.\n",
55                         progname );
56                 exit( EXIT_FAILURE );
57         }
58
59         for ( id = be->be_entry_first( be );
60                 id != NOID;
61                 id = be->be_entry_next( be ) )
62         {
63                 int rtn;
64
65                 if( verbose ) {
66                         printf("indexing id=%08lx\n", (long) id );
67                 }
68
69                 rtn =  be->be_entry_reindex( be, id );
70
71                 if( rtn != LDAP_SUCCESS ) {
72                         rc = EXIT_FAILURE;
73                         if( continuemode ) continue;
74                         break;
75                 }
76         }
77
78         (void) be->be_entry_close( be );
79
80         slap_tool_destroy();
81         return( rc );
82 }