2007-10-07 11:44:02 +00:00
|
|
|
/*
|
2021-12-05 09:35:27 -06:00
|
|
|
* 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 11:44:02 +00:00
|
|
|
*
|
2021-12-05 09:35:27 -06:00
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
2007-10-07 11:44:02 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-11-10 23:46:11 +00:00
|
|
|
#ident "$Id$"
|
2007-10-07 11:47:01 +00:00
|
|
|
|
2007-10-07 11:46:07 +00:00
|
|
|
#include <unistd.h>
|
2008-01-26 17:41:20 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2007-10-07 11:44:02 +00:00
|
|
|
#include "prototypes.h"
|
|
|
|
#include "defines.h"
|
2021-11-28 17:37:53 -06:00
|
|
|
#include "shadowlog_internal.h"
|
2008-01-26 17:41:20 +00:00
|
|
|
|
2013-08-03 23:07:06 +02:00
|
|
|
/*@exposed@*//*@null@*/char *pw_encrypt (const char *clear, const char *salt)
|
2007-10-07 11:44:02 +00:00
|
|
|
{
|
2007-10-07 11:46:07 +00:00
|
|
|
static char cipher[128];
|
|
|
|
char *cp;
|
2007-10-07 11:44:02 +00:00
|
|
|
|
2007-10-07 11:46:16 +00:00
|
|
|
cp = crypt (clear, salt);
|
2013-08-03 23:07:06 +02:00
|
|
|
if (NULL == cp) {
|
2007-10-07 11:44:02 +00:00
|
|
|
/*
|
|
|
|
* Single Unix Spec: crypt() may return a null pointer,
|
2013-07-28 18:41:11 +02:00
|
|
|
* and set errno to indicate an error. In this case return
|
|
|
|
* the NULL so the caller can handle appropriately.
|
2007-10-07 11:44:02 +00:00
|
|
|
*/
|
2013-08-03 23:07:06 +02:00
|
|
|
return NULL;
|
2007-10-07 11:44:02 +00:00
|
|
|
}
|
2007-11-24 00:37:37 +00:00
|
|
|
|
2013-08-03 23:07:06 +02:00
|
|
|
/* Some crypt() do not return NULL if the algorithm is not
|
2007-11-24 00:37:37 +00:00
|
|
|
* supported, and return a DES encrypted password. */
|
2008-05-26 01:07:13 +00:00
|
|
|
if ((NULL != salt) && (salt[0] == '$') && (strlen (cp) <= 13))
|
2007-11-24 00:37:37 +00:00
|
|
|
{
|
2010-08-22 12:49:07 +00:00
|
|
|
/*@observer@*/const char *method;
|
2007-11-24 00:37:37 +00:00
|
|
|
switch (salt[1])
|
|
|
|
{
|
|
|
|
case '1':
|
|
|
|
method = "MD5";
|
|
|
|
break;
|
2019-09-16 20:54:56 +02:00
|
|
|
case '2':
|
|
|
|
method = "BCRYPT";
|
|
|
|
break;
|
2007-11-24 00:37:37 +00:00
|
|
|
case '5':
|
|
|
|
method = "SHA256";
|
|
|
|
break;
|
|
|
|
case '6':
|
|
|
|
method = "SHA512";
|
|
|
|
break;
|
2020-12-27 21:09:25 +01:00
|
|
|
case 'y':
|
|
|
|
method = "YESCRYPT";
|
|
|
|
break;
|
2007-11-24 00:37:37 +00:00
|
|
|
default:
|
2008-01-06 13:49:00 +00:00
|
|
|
{
|
|
|
|
static char nummethod[4] = "$x$";
|
|
|
|
nummethod[1] = salt[1];
|
|
|
|
method = &nummethod[0];
|
|
|
|
}
|
2007-11-24 00:37:37 +00:00
|
|
|
}
|
2021-05-08 17:42:14 -05:00
|
|
|
(void) fprintf (shadow_logfd,
|
2010-08-22 12:49:07 +00:00
|
|
|
_("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-04-30 21:08:49 +00:00
|
|
|
exit (EXIT_FAILURE);
|
2007-11-24 00:37:37 +00:00
|
|
|
}
|
|
|
|
|
* 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-04-30 21:08:49 +00:00
|
|
|
if (strlen (cp) != 13) {
|
2007-10-07 11:46:07 +00:00
|
|
|
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-04-30 21:08:49 +00:00
|
|
|
}
|
|
|
|
|
2007-10-07 11:46:07 +00:00
|
|
|
strcpy (cipher, cp);
|
2007-10-07 11:44:02 +00:00
|
|
|
|
|
|
|
return cipher;
|
|
|
|
}
|
2008-05-26 01:07:13 +00:00
|
|
|
|