Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • texlive/luatex
1 result
Show changes
Commits on Source (4)
......@@ -88,6 +88,8 @@ consequence. The following command|-|line options are understood:
\NC \type{--[no-]mktex=FMT} \NC disable/enable \type {mktexFMT} generation with \type {FMT} is
\type {tex} or \type {tfm} \NC \NR
\NC \type{--nosocket} \NC disable the \LUA\ socket library \NC\NR
\NC \type{--no-socket} \NC disable the \LUA\ socket library \NC\NR
\NC \type{--socket} \NC enable the \LUA\ socket library \NC\NR
\NC \type{--output-comment=STRING} \NC use \type {STRING} for \DVI\ file comment instead of date (no
effect for \PDF) \NC \NR
\NC \type{--output-directory=DIR} \NC use \type {DIR} as the directory to write files to \NC \NR
......@@ -147,7 +149,8 @@ in the following order:
\startitem
First, it will parse the command line as usual, but it will only interpret a
small subset of the options immediately: \type {--safer}, \type {--nosocket},
\type {--[no-]shell-escape}, \type {--enable-write18}, \type
\type {--no-socket},
\type {--socket}, \type {--[no-]shell-escape}, \type {--enable-write18}, \type
{--disable-write18}, \type {--shell-restricted}, \type {--help}, \type
{--version}, and \type {--credits}.
\stopitem
......@@ -182,6 +185,9 @@ in the following order:
Furthermore, it disables loading of compiled \LUA\ libraries and it makes
\type {io.open()} fail on files that are opened for anything besides reading.
Finally, it disables the \type {socket} library unconditionally (but not the
\type {mime} library which is always available).
\stopitem
\startitem
......@@ -194,13 +200,25 @@ in the following order:
os.setlocale(nil,nil)
\stoptyping
The \type {--nosocket} option makes the socket library unavailable, so that \LUA\
cannot use networking.
The \type {--nosocket} or \type {--no-socket} option makes the socket library
unavailable, so that \LUA\ cannot use networking;
\type {--socket} option makes the socket library available.
The switches \type {--[no-]shell-escape}, \type {--[enable|disable]-write18}, and
\type {--shell-restricted} have the same effects as in \PDFTEX, and additionally
make \type {io.popen()}, \type {os.execute}, \type {os.exec}, \type {os.kpsepopen}
and \type {os.spawn} adhere to the requested option.
By default
the socket library is not enabled: one can enable it with with \type {--socket}
or with \type {--shell-escape} (but without \type {--shell-restricted})
and disable it with \type {--nosocket} (or \type {--no-socket})
or unconditionally with \type {--safer}.
In case of conflictual options, the most restrictive wins.
The \type{mime} library is always available.
\stopitem
\startitem
......@@ -434,8 +452,10 @@ used as building blocks for other helpers.
\startsubsection[title={Extra \type {os} library functions}]
The \type {os} library has a few extra functions and
variables: \libidx {os} {selfdir}, \libidx {os} {exec}, \libidx {os}
{kpsepopen}, \libidx {os} {spawn}, \libidx {os} {setenv},
variables: \libidx {os} {selfdir}, \libidx {os} {exec},
\libidx {os} {kpsepopen},
\libidx {os} {socketgettime}, \libidx {os} {socketsleep},
\libidx {os} {spawn}, \libidx {os} {setenv},
\libidx {os} {env}, \libidx {os} {gettimeofday}, \libidx {os} {times},
\libidx {os} {sleep}, \libidx {os} {tmpdir}, \libidx {os} {type},
\libidx {os} {name} and \libidx {os} {uname},{os} {uname},
......@@ -508,6 +528,11 @@ that we will discuss here.
Otherwise it will return the two values \type {nil} and \type {error}.
\stopitem
\startitem
\type {os.socketgettime} and \type {os.socketsleep} are the same as for
\type{socket.gettime} and \type{socket.sleep} but they are always available.
\stopitem
\startitem
\type {os.spawn(commandline)} is a returning version of \type {os.exec},
with otherwise identical calling conventions.
......
No preview for this file type
2023-04-28 Luigi Scarso <luigi.scarso@gmail.com>
* new option --no-socket, same as --nosocket
2023-04-27 Luigi Scarso <luigi.scarso@gmail.com>
* new option --socket to split socket and shell escape;
* the mime library is always available (Max Chernoff);
* Fixed ChangeLog
2023-04-25 Luigi Scarso <luigi.scarso@gmail.com>
* socket library by default not enabled;
it is enabled with --shell-escape but not with --shell-restricted.
The option ---nosocket remains unchanged.
The two new functions os.socketgettime and os.socketsleep are
like socket.gettime and socket.sleep, but they are always available.
* Luatex 1.17.0
2023-04-24 Luigi Scarso <luigi.scarso@gmail.com>
* static kpse.check_permissions in os.kpsepopen
* Fixed date in ChangeLog
......
......@@ -1154,6 +1154,59 @@ static int io_kpse_popen (lua_State *L) {
/* socket.sleep and socket.gettime */
/* are duplicated here, and they are */
/* always available (the socket library */
/* can be nil in some setups) */
#ifdef _WIN32
static int socket_timeout_lua_sleep(lua_State *L)
{
double n = luaL_checknumber(L, 1);
if (n < 0.0) n = 0.0;
if (n < DBL_MAX/1000.0) n *= 1000.0;
if (n > INT_MAX) n = INT_MAX;
Sleep((int)n);
return 0;
}
static double socket_timeout_gettime(void) {
FILETIME ft;
double t;
GetSystemTimeAsFileTime(&ft);
/* Windows file time (time since January 1, 1601 (UTC)) */
t = ft.dwLowDateTime/1.0e7 + ft.dwHighDateTime*(4294967296.0/1.0e7);
/* convert to Unix Epoch time (time since January 1, 1970 (UTC)) */
return (t - 11644473600.0);
}
#else
static int socket_timeout_lua_sleep(lua_State *L)
{
double n = luaL_checknumber(L, 1);
struct timespec t, r;
if (n < 0.0) n = 0.0;
if (n > INT_MAX) n = INT_MAX;
t.tv_sec = (int) n;
n -= t.tv_sec;
t.tv_nsec = (int) (n * 1000000000);
if (t.tv_nsec >= 1000000000) t.tv_nsec = 999999999;
while (nanosleep(&t, &r) != 0) {
t.tv_sec = r.tv_sec;
t.tv_nsec = r.tv_nsec;
}
return 0;
}
static double socket_timeout_gettime(void) {
struct timeval v;
gettimeofday(&v, (struct timezone *) NULL);
/* Unix Epoch time (time since January 1, 1970 (UTC)) */
return v.tv_sec + v.tv_usec/1.0e6;
}
#endif
static int socket_timeout_lua_gettime(lua_State *L)
{
lua_pushnumber(L, socket_timeout_gettime());
return 1;
}
void open_oslibext(lua_State * L)
{
......@@ -1188,8 +1241,16 @@ void open_oslibext(lua_State * L)
lua_setfield(L, -2, "execute");
lua_pushcfunction(L, os_tmpdir);
lua_setfield(L, -2, "tmpdir");
lua_pushcfunction(L, io_kpse_popen);
lua_setfield(L, -2, "kpsepopen");
lua_pushcfunction(L, socket_timeout_lua_sleep);
lua_setfield(L, -2, "socketsleep");
lua_pushcfunction(L, socket_timeout_lua_gettime);
lua_setfield(L, -2, "socketgettime");
lua_pop(L, 1); /* pop the table */
}
......@@ -85,6 +85,8 @@ const_string LUATEX_IHELP[] = {
" --lua=FILE load and execute a lua initialization script",
" --[no-]mktex=FMT disable/enable mktexFMT generation (FMT=tex/tfm)",
" --nosocket disable the lua socket library",
" --no-socket disable the lua socket library",
" --socket enable the lua socket library",
" --output-comment=STRING use STRING for DVI file comment instead of date (no effect for PDF)",
" --output-directory=DIR use existing DIR as the directory to write files in",
" --output-format=FORMAT use FORMAT for job output; FORMAT is 'dvi' or 'pdf'",
......@@ -212,9 +214,30 @@ char *jithash_hashname = NULL;
#endif
int safer_option = 0;
int nosocket_option = 0;
int nosocket_option = 1;
int nosocket_cli_option = 0;
int yessocket_cli_option = 0;
int socket_bitmask = 0;
int utc_option = 0;
/*tex We use a bitmask for the socket library: |0000| and |1xxx| implies |--nosocket|,
otherwise the socket library is enabled. Default value is |0000|, i.e. |--nosocket|.
*/
#define UPDATE_SOCKET_STATUS() do { \
socket_bitmask = 0; \
socket_bitmask = safer_option==1? (8+socket_bitmask):socket_bitmask;\
socket_bitmask = nosocket_cli_option==1? (4+socket_bitmask):socket_bitmask;\
socket_bitmask = (shellenabledp == 1 && restrictedshell == 0)?(2+socket_bitmask):socket_bitmask;\
socket_bitmask = yessocket_cli_option==1? (1+socket_bitmask):socket_bitmask;\
if( socket_bitmask==0) { \
nosocket_option = 1; \
} else if ( socket_bitmask<4) { \
nosocket_option = 0; \
} else { \
nosocket_option = 1; \
} \
} while (0)
/*tex
Test whether getopt found an option ``A''. Assumes the option index is in the
......@@ -242,7 +265,9 @@ static struct option long_options[] = {
#endif
{"safer", 0, &safer_option, 1},
{"utc", 0, &utc_option, 1},
{"nosocket", 0, &nosocket_option, 1},
{"nosocket", 0, &nosocket_cli_option, 1},
{"no-socket", 0, &nosocket_cli_option, 1},
{"socket", 0, &yessocket_cli_option, 1},
{"help", 0, 0, 0},
{"ini", 0, &ini_version, 1},
{"interaction", 1, 0, 0},
......@@ -524,14 +549,11 @@ static void parse_options(int ac, char **av)
input_name = xstrdup(sargv[sargc-1]);
sargv[sargc-1] = normalize_quotes(input_name, "argument");
}
if (safer_option) /* --safer implies --nosocket */
nosocket_option = 1;
UPDATE_SOCKET_STATUS();
return;
#endif
}
/*tex |--safer| implies |--nosocket| */
if (safer_option)
nosocket_option = 1;
UPDATE_SOCKET_STATUS();
/*tex Finalize the input filename. */
if (input_name != NULL) {
argv[optind] = normalize_quotes(input_name, "argument");
......@@ -981,6 +1003,7 @@ void lua_initialize(int ac, char **av)
shellenabledp = true;
restrictedshell = false;
safer_option = 0;
nosocket_option = 0;
}
/*tex
Get the current locale (it should be |C|) and save |LC_CTYPE|, |LC_COLLATE|
......@@ -1149,6 +1172,7 @@ void lua_initialize(int ac, char **av)
}
free(v1);
}
UPDATE_SOCKET_STATUS();
/*tex If shell escapes are restricted, get allowed cmds from cnf. */
if (shellenabledp && restrictedshell == 1) {
v1 = NULL;
......
......@@ -323,7 +323,8 @@ void luainterpreter(void)
/*tex
The socket and mime libraries are a bit tricky to open because they use a
load-time dependency that has to be worked around for luatex, where the C
module is loaded way before the lua module.
module is loaded way before the lua module.
The mime library is always available, even if the socket library is not enabled.
*/
if (!nosocket_option) {
/* todo: move this to common */
......@@ -348,6 +349,23 @@ void luainterpreter(void)
lua_pop(L, 2);
/*tex preload the pure \LUA\ modules */
luatex_socketlua_open(L);
} else {
lua_getglobal(L, "package");
lua_getfield(L, -1, "loaded");
if (!lua_istable(L, -1)) {
lua_newtable(L);
lua_setfield(L, -2, "loaded");
lua_getfield(L, -1, "loaded");
}
/*tex |package.loaded.mime = nil| */
luaopen_mime_core(L);
lua_setfield(L, -2, "mime.core");
lua_pushnil(L);
lua_setfield(L, -2, "mime");
/*tex pop the table */
lua_pop(L, 1);
/*tex preload the pure \LUA\ mime module */
luatex_socketlua_safe_open(L);
}
luaopen_zlib(L);
luaopen_gzip(L);
......
......@@ -123,6 +123,7 @@ extern int luaopen_profiler(lua_State * L);
extern int luaopen_socket_core(lua_State * L);
extern int luaopen_mime_core(lua_State * L);
extern void luatex_socketlua_open(lua_State * L);
extern void luatex_socketlua_safe_open(lua_State * L);
extern int luaopen_img(lua_State * L);
extern int l_new_image(lua_State * L);
......
......@@ -16,6 +16,7 @@ int luatex_ftp_lua_open(lua_State*);
extern void luatex_socketlua_open (lua_State *) ;
extern void luatex_socketlua_safe_open (lua_State *) ;
#include "ftp_lua.c"
#include "headers_lua.c"
#include "http_lua.c"
......@@ -47,3 +48,11 @@ luatex_socketlua_open (lua_State *L) {
TEST(luatex_http_lua_open(L));
TEST(luatex_ftp_lua_open(L));
}
/* luatex_socketlua_safe_open: load safe modules */
/* of luasocket ( mime ). */
void
luatex_socketlua_safe_open (lua_State *L) {
TEST(luatex_ltn12_lua_open(L));
TEST(luatex_mime_lua_open(L));
}
......@@ -32,9 +32,9 @@
stick to "0" upto "9" so users can expect a number represented as string.
*/
int luatex_version = 116;
int luatex_revision = '2';
const char *luatex_version_string = "1.16.2";
int luatex_version = 117;
int luatex_revision = '0';
const char *luatex_version_string = "1.17.0";
const char *engine_name = my_name;
#include <kpathsea/c-ctype.h>
......
#ifndef luatex_svn_revision_h
#define luatex_svn_revision_h
#define luatex_svn_revision 7576
#define luatex_svn_revision 7580
#endif