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,19 +35,35 @@ static int nixio_sock__sendto(lua_State *L, int to) {
if (to) {
argoff += 2;
const char *address = luaL_checkstring(L, 3);
struct sockaddr_storage addrstor;
addr = (struct sockaddr*)&addrstor;
if (sock->domain == AF_INET || sock->domain == AF_INET6) {
const char *address = luaL_checkstring(L, 3);
struct sockaddr_storage addrstor;
addr = (struct sockaddr*)&addrstor;
nixio_addr naddr;
memset(&naddr, 0, sizeof(naddr));
strncpy(naddr.host, address, sizeof(naddr.host) - 1);
naddr.port = (uint16_t)luaL_checkinteger(L, 4);
naddr.family = sock->domain;
nixio_addr naddr;
memset(&naddr, 0, sizeof(naddr));
strncpy(naddr.host, address, sizeof(naddr.host) - 1);
naddr.port = (uint16_t)luaL_checkinteger(L, 4);
naddr.family = sock->domain;
if (nixio__addr_write(&naddr, addr)) {
return nixio__perror_s(L);
if (nixio__addr_write(&naddr, addr)) {
return nixio__perror_s(L);
}
}
#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;
@ -104,15 +120,22 @@ static int nixio_sock__recvfrom(lua_State *L, int from) {
nixio_sock *sock = nixio__checksock(L);
char buffer[NIXIO_BUFFERSIZE];
struct sockaddr_storage addrobj;
struct sockaddr_un addrobj_un;
struct sockaddr *addr;
socklen_t alen;
uint req = luaL_checkinteger(L, 2);
int readc;
if (from && sock->domain != AF_INET && sock->domain != AF_INET6) {
return luaL_argerror(L, 1, "supported families: inet, inet6");
if (sock->domain == AF_INET || sock->domain == AF_INET6) {
addr = (from) ? (struct sockaddr*)&addrobj : NULL;
alen = (from) ? sizeof(addrobj) : 0;
}
struct sockaddr *addr = (from) ? (struct sockaddr*)&addrobj : NULL;
socklen_t alen = (from) ? sizeof(addrobj) : 0;
#ifndef __WINNT__
else if (sock->domain == AF_UNIX) {
addr = (from) ? (struct sockaddr*)&addrobj_un : NULL;
alen = (from) ? sizeof(addrobj_un) : 0;
}
#endif
/* We limit the readsize to NIXIO_BUFFERSIZE */
req = (req > NIXIO_BUFFERSIZE) ? NIXIO_BUFFERSIZE : req;
@ -137,7 +160,8 @@ static int nixio_sock__recvfrom(lua_State *L, int from) {
if (!from) {
return 1;
} else {
}
else if (sock->domain == AF_INET || sock->domain == AF_INET6) {
nixio_addr naddr;
if (!nixio__addr_parse(&naddr, (struct sockaddr *)&addrobj)) {
lua_pushstring(L, naddr.host);
@ -147,6 +171,12 @@ static int nixio_sock__recvfrom(lua_State *L, int from) {
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");
}
#ifdef WITH_CYASSL
SSL_CTX_set_verify(*ctx, SSL_VERIFY_NONE, NULL);
#endif
return 1;
}
@ -131,6 +127,14 @@ static int nixio_tls_ctx_set_cert(lua_State *L) {
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) {
SSL_CTX *ctx = nixio__checktlsctx(L);
const char *cert = luaL_checkstring(L, 2);
@ -203,13 +207,14 @@ static const luaL_reg R[] = {
/* ctx function table */
static const luaL_reg CTX_M[] = {
{"set_cert", nixio_tls_ctx_set_cert},
{"set_key", nixio_tls_ctx_set_key},
{"set_verify_locations", nixio_tls_ctx_set_verify_locations},
{"set_key", nixio_tls_ctx_set_key},
{"set_ciphers", nixio_tls_ctx_set_ciphers},
{"set_verify", nixio_tls_ctx_set_verify},
{"create", nixio_tls_ctx_create},
{"__gc", nixio_tls_ctx__gc},
{"create", nixio_tls_ctx_create},
{"__gc", nixio_tls_ctx__gc},
{"__tostring", nixio_tls_ctx__tostring},
{NULL, NULL}
{NULL, NULL}
};

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
+++ luci-0.9.0/libs/nixio/src/tls-context.c 2010-08-08 13:38:59.501480201 +0200
--- a/libs/nixio/src/tls-context.c 2010-08-08 13:31:53.529481604 +0200
+++ b/libs/nixio/src/tls-context.c 2010-08-08 13:38:59.501480201 +0200
@@ -65,10 +65,6 @@
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
+++ luci-0.9.0/libs/nixio/src/io.c 2010-08-11 11:28:09.724417190 +0200
--- a/libs/nixio/src/io.c 2010-08-10 22:26:11.920381434 +0200
+++ b/libs/nixio/src/io.c 2010-08-11 11:28:09.724417190 +0200
@@ -35,19 +35,35 @@
if (to) {