summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLauri Leukkunen <lle@rahina.org>2008-01-11 02:23:31 +0200
committerLauri Leukkunen <lle@rahina.org>2008-01-11 02:23:31 +0200
commitc602362bb73de9abf4d55edaf54d7be1f5c32294 (patch)
treecc5c9cfdeb88fb17fd9ec53fb75103bfc32fbd78
parent1a6d98440457c32eb79c615770b132905a465472 (diff)
Introduce sb2-show, cleanup some warnings
sb2-show allows you to inspect how path/argv/envp mangling would be done for a given binary. Patch by lauri.t.aarnio@nokia.com, somewhat cleaned up by lle@rahina.org. Signed-off-by: Lauri Leukkunen <lle@rahina.org>
-rw-r--r--AUTHORS11
-rw-r--r--Makefile16
-rw-r--r--README26
-rw-r--r--include/mapping.h10
-rw-r--r--luaif/Makefile4
-rw-r--r--luaif/paths.c23
-rw-r--r--luaif/sb_log.c5
-rw-r--r--preload/Makefile3
-rwxr-xr-xpreload/gen-interface.pl3
-rw-r--r--preload/interface.master8
-rw-r--r--preload/libsb2.c21
-rw-r--r--preload/sb_exec.c123
-rw-r--r--utils/Makefile15
-rwxr-xr-xutils/sb2-logz (renamed from utils/sb2logz)2
-rw-r--r--utils/sb2-show.c141
15 files changed, 354 insertions, 57 deletions
diff --git a/AUTHORS b/AUTHORS
index 73e4a07..6054ae7 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -1,9 +1,9 @@
Complete list of authors and their modules:
Lauri Leukkunen <lle@rahina.org>:
- mapping/*
+ luaif/*
preload/*
- redir_scripts/*
+ lua_scripts/*
utils/*
include/*
scripts/*
@@ -14,3 +14,10 @@ Valtteri Rahkonen <valtteri@rahkonen.fi>:
Riku Voipio <riku.voipio@movial.fi>:
debian/*
+Lauri T. Aarnio <lauri.aarnio@iki.fi>:
+ preload/gen-interface.pl
+ preload/interface.master
+ luaif/sb_log.c
+ utils/sb2-logz
+ utils/sb2-show.c
+
diff --git a/Makefile b/Makefile
index 0e4378a..e0715a4 100644
--- a/Makefile
+++ b/Makefile
@@ -27,11 +27,12 @@ PACKAGE_VERSION = "1.99.0.23"
PACKAGE = "SB2"
LIBSB2_SONAME = "libsb2.so.1"
LLBUILD ?= $(SRCDIR)/llbuild
+PROTOTYPEWARNINGS=-Wmissing-prototypes -Wstrict-prototypes
# targets variable will be filled by llbuild
targets =
-subdirs = luaif preload
+subdirs = luaif preload utils
-include config.mak
@@ -96,7 +97,7 @@ install-noarch: $(BUILD_TARGET)
install -c -m 755 $(SRCDIR)/utils/sb2-config $(prefix)/bin/sb2-config
install -c -m 755 $(SRCDIR)/utils/sb2-build-libtool $(prefix)/bin/sb2-build-libtool
install -c -m 755 $(SRCDIR)/utils/dpkg-checkbuilddeps $(prefix)/share/scratchbox2/scripts/dpkg-checkbuilddeps
- install -c -m 755 $(SRCDIR)/utils/sb2logz $(prefix)/share/scratchbox2/scripts/sb2logz
+ install -c -m 755 $(SRCDIR)/utils/sb2-logz $(prefix)/bin/sb2-logz
install -c -m 644 $(SRCDIR)/lua_scripts/main.lua $(prefix)/share/scratchbox2/lua_scripts/main.lua
install -c -m 644 $(SRCDIR)/lua_scripts/mapping.lua $(prefix)/share/scratchbox2/lua_scripts/mapping.lua
install -c -m 644 $(SRCDIR)/lua_scripts/argvenvp.lua $(prefix)/share/scratchbox2/lua_scripts/argvenvp.lua
@@ -120,6 +121,7 @@ install: install-noarch
install -d -m 755 $(prefix)/lib
install -d -m 755 $(prefix)/lib/libsb2
install -c -m 755 $(OBJDIR)/preload/libsb2.so $(prefix)/lib/libsb2/libsb2.so.$(PACKAGE_VERSION)
+ install -c -m 755 $(OBJDIR)/utils/sb2-show $(prefix)/bin/sb2-show
/sbin/ldconfig -n $(prefix)/lib/libsb2
@@ -128,6 +130,7 @@ multilib_prefix=$(prefix)
install-multilib: install-noarch
$(MAKE) -C obj-32 --include-dir=.. -f ../Makefile SRCDIR=.. do-install-multilib bitness=32
$(MAKE) -C obj-64 --include-dir=.. -f ../Makefile SRCDIR=.. do-install-multilib bitness=64
+ install -c -m 755 $(PRI_OBJDIR)/utils/sb2-show $(prefix)/bin/sb2-show
do-install-multilib:
install -d -m 755 $(multilib_prefix)/lib$(bitness)
@@ -136,10 +139,17 @@ do-install-multilib:
/sbin/ldconfig -n $(multilib_prefix)/lib$(bitness)/libsb2
-CLEAN_FILES += $(targets) config.status config.log obj-32 obj-64 .configure-multilib
+CLEAN_FILES += $(targets) config.status config.log
# make all object files depend on include/config.h
+superclean: clean
+ rm -rf obj-32 obj-64 .configure-multilib
+
+clean-multilib:
+ $(MAKE) -C obj-32 --include-dir .. -f ../Makefile clean
+ $(MAKE) -C obj-64 --include-dir .. -f ../Makefile clean
+
clean:
$(ll_clean)
diff --git a/README b/README
index 18c0370..0b519db 100644
--- a/README
+++ b/README
@@ -154,12 +154,34 @@ be created under ~/sb2_logs/ (The above command will also print out the
exact name and location of the logfile.)
The produced logfile can be quite huge, especially when using the higher
-logging levels. A logfile analyzer script, sb2logz, can be used to extract
+logging levels. A logfile analyzer script, sb2-logz, can be used to extract
essentials like error and warning messages and path mapping actions from
the logged information; log level 'info' in enough for anything that
-sb2logz needs. Higher logging levels ('debug', etc) are mostly useful
+sb2-logz needs. Higher logging levels ('debug', etc) are mostly useful
only for developers of scratchbox 2.
+Another useful helper tool is "sb2-show", an utility which can be used to
+test path and command mapping rules while scratchbox 2 is active.
+
+For example,
+
+$ sb2-show path /etc/apt
+
+$ sb2-show -b apt-get path /etc/apt
+
+will show how the /etc/apt database has been mapped. The latter command
+uses "apt-get" as the name of the calling program (the results may
+be different depending on mapping mode, name of the calling program, etc)
+
+sb2-show can also be used to see how parameters to certain processes will
+be modified:
+
+$ sb2-show exec gcc foo.c
+
+shows which "gcc" would be started inside the sb2 session, together with
+the actual, possibly modified, arguments. The result depends on how sb2
+was configured (see notes about sb2-init above)
+
--
diff --git a/include/mapping.h b/include/mapping.h
index 28ce5d6..555c23b 100644
--- a/include/mapping.h
+++ b/include/mapping.h
@@ -19,10 +19,12 @@ enum lua_engine_states {
LES_READY
};
-char *scratchbox_path(const char *func_name, const char *path);
-char *scratchbox_path2(const char *binary_name, const char *func_name,
+extern char *scratchbox_path(const char *func_name, const char *path);
+extern char *scratchbox_path2(const char *binary_name, const char *func_name,
const char *path);
-int sb_execve_mod(char **file, char ***argv, char ***envp);
-char *emumode_map(const char *path);
+extern char *scratchbox_path3(const char *binary_name, const char *func_name,
+ const char *path, const char *mapping_mode);
+extern int sb_execve_mod(char **file, char ***argv, char ***envp);
+extern char *emumode_map(const char *path);
#endif
diff --git a/luaif/Makefile b/luaif/Makefile
index d0bf565..9426c4d 100644
--- a/luaif/Makefile
+++ b/luaif/Makefile
@@ -2,8 +2,10 @@ LUASRC = luaif/lua-5.1.2/src
objs := $(D)/luaif.o $(D)/sb_log.o $(D)/paths.o $(D)/argvenvp.o
+$(D)/sb_log.o: preload/exported.h
+
luaif/libluaif.a: $(objs)
-luaif/libluaif.a: override CFLAGS := $(CFLAGS) -O2 -g -fPIC -Wall -W -I$(SRCDIR)/$(LUASRC)
+luaif/libluaif.a: override CFLAGS := $(CFLAGS) -O2 -g -fPIC -Wall -W -I$(SRCDIR)/$(LUASRC) -I$(OBJDIR)/preload -I$(SRCDIR)/preload
luaif/libluaif.a: override LDFLAGS := $(LDFLAGS)
luaif/libluaif.a: override LIBS :=
diff --git a/luaif/paths.c b/luaif/paths.c
index 3a149d0..ce6f43a 100644
--- a/luaif/paths.c
+++ b/luaif/paths.c
@@ -166,12 +166,13 @@ char *scratchbox_path(const char *func_name, const char *path)
/* make sure to use disable_mapping(m);
* to prevent recursive calls to this function
*/
-char *scratchbox_path2(const char *binary_name,
+char *scratchbox_path3(const char *binary_name,
const char *func_name,
- const char *path)
+ const char *path,
+ const char *mapping_mode)
{
char work_dir[PATH_MAX + 1];
- char *tmp = NULL, *decolon_path = NULL, *mapping_mode = NULL;
+ char *tmp = NULL, *decolon_path = NULL;
char pidlink[17]; /* /proc/2^8/exe */
struct lua_instance *luaif;
@@ -206,7 +207,9 @@ char *scratchbox_path2(const char *binary_name,
exit(1);
}
- if (!(mapping_mode = getenv("SBOX_MAPMODE"))) {
+ /* use a sane default for mapping_mode, if not defined by
+ * the parameter or environment */
+ if (!mapping_mode && !(mapping_mode = getenv("SBOX_MAPMODE"))) {
mapping_mode = "simple";
}
@@ -281,3 +284,15 @@ char *scratchbox_path2(const char *binary_name,
}
}
+char *scratchbox_path2(const char *binary_name,
+ const char *func_name,
+ const char *path)
+{
+ const char *mapping_mode;
+
+ if (!(mapping_mode = getenv("SBOX_MAPMODE"))) {
+ mapping_mode = "simple";
+ }
+ return(scratchbox_path3(binary_name, func_name, path, mapping_mode));
+}
+
diff --git a/luaif/sb_log.c b/luaif/sb_log.c
index 0b2ec13..64d28f2 100644
--- a/luaif/sb_log.c
+++ b/luaif/sb_log.c
@@ -18,6 +18,11 @@
#include <string.h>
#include <sb2.h>
+#include <config.h>
+#include <config_hardcoded.h>
+
+#include "libsb2.h"
+#include "exported.h"
/* ===================== Internal state variables =====================
*
diff --git a/preload/Makefile b/preload/Makefile
index 7c65886..780dd86 100644
--- a/preload/Makefile
+++ b/preload/Makefile
@@ -1,8 +1,5 @@
objs := wrappers.o libsb2.o sb_exec.o
-PROTOTYPEWARNINGS=-Wmissing-prototypes -Wstrict-prototypes
-
-
ifeq ($(shell uname -s),Linux)
LIBSB2_LDFLAGS = -Wl,-soname=$(LIBSB2_SONAME) \
-Wl,--retain-symbols-file=preload/ldexportlist
diff --git a/preload/gen-interface.pl b/preload/gen-interface.pl
index d22bd18..5380c67 100755
--- a/preload/gen-interface.pl
+++ b/preload/gen-interface.pl
@@ -256,9 +256,6 @@ sub add_function_name_to_symbol_table {
my $fn_name = shift;
if(defined($all_function_names{$fn_name})) {
- printf "Warning: Multiple references to function '%s'\n",
- $fn_name;
- #$num_errors++;
return;
}
$all_function_names{$fn_name} = 1;
diff --git a/preload/interface.master b/preload/interface.master
index cb9f918..af0cd21 100644
--- a/preload/interface.master
+++ b/preload/interface.master
@@ -22,6 +22,14 @@ EXPORT: void _fini(void)
-- 2. exported functions.
-- -------------------
+-- Functions used by the "sb2show" command:
+EXPORT: char *sb2show__map_path__(const char *binary_name, \
+ const char *mapping_mode, const char *fn_name, const char *pathname)
+EXPORT: int sb2show__execve_mods__( \
+ char *file, \
+ char *const *orig_argv, char *const *orig_envp, \
+ char **new_file, char ***new_argv, char ***new_envp)
+
-- FIXME: The following two functions do not have anything to do with path
-- remapping. Instead the implementations in libsb2.c prevent locking of
-- the shadow file, which I find really hard to understand. Please explain
diff --git a/preload/libsb2.c b/preload/libsb2.c
index d05ef30..baed8bb 100644
--- a/preload/libsb2.c
+++ b/preload/libsb2.c
@@ -528,23 +528,25 @@ void _exit_gate(void (*real__exit_ptr)(int status),
const char *realfnname, int status)
{
/* NOTE: Following SB_LOG() call is used by the log
- * postprocessor script "sb2logz". Do not change
+ * postprocessor script "sb2-logz". Do not change
* without making a corresponding change to the script!
*/
SB_LOG(SB_LOGLEVEL_INFO, "%s: status=%d", realfnname, status);
(real__exit_ptr)(status);
}
+
void _Exit_gate(void (*real__Exit_ptr)(int status),
const char *realfnname, int status)
{
/* NOTE: Following SB_LOG() call is used by the log
- * postprocessor script "sb2logz". Do not change
+ * postprocessor script "sb2-logz". Do not change
* without making a corresponding change to the script!
*/
SB_LOG(SB_LOGLEVEL_INFO, "%s: status=%d", realfnname, status);
(real__Exit_ptr)(status);
}
+//void _Exit_gate() __attribute__ ((noreturn));
/* ---------- */
@@ -567,3 +569,18 @@ void *sbox_find_next_symbol(int log_enabled, const char *fn_name)
}
return(fn_ptr);
}
+
+/* ---------- */
+char *sb2show__map_path__(const char *binary_name, const char *mapping_mode,
+ const char *fn_name, const char *pathname)
+{
+ char *mapped__pathname = NULL;
+
+ if (pathname != NULL) {
+ mapped__pathname = scratchbox_path3(binary_name, fn_name,
+ pathname, mapping_mode);
+ }
+ SB_LOG(SB_LOGLEVEL_DEBUG, "%s '%s'", __func__, pathname);
+ return(mapped__pathname);
+}
+
diff --git a/preload/sb_exec.c b/preload/sb_exec.c
index 1fd264f..9693a84 100644
--- a/preload/sb_exec.c
+++ b/preload/sb_exec.c
@@ -511,7 +511,7 @@ int run_hashbang(const char *file, char *const *argv, char *const *envp)
{
int argc, fd, c, i, j, n, ret;
char ch;
- char **p, *ptr, *mapped_interpreter;
+ char *ptr, *mapped_interpreter;
char **new_argv;
char hashbang[SBOX_MAXPATH]; /* only 60 needed on linux, just be safe */
char interpreter[SBOX_MAXPATH];
@@ -527,8 +527,7 @@ int run_hashbang(const char *file, char *const *argv, char *const *envp)
return run_app(file, argv, envp);
}
- for (argc = 0, p = (char **)argv; *p; p++)
- argc++;
+ argc = elem_count(argv);
/* extra element for hashbang argument */
new_argv = calloc(argc + 3, sizeof(char *));
@@ -585,33 +584,36 @@ int run_hashbang(const char *file, char *const *argv, char *const *envp)
return ret;
}
-int do_exec(const char *exec_fn_name, const char *file,
- char *const *argv, char *const *envp)
+static char ***duplicate_argv(char *const *argv)
{
- char ***my_envp, ***my_argv, **my_file, **p;
- char *binaryname, *tmp, *mapped_file;
- int envc = 0, argc = 0, i, has_ld_preload = 0, err = 0;
- enum binary_type type;
+ int argc = elem_count(argv);
+ char **p;
+ int i;
+ char ***my_argv;
- (void)exec_fn_name; /* not yet used */
+ my_argv = malloc(sizeof(char **));
+ *my_argv = (char **)calloc(argc + 1, sizeof(char *));
+ for (i = 0, p = (char **)argv; *p; p++) {
+ (*my_argv)[i++] = strdup(*p);
+ }
+ (*my_argv)[i] = NULL;
+
+ return(my_argv);
+}
+
+static char ***prepare_envp_for_do_exec(char *binaryname, char *const *envp)
+{
+ char **p;
+ int envc = 0;
+ char ***my_envp;
+ int has_ld_preload = 0;
+ int i;
+ char *tmp;
/* if we have LD_PRELOAD env var set, make sure the new my_envp
* has it as well
*/
- if (getenv("SBOX_DISABLE_MAPPING")) {
- /* just run it, don't worry, be happy! */
- return sb_next_execve(file, argv, envp);
- }
-
-
- tmp = strdup(file);
- binaryname = strdup(basename(tmp));
- free(tmp);
-
- my_file = malloc(sizeof(char *));
- *my_file = strdup(file);
-
/* count the environment variables and arguments, also check
* for LD_PRELOAD
*/
@@ -620,11 +622,7 @@ int do_exec(const char *exec_fn_name, const char *file,
has_ld_preload = 1;
}
- for (p=(char **)argv; *p; p++, argc++)
- ;
-
my_envp = malloc(sizeof(char **));
- my_argv = malloc(sizeof(char **));
if (has_ld_preload || !getenv("LD_PRELOAD")) {
*my_envp = (char **)calloc(envc + 2, sizeof(char *));
@@ -667,11 +665,33 @@ int do_exec(const char *exec_fn_name, const char *file,
}
(*my_envp)[i] = NULL;
- *my_argv = (char **)calloc(argc + 1, sizeof(char *));
- for (i = 0, p = (char **)argv; *p; p++) {
- (*my_argv)[i++] = strdup(*p);
+ return(my_envp);
+}
+
+int do_exec(const char *exec_fn_name, const char *file,
+ char *const *argv, char *const *envp)
+{
+ char ***my_envp, ***my_argv, **my_file;
+ char *binaryname, *tmp, *mapped_file;
+ int err = 0;
+ enum binary_type type;
+
+ (void)exec_fn_name; /* not yet used */
+
+ if (getenv("SBOX_DISABLE_MAPPING")) {
+ /* just run it, don't worry, be happy! */
+ return sb_next_execve(file, argv, envp);
}
- (*my_argv)[i] = NULL;
+
+ tmp = strdup(file);
+ binaryname = strdup(basename(tmp));
+ free(tmp);
+
+ my_file = malloc(sizeof(char *));
+ *my_file = strdup(file);
+
+ my_envp = prepare_envp_for_do_exec(binaryname, envp);
+ my_argv = duplicate_argv(argv);
if ((err = sb_execve_mod(my_file, my_argv, my_envp)) != 0) {
SB_LOG(SB_LOGLEVEL_ERROR, "argvenvp processing error %i", err);
@@ -682,7 +702,9 @@ int do_exec(const char *exec_fn_name, const char *file,
*/
mapped_file = scratchbox_path("do_exec", *my_file);
- SB_LOG(SB_LOGLEVEL_DEBUG, "do_exec(): *my_file = %s, mapped_file = %s", *my_file, mapped_file);
+ SB_LOG(SB_LOGLEVEL_DEBUG,
+ "do_exec(): *my_file = %s, mapped_file = %s",
+ *my_file, mapped_file);
type = inspect_binary(mapped_file); /* inspect the completely mangled
* filename */
@@ -726,3 +748,40 @@ int do_exec(const char *exec_fn_name, const char *file,
return sb_next_execve(mapped_file, *my_argv, *my_envp);
}
+/* ---------- */
+int sb2show__execve_mods__(
+ char *file,
+ char *const *orig_argv, char *const *orig_envp,
+ char **new_file, char ***new_argv, char ***new_envp)
+{
+ char *binaryname, *tmp;
+ int err = 0;
+ char ***my_envp, ***my_argv, **my_file;
+
+ SB_LOG(SB_LOGLEVEL_DEBUG, "%s '%s'", __func__, orig_argv[0]);
+
+ tmp = strdup(file);
+ binaryname = strdup(basename(tmp));
+ free(tmp);
+
+ my_file = malloc(sizeof(char *));
+ *my_file = strdup(file);
+
+ my_envp = prepare_envp_for_do_exec(binaryname, orig_envp);
+ my_argv = duplicate_argv(orig_argv);
+
+ if ((err = sb_execve_mod(my_file, my_argv, my_envp)) != 0) {
+ SB_LOG(SB_LOGLEVEL_ERROR, "argvenvp processing error %i", err);
+
+ *new_file = NULL;
+ *new_argv = NULL;
+ *new_envp = NULL;
+ } else {
+ *new_file = *my_file;
+ *new_argv = *my_argv;
+ *new_envp = *my_envp;
+ }
+
+ return(0);
+}
+
diff --git a/utils/Makefile b/utils/Makefile
new file mode 100644
index 0000000..3140bfd
--- /dev/null
+++ b/utils/Makefile
@@ -0,0 +1,15 @@
+# beware of namespace collisions, all subdir makefiles are included
+# into the top-level Makefile
+
+$(D)/sb2-show: CFLAGS := $(CFLAGS) -Wall -W -Werror \
+ -I$(SRCDIR)/preload -Ipreload/ $(PROTOTYPEWARNINGS) \
+ -I$(SRCDIR)/include
+
+$(D)/sb2-show.o: preload/exported.h
+$(D)/sb2-show: preload/libsb2.so $(D)/sb2-show.o
+ $(MKOUTPUTDIR)
+ $(P)LD
+ $(Q)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
+
+targets := $(targets) $(D)/sb2-show
+
diff --git a/utils/sb2logz b/utils/sb2-logz
index 747d383..4be527f 100755
--- a/utils/sb2logz
+++ b/utils/sb2-logz
@@ -15,7 +15,7 @@ use Getopt::Std;
sub usage {
print "Usage:\n".
- "\tsb2logz [options]\n".
+ "\tsb2-logz [options]\n".
"\t(stdin should be a logfile produced by the sb2 command,\n".
"\tsee options '-d' and '-L level' of sb2)\n".
"Options:\n".
diff --git a/utils/sb2-show.c b/utils/sb2-show.c
new file mode 100644
index 0000000..b32570d
--- /dev/null
+++ b/utils/sb2-show.c
@@ -0,0 +1,141 @@
+/* sb2-show:
+ * SB2 Mapping rule testingutility
+ *
+ * Copyright (c) 2008 Nokia Corporation. All rights reserved.
+ * Author: Lauri T. Aarnio
+ * Licensed under LGPL version 2.1, see top level LICENSE file for details.
+*/
+
+#include <unistd.h>
+#include <config.h>
+#include <config_hardcoded.h>
+
+#include "libsb2.h"
+#include "exported.h"
+
+static void usage_exit(const char *progname, const char *errmsg, int exitstatus)
+{
+ if (errmsg)
+ fprintf(stderr, "%s: Error: %s\n", progname, errmsg);
+
+ fprintf(stderr,
+ "\n%s: Usage:\n"
+ "\t%s [options] command [parameters]\n"
+ "\nOptions:\n"
+ "\t-b binary_name\tshow using binary_name as name of "
+ "the calling program\n"
+ "\t-m mode\t\tshow using named mapping mode "
+ "(default=current mode)\n"
+ "\t-f function\tshow using 'function' as callers name\n"
+ "\nCommands:\n"
+ "\tpath [path1] [path2].."
+ "\tShow mappings of pathnames\n"
+ "\texec file argv0 [argv1] [argv2].."
+ "\tShow execve() modifications\n"
+ "\n'%s' must be executed inside sb2 sandbox"
+ " (see the 'sb2' command)\n",
+ progname, progname, progname);
+
+ exit(exitstatus);
+}
+
+static void command_show_exec(
+ const char *binary_name,
+ const char *mapping_mode,
+ const char *fn_name,
+ const char *progname,
+ int argc, char **argv)
+{
+ char *new_file;
+ char **new_argv;
+ char **new_envp;
+ char *mapped_path = NULL;
+ int i;
+
+ if (argc < 2) {
+ usage_exit(progname, "Too few parameters for this command", 1);
+ }
+ sb2show__execve_mods__(argv[0], argv, environ,
+ &new_file, &new_argv, &new_envp);
+ printf("File\t%s\n", new_file);
+
+ /* do_exec() will map the path just after argvenvp modifications
+ * have been done, do that here also
+ */
+ mapped_path = sb2show__map_path__(binary_name, mapping_mode, fn_name,
+ new_file);
+ printf("Mapped\t%s\n", mapped_path);
+
+ for (i = 0; new_argv[i]; i++) {
+ printf("argv[%d]\t%s\n", i, new_argv[i]);
+ }
+}
+
+static void command_show_path(const char *binary_name,
+ const char *mapping_mode,
+ const char *fn_name, char **argv)
+{
+ char *mapped_path = NULL;
+
+ while (*argv) {
+ mapped_path = sb2show__map_path__(binary_name, mapping_mode,
+ fn_name, *argv);
+ printf("%s => %s\n", *argv, mapped_path);
+ argv++;
+ }
+}
+
+int main(int argc, char *argv[])
+{
+ int opt;
+ char *progname = argv[0];
+ char *mapping_mode = NULL;
+ char *function_name = "ANYFUNCTION";
+ char *binary_name = "ANYBINARY";
+
+#if 0 || defined(enable_this_after_sb2_preload_library_startup_has_been_fixed)
+ /* FIXME: this should be able to check if we are inside the sb2
+ * sandbox, but that is not currently possible (instead initialization
+ * of the preload library will fail even before main() is entered.
+ * this happens because the preload library was not designed to
+ * be used as ordinary library, which is exactly what we are doing
+ * now... initialization code of the library should be modified.
+ */
+
+ /* check that we are running inside 'sb2' environment */
+ if (!getenv("SBOX_LUA_SCRIPTS") ||
+ !getenv("SBOX_MAPMODE")) {
+ usage_exit(progname, "Not inside scratchboxed environment", 1);
+ }
+#endif
+
+ while ((opt = getopt(argc, argv, "hm:f:b:")) != -1) {
+ switch (opt) {
+ case 'h': usage_exit(progname, NULL, 0); break;
+ case 'm': mapping_mode = optarg; break;
+ case 'f': function_name = optarg; break;
+ case 'b': binary_name = optarg; break;
+ default: usage_exit(progname, "Illegal option", 1); break;
+ }
+ }
+
+ /* check parameters */
+ if (optind >= argc)
+ usage_exit(progname, "Wrong number of parameters", 1);
+ if (!mapping_mode)
+ mapping_mode = getenv("SBOX_MAPMODE");
+
+ /* params ok, go and perform the action */
+ if (!strcmp(argv[optind], "path")) {
+ command_show_path(binary_name, mapping_mode, function_name,
+ argv + optind + 1);
+ } else if (!strcmp(argv[optind], "exec")) {
+ command_show_exec(binary_name, mapping_mode, function_name,
+ progname, argc - (optind+1), argv + optind + 1);
+ } else {
+ usage_exit(progname, "Unknown command", 1);
+ }
+
+ return(0);
+}
+