[Pkg-shadow-commits] r2138 - in upstream/trunk: . libmisc
nekral-guest at alioth.debian.org
nekral-guest at alioth.debian.org
Fri Jun 13 19:37:16 UTC 2008
Author: nekral-guest
Date: 2008-06-13 19:37:15 +0000 (Fri, 13 Jun 2008)
New Revision: 2138
Modified:
upstream/trunk/ChangeLog
upstream/trunk/libmisc/salt.c
Log:
* libmisc/salt.c: Use a size_t for the size of strings instead of
unsigned int.
* libmisc/salt.c: Add brackets and parenthesis.
* libmisc/salt.c: Avoid assignments in comparisons.
Modified: upstream/trunk/ChangeLog
===================================================================
--- upstream/trunk/ChangeLog 2008-06-13 19:24:27 UTC (rev 2137)
+++ upstream/trunk/ChangeLog 2008-06-13 19:37:15 UTC (rev 2138)
@@ -1,5 +1,12 @@
2008-06-13 Nicolas François <nicolas.francois at centraliens.net>
+ * libmisc/salt.c: Use a size_t for the size of strings instead of
+ unsigned int.
+ * libmisc/salt.c: Add brackets and parenthesis.
+ * libmisc/salt.c: Avoid assignments in comparisons.
+
+2008-06-13 Nicolas François <nicolas.francois at centraliens.net>
+
* libmisc/age.c: fork() and wait return a pid_t, not an int.
* libmisc/age.c: Avoid implicit conversion of pointers to
booleans.
Modified: upstream/trunk/libmisc/salt.c
===================================================================
--- upstream/trunk/libmisc/salt.c 2008-06-13 19:24:27 UTC (rev 2137)
+++ upstream/trunk/libmisc/salt.c 2008-06-13 19:37:15 UTC (rev 2138)
@@ -24,9 +24,9 @@
char *l64a(long value);
#endif /* !HAVE_L64A */
static void seedRNG (void);
-static char *gensalt (unsigned int salt_size);
+static char *gensalt (size_t salt_size);
#ifdef USE_SHA_CRYPT
-static unsigned int SHA_salt_size (void);
+static size_t SHA_salt_size (void);
static const char *SHA_salt_rounds (int *prefered_rounds);
#endif /* USE_SHA_CRYPT */
@@ -46,14 +46,15 @@
for (i = 0; value != 0 && i < 6; i++) {
digit = value & 0x3f;
- if (digit < 2)
+ if (digit < 2) {
*s = digit + '.';
- else if (digit < 12)
+ } else if (digit < 12) {
*s = digit + '0' - 2;
- else if (digit < 38)
+ } else if (digit < 38) {
*s = digit + 'A' - 12;
- else
+ } else {
*s = digit + 'a' - 38;
+ }
value >>= 6;
s++;
@@ -88,12 +89,12 @@
* The size of the salt string is between 8 and 16 bytes for the SHA crypt
* methods.
*/
-static unsigned int SHA_salt_size (void)
+static size_t SHA_salt_size (void)
{
double rand_size;
seedRNG ();
rand_size = (double) 9.0 * random () / RAND_MAX;
- return 8 + rand_size;
+ return (size_t) (8 + rand_size);
}
/* ! Arguments evaluated twice ! */
@@ -120,41 +121,49 @@
long max_rounds = getdef_long ("SHA_CRYPT_MAX_ROUNDS", -1);
double rand_rounds;
- if (-1 == min_rounds && -1 == max_rounds)
+ if ((-1 == min_rounds) && (-1 == max_rounds)) {
return "";
+ }
- if (-1 == min_rounds)
+ if (-1 == min_rounds) {
min_rounds = max_rounds;
+ }
- if (-1 == max_rounds)
+ if (-1 == max_rounds) {
max_rounds = min_rounds;
+ }
- if (min_rounds > max_rounds)
+ if (min_rounds > max_rounds) {
max_rounds = min_rounds;
+ }
seedRNG ();
rand_rounds = (double) (max_rounds-min_rounds+1.0) * random ();
rand_rounds /= RAND_MAX;
rounds = min_rounds + rand_rounds;
- } else if (0 == *prefered_rounds)
+ } else if (0 == *prefered_rounds) {
return "";
- else
+ } else {
rounds = *prefered_rounds;
+ }
/* Sanity checks. The libc should also check this, but this
* protects against a rounds_prefix overflow. */
- if (rounds < ROUNDS_MIN)
+ if (rounds < ROUNDS_MIN) {
rounds = ROUNDS_MIN;
+ }
- if (rounds > ROUNDS_MAX)
+ if (rounds > ROUNDS_MAX) {
rounds = ROUNDS_MAX;
+ }
snprintf (rounds_prefix, 18, "rounds=%ld$", rounds);
/* Sanity checks. That should not be necessary. */
rounds_prefix[17] = '\0';
- if ('$' != rounds_prefix[16])
+ if ('$' != rounds_prefix[16]) {
rounds_prefix[17] = '$';
+ }
return rounds_prefix;
}
@@ -166,7 +175,7 @@
#define MAX_SALT_SIZE 16
#define MIN_SALT_SIZE 8
-static char *gensalt (unsigned int salt_size)
+static char *gensalt (size_t salt_size)
{
static char salt[32];
@@ -179,6 +188,7 @@
do {
strcat (salt, l64a (random()));
} while (strlen (salt) < salt_size);
+
salt[salt_size] = '\0';
return salt;
@@ -216,8 +226,10 @@
if (NULL != meth)
method = meth;
else {
- if ((method = getdef_str ("ENCRYPT_METHOD")) == NULL)
- method = getdef_bool ("MD5_CRYPT_ENAB") ? "MD5" : "DES";
+ method = getdef_str ("ENCRYPT_METHOD");
+ if (NULL == method) {
+ method = getdef_bool ("MD5_CRYPT_ENAB") ? "MD5" : "DES";
+ }
}
if (0 == strcmp (method, "MD5")) {
More information about the Pkg-shadow-commits
mailing list