From patchwork Fri Nov 27 16:27:15 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Etienne Champetier X-Patchwork-Id: 549539 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from arrakis.dune.hu (arrakis.dune.hu [78.24.191.176]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id C1E51140319 for ; Sat, 28 Nov 2015 03:47:26 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=wlJLImTr; dkim-atps=neutral Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 8583328C184; Fri, 27 Nov 2015 17:35:19 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on arrakis.dune.hu X-Spam-Level: X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,FREEMAIL_FROM, T_DKIM_INVALID autolearn=unavailable version=3.3.2 Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id C35C728C178 for ; Fri, 27 Nov 2015 17:34:19 +0100 (CET) X-policyd-weight: using cached result; rate: -8.5 Received: from mail-wm0-f43.google.com (mail-wm0-f43.google.com [74.125.82.43]) by arrakis.dune.hu (Postfix) with ESMTPS for ; Fri, 27 Nov 2015 17:34:19 +0100 (CET) Received: by wmvv187 with SMTP id v187so77571713wmv.1 for ; Fri, 27 Nov 2015 08:34:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=gDnVISE+a2wIilzFoNpvuQ6ovGBYAExwkzBugoC92Ns=; b=wlJLImTrEn4dWTGytMajCMulP33kIcYY2uNDHJaIdIAseehJx/SD6w242/zuq86rUv jKEAzXufbzFjI72RK6VXMhZWnIOBl4vrC5txH4vEdFtaX9GtfGwIWjxXEjU6SxnTgdTC NF61LXG7CxesdPl55EXTL/StsdNtL7myJnqBHPTUZE53iBCbWP/lMXM6GledrNjy8em5 nyNdOQRWrQUew04SZqHck21npFdhDR3wL8v1EAgmIoTqa5WOHTXefc2Y3iQPq276fGd7 HtaWppp0pnT60senn/3ChQFm4dKUm02xhKecY/CqdNJzh53AzrLusz0wKvpMbfuZYfd/ qjXQ== X-Received: by 10.28.14.209 with SMTP id 200mr11983616wmo.103.1448641654776; Fri, 27 Nov 2015 08:27:34 -0800 (PST) Received: from ubuntu1404.lxcnattst (ns623510.ovh.net. [5.135.134.9]) by smtp.gmail.com with ESMTPSA id w67sm8170842wmw.17.2015.11.27.08.27.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 27 Nov 2015 08:27:33 -0800 (PST) From: Etienne CHAMPETIER To: OpenWrt Development List Date: Fri, 27 Nov 2015 16:27:15 +0000 Message-Id: <1448641636-42493-17-git-send-email-champetier.etienne@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1448641636-42493-1-git-send-email-champetier.etienne@gmail.com> References: <1448641636-42493-1-git-send-email-champetier.etienne@gmail.com> Subject: [OpenWrt-Devel] [PATCH procd v3 16/17] ujail: automatically add script (#!) interpreter X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: openwrt-devel-bounces@lists.openwrt.org Sender: "openwrt-devel" this make simple script work easily with ujail Signed-off-by: Etienne CHAMPETIER --- 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;