Start of client-side LDAP tranactions (non-working)

and lots of cleanup (hence the commit)
(ldapmodify will need much more work for transactions)
This commit is contained in:
Kurt Zeilenga 2004-03-14 23:32:00 +00:00
parent f1f1b0f69b
commit 647df2b9cb
10 changed files with 794 additions and 544 deletions

View File

@ -116,33 +116,46 @@ static int dorename LDAP_P((
LDAPControl **pctrls )); LDAPControl **pctrls ));
static char *read_one_record LDAP_P(( FILE *fp )); static char *read_one_record LDAP_P(( FILE *fp ));
#ifdef LDAP_GROUP_TRANSACTION
static int txn = 0;
static int txnabort = 0;
#endif
void void
usage( void ) usage( void )
{ {
fprintf( stderr, _("Add or modify entries from an LDAP server\n\n")); fprintf( stderr, _("Add or modify entries from an LDAP server\n\n"));
fprintf( stderr, _("usage: %s [options]\n"), prog); fprintf( stderr, _("usage: %s [options]\n"), prog);
fprintf( stderr, _(" The list of desired operations are read from stdin or from the file\n")); fprintf( stderr, _(" The list of desired operations are read from stdin"
" or from the file\n"));
fprintf( stderr, _(" specified by \"-f file\".\n")); fprintf( stderr, _(" specified by \"-f file\".\n"));
fprintf( stderr, _("Add or modify options:\n")); fprintf( stderr, _("Add or modify options:\n"));
fprintf( stderr, _(" -a add values (%s)\n"), fprintf( stderr, _(" -a add values (%s)\n"),
(ldapadd ? _("default") : _("default is to replace"))); (ldapadd ? _("default") : _("default is to replace")));
fprintf( stderr, _(" -E [!]ext=extparam modify extensions"
" (! indicate s criticality)\n"));
#ifdef LDAP_GROUP_TRANSACTION
fprintf( stderr,
_(" [!]txn (transaction)\n"));
#endif
fprintf( stderr, _(" -F force all changes records to be used\n")); fprintf( stderr, _(" -F force all changes records to be used\n"));
fprintf( stderr, _(" -S file write skipped modifications to `file'\n")); fprintf( stderr, _(" -S file write skipped modifications to `file'\n"));
tool_common_usage(); tool_common_usage();
exit( EXIT_FAILURE ); exit( EXIT_FAILURE );
} }
const char options[] = "aFrS:" const char options[] = "aE:FrS:"
"cd:D:e:f:h:H:IkKMnO:p:P:QR:U:vVw:WxX:y:Y:Z"; "cd:D:e:f:h:H:IkKMnO:p:P:QR:U:vVw:WxX:y:Y:Z";
int int
handle_private_option( int i ) handle_private_option( int i )
{ {
switch ( i ) {
#if 0
char *control, *cvalue; char *control, *cvalue;
int crit; int crit;
switch ( i ) {
case 'E': /* modify extensions */ case 'E': /* modify extensions */
if( protocol == LDAP_VERSION2 ) { if( protocol == LDAP_VERSION2 ) {
fprintf( stderr, _("%s: -E incompatible with LDAPv%d\n"), fprintf( stderr, _("%s: -E incompatible with LDAPv%d\n"),
@ -166,9 +179,32 @@ handle_private_option( int i )
*cvalue++ = '\0'; *cvalue++ = '\0';
} }
fprintf( stderr, _("Invalid modify extension name: %s\n"), control ); #ifdef LDAP_GROUP_TRANSACTION
usage(); if( strcasecmp( control, "txn" ) == 0 ) {
/* Transaction */
if( txn ) {
fprintf( stderr,
_("txn control previously specified\n"));
exit( EXIT_FAILURE );
}
if( cvalue != NULL ) {
if( strcasecmp( cvalue, "abort" ) == 0 ) {
txnabort=1;
} else if( strcasecmp( cvalue, "commit" ) != 0 ) {
fprintf( stderr, _("Invalid value for txn control, %s\n"),
cvalue );
exit( EXIT_FAILURE );
}
}
txn = 1 + crit;
} else
#endif #endif
{
fprintf( stderr, _("Invalid modify extension name: %s\n"),
control );
usage();
}
case 'a': /* add */ case 'a': /* add */
ldapadd = 1; ldapadd = 1;
@ -199,6 +235,10 @@ handle_private_option( int i )
int int
main( int argc, char **argv ) main( int argc, char **argv )
{ {
#ifdef LDAP_GROUP_TRANSACTION
BerElement *txnber;
struct berval txnCookie = { 0, NULL };
#endif
char *rbuf, *start, *rejbuf = NULL; char *rbuf, *start, *rejbuf = NULL;
FILE *fp, *rejfp; FILE *fp, *rejfp;
char *matched_msg, *error_msg; char *matched_msg, *error_msg;
@ -250,12 +290,55 @@ main( int argc, char **argv )
tool_bind( ld ); tool_bind( ld );
} }
rc = 0; #ifdef LDAP_GROUP_TRANSACTION
if( txn ) {
struct berval *txnCookiep = &txnCookie;
if ( assertion || authzid || manageDSAit || noop || preread || postread ) { /* create transaction */
tool_server_controls( ld, NULL, 0 ); rc = ldap_txn_create_s( ld, &txnCookiep, NULL, NULL );
if( rc != LDAP_SUCCESS ) {
ldap_perror( ld, "ldap_txn_create_s" );
if( txn > 2 ) return EXIT_FAILURE;
txn = 0;
}
}
#endif
if ( assertion || authzid || manageDSAit || noop || preread || postread
#ifdef LDAP_GROUP_TRANSACTION
|| txn
#endif
)
{
int err;
int i;
LDAPControl c[1];
#ifdef LDAP_GROUP_TRANSACTION
if( txn ) {
txnber = ber_alloc_t( LBER_USE_DER );
if( txnber == NULL ) return EXIT_FAILURE;
err = ber_printf( txnber, "{o}", &txnCookie );
if( err == -1 ) {
ber_free( txnber, 1 );
fprintf( stderr, _("txn grouping control encoding error!\n") );
return EXIT_FAILURE;
} }
err = ber_flatten2( txnber, &c[i].ldctl_value, 0 );
if( err == -1 ) return EXIT_FAILURE;
c[i].ldctl_oid = LDAP_CONTROL_GROUPING;
c[i].ldctl_iscritical = 1;
i++;
}
#endif
tool_server_controls( ld, c, i );
}
rc = 0;
count = 0; count = 0;
retval = 0; retval = 0;
while (( rc == 0 || contoper ) && while (( rc == 0 || contoper ) &&
@ -304,6 +387,18 @@ main( int argc, char **argv )
free( rbuf ); free( rbuf );
} }
#ifdef LDAP_GROUP_TRANSACTION
if( txn ) {
/* create transaction */
rc = ldap_txn_end_s( ld, &txnCookie, !txnabort, NULL, NULL );
if( rc != LDAP_SUCCESS ) {
ldap_perror( ld, "ldap_txn_create_s" );
if( txn > 2 ) return EXIT_FAILURE;
txn = 0;
}
}
#endif
if ( !not ) { if ( !not ) {
ldap_unbind_ext( ld, NULL, NULL ); ldap_unbind_ext( ld, NULL, NULL );
} }
@ -367,15 +462,18 @@ process_ldif_rec( char *rbuf, int count )
*p++ = '\0'; *p++ = '\0';
replicaport = atoi( p ); replicaport = atoi( p );
} }
if ( ldaphost != NULL && strcasecmp( val.bv_val, ldaphost ) == 0 && if ( ldaphost != NULL &&
replicaport == ldapport ) { strcasecmp( val.bv_val, ldaphost ) == 0 &&
replicaport == ldapport )
{
use_record = 1; use_record = 1;
} }
} else if ( count == 1 && linenum == 1 && } else if ( count == 1 && linenum == 1 &&
strcasecmp( type, T_VERSION_STR ) == 0 ) strcasecmp( type, T_VERSION_STR ) == 0 )
{ {
if( val.bv_len == 0 || atoi(val.bv_val) != 1 ) { if( val.bv_len == 0 || atoi(val.bv_val) != 1 ) {
fprintf( stderr, _("%s: invalid version %s, line %d (ignored)\n"), fprintf( stderr,
_("%s: invalid version %s, line %d (ignored)\n"),
prog, val.bv_val, linenum ); prog, val.bv_val, linenum );
} }
version++; version++;
@ -391,13 +489,13 @@ process_ldif_rec( char *rbuf, int count )
} }
if ( expect_ct ) { if ( expect_ct ) {
/* Check for "control" tag after dn and before changetype. */ /* Check for "control" tag after dn and before changetype. */
if (strcasecmp(type, T_CONTROL_STR) == 0) { if (strcasecmp(type, T_CONTROL_STR) == 0) {
/* Parse and add it to the list of controls */ /* Parse and add it to the list of controls */
rc = parse_ldif_control( line, &pctrls ); rc = parse_ldif_control( line, &pctrls );
if (rc != 0) { if (rc != 0) {
fprintf( stderr, _("%s: Error processing %s line, line %d: %s\n"), fprintf( stderr,
_("%s: Error processing %s line, line %d: %s\n"),
prog, T_CONTROL_STR, linenum, ldap_err2string(rc) ); prog, T_CONTROL_STR, linenum, ldap_err2string(rc) );
} }
goto end_line; goto end_line;
@ -405,7 +503,8 @@ process_ldif_rec( char *rbuf, int count )
expect_ct = 0; expect_ct = 0;
if ( !use_record && saw_replica ) { if ( !use_record && saw_replica ) {
printf(_("%s: skipping change record for entry: %s\n"), prog, dn); printf(_("%s: skipping change record for entry: %s\n"),
prog, dn);
printf(_("\t(LDAP host/port does not match replica: lines)\n")); printf(_("\t(LDAP host/port does not match replica: lines)\n"));
free( dn ); free( dn );
ber_memfree( type ); ber_memfree( type );
@ -416,7 +515,6 @@ process_ldif_rec( char *rbuf, int count )
if ( strcasecmp( type, T_CHANGETYPESTR ) == 0 ) { if ( strcasecmp( type, T_CHANGETYPESTR ) == 0 ) {
#ifdef LIBERAL_CHANGETYPE_MODOP #ifdef LIBERAL_CHANGETYPE_MODOP
/* trim trailing spaces (and log warning ...) */ /* trim trailing spaces (and log warning ...) */
int icnt; int icnt;
for ( icnt = val.bv_len; --icnt > 0; ) { for ( icnt = val.bv_len; --icnt > 0; ) {
if ( !isspace( (unsigned char) val.bv_val[icnt] ) ) { if ( !isspace( (unsigned char) val.bv_val[icnt] ) ) {
@ -425,7 +523,8 @@ process_ldif_rec( char *rbuf, int count )
} }
if ( ++icnt != val.bv_len ) { if ( ++icnt != val.bv_len ) {
fprintf( stderr, _("%s: illegal trailing space after \"%s: %s\" trimmed (line %d of entry \"%s\")\n"), fprintf( stderr, _("%s: illegal trailing space after"
" \"%s: %s\" trimmed (line %d of entry \"%s\")\n"),
prog, T_CHANGETYPESTR, val.bv_val, linenum, dn ); prog, T_CHANGETYPESTR, val.bv_val, linenum, dn );
val.bv_val[icnt] = '\0'; val.bv_val[icnt] = '\0';
} }
@ -461,16 +560,14 @@ process_ldif_rec( char *rbuf, int count )
if ( expect_modop ) { if ( expect_modop ) {
#ifdef LIBERAL_CHANGETYPE_MODOP #ifdef LIBERAL_CHANGETYPE_MODOP
/* trim trailing spaces (and log warning ...) */ /* trim trailing spaces (and log warning ...) */
int icnt; int icnt;
for ( icnt = val.bv_len; --icnt > 0; ) { for ( icnt = val.bv_len; --icnt > 0; ) {
if ( !isspace( (unsigned char) val.bv_val[icnt] ) ) { if ( !isspace( (unsigned char) val.bv_val[icnt] ) ) break;
break;
}
} }
if ( ++icnt != val.bv_len ) { if ( ++icnt != val.bv_len ) {
fprintf( stderr, _("%s: illegal trailing space after \"%s: %s\" trimmed (line %d of entry \"%s\")\n"), fprintf( stderr, _("%s: illegal trailing space after"
" \"%s: %s\" trimmed (line %d of entry \"%s\")\n"),
prog, type, val.bv_val, linenum, dn ); prog, type, val.bv_val, linenum, dn );
val.bv_val[icnt] = '\0'; val.bv_val[icnt] = '\0';
} }
@ -507,7 +604,8 @@ process_ldif_rec( char *rbuf, int count )
expect_deleteoldrdn = 1; expect_deleteoldrdn = 1;
expect_newrdn = 0; expect_newrdn = 0;
} else { } else {
fprintf( stderr, _("%s: expecting \"%s:\" but saw \"%s:\" (line %d of entry \"%s\")\n"), fprintf( stderr, _("%s: expecting \"%s:\" but saw"
" \"%s:\" (line %d of entry \"%s\")\n"),
prog, T_NEWRDNSTR, type, linenum, dn ); prog, T_NEWRDNSTR, type, linenum, dn );
rc = LDAP_PARAM_ERROR; rc = LDAP_PARAM_ERROR;
} }
@ -518,7 +616,8 @@ process_ldif_rec( char *rbuf, int count )
expect_newsup = 1; expect_newsup = 1;
got_all = 1; got_all = 1;
} else { } else {
fprintf( stderr, _("%s: expecting \"%s:\" but saw \"%s:\" (line %d of entry \"%s\")\n"), fprintf( stderr, _("%s: expecting \"%s:\" but saw"
" \"%s:\" (line %d of entry \"%s\")\n"),
prog, T_DELETEOLDRDNSTR, type, linenum, dn ); prog, T_DELETEOLDRDNSTR, type, linenum, dn );
rc = LDAP_PARAM_ERROR; rc = LDAP_PARAM_ERROR;
} }
@ -530,7 +629,8 @@ process_ldif_rec( char *rbuf, int count )
} }
expect_newsup = 0; expect_newsup = 0;
} else { } else {
fprintf( stderr, _("%s: expecting \"%s:\" but saw \"%s:\" (line %d of entry \"%s\")\n"), fprintf( stderr, _("%s: expecting \"%s:\" but saw"
" \"%s:\" (line %d of entry \"%s\")\n"),
prog, T_NEWSUPSTR, type, linenum, dn ); prog, T_NEWSUPSTR, type, linenum, dn );
rc = LDAP_PARAM_ERROR; rc = LDAP_PARAM_ERROR;
} }
@ -566,16 +666,16 @@ end_line:
LDAPControl **newctrls = NULL; LDAPControl **newctrls = NULL;
ldap_get_option(ld, LDAP_OPT_SERVER_CONTROLS, &defctrls); ldap_get_option(ld, LDAP_OPT_SERVER_CONTROLS, &defctrls);
if (defctrls) { if (defctrls) {
int npc=0; /* Number of LDIF controls */ int npc=0; /* Num of LDIF controls */
int ndefc=0; /* Number of default controls */ int ndefc=0; /* Num of default controls */
while (pctrls[npc]) /* Count LDIF controls */ while (pctrls[npc]) npc++; /* Count LDIF controls */
npc++; while (defctrls[ndefc]) ndefc++; /* Count default controls */
while (defctrls[ndefc]) /* Count default controls */ newctrls = ber_memrealloc(pctrls,
ndefc++; (npc+ndefc+1)*sizeof(LDAPControl*));
newctrls = ber_memrealloc(pctrls, (npc+ndefc+1)*sizeof(LDAPControl*));
if (newctrls == NULL) if (newctrls == NULL) {
rc = LDAP_NO_MEMORY; rc = LDAP_NO_MEMORY;
else { } else {
int i; int i;
pctrls = newctrls; pctrls = newctrls;
for (i=npc; i<npc+ndefc; i++) { for (i=npc; i<npc+ndefc; i++) {
@ -616,7 +716,6 @@ end_line:
if ( pmods != NULL ) { if ( pmods != NULL ) {
ldap_mods_free( pmods, 1 ); ldap_mods_free( pmods, 1 );
} }
if (pctrls != NULL) { if (pctrls != NULL) {
ldap_controls_free( pctrls ); ldap_controls_free( pctrls );
} }
@ -631,7 +730,8 @@ end_line:
The control is added to the list of controls in *ppctrls. The control is added to the list of controls in *ppctrls.
*/ */
static int static int
parse_ldif_control( char *line, parse_ldif_control(
char *line,
LDAPControl ***ppctrls ) LDAPControl ***ppctrls )
{ {
char *oid = NULL; char *oid = NULL;
@ -644,38 +744,39 @@ parse_ldif_control( char *line,
LDAPControl *newctrl = NULL; LDAPControl *newctrl = NULL;
LDAPControl **pctrls = NULL; LDAPControl **pctrls = NULL;
if (ppctrls) { if (ppctrls) pctrls = *ppctrls;
pctrls = *ppctrls;
}
s = line + strlen(T_CONTROL_STR); /* Skip over "control" */ s = line + strlen(T_CONTROL_STR); /* Skip over "control" */
pcolon = s; /* Save this position for later */ pcolon = s; /* Save this position for later */
if (*s++ != ':') /* Make sure colon follows */ if (*s++ != ':') { /* Make sure colon follows */
return ( LDAP_PARAM_ERROR ); return ( LDAP_PARAM_ERROR );
while (*s && isspace((unsigned char)*s)) }
while (*s && isspace((unsigned char)*s)) {
s++; /* Skip white space before OID */ s++; /* Skip white space before OID */
}
/* OID should come next. Validate and extract it. */ /* OID should come next. Validate and extract it. */
if (*s == 0) if (*s == 0) return ( LDAP_PARAM_ERROR );
return ( LDAP_PARAM_ERROR );
oidStart = s; oidStart = s;
while (isdigit((unsigned char)*s) || *s == '.') while (isdigit((unsigned char)*s) || *s == '.') {
s++; /* OID should be digits or . */ s++; /* OID should be digits or . */
if (s == oidStart) }
if (s == oidStart) {
return ( LDAP_PARAM_ERROR ); /* OID was not present */ return ( LDAP_PARAM_ERROR ); /* OID was not present */
}
if (*s) { /* End of OID should be space or NULL */ if (*s) { /* End of OID should be space or NULL */
if (!isspace((unsigned char)*s)) if (!isspace((unsigned char)*s)) {
return ( LDAP_PARAM_ERROR ); /* else OID contained invalid chars */ return ( LDAP_PARAM_ERROR ); /* else OID contained invalid chars */
}
*s++ = 0; /* Replace space with null to terminate */ *s++ = 0; /* Replace space with null to terminate */
} }
oid = ber_strdup(oidStart); oid = ber_strdup(oidStart);
if (oid == NULL) if (oid == NULL) return ( LDAP_NO_MEMORY );
return ( LDAP_NO_MEMORY );
/* Optional Criticality field is next. */ /* Optional Criticality field is next. */
while (*s && isspace((unsigned char)*s)) while (*s && isspace((unsigned char)*s)) {
s++; /* Skip white space before criticality */ s++; /* Skip white space before criticality */
}
if (strncasecmp(s, "true", 4) == 0) { if (strncasecmp(s, "true", 4) == 0) {
criticality = 1; criticality = 1;
s += 4; s += 4;
@ -686,8 +787,9 @@ parse_ldif_control( char *line,
} }
/* Optional value field is next */ /* Optional value field is next */
while (*s && isspace((unsigned char)*s)) while (*s && isspace((unsigned char)*s)) {
s++; /* Skip white space before value */ s++; /* Skip white space before value */
}
if (*s) { if (*s) {
if (*s != ':') { /* If value is present, must start with : */ if (*s != ':') { /* If value is present, must start with : */
rc = LDAP_PARAM_ERROR; rc = LDAP_PARAM_ERROR;
@ -700,8 +802,9 @@ parse_ldif_control( char *line,
control:< url control:< url
Then we can use ldif_parse_line to extract and decode the value Then we can use ldif_parse_line to extract and decode the value
*/ */
while ( (*pcolon++ = *s++) != 0) /* Shift value */ while ( (*pcolon++ = *s++) != 0) { /* Shift value */
; /* EMPTY */;
}
rc = ldif_parse_line(line, &type, &val, &value_len); rc = ldif_parse_line(line, &type, &val, &value_len);
if (type) ber_memfree(type); /* Don't need this field*/ if (type) ber_memfree(type); /* Don't need this field*/
if (rc < 0) { if (rc < 0) {
@ -726,11 +829,13 @@ parse_ldif_control( char *line,
/* Add the new control to the passed-in list of controls. */ /* Add the new control to the passed-in list of controls. */
i = 0; i = 0;
if (pctrls) { if (pctrls) {
while ( pctrls[i] ) /* Count the # of controls passed in */ while ( pctrls[i] ) { /* Count the # of controls passed in */
i++; i++;
} }
}
/* Allocate 1 more slot for the new control and 1 for the NULL. */ /* Allocate 1 more slot for the new control and 1 for the NULL. */
pctrls = (LDAPControl **)ber_memrealloc(pctrls, (i+2)*(sizeof(LDAPControl *))); pctrls = (LDAPControl **) ber_memrealloc(pctrls,
(i+2)*(sizeof(LDAPControl *)));
if (pctrls == NULL) { if (pctrls == NULL) {
rc = LDAP_NO_MEMORY; rc = LDAP_NO_MEMORY;
goto cleanup; goto cleanup;
@ -742,16 +847,14 @@ parse_ldif_control( char *line,
cleanup: cleanup:
if (newctrl) { if (newctrl) {
if (newctrl->ldctl_oid) if (newctrl->ldctl_oid) ber_memfree(newctrl->ldctl_oid);
ber_memfree(newctrl->ldctl_oid); if (newctrl->ldctl_value.bv_val) {
if (newctrl->ldctl_value.bv_val)
ber_memfree(newctrl->ldctl_value.bv_val); ber_memfree(newctrl->ldctl_value.bv_val);
}
ber_memfree(newctrl); ber_memfree(newctrl);
} }
if (val) if (val) ber_memfree(val);
ber_memfree(val); if (oid) ber_memfree(oid);
if (oid)
ber_memfree(oid);
return( rc ); return( rc );
} }
@ -847,7 +950,8 @@ domodify(
} }
if ( pmods == NULL ) { if ( pmods == NULL ) {
fprintf( stderr, _("%s: no attributes to change or add (entry=\"%s\")\n"), fprintf( stderr,
_("%s: no attributes to change or add (entry=\"%s\")\n"),
prog, dn ); prog, dn );
return( LDAP_PARAM_ERROR ); return( LDAP_PARAM_ERROR );
} }
@ -872,6 +976,7 @@ domodify(
op == LDAP_MOD_DELETE ? _("delete") : op == LDAP_MOD_DELETE ? _("delete") :
_("unknown"), _("unknown"),
pmods[ i ]->mod_type ); pmods[ i ]->mod_type );
if ( pmods[ i ]->mod_bvalues != NULL ) { if ( pmods[ i ]->mod_bvalues != NULL ) {
for ( j = 0; pmods[ i ]->mod_bvalues[ j ] != NULL; ++j ) { for ( j = 0; pmods[ i ]->mod_bvalues[ j ] != NULL; ++j ) {
bvp = pmods[ i ]->mod_bvalues[ j ]; bvp = pmods[ i ]->mod_bvalues[ j ];
@ -916,7 +1021,6 @@ domodify(
} }
putchar( '\n' ); putchar( '\n' );
return( i ); return( i );
} }
@ -930,7 +1034,8 @@ dodelete(
printf( _("%sdeleting entry \"%s\"\n"), not ? "!" : "", dn ); printf( _("%sdeleting entry \"%s\"\n"), not ? "!" : "", dn );
if ( !not ) { if ( !not ) {
if (( rc = ldap_delete_ext_s( ld, dn, pctrls, NULL )) != LDAP_SUCCESS ) { rc = ldap_delete_ext_s( ld, dn, pctrls, NULL );
if ( rc != LDAP_SUCCESS ) {
fprintf( stderr, _("%s: delete failed: %s\n"), prog, dn ); fprintf( stderr, _("%s: delete failed: %s\n"), prog, dn );
ldap_perror( ld, "ldap_delete" ); ldap_perror( ld, "ldap_delete" );
} else if ( verbose ) { } else if ( verbose ) {
@ -941,7 +1046,6 @@ dodelete(
} }
putchar( '\n' ); putchar( '\n' );
return( rc ); return( rc );
} }
@ -956,15 +1060,15 @@ dorename(
{ {
int rc; int rc;
printf( _("%smodifying rdn of entry \"%s\"\n"), not ? "!" : "", dn ); printf( _("%smodifying rdn of entry \"%s\"\n"), not ? "!" : "", dn );
if ( verbose ) { if ( verbose ) {
printf( _("\tnew RDN: \"%s\" (%skeep existing values)\n"), printf( _("\tnew RDN: \"%s\" (%skeep existing values)\n"),
newrdn, deleteoldrdn ? _("do not ") : "" ); newrdn, deleteoldrdn ? _("do not ") : "" );
} }
if ( !not ) { if ( !not ) {
if (( rc = ldap_rename_s( ld, dn, newrdn, newsup, deleteoldrdn, pctrls, NULL )) rc = ldap_rename_s( ld, dn, newrdn, newsup, deleteoldrdn,
!= LDAP_SUCCESS ) { pctrls, NULL );
if ( rc != LDAP_SUCCESS ) {
fprintf( stderr, _("%s: rename failed: %s\n"), prog, dn ); fprintf( stderr, _("%s: rename failed: %s\n"), prog, dn );
ldap_perror( ld, "ldap_modrdn" ); ldap_perror( ld, "ldap_modrdn" );
} else { } else {
@ -975,7 +1079,6 @@ dorename(
} }
putchar( '\n' ); putchar( '\n' );
return( rc ); return( rc );
} }

View File

@ -102,7 +102,7 @@ usage( void )
fprintf( stderr, _(" -a deref one of never (default), always, search, or find\n")); fprintf( stderr, _(" -a deref one of never (default), always, search, or find\n"));
fprintf( stderr, _(" -A retrieve attribute names only (no values)\n")); fprintf( stderr, _(" -A retrieve attribute names only (no values)\n"));
fprintf( stderr, _(" -b basedn base dn for search\n")); fprintf( stderr, _(" -b basedn base dn for search\n"));
fprintf( stderr, _(" -E [!]<ctrl>[=<ctrlparam>] search extensions (! indicates criticality)\n")); fprintf( stderr, _(" -E [!]<ext>[=<extparam>] search extensions (! indicates criticality)\n"));
#ifdef LDAP_CONTROL_X_DOMAIN_SCOPE #ifdef LDAP_CONTROL_X_DOMAIN_SCOPE
fprintf( stderr, _(" [!]domainScope (domain scope)\n")); fprintf( stderr, _(" [!]domainScope (domain scope)\n"));
#endif #endif
@ -245,7 +245,8 @@ handle_private_option( int i )
} else if ( strcasecmp( optarg, "always" ) == 0 ) { } else if ( strcasecmp( optarg, "always" ) == 0 ) {
deref = LDAP_DEREF_ALWAYS; deref = LDAP_DEREF_ALWAYS;
} else { } else {
fprintf( stderr, _("alias deref should be never, search, find, or always\n") ); fprintf( stderr,
_("alias deref should be never, search, find, or always\n") );
usage(); usage();
} }
break; break;
@ -253,7 +254,7 @@ handle_private_option( int i )
++attrsonly; ++attrsonly;
break; break;
case 'b': /* search base */ case 'b': /* search base */
base = strdup( optarg ); base = ber_strdup( optarg );
break; break;
case 'E': /* search extensions */ case 'E': /* search extensions */
if( protocol == LDAP_VERSION2 ) { if( protocol == LDAP_VERSION2 ) {
@ -273,7 +274,7 @@ handle_private_option( int i )
optarg++; optarg++;
} }
control = strdup( optarg ); control = ber_strdup( optarg );
if ( (cvalue = strchr( control, '=' )) != NULL ) { if ( (cvalue = strchr( control, '=' )) != NULL ) {
*cvalue++ = '\0'; *cvalue++ = '\0';
} }
@ -281,7 +282,8 @@ handle_private_option( int i )
if ( strcasecmp( control, "mv" ) == 0 ) { if ( strcasecmp( control, "mv" ) == 0 ) {
/* ValuesReturnFilter control */ /* ValuesReturnFilter control */
if( valuesReturnFilter ) { if( valuesReturnFilter ) {
fprintf( stderr, _("ValuesReturnFilter previously specified\n")); fprintf( stderr,
_("ValuesReturnFilter previously specified\n"));
exit( EXIT_FAILURE ); exit( EXIT_FAILURE );
} }
valuesReturnFilter= 1 + crit; valuesReturnFilter= 1 + crit;
@ -300,7 +302,8 @@ handle_private_option( int i )
int num, tmp; int num, tmp;
/* PagedResults control */ /* PagedResults control */
if ( pagedResults != 0 ) { if ( pagedResults != 0 ) {
fprintf( stderr, _("PagedResultsControl previously specified\n") ); fprintf( stderr,
_("PagedResultsControl previously specified\n") );
exit( EXIT_FAILURE ); exit( EXIT_FAILURE );
} }
@ -315,17 +318,22 @@ handle_private_option( int i )
} else if ( strcasecmp( promptp, "noprompt" ) == 0) { } else if ( strcasecmp( promptp, "noprompt" ) == 0) {
pagePrompt = 0; pagePrompt = 0;
} else { } else {
fprintf( stderr, _("Invalid value for PagedResultsControl, %s/%s.\n"), cvalue, promptp); fprintf( stderr,
_("Invalid value for PagedResultsControl,"
" %s/%s.\n"), cvalue, promptp );
exit( EXIT_FAILURE ); exit( EXIT_FAILURE );
} }
} }
num = sscanf( cvalue, "%d", &tmp ); num = sscanf( cvalue, "%d", &tmp );
if ( num != 1 ) { if ( num != 1 ) {
fprintf( stderr, _("Invalid value for PagedResultsControl, %s.\n"), cvalue); fprintf( stderr,
_("Invalid value for PagedResultsControl, %s.\n"),
cvalue );
exit( EXIT_FAILURE ); exit( EXIT_FAILURE );
} }
} else { } else {
fprintf( stderr, _("Invalid value for PagedResultsControl.\n"), cvalue); fprintf( stderr, _("Invalid value for PagedResultsControl.\n"),
cvalue);
exit( EXIT_FAILURE ); exit( EXIT_FAILURE );
} }
pageSize = (ber_int_t) tmp; pageSize = (ber_int_t) tmp;
@ -350,7 +358,8 @@ handle_private_option( int i )
#ifdef LDAP_CONTROL_SUBENTRIES #ifdef LDAP_CONTROL_SUBENTRIES
} else if ( strcasecmp( control, "subentries" ) == 0 ) { } else if ( strcasecmp( control, "subentries" ) == 0 ) {
if( subentries ) { if( subentries ) {
fprintf( stderr, _("subentries control previously specified\n")); fprintf( stderr,
_("subentries control previously specified\n"));
exit( EXIT_FAILURE ); exit( EXIT_FAILURE );
} }
if( cvalue == NULL || strcasecmp( cvalue, "true") == 0 ) { if( cvalue == NULL || strcasecmp( cvalue, "true") == 0 ) {
@ -370,12 +379,11 @@ handle_private_option( int i )
char *cookiep; char *cookiep;
char *slimitp; char *slimitp;
if ( ldapsync ) { if ( ldapsync ) {
fprintf( stderr, _("ldap sync control previously specified\n") ); fprintf( stderr, _("sync control previously specified\n") );
exit( EXIT_FAILURE ); exit( EXIT_FAILURE );
} }
if ( cvalue == NULL ) { if ( cvalue == NULL ) {
fprintf( stderr, fprintf( stderr, _("missing specification of sync control\n"));
_("missing specification of ldap sync control\n"));
exit( EXIT_FAILURE ); exit( EXIT_FAILURE );
} }
if ( strncasecmp( cvalue, "ro", 2 ) == 0 ) { if ( strncasecmp( cvalue, "ro", 2 ) == 0 ) {
@ -403,15 +411,15 @@ handle_private_option( int i )
if ( slimitp != NULL && *slimitp != '\0' ) if ( slimitp != NULL && *slimitp != '\0' )
sync_slimit = atoi( slimitp ); sync_slimit = atoi( slimitp );
} else { } else {
fprintf( stderr, fprintf( stderr, _("sync control value \"%s\" invalid\n"),
_("ldap sync control value \"%s\" invalid\n"),
cvalue ); cvalue );
exit( EXIT_FAILURE ); exit( EXIT_FAILURE );
} }
if ( crit ) ldapsync *= -1; if ( crit ) ldapsync *= -1;
} else { } else {
fprintf( stderr, _("Invalid search extension name: %s\n"), control ); fprintf( stderr, _("Invalid search extension name: %s\n"),
control );
usage(); usage();
} }
break; break;
@ -473,21 +481,25 @@ static void
private_conn_setup( LDAP *ld ) private_conn_setup( LDAP *ld )
{ {
if (deref != -1 && if (deref != -1 &&
ldap_set_option( ld, LDAP_OPT_DEREF, (void *) &deref ) != LDAP_OPT_SUCCESS ) ldap_set_option( ld, LDAP_OPT_DEREF, (void *) &deref )
!= LDAP_OPT_SUCCESS )
{ {
fprintf( stderr, _("Could not set LDAP_OPT_DEREF %d\n"), deref ); fprintf( stderr, _("Could not set LDAP_OPT_DEREF %d\n"), deref );
exit( EXIT_FAILURE ); exit( EXIT_FAILURE );
} }
if (timelimit != -1 && if (timelimit != -1 &&
ldap_set_option( ld, LDAP_OPT_TIMELIMIT, (void *) &timelimit ) != LDAP_OPT_SUCCESS ) ldap_set_option( ld, LDAP_OPT_TIMELIMIT, (void *) &timelimit )
!= LDAP_OPT_SUCCESS )
{ {
fprintf( stderr, _("Could not set LDAP_OPT_TIMELIMIT %d\n"), timelimit ); fprintf( stderr, _("Could not set LDAP_OPT_TIMELIMIT %d\n"), timelimit );
exit( EXIT_FAILURE ); exit( EXIT_FAILURE );
} }
if (sizelimit != -1 && if (sizelimit != -1 &&
ldap_set_option( ld, LDAP_OPT_SIZELIMIT, (void *) &sizelimit ) != LDAP_OPT_SUCCESS ) ldap_set_option( ld, LDAP_OPT_SIZELIMIT, (void *) &sizelimit )
!= LDAP_OPT_SUCCESS )
{ {
fprintf( stderr, _("Could not set LDAP_OPT_SIZELIMIT %d\n"), sizelimit ); fprintf( stderr,
_("Could not set LDAP_OPT_SIZELIMIT %d\n"), sizelimit );
exit( EXIT_FAILURE ); exit( EXIT_FAILURE );
} }
} }
@ -715,9 +727,13 @@ getNextPage:
tool_server_controls( ld, c, i ); tool_server_controls( ld, c, i );
#ifdef LDAP_CONTROL_SUBENTRIES
ber_free( seber, 1 ); ber_free( seber, 1 );
#endif
ber_free( vrber, 1 ); ber_free( vrber, 1 );
#ifdef LDAP_CONTROL_PAGEDRESULTS
ber_free( prber, 1 ); ber_free( prber, 1 );
#endif
} }
if ( verbose ) { if ( verbose ) {
@ -1121,8 +1137,8 @@ print_entry(
} else if ( bvals ) { } else if ( bvals ) {
for ( i = 0; bvals[i].bv_val != NULL; i++ ) { for ( i = 0; bvals[i].bv_val != NULL; i++ ) {
if ( vals2tmp > 1 || ( vals2tmp if ( vals2tmp > 1 || ( vals2tmp &&
&& ldif_is_not_printable( bvals[i].bv_val, bvals[i].bv_len ) )) ldif_is_not_printable( bvals[i].bv_val, bvals[i].bv_len )))
{ {
int tmpfd; int tmpfd;
/* write value to file */ /* write value to file */

View File

@ -1835,6 +1835,47 @@ ldap_parse_vlv_control LDAP_P((
struct berval **contextp, struct berval **contextp,
int *errcodep )); int *errcodep ));
/*
* LDAP Transactions
* in txn.c
*/
LDAP_F( int )
ldap_parse_txn_create LDAP_P((
LDAP *ld,
LDAPMessage *res,
struct berval **cookie ));
LDAP_F( int )
ldap_txn_create LDAP_P((
LDAP *ld,
LDAPControl **sctrls,
LDAPControl **cctrls,
int *msgidp ));
LDAP_F( int )
ldap_txn_create_s LDAP_P((
LDAP *ld,
struct berval **cookie,
LDAPControl **sctrls,
LDAPControl **cctrls ));
LDAP_F( int )
ldap_txn_end LDAP_P((
LDAP *ld,
struct berval *cookie,
int commit,
LDAPControl **sctrls,
LDAPControl **cctrls,
int *msgidp ));
LDAP_F( int )
ldap_txn_end_s LDAP_P((
LDAP *ld,
struct berval *cookie,
int commit,
LDAPControl **sctrls,
LDAPControl **cctrls ));
/* /*
* LDAP Who Am I? * LDAP Who Am I?
* in whoami.c * in whoami.c

View File

@ -26,7 +26,7 @@ SRCS = bind.c open.c result.c error.c compare.c search.c \
request.c os-ip.c url.c sortctrl.c vlvctrl.c \ request.c os-ip.c url.c sortctrl.c vlvctrl.c \
init.c options.c print.c string.c util-int.c schema.c \ init.c options.c print.c string.c util-int.c schema.c \
charray.c tls.c os-local.c dnssrv.c utf-8.c utf-8-conv.c \ charray.c tls.c os-local.c dnssrv.c utf-8.c utf-8-conv.c \
pcontrol.c groupings.c txn.c ppcontrol.c
OBJS = bind.lo open.lo result.lo error.lo compare.lo search.lo \ OBJS = bind.lo open.lo result.lo error.lo compare.lo search.lo \
controls.lo messages.lo references.lo extended.lo cyrus.lo \ controls.lo messages.lo references.lo extended.lo cyrus.lo \
@ -37,7 +37,7 @@ OBJS = bind.lo open.lo result.lo error.lo compare.lo search.lo \
request.lo os-ip.lo url.lo sortctrl.lo vlvctrl.lo \ request.lo os-ip.lo url.lo sortctrl.lo vlvctrl.lo \
init.lo options.lo print.lo string.lo util-int.lo schema.lo \ init.lo options.lo print.lo string.lo util-int.lo schema.lo \
charray.lo tls.lo os-local.lo dnssrv.lo utf-8.lo utf-8-conv.lo \ charray.lo tls.lo os-local.lo dnssrv.lo utf-8.lo utf-8-conv.lo \
ppcontrol.lo groupings.lo txn.lo ppcontrol.lo
LDAP_INCDIR= ../../include LDAP_INCDIR= ../../include
LDAP_LIBDIR= ../../libraries LDAP_LIBDIR= ../../libraries

View File

@ -12,6 +12,10 @@
* top-level directory of the distribution or, alternatively, at * top-level directory of the distribution or, alternatively, at
* <http://www.OpenLDAP.org/license.html>. * <http://www.OpenLDAP.org/license.html>.
*/ */
/* ACKNOWLEDGEMENTS:
* This program was orignally developed by Kurt D. Zeilenga for inclusion in
* OpenLDAP Software.
*/
/* /*
* LDAPv3 Cancel Operation Request * LDAPv3 Cancel Operation Request

View File

@ -0,0 +1,30 @@
/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
* Copyright 2004 The OpenLDAP Foundation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted only as authorized by the OpenLDAP
* Public License.
*
* A copy of this license is available in the file LICENSE in the
* top-level directory of the distribution or, alternatively, at
* <http://www.OpenLDAP.org/license.html>.
*/
/* ACKNOWLEDGEMENTS:
* This program was orignally developed by Kurt D. Zeilenga for inclusion in
* OpenLDAP Software.
*/
#include "portable.h"
#include <ac/stdlib.h>
#include <ac/time.h>
#include <ac/string.h>
#include "ldap-int.h"

View File

@ -12,6 +12,10 @@
* top-level directory of the distribution or, alternatively, at * top-level directory of the distribution or, alternatively, at
* <http://www.OpenLDAP.org/license.html>. * <http://www.OpenLDAP.org/license.html>.
*/ */
/* ACKNOWLEDGEMENTS:
* This program was orignally developed by Kurt D. Zeilenga for inclusion in
* OpenLDAP Software.
*/
#include "portable.h" #include "portable.h"

48
libraries/libldap/txn.c Normal file
View File

@ -0,0 +1,48 @@
/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
* Copyright 2004 The OpenLDAP Foundation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted only as authorized by the OpenLDAP
* Public License.
*
* A copy of this license is available in the file LICENSE in the
* top-level directory of the distribution or, alternatively, at
* <http://www.OpenLDAP.org/license.html>.
*/
/* ACKNOWLEDGEMENTS:
* This program was orignally developed by Kurt D. Zeilenga for inclusion in
* OpenLDAP Software.
*/
#include "portable.h"
#include <ac/stdlib.h>
#include <ac/time.h>
#include <ac/string.h>
#include "ldap-int.h"
int
ldap_txn_create_s(
LDAP *ld,
struct berval **cookie,
LDAPControl **sctrls,
LDAPControl **cctrls )
{
return LDAP_NOT_SUPPORTED;
}
int
ldap_txn_end_s(
LDAP *ld,
struct berval *cookie,
int commit,
LDAPControl **sctrls,
LDAPControl **cctrls )
{
return LDAP_NOT_SUPPORTED;
}

View File

@ -12,6 +12,10 @@
* top-level directory of the distribution or, alternatively, at * top-level directory of the distribution or, alternatively, at
* <http://www.OpenLDAP.org/license.html>. * <http://www.OpenLDAP.org/license.html>.
*/ */
/* ACKNOWLEDGEMENTS:
* This program was orignally developed by Kurt D. Zeilenga for inclusion in
* OpenLDAP Software.
*/
#include "portable.h" #include "portable.h"

View File

@ -28,7 +28,7 @@ XXSRCS = apitest.c test.c \
request.c os-ip.c url.c sortctrl.c vlvctrl.c \ request.c os-ip.c url.c sortctrl.c vlvctrl.c \
init.c options.c print.c string.c util-int.c schema.c \ init.c options.c print.c string.c util-int.c schema.c \
charray.c tls.c os-local.c dnssrv.c utf-8.c utf-8-conv.c \ charray.c tls.c os-local.c dnssrv.c utf-8.c utf-8-conv.c \
ppcontrol.c groupings.c txn.c ppcontrol.c
SRCS = threads.c rdwr.c tpool.c rq.c \ SRCS = threads.c rdwr.c tpool.c rq.c \
thr_posix.c thr_cthreads.c thr_thr.c thr_lwp.c thr_nt.c \ thr_posix.c thr_cthreads.c thr_thr.c thr_lwp.c thr_nt.c \
thr_pth.c thr_stub.c thr_pth.c thr_stub.c
@ -44,7 +44,7 @@ OBJS = threads.lo rdwr.lo tpool.lo rq.lo \
request.lo os-ip.lo url.lo sortctrl.lo vlvctrl.lo \ request.lo os-ip.lo url.lo sortctrl.lo vlvctrl.lo \
init.lo options.lo print.lo string.lo util-int.lo schema.lo \ init.lo options.lo print.lo string.lo util-int.lo schema.lo \
charray.lo tls.lo os-local.lo dnssrv.lo utf-8.lo utf-8-conv.lo \ charray.lo tls.lo os-local.lo dnssrv.lo utf-8.lo utf-8-conv.lo \
ppcontrol.lo groupings.lo txn.lo ppcontrol.lo
LDAP_INCDIR= ../../include LDAP_INCDIR= ../../include
LDAP_LIBDIR= ../../libraries LDAP_LIBDIR= ../../libraries