3 * Copyright 1998-2002 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;
31 char textbuf[SLAP_TEXT_BUFLEN] = { '\0' };
32 size_t textlen = sizeof textbuf;
35 lutil_log_initialize(argc, argv );
37 slap_tool_init( "slapadd", SLAPADD, argc, argv );
39 if( !be->be_entry_open ||
40 !be->be_entry_close ||
43 fprintf( stderr, "%s: database doesn't support necessary operations.\n",
51 if( be->be_entry_open( be, 1 ) != 0 ) {
52 fprintf( stderr, "%s: could not open database.\n",
57 while( ldif_read_record( ldiffp, &lineno, &buf, &lmax ) ) {
58 Entry *e = str2entry( buf );
61 bvtext.bv_len = textlen;
62 bvtext.bv_val = textbuf;
65 fprintf( stderr, "%s: could not parse entry (line=%d)\n",
68 if( continuemode ) continue;
72 /* make sure the DN is not empty */
73 if( !e->e_nname.bv_len ) {
74 fprintf( stderr, "%s: empty dn=\"%s\" (line=%d)\n",
75 progname, e->e_dn, lineno );
78 if( continuemode ) continue;
83 if( select_backend( &e->e_nname, is_entry_referral(e), nosubordinates )
86 fprintf( stderr, "%s: line %d: "
87 "database (%s) not configured to hold \"%s\"\n",
89 be ? be->be_suffix[0].bv_val : "<none>",
91 fprintf( stderr, "%s: line %d: "
92 "database (%s) not configured to hold \"%s\"\n",
94 be ? be->be_nsuffix[0].bv_val : "<none>",
98 if( continuemode ) continue;
103 Attribute *sc = attr_find( e->e_attrs,
104 slap_schema.si_ad_structuralObjectClass );
105 Attribute *oc = attr_find( e->e_attrs,
106 slap_schema.si_ad_objectClass );
109 fprintf( stderr, "%s: dn=\"%s\" (line=%d): %s\n",
110 progname, e->e_dn, lineno,
111 "no objectClass attribute");
114 if( continuemode ) continue;
119 struct berval vals[2];
122 structural_class( oc->a_vals, vals,
123 NULL, &text, textbuf, textlen );
125 if( vals[0].bv_len == 0 ) {
126 fprintf( stderr, "%s: dn=\"%s\" (line=%d): %s\n",
127 progname, e->e_dn, lineno, text );
130 if( continuemode ) continue;
134 vals[1].bv_val = NULL;
135 attr_merge( e, slap_schema.si_ad_structuralObjectClass,
140 if( global_schemacheck ) {
143 rc = entry_schema_check( be, e, NULL, &text, textbuf, textlen );
145 if( rc != LDAP_SUCCESS ) {
146 fprintf( stderr, "%s: dn=\"%s\" (line=%d): %s\n",
147 progname, e->e_dn, lineno, text );
150 if( continuemode ) continue;
156 ID id = be->be_entry_put( be, e, &bvtext );
158 fprintf( stderr, "%s: could not add entry dn=\"%s\" (line=%d): %s\n",
159 progname, e->e_dn, lineno, bvtext.bv_val );
162 if( continuemode ) continue;
167 fprintf( stderr, "added: \"%s\" (%08lx)\n",
168 e->e_dn, (long) id );
172 fprintf( stderr, "(dry) added: \"%s\"\n", e->e_dn );
181 be->be_entry_close( be );