streamline server control requests

This commit is contained in:
Pierangelo Masarati 2006-01-09 23:00:28 +00:00
parent 282f5638ed
commit ade9272561
8 changed files with 67 additions and 63 deletions

View File

@ -1119,6 +1119,21 @@ tool_server_controls( LDAP *ld, LDAPControl *extra_c, int count )
int i = 0, j, crit = 0, err;
LDAPControl c[10], **ctrls;
if ( ! ( assertctl
|| authzid
|| manageDIT
|| manageDSAit
|| noop
|| preread
|| postread
#ifdef LDAP_CONTROL_X_CHAINING_BEHAVIOR
|| chaining
#endif /* LDAP_CONTROL_X_CHAINING_BEHAVIOR */
|| count ) )
{
return;
}
ctrls = (LDAPControl**) malloc(sizeof(c) + (count+1)*sizeof(LDAPControl*));
if ( ctrls == NULL ) {
fprintf( stderr, "No memory\n" );

View File

@ -181,11 +181,14 @@ handle_private_option( int i )
int
main( int argc, char **argv )
{
char *compdn = NULL, *attrs = NULL;
char *sep;
char *compdn = NULL, *attrs = NULL;
char *sep;
int rc;
LDAP *ld = NULL;
struct berval bvalue = { 0, NULL };
LDAP *ld = NULL;
struct berval bvalue = { 0, NULL };
int i = 0;
LDAPControl c[1];
tool_init( TOOL_COMPARE );
prog = lutil_progname( "ldapcompare", argc, argv );
@ -238,16 +241,12 @@ main( int argc, char **argv )
tool_bind( ld );
if ( assertion || authzid || manageDSAit || noop
if ( 0
#ifdef LDAP_CONTROL_DONTUSECOPY
|| dontUseCopy
#endif
)
{
int err;
int i = 0;
LDAPControl c[1];
#ifdef LDAP_CONTROL_DONTUSECOPY
if ( dontUseCopy ) {
c[i].ldctl_oid = LDAP_CONTROL_DONTUSECOPY;
@ -257,10 +256,10 @@ main( int argc, char **argv )
i++;
}
#endif
tool_server_controls( ld, c, i );
}
tool_server_controls( ld, c, i );
if ( verbose ) {
fprintf( stderr, _("DN:%s, attr:%s, value:%s\n"),
compdn, attrs, sep );

View File

@ -170,13 +170,11 @@ main( int argc, char **argv )
tool_bind( ld );
if ( assertion || authzid || manageDIT || manageDSAit || noop ) {
tool_server_controls( ld, NULL, 0 );
}
tool_server_controls( ld, NULL, 0 );
retval = rc = 0;
if ( fp == NULL ) {
if ( fp == NULL ) {
for ( ; optind < argc; ++optind ) {
rc = dodelete( ld, argv[ optind ] );

View File

@ -116,14 +116,7 @@ main( int argc, char *argv[] )
usage();
}
if ( assertion || manageDSAit || noop ) {
fprintf( stderr, _("controls incompatible with WhoAmI exop\n\n") );
usage();
}
if ( authzid ) {
tool_server_controls( ld, NULL, 0 );
}
tool_server_controls( ld, NULL, 0 );
rc = ldap_whoami( ld, NULL, NULL, &id );
if ( rc != LDAP_SUCCESS ) {
@ -156,7 +149,9 @@ main( int argc, char *argv[] )
}
} else if ( strcasecmp( argv[ 0 ], "passwd" ) == 0 ) {
/* do we need this? */
fprintf( stderr, "use ldappasswd(1) instead.\n\n", argv[ 0 ] );
usage();
/* TODO? */
} else if ( strcasecmp( argv[ 0 ], "refresh" ) == 0 ) {
int ttl = 3600;
@ -178,9 +173,7 @@ main( int argc, char *argv[] )
usage();
}
if ( assertion || manageDSAit || noop || authzid ) {
tool_server_controls( ld, NULL, 0 );
}
tool_server_controls( ld, NULL, 0 );
rc = ldap_refresh( ld, &dn, ttl, NULL, NULL, &id );
if ( rc != LDAP_SUCCESS ) {
@ -190,6 +183,9 @@ main( int argc, char *argv[] )
}
} else if ( tool_is_oid( argv[ 0 ] ) ) {
/* TODO */
fprintf( stderr, "exop \"%s\" not implemented yet.\n\n", argv[ 0 ] );
usage();
} else {
fprintf( stderr, "unknown exop \"%s\"\n\n", argv[ 0 ] );
@ -258,6 +254,7 @@ main( int argc, char *argv[] )
assert( 0 );
} else if ( strcasecmp( argv[ 0 ], "passwd" ) == 0 ) {
/* TODO */
} else if ( strcasecmp( argv[ 0 ], "refresh" ) == 0 ) {
int newttl;

View File

@ -242,14 +242,17 @@ int
main( int argc, char **argv )
{
#ifdef LDAP_GROUP_TRANSACTION
BerElement *txnber;
struct berval txnCookie = { 0, NULL };
BerElement *txnber;
struct berval txnCookie = { 0, NULL };
#endif
char *rbuf, *start, *rejbuf = NULL;
FILE *fp, *rejfp;
char *matched_msg, *error_msg;
int rc, retval;
int count, len;
int count, len;
int i = 0;
LDAPControl c[1];
prog = lutil_progname( "ldapmodify", argc, argv );
@ -311,15 +314,12 @@ main( int argc, char **argv )
}
#endif
if ( assertion || authzid || manageDIT || manageDSAit || noop
if ( 0
#ifdef LDAP_GROUP_TRANSACTION
|| txn
#endif
|| preread || postread )
)
{
int i = 0;
LDAPControl c[1];
#ifdef LDAP_GROUP_TRANSACTION
if( txn ) {
int err;
@ -341,10 +341,10 @@ main( int argc, char **argv )
i++;
}
#endif
tool_server_controls( ld, c, i );
}
tool_server_controls( ld, c, i );
rc = 0;
count = 0;
retval = 0;

View File

@ -198,9 +198,7 @@ main(int argc, char **argv)
tool_bind( ld );
if ( assertion || authzid || manageDSAit || noop ) {
tool_server_controls( ld, NULL, 0 );
}
tool_server_controls( ld, NULL, 0 );
retval = rc = 0;
if (havedn)

View File

@ -625,12 +625,13 @@ main( int argc, char **argv )
{
char *filtpattern, **attrs = NULL, line[BUFSIZ];
FILE *fp = NULL;
int rc, i, first;
int rc, i, first;
LDAP *ld = NULL;
BerElement *seber = NULL, *vrber = NULL;
BerElement *syncber = NULL;
struct berval *syncbvalp = NULL;
int err;
tool_init( TOOL_SEARCH );
@ -724,20 +725,18 @@ main( int argc, char **argv )
tool_bind( ld );
getNextPage:
if ( nctrls > 0 || assertion || authzid || manageDSAit || noop
save_nctrls = nctrls;
i = nctrls;
if ( nctrls > 0
#ifdef LDAP_CONTROL_DONTUSECOPY
|| dontUseCopy
#endif
|| domainScope || pagedResults
#ifdef LDAP_CONTROL_X_CHAINING_BEHAVIOR
|| chaining
#endif /* LDAP_CONTROL_X_CHAINING_BEHAVIOR */
|| domainScope
|| pagedResults
|| ldapsync
|| subentries || valuesReturnFilter )
|| subentries
|| valuesReturnFilter )
{
int err;
int i = nctrls;
save_nctrls = nctrls;
#ifdef LDAP_CONTROL_DONTUSECOPY
if ( dontUseCopy ) {
@ -867,17 +866,17 @@ getNextPage:
c[i].ldctl_iscritical = pagedResults > 1;
i++;
}
tool_server_controls( ld, c, i );
/* step back to the original number of controls, so that
* those set while parsing args are preserved */
nctrls = save_nctrls;
ber_free( seber, 1 );
ber_free( vrber, 1 );
}
tool_server_controls( ld, c, i );
ber_free( seber, 1 );
ber_free( vrber, 1 );
/* step back to the original number of controls, so that
* those set while parsing args are preserved */
nctrls = save_nctrls;
if ( verbose ) {
fprintf( stderr, _("filter%s: %s\nrequesting: "),
infile != NULL ? _(" pattern") : "",

View File

@ -154,9 +154,7 @@ main( int argc, char *argv[] )
goto skip;
}
if ( assertion || authzid || manageDSAit || noop ) {
tool_server_controls( ld, NULL, 0 );
}
tool_server_controls( ld, NULL, 0 );
rc = ldap_whoami( ld, NULL, NULL, &id );