@@ -290,6 +290,43 @@ static bool check_ruleset_scope(const char *const env_var,
290290
291291#define LANDLOCK_ABI_LAST 6
292292
293+ #define XSTR (s ) #s
294+ #define STR (s ) XSTR(s)
295+
296+ /* clang-format off */
297+
298+ static const char help [] =
299+ "usage: "
300+ ENV_FS_RO_NAME "=\"...\" "
301+ ENV_FS_RW_NAME "=\"...\" "
302+ ENV_TCP_BIND_NAME "=\"...\" "
303+ ENV_TCP_CONNECT_NAME "=\"...\" "
304+ ENV_SCOPED_NAME "=\"...\" %1$s <cmd> [args]...\n"
305+ "\n"
306+ "Execute a command in a restricted environment.\n"
307+ "\n"
308+ "Environment variables containing paths and ports each separated by a colon:\n"
309+ "* " ENV_FS_RO_NAME ": list of paths allowed to be used in a read-only way.\n"
310+ "* " ENV_FS_RW_NAME ": list of paths allowed to be used in a read-write way.\n"
311+ "\n"
312+ "Environment variables containing ports are optional and could be skipped.\n"
313+ "* " ENV_TCP_BIND_NAME ": list of ports allowed to bind (server).\n"
314+ "* " ENV_TCP_CONNECT_NAME ": list of ports allowed to connect (client).\n"
315+ "* " ENV_SCOPED_NAME ": list of scoped IPCs.\n"
316+ "\n"
317+ "example:\n"
318+ ENV_FS_RO_NAME "=\"${PATH}:/lib:/usr:/proc:/etc:/dev/urandom\" "
319+ ENV_FS_RW_NAME "=\"/dev/null:/dev/full:/dev/zero:/dev/pts:/tmp\" "
320+ ENV_TCP_BIND_NAME "=\"9418\" "
321+ ENV_TCP_CONNECT_NAME "=\"80:443\" "
322+ ENV_SCOPED_NAME "=\"a:s\" "
323+ "%1$s bash -i\n"
324+ "\n"
325+ "This sandboxer can use Landlock features up to ABI version "
326+ STR (LANDLOCK_ABI_LAST ) ".\n" ;
327+
328+ /* clang-format on */
329+
293330int main (const int argc , char * const argv [], char * const * const envp )
294331{
295332 const char * cmd_path ;
@@ -308,47 +345,7 @@ int main(const int argc, char *const argv[], char *const *const envp)
308345 };
309346
310347 if (argc < 2 ) {
311- fprintf (stderr ,
312- "usage: %s=\"...\" %s=\"...\" %s=\"...\" %s=\"...\" %s=\"...\" %s "
313- "<cmd> [args]...\n\n" ,
314- ENV_FS_RO_NAME , ENV_FS_RW_NAME , ENV_TCP_BIND_NAME ,
315- ENV_TCP_CONNECT_NAME , ENV_SCOPED_NAME , argv [0 ]);
316- fprintf (stderr ,
317- "Execute a command in a restricted environment.\n\n" );
318- fprintf (stderr ,
319- "Environment variables containing paths and ports "
320- "each separated by a colon:\n" );
321- fprintf (stderr ,
322- "* %s: list of paths allowed to be used in a read-only way.\n" ,
323- ENV_FS_RO_NAME );
324- fprintf (stderr ,
325- "* %s: list of paths allowed to be used in a read-write way.\n\n" ,
326- ENV_FS_RW_NAME );
327- fprintf (stderr ,
328- "Environment variables containing ports are optional "
329- "and could be skipped.\n" );
330- fprintf (stderr ,
331- "* %s: list of ports allowed to bind (server).\n" ,
332- ENV_TCP_BIND_NAME );
333- fprintf (stderr ,
334- "* %s: list of ports allowed to connect (client).\n" ,
335- ENV_TCP_CONNECT_NAME );
336- fprintf (stderr , "* %s: list of scoped IPCs.\n" ,
337- ENV_SCOPED_NAME );
338- fprintf (stderr ,
339- "\nexample:\n"
340- "%s=\"${PATH}:/lib:/usr:/proc:/etc:/dev/urandom\" "
341- "%s=\"/dev/null:/dev/full:/dev/zero:/dev/pts:/tmp\" "
342- "%s=\"9418\" "
343- "%s=\"80:443\" "
344- "%s=\"a:s\" "
345- "%s bash -i\n\n" ,
346- ENV_FS_RO_NAME , ENV_FS_RW_NAME , ENV_TCP_BIND_NAME ,
347- ENV_TCP_CONNECT_NAME , ENV_SCOPED_NAME , argv [0 ]);
348- fprintf (stderr ,
349- "This sandboxer can use Landlock features "
350- "up to ABI version %d.\n" ,
351- LANDLOCK_ABI_LAST );
348+ fprintf (stderr , help , argv [0 ]);
352349 return 1 ;
353350 }
354351
0 commit comments