summaryrefslogtreecommitdiffstats
path: root/sysif.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2019-08-26 06:46:09 -0700
committerKaz Kylheku <kaz@kylheku.com>2019-08-26 06:46:09 -0700
commite1d9261a6c0cacf922c7d189603bbd4bf0ba3017 (patch)
treeb6d7b8e0fecc2ba7273654eccc21f463e0994d0e /sysif.c
parentc45fbf26af40b73202d42b6f0d5ef419e3412883 (diff)
downloadtxr-e1d9261a6c0cacf922c7d189603bbd4bf0ba3017.tar.gz
txr-e1d9261a6c0cacf922c7d189603bbd4bf0ba3017.tar.bz2
txr-e1d9261a6c0cacf922c7d189603bbd4bf0ba3017.zip
crypt: detect and use glibc's crypt_r.
* configure: New test for crypt_r, depositing HAVE_CRYPT_R preprocessor symbol in config.h. * sysif.c: Conditionally include <crypt.h> header. (crypt_wrap): Use crypt_r if HAVE_CRYPT_R is nonzero. (sysif_init): Register crypt intrinsic if we HAVE_CRYPT or if we HAVE_CRYPT_R.
Diffstat (limited to 'sysif.c')
-rw-r--r--sysif.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/sysif.c b/sysif.c
index 1cce32db..f1eb5fa4 100644
--- a/sysif.c
+++ b/sysif.c
@@ -76,6 +76,9 @@
#if HAVE_DLOPEN
#include <dlfcn.h>
#endif
+#if HAVE_CRYPT_R
+#include <crypt.h>
+#endif
#include "alloca.h"
#include "lib.h"
#include "stream.h"
@@ -1446,7 +1449,7 @@ static val getgrnam_wrap(val wname)
#endif
-#if HAVE_CRYPT
+#if HAVE_CRYPT || HAVE_CRYPT_R
static val crypt_wrap(val wkey, val wsalt)
{
@@ -1454,7 +1457,12 @@ static val crypt_wrap(val wkey, val wsalt)
const wchar_t *cwsalt = c_str(wsalt);
char *key = utf8_dup_to(cwkey);
char *salt = utf8_dup_to(cwsalt);
+#if HAVE_CRYPT_R
+ struct crypt_data cd;
+ char *hash = (cd.initialized = 0, crypt_r(key, salt, &cd));
+#else
char *hash = crypt(key, salt);
+#endif
val whash = string_utf8(hash);
free(key);
free(salt);
@@ -2137,7 +2145,7 @@ void sysif_init(void)
reg_fun(intern(lit("getgrnam"), user_package), func_n1(getgrnam_wrap));
#endif
-#if HAVE_CRYPT
+#if HAVE_CRYPT || HAVE_CRYPT_R
reg_fun(intern(lit("crypt"), user_package), func_n2(crypt_wrap));
#endif