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 );
58 bvtext.bv_len = textlen;
59 bvtext.bv_val = textbuf;
62 fprintf( stderr, "%s: could not parse entry (line=%d)\n",
65 if( continuemode ) continue;
69 /* make sure the DN is not empty */
70 if( !e->e_nname.bv_len ) {
71 fprintf( stderr, "%s: empty dn=\"%s\" (line=%d)\n",
72 progname, e->e_dn, lineno );
75 if( continuemode ) continue;
80 if( select_backend( &e->e_nname, is_entry_referral(e), nosubordinates )
83 fprintf( stderr, "%s: line %d: "
84 "database (%s) not configured to hold \"%s\"\n",
86 be ? be->be_suffix[0]->bv_val : "<none>",
88 fprintf( stderr, "%s: line %d: "
89 "database (%s) not configured to hold \"%s\"\n",
91 be ? be->be_nsuffix[0]->bv_val : "<none>",
95 if( continuemode ) continue;
100 Attribute *sc = attr_find( e->e_attrs,
101 slap_schema.si_ad_structuralObjectClass );
102 Attribute *oc = attr_find( e->e_attrs,
103 slap_schema.si_ad_objectClass );
106 fprintf( stderr, "%s: dn=\"%s\" (line=%d): %s\n",
107 progname, e->e_dn, lineno,
108 "no objectClass attribute");
111 if( continuemode ) continue;
116 struct berval vals[2];
119 structural_class( oc->a_vals, vals,
120 NULL, &text, textbuf, textlen );
122 if( vals[0].bv_len == 0 ) {
123 fprintf( stderr, "%s: dn=\"%s\" (line=%d): %s\n",
124 progname, e->e_dn, lineno, text );
127 if( continuemode ) continue;
131 vals[1].bv_val = NULL;
132 attr_merge( e, slap_schema.si_ad_structuralObjectClass,
137 if( global_schemacheck ) {
140 rc = entry_schema_check( be, e, NULL, &text, textbuf, textlen );
142 if( rc != LDAP_SUCCESS ) {
143 fprintf( stderr, "%s: dn=\"%s\" (line=%d): %s\n",
144 progname, e->e_dn, lineno, text );
147 if( continuemode ) continue;
153 ID id = be->be_entry_put( be, e, &bvtext );
155 fprintf( stderr, "%s: could not add entry dn=\"%s\" (line=%d): %s\n",
156 progname, e->e_dn, lineno, bvtext.bv_val );
159 if( continuemode ) continue;
164 fprintf( stderr, "added: \"%s\" (%08lx)\n",
165 e->e_dn, (long) id );
169 fprintf( stderr, "(dry) added: \"%s\"\n", e->e_dn );
178 be->be_entry_close( be );