blob: e9cf4e3b8ec5f8d0c49145e7d5e5a8f011b031e6 [file] [log] [blame]
Eric Andersen27f64e12002-06-23 04:24:25 +00001/* vi: set sw=4 ts=4: */
2/*
3 * Utility routine.
4 *
Eric Andersenc7bda1c2004-03-15 08:29:22 +00005 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
Eric Andersen27f64e12002-06-23 04:24:25 +00006 *
"Robert P. J. Day"5d8843e2006-07-10 11:41:19 +00007 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
Eric Andersen27f64e12002-06-23 04:24:25 +00008 */
9
Rob Landleyea224be2006-06-18 20:20:07 +000010#include "libbb.h"
Eric Andersen27f64e12002-06-23 04:24:25 +000011#include <crypt.h>
Eric Andersen27f64e12002-06-23 04:24:25 +000012
Rob Landleydfba7412006-03-06 20:47:33 +000013char *pw_encrypt(const char *clear, const char *salt)
Eric Andersen27f64e12002-06-23 04:24:25 +000014{
Denis Vlasenko91e149a2007-06-18 10:35:06 +000015 /* Was static char[BIGNUM]. Malloced thing works as well */
16 static char *cipher;
Eric Andersen27f64e12002-06-23 04:24:25 +000017
Denis Vlasenkode9ec922006-09-27 23:31:59 +000018#if 0 /* was CONFIG_FEATURE_SHA1_PASSWORDS, but there is no such thing??? */
Eric Andersen27f64e12002-06-23 04:24:25 +000019 if (strncmp(salt, "$2$", 3) == 0) {
20 return sha1_crypt(clear);
21 }
22#endif
Denis Vlasenko91e149a2007-06-18 10:35:06 +000023
24 free(cipher);
25 cipher = xstrdup(crypt(clear, salt));
Eric Andersen27f64e12002-06-23 04:24:25 +000026 return cipher;
27}