Eric Andersen | 27f64e1 | 2002-06-23 04:24:25 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
| 2 | /* |
| 3 | * Utility routine. |
| 4 | * |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 5 | * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> |
Eric Andersen | 27f64e1 | 2002-06-23 04:24:25 +0000 | [diff] [blame] | 6 | * |
"Robert P. J. Day" | 5d8843e | 2006-07-10 11:41:19 +0000 | [diff] [blame] | 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
Eric Andersen | 27f64e1 | 2002-06-23 04:24:25 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
Rob Landley | ea224be | 2006-06-18 20:20:07 +0000 | [diff] [blame] | 10 | #include "libbb.h" |
Eric Andersen | 27f64e1 | 2002-06-23 04:24:25 +0000 | [diff] [blame] | 11 | #include <string.h> |
| 12 | #include <crypt.h> |
Eric Andersen | 27f64e1 | 2002-06-23 04:24:25 +0000 | [diff] [blame] | 13 | |
| 14 | |
Rob Landley | dfba741 | 2006-03-06 20:47:33 +0000 | [diff] [blame] | 15 | char *pw_encrypt(const char *clear, const char *salt) |
Eric Andersen | 27f64e1 | 2002-06-23 04:24:25 +0000 | [diff] [blame] | 16 | { |
| 17 | static char cipher[128]; |
| 18 | char *cp; |
| 19 | |
| 20 | #ifdef CONFIG_FEATURE_SHA1_PASSWORDS |
| 21 | if (strncmp(salt, "$2$", 3) == 0) { |
| 22 | return sha1_crypt(clear); |
| 23 | } |
| 24 | #endif |
| 25 | cp = (char *) crypt(clear, salt); |
| 26 | /* if crypt (a nonstandard crypt) returns a string too large, |
| 27 | truncate it so we don't overrun buffers and hope there is |
| 28 | enough security in what's left */ |
Glenn L McGrath | 393183d | 2003-05-26 14:07:50 +0000 | [diff] [blame] | 29 | safe_strncpy(cipher, cp, sizeof(cipher)); |
Eric Andersen | 27f64e1 | 2002-06-23 04:24:25 +0000 | [diff] [blame] | 30 | return cipher; |
| 31 | } |
| 32 | |