1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
--- a/lposix.c
+++ b/lposix.c
@@ -1016,6 +1016,29 @@
}
#endif
+/*
+ * XXX: GNU and BSD handle the forward declaration of crypt() in different
+ * and annoying ways (especially GNU). Declare it here just to make sure
+ * that it's there
+ */
+char *crypt(const char *, const char *);
+
+static int Pcrypt(lua_State *L)
+{
+ const char *str, *salt;
+ char *res;
+
+ str = luaL_checkstring(L, 1);
+ salt = luaL_checkstring(L, 2);
+ if (strlen(salt) < 2)
+ luaL_error(L, "not enough salt");
+
+ res = crypt(str, salt);
+ lua_pushstring(L, res);
+
+ return 1;
+}
+
static const luaL_reg R[] =
{
{"access", Paccess},
@@ -1023,6 +1046,7 @@
{"chdir", Pchdir},
{"chmod", Pchmod},
{"chown", Pchown},
+ {"crypt", Pcrypt},
{"ctermid", Pctermid},
{"dirname", Pdirname},
{"dir", Pdir},
--- a/Makefile
+++ b/Makefile
@@ -37,8 +37,10 @@
OS=$(shell uname)
ifeq ($(OS),Darwin)
LDFLAGS_SHARED=-bundle -undefined dynamic_lookup
+ LIBS=
else
LDFLAGS_SHARED=-shared
+ LIBS=-lcrypt
endif
# targets
@@ -50,7 +52,7 @@
$(LUA) test.lua
$T: $(OBJS)
- $(CC) $(LDFLAGS) -o $@ $(LDFLAGS_SHARED) $(OBJS)
+ $(CC) $(LDFLAGS) -o $@ $(LDFLAGS_SHARED) $(OBJS) $(LIBS)
$(OBJS): modemuncher.c
|