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;
31 char textbuf[SLAP_TEXT_BUFLEN];
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",
49 if( be->be_entry_open( be, 1 ) != 0 ) {
50 fprintf( stderr, "%s: could not open database.\n",
55 while( ldif_read_record( ldiffp, &lineno, &buf, &lmax ) ) {
57 Entry *e = str2entry( buf );
60 fprintf( stderr, "%s: could not parse entry (line=%d)\n",
63 if( continuemode ) continue;
67 /* make sure the DN is not empty */
68 if( !e->e_nname.bv_len ) {
69 fprintf( stderr, "%s: empty dn=\"%s\" (line=%d)\n",
70 progname, e->e_dn, lineno );
73 if( continuemode ) continue;
78 if( select_backend( e->e_ndn, is_entry_referral(e), nosubs ) != be ) {
79 fprintf( stderr, "%s: line %d: "
80 "database (%s) not configured to hold \"%s\"\n",
82 be ? be->be_suffix[0] : "<none>",
84 fprintf( stderr, "%s: line %d: "
85 "database (%s) not configured to hold \"%s\"\n",
87 be ? be->be_nsuffix[0]->bv_val : "<none>",
91 if( continuemode ) continue;
96 Attribute *sc = attr_find( e->e_attrs,
97 slap_schema.si_ad_structuralObjectClass );
98 Attribute *oc = attr_find( e->e_attrs,
99 slap_schema.si_ad_objectClass );
102 fprintf( stderr, "%s: dn=\"%s\" (line=%d): %s\n",
103 progname, e->e_dn, lineno,
104 "no objectClass attribute");
107 if( continuemode ) continue;
112 struct berval *vals[2];
115 int ret = structural_class(
116 oc->a_vals, &scbv, &text, textbuf, textlen );
118 if( scbv.bv_len == 0 ) {
119 fprintf( stderr, "%s: dn=\"%s\" (line=%d): %s\n",
120 progname, e->e_dn, lineno, text );
123 if( continuemode ) continue;
129 attr_merge( e, slap_schema.si_ad_structuralObjectClass,
134 if( global_schemacheck ) {
137 rc = entry_schema_check( e, NULL, &text, textbuf, textlen );
139 if( rc != LDAP_SUCCESS ) {
140 fprintf( stderr, "%s: dn=\"%s\" (line=%d): %s\n",
141 progname, e->e_dn, lineno, text );
144 if( continuemode ) continue;
149 id = be->be_entry_put( be, e );
151 fprintf( stderr, "%s: could not add entry dn=\"%s\" (line=%d)\n",
152 progname, e->e_dn, lineno );
155 if( continuemode ) continue;
161 fprintf( stderr, "added: \"%s\" (%08lx)\n",
162 e->e_dn, (long) id );
170 be->be_entry_close( be );