1998-10-25 09:41:42 +08:00
|
|
|
#include "portable.h"
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
#include <stdio.h>
|
1998-10-25 09:41:42 +08:00
|
|
|
#include <limits.h>
|
|
|
|
|
1999-06-03 08:37:44 +08:00
|
|
|
#include <ac/stdlib.h>
|
1998-10-25 09:41:42 +08:00
|
|
|
#include <ac/socket.h>
|
|
|
|
#include <ac/string.h>
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-16 06:40:11 +08:00
|
|
|
#include <ac/ctype.h>
|
1998-10-25 09:41:42 +08:00
|
|
|
#include <ac/time.h>
|
|
|
|
#include <ac/unistd.h>
|
|
|
|
#include <ac/wait.h>
|
|
|
|
|
1999-03-02 06:37:05 +08:00
|
|
|
#ifdef HAVE_SYS_RESOURCE_H
|
1998-08-09 08:43:13 +08:00
|
|
|
#include <sys/resource.h>
|
1999-03-02 06:37:05 +08:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_PARAM_H
|
1998-08-09 08:43:13 +08:00
|
|
|
#include <sys/param.h>
|
1999-03-02 06:37:05 +08:00
|
|
|
#endif
|
1998-08-09 08:43:13 +08:00
|
|
|
#include <sys/stat.h>
|
1998-10-25 09:41:42 +08:00
|
|
|
|
|
|
|
#ifdef HAVE_FCNTL_H
|
|
|
|
#include <fcntl.h>
|
|
|
|
#endif
|
|
|
|
|
1999-03-02 06:37:05 +08:00
|
|
|
#ifdef HAVE_IO_H
|
|
|
|
#include <io.h>
|
|
|
|
#endif
|
|
|
|
|
1999-06-17 11:54:25 +08:00
|
|
|
#include "ldap_defaults.h"
|
1998-08-09 08:43:13 +08:00
|
|
|
#include "../slap.h"
|
|
|
|
#include "../back-ldbm/back-ldbm.h"
|
|
|
|
|
1999-07-20 03:40:33 +08:00
|
|
|
static DBCache *openchoice(char c, int mode, int verbose, char **fname);
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-16 06:40:11 +08:00
|
|
|
static void print_entry(FILE *fp, char c, Datum *key, char *klabel, Datum *data, char *dlabel);
|
1999-07-20 03:40:33 +08:00
|
|
|
static void free_and_close(DBCache *dbc, Datum key, Datum data);
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-16 06:40:11 +08:00
|
|
|
static void edit_entry(char c, Datum *data);
|
|
|
|
static void get_keydata(FILE *fp, char c, Datum *key, Datum *data);
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1999-07-20 03:40:33 +08:00
|
|
|
static DBCache *dbc;
|
1999-01-12 02:36:40 +08:00
|
|
|
static LDBM dbp;
|
|
|
|
static Backend *be = NULL;
|
1998-08-09 08:43:13 +08:00
|
|
|
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-16 06:40:11 +08:00
|
|
|
int
|
|
|
|
main( int argc, char **argv )
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
|
|
|
char buf[256];
|
|
|
|
Datum savekey, key, data, last;
|
|
|
|
char *fname;
|
|
|
|
ID id;
|
1999-01-31 15:55:53 +08:00
|
|
|
ID_BLOCK *idl;
|
1998-08-09 08:43:13 +08:00
|
|
|
Backend *tbe;
|
|
|
|
int i;
|
1999-01-12 02:36:40 +08:00
|
|
|
char *tailorfile;
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1998-10-25 09:41:42 +08:00
|
|
|
#ifdef HAVE_BERKELEY_DB2
|
1998-09-03 08:50:13 +08:00
|
|
|
DBC *cursorp;
|
1999-01-07 11:28:08 +08:00
|
|
|
#endif
|
1998-12-18 20:28:47 +08:00
|
|
|
|
1998-12-30 01:28:45 +08:00
|
|
|
ldbm_datum_init( savekey );
|
|
|
|
ldbm_datum_init( key );
|
|
|
|
ldbm_datum_init( data );
|
|
|
|
ldbm_datum_init( last );
|
1998-09-03 08:50:13 +08:00
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
tailorfile = SLAPD_DEFAULT_CONFIGFILE;
|
|
|
|
while ( (i = getopt( argc, argv, "d:f:" )) != EOF ) {
|
|
|
|
switch ( i ) {
|
|
|
|
case 'd': /* turn on debugging */
|
|
|
|
ldap_debug = atoi( optarg );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'f': /* specify a tailor file */
|
|
|
|
tailorfile = strdup( optarg );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
fprintf( stderr,
|
|
|
|
"usage: %s [-d level] [-f slapdconfigfile]\n",
|
|
|
|
argv[0] );
|
1999-08-04 02:14:24 +08:00
|
|
|
exit( EXIT_FAILURE );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* initialize stuff and figure out which backend we're dealing with
|
|
|
|
*/
|
|
|
|
|
1999-02-05 17:03:47 +08:00
|
|
|
slap_init(SLAP_TOOL_MODE, "ldbmtest");
|
|
|
|
read_config( tailorfile );
|
|
|
|
slap_startup(-1);
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
while ( 1 ) {
|
|
|
|
printf( "dbtest: " );
|
|
|
|
|
|
|
|
if ( fgets( buf, sizeof(buf), stdin ) == NULL )
|
|
|
|
break;
|
|
|
|
|
|
|
|
switch ( buf[0] ) {
|
|
|
|
case 'c': /* create an index */
|
|
|
|
fname = NULL;
|
|
|
|
if ( (dbc = openchoice( buf[1], LDBM_READER, 0,
|
|
|
|
&fname )) != NULL ) {
|
|
|
|
printf( "Already exists\n" );
|
|
|
|
ldbm_close( dbc->dbc_db );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ( (dbc = openchoice( buf[1], LDBM_WRCREAT, 1,
|
|
|
|
&fname )) != NULL ) {
|
|
|
|
ldbm_close( dbc->dbc_db );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'l': /* lookup somethig in an index */
|
|
|
|
if ( (dbc = openchoice( buf[1], LDBM_READER, 1, NULL ))
|
|
|
|
== NULL ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
get_keydata( stdin, buf[1], &key, NULL );
|
|
|
|
data = ldbm_fetch( dbc->dbc_db, key );
|
|
|
|
print_entry( stdout, buf[1], &key, "key: ", &data,
|
|
|
|
"data:\n" );
|
|
|
|
|
|
|
|
free_and_close( dbc, key, data );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'L': /* get all blocks for a key from an index */
|
|
|
|
if ( (dbc = openchoice( buf[1], LDBM_READER, 1, NULL ))
|
|
|
|
== NULL ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
get_keydata( stdin, buf[1], &key, NULL );
|
|
|
|
if ( (idl = idl_fetch( be, dbc, key )) != NULL ) {
|
|
|
|
data.dptr = (char *) idl;
|
1999-01-31 15:55:53 +08:00
|
|
|
data.dsize = (ID_BLOCK_NMAX(idl) + 1) * sizeof(ID);
|
1998-08-09 08:43:13 +08:00
|
|
|
print_entry( stdout, buf[1], &key, "key: ",
|
|
|
|
&data, "data:\n" );
|
|
|
|
}
|
|
|
|
free_and_close( dbc, key, data );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 't': /* traverse */
|
|
|
|
case 'T': /* traverse - keys only */
|
|
|
|
if ( (dbc = openchoice( buf[1], LDBM_READER, 1, NULL ))
|
|
|
|
== NULL ) {
|
|
|
|
perror( "openchoice" );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
savekey.dptr = NULL;
|
1998-10-25 09:41:42 +08:00
|
|
|
#ifdef HAVE_BERKELEY_DB2
|
1998-09-03 08:50:13 +08:00
|
|
|
for ( key = ldbm_firstkey( dbc->dbc_db, &cursorp );
|
|
|
|
key.dptr != NULL;
|
|
|
|
key = ldbm_nextkey( dbc->dbc_db, key, cursorp ) )
|
|
|
|
#else
|
1998-08-09 08:43:13 +08:00
|
|
|
for ( key = ldbm_firstkey( dbc->dbc_db );
|
|
|
|
key.dptr != NULL;
|
1998-09-03 08:50:13 +08:00
|
|
|
key = ldbm_nextkey( dbc->dbc_db, key ) )
|
|
|
|
#endif
|
|
|
|
{
|
1998-08-09 08:43:13 +08:00
|
|
|
if ( savekey.dptr != NULL )
|
|
|
|
ldbm_datum_free( dbc->dbc_db, savekey );
|
|
|
|
savekey = key;
|
|
|
|
|
|
|
|
data = ldbm_fetch( dbc->dbc_db, key );
|
|
|
|
|
|
|
|
if ( buf[0] == 't' ) {
|
|
|
|
print_entry( stdout, buf[1], &key,
|
|
|
|
"key: ", &data, "data:\n" );
|
|
|
|
} else {
|
|
|
|
print_entry( stdout, buf[1], &key,
|
|
|
|
"key: ", NULL, NULL );
|
|
|
|
}
|
|
|
|
|
1998-12-30 01:28:45 +08:00
|
|
|
if ( data.dptr != NULL ) {
|
|
|
|
ldbm_datum_free( dbc->dbc_db, data );
|
|
|
|
}
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
if ( savekey.dptr != NULL )
|
|
|
|
ldbm_datum_free( dbc->dbc_db, savekey );
|
|
|
|
|
|
|
|
ldbm_close( dbc->dbc_db );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'x': /* delete an entry */
|
|
|
|
if ( (dbc = openchoice( buf[1], LDBM_WRITER, 1, NULL ))
|
|
|
|
== NULL ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
get_keydata( stdin, buf[1], &key, NULL );
|
|
|
|
|
|
|
|
if ( ldbm_delete( dbc->dbc_db, key ) != 0 ) {
|
|
|
|
if ( ldbm_errno( dbc->dbc_db ) == 0 ) {
|
|
|
|
perror( "ldbm_delete" );
|
|
|
|
} else {
|
|
|
|
fprintf( stderr, "db_errno %d",
|
|
|
|
ldbm_errno( dbc->dbc_db ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
data.dptr = NULL;
|
|
|
|
free_and_close( dbc, key, data );
|
|
|
|
break;
|
|
|
|
|
1999-07-16 10:45:46 +08:00
|
|
|
#ifndef HAVE_WINSOCK
|
1998-08-09 08:43:13 +08:00
|
|
|
case 'e': /* edit an entry */
|
|
|
|
if ( (dbc = openchoice( buf[1], LDBM_WRITER, 1, NULL ))
|
|
|
|
== NULL ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
get_keydata( stdin, buf[1], &key, NULL );
|
|
|
|
|
|
|
|
data = ldbm_fetch( dbc->dbc_db, key );
|
|
|
|
if ( data.dptr == NULL ) {
|
|
|
|
if ( ldbm_errno( dbc->dbc_db ) == 0 ) {
|
|
|
|
perror( "ldbm_fetch" );
|
|
|
|
} else {
|
|
|
|
fprintf( stderr, "db_errno %d\n",
|
|
|
|
ldbm_errno( dbc->dbc_db ) );
|
|
|
|
}
|
|
|
|
free_and_close( dbc, key, data );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
edit_entry( buf[1], &data );
|
|
|
|
|
|
|
|
if ( data.dptr == NULL ) {
|
|
|
|
if ( ldbm_delete( dbc->dbc_db, key ) != 0 ) {
|
|
|
|
perror( "ldbm_delete" );
|
|
|
|
}
|
|
|
|
} else if ( ldbm_store( dbc->dbc_db, key, data,
|
|
|
|
LDBM_REPLACE ) != 0 ) {
|
|
|
|
if ( ldbm_errno( dbc->dbc_db ) == 0 ) {
|
|
|
|
perror( "ldbm_store" );
|
|
|
|
} else {
|
|
|
|
fprintf( stderr, "db_errno %d\n",
|
|
|
|
ldbm_errno( dbc->dbc_db ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free_and_close( dbc, key, data );
|
|
|
|
break;
|
1999-07-16 10:45:46 +08:00
|
|
|
#endif
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
case 'a': /* add an entry */
|
|
|
|
if ( (dbc = openchoice( buf[1], LDBM_WRITER, 1, NULL ))
|
|
|
|
== NULL ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
get_keydata( stdin, buf[1], &key, &data );
|
|
|
|
|
|
|
|
if ( ldbm_store( dbc->dbc_db, key, data, LDBM_INSERT )
|
|
|
|
!= 0 ) {
|
|
|
|
if ( ldbm_errno( dbc->dbc_db ) == 0 ) {
|
|
|
|
perror( "ldbm_store" );
|
|
|
|
} else {
|
|
|
|
fprintf( stderr, "db_errno %d\n",
|
|
|
|
ldbm_errno( dbc->dbc_db ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free_and_close( dbc, key, data );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'i': /* insert an id into an index entry */
|
|
|
|
if ( (dbc = openchoice( buf[1], LDBM_WRITER, 1, NULL ))
|
|
|
|
== NULL ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
get_keydata( stdin, buf[1], &key, &data );
|
|
|
|
|
1999-01-31 15:55:53 +08:00
|
|
|
idl = (ID_BLOCK *) data.dptr;
|
1998-08-09 08:43:13 +08:00
|
|
|
for ( id = idl_firstid( idl ); id != NOID;
|
|
|
|
id = idl_nextid( idl, id ) ) {
|
|
|
|
if ( idl_insert_key( be, dbc, key, id )
|
|
|
|
!= 0 ) {
|
|
|
|
fprintf( stderr,
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-16 06:40:11 +08:00
|
|
|
"idl_insert_key (%s) %ld failed\n",
|
1998-08-09 08:43:13 +08:00
|
|
|
key.dptr, id );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free_and_close( dbc, key, data );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'b': /* select a backend by suffix */
|
|
|
|
printf( "suffix: " );
|
|
|
|
fflush( stdout );
|
|
|
|
if ( fgets( buf, sizeof(buf), stdin ) == NULL ) {
|
1999-08-04 02:14:24 +08:00
|
|
|
exit( EXIT_SUCCESS );
|
1998-08-09 08:43:13 +08:00
|
|
|
} else {
|
|
|
|
buf[strlen( buf ) - 1] = '\0';
|
|
|
|
}
|
1999-01-20 02:25:21 +08:00
|
|
|
(void) dn_normalize_case( buf );
|
1998-08-09 08:43:13 +08:00
|
|
|
if ( (tbe = select_backend( buf )) == NULL ) {
|
|
|
|
fprintf( stderr, "unknown suffix \"%s\"\n",
|
|
|
|
buf );
|
|
|
|
} else {
|
|
|
|
be = tbe;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'B': /* print current suffix */
|
|
|
|
if ( be == NULL ) {
|
|
|
|
printf( "no current backend\n" );
|
|
|
|
} else {
|
|
|
|
printf( "current backend has suffix \"%s\"\n",
|
|
|
|
be->be_suffix[0] );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'C': /* produce concordance of an index */
|
|
|
|
if ( (dbc = openchoice( 'i', LDBM_READER, 1, NULL ))
|
|
|
|
== NULL ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
last.dptr = NULL;
|
1998-09-03 08:50:13 +08:00
|
|
|
|
1998-10-25 09:41:42 +08:00
|
|
|
#ifdef HAVE_BERKELEY_DB2
|
1998-09-03 08:50:13 +08:00
|
|
|
for ( key = ldbm_firstkey( dbp, &cursorp );
|
|
|
|
key.dptr != NULL;
|
|
|
|
key = ldbm_nextkey( dbp, last, cursorp ) )
|
|
|
|
#else
|
1998-08-09 08:43:13 +08:00
|
|
|
for ( key = ldbm_firstkey( dbp ); key.dptr != NULL;
|
1998-09-03 08:50:13 +08:00
|
|
|
key = ldbm_nextkey( dbp, last ) )
|
|
|
|
#endif
|
|
|
|
{
|
1998-08-09 08:43:13 +08:00
|
|
|
if ( last.dptr != NULL ) {
|
|
|
|
ldbm_datum_free( dbp, last );
|
|
|
|
}
|
|
|
|
last = key;
|
|
|
|
printf( "key(%d): (%s)\n", key.dsize,
|
|
|
|
key.dptr );
|
|
|
|
}
|
|
|
|
|
|
|
|
free_and_close( dbc, key, last );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
printf( "commands: l<c> => lookup index\n" );
|
|
|
|
printf( " L<c> => lookup index (all)\n" );
|
|
|
|
printf( " t<c> => traverse index\n" );
|
|
|
|
printf( " T<c> => traverse index keys\n" );
|
|
|
|
printf( " x<c> => delete from index\n" );
|
|
|
|
printf( " e<c> => edit index entry\n" );
|
|
|
|
printf( " a<c> => add index entry\n" );
|
|
|
|
printf( " c<c> => create index\n" );
|
|
|
|
printf( " i<c> => insert ids into index\n" );
|
|
|
|
printf( " b => change default backend\n" );
|
|
|
|
printf( " B => print default backend\n" );
|
|
|
|
printf( "where <c> is a char selecting the index:\n" );
|
|
|
|
printf( " c => id2children\n" );
|
|
|
|
printf( " d => dn2id\n" );
|
|
|
|
printf( " e => id2entry\n" );
|
|
|
|
printf( " f => arbitrary file\n" );
|
|
|
|
printf( " i => attribute index\n" );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-02-05 17:03:47 +08:00
|
|
|
slap_shutdown(-1);
|
|
|
|
slap_destroy();
|
|
|
|
|
1999-08-04 14:05:05 +08:00
|
|
|
return( EXIT_SUCCESS );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1999-07-20 03:40:33 +08:00
|
|
|
free_and_close( DBCache *dbc, Datum key, Datum data )
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
|
|
|
ldbm_cache_really_close( be, dbc );
|
|
|
|
if ( key.dptr != NULL )
|
|
|
|
ldbm_datum_free( dbp, key );
|
|
|
|
if ( data.dptr != NULL )
|
|
|
|
ldbm_datum_free( dbp, data );
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-16 06:40:11 +08:00
|
|
|
dnid_cmp( const void *a, const void *b )
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-16 06:40:11 +08:00
|
|
|
return( *(const long int *)a - *(const long int *)b );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-16 06:40:11 +08:00
|
|
|
myrealloc( char *p, int size )
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
|
|
|
if ( p == NULL )
|
|
|
|
return( (char *) malloc( size ) );
|
|
|
|
else
|
|
|
|
return( (char *) realloc( p, size ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-16 06:40:11 +08:00
|
|
|
get_idlist( FILE *fp, Datum *data )
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
|
|
|
char buf[20];
|
1999-03-02 06:37:05 +08:00
|
|
|
int i, fd, tty;
|
1999-01-31 15:55:53 +08:00
|
|
|
ID_BLOCK *p;
|
1999-03-02 06:37:05 +08:00
|
|
|
unsigned int psize, pmax;
|
|
|
|
unsigned int nmax, nids;
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
fd = fileno( fp );
|
|
|
|
tty = isatty( fd );
|
|
|
|
|
|
|
|
p = NULL;
|
|
|
|
psize = 2 * sizeof(ID);
|
|
|
|
pmax = 0;
|
|
|
|
nmax = 0;
|
|
|
|
nids = 0;
|
|
|
|
i = 0;
|
|
|
|
while ( 1 ) {
|
|
|
|
if ( tty )
|
|
|
|
printf( "id? " );
|
|
|
|
if ( fgets( buf, sizeof(buf), fp ) == NULL || buf[0] == '\n' )
|
|
|
|
break;
|
|
|
|
if ( strncmp( buf, "nmax=", 5 ) == 0 ) {
|
|
|
|
nmax = atol( buf + 5 );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( psize + sizeof(ID) > pmax ) {
|
|
|
|
pmax += BUFSIZ;
|
1999-01-31 15:55:53 +08:00
|
|
|
p = (ID_BLOCK *) myrealloc( (char *) p, pmax );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( strncmp( buf, "nids=0", 6 ) == 0 ) {
|
|
|
|
nids = NOID;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
1999-01-31 15:55:53 +08:00
|
|
|
ID_BLOCK_ID(p,i++) = atol( buf );
|
1998-08-09 08:43:13 +08:00
|
|
|
psize += sizeof(ID);
|
|
|
|
}
|
|
|
|
if ( nmax == 0 ) {
|
|
|
|
if ( tty ) {
|
|
|
|
nmax = i;
|
|
|
|
printf( "%d IDs entered. Max number of ids? [%d] ", i,
|
|
|
|
i );
|
|
|
|
if ( fgets( buf, sizeof(buf), fp ) != NULL &&
|
1999-02-23 01:57:22 +08:00
|
|
|
isdigit( (unsigned char) buf[0] ) ) {
|
1998-08-09 08:43:13 +08:00
|
|
|
nmax = atol( buf );
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
nmax = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( i > 0 ) {
|
1999-01-31 15:55:53 +08:00
|
|
|
ID_BLOCK_NMAX(p) = nmax;
|
1998-08-09 08:43:13 +08:00
|
|
|
if ( nids != 0 ) {
|
1999-01-31 15:55:53 +08:00
|
|
|
ID_BLOCK_NIDS(p) = 0;
|
|
|
|
ID_BLOCK_ID(p,i) = NOID;
|
1998-08-09 08:43:13 +08:00
|
|
|
} else {
|
1999-01-31 15:55:53 +08:00
|
|
|
ID_BLOCK_NIDS(p) = i;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
1999-01-31 15:55:53 +08:00
|
|
|
qsort( (void *) &ID_BLOCK_ID(p, 0), i, sizeof(ID), dnid_cmp );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
data->dptr = (char *) p;
|
1999-01-31 15:55:53 +08:00
|
|
|
data->dsize = (nmax + ID_BLOCK_IDS_OFFSET) * sizeof(ID);
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-16 06:40:11 +08:00
|
|
|
get_entry( FILE *fp, Datum *data )
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
|
|
|
char buf[BUFSIZ];
|
|
|
|
char *p;
|
1999-03-02 06:37:05 +08:00
|
|
|
unsigned int pmax, psize, len;
|
1998-08-09 08:43:13 +08:00
|
|
|
int fd;
|
|
|
|
|
|
|
|
fd = fileno( fp );
|
|
|
|
if ( isatty( fd ) )
|
|
|
|
printf( "Enter entry, <cr><cr> to end:\n" );
|
|
|
|
|
|
|
|
p = NULL;
|
|
|
|
pmax = psize = 0;
|
|
|
|
while ( fgets( buf, sizeof(buf), fp ) != NULL ) {
|
|
|
|
len = strlen( buf );
|
|
|
|
if ( psize + strlen( buf ) > pmax ) {
|
|
|
|
pmax += BUFSIZ;
|
|
|
|
p = myrealloc( p, pmax );
|
|
|
|
}
|
|
|
|
if ( psize == 0 )
|
|
|
|
strcpy( p, buf );
|
|
|
|
else
|
|
|
|
strcat( p, buf );
|
|
|
|
psize += len;
|
|
|
|
|
|
|
|
if ( buf[0] == '\n' )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
data->dptr = p;
|
|
|
|
data->dsize = psize + 1;
|
|
|
|
}
|
|
|
|
|
1999-07-16 10:45:46 +08:00
|
|
|
#ifndef HAVE_WINSOCK
|
1998-08-09 08:43:13 +08:00
|
|
|
static void
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-16 06:40:11 +08:00
|
|
|
edit_entry( char c, Datum *data )
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
|
|
|
int fd, pid;
|
|
|
|
char tmpname[20];
|
|
|
|
FILE *fp;
|
1998-10-25 09:41:42 +08:00
|
|
|
#ifndef HAVE_WAITPID
|
1998-08-09 08:43:13 +08:00
|
|
|
WAITSTATUSTYPE status;
|
1998-10-25 09:41:42 +08:00
|
|
|
#endif
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
strcpy( tmpname, "/tmp/dbtestXXXXXX" );
|
1998-10-25 09:41:42 +08:00
|
|
|
#ifndef HAVE_MKSTEMP
|
1998-08-09 08:43:13 +08:00
|
|
|
if ( (fd = open( mktemp( tmpname ), O_RDWR, 0600 )) == -1 ) {
|
|
|
|
perror( tmpname );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
if ( (fd = mkstemp( tmpname )) == -1 ) {
|
|
|
|
perror( tmpname );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
fp = fdopen( fd, "w" );
|
|
|
|
print_entry( fp, c, NULL, NULL, data, NULL );
|
|
|
|
fflush( fp );
|
|
|
|
|
|
|
|
pid = fork();
|
|
|
|
|
|
|
|
if ( pid == -1 ) {
|
|
|
|
perror( "fork" );
|
|
|
|
return;
|
|
|
|
} else if ( pid == 0 ) {
|
|
|
|
char *editor;
|
|
|
|
|
|
|
|
if ( (editor = getenv( "EDITOR" )) == NULL ) {
|
1999-06-17 11:54:25 +08:00
|
|
|
editor = LDAP_EDITOR;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
execl( editor, editor, tmpname, NULL );
|
|
|
|
perror( "execl" );
|
1999-08-04 02:14:24 +08:00
|
|
|
exit( EXIT_FAILURE );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fclose( fp );
|
|
|
|
|
1998-10-25 09:41:42 +08:00
|
|
|
#ifdef HAVE_WAITPID
|
1999-04-02 17:11:26 +08:00
|
|
|
if ( waitpid( (pid_t) -1, NULL, WAIT_FLAGS ) < 0 )
|
1998-08-09 08:43:13 +08:00
|
|
|
#else
|
1999-04-02 17:11:26 +08:00
|
|
|
if ( wait3( (pid_t) -1, &status, WAIT_FLAGS, 0 ) < 0 )
|
1998-08-09 08:43:13 +08:00
|
|
|
#endif
|
1999-04-02 17:11:26 +08:00
|
|
|
{
|
1998-08-09 08:43:13 +08:00
|
|
|
perror( "wait" );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( (fp = fopen( tmpname, "r" )) == NULL ) {
|
|
|
|
perror( tmpname );
|
|
|
|
return;
|
|
|
|
}
|
1998-12-30 01:28:45 +08:00
|
|
|
if ( data->dptr != NULL ) {
|
|
|
|
ldbm_datum_free( NULL, *data );
|
|
|
|
}
|
1998-08-09 08:43:13 +08:00
|
|
|
get_keydata( fp, c, NULL, data );
|
|
|
|
fclose( fp );
|
|
|
|
unlink( tmpname );
|
|
|
|
}
|
1999-07-16 10:45:46 +08:00
|
|
|
#endif
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1999-07-20 03:40:33 +08:00
|
|
|
static DBCache *
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-16 06:40:11 +08:00
|
|
|
openfile( char *name, int namesiz, int mode, int verbose, char c )
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
1999-07-20 03:40:33 +08:00
|
|
|
DBCache *dbc;
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
if ( name == NULL || *name == '\0' ) {
|
|
|
|
if ( c == 'f' ) {
|
|
|
|
printf( " file: " );
|
|
|
|
if ( fgets( name, namesiz, stdin ) == NULL )
|
1999-08-04 02:14:24 +08:00
|
|
|
exit( EXIT_SUCCESS );
|
1998-08-09 08:43:13 +08:00
|
|
|
name[strlen( name ) - 1] = '\0';
|
|
|
|
} else {
|
|
|
|
printf( " attr: " );
|
|
|
|
if ( fgets( name, namesiz, stdin ) == NULL )
|
1999-08-04 02:14:24 +08:00
|
|
|
exit( EXIT_SUCCESS );
|
1998-08-09 08:43:13 +08:00
|
|
|
name[strlen( name ) - 1] = '\0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( (dbc = ldbm_cache_open( be, name, (c == 'f') ? "" : LDBM_SUFFIX,
|
|
|
|
LDBM_READER )) == NULL ) {
|
|
|
|
perror( name );
|
|
|
|
} else {
|
|
|
|
dbp = dbc->dbc_db;
|
|
|
|
}
|
|
|
|
|
|
|
|
return( dbc );
|
|
|
|
}
|
|
|
|
|
1999-07-20 03:40:33 +08:00
|
|
|
static DBCache *
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-16 06:40:11 +08:00
|
|
|
openchoice( char c, int mode, int verbose, char **fname )
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
|
|
|
static char name[MAXPATHLEN];
|
|
|
|
|
|
|
|
switch ( c ) {
|
|
|
|
case 'c': /* id2children */
|
|
|
|
sprintf( name, "id2children" );
|
|
|
|
break;
|
|
|
|
case 'd': /* dn2id */
|
|
|
|
sprintf( name, "dn2id" );
|
|
|
|
break;
|
|
|
|
case 'e': /* id2entry */
|
|
|
|
sprintf( name, "id2entry" );
|
|
|
|
break;
|
|
|
|
case 'f': /* arbitrary file */
|
|
|
|
case 'i': /* index */
|
|
|
|
if ( fname != NULL && *fname != NULL ) {
|
|
|
|
strcpy( name, *fname );
|
|
|
|
} else {
|
|
|
|
name[0] = '\0';
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf( "specify one of [fdeci] to select file\n" );
|
|
|
|
return( NULL );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ( fname != NULL ) {
|
|
|
|
*fname = name;
|
|
|
|
}
|
|
|
|
|
|
|
|
return( openfile( name, MAXPATHLEN, mode, verbose, c ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-16 06:40:11 +08:00
|
|
|
print_entry(
|
|
|
|
FILE *fp,
|
|
|
|
char c,
|
|
|
|
Datum *key,
|
|
|
|
char *klabel,
|
|
|
|
Datum *data,
|
|
|
|
char *dlabel
|
|
|
|
)
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
|
|
|
ID id;
|
1999-01-31 15:55:53 +08:00
|
|
|
ID_BLOCK *idl;
|
1999-03-02 06:37:05 +08:00
|
|
|
unsigned int i;
|
1998-08-09 08:43:13 +08:00
|
|
|
char msg[2];
|
|
|
|
|
|
|
|
if ( data != NULL && data->dptr == NULL ) {
|
|
|
|
msg[0] = c;
|
|
|
|
msg[1] = '\0';
|
|
|
|
|
|
|
|
if ( ldbm_errno( dbp ) == 0 )
|
|
|
|
perror( msg );
|
|
|
|
else
|
|
|
|
fprintf( stderr, "%s: db_errno %d\n", msg,
|
|
|
|
ldbm_errno( dbp ) );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ( c ) {
|
|
|
|
case 'd': /* dn2id - key is dn, data is dnid */
|
|
|
|
if ( key != NULL )
|
|
|
|
fprintf( fp, "%s%s (len %d)\n", klabel, key->dptr,
|
|
|
|
key->dsize );
|
|
|
|
if ( data != NULL ) {
|
|
|
|
SAFEMEMCPY( (char *) &id, data->dptr, sizeof(ID) );
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-16 06:40:11 +08:00
|
|
|
fprintf( fp, "%s%ld\n", dlabel ? dlabel : "", id );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'e': /* id2entry - key is dnid, data is entry */
|
|
|
|
if ( key != NULL ) {
|
|
|
|
SAFEMEMCPY( (char *) &id, key->dptr, sizeof(ID) );
|
1999-02-12 05:26:57 +08:00
|
|
|
fprintf( fp, "%s %ld\n", klabel, id );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
if ( data != NULL ) {
|
|
|
|
if ( dlabel ) {
|
|
|
|
fprintf( fp, "data length: %d\n", data->dsize );
|
|
|
|
fputs( dlabel, fp );
|
|
|
|
}
|
|
|
|
fputs( data->dptr, fp );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'c':
|
|
|
|
case 'i': /* index - key is string, data is dnid[] */
|
|
|
|
if ( key != NULL )
|
|
|
|
fprintf( fp, "%s%s (len %d)\n", klabel, key->dptr,
|
|
|
|
key->dsize );
|
|
|
|
if ( data != NULL ) {
|
1999-01-31 15:55:53 +08:00
|
|
|
idl = (ID_BLOCK *) data->dptr;
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
if ( dlabel )
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-16 06:40:11 +08:00
|
|
|
fprintf( fp, "%s\tnmax=%ld\n\tncur=%ld\n", dlabel,
|
1999-01-31 15:55:53 +08:00
|
|
|
ID_BLOCK_NMAX(idl), ID_BLOCK_NIDS(idl) );
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1999-01-31 15:55:53 +08:00
|
|
|
if ( ID_BLOCK_INDIRECT( idl ) ) {
|
|
|
|
for ( i = 0; !ID_BLOCK_NOID(idl, i); i++ ) {
|
|
|
|
fprintf( fp, "\t%ld\n", ID_BLOCK_ID(idl, i) );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
1999-01-31 15:55:53 +08:00
|
|
|
} else if ( ID_BLOCK_ALLIDS( idl ) ) {
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-16 06:40:11 +08:00
|
|
|
fprintf( fp, "\tALLIDS (1..%ld)\n",
|
1999-01-31 15:55:53 +08:00
|
|
|
ID_BLOCK_NIDS(idl) - 1 );
|
1998-08-09 08:43:13 +08:00
|
|
|
} else {
|
1999-01-31 15:55:53 +08:00
|
|
|
for ( i = 0; i < ID_BLOCK_NIDS(idl); i++ ) {
|
|
|
|
fprintf( fp, "\t%ld\n", ID_BLOCK_ID(idl,i) );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'f': /* arbitrary file - assume key & data are strings */
|
|
|
|
if ( key != NULL )
|
|
|
|
fprintf( fp, "%s%s\n", klabel, key->dptr );
|
|
|
|
if ( data != NULL ) {
|
|
|
|
fprintf( fp, "%s%s\n", dlabel ? dlabel : "",
|
|
|
|
data->dptr );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
fprintf( stderr, "specify [deci] to select a file\n" );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-16 06:40:11 +08:00
|
|
|
get_keydata( FILE *fp, char c, Datum *key, Datum *data )
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
|
|
|
static char kbuf[BUFSIZ], dbuf[BUFSIZ];
|
|
|
|
long n;
|
|
|
|
int fd, tty;
|
|
|
|
|
|
|
|
fd = fileno( fp );
|
|
|
|
tty = isatty( fd );
|
|
|
|
|
|
|
|
switch ( c ) {
|
|
|
|
case 'd': /* dn2id - key is dn, data is dnid */
|
|
|
|
if ( key != NULL ) {
|
|
|
|
if ( tty )
|
|
|
|
printf( " dn: " );
|
|
|
|
if ( fgets( kbuf, sizeof(kbuf), fp ) == NULL ) {
|
1999-08-04 02:14:24 +08:00
|
|
|
exit( EXIT_SUCCESS );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
kbuf[strlen( kbuf ) - 1] = '\0';
|
|
|
|
key->dptr = strdup( kbuf );
|
|
|
|
key->dsize = strlen( kbuf ) + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( data != NULL ) {
|
|
|
|
if ( tty )
|
|
|
|
printf( " dnid: " );
|
|
|
|
if ( fgets( dbuf, sizeof(dbuf), fp ) == NULL ) {
|
1999-08-04 02:14:24 +08:00
|
|
|
exit( EXIT_SUCCESS );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
n = atol( dbuf );
|
|
|
|
data->dptr = (char *) malloc( sizeof(n) );
|
|
|
|
memcpy( data->dptr, (char *) &n, sizeof(n) );
|
|
|
|
data->dsize = sizeof(n);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'e': /* id2entry - key is dnid, data is entry */
|
|
|
|
if ( key != NULL ) {
|
|
|
|
if ( tty )
|
|
|
|
printf( " dnid: " );
|
|
|
|
if ( fgets( kbuf, sizeof(kbuf), fp ) == NULL ) {
|
1999-08-04 02:14:24 +08:00
|
|
|
exit( EXIT_SUCCESS );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
n = atol( kbuf );
|
|
|
|
key->dptr = (char *) malloc( sizeof(n) );
|
|
|
|
memcpy( key->dptr, (char *) &n, sizeof(n) );
|
|
|
|
key->dsize = sizeof(n);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( data != NULL ) {
|
|
|
|
get_entry( fp, data );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'c': /* id2children - key is string dnid, data is dnid[] */
|
|
|
|
case 'i': /* index - key is string, data is dnid[] */
|
|
|
|
if ( key != NULL ) {
|
|
|
|
if ( tty )
|
|
|
|
printf( " key: " );
|
|
|
|
if ( fgets( kbuf, sizeof(kbuf), fp ) == NULL ) {
|
1999-08-04 02:14:24 +08:00
|
|
|
exit( EXIT_SUCCESS );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
kbuf[strlen( kbuf ) - 1] = '\0';
|
|
|
|
key->dptr = strdup( kbuf );
|
|
|
|
key->dsize = strlen( kbuf ) + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( data != NULL ) {
|
|
|
|
get_idlist( fp, data );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
fprintf(stderr, "specify [deci] to select file type\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|