]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/tools/slapadd.c
First stable an implementing latest namedref specification.
[openldap] / servers / slapd / tools / slapadd.c
index abc894b71c93b3c408673433848439b593ab265d..55b536c43dcde2143c23038713e7898105602103 100644 (file)
@@ -1,5 +1,6 @@
+/* $OpenLDAP$ */
 /*
- * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
+ * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
  */
 #include "portable.h"
@@ -25,8 +26,8 @@ main( int argc, char **argv )
 
        slap_tool_init( "slapadd", SLAPADD, argc, argv );
 
-       if( !be->be_entry_open &&
-               !be->be_entry_close &&
+       if( !be->be_entry_open ||
+               !be->be_entry_close ||
                !be->be_entry_put )
        {
                fprintf( stderr, "%s: database doesn't support necessary operations.\n",
@@ -36,6 +37,7 @@ main( int argc, char **argv )
 
        buf = NULL;
        lmax = 0;
+       lineno = 0;
 
        if( be->be_entry_open( be, 1 ) != 0 ) {
                fprintf( stderr, "%s: could not open database.\n",
@@ -55,31 +57,51 @@ main( int argc, char **argv )
                        break;
                }
 
-               if( !noschemacheck ) {
-                       /* make sure the DN is valid */
-                       if( dn_normalize_case( e->e_ndn ) == NULL ) {
-                               fprintf( stderr, "%s: bad dn=\"%s\" (line=%d)\n",
-                                       progname, e->e_dn, lineno );
-                               rc = EXIT_FAILURE;
-                               entry_free( e );
-                               if( continuemode ) continue;
-                               break;
-                       }
+               /* make sure the DN is valid */
+               if( dn_normalize( e->e_ndn ) == NULL || e->e_ndn[0] == '\0' ) {
+                       fprintf( stderr, "%s: invalid dn=\"%s\" (line=%d)\n",
+                               progname, e->e_dn, lineno );
+                       rc = EXIT_FAILURE;
+                       entry_free( e );
+                       if( continuemode ) continue;
+                       break;
+               }
 
+               /* make sure the DN is not empty */
+               if( e->e_ndn == '\0' ) {
+                       fprintf( stderr, "%s: empty dn=\"%s\" (line=%d)\n",
+                               progname, e->e_dn, lineno );
+                       rc = EXIT_FAILURE;
+                       entry_free( e );
+                       if( continuemode ) continue;
+                       break;
+               }
+
+               /* check backend */
+               if( select_backend( e->e_ndn, is_entry_referral(e) ) != be )
+               {
+                       fprintf( stderr, "%s: database (%s) not configured to "
+                               "hold dn=\"%s\" (line=%d)\n",
+                               progname,
+                               be ? be->be_suffix[0] : "<none>",
+                               e->e_dn, lineno );
+                       rc = EXIT_FAILURE;
+                       entry_free( e );
+                       if( continuemode ) continue;
+                       break;
+               }
+
+               if( global_schemacheck ) {
                        /* check schema */
-                       if ( global_schemacheck && oc_schema_check( e ) != 0 ) {
-                               fprintf( stderr, "%s: entry dn=\"%s\" violates schema violation (line=%d)\n",
-                                       progname, e->e_dn, lineno );
-                               rc = EXIT_FAILURE;
-                               entry_free( e );
-                               if( continuemode ) continue;
-                               break;
-                       }
+                       const char *text;
+                       char textbuf[SLAP_TEXT_BUFLEN];
+                       size_t textlen = sizeof textbuf;
 
-                       /* check backend */
-                       if( select_backend( e->e_ndn ) != be ) {
-                               fprintf( stderr, "%s: database not configured to hold dn=\"%s\" (line=%d)\n",
-                                       progname, e->e_dn, lineno );
+                       rc = entry_schema_check( e, NULL, &text, textbuf, textlen );
+
+                       if( rc != LDAP_SUCCESS ) {
+                               fprintf( stderr, "%s: dn=\"%s\" (line=%d): %s\n",
+                                       progname, e->e_dn, lineno, text );
                                rc = EXIT_FAILURE;
                                entry_free( e );
                                if( continuemode ) continue;
@@ -88,7 +110,6 @@ main( int argc, char **argv )
                }
 
                id = be->be_entry_put( be, e );
-
                if( id == NOID ) {
                        fprintf( stderr, "%s: could not add entry dn=\"%s\" (line=%d)\n",
                                progname, e->e_dn, lineno );
@@ -97,7 +118,9 @@ main( int argc, char **argv )
                        if( continuemode ) continue;
                        break;
 
-               } else if ( verbose ) {
+               }
+               
+               if ( verbose ) {
                        fprintf( stderr, "added: \"%s\" (%08lx)\n",
                                e->e_dn, (long) id );
                }
@@ -105,6 +128,8 @@ main( int argc, char **argv )
                entry_free( e );
        }
 
+       ch_free( buf );
+
        be->be_entry_close( be );
 
        if( be->be_sync ) {