2 * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
3 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
12 #include <ac/string.h>
13 #include <ac/socket.h>
14 #include <ac/unistd.h>
16 #include "ldif2common.h"
17 #include "../back-ldbm/back-ldbm.h"
20 main( int argc, char **argv )
24 char line[BUFSIZ], idbuf[BUFSIZ];
32 struct berval *vals[2];
35 ldbm_ignore_nextid_file = 1;
37 slap_ldif_init( argc, argv, LDIF2ID2ENTRY, "ldbm", SLAP_TOOL_MODE );
41 be = &backends[dbnum];
43 /* disable write sync'ing */
44 li = (struct ldbminfo *) be->be_private;
45 li->li_dbcachewsync = 0;
47 if ( (db = ldbm_cache_open( be, "id2entry", LDBM_SUFFIX, LDBM_NEWDB ))
49 perror( "id2entry file" );
63 ldbm_datum_init( key );
64 ldbm_datum_init( data );
66 if ( fgets( line, sizeof(line), stdin ) != NULL ) {
70 if ( buf == NULL || *buf == '\0' ) {
71 if (!isdigit((unsigned char) line[0])) {
72 sprintf( idbuf, "%ld\n", id + 1 );
73 idlen = strlen( idbuf );
82 while ( lcur + len + idlen + 1 > lmax ) {
84 buf = (char *) ch_realloc( buf, lmax );
88 strcpy( buf + lcur, idbuf );
91 strcpy( buf + lcur, line );
96 if ( line[0] == '\n' || stop && buf && *buf ) {
103 key.dptr = (char *) &id;
104 key.dsize = sizeof(ID);
107 if (buf[len - 1] == '\n')
109 data.dsize = len + 1;
110 if ( ldbm_store( db->dbc_db, key, data,
111 LDBM_INSERT ) != 0 ) {
112 fputs("id2entry ldbm_store failed\n",
114 exit( EXIT_FAILURE );
124 ldbm_cache_close( be, db );
127 slap_shutdown(dbnum);
130 sprintf( line, "%s/NEXTID",
131 ((struct ldbminfo *) be->be_private)->li_directory );
132 if ( (fp = fopen( line, "w" )) == NULL ) {
134 fprintf( stderr, "Could not write next id %ld\n", maxid );
136 fprintf( fp, "%ld\n", maxid );
142 return( EXIT_SUCCESS );