]> git.sur5r.net Git - openldap/blobdiff - clients/finger/main.c
Added dnPretty2/dnNormalize2 using preallocated destination berval
[openldap] / clients / finger / main.c
index d172380fad0405397468c8a91f5997b2d934d9b9..ec2a07460e867722c8c5b70cfc9755292831818a 100644 (file)
@@ -1,3 +1,4 @@
+/* $OpenLDAP$ */
 /*
  * Copyright (c) 1990,1994 Regents of the University of Michigan.
  * All rights reserved.
 #include <sys/resource.h>
 #endif
 
-#include "lber.h"
-#include "ldap.h"
-
-#include "disptmpl.h"
+#include <ldap.h>
+#include <disptmpl.h>
 
 #include "ldap_defaults.h"
 
@@ -53,8 +52,8 @@ static void do_read(LDAP *ld, LDAPMessage *e);
 static void
 usage( char *name )
 {
-       fprintf( stderr, "usage: %s [-l] [-x ldaphost] [-p ldapport] [-f filterfile] [-t templatefile] [-c rdncount]\r\n", name );
-       exit( 1 );
+       fprintf( stderr, "usage: %s [-l] [-x ldaphost] [-p ldapport] [-b searchbase] [-f filterfile] [-t templatefile] [-c rdncount]\r\n", name );
+       exit( EXIT_FAILURE );
 }
 
 int
@@ -64,11 +63,11 @@ main( int argc, char **argv )
        char                    *myname;
        struct hostent          *hp;
        struct sockaddr_in      peername;
-       int                     peernamelen;
+       socklen_t               peernamelen;
        int                     interactive = 0;
 
        deref = FINGER_DEREF;
-       while ( (i = getopt( argc, argv, "f:ilp:t:x:p:c:" )) != EOF ) {
+       while ( (i = getopt( argc, argv, "f:ilp:t:x:p:b:c:" )) != EOF ) {
                switch( i ) {
                case 'f':       /* ldap filter file */
                        filterfile = strdup( optarg );
@@ -94,6 +93,10 @@ main( int argc, char **argv )
                        ldapport = atoi( optarg );
                        break;
 
+               case 'b':       /* specify search base */
+                       base = strdup( optarg );
+                       break; 
+
                case 'c':       /* specify number of DN components to show */
                        rdncount = atoi( optarg );
                        break;
@@ -108,7 +111,7 @@ main( int argc, char **argv )
                if ( getpeername( 0, (struct sockaddr *)&peername,
                    &peernamelen ) != 0 ) {
                        perror( "getpeername" );
-                       exit( 1 );
+                       exit( EXIT_FAILURE );
                }
        }
 
@@ -119,7 +122,7 @@ main( int argc, char **argv )
        }
 #endif
 
-       if ( (myname = strrchr( argv[0], '/' )) == NULL )
+       if ( (myname = strrchr( argv[0], *LDAP_DIRSEP )) == NULL )
                myname = strdup( argv[0] );
        else
                myname = strdup( myname + 1 );
