From 448fa12bc1b947a8c8b2d50fb9ab07d90f55e8f0 Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Tue, 19 Apr 2005 18:07:27 +0000 Subject: [PATCH] enable abandon/cancel in ldapsearch (ITS#3670) --- clients/tools/ldapsearch.c | 44 +++++++++++++++++--------------------- doc/devel/args | 6 +++--- doc/man/man1/ldapsearch.1 | 9 ++++++++ 3 files changed, 32 insertions(+), 27 deletions(-) diff --git a/clients/tools/ldapsearch.c b/clients/tools/ldapsearch.c index 9345c77c25..2de87f9d76 100644 --- a/clients/tools/ldapsearch.c +++ b/clients/tools/ldapsearch.c @@ -48,9 +48,7 @@ #include #include -#if defined(TEST_ABANDON) || defined(TEST_CANCEL) #include -#endif #ifdef HAVE_FCNTL_H #include @@ -234,7 +232,7 @@ urlize(char *url) } -const char options[] = "a:Ab:E:F:l:Ls:S:tT:uz:" +const char options[] = "a:Ab:cE:F:l:Ls:S:tT:uz:" "Cd:D:e:f:h:H:IkKMnO:p:P:QR:U:vVw:WxX:y:Y:Z"; int @@ -555,15 +553,13 @@ private_conn_setup( LDAP *ld ) } } -#if defined(TEST_ABANDON) || defined(TEST_CANCEL) static int gotintr; RETSIGTYPE do_sig( int sig ) { - gotintr = 1; + gotintr = contoper; } -#endif int main( int argc, char **argv ) @@ -623,9 +619,9 @@ main( int argc, char **argv ) attrs = &argv[optind]; } -#if defined(TEST_ABANDON) || defined(TEST_CANCEL) - SIGNAL( SIGINT, do_sig ); -#endif + if ( contoper > 0 ) { + SIGNAL( SIGINT, do_sig ); + } if ( infile != NULL ) { if ( infile[0] == '-' && infile[1] == '\0' ) { @@ -1022,6 +1018,20 @@ static int dosearch( sortattr ? LDAP_MSG_ALL : LDAP_MSG_ONE, NULL, &res )) > 0 ) { + switch ( gotintr ) { + case 2: + rc = ldap_cancel_s( ld, msgid, NULL, NULL ); + fprintf( stderr, "got interrupt, cancel got %d: %s\n", + rc, ldap_err2string( rc ) ); + return -1; + + case 1: + rc = ldap_abandon( ld, msgid ); + fprintf( stderr, "got interrupt, abandon got %d: %s\n", + rc, ldap_err2string( rc ) ); + return -1; + } + if( sortattr ) { (void) ldap_sort_entries( ld, &res, ( *sortattr == '\0' ) ? NULL : sortattr, strcasecmp ); @@ -1118,27 +1128,13 @@ static int dosearch( ldap_msgfree( res ); } -#if defined(TEST_ABANDON) || defined(TEST_CANCEL) - if ( gotintr ) { -#ifdef TEST_CANCEL - rc = ldap_cancel_s( ld, msgid, NULL, NULL ); - fprintf( stderr, "got interrupt, cancel got %d\n", rc ); - return -1; -#endif -#ifdef TEST_ABANDON - rc = ldap_abandon( ld, msgid ); - fprintf( stderr, "got interrupt, abandon got %d\n", rc ); - return -1; -#endif - } -#endif +done: if ( rc == -1 ) { ldap_perror( ld, "ldap_result" ); return( rc ); } -done: ldap_msgfree( res ); #ifdef LDAP_CONTROL_PAGEDRESULTS if ( pagedResults ) { diff --git a/doc/devel/args b/doc/devel/args index a9dd91ebf7..5c637fc85e 100644 --- a/doc/devel/args +++ b/doc/devel/args @@ -1,11 +1,11 @@ Tools ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz -ldapcompare * DE**HI*K M*OPQR UVWXYZ de *h**k *n*p* vwxyz +ldapcompare * DE**HI*K M*OPQR UVWXYZ de *h**k *n*p* vwxyz ldapdelete *CDE**HI*K M*OPQR UVWXYZ cdef*h**k *n*p* vwxy ldapmodify *CDE**HI*K M*OPQRS UVWXYZabcde *h**k *n*p*r t vwxy ldapmodrdn *CDE**HI*K M*OPQR UVWXYZ cdef*h**k *n*p*rs vwxy ldappasswd A*CDE**HI* *O QRS UVWXYZa def*h** * * * s vwxy -ldapsearch A*CDE**HI*KLM*OPQRSTUVWXYZab*def*h**kl*n*p* stuvwxyz -ldapwhoami * DE**HI* *O QR UVWXYZ def*h** *n*p* vwxy +ldapsearch A*CDE**HI*KLM*OPQRSTUVWXYZabcdef*h**kl*n*p* stuvwxyz +ldapwhoami * DE**HI* *O QR UVWXYZ def*h** *n*p* vwxy * reserved diff --git a/doc/man/man1/ldapsearch.1 b/doc/man/man1/ldapsearch.1 index cdb952bb67..1086110b01 100644 --- a/doc/man/man1/ldapsearch.1 +++ b/doc/man/man1/ldapsearch.1 @@ -9,6 +9,8 @@ ldapsearch \- LDAP search tool [\c .BR \-n ] [\c +.BR \-c ] +[\c .BR \-u ] [\c .BR \-v ] @@ -99,6 +101,13 @@ If no \fIattrs\fP are listed, all user attributes are returned. If only Show what would be done, but don't actually perform the search. Useful for debugging in conjunction with -v. .TP +.B \-c +Trap SIGINT and issue an +.B abandon +operation (if the switch appears once), or a +.B cancel +extended operation (if the switch appears twice). +.TP .B \-u Include the User Friendly Name form of the Distinguished Name (DN) in the output. -- 2.39.5