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>
17 #include "slapcommon.h"
20 main( int argc, char **argv )
25 int rc = EXIT_SUCCESS;
27 slap_tool_init( "slapadd", SLAPADD, argc, argv );
29 if( !be->be_entry_open ||
30 !be->be_entry_close ||
33 fprintf( stderr, "%s: database doesn't support necessary operations.\n",
42 if( be->be_entry_open( be, 1 ) != 0 ) {
43 fprintf( stderr, "%s: could not open database.\n",
48 while( ldif_read_record( ldiffp, &lineno, &buf, &lmax ) ) {
50 Entry *e = str2entry( buf );
53 fprintf( stderr, "%s: could not parse entry (line=%d)\n",
56 if( continuemode ) continue;
60 /* make sure the DN is valid */
61 if( dn_normalize( e->e_ndn ) == NULL || e->e_ndn[0] == '\0' ) {
62 fprintf( stderr, "%s: invalid dn=\"%s\" (line=%d)\n",
63 progname, e->e_dn, lineno );
66 if( continuemode ) continue;
70 /* make sure the DN is not empty */
71 if( e->e_ndn == '\0' ) {
72 fprintf( stderr, "%s: empty dn=\"%s\" (line=%d)\n",
73 progname, e->e_dn, lineno );
76 if( continuemode ) continue;
81 if( select_backend( e->e_ndn, is_entry_referral(e) ) != be )
83 fprintf( stderr, "%s: database (%s) not configured to "
84 "hold dn=\"%s\" (line=%d)\n",
86 be ? be->be_suffix[0] : "<none>",
90 if( continuemode ) continue;
94 if( global_schemacheck ) {
97 char textbuf[SLAP_TEXT_BUFLEN];
98 size_t textlen = sizeof textbuf;
100 rc = entry_schema_check( e, NULL, &text, textbuf, textlen );
102 if( rc != LDAP_SUCCESS ) {
103 fprintf( stderr, "%s: dn=\"%s\" (line=%d): %s\n",
104 progname, e->e_dn, lineno, text );
107 if( continuemode ) continue;
112 id = be->be_entry_put( be, e );
114 fprintf( stderr, "%s: could not add entry dn=\"%s\" (line=%d)\n",
115 progname, e->e_dn, lineno );
118 if( continuemode ) continue;
124 fprintf( stderr, "added: \"%s\" (%08lx)\n",
125 e->e_dn, (long) id );
133 be->be_entry_close( be );