From: <jan...@us...> - 2007-07-07 05:43:30
|
Revision: 12508 http://squirrelmail.svn.sourceforge.net/squirrelmail/?rev=12508&view=rev Author: jangliss Date: 2007-07-06 22:43:28 -0700 (Fri, 06 Jul 2007) Log Message: ----------- Backported code for site wide SMTP authentication (#1531889). Modified Paths: -------------- branches/SM-1_4-STABLE/squirrelmail/ChangeLog branches/SM-1_4-STABLE/squirrelmail/class/deliver/Deliver_SMTP.class.php branches/SM-1_4-STABLE/squirrelmail/config/conf.pl branches/SM-1_4-STABLE/squirrelmail/config/config_default.php branches/SM-1_4-STABLE/squirrelmail/functions/auth.php branches/SM-1_4-STABLE/squirrelmail/plugins/administrator/defines.php branches/SM-1_4-STABLE/squirrelmail/src/compose.php branches/SM-1_4-STABLE/squirrelmail/src/read_body.php Modified: branches/SM-1_4-STABLE/squirrelmail/ChangeLog =================================================================== --- branches/SM-1_4-STABLE/squirrelmail/ChangeLog 2007-07-06 23:49:59 UTC (rev 12507) +++ branches/SM-1_4-STABLE/squirrelmail/ChangeLog 2007-07-07 05:43:28 UTC (rev 12508) @@ -18,6 +18,7 @@ - Fix compatibility with Windows path in administrator plugin (#1740469). - Fix disabling password encryption in mail_fetch (#1738001). - Fix busy loop and notice when two literals in IMAP fetch (#1739433). + - Backported code for site wide SMTP authentication (#1531889). Version 1.4.10a - 10 May 2007 ----------------------------- Modified: branches/SM-1_4-STABLE/squirrelmail/class/deliver/Deliver_SMTP.class.php =================================================================== --- branches/SM-1_4-STABLE/squirrelmail/class/deliver/Deliver_SMTP.class.php 2007-07-06 23:49:59 UTC (rev 12507) +++ branches/SM-1_4-STABLE/squirrelmail/class/deliver/Deliver_SMTP.class.php 2007-07-07 05:43:28 UTC (rev 12508) @@ -27,8 +27,6 @@ } } - // TODO merge 1.5.1 changes regarding system wide SMTP username - function initStream($message, $domain, $length=0, $host='', $port='', $user='', $pass='', $authpop=false) { global $use_smtp_tls,$smtp_auth_mech,$username,$key,$onetimepad; Modified: branches/SM-1_4-STABLE/squirrelmail/config/conf.pl =================================================================== --- branches/SM-1_4-STABLE/squirrelmail/config/conf.pl 2007-07-06 23:49:59 UTC (rev 12507) +++ branches/SM-1_4-STABLE/squirrelmail/config/conf.pl 2007-07-07 05:43:28 UTC (rev 12508) @@ -344,6 +344,10 @@ $sendmail_args = '-i -t'; } +# Added in 1.4.11 +$smtp_sitewide_user = '' if ( !$smtp_sitewide_user ); +$smtp_sitewide_pass = '' if ( !$smtp_sitewide_pass ); + # Added in 1.4.9 $abook_global_file_listing = 'true' if ( !$abook_global_file_listing ); $abook_file_line_length = 2048 if ( !$abook_file_line_length ); @@ -463,7 +467,7 @@ print "4. SMTP Server : $WHT$smtpServerAddress$NRM\n"; print "5. SMTP Port : $WHT$smtpPort$NRM\n"; print "6. POP before SMTP : $WHT$pop_before_smtp$NRM\n"; - print "7. SMTP Authentication : $WHT$smtp_auth_mech$NRM\n"; + print "7. SMTP Authentication : $WHT$smtp_auth_mech" . display_smtp_sitewide_userpass() . "$NRM\n"; print "8. Secure SMTP (TLS) : $WHT$use_smtp_tls$NRM\n"; print "9. Header encryption key : $WHT$encode_header_key$NRM\n"; print "\n"; @@ -1338,17 +1342,95 @@ chomp($inval); if ($inval =~ /^none\b/i) { # SMTP doesn't necessarily require logins + $smtp_sitewide_user = ''; + $smtp_sitewide_pass = ''; return "none"; } if ( ($inval =~ /^cram-md5\b/i) || ($inval =~ /^digest-md5\b/i) || ($inval =~ /^login\b/i)) { + command_smtp_sitewide_userpass($inval); return lc($inval); + } elsif (trim($inval) eq '') { + command_smtp_sitewide_userpass($smtp_auth_mech); + return $smtp_auth_mech; } else { - # user entered garbage, or default value so nothing needs to be set + # user entered garbage return $smtp_auth_mech; } } +sub command_smtp_sitewide_userpass($) { + # get first function argument + my $auth_mech = shift(@_); + my $default, $tmp; + $auth_mech = lc(trim($auth_mech)); + if ($auth_mech eq 'none') { + return; + } + print "SMTP authentication uses IMAP username and password by default.\n"; + print "\n"; + print "Would you like to use other login and password for all SquirrelMail \n"; + print "SMTP connections?"; + if ($smtp_sitewide_user ne '') { + $default = 'y'; + print " [Yn]:"; + } else { + $default = 'n'; + print " [yN]:"; + } + $tmp=<STDIN>; + $tmp = trim($tmp); + + if ($tmp eq '') { + $tmp = $default; + } else { + $tmp = lc($tmp); + } + + if ($tmp eq 'n') { + $smtp_sitewide_user = ''; + $smtp_sitewide_pass = ''; + } elsif ($tmp eq 'y') { + print "Enter username [$smtp_sitewide_user]:"; + my $new_user = <STDIN>; + $new_user = trim($new_user); + if ($new_user ne '') { + $smtp_sitewide_user = $new_user; + } + if ($smtp_sitewide_user ne '') { + print "If you don't enter any password, current sitewide password will be used.\n"; + print "If you enter space, password will be set to empty string.\n"; + print "Enter password:"; + my $new_pass = <STDIN>; + if ($new_pass ne "\n") { + $smtp_sitewide_pass = trim($new_pass); + } + } else { + print "Invalid input. You must set username used for SMTP authentication.\n"; + print "Click any key to continue\n"; + $tmp = <STDIN>; + } + } else { + print "Invalid input\n"; + print "Click any key to continue\n"; + $tmp = <STDIN>; + } +} + +# Sub adds information about SMTP authentication type to menu +sub display_smtp_sitewide_userpass() { + my $ret = ''; + if ($smtp_auth_mech ne 'none') { + if ($smtp_sitewide_user ne '') { + $ret = ' (with custom username and password)'; + } else { + $ret = ' (with IMAP username and password)'; + } + } + return $ret; +} + + # TLS # This sub is reused for IMAP and SMTP # Args: service name, default value @@ -3319,6 +3401,8 @@ # string print CF "\$smtp_auth_mech = '$smtp_auth_mech';\n"; print CF "\$imap_auth_mech = '$imap_auth_mech';\n"; + print CF "\$smtp_sitewide_user = '" . quote_singe($smtp_sitewide_user) . "';\n"; + print CF "\$smtp_sitewide_pass = '" . quote_singe($smtp_sitewide_pass) . "';\n"; # boolean print CF "\$use_imap_tls = $use_imap_tls;\n"; print CF "\$use_smtp_tls = $use_smtp_tls;\n"; @@ -3708,6 +3792,13 @@ } } +# Quotes safely strings containing single quote +sub quote_single($) { + my $string = shift(@_); + $string =~ s/\'/\\'/g; + return $string; +} + # trims whitespace # Example code from O'Reilly Perl Cookbook sub trim { Modified: branches/SM-1_4-STABLE/squirrelmail/config/config_default.php =================================================================== --- branches/SM-1_4-STABLE/squirrelmail/config/config_default.php 2007-07-06 23:49:59 UTC (rev 12507) +++ branches/SM-1_4-STABLE/squirrelmail/config/config_default.php 2007-07-07 05:43:28 UTC (rev 12508) @@ -257,6 +257,26 @@ $smtp_auth_mech = 'none'; /** + * Custom SMTP Authentication Username + * + * IMAP username is used if variable is set to an empty string. Variable is included in + * the main configuration file only in 1.4.11+ and 1.5.2+. + * @global string $smtp_sitewide_user + * @since 1.4.11 + */ +$smtp_sitewide_user = ''; + +/** + * Custom SMTP Authentication Password + * + * IMAP password is used if variable is set to an empty string. Variable is included in + * the main configuration file in 1.4.11+ and 1.5.2+ + * @global string $smtp_sitewide_pass + * @since 1.4.11 + */ +$smtp_sitewide_pass = ''; + +/** * IMAP authentication mechanism * * auth_mech can be either 'login','plain', 'cram-md5', or 'digest-md5' Modified: branches/SM-1_4-STABLE/squirrelmail/functions/auth.php =================================================================== --- branches/SM-1_4-STABLE/squirrelmail/functions/auth.php 2007-07-06 23:49:59 UTC (rev 12507) +++ branches/SM-1_4-STABLE/squirrelmail/functions/auth.php 2007-07-07 05:43:28 UTC (rev 12508) @@ -231,4 +231,43 @@ return $hmac; } +/** + * Reads and decodes stored user password information + * + * Direct access to password information is deprecated. + * @return string password in plain text + * @since 1.5.1 + */ +function sqauth_read_password() { + sqgetGlobalVar('key', $key, SQ_COOKIE); + sqgetGlobalVar('onetimepad', $onetimepad,SQ_SESSION); + + return OneTimePadDecrypt($key, $onetimepad); +} + +/** + * Fillin user and password based on SMTP auth settings. + * + * @param string $user Reference to SMTP username + * @param string $pass Reference to SMTP password (unencrypted) + * @since 1.4.11 + */ +function get_smtp_user(&$user, &$pass) { + global $username, $smtp_auth_mech, + $smtp_sitewide_user, $smtp_sitewide_pass; + + if ($smtp_auth_mech == 'none') { + $user = ''; + $pass = ''; + } elseif ( isset($smtp_sitewide_user) && isset($smtp_sitewide_pass) && + !empty($smtp_sitewide_user)) { + $user = $smtp_sitewide_user; + $pass = $smtp_sitewide_pass; + } else { + $user = $username; + $pass = sqauth_read_password(); + } +} + + ?> Modified: branches/SM-1_4-STABLE/squirrelmail/plugins/administrator/defines.php =================================================================== --- branches/SM-1_4-STABLE/squirrelmail/plugins/administrator/defines.php 2007-07-06 23:49:59 UTC (rev 12507) +++ branches/SM-1_4-STABLE/squirrelmail/plugins/administrator/defines.php 2007-07-07 05:43:28 UTC (rev 12508) @@ -151,6 +151,12 @@ 'cram-md5' => 'CRAM-MD5', 'digest-md5' => 'DIGEST-MD5'), 'default' => 'none'), + '$smtp_sitewide_user' => array( 'name' => _("Custom SMTP AUTH username"), + 'type' => SMOPT_TYPE_STRING, + 'size' => 40), + '$smtp_sitewide_pass' => array( 'name' => _("Custom SMTP AUTH password"), + 'type' => SMOPT_TYPE_STRING, + 'size' => 40), '$pop_before_smtp' => array( 'name' => _("POP3 Before SMTP?"), 'type' => SMOPT_TYPE_BOOLEAN, 'default' => false ), Modified: branches/SM-1_4-STABLE/squirrelmail/src/compose.php =================================================================== --- branches/SM-1_4-STABLE/squirrelmail/src/compose.php 2007-07-06 23:49:59 UTC (rev 12507) +++ branches/SM-1_4-STABLE/squirrelmail/src/compose.php 2007-07-07 05:43:28 UTC (rev 12508) @@ -1532,16 +1532,12 @@ global $smtpServerAddress, $smtpPort, $pop_before_smtp, $smtp_auth_mech; $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ? true : false; + + $user = ''; + $pass = ''; + + get_smtp_user($user, $pass); - if ($smtp_auth_mech == 'none' && !$authPop) { - $user = ''; - $pass = ''; - } else { - global $key, $onetimepad; - $user = $username; - $pass = OneTimePadDecrypt($key, $onetimepad); - } - $stream = $deliver->initStream($composeMessage,$domain,0, $smtpServerAddress, $smtpPort, $user, $pass, $authPop); } elseif (!$draft) { Modified: branches/SM-1_4-STABLE/squirrelmail/src/read_body.php =================================================================== --- branches/SM-1_4-STABLE/squirrelmail/src/read_body.php 2007-07-06 23:49:59 UTC (rev 12507) +++ branches/SM-1_4-STABLE/squirrelmail/src/read_body.php 2007-07-07 05:43:28 UTC (rev 12508) @@ -307,16 +307,11 @@ } else { require_once(SM_PATH . 'class/deliver/Deliver_SMTP.class.php'); $deliver = new Deliver_SMTP(); - global $smtpServerAddress, $smtpPort, $smtp_auth_mech, $pop_before_smtp; - if ($smtp_auth_mech == 'none') { - $user = ''; - $pass = ''; - } else { - global $key, $onetimepad; - $user = $username; - $pass = OneTimePadDecrypt($key, $onetimepad); - } + global $smtpServerAddress, $smtpPort, $pop_before_smtp; + $user = ''; + $pass = ''; $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ? true : false; + get_smtp_user($user, $pass); $stream = $deliver->initStream($composeMessage,$domain,0, $smtpServerAddress, $smtpPort, $user, $pass, $authPop); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |