3 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
7 * Copyright (c) 1992, 1993 Regents of the University of Michigan.
10 * Redistribution and use in source and binary forms are permitted
11 * provided that this notice is preserved and that due credit is given
12 * to the University of Michigan at Ann Arbor. The name of the University
13 * may not be used to endorse or promote products derived from this
14 * software without specific prior written permission. This software
15 * is provided ``as is'' without express or implied warranty.
22 #include <ac/stdlib.h>
25 #include <ac/signal.h>
26 #include <ac/string.h>
27 #include <ac/termios.h>
29 #include <ac/unistd.h>
31 #ifdef NEED_GETPASSPHRASE
44 #include "ldap_defaults.h"
47 lutil_getpass( const char *prompt )
49 #if !defined(HAVE_POSIX_TERMIOS) && !defined(HAVE_SGTTY_H)
53 if( prompt == NULL ) prompt = "Password: ";
57 printf("->getpass(%s)\n", prompt);
62 while ( (c = getch()) != EOF && c != '\n' && c != '\r' )
73 static char pbuf[513];
77 RETSIGTYPE (*sig)( int sig );
79 if( prompt == NULL ) prompt = "Password: ";
83 printf("->getpass(%s)\n", prompt);
86 * Stolen from the getpass() routine. Can't use the plain
87 * getpass() for two reasons. One is that LDAP passwords
88 * can be really, really long - much longer than 8 chars.
89 * The second is that we like to make this client available
90 * out of inetd via a Merit asynch port, and we need to be
91 * able to do telnet control codes to turn on and off line
94 if ((fi = fdopen(open("/dev/tty", 2), "r")) == NULL)
97 setbuf(fi, (char *)NULL);
98 sig = SIGNAL (SIGINT, SIG_IGN);
100 if (GETATTR(fileno(fi), &ttyb) < 0)
103 flags = GETFLAGS( ttyb );
104 SETFLAGS( ttyb, flags & ~ECHO );
106 if (SETATTR(fileno(fi), &ttyb) < 0)
110 /* blank the line if through Merit */
112 printf("%c%c%c", 255, 251, 1);
114 (void) scanf("%c%c%c", &i, &j, &k);
118 /* fetch the password */
119 fprintf(stdout, "%s", prompt);
121 for (p=pbuf; (c = getc(fi))!='\n' && c!=EOF;) {
131 if (*(p - 1) == '\r')
135 /* unblank the line if through Merit */
137 printf("%c%c%c", 255, 252, 1);
139 (void) scanf("%c%c%c", &i, &j, &k);
141 printf("\n"); fflush(stdout);
143 fprintf(stdout, "\n");
147 SETFLAGS( ttyb, flags );
149 if (SETATTR(fileno(fi), &ttyb) < 0)
152 (void) SIGNAL (SIGINT, sig);
163 #endif /* !NEED_GETPASSPHRASE */