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];
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_nname, is_entry_referral(e), nosubordinates )
81 fprintf( stderr, "%s: line %d: "
82 "database (%s) not configured to hold \"%s\"\n",
84 be ? be->be_suffix[0]->bv_val : "<none>",
86 fprintf( stderr, "%s: line %d: "
87 "database (%s) not configured to hold \"%s\"\n",
89 be ? be->be_nsuffix[0]->bv_val : "<none>",
93 if( continuemode ) continue;
98 Attribute *sc = attr_find( e->e_attrs,
99 slap_schema.si_ad_structuralObjectClass );
100 Attribute *oc = attr_find( e->e_attrs,
101 slap_schema.si_ad_objectClass );
104 fprintf( stderr, "%s: dn=\"%s\" (line=%d): %s\n",
105 progname, e->e_dn, lineno,
106 "no objectClass attribute");
109 if( continuemode ) continue;
114 struct berval vals[2];
116 int ret = structural_class( oc->a_vals, vals,
117 NULL, &text, textbuf, textlen );
119 if( vals[0].bv_len == 0 ) {
120 fprintf( stderr, "%s: dn=\"%s\" (line=%d): %s\n",
121 progname, e->e_dn, lineno, text );
124 if( continuemode ) continue;
128 vals[1].bv_val = NULL;
129 attr_merge( e, slap_schema.si_ad_structuralObjectClass,
134 if( global_schemacheck ) {
137 rc = entry_schema_check( be, 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 );