Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / external / bsd / openldap / dist / servers / slapd / slapindex.c
blob9d0a367a07615c0b49e8f891bf633159f43eb159
1 /* $OpenLDAP: pkg/ldap/servers/slapd/slapindex.c,v 1.3.2.3 2008/02/11 23:26:44 kurt Exp $ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1998-2008 The OpenLDAP Foundation.
5 * Portions Copyright 1998-2003 Kurt D. Zeilenga.
6 * All rights reserved.
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.
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>.
16 /* ACKNOWLEDGEMENTS:
17 * This work was initially developed by Kurt Zeilenga for inclusion
18 * in OpenLDAP Software.
21 #include "portable.h"
23 #include <stdio.h>
25 #include <ac/stdlib.h>
27 #include <ac/ctype.h>
28 #include <ac/string.h>
29 #include <ac/socket.h>
30 #include <ac/unistd.h>
32 #include "slapcommon.h"
34 int
35 slapindex( int argc, char **argv )
37 ID id;
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 ||
47 !be->be_entry_next ||
48 !be->be_entry_reindex )
50 fprintf( stderr, "%s: database doesn't support necessary operations.\n",
51 progname );
52 exit( EXIT_FAILURE );
55 argc -= optind;
56 if ( argc > 0 ) {
57 const char *text;
58 int i;
60 argv = &argv[optind];
61 adv = (AttributeDescription **)argv;
63 for (i = 0; i < argc; i++ ) {
64 ad = NULL;
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 ));
69 exit( EXIT_FAILURE );
71 adv[i] = ad;
75 if( be->be_entry_open( be, 0 ) != 0 ) {
76 fprintf( stderr, "%s: could not open database.\n",
77 progname );
78 exit( EXIT_FAILURE );
81 for ( id = be->be_entry_first( be );
82 id != NOID;
83 id = be->be_entry_next( be ) )
85 int rtn;
87 if( verbose ) {
88 printf("indexing id=%08lx\n", (long) id );
91 rtn = be->be_entry_reindex( be, id, adv );
93 if( rtn != LDAP_SUCCESS ) {
94 rc = EXIT_FAILURE;
95 if( continuemode ) continue;
96 break;
100 (void) be->be_entry_close( be );
102 slap_tool_destroy();
103 return( rc );