2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1998-2014 The OpenLDAP Foundation.
5 * Portions Copyright 1998-2003 Kurt D. Zeilenga.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
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>.
17 * This work was initially developed by Kurt Zeilenga for inclusion
18 * in OpenLDAP Software.
25 #include <ac/stdlib.h>
28 #include <ac/string.h>
29 #include <ac/socket.h>
30 #include <ac/unistd.h>
32 #include "slapcommon.h"
35 slapindex( int argc, char **argv )
38 int rc = EXIT_SUCCESS;
39 const char *progname = "slapindex";
40 AttributeDescription *ad, **adv = NULL;
42 slap_tool_init( progname, SLAPINDEX, argc, argv );
44 if( !be->be_entry_open ||
45 !be->be_entry_close ||
46 !( be->be_entry_first || be->be_entry_first_x ) ||
48 !be->be_entry_reindex )
50 fprintf( stderr, "%s: database doesn't support necessary operations.\n",
61 adv = (AttributeDescription **)argv;
63 for (i = 0; i < argc; i++ ) {
65 rc = slap_str2ad( argv[i], &ad, &text );
66 if ( rc != LDAP_SUCCESS ) {
67 fprintf( stderr, "slap_str2ad(%s) failed %d (%s)\n",
68 argv[i], rc, ldap_err2string( rc ));
75 if( be->be_entry_open( be, 0 ) != 0 ) {
76 fprintf( stderr, "%s: could not open database.\n",
81 if ( be->be_entry_first ) {
82 id = be->be_entry_first( be );
85 assert( be->be_entry_first_x != NULL );
86 id = be->be_entry_first_x( be, NULL, LDAP_SCOPE_DEFAULT, NULL );
89 for ( ; id != NOID; id = be->be_entry_next( be ) ) {
93 printf("indexing id=%08lx\n", (long) id );
96 rtn = be->be_entry_reindex( be, id, adv );
98 if( rtn != LDAP_SUCCESS ) {
100 if( continuemode ) continue;
105 (void) be->be_entry_close( be );
107 if ( slap_tool_destroy())