Commit 07b73403 authored by Kurt Zeilenga's avatar Kurt Zeilenga
Browse files

Kludge ldapmodify to accept "version: 1" in LDIF input.

parent b73b0c61
......@@ -41,6 +41,7 @@ static LDAP *ld;
#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"
......@@ -61,7 +62,7 @@ static LDAP *ld;
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 ));
......@@ -102,6 +103,7 @@ main( int argc, char **argv )
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 ];
......@@ -289,8 +291,10 @@ main( int argc, char **argv )
}
}
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
......@@ -316,7 +320,7 @@ main( int argc, char **argv )
}
if ( use_ldif ) {
rc = process_ldif_rec( start );
rc = process_ldif_rec( start, count );
} else {
rc = process_ldapmod_rec( start );
}
......@@ -337,7 +341,7 @@ main( int argc, char **argv )
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;
......@@ -346,6 +350,7 @@ process_ldif_rec( char *rbuf )
int expect_deleteoldrdn, deleteoldrdn;
int saw_replica, use_record, new_entry, delete_entry, got_all;
LDAPMod **pmods;
int version;
new_entry = new;
......@@ -353,6 +358,7 @@ process_ldif_rec( char *rbuf )
expect_deleteoldrdn = expect_newrdn = expect_newsup = 0;
expect_sep = expect_ct = 0;
linenum = 0;
version = 0;
deleteoldrdn = 1;
use_record = force;
pmods = NULL;
......@@ -360,6 +366,7 @@ process_ldif_rec( char *rbuf )
while ( rc == 0 && ( line = ldif_getline( &rbuf )) != NULL ) {
++linenum;
if ( expect_sep && strcasecmp( line, T_MODSEPSTR ) == 0 ) {
expect_sep = 0;
expect_ct = 1;
......@@ -386,6 +393,15 @@ process_ldif_rec( char *rbuf )
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" );
......@@ -501,6 +517,10 @@ process_ldif_rec( char *rbuf )
return 0;
}
if( version && linenum == 1 ) {
return 0;
}
if ( rc == 0 ) {
if ( delete_entry ) {
rc = dodelete( dn );
......
......@@ -423,7 +423,7 @@ main( int argc, char **argv )
if ( ldif ) {
if (ldif < 3 ) {
/* TEMPORARILY put the version in a comment many tools cannot yet a version attribute */
printf( "# version: 1\n");
printf( "version: 1\n\n");
}
if (ldif < 2 ) {
......
......@@ -48,6 +48,7 @@ fi
echo "Testing modify, add, and delete..."
$LDAPMODIFY -v -D "$MANAGERDN" -h localhost -p $PORT -w $PASSWD > \
$TESTOUT 2>&1 << EOMODS
version: 1
# LEADING COMMENT AND WHITE SPACE
......@@ -59,6 +60,8 @@ drink: Orange Juice
dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, o=University of Michigan, c=US
changetype: modify
# EMBEDDED COMMENT
CONTINUED
replace: multilinedescription
multilinedescription: The replaced multiLineDescription $ Blah Woof.
-
......
......@@ -66,6 +66,7 @@ $LDAPSEARCH -b "$JAJDN" -h localhost -p $PORT \
# 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
......@@ -75,6 +76,7 @@ EOMODS1
$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
......@@ -98,10 +100,17 @@ EOMODS3
$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..."
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment