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>
38 #include <ldap_defaults.h>
41 getpass( const char *prompt )
43 #if !defined(HAVE_POSIX_TERMIOS) && !defined(HAVE_SGTTY_H)
49 printf("->getpass(%s)\n", prompt);
53 while ( (c = getch()) != EOF && c != '\n' && c != '\r' )
64 static char pbuf[513];
68 RETSIGTYPE (*sig)( int sig );
72 printf("->getpass(%s)\n", prompt);
75 * Stolen from the getpass() routine. Can't use the plain
76 * getpass() for two reasons. One is that LDAP passwords
77 * can be really, really long - much longer than 8 chars.
78 * The second is that we like to make this client available
79 * out of inetd via a Merit asynch port, and we need to be
80 * able to do telnet control codes to turn on and off line
83 if ((fi = fdopen(open("/dev/tty", 2), "r")) == NULL)
86 setbuf(fi, (char *)NULL);
87 sig = SIGNAL (SIGINT, SIG_IGN);
89 if (GETATTR(fileno(fi), &ttyb) < 0)
92 flags = GETFLAGS( ttyb );
93 SETFLAGS( ttyb, flags & ~ECHO );
95 if (SETATTR(fileno(fi), &ttyb) < 0)
99 /* blank the line if through Merit */
101 printf("%c%c%c", 255, 251, 1);
103 (void) scanf("%c%c%c", &i, &j, &k);
107 /* fetch the password */
108 fprintf(stdout, "%s", prompt);
110 for (p=pbuf; (c = getc(fi))!='\n' && c!=EOF;) {
120 if (*(p - 1) == '\r')
124 /* unblank the line if through Merit */
126 printf("%c%c%c", 255, 252, 1);
128 (void) scanf("%c%c%c", &i, &j, &k);
130 printf("\n"); fflush(stdout);
132 fprintf(stdout, "\n");
136 SETFLAGS( ttyb, flags );
138 if (SETATTR(fileno(fi), &ttyb) < 0)
141 (void) SIGNAL (SIGINT, sig);
152 #endif /* !HAVE_GETPASS */