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;
34 slap_tool_init( "slapadd", SLAPADD, argc, argv );
36 if( !be->be_entry_open ||
37 !be->be_entry_close ||
40 fprintf( stderr, "%s: database doesn't support necessary operations.\n",
48 if( be->be_entry_open( be, 1 ) != 0 ) {
49 fprintf( stderr, "%s: could not open database.\n",
54 while( ldif_read_record( ldiffp, &lineno, &buf, &lmax ) ) {
55 Entry *e = str2entry( buf );
56 struct berval bvtext = { textlen, textbuf };
59 fprintf( stderr, "%s: could not parse entry (line=%d)\n",
62 if( continuemode ) continue;
66 /* make sure the DN is not empty */
67 if( !e->e_nname.bv_len ) {
68 fprintf( stderr, "%s: empty dn=\"%s\" (line=%d)\n",
69 progname, e->e_dn, lineno );
72 if( continuemode ) continue;
77 if( select_backend( &e->e_nname, is_entry_referral(e), nosubordinates )
80 fprintf( stderr, "%s: line %d: "
81 "database (%s) not configured to hold \"%s\"\n",
83 be ? be->be_suffix[0]->bv_val : "<none>",
85 fprintf( stderr, "%s: line %d: "
86 "database (%s) not configured to hold \"%s\"\n",
88 be ? be->be_nsuffix[0]->bv_val : "<none>",
92 if( continuemode ) continue;
97 Attribute *sc = attr_find( e->e_attrs,
98 slap_schema.si_ad_structuralObjectClass );
99 Attribute *oc = attr_find( e->e_attrs,
100 slap_schema.si_ad_objectClass );
103 fprintf( stderr, "%s: dn=\"%s\" (line=%d): %s\n",
104 progname, e->e_dn, lineno,
105 "no objectClass attribute");
108 if( continuemode ) continue;
113 struct berval vals[2];
115 int ret = structural_class( oc->a_vals, vals,
116 NULL, &text, textbuf, textlen );
118 if( vals[0].bv_len == 0 ) {
119 fprintf( stderr, "%s: dn=\"%s\" (line=%d): %s\n",
120 progname, e->e_dn, lineno, text );
123 if( continuemode ) continue;
127 vals[1].bv_val = NULL;
128 attr_merge( e, slap_schema.si_ad_structuralObjectClass,
133 if( global_schemacheck ) {
136 rc = entry_schema_check( be, e, NULL, &text, textbuf, textlen );
138 if( rc != LDAP_SUCCESS ) {
139 fprintf( stderr, "%s: dn=\"%s\" (line=%d): %s\n",
140 progname, e->e_dn, lineno, text );
143 if( continuemode ) continue;
149 ID id = be->be_entry_put( be, e, &bvtext );
151 fprintf( stderr, "%s: could not add entry dn=\"%s\" (line=%d): %s\n",
152 progname, e->e_dn, lineno, bvtext.bv_val );
155 if( continuemode ) continue;
160 fprintf( stderr, "added: \"%s\" (%08lx)\n",
161 e->e_dn, (long) id );
165 fprintf( stderr, "(dry) added: \"%s\"\n", e->e_dn );
174 be->be_entry_close( be );