@matheusbsbs / matheus-bagliano / commits / 2363d7467d
Fork 0

git-send-email: ssh/login style password requests

Whilst convenient, it is most unwise to record passwords in any place but one's brain. Moreover, it is especially foolish to store them in configuration files, even with access permissions set accordingly. git-send-email has been amended, so that if it detects an smtp username without a password, it promptly prompts for the password and masks the input for privacy. Furthermore, the argument to --smtp-pass has been rendered optional. The documentation has been updated to reflect these changes. Signed-off-by: Michael Witten <mfwitten@mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Michael Witten committed Feb 3, 2008 at 19:53 UTC 2363d7467dcd60467b3e694b3ba6f859bb226f5c
2 files changed +55 -9
Documentation/git-send-email.txt
+34 -5
@@ -96,11 +96,40 @@ The --cc option must be repeated for each user you want on the cc list.
96 servers typically listen to smtp port 25 and ssmtp port
97 465).
98
99 ---smtp-user, --smtp-pass::
100 - Username and password for SMTP-AUTH. Defaults are the values of
101 - the configuration values 'sendemail.smtpuser' and
102 - 'sendemail.smtppass', but see also 'sendemail.identity'.
103 - If not set, authentication is not attempted.
99 +--smtp-user::
100 + Username for SMTP-AUTH. In place of this option, the following
101 + configuration variables can be specified:
102 ++
103 +--
104 + * sendemail.smtpuser
105 + * sendemail.<identity>.smtpuser (see sendemail.identity).
106 +--
107 ++
108 +However, --smtp-user always overrides these variables.
109 ++
110 +If a username is not specified (with --smtp-user or a
111 +configuration variable), then authentication is not attempted.
112 +
113 +--smtp-pass::
114 + Password for SMTP-AUTH. The argument is optional: If no
115 + argument is specified, then the empty string is used as
116 + the password.
117 ++
118 +In place of this option, the following configuration variables
119 +can be specified:
120 ++
121 +--
122 + * sendemail.smtppass
123 + * sendemail.<identity>.smtppass (see sendemail.identity).
124 +--
125 ++
126 +However, --smtp-pass always overrides these variables.
127 ++
128 +Furthermore, passwords need not be specified in configuration files
129 +or on the command line. If a username has been specified (with
130 +--smtp-user or a configuration variable), but no password has been
131 +specified (with --smtp-pass or a configuration variable), then the
132 +user is prompted for a password while the input is masked for privacy.
133
134 --smtp-ssl::
135 If set, connects to the SMTP server using SSL.
git-send-email.perl
+21 -4
@@ -157,7 +157,7 @@ my $compose_filename = ".msg.$$";
157
158 # Variables we fill in automatically, or via prompting:
159 my (@to,@cc,@initial_cc,@bcclist,@xh,
160 - $initial_reply_to,$initial_subject,@files,$author,$sender,$compose,$time);
160 + $initial_reply_to,$initial_subject,@files,$author,$sender,$smtp_authpass,$compose,$time);
161
162 my $envelope_sender;
163
@@ -177,7 +177,7 @@ my ($quiet, $dry_run) = (0, 0);
177
178 # Variables with corresponding config settings
179 my ($thread, $chain_reply_to, $suppress_from, $signed_off_cc, $cc_cmd);
180 -my ($smtp_server, $smtp_server_port, $smtp_authuser, $smtp_authpass, $smtp_ssl);
180 +my ($smtp_server, $smtp_server_port, $smtp_authuser, $smtp_ssl);
181 my ($identity, $aliasfiletype, @alias_files, @smtp_host_parts);
182 my ($no_validate);
183
@@ -214,7 +214,7 @@ my $rc = GetOptions("sender|from=s" => \$sender,
214 "smtp-server=s" => \$smtp_server,
215 "smtp-server-port=s" => \$smtp_server_port,
216 "smtp-user=s" => \$smtp_authuser,
217 - "smtp-pass=s" => \$smtp_authpass,
217 + "smtp-pass:s" => \$smtp_authpass,
218 "smtp-ssl!" => \$smtp_ssl,
219 "identity=s" => \$identity,
220 "compose" => \$compose,
@@ -647,9 +647,26 @@ X-Mailer: git-send-email $gitversion
647 die "Unable to initialize SMTP properly. Is there something wrong with your config?";
648 }
649
650 - if ((defined $smtp_authuser) && (defined $smtp_authpass)) {
650 + if (defined $smtp_authuser) {
651 +
652 + if (!defined $smtp_authpass) {
653 +
654 + system "stty -echo";
655 +
656 + do {
657 + print "Password: ";
658 + $_ = <STDIN>;
659 + print "\n";
660 + } while (!defined $_);
661 +
662 + chomp($smtp_authpass = $_);
663 +
664 + system "stty echo";
665 + }
666 +
667 $auth ||= $smtp->auth( $smtp_authuser, $smtp_authpass ) or die $smtp->message;
668 }
669 +
670 $smtp->mail( $raw_from ) or die $smtp->message;
671 $smtp->to( @recipients ) or die $smtp->message;
672 $smtp->data or die $smtp->message;