2007-10-07 17:14:02 +05:30
|
|
|
/*
|
2021-12-05 21:05:27 +05:30
|
|
|
* SPDX-FileCopyrightText: 1990 - 1993, Julianne Frances Haugh
|
|
|
|
* SPDX-FileCopyrightText: 1996 - 2000, Marek Michałkiewicz
|
|
|
|
* SPDX-FileCopyrightText: 2005 , Tomasz Kłoczko
|
|
|
|
* SPDX-FileCopyrightText: 2007 - 2010, Nicolas François
|
2007-10-07 17:14:02 +05:30
|
|
|
*
|
2021-12-05 21:05:27 +05:30
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-11-11 05:16:11 +05:30
|
|
|
#ident "$Id$"
|
2007-10-07 17:17:01 +05:30
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
#include <unistd.h>
|
2008-01-26 23:11:20 +05:30
|
|
|
#include <stdio.h>
|
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
#include "prototypes.h"
|
|
|
|
#include "defines.h"
|
2021-11-29 05:07:53 +05:30
|
|
|
#include "shadowlog_internal.h"
|
2008-01-26 23:11:20 +05:30
|
|
|
|
2013-08-04 02:37:06 +05:30
|
|
|
/*@exposed@*//*@null@*/char *pw_encrypt (const char *clear, const char *salt)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:16:07 +05:30
|
|
|
static char cipher[128];
|
|
|
|
char *cp;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:16:16 +05:30
|
|
|
cp = crypt (clear, salt);
|
2013-08-04 02:37:06 +05:30
|
|
|
if (NULL == cp) {
|
2007-10-07 17:14:02 +05:30
|
|
|
/*
|
|
|
|
* Single Unix Spec: crypt() may return a null pointer,
|
2013-07-28 22:11:11 +05:30
|
|
|
* and set errno to indicate an error. In this case return
|
|
|
|
* the NULL so the caller can handle appropriately.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
2013-08-04 02:37:06 +05:30
|
|
|
return NULL;
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2007-11-24 06:07:37 +05:30
|
|
|
|
2013-08-04 02:37:06 +05:30
|
|
|
/* Some crypt() do not return NULL if the algorithm is not
|
2007-11-24 06:07:37 +05:30
|
|
|
* supported, and return a DES encrypted password. */
|
2008-05-26 06:37:13 +05:30
|
|
|
if ((NULL != salt) && (salt[0] == '$') && (strlen (cp) <= 13))
|
2007-11-24 06:07:37 +05:30
|
|
|
{
|
2010-08-22 18:19:07 +05:30
|
|
|
/*@observer@*/const char *method;
|
2007-11-24 06:07:37 +05:30
|
|
|
switch (salt[1])
|
|
|
|
{
|
|
|
|
case '1':
|
|
|
|
method = "MD5";
|
|
|
|
break;
|
2019-09-17 00:24:56 +05:30
|
|
|
case '2':
|
|
|
|
method = "BCRYPT";
|
|
|
|
break;
|
2007-11-24 06:07:37 +05:30
|
|
|
case '5':
|
|
|
|
method = "SHA256";
|
|
|
|
break;
|
|
|
|
case '6':
|
|
|
|
method = "SHA512";
|
|
|
|
break;
|
2020-12-28 01:39:25 +05:30
|
|
|
case 'y':
|
|
|
|
method = "YESCRYPT";
|
|
|
|
break;
|
2007-11-24 06:07:37 +05:30
|
|
|
default:
|
2008-01-06 19:19:00 +05:30
|
|
|
{
|
|
|
|
static char nummethod[4] = "$x$";
|
|
|
|
nummethod[1] = salt[1];
|
|
|
|
method = &nummethod[0];
|
|
|
|
}
|
2007-11-24 06:07:37 +05:30
|
|
|
}
|
2021-05-09 04:12:14 +05:30
|
|
|
(void) fprintf (shadow_logfd,
|
2010-08-22 18:19:07 +05:30
|
|
|
_("crypt method not supported by libcrypt? (%s)\n"),
|
|
|
|
method);
|
* lib/exitcodes.h: Define E_SUCCESS as EXIT_SUCCESS. Added FIXMEs.
* libmisc/chowntty.c, libmisc/rlogin.c, libmisc/sub.c,
src/newusers.c, libmisc/sulog.c, libmisc/system.c, src/logoutd.c,
src/groups.c, src/id.c, lib/encrypt.c, libmisc/audit_help.c,
libmisc/limits.c: Return EXIT_FAILURE instead of 1, and
EXIT_SUCCESS instead of 0.
* libmisc/audit_help.c: Replace an fprintf() by fputs().
* libmisc/audit_help.c: Remove documentation of the audit_logger
returned values. The function returns void.
* libmisc/system.c: Only return status if waitpid succeeded.
Return -1 otherwise.
2009-05-01 02:38:49 +05:30
|
|
|
exit (EXIT_FAILURE);
|
2007-11-24 06:07:37 +05:30
|
|
|
}
|
|
|
|
|
* lib/exitcodes.h: Define E_SUCCESS as EXIT_SUCCESS. Added FIXMEs.
* libmisc/chowntty.c, libmisc/rlogin.c, libmisc/sub.c,
src/newusers.c, libmisc/sulog.c, libmisc/system.c, src/logoutd.c,
src/groups.c, src/id.c, lib/encrypt.c, libmisc/audit_help.c,
libmisc/limits.c: Return EXIT_FAILURE instead of 1, and
EXIT_SUCCESS instead of 0.
* libmisc/audit_help.c: Replace an fprintf() by fputs().
* libmisc/audit_help.c: Remove documentation of the audit_logger
returned values. The function returns void.
* libmisc/system.c: Only return status if waitpid succeeded.
Return -1 otherwise.
2009-05-01 02:38:49 +05:30
|
|
|
if (strlen (cp) != 13) {
|
2007-10-07 17:16:07 +05:30
|
|
|
return cp; /* nonstandard crypt() in libc, better bail out */
|
* lib/exitcodes.h: Define E_SUCCESS as EXIT_SUCCESS. Added FIXMEs.
* libmisc/chowntty.c, libmisc/rlogin.c, libmisc/sub.c,
src/newusers.c, libmisc/sulog.c, libmisc/system.c, src/logoutd.c,
src/groups.c, src/id.c, lib/encrypt.c, libmisc/audit_help.c,
libmisc/limits.c: Return EXIT_FAILURE instead of 1, and
EXIT_SUCCESS instead of 0.
* libmisc/audit_help.c: Replace an fprintf() by fputs().
* libmisc/audit_help.c: Remove documentation of the audit_logger
returned values. The function returns void.
* libmisc/system.c: Only return status if waitpid succeeded.
Return -1 otherwise.
2009-05-01 02:38:49 +05:30
|
|
|
}
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
strcpy (cipher, cp);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
return cipher;
|
|
|
|
}
|
2008-05-26 06:37:13 +05:30
|
|
|
|