@@ -131,14 +134,14 @@ main( int argc, char **argv )
        if ( dosyslog ) {
 #ifdef LOG_LOCAL4
                openlog( myname, OPENLOG_OPTIONS, LOG_LOCAL4 );
-#else
+#elif LOG_DEBUG
                openlog( myname, OPENLOG_OPTIONS );
 #endif
        }
 
        if ( dosyslog && !interactive ) {
-               hp = gethostbyaddr( (char *) &peername.sin_addr.s_addr,
-                                   sizeof(peername.sin_addr.s_addr), AF_INET );
+               hp = gethostbyaddr( (char *) &peername.sin_addr,
+                                   sizeof(peername.sin_addr), AF_INET );
                syslog( LOG_INFO, "connection from %s (%s)",
                        (hp == NULL) ? "unknown" : hp->h_name,
                        inet_ntoa( peername.sin_addr ) );
@@ -161,7 +164,7 @@ do_query( void )
        if ( (ld = ldap_init( ldaphost, ldapport )) == NULL ) {
                fprintf( stderr, FINGER_UNAVAILABLE );
                perror( "ldap_init" );
-               exit( 1 );
+               exit( EXIT_FAILURE );
        }
 
        {
@@ -175,7 +178,7 @@ do_query( void )
        {
                fprintf( stderr, FINGER_UNAVAILABLE );
                ldap_perror( ld, "ldap_simple_bind_s" );
-               exit( 1 );
+               exit( EXIT_FAILURE );
        }
 
 #ifdef HAVE_SYSCONF
@@ -202,11 +205,11 @@ do_query( void )
                        perror( "select" );
                else
                        fprintf( stderr, "connection timed out on input\r\n" );
-               exit( 1 );
+               exit( EXIT_FAILURE );
        }
 
        if ( fgets( buf, sizeof(buf), stdin ) == NULL )
-               exit( 1 );
+               exit( EXIT_FAILURE );
 
        len = strlen( buf );
 
@@ -256,10 +259,10 @@ do_search( LDAP *ld, char *buf )
 {
        char            *dn, *rdn;
        char            **title;
-       int             rc, matches, i, ufn;
+       int             rc = 0, matches = 0, i;
        struct timeval  tv;
        LDAPFiltDesc    *fd;
-       LDAPFiltInfo    *fi;
+       LDAPFiltInfo    *fi = NULL;
        LDAPMessage     *result, *e;
        static char     *attrs[] = { "cn", "title", "objectClass", "joinable",
 #ifdef FINGER_SORT_ATTR
@@ -267,30 +270,11 @@ do_search( LDAP *ld, char *buf )
 #endif
                                        0 };
 
-       ufn = 0;
-#ifdef FINGER_UFN
-       if ( strchr( buf, ',' ) != NULL ) {
-               ldap_ufn_setprefix( ld, base );
-               tv.tv_sec = FINGER_TIMEOUT;
-               tv.tv_usec = 0;
-               ldap_ufn_timeout( (void *) &tv );
-
-               if ( (rc = ldap_ufn_search_s( ld, buf, attrs, 0, &result ))
-                   != LDAP_SUCCESS && rc != LDAP_SIZELIMIT_EXCEEDED ) {
-                       fprintf( stderr, FINGER_UNAVAILABLE );
-                       ldap_perror( ld, "ldap_search_st" );
-                       exit( 1 );
-               }
-
-               matches = ldap_count_entries( ld, result );
-               ufn = 1;
-       } else {
-#endif
                if ( (fd = ldap_init_getfilter( filterfile ))
                    == NULL ) {
                        fprintf( stderr, "Cannot open filter file (%s)\n",
                            filterfile );
-                       exit( 1 );
+                       exit( EXIT_FAILURE );
                }
 
                for ( fi = ldap_getfirstfilter( fd, "finger", buf );
@@ -306,7 +290,7 @@ do_search( LDAP *ld, char *buf )
                        {
                                fprintf( stderr, FINGER_UNAVAILABLE );
                                ldap_perror( ld, "ldap_search_st" );
-                               exit( 1 );
+                               exit( EXIT_FAILURE );
                        }
 
                        if ( (matches = ldap_count_entries( ld, result )) != 0 )
@@ -315,9 +299,6 @@ do_search( LDAP *ld, char *buf )
                        ldap_msgfree( result );
                        result = NULL;
                }
-#ifdef FINGER_UFN
-       }
-#endif
 
        if ( rc == LDAP_SIZELIMIT_EXCEEDED ) {
                printf( "(Partial results - a size limit was exceeded)\r\n" );
@@ -330,10 +311,10 @@ do_search( LDAP *ld, char *buf )
                fflush( stdout );
        } else if ( matches < 0 ) {
                fprintf( stderr, "error return from ldap_count_entries\r\n" );
-               exit( 1 );
+               exit( EXIT_FAILURE );
        } else if ( matches <= FINGER_LISTLIMIT ) {
                printf( "%d %s match%s found for \"%s\":\r\n", matches,
-                   ufn ? "UFN" : fi->lfi_desc, matches > 1 ? "es" : "", buf );
+                   fi->lfi_desc, matches > 1 ? "es" : "", buf );
                fflush( stdout );
 
                for ( e = ldap_first_entry( ld, result ); e != NULL; ) {
@@ -345,7 +326,7 @@ do_search( LDAP *ld, char *buf )
                }
        } else {
                printf( "%d %s matches for \"%s\":\r\n", matches,
-                   ufn ? "UFN" : fi->lfi_desc, buf );
+                   fi->lfi_desc, buf );
                fflush( stdout );
 
 #ifdef FINGER_SORT_ATTR
@@ -431,7 +412,7 @@ do_read( LDAP *ld, LDAPMessage *e )
            defvals, entry2textwrite, (void *)stdout, "\r\n", rdncount,
            LDAP_DISP_OPT_DOSEARCHACTIONS ) != LDAP_SUCCESS ) {
                ldap_perror( ld, "ldap_entry2text_search" );
-               exit( 1 );
+               exit( EXIT_FAILURE );
        }
 
        if ( tmpllist != NULL ) {