From mboxrd@z Thu Jan 1 00:00:00 1970 From: Michael Witten Subject: [PATCH 1/3][V.2] git-send-email: ssh/login style password requests Date: Sun, 3 Feb 2008 19:53:56 -0500 Message-ID: <1202086438-16251-1-git-send-email-mfwitten@mit.edu> References: <5C100A3B-0B4A-4D4E-B68B-1A54674A795A@mit.edu> Cc: git@vger.kernel.org, Michael Witten To: gitster@pobox.com X-From: git-owner@vger.kernel.org Mon Feb 04 01:59:15 2008 Return-path: Envelope-to: gcvg-git-2@gmane.org Received: from vger.kernel.org ([209.132.176.167]) by lo.gmane.org with esmtp (Exim 4.50) id 1JLpg2-0003T4-U8 for gcvg-git-2@gmane.org; Mon, 04 Feb 2008 01:59:15 +0100 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754762AbYBDA6n (ORCPT ); Sun, 3 Feb 2008 19:58:43 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754355AbYBDA6n (ORCPT ); Sun, 3 Feb 2008 19:58:43 -0500 Received: from BISCAYNE-ONE-STATION.MIT.EDU ([18.7.7.80]:35456 "EHLO biscayne-one-station.mit.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754494AbYBDA6m (ORCPT ); Sun, 3 Feb 2008 19:58:42 -0500 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by biscayne-one-station.mit.edu (8.13.6/8.9.2) with ESMTP id m140w3XH012257; Sun, 3 Feb 2008 19:58:18 -0500 (EST) Received: from localhost.localdomain (WITTEN.MIT.EDU [18.239.2.43]) (authenticated bits=0) (User authenticated as mfwitten@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id m140rw7U001110 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Sun, 3 Feb 2008 19:54:01 -0500 (EST) X-Mailer: git-send-email 1.5.4.9.gcc769-dirty In-Reply-To: <5C100A3B-0B4A-4D4E-B68B-1A54674A795A@mit.edu> X-Scanned-By: MIMEDefang 2.42 X-Spam-Flag: NO X-Spam-Score: 0.00 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: 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 --- The backend ambiguity of Term:ReadLine is avoided, and EOF is handled for the Password Prompt. Documentation/git-send-email.txt | 39 +++++++++++++++++++++++++++++++++---- git-send-email.perl | 25 ++++++++++++++++++++--- 2 files changed, 55 insertions(+), 9 deletions(-) diff --git a/Documentation/git-send-email.txt b/Documentation/git-send-email.txt index 0554f2b..4f4caa4 100644 --- a/Documentation/git-send-email.txt +++ b/Documentation/git-send-email.txt @@ -96,11 +96,40 @@ The --cc option must be repeated for each user you want on the cc list. servers typically listen to smtp port 25 and ssmtp port 465). ---smtp-user, --smtp-pass:: - Username and password for SMTP-AUTH. Defaults are the values of - the configuration values 'sendemail.smtpuser' and - 'sendemail.smtppass', but see also 'sendemail.identity'. - If not set, authentication is not attempted. +--smtp-user:: + Username for SMTP-AUTH. In place of this option, the following + configuration variables can be specified: ++ +-- + * sendemail.smtpuser + * sendemail..smtpuser (see sendemail.identity). +-- ++ +However, --smtp-user always overrides these variables. ++ +If a username is not specified (with --smtp-user or a +configuration variable), then authentication is not attempted. + +--smtp-pass:: + Password for SMTP-AUTH. The argument is optional: If no + argument is specified, then the empty string is used as + the password. ++ +In place of this option, the following configuration variables +can be specified: ++ +-- + * sendemail.smtppass + * sendemail..smtppass (see sendemail.identity). +-- ++ +However, --smtp-pass always overrides these variables. ++ +Furthermore, passwords need not be specified in configuration files +or on the command line. If a username has been specified (with +--smtp-user or a configuration variable), but no password has been +specified (with --smtp-pass or a configuration variable), then the +user is prompted for a password while the input is masked for privacy. --smtp-ssl:: If set, connects to the SMTP server using SSL. diff --git a/git-send-email.perl b/git-send-email.perl index a1a9d14..fec55ea 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -157,7 +157,7 @@ my $compose_filename = ".msg.$$"; # Variables we fill in automatically, or via prompting: my (@to,@cc,@initial_cc,@bcclist,@xh, - $initial_reply_to,$initial_subject,@files,$author,$sender,$compose,$time); + $initial_reply_to,$initial_subject,@files,$author,$sender,$smtp_authpass,$compose,$time); my $envelope_sender; @@ -177,7 +177,7 @@ my ($quiet, $dry_run) = (0, 0); # Variables with corresponding config settings my ($thread, $chain_reply_to, $suppress_from, $signed_off_cc, $cc_cmd); -my ($smtp_server, $smtp_server_port, $smtp_authuser, $smtp_authpass, $smtp_ssl); +my ($smtp_server, $smtp_server_port, $smtp_authuser, $smtp_ssl); my ($identity, $aliasfiletype, @alias_files, @smtp_host_parts); my ($no_validate); @@ -214,7 +214,7 @@ my $rc = GetOptions("sender|from=s" => \$sender, "smtp-server=s" => \$smtp_server, "smtp-server-port=s" => \$smtp_server_port, "smtp-user=s" => \$smtp_authuser, - "smtp-pass=s" => \$smtp_authpass, + "smtp-pass:s" => \$smtp_authpass, "smtp-ssl!" => \$smtp_ssl, "identity=s" => \$identity, "compose" => \$compose, @@ -647,9 +647,26 @@ X-Mailer: git-send-email $gitversion die "Unable to initialize SMTP properly. Is there something wrong with your config?"; } - if ((defined $smtp_authuser) && (defined $smtp_authpass)) { + if (defined $smtp_authuser) { + + if (!defined $smtp_authpass) { + + system "stty -echo"; + + do { + print "Password: "; + $_ = ; + print "\n"; + } while (!defined $_); + + chomp($smtp_authpass = $_); + + system "stty echo"; + } + $auth ||= $smtp->auth( $smtp_authuser, $smtp_authpass ) or die $smtp->message; } + $smtp->mail( $raw_from ) or die $smtp->message; $smtp->to( @recipients ) or die $smtp->message; $smtp->data or die $smtp->message; -- 1.5.4.9.gcc769-dirty