-static int want_entryhash = 0;
-static int auto_gen_pw = 0;
-
-/*** functions ***/
-
-/*
- * pw_encode() essentially base64 encodes a password and it's salt
- */
-
-char *
-pw_encode (unsigned char *passwd, Salt * salt, unsigned int len)
-{
- int salted = salt && salt->salt && salt->len;
- int b64_len = 0;
- char *base64digest = NULL;
- unsigned char *npasswd = passwd;
-
- if (salted)
- {
- npasswd = (unsigned char *)malloc (len + salt->len);
- memcpy (npasswd, passwd, len);
- memcpy (&npasswd[len], salt->salt, salt->len);
- len += salt->len;
- }
-
- b64_len = CEILING (len / 3) * 4 + 1;
- base64digest = (char *)malloc (b64_len);
- if (lutil_b64_ntop (npasswd, len, base64digest, b64_len) < 0)
- {
- free (base64digest);
- base64digest = NULL;
- }
-
- if (salted)
- free (npasswd);
-
- return (base64digest);
-}
-
-/*
- * if you'd like to write a better salt generator, please, be my guest.
- */
-
-void
-make_salt (Salt * salt, unsigned int len)
-{
- struct timeval tv;
-
- if (!salt)
- return;
-
- /* seed random number generator */
- gettimeofday (&tv, NULL);
- srand (tv.tv_usec);
-
- salt->len = len;
- salt->salt = (unsigned char *)malloc (len);
-
- for (len = 0; len < salt->len; len++)
- salt->salt[len] = (tv.tv_usec ^ rand ()) & 0xff;
-}
-
-/*
- * password generator
- */
-
-char *
-gen_pass (unsigned int len)
-{
- const unsigned char autogen[] =
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890.,";
- int i;
- Salt salt = {NULL, 0};
-
- make_salt (&salt, len);
- for (i = 0; i < len; i++)
- salt.salt[i] = autogen[salt.salt[i] % (sizeof (autogen) - 1)];
-
- return ((char *)salt.salt);
-}
-
-char *
-hash_none (const char *pw_in, Salt * salt)
-{
- return (STRDUP (pw_in));
-}
-
-char *
-hash_crypt (const char *pw_in, Salt * salt)
-{
- const unsigned char crypt64[] =
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890./";
- char *crypted_pw = NULL;
- Salt lsalt;
-
- if (salt && salt->salt && strlen ((char *)salt->salt) >= 2)
- {
- /* sanity check */
- if (!(isalnum(salt->salt[0]) || salt->salt[0] == '.' || salt->salt[0] == '/'))
- salt->salt[0] = crypt64[salt->salt[0] % (sizeof (crypt64) - 1)];
- if (!(isalnum(salt->salt[1]) || salt->salt[1] == '.' || salt->salt[1] == '/'))
- salt->salt[1] = crypt64[salt->salt[1] % (sizeof (crypt64) - 1)];
-
- crypted_pw = crypt (pw_in, (char *)salt->salt);
- }
- else
- {
- make_salt (&lsalt, 2);
- lsalt.salt[0] = crypt64[lsalt.salt[0] % (sizeof (crypt64) - 1)];
- lsalt.salt[1] = crypt64[lsalt.salt[1] % (sizeof (crypt64) - 1)];
- crypted_pw = crypt (pw_in, (char *)lsalt.salt);
- free (lsalt.salt);
- }
- return (STRDUP (crypted_pw));
-}
-
-char *
-hash_md5 (const char *pw_in, Salt * salt)
-{
- lutil_MD5_CTX MD5context;
- unsigned char MD5digest[16];
-
- lutil_MD5Init (&MD5context);
- lutil_MD5Update (&MD5context, pw_in, strlen(pw_in));
- if (salt && salt->salt && salt->len)
- lutil_MD5Update (&MD5context, salt->salt, salt->len);
- lutil_MD5Final (MD5digest, &MD5context);
-
- return (pw_encode (MD5digest, salt, sizeof (MD5digest)));
-}