#define LDAPMOD_MAXLINE 4096
/* strings found in replog/LDIF entries (mostly lifted from slurpd/slurp.h) */
+#define T_VERSION_STR "version"
#define T_REPLICA_STR "replica"
#define T_DN_STR "dn"
#define T_CHANGETYPESTR "changetype"
static void usage LDAP_P(( const char *prog ));
static int process_ldapmod_rec LDAP_P(( char *rbuf ));
-static int process_ldif_rec LDAP_P(( char *rbuf ));
+static int process_ldif_rec LDAP_P(( char *rbuf, int count ));
static void addmodifyop LDAP_P(( LDAPMod ***pmodsp, int modop, char *attr,
char *value, int vlen ));
static int domodify LDAP_P(( char *dn, LDAPMod **pmods, int newentry ));
char *infile, *rbuf, *start, *p, *q;
FILE *fp;
int rc, i, use_ldif, authmethod, version, want_bindpw, debug, manageDSAit;
+ int count;
if (( prog = strrchr( argv[ 0 ], *LDAP_DIRSEP )) == NULL ) {
prog = argv[ 0 ];
}
}
+ count = 0;
while (( rc == 0 || contoper ) &&
( rbuf = read_one_record( fp )) != NULL ) {
+ count++;
/*
* we assume record is ldif/slapd.replog if the first line
* has a colon that appears to the left of any equal signs, OR
}
if ( use_ldif ) {
- rc = process_ldif_rec( start );
+ rc = process_ldif_rec( start, count );
} else {
rc = process_ldapmod_rec( start );
}
static int
-process_ldif_rec( char *rbuf )
+process_ldif_rec( char *rbuf, int count )
{
char *line, *dn, *type, *value, *newrdn, *newsup, *p;
int rc, linenum, modop, replicaport;
int expect_deleteoldrdn, deleteoldrdn;
int saw_replica, use_record, new_entry, delete_entry, got_all;
LDAPMod **pmods;
+ int version;
new_entry = new;
expect_deleteoldrdn = expect_newrdn = expect_newsup = 0;
expect_sep = expect_ct = 0;
linenum = 0;
+ version = 0;
deleteoldrdn = 1;
use_record = force;
pmods = NULL;
while ( rc == 0 && ( line = ldif_getline( &rbuf )) != NULL ) {
++linenum;
+
if ( expect_sep && strcasecmp( line, T_MODSEPSTR ) == 0 ) {
expect_sep = 0;
expect_ct = 1;
replicaport == ldapport ) {
use_record = 1;
}
+ } else if ( count == 1 && linenum == 1 &&
+ strcasecmp( type, T_VERSION_STR ) == 0 )
+ {
+ if( vlen == 0 || atoi(value) != 1 ) {
+ fprintf( stderr, "%s: invalid version %s, line %d (ignored)\n",
+ prog, value == NULL ? "(null)" : value, linenum );
+ }
+ version++;
+
} else if ( strcasecmp( type, T_DN_STR ) == 0 ) {
if (( dn = strdup( value )) == NULL ) {
perror( "strdup" );
return 0;
}
+ if( version && linenum == 1 ) {
+ return 0;
+ }
+
if ( rc == 0 ) {
if ( delete_entry ) {
rc = dodelete( dn );
# bjensen
$LDAPMODIFY -D "$JAJDN" -h localhost -p $PORT -w jaj > \
$TESTOUT 2>&1 << EOMODS1
+version: 1
dn: cn=ITD Staff, ou=Groups, o=University of Michigan, c=US
changetype: modify
add: member
$LDAPMODIFY -D "$JAJDN" -h localhost -p $PORT -w jaj >> \
$TESTOUT 2>&1 << EOMODS2
+version: 1
dn: cn=ITD Staff, ou=Groups, o=University of Michigan, c=US
changetype: modify
$LDAPMODIFY -D "$BJORNSDN" -h localhost -p $PORT -w bjorn >> \
$TESTOUT 2>&1 << EOMODS4
+# COMMENT
+version: 1
+# comment
dn: cn=ITD Staff, ou=Groups, o=University of Michigan, c=US
+# comment
changetype: modify
+# comment
add: telephonenumber
+# comment
telephonenumber: +1 810 555 1212
+# comment
EOMODS4
echo "Using ldapsearch to retrieve all the entries..."