2 * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
3 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6 * Copyright (c) 1992, 1993 Regents of the University of Michigan.
9 * Redistribution and use in source and binary forms are permitted
10 * provided that this notice is preserved and that due credit is given
11 * to the University of Michigan at Ann Arbor. The name of the University
12 * may not be used to endorse or promote products derived from this
13 * software without specific prior written permission. This software
14 * is provided ``as is'' without express or implied warranty.
23 #include <ac/stdlib.h>
26 #include <ac/signal.h>
27 #include <ac/string.h>
28 #include <ac/termios.h>
30 #include <ac/unistd.h>
43 #include "ldap_defaults.h"
46 getpass( const char *prompt )
48 #if !defined(HAVE_POSIX_TERMIOS) && !defined(HAVE_SGTTY_H)
54 printf("->getpass(%s)\n", prompt);
58 while ( (c = getch()) != EOF && c != '\n' && c != '\r' )
69 static char pbuf[513];
73 RETSIGTYPE (*sig)( int sig );
77 printf("->getpass(%s)\n", prompt);
80 * Stolen from the getpass() routine. Can't use the plain
81 * getpass() for two reasons. One is that LDAP passwords
82 * can be really, really long - much longer than 8 chars.
83 * The second is that we like to make this client available
84 * out of inetd via a Merit asynch port, and we need to be
85 * able to do telnet control codes to turn on and off line
88 if ((fi = fdopen(open("/dev/tty", 2), "r")) == NULL)
91 setbuf(fi, (char *)NULL);
92 sig = SIGNAL (SIGINT, SIG_IGN);
94 if (GETATTR(fileno(fi), &ttyb) < 0)
97 flags = GETFLAGS( ttyb );
98 SETFLAGS( ttyb, flags & ~ECHO );
100 if (SETATTR(fileno(fi), &ttyb) < 0)
104 /* blank the line if through Merit */
106 printf("%c%c%c", 255, 251, 1);
108 (void) scanf("%c%c%c", &i, &j, &k);
112 /* fetch the password */
113 fprintf(stdout, "%s", prompt);
115 for (p=pbuf; (c = getc(fi))!='\n' && c!=EOF;) {
125 if (*(p - 1) == '\r')
129 /* unblank the line if through Merit */
131 printf("%c%c%c", 255, 252, 1);
133 (void) scanf("%c%c%c", &i, &j, &k);
135 printf("\n"); fflush(stdout);
137 fprintf(stdout, "\n");
141 SETFLAGS( ttyb, flags );
143 if (SETATTR(fileno(fi), &ttyb) < 0)
146 (void) SIGNAL (SIGINT, sig);
157 #endif /* !HAVE_GETPASS */