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 valid */
68 if( dn_normalize( e->e_ndn ) == NULL || e->e_ndn[0] == '\0' ) {
69 fprintf( stderr, "%s: invalid dn=\"%s\" (line=%d)\n",
70 progname, e->e_dn, lineno );
73 if( continuemode ) continue;
77 /* make sure the DN is not empty */
78 if( e->e_ndn == '\0' ) {
79 fprintf( stderr, "%s: empty dn=\"%s\" (line=%d)\n",
80 progname, e->e_dn, lineno );
83 if( continuemode ) continue;
88 if( select_backend( e->e_ndn, is_entry_referral(e), nosubs ) != be ) {
89 fprintf( stderr, "%s: database (%s) not configured to "
90 "hold dn=\"%s\" (line=%d)\n",
92 be ? be->be_suffix[0] : "<none>",
96 if( continuemode ) continue;
101 Attribute *sc = attr_find( e->e_attrs,
102 slap_schema.si_ad_structuralObjectClass );
103 Attribute *oc = attr_find( e->e_attrs,
104 slap_schema.si_ad_objectClass );
107 fprintf( stderr, "%s: dn=\"%s\" (line=%d): %s\n",
108 progname, e->e_dn, lineno,
109 "no objectClass attribute");
112 if( continuemode ) continue;
117 struct berval *vals[2];
120 int ret = structural_class(
121 oc->a_vals, &scbv, &text, textbuf, textlen );
123 if( scbv.bv_len == 0 ) {
124 fprintf( stderr, "%s: dn=\"%s\" (line=%d): %s\n",
125 progname, e->e_dn, lineno, text );
128 if( continuemode ) continue;
134 attr_merge( e, slap_schema.si_ad_structuralObjectClass,
139 if( global_schemacheck ) {
142 rc = entry_schema_check( e, NULL, &text, textbuf, textlen );
144 if( rc != LDAP_SUCCESS ) {
145 fprintf( stderr, "%s: dn=\"%s\" (line=%d): %s\n",
146 progname, e->e_dn, lineno, text );
149 if( continuemode ) continue;
154 id = be->be_entry_put( be, e );
156 fprintf( stderr, "%s: could not add entry dn=\"%s\" (line=%d)\n",
157 progname, e->e_dn, lineno );
160 if( continuemode ) continue;
166 fprintf( stderr, "added: \"%s\" (%08lx)\n",
167 e->e_dn, (long) id );
175 be->be_entry_close( be );