openwrt: clean up luci nixio tls and unix domain socket patches and apply them to luci 0.9

This commit is contained in:
Bart Van Der Meerssche 2010-12-19 21:17:16 +01:00
parent 6fe1376501
commit 1a9ada411f
4 changed files with 63 additions and 28 deletions

View File

@ -35,6 +35,7 @@ static int nixio_sock__sendto(lua_State *L, int to) {
if (to) { if (to) {
argoff += 2; argoff += 2;
if (sock->domain == AF_INET || sock->domain == AF_INET6) {
const char *address = luaL_checkstring(L, 3); const char *address = luaL_checkstring(L, 3);
struct sockaddr_storage addrstor; struct sockaddr_storage addrstor;
addr = (struct sockaddr*)&addrstor; addr = (struct sockaddr*)&addrstor;
@ -50,6 +51,21 @@ static int nixio_sock__sendto(lua_State *L, int to) {
} }
} }
#ifndef __WINNT__
else if (sock->domain == AF_UNIX) {
size_t pathlen;
const char *path = luaL_checklstring(L, 3, &pathlen);
struct sockaddr_un addr_un;
addr_un.sun_family = AF_UNIX;
luaL_argcheck(L, pathlen < sizeof(addr_un.sun_path), 3, "out of range");
strncpy(addr_un.sun_path, path, sizeof(addr_un.sun_path));
addr = (struct sockaddr*)&addr_un;
}
#endif
}
size_t len; size_t len;
ssize_t sent; ssize_t sent;
const char *data = luaL_checklstring(L, 2, &len); const char *data = luaL_checklstring(L, 2, &len);
@ -104,15 +120,22 @@ static int nixio_sock__recvfrom(lua_State *L, int from) {
nixio_sock *sock = nixio__checksock(L); nixio_sock *sock = nixio__checksock(L);
char buffer[NIXIO_BUFFERSIZE]; char buffer[NIXIO_BUFFERSIZE];
struct sockaddr_storage addrobj; struct sockaddr_storage addrobj;
struct sockaddr_un addrobj_un;
struct sockaddr *addr;
socklen_t alen;
uint req = luaL_checkinteger(L, 2); uint req = luaL_checkinteger(L, 2);
int readc; int readc;
if (from && sock->domain != AF_INET && sock->domain != AF_INET6) { if (sock->domain == AF_INET || sock->domain == AF_INET6) {
return luaL_argerror(L, 1, "supported families: inet, inet6"); addr = (from) ? (struct sockaddr*)&addrobj : NULL;
alen = (from) ? sizeof(addrobj) : 0;
} }
#ifndef __WINNT__
struct sockaddr *addr = (from) ? (struct sockaddr*)&addrobj : NULL; else if (sock->domain == AF_UNIX) {
socklen_t alen = (from) ? sizeof(addrobj) : 0; addr = (from) ? (struct sockaddr*)&addrobj_un : NULL;
alen = (from) ? sizeof(addrobj_un) : 0;
}
#endif
/* We limit the readsize to NIXIO_BUFFERSIZE */ /* We limit the readsize to NIXIO_BUFFERSIZE */
req = (req > NIXIO_BUFFERSIZE) ? NIXIO_BUFFERSIZE : req; req = (req > NIXIO_BUFFERSIZE) ? NIXIO_BUFFERSIZE : req;
@ -137,7 +160,8 @@ static int nixio_sock__recvfrom(lua_State *L, int from) {
if (!from) { if (!from) {
return 1; return 1;
} else { }
else if (sock->domain == AF_INET || sock->domain == AF_INET6) {
nixio_addr naddr; nixio_addr naddr;
if (!nixio__addr_parse(&naddr, (struct sockaddr *)&addrobj)) { if (!nixio__addr_parse(&naddr, (struct sockaddr *)&addrobj)) {
lua_pushstring(L, naddr.host); lua_pushstring(L, naddr.host);
@ -147,6 +171,12 @@ static int nixio_sock__recvfrom(lua_State *L, int from) {
return 1; return 1;
} }
} }
#ifndef __WINNT__
else if (sock->domain == AF_UNIX) {
lua_pushstring(L, addrobj_un.sun_path);
return 2;
}
#endif
} }
} }

View File

@ -65,10 +65,6 @@ static int nixio_tls_ctx(lua_State * L) {
return luaL_error(L, "unable to create TLS context"); return luaL_error(L, "unable to create TLS context");
} }
#ifdef WITH_CYASSL
SSL_CTX_set_verify(*ctx, SSL_VERIFY_NONE, NULL);
#endif
return 1; return 1;
} }
@ -131,6 +127,14 @@ static int nixio_tls_ctx_set_cert(lua_State *L) {
SSL_CTX_use_certificate_file(ctx, cert, ktype)); SSL_CTX_use_certificate_file(ctx, cert, ktype));
} }
static int nixio_tls_ctx_set_verify_locations(lua_State *L) {
SSL_CTX *ctx = nixio__checktlsctx(L);
const char *CAfile = luaL_optstring(L, 2, NULL);
const char *CApath = luaL_optstring(L, 3, NULL);
return nixio__tls_pstatus(L, SSL_CTX_load_verify_locations(ctx, CAfile, CApath));
}
static int nixio_tls_ctx_set_key(lua_State *L) { static int nixio_tls_ctx_set_key(lua_State *L) {
SSL_CTX *ctx = nixio__checktlsctx(L); SSL_CTX *ctx = nixio__checktlsctx(L);
const char *cert = luaL_checkstring(L, 2); const char *cert = luaL_checkstring(L, 2);
@ -203,6 +207,7 @@ static const luaL_reg R[] = {
/* ctx function table */ /* ctx function table */
static const luaL_reg CTX_M[] = { static const luaL_reg CTX_M[] = {
{"set_cert", nixio_tls_ctx_set_cert}, {"set_cert", nixio_tls_ctx_set_cert},
{"set_verify_locations", nixio_tls_ctx_set_verify_locations},
{"set_key", nixio_tls_ctx_set_key}, {"set_key", nixio_tls_ctx_set_key},
{"set_ciphers", nixio_tls_ctx_set_ciphers}, {"set_ciphers", nixio_tls_ctx_set_ciphers},
{"set_verify", nixio_tls_ctx_set_verify}, {"set_verify", nixio_tls_ctx_set_verify},

View File

@ -1,5 +1,5 @@
--- /tmp/luci-0.9.0/libs/nixio/src/tls-context.c 2010-08-08 13:31:53.529481604 +0200 --- a/libs/nixio/src/tls-context.c 2010-08-08 13:31:53.529481604 +0200
+++ luci-0.9.0/libs/nixio/src/tls-context.c 2010-08-08 13:38:59.501480201 +0200 +++ b/libs/nixio/src/tls-context.c 2010-08-08 13:38:59.501480201 +0200
@@ -65,10 +65,6 @@ @@ -65,10 +65,6 @@
return luaL_error(L, "unable to create TLS context"); return luaL_error(L, "unable to create TLS context");
} }

View File

@ -1,5 +1,5 @@
--- /tmp/luci-0.9.0/libs/nixio/src/io.c 2010-08-10 22:26:11.920381434 +0200 --- a/libs/nixio/src/io.c 2010-08-10 22:26:11.920381434 +0200
+++ luci-0.9.0/libs/nixio/src/io.c 2010-08-11 11:28:09.724417190 +0200 +++ b/libs/nixio/src/io.c 2010-08-11 11:28:09.724417190 +0200
@@ -35,19 +35,35 @@ @@ -35,19 +35,35 @@
if (to) { if (to) {