#define T_MODIFYCTSTR "modify"
#define T_DELETECTSTR "delete"
#define T_MODRDNCTSTR "modrdn"
+#define T_MODDNCTSTR "moddn"
+#define T_RENAMECTSTR "rename"
#define T_MODOPADDSTR "add"
#define T_MODOPREPLACESTR "replace"
#define T_MODOPDELETESTR "delete"
#define T_MODSEPSTR "-"
#define T_NEWRDNSTR "newrdn"
#define T_DELETEOLDRDNSTR "deleteoldrdn"
+#define T_NEWSUPSTR "newsuperior"
static void usage LDAP_P(( const char *prog ));
* has a colon that appears to the left of any equal signs, OR
* if the first line consists entirely of digits (an entry id)
*/
- use_ldif = ( p = strchr( rbuf, ':' )) != NULL &&
- ( q = strchr( rbuf, '\n' )) != NULL && p < q &&
- (( q = strchr( rbuf, '=' )) == NULL || p < q );
+ use_ldif = ( *rbuf == '#' ) ||
+ (( p = strchr( rbuf, ':' )) != NULL &&
+ ( q = strchr( rbuf, '\n' )) != NULL && p < q &&
+ (( q = strchr( rbuf, '=' )) == NULL || p < q ));
start = rbuf;
static int
process_ldif_rec( char *rbuf )
{
- char *line, *dn, *type, *value, *newrdn, *p;
+ char *line, *dn, *type, *value, *newrdn, *newsup, *p;
int rc, linenum, vlen, modop, replicaport;
- int expect_modop, expect_sep, expect_ct, expect_newrdn;
+ int expect_modop, expect_sep, expect_ct, expect_newrdn, expect_newsup;
int expect_deleteoldrdn, deleteoldrdn;
int saw_replica, use_record, new_entry, delete_entry, got_all;
LDAPMod **pmods;
new_entry = new;
rc = got_all = saw_replica = delete_entry = expect_modop = 0;
- expect_deleteoldrdn = expect_newrdn = expect_sep = expect_ct = 0;
+ expect_deleteoldrdn = expect_newrdn = expect_newsup = 0;
+ expect_sep = expect_ct = 0;
linenum = 0;
deleteoldrdn = 1;
use_record = force;
pmods = NULL;
- dn = newrdn = NULL;
+ dn = newrdn = newsup = NULL;
while ( rc == 0 && ( line = ldif_getline( &rbuf )) != NULL ) {
++linenum;
expect_modop = 1;
} else if ( strcasecmp( value, T_ADDCTSTR ) == 0 ) {
new_entry = 1;
- } else if ( strcasecmp( value, T_MODRDNCTSTR ) == 0 ) {
+ } else if ( strcasecmp( value, T_MODRDNCTSTR ) == 0
+ || strcasecmp( value, T_MODDNCTSTR ) == 0
+ || strcasecmp( value, T_RENAMECTSTR ) == 0)
+ {
expect_newrdn = 1;
} else if ( strcasecmp( value, T_DELETECTSTR ) == 0 ) {
got_all = delete_entry = 1;
} else if ( expect_deleteoldrdn ) {
if ( strcasecmp( type, T_DELETEOLDRDNSTR ) == 0 ) {
deleteoldrdn = ( *value == '0' ) ? 0 : 1;
+ expect_deleteoldrdn = 0;
+ expect_newsup = 1;
got_all = 1;
} else {
fprintf( stderr, "%s: expecting \"%s:\" but saw \"%s:\" (line %d of entry %s)\n",
prog, T_DELETEOLDRDNSTR, type, linenum, dn );
rc = LDAP_PARAM_ERROR;
}
+ } else if ( expect_newsup ) {
+ if ( strcasecmp( type, T_NEWSUPSTR ) == 0 ) {
+ if (( newsup = strdup( value )) == NULL ) {
+ perror( "strdup" );
+ exit( 1 );
+ }
+ expect_newsup = 0;
+ } else {
+ fprintf( stderr, "%s: expecting \"%s:\" but saw \"%s:\" (line %d of entry %s)\n",
+ prog, T_NEWSUPSTR, type, linenum, dn );
+ rc = LDAP_PARAM_ERROR;
+ }
} else if ( got_all ) {
fprintf( stderr,
"%s: extra lines at end (line %d of entry %s)\n",
}
}
+ if( linenum == 0 ) {
+ return 0;
+ }
+
if ( rc == 0 ) {
if ( delete_entry ) {
rc = dodelete( dn );
static char *
read_one_record( FILE *fp )
{
- int len;
char *buf, line[ LDAPMOD_MAXLINE ];
int lcur, lmax;
lcur = lmax = 0;
buf = NULL;
- while (( fgets( line, sizeof(line), fp ) != NULL ) &&
- (( len = strlen( line )) > 1 )) {
- if ( lcur + len + 1 > lmax ) {
- lmax = LDAPMOD_MAXLINE
- * (( lcur + len + 1 ) / LDAPMOD_MAXLINE + 1 );
- if (( buf = (char *)realloc( buf, lmax )) == NULL ) {
- perror( "realloc" );
- exit( 1 );
- }
- }
- strcpy( buf + lcur, line );
- lcur += len;
+ while ( fgets( line, sizeof(line), fp ) != NULL ) {
+ int len = strlen( line );
+
+ if( len < 2 ) {
+ if( buf == NULL ) {
+ continue;
+ } else {
+ break;
+ }
+ }
+
+ if ( lcur + len + 1 > lmax ) {
+ lmax = LDAPMOD_MAXLINE
+ * (( lcur + len + 1 ) / LDAPMOD_MAXLINE + 1 );
+
+ if (( buf = (char *)realloc( buf, lmax )) == NULL ) {
+ perror( "realloc" );
+ exit( 1 );
+ }
+ }
+
+ strcpy( buf + lcur, line );
+ lcur += len;
}
return( buf );
}
if ( (*be->be_add)( be, conn, op, e ) == 0 ) {
- replog( be, LDAP_REQ_ADD, e->e_dn, e, 0 );
+ replog( be, op, e->e_dn, e );
be_entry_release_w( be, e );
}
strcmp( be->be_update_ndn, op->o_ndn ) == 0 )
{
if ( (*be->be_delete)( be, conn, op, ndn ) == 0 ) {
- replog( be, LDAP_REQ_DELETE, ndn, NULL, 0 );
+ replog( be, op, ndn, NULL );
}
} else {
send_ldap_result( conn, op, rc = LDAP_REFERRAL, NULL, NULL,
}
if ( (*be->be_modify)( be, conn, op, ndn, modlist ) == 0 ) {
- replog( be, LDAP_REQ_MODIFY, ndn, modlist, 0 );
+ replog( be, op, ndn, modlist );
}
/* send a referral */
strcmp( be->be_update_ndn, op->o_ndn ) == 0 )
{
if ( (*be->be_modrdn)( be, conn, op, ndn, newrdn,
- deloldrdn, newSuperior ) == 0 ) {
- /* XXX: MAY NEED TO ADD newSuperior HERE */
- replog( be, LDAP_REQ_MODRDN, ndn, newrdn,
- deloldrdn );
+ deloldrdn, newSuperior ) == 0 )
+ {
+ struct replog_moddn moddn;
+ moddn.newrdn = newrdn;
+ moddn.deloldrdn = deloldrdn;
+ moddn.newsup = newSuperior;
+ replog( be, op, ndn, &moddn );
}
} else {
send_ldap_result( conn, op, rc = LDAP_REFERRAL, NULL, NULL,
* repl.c
*/
-void replog LDAP_P(( Backend *be, int optype, char *dn, void *change, int flag ));
+void replog LDAP_P(( Backend *be, Operation *op, char *dn, void *change ));
/*
* result.c
void
replog(
Backend *be,
- int optype,
+ Operation *op,
char *dn,
- void *change,
- int flag
+ void *change
)
{
LDAPModList *ml;
Entry *e;
- char *newrdn, *tmp;
+ struct replog_moddn *moddn;
+ char *tmp;
FILE *fp, *lfp;
int len, i;
fprintf( fp, "time: %ld\n", (long) slap_get_time() );
fprintf( fp, "dn: %s\n", dn );
- switch ( optype ) {
+ switch ( op->o_tag ) {
case LDAP_REQ_MODIFY:
fprintf( fp, "changetype: modify\n" );
ml = change;
break;
case LDAP_REQ_MODRDN:
- newrdn = change;
+ moddn = change;
fprintf( fp, "changetype: modrdn\n" );
- fprintf( fp, "newrdn: %s\n", newrdn );
- fprintf( fp, "deleteoldrdn: %d\n", flag ? 1 : 0 );
+ fprintf( fp, "newrdn: %s\n", moddn->newrdn );
+ fprintf( fp, "deleteoldrdn: %d\n", moddn->deloldrdn ? 1 : 0 );
+ if( moddn->newsup != NULL ) {
+ fprintf( fp, "newsuperior: %s\n", moddn->newsup );
+ }
}
fprintf( fp, "\n" );
struct slap_op;
struct slap_conn;
+struct replog_moddn {
+ char *newrdn;
+ int deloldrdn;
+ char *newsup;
+};
+
/*
* represents an attribute value assertion (i.e., attr=value)
*/
while (( fgets( line, sizeof(line), fp ) != NULL ) &&
(( len = strlen( line )) > 1 )) {
- while ( lcur + len + 1 > lmax ) {
- lmax += BUFSIZ;
- buf = (char *) ch_realloc( buf, lmax );
- }
- strcpy( buf + lcur, line );
- lcur += len;
+
+ while ( lcur + len + 1 > lmax ) {
+ lmax += BUFSIZ;
+ buf = (char *) ch_realloc( buf, lmax );
+ }
+ strcpy( buf + lcur, line );
+ lcur += len;
}
return( buf );
}
/*
* Perform an ldap modrdn operation.
*/
-#define GOT_NEWRDN 1
-#define GOT_DRDNFLAGSTR 2
-#define GOT_ALLNEWRDNFLAGS ( GOT_NEWRDN | GOT_DRDNFLAGSTR )
+#define GOT_NEWRDN 0x1
+#define GOT_DELOLDRDN 0x2
+#define GOT_NEWSUP 0x4
+
+#define GOT_MODDN_REQ (GOT_NEWRDN|GOT_DELOLDRDN)
+#define GOT_ALL_MODDN(f) (((f) & GOT_MODDN_REQ) == GOT_MODDN_REQ)
static int
op_ldap_modrdn(
Ri *ri,
int state = 0;
int drdnflag = -1;
char *newrdn;
+ char *newsup = NULL;
if ( re->re_mods == NULL ) {
*errmsg = "No arguments given";
*/
for ( mi = re->re_mods, i = 0; mi[ i ].mi_type != NULL; i++ ) {
if ( !strcmp( mi[ i ].mi_type, T_NEWRDNSTR )) {
+ if( state & GOT_NEWRDN ) {
+ Debug( LDAP_DEBUG_ANY,
+ "Error: op_ldap_modrdn: multiple newrdn arg \"%s\"\n",
+ mi[ i ].mi_val, 0, 0 );
+ *errmsg = "Multiple newrdn argument";
+ return -1;
+ }
+
newrdn = mi[ i ].mi_val;
state |= GOT_NEWRDN;
- } else if ( !strcmp( mi[ i ].mi_type, T_DRDNFLAGSTR )) {
- state |= GOT_DRDNFLAGSTR;
+
+ } else if ( !strcmp( mi[ i ].mi_type, T_DELOLDRDNSTR )) {
+ if( state & GOT_DELOLDRDN ) {
+ Debug( LDAP_DEBUG_ANY,
+ "Error: op_ldap_modrdn: multiple deleteoldrdn arg \"%s\"\n",
+ mi[ i ].mi_val, 0, 0 );
+ *errmsg = "Multiple newrdn argument";
+ return -1;
+ }
+
+ state |= GOT_DELOLDRDN;
if ( !strcmp( mi[ i ].mi_val, "0" )) {
drdnflag = 0;
} else if ( !strcmp( mi[ i ].mi_val, "1" )) {
*errmsg = "Incorrect argument to deleteoldrdn";
return -1;
}
+
+ } else if ( !strcmp( mi[ i ].mi_type, T_NEWSUPSTR )) {
+ if( state & GOT_NEWSUP ) {
+ Debug( LDAP_DEBUG_ANY,
+ "Error: op_ldap_modrdn: multiple newsuperior arg \"%s\"\n",
+ mi[ i ].mi_val, 0, 0 );
+ *errmsg = "Multiple newrdn argument";
+ return -1;
+ }
+
+ newrdn = mi[ i ].mi_val;
+ state |= GOT_NEWSUP;
+
} else {
Debug( LDAP_DEBUG_ANY, "Error: op_ldap_modrdn: bad type \"%s\"\n",
mi[ i ].mi_type, 0, 0 );
/*
* Punt if we don't have all the args.
*/
- if ( state != GOT_ALLNEWRDNFLAGS ) {
+ if ( GOT_ALL_MODDN(state) ) {
Debug( LDAP_DEBUG_ANY, "Error: op_ldap_modrdn: missing arguments\n",
0, 0, 0 );
*errmsg = "Missing argument: requires \"newrdn\" and \"deleteoldrdn\"";
#endif /* LDAP_DEBUG */
/* Do the modrdn */
- rc = ldap_modrdn2_s( ri->ri_ldp, re->re_dn, mi->mi_val, drdnflag );
+ rc = ldap_rename2_s( ri->ri_ldp, re->re_dn, mi->mi_val, drdnflag, newsup );
ldap_get_option( ri->ri_ldp, LDAP_OPT_ERROR_NUMBER, &lderr);
return( lderr );
#define T_DELETECTSTR "delete"
#define T_DELETECT 6
#define T_MODRDNCTSTR "modrdn"
+#define T_MODDNCTSTR "moddn"
+#define T_RENAMECTSTR "rename"
#define T_MODRDNCT 7
#define T_MODOPADDSTR "add"
#define T_MODSEP 11
#define T_NEWRDNSTR "newrdn"
-#define T_DRDNFLAGSTR "deleteoldrdn"
+#define T_DELOLDRDNSTR "deleteoldrdn"
+#define T_NEWSUPSTR "newsuperior"
#define T_ERR -1
LDIFFLT=$DBDIR/ldif.flt
MASTEROUT=$DBDIR/master.out
SLAVEOUT=$DBDIR/slave.out
-TESTOUT=$DBDIR/ldapsearch.out
+TESTOUT=$DBDIR/test.out
SEARCHOUTMASTER=$DATADIR/search.out.master
MODIFYOUTMASTER=$DATADIR/modify.out.master
ADDDELOUTMASTER=$DATADIR/adddel.out.master
echo "Using ldapadd to populate the database..."
$LDAPADD -D "$MANAGERDN" -h localhost -p $PORT -w $PASSWD < \
- $LDIFORDERED > /dev/null 2>&1
+ $LDIFORDERED > $TESTOUT 2>&1
RC=$?
if test $RC != 0 ; then
echo "ldapadd failed!"
kill -HUP $PID
-TESTOUT=$SEARCHOUT
LDIF=$SEARCHOUTMASTER
echo "Filtering ldapsearch results..."
exit $RC
fi
-cat /dev/null > $TESTOUT
-
echo "Testing modify, add, and delete..."
$LDAPMODIFY -v -D "$MANAGERDN" -h localhost -p $PORT -w $PASSWD > \
- /dev/null 2>&1 << EOMODS
+ $TESTOUT 2>&1 << EOMODS
+
+# LEADING COMMENT AND WHITE SPACE
+
dn: cn=James A Jones 1, ou=Alumni Association, ou=People, o=University of Michigan, c=US
+# EMBEDDED COMMENT
changetype: modify
add: drink
drink: Orange Juice
dn: cn=James A Jones 2, ou=Information Technology Division, ou=People, o=University of Michigan, c=US
changetype: delete
+# TRAILING COMMENT AND WHITE SPACE
EOMODS
echo ">>>>> Test succeeded"
-
exit 0
exit $RC
fi
-cat /dev/null > $TESTOUT
-
-
# -r used to do remove of old rdn
echo "Testing modrdn(deleteoldrdn=0)..."
$LDAPMODRDN -v -D "$MANAGERDN" -h localhost -p $PORT -w $PASSWD > \
- /dev/null 2>&1 'cn=James A Jones 1, ou=Alumni Association, ou=People, o=University of Michigan, c=US' 'cn=James A Jones III'
+ $TESTOUT 2>&1 'cn=James A Jones 1, ou=Alumni Association, ou=People, o=University of Michigan, c=US' 'cn=James A Jones III'
RC=$?
if test $RC != 0 ; then
fi
echo "Testing modrdn(deleteoldrdn=1)..."
-$LDAPMODRDN -v -D "$MANAGERDN" -r -h localhost -p $PORT -w $PASSWD > \
- /dev/null 2>&1 'cn=James A Jones 2, ou=Information Technology Division, ou=People, o=University of Michigan, c=US' 'cn=James A Jones II'
+$LDAPMODRDN -v -D "$MANAGERDN" -r -h localhost -p $PORT -w $PASSWD >> \
+ $TESTOUT 2>&1 'cn=James A Jones 2, ou=Information Technology Division, ou=People, o=University of Michigan, c=US' 'cn=James A Jones II'
RC=$?
if test $RC != 0 ; then
# we add our own DN.
# bjensen
$LDAPMODIFY -D "$JAJDN" -h localhost -p $PORT -w jaj > \
- /dev/null 2>&1 << EOMODS1
+ $TESTOUT 2>&1 << EOMODS1
dn: cn=ITD Staff, ou=Groups, o=University of Michigan, c=US
changetype: modify
add: member
EOMODS1
-$LDAPMODIFY -D "$JAJDN" -h localhost -p $PORT -w jaj > \
- /dev/null 2>&1 << EOMODS2
+$LDAPMODIFY -D "$JAJDN" -h localhost -p $PORT -w jaj >> \
+ $TESTOUT 2>&1 << EOMODS2
+
dn: cn=ITD Staff, ou=Groups, o=University of Michigan, c=US
changetype: modify
add: member
member: cn=James A Jones 1, ou=Alumni Association, ou=People, o=University of Michigan, c=US
-
EOMODS2
#
# 1) bound as "James A Jones 1" - should fail
# 2) bound as "Barbara Jensen" - should succeed
#
-$LDAPMODIFY -D "$JAJDN" -h localhost -p $PORT -w jaj > \
- /dev/null 2>&1 << EOMODS3
+$LDAPMODIFY -D "$JAJDN" -h localhost -p $PORT -w jaj >> \
+ $TESTOUT 2>&1 << EOMODS3
+
dn: cn=ITD Staff, ou=Groups, o=University of Michigan, c=US
changetype: modify
delete: member
EOMODS3
-$LDAPMODIFY -D "$BJORNSDN" -h localhost -p $PORT -w bjorn > \
- /dev/null 2>&1 << EOMODS4
+$LDAPMODIFY -D "$BJORNSDN" -h localhost -p $PORT -w bjorn >> \
+ $TESTOUT 2>&1 << EOMODS4
dn: cn=ITD Staff, ou=Groups, o=University of Michigan, c=US
changetype: modify
add: telephonenumber
telephonenumber: +1 810 555 1212
-
EOMODS4
echo "Using ldapsearch to retrieve all the entries..."
#
$LDAPMODIFY -v -D "$MANAGERDN" -h localhost -p $SLAVEPORT -w $PASSWD > \
- /dev/null 2>&1 << EOMODS
+ $TESTOUT 2>&1 << EOMODS
dn: cn=James A Jones 1, ou=Alumni Association, ou=People, o=University of Michigan, c=US
changetype: modify
add: drink
kill -HUP $PID $SLAVEPID
-TESTOUT=$SEARCHOUT
LDIF=$SEARCHOUTMASTER
echo "Filtering ldapsearch results..."