diff options
-rwxr-xr-x | configure | 27 | ||||
-rw-r--r-- | sysif.c | 19 | ||||
-rw-r--r-- | txr.1 | 27 |
3 files changed, 73 insertions, 0 deletions
@@ -2235,6 +2235,33 @@ int main(void) fi fi +printf "Checking for crypt ... " + +cat > conftest.c <<! +#include <unistd.h> + +int main(void) +{ + char *c = crypt("foo", "bar"); + return 0; +} +! + +for try_lcrypt in "" "-lcrypt" "no" ; do + if [ "$try_lcrypt" = "no" ] ; then + printf "no\n" + break + fi + if conftest EXTRA_LDFLAGS=$try_lcrypt; then + printf "yes\n" + printf "#define HAVE_CRYPT 1\n" >> $config_h + if [ -n "$try_lcrypt" ] ; then + conf_ldflags="${conf_ldflags:+"$conf_ldflags "}-lcrypt" + fi + break; + fi +done + printf "Checking for alloca ... " for try_header in alloca.h malloc.h ; do @@ -1037,6 +1037,21 @@ static val getgrnam_wrap(val wname) #endif +#if HAVE_CRYPT + +static val crypt_wrap(val wkey, val wsalt) +{ + char *key = utf8_dup_to(c_str(wkey)); + char *salt = utf8_dup_to(c_str(wsalt)); + char *hash = crypt(key, salt); + val whash = string_utf8(hash); + free(key); + free(salt); + return whash; +} + +#endif + off_t off_t_num(val num) { switch (type(num)) { @@ -1397,6 +1412,10 @@ void sysif_init(void) reg_fun(intern(lit("getgrnam"), user_package), func_n1(getgrnam_wrap)); #endif +#if HAVE_CRYPT + reg_fun(intern(lit("crypt"), user_package), func_n2(crypt_wrap)); +#endif + #if HAVE_POLL reg_fun(intern(lit("poll"), user_package), func_n2o(poll_wrap, 1)); #endif @@ -36030,6 +36030,33 @@ If the search fails, .code nil is returned. +.SS* Unix Password Hashing +.coNP Function @ crypt +.synb +.mets (crypt < key << salt ) +.syne +.desc +The +.code crypt +function is a wrapper for the Unix C library function of the same name. +It calculates a hash over the +.meta key +and +.meta salt +arguments, which are strings. The hash is returned as a string. + +The +.meta key +and +.meta salt +arguments are converted into UTF-8 prior to being passed into the underlying +platform function. The hash value is assumed to be UTF-8 and converted to +Unicode characters, though it is not expected to contain anything but 7 +bit ASCII characters. + +Note: the underlying C library function uses a static buffer for its return +value. The return value of the \*(TL function is a copy of that buffer. + .SS* Unix Signal Handling On platforms where certain advanced features of POSIX signal handling are |