passwd.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
#if defined OPENSSL_NO_MD5 || defined CHARSET_EBCDIC
# define NO_MD5CRYPT_1
#endif
#if !defined(OPENSSL_NO_DES) || !defined(NO_MD5CRYPT_1)
#include <assert.h>
#include <string.h>
#include "apps.h"
#ifndef OPENSSL_NO_DES
#endif
#ifndef NO_MD5CRYPT_1
#endif
#define PROG passwd_main
static unsigned const char cov_2char[64]={
0x2E,0x2F,0x30,0x31,0x32,0x33,0x34,0x35,
0x36,0x37,0x38,0x39,0x41,0x42,0x43,0x44,
0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,
0x4D,0x4E,0x4F,0x50,0x51,0x52,0x53,0x54,
0x55,0x56,0x57,0x58,0x59,0x5A,0x61,0x62,
0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,
0x6B,0x6C,0x6D,0x6E,0x6F,0x70,0x71,0x72,
0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A
};
/* -crypt - standard Unix password algorithm (default)
* -1 - MD5-based password algorithm
* -apr1 - MD5-based password algorithm, Apache variant
* -salt string - salt
* -in file - read passwords from file
* -stdin - read passwords from stdin
* -noverify - never verify when reading password from terminal
* -quiet - no warnings
* -table - format output as table
* -reverse - switch table columns
*/
int MAIN(int, char **);
{
int ret = 1;
int in_stdin = 0;
int in_noverify = 0;
size_t passwd_malloc_size = 0;
int pw_source_defined = 0;
apps_startup();
goto err;
goto err;
#ifdef OPENSSL_SYS_VMS
{
}
#endif
i = 0;
{
usecrypt = 1;
use1 = 1;
useapr1 = 1;
{
{
passed_salt = 1;
}
else
badopt = 1;
}
{
{
pw_source_defined = 1;
}
else
badopt = 1;
}
{
if (!pw_source_defined)
{
pw_source_defined = 1;
in_stdin = 1;
}
else
badopt = 1;
}
in_noverify = 1;
quiet = 1;
table = 1;
reverse = 1;
else if (argv[i][0] == '-')
badopt = 1;
else if (!pw_source_defined)
/* non-option arguments, use as passwords */
{
pw_source_defined = 1;
opt_done = 1;
}
else
badopt = 1;
}
usecrypt = 1;
badopt = 1;
/* reject unsupported algorithms */
#ifdef OPENSSL_NO_DES
#endif
#ifdef NO_MD5CRYPT_1
#endif
if (badopt)
{
#ifndef OPENSSL_NO_DES
#endif
#ifndef NO_MD5CRYPT_1
#endif
goto err;
}
{
goto err;
{
goto err;
}
else
{
}
}
if (usecrypt)
pw_maxlen = 8;
{
/* no passwords on the command line */
/* longer than necessary so that we can warn about truncation */
if (passwd_malloc == NULL)
goto err;
}
{
/* build a null-terminated list */
if (EVP_read_pw_string(passwd_malloc, passwd_malloc_size, "Password: ", !(passed_salt || in_noverify)) != 0)
goto err;
passwds[0] = passwd_malloc;
}
{
do /* loop over list of passwords */
{
goto err;
}
}
else
/* in != NULL */
{
int done;
do
{
if (r > 0)
{
if (c != NULL)
*c = 0; /* truncate at newline */
else
{
/* ignore rest of line */
do
}
goto err;
}
done = (r <= 0);
}
while (!done);
}
ret = 0;
err:
if (salt_malloc)
if (passwd_malloc)
if (in)
if (out)
}
#ifndef NO_MD5CRYPT_1
/* MD5-based password algorithm (should probably be available as a library
* function; then the static buffer would not be acceptable).
* For magic string "1", this should be compatible to the MD5-based BSD
* password algorithm.
* For 'magic' string "apr1", this is compatible to the MD5-based Apache
* password algorithm.
* (Apparently, the Apache password algorithm is identical except that the
* 'magic' string was changed -- the laziest application of the NIH principle
* I've ever encountered.)
*/
{
unsigned char buf[MD5_DIGEST_LENGTH];
char *salt_out;
int n, i;
out_buf[0] = '$';
out_buf[1] = 0;
n = passwd_len;
while (n)
{
n >>= 1;
}
for (i = 0; i < 1000; i++)
{
if (i % 3)
if (i % 7)
}
{
/* transform buf into output string */
char *output;
/* silly output permutation */
#ifndef PEDANTIC /* Unfortunately, this generates a "no effect" warning */
#endif
*output++ = '$';
for (i = 0; i < 15; i += 3)
{
}
assert(i == 15);
*output = 0;
}
return out_buf;
}
#endif
{
/* first make sure we have a salt */
if (!passed_salt)
{
#ifndef OPENSSL_NO_DES
if (usecrypt)
{
if (*salt_malloc_p == NULL)
{
if (*salt_malloc_p == NULL)
goto err;
}
goto err;
(*salt_p)[2] = 0;
#ifdef CHARSET_EBCDIC
* back to ASCII */
#endif
}
#endif /* !OPENSSL_NO_DES */
#ifndef NO_MD5CRYPT_1
{
int i;
if (*salt_malloc_p == NULL)
{
if (*salt_malloc_p == NULL)
goto err;
}
goto err;
for (i = 0; i < 8; i++)
(*salt_p)[8] = 0;
}
#endif /* !NO_MD5CRYPT_1 */
}
/* truncate password if necessary */
{
if (!quiet)
}
/* now compute password hash */
#ifndef OPENSSL_NO_DES
if (usecrypt)
#endif
#ifndef NO_MD5CRYPT_1
#endif
else
return 1;
err:
return 0;
}
#else
{
OPENSSL_EXIT(1);
}
#endif