]> git.sur5r.net Git - openldap/blob - servers/slapd/slapindex.c
import fix to ITS#3474 from HEAD
[openldap] / servers / slapd / 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 slapindex( int argc, char **argv )
36 {
37         ID id;
38         int rc = EXIT_SUCCESS;
39         const char *progname = "slapindex";
40
41         slap_tool_init( progname, SLAPINDEX, argc, argv );
42
43         if( !be->be_entry_open ||
44                 !be->be_entry_close ||
45                 !be->be_entry_first ||
46                 !be->be_entry_next  ||
47                 !be->be_entry_reindex )
48         {
49                 fprintf( stderr, "%s: database doesn't support necessary operations.\n",
50                         progname );
51                 exit( EXIT_FAILURE );
52         }
53
54         if( be->be_entry_open( be, 0 ) != 0 ) {
55                 fprintf( stderr, "%s: could not open database.\n",
56                         progname );
57                 exit( EXIT_FAILURE );
58         }
59
60         for ( id = be->be_entry_first( be );
61                 id != NOID;
62                 id = be->be_entry_next( be ) )
63         {
64                 int rtn;
65
66                 if( verbose ) {
67                         printf("indexing id=%08lx\n", (long) id );
68                 }
69
70                 rtn =  be->be_entry_reindex( be, id );
71
72                 if( rtn != LDAP_SUCCESS ) {
73                         rc = EXIT_FAILURE;
74                         if( continuemode ) continue;
75                         break;
76                 }
77         }
78
79         (void) be->be_entry_close( be );
80
81         slap_tool_destroy();
82         return( rc );
83 }