gsi_openssh/source/readpass.c
char *
read_passphrase(const char *prompt, int flags)
{
	char cr = '\r', *askpass = NULL, *ret, buf[1024];
	int rppflags, ttyfd, use_askpass = 0, allow_askpass = 0;
	const char *askpass_hint = NULL;
	const char *s;

	if ((s = getenv("DISPLAY")) != NULL)
		allow_askpass = *s != '\0';
	if ((s = getenv(SSH_ASKPASS_REQUIRE_ENV)) != NULL) {
		if (strcasecmp(s, "force") == 0) {
			use_askpass = 1;
			allow_askpass = 1;
		} else if (strcasecmp(s, "prefer") == 0)
			use_askpass = allow_askpass;
		else if (strcasecmp(s, "never") == 0)
			allow_askpass = 0;
	}

	rppflags = (flags & RP_ECHO) ? RPP_ECHO_ON : RPP_ECHO_OFF;
	if (use_askpass)
		debug_f("requested to askpass");
	else if (flags & RP_USE_ASKPASS)
		use_askpass = 1;
	else if (flags & RP_ALLOW_STDIN) {
		if (!isatty(STDIN_FILENO)) {
			debug_f("stdin is not a tty");
			use_askpass = 1;
		}
	} else {
		rppflags |= RPP_REQUIRE_TTY;
		ttyfd = open(_PATH_TTY, O_RDWR);
		if (ttyfd >= 0) {
			/*
			 * If we're on a tty, ensure that show the prompt at
			 * the beginning of the line. This will hopefully
			 * clobber any password characters the user has
			 * optimistically typed before echo is disabled.
			 */
			(void)write(ttyfd, &cr, 1);
			close(ttyfd);
		} else {
			debug_f("can't open %s: %s", _PATH_TTY,
			    strerror(errno));
			use_askpass = 1;
		}
	}

	if ((flags & RP_USE_ASKPASS) && !allow_askpass)
		return (flags & RP_ALLOW_EOF) ? NULL : xstrdup("");

	if (use_askpass && allow_askpass) {
		if (getenv(SSH_ASKPASS_ENV))
			askpass = getenv(SSH_ASKPASS_ENV);
		else
			askpass = _PATH_SSH_ASKPASS_DEFAULT;
		if ((flags & RP_ASK_PERMISSION) != 0)
			askpass_hint = "confirm";
		if ((ret = ssh_askpass(askpass, prompt, askpass_hint)) == NULL)
			if (!(flags & RP_ALLOW_EOF))
				return xstrdup("");
		return ret;
	}

	if (readpassphrase(prompt, buf, sizeof buf, rppflags) == NULL) {
		if (flags & RP_ALLOW_EOF)
			return NULL;
		return xstrdup("");
	}

	ret = xstrdup(buf);
	explicit_bzero(buf, sizeof(buf));
	return ret;
}
/*
 * Reads a passphrase from /dev/tty with echo turned off/on.  Returns the
 * passphrase (allocated with xmalloc).  Exits if EOF is encountered. If
 * RP_ALLOW_STDIN is set, the passphrase will be read from stdin if no
 * tty is or askpass program is available
 */
