Return-Path: Delivered-To: apmail-httpd-cvs-archive@www.apache.org Received: (qmail 16836 invoked from network); 19 Feb 2008 17:05:52 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 19 Feb 2008 17:05:52 -0000 Received: (qmail 51361 invoked by uid 500); 19 Feb 2008 17:05:46 -0000 Delivered-To: apmail-httpd-cvs-archive@httpd.apache.org Received: (qmail 51164 invoked by uid 500); 19 Feb 2008 17:05:46 -0000 Mailing-List: contact cvs-help@httpd.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@httpd.apache.org list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list cvs@httpd.apache.org Received: (qmail 51153 invoked by uid 99); 19 Feb 2008 17:05:46 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 19 Feb 2008 09:05:46 -0800 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 19 Feb 2008 17:05:08 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 909EC1A9832; Tue, 19 Feb 2008 09:05:28 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r629164 - /httpd/httpd/trunk/support/htpasswd.c Date: Tue, 19 Feb 2008 17:05:28 -0000 To: cvs@httpd.apache.org From: pquerna@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080219170528.909EC1A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: pquerna Date: Tue Feb 19 09:05:26 2008 New Revision: 629164 URL: http://svn.apache.org/viewvc?rev=629164&view=rev Log: Improve generation of the seed to rand, by using apr_generate_random_bytes, rather than the current time as a seed. PR: 31440 Modified: httpd/httpd/trunk/support/htpasswd.c Modified: httpd/httpd/trunk/support/htpasswd.c URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/support/htpasswd.c?rev=629164&r1=629163&r2=629164&view=diff ============================================================================== --- httpd/httpd/trunk/support/htpasswd.c (original) +++ httpd/httpd/trunk/support/htpasswd.c Tue Feb 19 09:05:26 2008 @@ -126,6 +126,18 @@ } } +static apr_status_t seed_rand() +{ + int seed = 0; + apr_status_t rv; + rv = apr_generate_random_bytes((unsigned char*) &seed, sizeof(seed)); + if (rv) { + apr_file_printf(errfile, "Unable to generate random bytes: %pm" NL, rv); + return rv; + } + srand(seed); + return rv; +} static void putline(apr_file_t *f, const char *l) { @@ -174,7 +186,9 @@ break; case ALG_APMD5: - (void) srand((int) time((time_t *) NULL)); + if (seed_rand()) { + break; + } generate_salt(&salt[0], 8); salt[8] = '\0'; @@ -190,7 +204,9 @@ #if (!(defined(WIN32) || defined(TPF) || defined(NETWARE))) case ALG_CRYPT: default: - (void) srand((int) time((time_t *) NULL)); + if (seed_rand()) { + break; + } to64(&salt[0], rand(), 8); salt[8] = '\0';