3 * Copyright 1998-1999 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.
24 #include <ac/stdlib.h>
27 #include <ac/signal.h>
28 #include <ac/string.h>
29 #include <ac/termios.h>
31 #include <ac/unistd.h>
44 #include "ldap_defaults.h"
47 getpass( const char *prompt )
49 #if !defined(HAVE_POSIX_TERMIOS) && !defined(HAVE_SGTTY_H)
55 printf("->getpass(%s)\n", prompt);
59 while ( (c = getch()) != EOF && c != '\n' && c != '\r' )
70 static char pbuf[513];
74 RETSIGTYPE (*sig)( int sig );
78 printf("->getpass(%s)\n", prompt);
81 * Stolen from the getpass() routine. Can't use the plain
82 * getpass() for two reasons. One is that LDAP passwords
83 * can be really, really long - much longer than 8 chars.
84 * The second is that we like to make this client available
85 * out of inetd via a Merit asynch port, and we need to be
86 * able to do telnet control codes to turn on and off line
89 if ((fi = fdopen(open("/dev/tty", 2), "r")) == NULL)
92 setbuf(fi, (char *)NULL);
93 sig = SIGNAL (SIGINT, SIG_IGN);
95 if (GETATTR(fileno(fi), &ttyb) < 0)
98 flags = GETFLAGS( ttyb );
99 SETFLAGS( ttyb, flags & ~ECHO );
101 if (SETATTR(fileno(fi), &ttyb) < 0)
105 /* blank the line if through Merit */
107 printf("%c%c%c", 255, 251, 1);
109 (void) scanf("%c%c%c", &i, &j, &k);
113 /* fetch the password */
114 fprintf(stdout, "%s", prompt);
116 for (p=pbuf; (c = getc(fi))!='\n' && c!=EOF;) {
126 if (*(p - 1) == '\r')
130 /* unblank the line if through Merit */
132 printf("%c%c%c", 255, 252, 1);
134 (void) scanf("%c%c%c", &i, &j, &k);
136 printf("\n"); fflush(stdout);
138 fprintf(stdout, "\n");
142 SETFLAGS( ttyb, flags );
144 if (SETATTR(fileno(fi), &ttyb) < 0)
147 (void) SIGNAL (SIGINT, sig);
158 #endif /* !HAVE_GETPASS */