Reads a passphrase from /dev/tty with echo turned off/on.  Returns the
passphrase (allocated with xmalloc).  Exits if EOF is encountered. If
RP_ALLOW_STDIN is set, the passphrase will be read from stdin if no
tty is or askpass program is available
Reads a passphrase from / dev / tty with echo turned off / on . Returns the passphrase ( allocated with xmalloc ) . Exits if EOF is encountered . If RP_ALLOW_STDIN is set the passphrase will be read from stdin if no tty is or askpass program is available
char *
read_passphrase(const char *prompt, int flags)
{
	char cr = '\r', *askpass = NULL, *ret, buf[1024];
	int rppflags, ttyfd, use_askpass = 0, allow_askpass = 0;
	const char *askpass_hint = NULL;
	const char *s;
	if ((s = getenv("DISPLAY")) != NULL)
		allow_askpass = *s != '\0';
	if ((s = getenv(SSH_ASKPASS_REQUIRE_ENV)) != NULL) {
		if (strcasecmp(s, "force") == 0) {
			use_askpass = 1;
			allow_askpass = 1;
		} else if (strcasecmp(s, "prefer") == 0)
			use_askpass = allow_askpass;
		else if (strcasecmp(s, "never") == 0)
			allow_askpass = 0;
	}
	rppflags = (flags & RP_ECHO) ? RPP_ECHO_ON : RPP_ECHO_OFF;
	if (use_askpass)
		debug_f("requested to askpass");
	else if (flags & RP_USE_ASKPASS)
		use_askpass = 1;
	else if (flags & RP_ALLOW_STDIN) {
		if (!isatty(STDIN_FILENO)) {
			debug_f("stdin is not a tty");
			use_askpass = 1;
		}
	} else {
		rppflags |= RPP_REQUIRE_TTY;
		ttyfd = open(_PATH_TTY, O_RDWR);
		if (ttyfd >= 0) {
			(void)write(ttyfd, &cr, 1);
			close(ttyfd);
		} else {
			debug_f("can't open %s: %s", _PATH_TTY,
			    strerror(errno));
			use_askpass = 1;
		}
	}
	if ((flags & RP_USE_ASKPASS) && !allow_askpass)
		return (flags & RP_ALLOW_EOF) ? NULL : xstrdup("");
	if (use_askpass && allow_askpass) {
		if (getenv(SSH_ASKPASS_ENV))
			askpass = getenv(SSH_ASKPASS_ENV);
		else
			askpass = _PATH_SSH_ASKPASS_DEFAULT;
		if ((flags & RP_ASK_PERMISSION) != 0)
			askpass_hint = "confirm";
		if ((ret = ssh_askpass(askpass, prompt, askpass_hint)) == NULL)
			if (!(flags & RP_ALLOW_EOF))
				return xstrdup("");
		return ret;
	}
	if (readpassphrase(prompt, buf, sizeof buf, rppflags) == NULL) {
		if (flags & RP_ALLOW_EOF)
			return NULL;
		return xstrdup("");
	}
	ret = xstrdup(buf);
	explicit_bzero(buf, sizeof(buf));
	return ret;
}
char * read_passphrase ( const char * prompt , int flags ) { char cr = ' \r ' , * askpass = NULL , * ret , buf [ 1024 ] ; int rppflags , ttyfd , use_askpass = 0 , allow_askpass = 0 ; const char * askpass_hint = NULL ; const char * s ; if ( ( s = getenv ( " " ) ) != NULL ) allow_askpass = * s != ' \0 ' ; if ( ( s = getenv ( SSH_ASKPASS_REQUIRE_ENV ) ) != NULL ) { if ( strcasecmp ( s , " " ) == 0 ) { use_askpass = 1 ; allow_askpass = 1 ; } else if ( strcasecmp ( s , " " ) == 0 ) use_askpass = allow_askpass ; else if ( strcasecmp ( s , " " ) == 0 ) allow_askpass = 0 ; } rppflags = ( flags & RP_ECHO ) ? RPP_ECHO_ON : RPP_ECHO_OFF ; if ( use_askpass ) debug_f ( " " ) ; else if ( flags & RP_USE_ASKPASS ) use_askpass = 1 ; else if ( flags & RP_ALLOW_STDIN ) { if ( ! isatty ( STDIN_FILENO ) ) { debug_f ( " " ) ; use_askpass = 1 ; } } else { rppflags |= RPP_REQUIRE_TTY ; ttyfd = open ( _PATH_TTY , O_RDWR ) ; if ( ttyfd >= 0 ) { ( void ) write ( ttyfd , & cr , 1 ) ; close ( ttyfd ) ; } else { debug_f ( " " , _PATH_TTY , strerror ( errno ) ) ; use_askpass = 1 ; } } if ( ( flags & RP_USE_ASKPASS ) && ! allow_askpass ) return ( flags & RP_ALLOW_EOF ) ? NULL : xstrdup ( " " ) ; if ( use_askpass && allow_askpass ) { if ( getenv ( SSH_ASKPASS_ENV ) ) askpass = getenv ( SSH_ASKPASS_ENV ) ; else askpass = _PATH_SSH_ASKPASS_DEFAULT ; if ( ( flags & RP_ASK_PERMISSION ) != 0 ) askpass_hint = " " ; if ( ( ret = ssh_askpass ( askpass , prompt , askpass_hint ) ) == NULL ) if ( ! ( flags & RP_ALLOW_EOF ) ) return xstrdup ( " " ) ; return ret ; } if ( readpassphrase ( prompt , buf , sizeof buf , rppflags ) == NULL ) { if ( flags & RP_ALLOW_EOF ) return NULL ; return xstrdup ( " " ) ; } ret = xstrdup ( buf ) ; explicit_bzero ( buf , sizeof ( buf ) ) ; return ret ; }
Reads a passphrase from /dev/tty with echo turned off/on.
Reads a passphrase from / dev / tty with echo turned off / on .
/*
			 * If we're on a tty, ensure that show the prompt at
			 * the beginning of the line. This will hopefully
			 * clobber any password characters the user has
			 * optimistically typed before echo is disabled.
			 */