Commit 17a975b6 authored by Kurt Zeilenga's avatar Kurt Zeilenga
Browse files

Very crude LDIF changes:

	add MODRDN newSuperior support
	add '#' support to ldapmodify (but not slurpd and ldbm tools)
parent 5695d590
......@@ -48,12 +48,15 @@ static LDAP *ld;
#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 ));
......@@ -293,9 +296,10 @@ main( int argc, char **argv )
* 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;
......@@ -335,9 +339,9 @@ main( int argc, char **argv )
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;
......@@ -345,12 +349,13 @@ process_ldif_rec( char *rbuf )
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;
......@@ -405,7 +410,10 @@ process_ldif_rec( char *rbuf )
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;
......@@ -458,12 +466,26 @@ process_ldif_rec( char *rbuf )
} 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",
......@@ -474,6 +496,10 @@ process_ldif_rec( char *rbuf )
}
}
if( linenum == 0 ) {
return 0;
}
if ( rc == 0 ) {
if ( delete_entry ) {
rc = dodelete( dn );
......@@ -856,25 +882,35 @@ fromfile( char *path, struct berval *bv )
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 );
......
......@@ -169,7 +169,7 @@ do_add( Connection *conn, Operation *op )
}
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 );
}
......
......@@ -96,7 +96,7 @@ do_delete(
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,
......
......@@ -204,7 +204,7 @@ do_modify(
}
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 */
......
......@@ -227,10 +227,13 @@ do_modrdn(
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,
......
......@@ -277,7 +277,7 @@ char * phonetic LDAP_P(( char *s ));
* 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
......
......@@ -18,15 +18,15 @@
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;
......@@ -48,7 +48,7 @@ replog(
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;
......@@ -109,10 +109,13 @@ replog(
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" );
......
......@@ -95,6 +95,12 @@ extern int slap_debug;
struct slap_op;
struct slap_conn;
struct replog_moddn {
char *newrdn;
int deloldrdn;
char *newsup;
};
/*
* represents an attribute value assertion (i.e., attr=value)
*/
......
......@@ -229,12 +229,13 @@ get_record(
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 );
}
......@@ -350,9 +350,12 @@ op_ldap_delete(
/*
* 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,
......@@ -367,6 +370,7 @@ op_ldap_modrdn(
int state = 0;
int drdnflag = -1;
char *newrdn;
char *newsup = NULL;
if ( re->re_mods == NULL ) {
*errmsg = "No arguments given";
......@@ -380,10 +384,27 @@ op_ldap_modrdn(
*/
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" )) {
......@@ -395,6 +416,19 @@ op_ldap_modrdn(
*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 );
......@@ -406,7 +440,7 @@ op_ldap_modrdn(
/*
* 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\"";
......@@ -429,7 +463,7 @@ op_ldap_modrdn(
#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 );
......
......@@ -89,6 +89,8 @@
#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"
......@@ -101,7 +103,8 @@
#define T_MODSEP 11
#define T_NEWRDNSTR "newrdn"
#define T_DRDNFLAGSTR "deleteoldrdn"
#define T_DELOLDRDNSTR "deleteoldrdn"
#define T_NEWSUPSTR "newsuperior"
#define T_ERR -1
......
......@@ -59,7 +59,7 @@ SEARCHFLT=$DBDIR/ldapsearch.flt
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
......
......@@ -33,7 +33,7 @@ done
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!"
......
......@@ -85,7 +85,6 @@ fi
kill -HUP $PID
TESTOUT=$SEARCHOUT
LDIF=$SEARCHOUTMASTER
echo "Filtering ldapsearch results..."
......
......@@ -45,12 +45,14 @@ if test $RC != 0 ; then
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
......@@ -102,6 +104,7 @@ homephone: +1 313 555 8844
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
......@@ -138,5 +141,4 @@ fi
echo ">>>>> Test succeeded"
exit 0
......@@ -46,14 +46,11 @@ if test $RC != 0 ; then
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
......@@ -63,8 +60,8 @@ 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
......
......@@ -65,7 +65,7 @@ $LDAPSEARCH -L -b "$JAJDN" -h localhost -p $PORT \
# 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
......@@ -73,13 +73,13 @@ member: cn=Barbara Jensen, ou=Information Technology Division, ou=People, o=Univ
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
#
......@@ -87,21 +87,21 @@ 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..."
......
......@@ -87,7 +87,7 @@ echo "Using ldapmodify to modify slave directory..."
#
$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
......
......@@ -105,7 +105,6 @@ fi
kill -HUP $PID $SLAVEPID
TESTOUT=$SEARCHOUT
LDIF=$SEARCHOUTMASTER
echo "Filtering ldapsearch results..."
......
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