2 * Copyright (c) 1992, 1993 Regents of the University of Michigan.
5 * Redistribution and use in source and binary forms are permitted
6 * provided that this notice is preserved and that due credit is given
7 * to the University of Michigan at Ann Arbor. The name of the University
8 * may not be used to endorse or promote products derived from this
9 * software without specific prior written permission. This software
10 * is provided ``as is'' without express or implied warranty.
19 #include <ac/stdlib.h>
22 #include <ac/signal.h>
23 #include <ac/string.h>
24 #include <ac/termios.h>
26 #include <ac/unistd.h>
39 #include "ldap_defaults.h"
42 getpass( const char *prompt )
44 #if !defined(HAVE_POSIX_TERMIOS) && !defined(HAVE_SGTTY_H)
50 printf("->getpass(%s)\n", prompt);
54 while ( (c = getch()) != EOF && c != '\n' && c != '\r' )
65 static char pbuf[513];
69 RETSIGTYPE (*sig)( int sig );
73 printf("->getpass(%s)\n", prompt);
76 * Stolen from the getpass() routine. Can't use the plain
77 * getpass() for two reasons. One is that LDAP passwords
78 * can be really, really long - much longer than 8 chars.
79 * The second is that we like to make this client available
80 * out of inetd via a Merit asynch port, and we need to be
81 * able to do telnet control codes to turn on and off line
84 if ((fi = fdopen(open("/dev/tty", 2), "r")) == NULL)
87 setbuf(fi, (char *)NULL);
88 sig = SIGNAL (SIGINT, SIG_IGN);
90 if (GETATTR(fileno(fi), &ttyb) < 0)
93 flags = GETFLAGS( ttyb );
94 SETFLAGS( ttyb, flags & ~ECHO );
96 if (SETATTR(fileno(fi), &ttyb) < 0)
100 /* blank the line if through Merit */
102 printf("%c%c%c", 255, 251, 1);
104 (void) scanf("%c%c%c", &i, &j, &k);
108 /* fetch the password */
109 fprintf(stdout, "%s", prompt);
111 for (p=pbuf; (c = getc(fi))!='\n' && c!=EOF;) {
121 if (*(p - 1) == '\r')
125 /* unblank the line if through Merit */
127 printf("%c%c%c", 255, 252, 1);
129 (void) scanf("%c%c%c", &i, &j, &k);
131 printf("\n"); fflush(stdout);
133 fprintf(stdout, "\n");
137 SETFLAGS( ttyb, flags );
139 if (SETATTR(fileno(fi), &ttyb) < 0)
142 (void) SIGNAL (SIGINT, sig);
153 #endif /* !HAVE_GETPASS */