3 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
10 #include <ac/stdlib.h>
13 #include <ac/string.h>
14 #include <ac/socket.h>
15 #include <ac/unistd.h>
20 #include "slapcommon.h"
23 main( int argc, char **argv )
28 int rc = EXIT_SUCCESS;
30 slap_tool_init( "slapadd", SLAPADD, argc, argv );
32 if( !be->be_entry_open ||
33 !be->be_entry_close ||
36 fprintf( stderr, "%s: database doesn't support necessary operations.\n",
45 if( be->be_entry_open( be, 1 ) != 0 ) {
46 fprintf( stderr, "%s: could not open database.\n",
51 while( ldif_read_record( ldiffp, &lineno, &buf, &lmax ) ) {
53 Entry *e = str2entry( buf );
56 fprintf( stderr, "%s: could not parse entry (line=%d)\n",
59 if( continuemode ) continue;
63 /* make sure the DN is valid */
64 if( dn_normalize( e->e_ndn ) == NULL || e->e_ndn[0] == '\0' ) {
65 fprintf( stderr, "%s: invalid dn=\"%s\" (line=%d)\n",
66 progname, e->e_dn, lineno );
69 if( continuemode ) continue;
73 /* make sure the DN is not empty */
74 if( e->e_ndn == '\0' ) {
75 fprintf( stderr, "%s: empty dn=\"%s\" (line=%d)\n",
76 progname, e->e_dn, lineno );
79 if( continuemode ) continue;
84 if( select_backend( e->e_ndn, is_entry_referral(e), nosubs ) != be )
86 fprintf( stderr, "%s: database (%s) not configured to "
87 "hold dn=\"%s\" (line=%d)\n",
89 be ? be->be_suffix[0] : "<none>",
93 if( continuemode ) continue;
97 if( global_schemacheck ) {
100 char textbuf[SLAP_TEXT_BUFLEN];
101 size_t textlen = sizeof textbuf;
103 rc = entry_schema_check( e, NULL, &text, textbuf, textlen );
105 if( rc != LDAP_SUCCESS ) {
106 fprintf( stderr, "%s: dn=\"%s\" (line=%d): %s\n",
107 progname, e->e_dn, lineno, text );
110 if( continuemode ) continue;
115 id = be->be_entry_put( be, e );
117 fprintf( stderr, "%s: could not add entry dn=\"%s\" (line=%d)\n",
118 progname, e->e_dn, lineno );
121 if( continuemode ) continue;
127 fprintf( stderr, "added: \"%s\" (%08lx)\n",
128 e->e_dn, (long) id );
136 be->be_entry_close( be );