pw_encrypt.c 611 B

123456789101112131415161718192021222324252627
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * Utility routine.
  4. *
  5. * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
  6. *
  7. * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
  8. */
  9. #include "libbb.h"
  10. #include <crypt.h>
  11. char *pw_encrypt(const char *clear, const char *salt)
  12. {
  13. /* Was static char[BIGNUM]. Malloced thing works as well */
  14. static char *cipher;
  15. #if 0 /* was CONFIG_FEATURE_SHA1_PASSWORDS, but there is no such thing??? */
  16. if (strncmp(salt, "$2$", 3) == 0) {
  17. return sha1_crypt(clear);
  18. }
  19. #endif
  20. free(cipher);
  21. cipher = xstrdup(crypt(clear, salt));
  22. return cipher;
  23. }