+/* $OpenLDAP$ */
+/*
+ * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
+ * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+ */
/*
* Copyright (c) 1992, 1993 Regents of the University of Michigan.
* All rights reserved.
#include "portable.h"
#include <stdio.h>
-#include <stdlib.h>
+
+#include <ac/stdlib.h>
#include <ac/ctype.h>
#include <ac/errno.h>
#include <ac/time.h>
#include <ac/unistd.h>
-#ifdef HAVE_FCNTL_H
-#include <fcntl.h>
-#endif
-
-#ifdef HAVE_CONIO_H
-#include <conio.h>
-#endif
-
#include <lber.h>
#include <ldap.h>
-#include <ldapconfig.h>
+#include "ldap_defaults.h"
#include "ud.h"
-char *
-mygetpass( char *prompt )
-{
-#if !defined(HAVE_TERMIOS) && !defined(HAVE_SGTTY_H)
- static char buf[256];
- int i, c;
-
-#ifdef DEBUG
- if (debug & D_TRACE)
- printf("->mygetpass(%s)\n", prompt);
-#endif
- printf("%s", prompt);
- i = 0;
- while ( (c = getch()) != EOF && c != '\n' && c != '\r' )
- buf[i++] = c;
- if ( c == EOF )
- return( NULL );
- buf[i] = '\0';
- return (buf);
-#else
- int no_pass = 0;
- char i, j, k;
- TERMIO_TYPE ttyb;
- TERMFLAG_TYPE flags;
- static char pbuf[513];
- register char *p;
- register int c;
- FILE *fi;
- RETSIGTYPE (*sig)( int sig );
-
-#ifdef DEBUG
- if (debug & D_TRACE)
- printf("->mygetpass(%s)\n", prompt);
-#endif
- /*
- * Stolen from the getpass() routine. Can't use the plain
- * getpass() for two reasons. One is that LDAP passwords
- * can be really, really long - much longer than 8 chars.
- * The second is that we like to make this client available
- * out of inetd via a Merit asynch port, and we need to be
- * able to do telnet control codes to turn on and off line
- * blanking.
- */
- if ((fi = fdopen(open("/dev/tty", 2), "r")) == NULL)
- fi = stdin;
- else
- setbuf(fi, (char *)NULL);
- sig = SIGNAL (SIGINT, SIG_IGN);
- if (fi != stdin) {
- if (GETATTR(fileno(fi), &ttyb) < 0)
- perror("GETATTR");
- }
- flags = GETFLAGS( ttyb );
- SETFLAGS( ttyb, flags & ~ECHO );
- if (fi != stdin) {
- if (SETATTR(fileno(fi), &ttyb) < 0)
- perror("SETATTR");
- }
-
- /* blank the line if through Merit */
- if (fi == stdin) {
- printf("%c%c%c", 255, 251, 1);
- fflush(stdout);
- (void) scanf("%c%c%c", &i, &j, &k);
- fflush(stdin);
- }
-
- /* fetch the password */
- fprintf(stdout, "%s", prompt);
- fflush(stdout);
- for (p=pbuf; (c = getc(fi))!='\n' && c!=EOF;) {
- if (c == '\r')
- break;
- if (p < &pbuf[512])
- *p++ = c;
- }
- if (c == EOF)
- no_pass = 1;
- else {
- *p = '\0';
- if (*(p - 1) == '\r')
- *(p - 1) = '\0';
- }
-
- /* unblank the line if through Merit */
- if (fi == stdin) {
- printf("%c%c%c", 255, 252, 1);
- fflush(stdout);
- (void) scanf("%c%c%c", &i, &j, &k);
- fflush(stdin);
- printf("\n"); fflush(stdout);
- }
- fprintf(stdout, "\n");
- fflush(stdout);
-
- /* tidy up */
- SETFLAGS( ttyb, flags );
- if (fi != stdin) {
- if (SETATTR(fileno(fi), &ttyb) < 0)
- perror("SETATTR");
- }
- (void) SIGNAL (SIGINT, sig);
- if (fi != stdin)
- (void) fclose(fi);
- else
- i = getchar();
- if (no_pass)
- return(NULL);
- return(pbuf);
-#endif /* DOS */
-}
-
void
printbase( char *lead, char *s )
{
errno = 0; /* so fatal() doesn't bitch */
fatal("fgets");
}
- for (i = strlen(buffer) - 1; i >= 0 && !isprint(buffer[i]); i--)
+ for (i = strlen(buffer) - 1;
+ i >= 0 && !isprint((unsigned char) buffer[i]); i--)
buffer[i] = '\0';
p = buffer;
while ( *p != '\0' ) {
- if ( isprint( *p )) {
+ if ( isprint( (unsigned char) *p )) {
++p;
} else {
- strcpy( p, p + 1 );
+ SAFEMEMCPY( p, p + 1, strlen( p + 1 ) + 1 );
}
}
{
if (errno != 0)
perror(s);
-#ifdef HAVE_KERBEROS
+#ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
destroy_tickets();
#endif
- exit(-1);
+ exit( EXIT_FAILURE );
}
int
*/
s = original = strdup(str);
for (;;) {
- if ((strlen(s) + lead) < width) {
+ if (((int) strlen(s) + lead) < width) {
printf("%s%s\n", leader, s);
Free(leader);
Free(original);
/*NOTREACHED*/
}
cp = s + width - lead;
- while (!isspace(*cp) && (cp != s))
+ while (!isspace((unsigned char)*cp) && (cp != s))
cp--;
*cp = '\0';
- while (isspace(*s))
+ while (isspace((unsigned char)*s))
s++;
printf("%s%s\n", leader, s);
s = cp + 1;
i = "";
/* now do the first line */
- if ((strlen(s) + strlen(first_tag) + first_indent) < width) {
+ if (((int) strlen(s) + (int) strlen(first_tag) + first_indent) < width) {
printf("%s%s%s\n", fi, first_tag, s);
Free(fi);
Free(i);
* back it up to the first space character.
*/
cp = s + width - first_indent - strlen(first_tag);
- while (!isspace(*cp) && (cp != s))
+ while (!isspace((unsigned char)*cp) && (cp != s))
cp--;
/*
* as well. We should gobble up all of these since we don't want
* unexpected leading blanks.
*/
- for (s = cp + 1; isspace(*s); s++)
+ for (s = cp + 1; isspace((unsigned char)*s); s++)
;
/* now do all of the other lines */
for (;;) {
- if ((strlen(s) + strlen(tag) + indent) < width) {
+ if (((int) strlen(s) + (int) strlen(tag) + indent) < width) {
printf("%s%s%s\n", i, tag, s);
Free(fi);
Free(i);
/*NOTREACHED*/
}
cp = s + width - indent - strlen(tag);
- while (!isspace(*cp) && (cp != s))
+ while (!isspace((unsigned char)*cp) && (cp != s))
cp--;
c = *cp;
*cp = '\0';
char *
friendly_name( char *s )
{
- static FriendlyMap *map = NULL;
+ static LDAPFriendlyMap *map = NULL;
static char *cp;
cp = ldap_friendly_name(FRIENDLYFILE, s, &map);
if ((i < 3) || (i > 8)) /* uniqnames are 3-8 chars */
return(FALSE);
- if (!isalpha(*s)) /* uniqnames begin with a letter */
+ if (!isalpha((unsigned char)*s)) /* uniqnames begin with a letter */
return(FALSE);
for ( ; *s != '\0'; s++) /* uniqnames are alphanumeric */
- if (!isalnum(*s))
+ if (!isalnum((unsigned char)*s))
return(FALSE);
return(TRUE);
}
char *
my_ldap_dn2ufn( char *s )
{
+#ifdef UD_BASE
register char **cpp;
static char short_DN[BUFSIZ];
- if (strstr(s, NULL) == NULL)
+ if (strstr(s, UD_BASE) == NULL)
return(ldap_dn2ufn(s));
cpp = ldap_explode_dn(s, TRUE);
sprintf(short_DN, "%s, %s", *cpp, *(cpp + 1));
ldap_value_free(cpp);
return(short_DN);
+#else
+ return(ldap_dn2ufn(s));
+#endif
}
/* return TRUE if this attribute should be printed as a URL */
void_ptr = (void *) malloc(size);
if (void_ptr == NULL) {
perror("malloc");
- exit(-1);
+ exit( EXIT_FAILURE );
/*NOTREACHED*/
}
return(void_ptr);
void
Free( void *ptr )
{
-#ifndef STDC_HEADERS
- if (free(ptr) < 0) {
- perror("free");
- exit(-1);
- /*NOTREACHED*/
- }
-#else
free(ptr);
-#endif
- return;
}
char *
nextstr( char *s )
{
- while (isspace(*s) && (*s != '\0'))
+ while (isspace((unsigned char) *s) && (*s != '\0'))
s++;
if (s == NULL)
return(NULL);