1999-09-09 03:06:24 +08:00
|
|
|
/* $OpenLDAP$ */
|
1999-08-18 03:00:59 +08:00
|
|
|
/*
|
|
|
|
* Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
|
|
|
|
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
|
|
|
|
*/
|
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <ac/stdlib.h>
|
|
|
|
|
|
|
|
#include <ac/ctype.h>
|
|
|
|
#include <ac/string.h>
|
|
|
|
#include <ac/socket.h>
|
|
|
|
#include <ac/unistd.h>
|
|
|
|
|
|
|
|
#include "slapcommon.h"
|
|
|
|
|
|
|
|
int
|
|
|
|
main( int argc, char **argv )
|
|
|
|
{
|
|
|
|
char *buf;
|
|
|
|
int lineno;
|
|
|
|
int lmax;
|
|
|
|
int rc = EXIT_SUCCESS;
|
|
|
|
|
|
|
|
slap_tool_init( "slapadd", SLAPADD, argc, argv );
|
|
|
|
|
|
|
|
if( !be->be_entry_open &&
|
|
|
|
!be->be_entry_close &&
|
|
|
|
!be->be_entry_put )
|
|
|
|
{
|
|
|
|
fprintf( stderr, "%s: database doesn't support necessary operations.\n",
|
|
|
|
progname );
|
|
|
|
exit( EXIT_FAILURE );
|
|
|
|
}
|
|
|
|
|
|
|
|
buf = NULL;
|
|
|
|
lmax = 0;
|
1999-08-22 11:32:13 +08:00
|
|
|
lineno = 0;
|
1999-08-18 03:00:59 +08:00
|
|
|
|
|
|
|
if( be->be_entry_open( be, 1 ) != 0 ) {
|
|
|
|
fprintf( stderr, "%s: could not open database.\n",
|
|
|
|
progname );
|
|
|
|
exit( EXIT_FAILURE );
|
|
|
|
}
|
|
|
|
|
|
|
|
while( ldif_read_record( ldiffp, &lineno, &buf, &lmax ) ) {
|
|
|
|
ID id;
|
|
|
|
Entry *e = str2entry( buf );
|
|
|
|
|
|
|
|
if( e == NULL ) {
|
1999-08-18 09:45:59 +08:00
|
|
|
fprintf( stderr, "%s: could not parse entry (line=%d)\n",
|
1999-08-18 03:00:59 +08:00
|
|
|
progname, lineno );
|
|
|
|
rc = EXIT_FAILURE;
|
1999-08-18 09:45:59 +08:00
|
|
|
if( continuemode ) continue;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !noschemacheck ) {
|
|
|
|
/* make sure the DN is valid */
|
|
|
|
if( dn_normalize_case( e->e_ndn ) == NULL ) {
|
|
|
|
fprintf( stderr, "%s: bad dn=\"%s\" (line=%d)\n",
|
|
|
|
progname, e->e_dn, lineno );
|
|
|
|
rc = EXIT_FAILURE;
|
|
|
|
entry_free( e );
|
|
|
|
if( continuemode ) continue;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check schema */
|
|
|
|
if ( global_schemacheck && oc_schema_check( e ) != 0 ) {
|
1999-08-31 08:40:07 +08:00
|
|
|
fprintf( stderr, "%s: schema violation in entry dn=\"%s\" (line=%d)\n",
|
1999-08-18 09:45:59 +08:00
|
|
|
progname, e->e_dn, lineno );
|
|
|
|
rc = EXIT_FAILURE;
|
|
|
|
entry_free( e );
|
|
|
|
if( continuemode ) continue;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check backend */
|
|
|
|
if( select_backend( e->e_ndn ) != be ) {
|
|
|
|
fprintf( stderr, "%s: database not configured to hold dn=\"%s\" (line=%d)\n",
|
|
|
|
progname, e->e_dn, lineno );
|
|
|
|
rc = EXIT_FAILURE;
|
|
|
|
entry_free( e );
|
|
|
|
if( continuemode ) continue;
|
|
|
|
break;
|
|
|
|
}
|
1999-08-18 03:00:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
id = be->be_entry_put( be, e );
|
|
|
|
|
|
|
|
if( id == NOID ) {
|
1999-08-18 09:45:59 +08:00
|
|
|
fprintf( stderr, "%s: could not add entry dn=\"%s\" (line=%d)\n",
|
1999-08-18 03:00:59 +08:00
|
|
|
progname, e->e_dn, lineno );
|
|
|
|
rc = EXIT_FAILURE;
|
1999-08-18 09:45:59 +08:00
|
|
|
entry_free( e );
|
|
|
|
if( continuemode ) continue;
|
|
|
|
break;
|
1999-08-18 03:00:59 +08:00
|
|
|
|
|
|
|
} else if ( verbose ) {
|
1999-08-19 08:40:18 +08:00
|
|
|
fprintf( stderr, "added: \"%s\" (%08lx)\n",
|
1999-08-18 03:00:59 +08:00
|
|
|
e->e_dn, (long) id );
|
|
|
|
}
|
|
|
|
|
|
|
|
entry_free( e );
|
|
|
|
}
|
|
|
|
|
1999-08-20 02:19:20 +08:00
|
|
|
free( buf );
|
|
|
|
|
1999-08-18 03:00:59 +08:00
|
|
|
be->be_entry_close( be );
|
|
|
|
|
|
|
|
if( be->be_sync ) {
|
|
|
|
be->be_sync( be );
|
|
|
|
}
|
|
|
|
|
1999-08-20 01:20:15 +08:00
|
|
|
slap_tool_destroy();
|
1999-08-18 03:00:59 +08:00
|
|
|
return rc;
|
|
|
|
}
|