[OpenWrt-Devel] [PATCH procd v3 16/17] ujail: automatically add script (#!) interpreter
Etienne CHAMPETIER
champetier.etienne at gmail.com
Fri Nov 27 11:27:15 EST 2015
this make simple script work easily with ujail
Signed-off-by: Etienne CHAMPETIER <champetier.etienne at gmail.com>
---
jail/fs.c | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/jail/fs.c b/jail/fs.c
index aeab730..c848700 100644
--- a/jail/fs.c
+++ b/jail/fs.c
@@ -79,6 +79,29 @@ void mount_list_init(void) {
avl_init(&mounts, avl_strcmp, false, NULL);
}
+static int add_script_interp(const char *path, const char *map, int size)
+{
+ int start = 2;
+ while (start < size && map[start] != '/') {
+ start++;
+ }
+ if (start >= size) {
+ ERROR("bad script interp (%s)", path);
+ return -1;
+ }
+ int stop = start + 1;
+ while (stop < size && map[stop] > 0x20 && map[stop] <= 0x7e) {
+ stop++;
+ }
+ if (stop >= size || (stop-start) > PATH_MAX) {
+ ERROR("bad script interp (%s)", path);
+ return -1;
+ }
+ char buf[PATH_MAX];
+ strncpy(buf, map+start, stop-start);
+ return add_path_and_deps(buf, 1, -1, 0);
+}
+
int add_path_and_deps(const char *path, int readonly, int error, int lib)
{
assert(path != NULL);
@@ -135,6 +158,11 @@ int add_path_and_deps(const char *path, int readonly, int error, int lib)
goto out;
}
+ if (map[0] == '#' && map[1] == '!') {
+ ret = add_script_interp(path, map, s.st_size);
+ goto out;
+ }
+
if (map[0] == ELFMAG0 && map[1] == ELFMAG1 && map[2] == ELFMAG2 && map[3] == ELFMAG3) {
ret = elf_load_deps(path, map);
goto out;
--
1.9.1
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
More information about the openwrt-devel
mailing list