1999-09-09 03:06:24 +08:00
|
|
|
/* $OpenLDAP$ */
|
1999-08-18 03:00:59 +08:00
|
|
|
/*
|
2000-05-13 10:47:56 +08:00
|
|
|
* Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
|
1999-08-18 03:00:59 +08:00
|
|
|
* 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 );
|
|
|
|
|
2000-08-21 11:08:01 +08:00
|
|
|
if( !be->be_entry_open ||
|
|
|
|
!be->be_entry_close ||
|
1999-08-18 03:00:59 +08:00
|
|
|
!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;
|
|
|
|
}
|
|
|
|
|
2000-02-26 03:31:54 +08:00
|
|
|
/* make sure the DN is valid */
|
|
|
|
if( dn_normalize( e->e_ndn ) == NULL ) {
|
2000-09-16 14:23:53 +08:00
|
|
|
fprintf( stderr, "%s: invalid dn=\"%s\" (line=%d)\n",
|
2000-02-26 03:31:54 +08:00
|
|
|
progname, e->e_dn, lineno );
|
|
|
|
rc = EXIT_FAILURE;
|
|
|
|
entry_free( e );
|
|
|
|
if( continuemode ) continue;
|
|
|
|
break;
|
|
|
|
}
|
1999-08-18 09:45:59 +08:00
|
|
|
|
2000-09-16 14:23:53 +08:00
|
|
|
/* make sure the DN is not empty */
|
2000-09-08 13:20:46 +08:00
|
|
|
if( e->e_ndn == '\0' ) {
|
|
|
|
fprintf( stderr, "%s: empty dn=\"%s\" (line=%d)\n",
|
|
|
|
progname, e->e_dn, lineno );
|
|
|
|
rc = EXIT_FAILURE;
|
|
|
|
entry_free( e );
|
|
|
|
if( continuemode ) continue;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2000-09-16 14:23:53 +08:00
|
|
|
/* check backend */
|
2000-10-21 11:29:02 +08:00
|
|
|
if( select_backend( e->e_ndn, is_entry_referral(e) ) != be )
|
|
|
|
{
|
2000-10-10 09:37:07 +08:00
|
|
|
fprintf( stderr, "%s: database (%s) not configured to "
|
2000-09-16 14:23:53 +08:00
|
|
|
"hold dn=\"%s\" (line=%d)\n",
|
2000-10-10 09:37:07 +08:00
|
|
|
progname,
|
|
|
|
be ? be->be_suffix[0] : "<none>",
|
|
|
|
e->e_dn, lineno );
|
2000-09-16 14:23:53 +08:00
|
|
|
rc = EXIT_FAILURE;
|
|
|
|
entry_free( e );
|
|
|
|
if( continuemode ) continue;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2000-09-18 04:40:43 +08:00
|
|
|
if( global_schemacheck ) {
|
1999-08-18 09:45:59 +08:00
|
|
|
/* check schema */
|
2000-05-22 11:46:57 +08:00
|
|
|
const char *text;
|
2000-04-25 21:07:14 +08:00
|
|
|
if ( entry_schema_check( e, NULL, &text ) != LDAP_SUCCESS ) {
|
|
|
|
fprintf( stderr, "%s: dn=\"%s\" (line=%d): %s\n",
|
|
|
|
progname, e->e_dn, lineno, text );
|
1999-08-18 09:45:59 +08:00
|
|
|
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
|
|
|
|
2000-09-17 06:46:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
2000-05-28 01:06:11 +08:00
|
|
|
ch_free( buf );
|
1999-08-20 02:19:20 +08:00
|
|
|
|
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;
|
|
|
|
}
|