mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-12-22 07:39:35 -05:00
ITS#2657: authzid (and assertion) should apply to most everything
(preliminary modify/incr client-side code)
This commit is contained in:
parent
443d4c8999
commit
afa2cd1893
8 changed files with 107 additions and 92 deletions
|
|
@ -29,6 +29,7 @@ extern char *sasl_secprops;
|
||||||
#endif
|
#endif
|
||||||
extern int use_tls;
|
extern int use_tls;
|
||||||
|
|
||||||
|
extern char *assertion;
|
||||||
extern char *authzid;
|
extern char *authzid;
|
||||||
extern int manageDSAit;
|
extern int manageDSAit;
|
||||||
extern int noop;
|
extern int noop;
|
||||||
|
|
|
||||||
|
|
@ -172,8 +172,9 @@ main( int argc, char **argv )
|
||||||
|
|
||||||
tool_bind( ld );
|
tool_bind( ld );
|
||||||
|
|
||||||
if ( authzid || manageDSAit || noop )
|
if ( assertion || authzid || manageDSAit || noop ) {
|
||||||
tool_server_controls( ld, NULL, 0 );
|
tool_server_controls( ld, NULL, 0 );
|
||||||
|
}
|
||||||
|
|
||||||
if ( verbose ) {
|
if ( verbose ) {
|
||||||
fprintf( stderr, _("DN:%s, attr:%s, value:%s\n"),
|
fprintf( stderr, _("DN:%s, attr:%s, value:%s\n"),
|
||||||
|
|
|
||||||
|
|
@ -143,8 +143,9 @@ main( int argc, char **argv )
|
||||||
|
|
||||||
tool_bind( ld );
|
tool_bind( ld );
|
||||||
|
|
||||||
if ( authzid || manageDSAit || noop )
|
if ( assertion || authzid || manageDSAit || noop ) {
|
||||||
tool_server_controls( ld, NULL, 0 );
|
tool_server_controls( ld, NULL, 0 );
|
||||||
|
}
|
||||||
|
|
||||||
retval = rc = 0;
|
retval = rc = 0;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,7 @@ static LDAP *ld = NULL;
|
||||||
#define T_MODOPADDSTR "add"
|
#define T_MODOPADDSTR "add"
|
||||||
#define T_MODOPREPLACESTR "replace"
|
#define T_MODOPREPLACESTR "replace"
|
||||||
#define T_MODOPDELETESTR "delete"
|
#define T_MODOPDELETESTR "delete"
|
||||||
|
#define T_MODOPINCREMENTSTR "increment"
|
||||||
#define T_MODSEPSTR "-"
|
#define T_MODSEPSTR "-"
|
||||||
#define T_NEWRDNSTR "newrdn"
|
#define T_NEWRDNSTR "newrdn"
|
||||||
#define T_DELETEOLDRDNSTR "deleteoldrdn"
|
#define T_DELETEOLDRDNSTR "deleteoldrdn"
|
||||||
|
|
@ -168,123 +169,123 @@ handle_private_option( int i )
|
||||||
int
|
int
|
||||||
main( int argc, char **argv )
|
main( int argc, char **argv )
|
||||||
{
|
{
|
||||||
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;
|
||||||
int rc, retval;
|
int rc, retval;
|
||||||
int count, len;
|
int count, len;
|
||||||
|
|
||||||
tool_init();
|
tool_init();
|
||||||
prog = lutil_progname( "ldapmodify", argc, argv );
|
prog = lutil_progname( "ldapmodify", argc, argv );
|
||||||
|
|
||||||
/* strncmp instead of strcmp since NT binaries carry .exe extension */
|
/* strncmp instead of strcmp since NT binaries carry .exe extension */
|
||||||
ldapadd = ( strncasecmp( prog, "ldapadd", sizeof("ldapadd")-1 ) == 0 );
|
ldapadd = ( strncasecmp( prog, "ldapadd", sizeof("ldapadd")-1 ) == 0 );
|
||||||
|
|
||||||
/* Print usage when no parameters */
|
/* Print usage when no parameters */
|
||||||
if( argc < 2 ) usage();
|
if( argc < 2 ) usage();
|
||||||
|
|
||||||
tool_args( argc, argv );
|
tool_args( argc, argv );
|
||||||
|
|
||||||
if ( argc != optind )
|
if ( argc != optind ) usage();
|
||||||
usage();
|
|
||||||
|
|
||||||
if ( rejfile != NULL ) {
|
if ( rejfile != NULL ) {
|
||||||
if (( rejfp = fopen( rejfile, "w" )) == NULL ) {
|
if (( rejfp = fopen( rejfile, "w" )) == NULL ) {
|
||||||
perror( rejfile );
|
perror( rejfile );
|
||||||
return( EXIT_FAILURE );
|
return( EXIT_FAILURE );
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
rejfp = NULL;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
rejfp = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( infile != NULL ) {
|
if ( infile != NULL ) {
|
||||||
if (( fp = fopen( infile, "r" )) == NULL ) {
|
if (( fp = fopen( infile, "r" )) == NULL ) {
|
||||||
perror( infile );
|
perror( infile );
|
||||||
return( EXIT_FAILURE );
|
return( EXIT_FAILURE );
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fp = stdin;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
fp = stdin;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( debug )
|
if ( debug ) ldif_debug = debug;
|
||||||
ldif_debug = debug;
|
|
||||||
|
|
||||||
ld = tool_conn_setup( not, 0 );
|
ld = tool_conn_setup( not, 0 );
|
||||||
|
|
||||||
if ( !not ) {
|
if ( !not ) {
|
||||||
if ( pw_file || want_bindpw ) {
|
if ( pw_file || want_bindpw ) {
|
||||||
if ( pw_file ) {
|
if ( pw_file ) {
|
||||||
rc = lutil_get_filed_password( pw_file, &passwd );
|
rc = lutil_get_filed_password( pw_file, &passwd );
|
||||||
if( rc ) return EXIT_FAILURE;
|
if( rc ) return EXIT_FAILURE;
|
||||||
} else {
|
} else {
|
||||||
passwd.bv_val = getpassphrase( _("Enter LDAP Password: ") );
|
passwd.bv_val = getpassphrase( _("Enter LDAP Password: ") );
|
||||||
passwd.bv_len = passwd.bv_val ? strlen( passwd.bv_val ) : 0;
|
passwd.bv_len = passwd.bv_val ? strlen( passwd.bv_val ) : 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
tool_bind( ld );
|
||||||
}
|
}
|
||||||
|
|
||||||
tool_bind( ld );
|
|
||||||
}
|
|
||||||
|
|
||||||
rc = 0;
|
rc = 0;
|
||||||
|
|
||||||
if ( authzid || manageDSAit || noop )
|
if ( assertion || authzid || manageDSAit || noop ) {
|
||||||
tool_server_controls( ld, NULL, 0 );
|
tool_server_controls( ld, NULL, 0 );
|
||||||
|
}
|
||||||
|
|
||||||
count = 0;
|
count = 0;
|
||||||
retval = 0;
|
retval = 0;
|
||||||
while (( rc == 0 || contoper ) &&
|
while (( rc == 0 || contoper ) &&
|
||||||
( rbuf = read_one_record( fp )) != NULL ) {
|
( rbuf = read_one_record( fp )) != NULL )
|
||||||
count++;
|
{
|
||||||
|
count++;
|
||||||
|
|
||||||
start = rbuf;
|
start = rbuf;
|
||||||
|
|
||||||
if ( rejfp ) {
|
if ( rejfp ) {
|
||||||
len = strlen( rbuf );
|
len = strlen( rbuf );
|
||||||
if (( rejbuf = (char *)ber_memalloc( len+1 )) == NULL ) {
|
if (( rejbuf = (char *)ber_memalloc( len+1 )) == NULL ) {
|
||||||
perror( "malloc" );
|
perror( "malloc" );
|
||||||
exit( EXIT_FAILURE );
|
exit( EXIT_FAILURE );
|
||||||
}
|
}
|
||||||
memcpy( rejbuf, rbuf, len+1 );
|
memcpy( rejbuf, rbuf, len+1 );
|
||||||
}
|
|
||||||
|
|
||||||
rc = process_ldif_rec( start, count );
|
|
||||||
|
|
||||||
if ( rc )
|
|
||||||
retval = rc;
|
|
||||||
if ( rc && rejfp ) {
|
|
||||||
fprintf(rejfp, _("# Error: %s (%d)"), ldap_err2string(rc), rc);
|
|
||||||
|
|
||||||
matched_msg = NULL;
|
|
||||||
ldap_get_option(ld, LDAP_OPT_MATCHED_DN, &matched_msg);
|
|
||||||
if ( matched_msg != NULL ) {
|
|
||||||
if ( *matched_msg != '\0' )
|
|
||||||
fprintf( rejfp, _(", matched DN: %s"), matched_msg );
|
|
||||||
ldap_memfree( matched_msg );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
error_msg = NULL;
|
rc = process_ldif_rec( start, count );
|
||||||
ldap_get_option(ld, LDAP_OPT_ERROR_STRING, &error_msg);
|
|
||||||
if ( error_msg != NULL ) {
|
if ( rc ) retval = rc;
|
||||||
if ( *error_msg != '\0' )
|
if ( rc && rejfp ) {
|
||||||
fprintf( rejfp, _(", additional info: %s"), error_msg );
|
fprintf(rejfp, _("# Error: %s (%d)"), ldap_err2string(rc), rc);
|
||||||
ldap_memfree( error_msg );
|
|
||||||
|
matched_msg = NULL;
|
||||||
|
ldap_get_option(ld, LDAP_OPT_MATCHED_DN, &matched_msg);
|
||||||
|
if ( matched_msg != NULL ) {
|
||||||
|
if ( *matched_msg != '\0' ) {
|
||||||
|
fprintf( rejfp, _(", matched DN: %s"), matched_msg );
|
||||||
|
}
|
||||||
|
ldap_memfree( matched_msg );
|
||||||
|
}
|
||||||
|
|
||||||
|
error_msg = NULL;
|
||||||
|
ldap_get_option(ld, LDAP_OPT_ERROR_STRING, &error_msg);
|
||||||
|
if ( error_msg != NULL ) {
|
||||||
|
if ( *error_msg != '\0' ) {
|
||||||
|
fprintf( rejfp, _(", additional info: %s"), error_msg );
|
||||||
|
}
|
||||||
|
ldap_memfree( error_msg );
|
||||||
|
}
|
||||||
|
fprintf( rejfp, "\n%s\n", rejbuf );
|
||||||
}
|
}
|
||||||
fprintf( rejfp, "\n%s\n", rejbuf );
|
|
||||||
}
|
if (rejfp) free( rejbuf );
|
||||||
if (rejfp)
|
|
||||||
free( rejbuf );
|
|
||||||
free( rbuf );
|
free( rbuf );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !not ) {
|
if ( !not ) {
|
||||||
ldap_unbind( ld );
|
ldap_unbind( ld );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( rejfp != NULL ) {
|
if ( rejfp != NULL ) {
|
||||||
fclose( rejfp );
|
fclose( rejfp );
|
||||||
}
|
}
|
||||||
|
|
||||||
return( retval );
|
return( retval );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -461,6 +462,10 @@ process_ldif_rec( char *rbuf, int count )
|
||||||
modop = LDAP_MOD_DELETE;
|
modop = LDAP_MOD_DELETE;
|
||||||
addmodifyop( &pmods, modop, val.bv_val, NULL );
|
addmodifyop( &pmods, modop, val.bv_val, NULL );
|
||||||
goto end_line;
|
goto end_line;
|
||||||
|
} else if ( strcasecmp( type, T_MODOPINCREMENTSTR ) == 0 ) {
|
||||||
|
modop = LDAP_MOD_INCREMENT;
|
||||||
|
addmodifyop( &pmods, modop, val.bv_val, NULL );
|
||||||
|
goto end_line;
|
||||||
} else { /* no modify op: use default */
|
} else { /* no modify op: use default */
|
||||||
modop = ldapadd ? LDAP_MOD_ADD : LDAP_MOD_REPLACE;
|
modop = ldapadd ? LDAP_MOD_ADD : LDAP_MOD_REPLACE;
|
||||||
}
|
}
|
||||||
|
|
@ -829,8 +834,11 @@ domodify(
|
||||||
for ( i = 0; pmods[ i ] != NULL; ++i ) {
|
for ( i = 0; pmods[ i ] != NULL; ++i ) {
|
||||||
op = pmods[ i ]->mod_op & ~LDAP_MOD_BVALUES;
|
op = pmods[ i ]->mod_op & ~LDAP_MOD_BVALUES;
|
||||||
printf( "%s %s:\n",
|
printf( "%s %s:\n",
|
||||||
op == LDAP_MOD_REPLACE ? _("replace") : op == LDAP_MOD_ADD
|
op == LDAP_MOD_REPLACE ? _("replace") :
|
||||||
? _("add") : _("delete"),
|
op == LDAP_MOD_ADD ? _("add") :
|
||||||
|
op == LDAP_MOD_INCREMENT ? _("increment") :
|
||||||
|
op == LDAP_MOD_DELETE ? _("delete") :
|
||||||
|
_("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 ) {
|
||||||
|
|
|
||||||
|
|
@ -171,8 +171,9 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
tool_bind( ld );
|
tool_bind( ld );
|
||||||
|
|
||||||
if ( authzid || manageDSAit || noop )
|
if ( assertion || authzid || manageDSAit || noop ) {
|
||||||
tool_server_controls( ld, NULL, 0 );
|
tool_server_controls( ld, NULL, 0 );
|
||||||
|
}
|
||||||
|
|
||||||
retval = rc = 0;
|
retval = rc = 0;
|
||||||
if (havedn)
|
if (havedn)
|
||||||
|
|
|
||||||
|
|
@ -221,8 +221,9 @@ main( int argc, char *argv[] )
|
||||||
|
|
||||||
tool_bind( ld );
|
tool_bind( ld );
|
||||||
|
|
||||||
if ( authzid || manageDSAit || noop )
|
if ( assertion || authzid || manageDSAit || noop ) {
|
||||||
tool_server_controls( ld, NULL, 0 );
|
tool_server_controls( ld, NULL, 0 );
|
||||||
|
}
|
||||||
|
|
||||||
if( user != NULL || oldpw.bv_val != NULL || newpw.bv_val != NULL ) {
|
if( user != NULL || oldpw.bv_val != NULL || newpw.bv_val != NULL ) {
|
||||||
/* build change password control */
|
/* build change password control */
|
||||||
|
|
|
||||||
|
|
@ -548,17 +548,18 @@ main( int argc, char **argv )
|
||||||
tool_bind( ld );
|
tool_bind( ld );
|
||||||
|
|
||||||
getNextPage:
|
getNextPage:
|
||||||
if ( manageDSAit || noop || subentries || valuesReturnFilter
|
if ( assertion || authzid || manageDSAit || noop
|
||||||
#ifdef LDAP_CONTROL_X_DOMAIN_SCOPE
|
#ifdef LDAP_CONTROL_X_DOMAIN_SCOPE
|
||||||
|| domainScope
|
|| domainScope
|
||||||
#endif
|
#endif
|
||||||
#ifdef LDAP_CONTROL_PAGEDRESULTS
|
#ifdef LDAP_CONTROL_PAGEDRESULTS
|
||||||
|| pageSize
|
|| pageSize
|
||||||
#endif
|
#endif
|
||||||
#ifdef LDAP_SYNC
|
#ifdef LDAP_SYNC
|
||||||
|| ldapsync
|
|| ldapsync
|
||||||
#endif
|
#endif
|
||||||
) {
|
|| subentries || valuesReturnFilter )
|
||||||
|
{
|
||||||
int err;
|
int err;
|
||||||
int i=0;
|
int i=0;
|
||||||
LDAPControl c[6];
|
LDAPControl c[6];
|
||||||
|
|
|
||||||
|
|
@ -124,8 +124,9 @@ main( int argc, char *argv[] )
|
||||||
goto skip;
|
goto skip;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( authzid || manageDSAit || noop )
|
if ( assertion || authzid || manageDSAit || noop ) {
|
||||||
tool_server_controls( ld, NULL, 0 );
|
tool_server_controls( ld, NULL, 0 );
|
||||||
|
}
|
||||||
|
|
||||||
rc = ldap_whoami_s( ld, &retdata, NULL, NULL );
|
rc = ldap_whoami_s( ld, &retdata, NULL, NULL );
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue