@matheusbsbs / matheus-bagliano / commits / 6f729591d1
Fork 0

git-svn: print and flush authentication prompts to STDERR

People that redirect STDOUT output should always see STDERR prompts interactively. STDERR should always be flushed without buffering, so they should always show up. If that is unset, we still explicitly flush by calling STDERR->flush. The svn command-line client prompts to STDERR, too. Signed-off-by: Eric Wong <normalperson@yhbt.net> Signed-off-by: Junio C Hamano <junkio@cox.net>

Eric Wong committed Jan 15, 2007 at 20:15 UTC 6f729591d1f9c52bd1cdd0601b4cc1afc028fbf9
1 file changed +22 -15
git-svn.perl
+22 -15
@@ -1918,7 +1918,8 @@ sub _simple_prompt {
1918 $default_username = $_username if defined $_username;
1919 if (defined $default_username && length $default_username) {
1920 if (defined $realm && length $realm) {
1921 - print "Authentication realm: $realm\n";
1921 + print STDERR "Authentication realm: $realm\n";
1922 + STDERR->flush;
1923 }
1924 $cred->username($default_username);
1925 } else {
@@ -1933,36 +1934,38 @@ sub _simple_prompt {
1934 sub _ssl_server_trust_prompt {
1935 my ($cred, $realm, $failures, $cert_info, $may_save, $pool) = @_;
1936 $may_save = undef if $_no_auth_cache;
1936 - print "Error validating server certificate for '$realm':\n";
1937 + print STDERR "Error validating server certificate for '$realm':\n";
1938 if ($failures & $SVN::Auth::SSL::UNKNOWNCA) {
1938 - print " - The certificate is not issued by a trusted ",
1939 + print STDERR " - The certificate is not issued by a trusted ",
1940 "authority. Use the\n",
1941 " fingerprint to validate the certificate manually!\n";
1942 }
1943 if ($failures & $SVN::Auth::SSL::CNMISMATCH) {
1943 - print " - The certificate hostname does not match.\n";
1944 + print STDERR " - The certificate hostname does not match.\n";
1945 }
1946 if ($failures & $SVN::Auth::SSL::NOTYETVALID) {
1946 - print " - The certificate is not yet valid.\n";
1947 + print STDERR " - The certificate is not yet valid.\n";
1948 }
1949 if ($failures & $SVN::Auth::SSL::EXPIRED) {
1949 - print " - The certificate has expired.\n";
1950 + print STDERR " - The certificate has expired.\n";
1951 }
1952 if ($failures & $SVN::Auth::SSL::OTHER) {
1952 - print " - The certificate has an unknown error.\n";
1953 + print STDERR " - The certificate has an unknown error.\n";
1954 }
1954 - printf( "Certificate information:\n".
1955 + printf STDERR
1956 + "Certificate information:\n".
1957 " - Hostname: %s\n".
1958 " - Valid: from %s until %s\n".
1959 " - Issuer: %s\n".
1960 " - Fingerprint: %s\n",
1961 map $cert_info->$_, qw(hostname valid_from valid_until
1960 - issuer_dname fingerprint) );
1962 + issuer_dname fingerprint);
1963 my $choice;
1964 prompt:
1963 - print $may_save ?
1965 + print STDERR $may_save ?
1966 "(R)eject, accept (t)emporarily or accept (p)ermanently? " :
1967 "(R)eject or accept (t)emporarily? ";
1968 + STDERR->flush;
1969 $choice = lc(substr(<STDIN> || 'R', 0, 1));
1970 if ($choice =~ /^t$/i) {
1971 $cred->may_save(undef);
@@ -1980,7 +1983,8 @@ prompt:
1983 sub _ssl_client_cert_prompt {
1984 my ($cred, $realm, $may_save, $pool) = @_;
1985 $may_save = undef if $_no_auth_cache;
1983 - print "Client certificate filename: ";
1986 + print STDERR "Client certificate filename: ";
1987 + STDERR->flush;
1988 chomp(my $filename = <STDIN>);
1989 $cred->cert_file($filename);
1990 $cred->may_save($may_save);
@@ -1999,13 +2003,14 @@ sub _username_prompt {
2003 my ($cred, $realm, $may_save, $pool) = @_;
2004 $may_save = undef if $_no_auth_cache;
2005 if (defined $realm && length $realm) {
2002 - print "Authentication realm: $realm\n";
2006 + print STDERR "Authentication realm: $realm\n";
2007 }
2008 my $username;
2009 if (defined $_username) {
2010 $username = $_username;
2011 } else {
2008 - print "Username: ";
2012 + print STDERR "Username: ";
2013 + STDERR->flush;
2014 chomp($username = <STDIN>);
2015 }
2016 $cred->username($username);
@@ -2015,7 +2020,8 @@ sub _username_prompt {
2020
2021 sub _read_password {
2022 my ($prompt, $realm) = @_;
2018 - print $prompt;
2023 + print STDERR $prompt;
2024 + STDERR->flush;
2025 require Term::ReadKey;
2026 Term::ReadKey::ReadMode('noecho');
2027 my $password = '';
@@ -2024,7 +2030,8 @@ sub _read_password {
2030 $password .= $key;
2031 }
2032 Term::ReadKey::ReadMode('restore');
2027 - print "\n";
2033 + print STDERR "\n";
2034 + STDERR->flush;
2035 $password;
2036 }
2037