+/* $OpenLDAP$ */
/*
* Copyright (c) 1990,1994 Regents of the University of Michigan.
* All rights reserved.
#include "portable.h"
#include <stdio.h>
-#include <stdlib.h>
-#include <ctype.h>
-#include <signal.h>
+#include <ac/stdlib.h>
+
+#include <ac/ctype.h>
+#include <ac/signal.h>
#include <ac/socket.h>
#include <ac/string.h>
#include <ac/syslog.h>
#include <ac/time.h>
#include <ac/unistd.h>
#include <ac/wait.h>
-extern char *strdup (const char *);
-extern int strcasecmp(const char *, const char *);
+#ifdef HAVE_SYS_RESOURCE_H
#include <sys/resource.h>
+#endif
-#include "lber.h"
-#include "ldap.h"
-
-#include "disptmpl.h"
+#include <ldap.h>
+#include <disptmpl.h>
-#include "ldapconfig.h"
+#include "ldap_defaults.h"
int dosyslog = 1;
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
{
int i;
char *myname;
- unsigned long mypeer = -1;
struct hostent *hp;
struct sockaddr_in peername;
- int peernamelen;
+ socklen_t peernamelen;
int interactive = 0;
- extern char *optarg;
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 );
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;
if ( getpeername( 0, (struct sockaddr *)&peername,
&peernamelen ) != 0 ) {
perror( "getpeername" );
- exit( 1 );
+ exit( EXIT_FAILURE );
}
- mypeer = (unsigned long) peername.sin_addr.s_addr;
}
#ifdef FINGER_BANNER
}
#endif
- if ( (myname = strrchr( argv[0], '/' )) == NULL )
+ if ( (myname = strrchr( argv[0], *LDAP_DIRSEP )) == NULL )
myname = strdup( argv[0] );
else
myname = strdup( myname + 1 );
+#ifdef SIGPIPE
+ (void) SIGNAL( SIGPIPE, SIG_IGN );
+#endif
+
if ( dosyslog ) {
#ifdef LOG_LOCAL4
openlog( myname, OPENLOG_OPTIONS, LOG_LOCAL4 );
-#else
+#elif LOG_DEBUG
openlog( myname, OPENLOG_OPTIONS );
#endif
}
- if ( dosyslog && mypeer != (unsigned long) -1 ) {
- struct in_addr addr;
-
- hp = gethostbyaddr( (char *) &mypeer, sizeof(mypeer), AF_INET );
- addr.s_addr = mypeer;
- syslog( LOG_INFO, "connection from %s (%s)", (hp == NULL) ?
- "unknown" : hp->h_name, inet_ntoa( addr ) );
+ if ( dosyslog && !interactive ) {
+ 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 ) );
}
do_query();
fd_set readfds;
LDAP *ld;
- if ( (ld = ldap_open( ldaphost, ldapport )) == NULL ) {
+ if ( (ld = ldap_init( ldaphost, ldapport )) == NULL ) {
fprintf( stderr, FINGER_UNAVAILABLE );
- perror( "ldap_open" );
- exit( 1 );
+ perror( "ldap_init" );
+ exit( EXIT_FAILURE );
}
{
{
fprintf( stderr, FINGER_UNAVAILABLE );
ldap_perror( ld, "ldap_simple_bind_s" );
- exit( 1 );
+ exit( EXIT_FAILURE );
}
#ifdef HAVE_SYSCONF
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 );
p = buf;
}
- for ( ; *p && isspace( *p ); p++ )
+ for ( ; *p && isspace( (unsigned char) *p ); p++ )
; /* NULL */
do_search( ld, p );
{
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
#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 );
{
fprintf( stderr, FINGER_UNAVAILABLE );
ldap_perror( ld, "ldap_search_st" );
- exit( 1 );
+ exit( EXIT_FAILURE );
}
if ( (matches = ldap_count_entries( ld, result )) != 0 )
ldap_msgfree( result );
result = NULL;
}
-#ifdef FINGER_UFN
- }
-#endif
if ( rc == LDAP_SIZELIMIT_EXCEEDED ) {
printf( "(Partial results - a size limit was exceeded)\r\n" );
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; ) {
}
} 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
cn = ldap_get_values( ld, e, "cn" );
for ( i = 0; cn[i] != NULL; i++ ) {
last = strlen( cn[i] ) - 1;
- if ( isdigit( cn[i][last] ) ) {
+ if (isdigit((unsigned char) cn[i][last])) {
rdn = strdup( cn[i] );
break;
}
static int
-entry2textwrite( void *fp, char *buf, int len )
+entry2textwrite( void *fp, char *buf, ber_len_t len )
{
return( fwrite( buf, len, 1, (FILE *)fp ) == 0 ? -1 : len );
}
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 ) {