mirror of
https://github.com/bol-van/zapret2.git
synced 2026-03-14 06:13:09 +00:00
nfqws2: support gzipped lua
This commit is contained in:
@@ -143,3 +143,4 @@ v0.8.0
|
|||||||
* zapret-lib: tls dissector/reconstructor
|
* zapret-lib: tls dissector/reconstructor
|
||||||
* zapret-antidpi: tls_client_hello_clone
|
* zapret-antidpi: tls_client_hello_clone
|
||||||
* zapret-antidpi: "optional" arg to blob taking functions
|
* zapret-antidpi: "optional" arg to blob taking functions
|
||||||
|
* nfqws2: support gzipped lua file. auto use script.lua.gz
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
#define BUFMIN 128
|
#define BUFMIN 128
|
||||||
#define BUFCHUNK (1024*128)
|
#define BUFCHUNK (1024*128)
|
||||||
|
|
||||||
int z_readfile(FILE *F, char **buf, size_t *size)
|
int z_readfile(FILE *F, char **buf, size_t *size, size_t extra_alloc)
|
||||||
{
|
{
|
||||||
z_stream zs;
|
z_stream zs;
|
||||||
int r;
|
int r;
|
||||||
@@ -38,7 +38,7 @@ int z_readfile(FILE *F, char **buf, size_t *size)
|
|||||||
if ((bufsize - *size) < BUFMIN)
|
if ((bufsize - *size) < BUFMIN)
|
||||||
{
|
{
|
||||||
bufsize += BUFCHUNK;
|
bufsize += BUFCHUNK;
|
||||||
newbuf = *buf ? realloc(*buf, bufsize) : malloc(bufsize);
|
newbuf = *buf ? realloc(*buf, bufsize + extra_alloc) : malloc(bufsize + extra_alloc);
|
||||||
if (!newbuf)
|
if (!newbuf)
|
||||||
{
|
{
|
||||||
r = Z_MEM_ERROR;
|
r = Z_MEM_ERROR;
|
||||||
@@ -57,7 +57,7 @@ int z_readfile(FILE *F, char **buf, size_t *size)
|
|||||||
if (*size < bufsize)
|
if (*size < bufsize)
|
||||||
{
|
{
|
||||||
// free extra space
|
// free extra space
|
||||||
if ((newbuf = realloc(*buf, *size))) *buf = newbuf;
|
if ((newbuf = realloc(*buf, *size + extra_alloc))) *buf = newbuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
inflateEnd(&zs);
|
inflateEnd(&zs);
|
||||||
|
|||||||
@@ -4,5 +4,5 @@
|
|||||||
#include <zlib.h>
|
#include <zlib.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
int z_readfile(FILE *F,char **buf,size_t *size);
|
int z_readfile(FILE *F, char **buf, size_t *size, size_t extra_alloc);
|
||||||
bool is_gzip(FILE* F);
|
bool is_gzip(FILE* F);
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ bool AppendHostList(hostlist_pool **hostlist, const char *filename)
|
|||||||
|
|
||||||
if (is_gzip(F))
|
if (is_gzip(F))
|
||||||
{
|
{
|
||||||
r = z_readfile(F,&zbuf,&zsize);
|
r = z_readfile(F,&zbuf,&zsize,0);
|
||||||
fclose(F);
|
fclose(F);
|
||||||
if (r==Z_OK)
|
if (r==Z_OK)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ static bool AppendIpset(ipset *ips, const char *filename)
|
|||||||
|
|
||||||
if (is_gzip(F))
|
if (is_gzip(F))
|
||||||
{
|
{
|
||||||
r = z_readfile(F,&zbuf,&zsize);
|
r = z_readfile(F,&zbuf,&zsize,0);
|
||||||
fclose(F);
|
fclose(F);
|
||||||
if (r==Z_OK)
|
if (r==Z_OK)
|
||||||
{
|
{
|
||||||
|
|||||||
60
nfq2/lua.c
60
nfq2/lua.c
@@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
#include "lua.h"
|
#include "lua.h"
|
||||||
#include "params.h"
|
#include "params.h"
|
||||||
|
#include "gzip.h"
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
#include "conntrack.h"
|
#include "conntrack.h"
|
||||||
#include "crypto/sha.h"
|
#include "crypto/sha.h"
|
||||||
@@ -2899,17 +2900,43 @@ static bool lua_desync_functions_exist()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool lua_file_open_test(const char *filename, bool *b_gzip, char *fname)
|
||||||
|
{
|
||||||
|
FILE *F = fopen(filename,"rb");
|
||||||
|
if (F)
|
||||||
|
{
|
||||||
|
if (fname) snprintf(fname,PATH_MAX,"%s",filename);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
size_t l = strlen(filename);
|
||||||
|
char *fngz = malloc(l+4);
|
||||||
|
if (!fngz) return false;
|
||||||
|
memcpy(fngz, filename, l);
|
||||||
|
memcpy(fngz+l,".gz",4);
|
||||||
|
if (fname) snprintf(fname,PATH_MAX,"%s",fngz);
|
||||||
|
F = fopen(fngz,"rb");
|
||||||
|
free(fngz);
|
||||||
|
}
|
||||||
|
if (F)
|
||||||
|
{
|
||||||
|
if (b_gzip) *b_gzip = is_gzip(F);
|
||||||
|
fclose(F);
|
||||||
|
}
|
||||||
|
return !!F;
|
||||||
|
}
|
||||||
|
|
||||||
bool lua_test_init_script_files(void)
|
bool lua_test_init_script_files(void)
|
||||||
{
|
{
|
||||||
struct str_list *str;
|
struct str_list *str;
|
||||||
LIST_FOREACH(str, ¶ms.lua_init_scripts, next)
|
LIST_FOREACH(str, ¶ms.lua_init_scripts, next)
|
||||||
{
|
{
|
||||||
if (str->str[0]=='@' && !file_open_test(str->str+1, O_RDONLY))
|
if (str->str[0]=='@' && !lua_file_open_test(str->str+1, NULL, NULL))
|
||||||
{
|
{
|
||||||
#ifndef __CYGWIN__
|
#ifndef __CYGWIN__
|
||||||
int e = errno;
|
int e = errno;
|
||||||
#endif
|
#endif
|
||||||
DLOG_ERR("LUA file '%s' not accessible\n", str->str+1);
|
DLOG_ERR("LUA file '%s' or '%s.gz' not accessible\n", str->str+1, str->str+1);
|
||||||
#ifndef __CYGWIN__
|
#ifndef __CYGWIN__
|
||||||
if (e==EACCES)
|
if (e==EACCES)
|
||||||
DLOG_ERR("I drop my privileges and do not run Lua as root\ncheck file permissions and +x rights on all directories in the path\n");
|
DLOG_ERR("I drop my privileges and do not run Lua as root\ncheck file permissions and +x rights on all directories in the path\n");
|
||||||
@@ -2920,6 +2947,33 @@ bool lua_test_init_script_files(void)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int luaL_doZfile(lua_State *L, const char *filename)
|
||||||
|
{
|
||||||
|
bool b_gzip;
|
||||||
|
char fname[PATH_MAX];
|
||||||
|
if (!lua_file_open_test(filename, &b_gzip, fname))
|
||||||
|
luaL_error(L, "could not open lua file '%s' or '%s.gz'", filename, filename);
|
||||||
|
if (b_gzip)
|
||||||
|
{
|
||||||
|
size_t size;
|
||||||
|
char *buf;
|
||||||
|
int r;
|
||||||
|
FILE *F = fopen(fname, "rb");
|
||||||
|
if (!F)
|
||||||
|
luaL_error(L, "could not open lua file '%s'", fname);
|
||||||
|
r = z_readfile(F, &buf, &size, 1);
|
||||||
|
fclose(F);
|
||||||
|
if (r != Z_OK)
|
||||||
|
luaL_error(L, "could not unzip lua file '%s'", fname);
|
||||||
|
buf[size] = 0;
|
||||||
|
r = luaL_dostring(L, buf);
|
||||||
|
free(buf);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return luaL_dofile(L, filename);
|
||||||
|
}
|
||||||
|
|
||||||
static bool lua_init_scripts(void)
|
static bool lua_init_scripts(void)
|
||||||
{
|
{
|
||||||
struct str_list *str;
|
struct str_list *str;
|
||||||
@@ -2938,7 +2992,7 @@ static bool lua_init_scripts(void)
|
|||||||
DLOG("LUA RUN STR: %s\n",s);
|
DLOG("LUA RUN STR: %s\n",s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((status = str->str[0]=='@' ? luaL_dofile(params.L, str->str+1) : luaL_dostring(params.L, str->str)))
|
if ((status = str->str[0]=='@' ? luaL_doZfile(params.L, str->str+1) : luaL_dostring(params.L, str->str)))
|
||||||
{
|
{
|
||||||
lua_perror(params.L);
|
lua_perror(params.L);
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user