]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/slapadd.c
warn if entryUUID,entryCSN are missing and the database is shadow (ITS#6281)
[openldap] / servers / slapd / slapadd.c
index 5ee5abf08a4c20544e2b6e3b2da6ca6d506227ed..1c39b45eed36aa712a59d30e2cb417ae07ba8738 100644 (file)
@@ -40,8 +40,8 @@
 
 #include "slapcommon.h"
 
-static char csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
-static char maxcsnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE * ( SLAP_SYNC_SID_MAX + 1 ) ];
+static char csnbuf[ LDAP_PVT_CSNSTR_BUFSIZE ];
+static char maxcsnbuf[ LDAP_PVT_CSNSTR_BUFSIZE * ( SLAP_SYNC_SID_MAX + 1 ) ];
 
 int
 slapadd( int argc, char **argv )
@@ -64,7 +64,7 @@ slapadd( int argc, char **argv )
 
        int match;
        int checkvals;
-       int lineno, nextline;
+       int lineno, nextline, ldifrc;
        int lmax;
        int rc = EXIT_SUCCESS;
        int manage = 0; 
@@ -120,7 +120,7 @@ slapadd( int argc, char **argv )
        if ( update_ctxcsn ) {
                maxcsn[ 0 ].bv_val = maxcsnbuf;
                for ( sid = 1; sid <= SLAP_SYNC_SID_MAX; sid++ ) {
-                       maxcsn[ sid ].bv_val = maxcsn[ sid - 1 ].bv_val + LDAP_LUTIL_CSNSTR_BUFSIZE;
+                       maxcsn[ sid ].bv_val = maxcsn[ sid - 1 ].bv_val + LDAP_PVT_CSNSTR_BUFSIZE;
                        maxcsn[ sid ].bv_len = 0;
                }
        }
@@ -142,7 +142,7 @@ slapadd( int argc, char **argv )
        }
 
        /* nextline is the line number of the end of the current entry */
-       for( lineno=1; ldif_read_record( ldiffp, &nextline, &buf, &lmax );
+       for( lineno=1; ( ldifrc = ldif_read_record( ldiffp, &nextline, &buf, &lmax )) > 0;
                lineno=nextline+1 )
        {
                BackendDB *bd;
@@ -177,8 +177,26 @@ slapadd( int argc, char **argv )
                if( BER_BVISEMPTY( &e->e_nname ) &&
                        !BER_BVISEMPTY( be->be_nsuffix ))
                {
-                       fprintf( stderr, "%s: empty dn=\"%s\" (line=%d)\n",
-                               progname, e->e_dn, lineno );
+                       fprintf( stderr, "%s: line %d: "
+                               "cannot add entry with empty dn=\"%s\"",
+                               progname, lineno, e->e_dn );
+                       bd = select_backend( &e->e_nname, nosubordinates );
+                       if ( bd ) {
+                               BackendDB *bdtmp;
+                               int dbidx = 0;
+                               LDAP_STAILQ_FOREACH( bdtmp, &backendDB, be_next ) {
+                                       if ( bdtmp == bd ) break;
+                                       dbidx++;
+                               }
+
+                               assert( bdtmp != NULL );
+                               
+                               fprintf( stderr, "; did you mean to use database #%d (%s)?",
+                                       dbidx,
+                                       bd->be_suffix[0].bv_val );
+
+                       }
+                       fprintf( stderr, "\n" );
                        rc = EXIT_FAILURE;
                        entry_free( e );
                        if( continuemode ) continue;
@@ -262,13 +280,20 @@ slapadd( int argc, char **argv )
                        struct berval nname;
                        char timebuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
 
+                       enum {
+                               GOT_NONE = 0x0,
+                               GOT_CSN = 0x1,
+                               GOT_UUID = 0x2,
+                               GOT_ALL = (GOT_CSN|GOT_UUID)
+                       } got = GOT_ALL;
+
                        vals[1].bv_len = 0;
                        vals[1].bv_val = NULL;
 
                        nvals[1].bv_len = 0;
                        nvals[1].bv_val = NULL;
 
-                       csn.bv_len = lutil_csnstr( csnbuf, sizeof( csnbuf ), csnsid, 0 );
+                       csn.bv_len = ldap_pvt_csnstr( csnbuf, sizeof( csnbuf ), csnsid, 0 );
                        csn.bv_val = csnbuf;
 
                        timestamp.bv_val = timebuf;
@@ -287,6 +312,7 @@ slapadd( int argc, char **argv )
                        if( attr_find( e->e_attrs, slap_schema.si_ad_entryUUID )
                                == NULL )
                        {
+                               got &= ~GOT_UUID;
                                vals[0].bv_len = lutil_uuidstr( uuidbuf, sizeof( uuidbuf ) );
                                vals[0].bv_val = uuidbuf;
                                attr_merge_normalize_one( e, slap_schema.si_ad_entryUUID, vals, NULL );
@@ -310,6 +336,7 @@ slapadd( int argc, char **argv )
                        if( attr_find( e->e_attrs, slap_schema.si_ad_entryCSN )
                                == NULL )
                        {
+                               got &= ~GOT_CSN;
                                vals[0] = csn;
                                attr_merge( e, slap_schema.si_ad_entryCSN, vals, NULL );
                        }
@@ -329,6 +356,19 @@ slapadd( int argc, char **argv )
                                attr_merge( e, slap_schema.si_ad_modifyTimestamp, vals, NULL );
                        }
 
+                       if ( SLAP_SINGLE_SHADOW(be) && got != GOT_ALL ) {
+                               char buf[SLAP_TEXT_BUFLEN];
+
+                               snprintf( buf, sizeof(buf),
+                                       "%s%s%s",
+                                       ( !(got & GOT_UUID) ? slap_schema.si_ad_entryUUID->ad_cname.bv_val : "" ),
+                                       ( !(got & GOT_CSN) ? "," : "" ),
+                                       ( !(got & GOT_CSN) ? slap_schema.si_ad_entryCSN->ad_cname.bv_val : "" ) );
+
+                               Debug( LDAP_DEBUG_ANY, "%s: warning, missing attrs %s from entry dn=\"%s\"\n",
+                                       progname, buf, e->e_name.bv_val );
+                       }
+
                        if ( update_ctxcsn ) {
                                int rc_sid;
 
@@ -338,8 +378,8 @@ slapadd( int argc, char **argv )
                                rc_sid = slap_parse_csn_sid( &attr->a_nvals[ 0 ] );
                                if ( rc_sid < 0 ) {
                                        Debug( LDAP_DEBUG_ANY, "%s: could not "
-                                               "extract SID from entryCSN=%s\n",
-                                               progname, attr->a_nvals[ 0 ].bv_val, 0 );
+                                               "extract SID from entryCSN=%s, entry dn=\"%s\"\n",
+                                               progname, attr->a_nvals[ 0 ].bv_val, e->e_name.bv_val );
 
                                } else {
                                        assert( rc_sid <= SLAP_SYNC_SID_MAX );
@@ -385,6 +425,9 @@ slapadd( int argc, char **argv )
                entry_free( e );
        }
 
+       if ( ldifrc < 0 )
+               rc = EXIT_FAILURE;
+
        bvtext.bv_len = textlen;
        bvtext.bv_val = textbuf;
        bvtext.bv_val[0] = '\0';