From patchwork Wed Nov 25 17:54:49 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Etienne Champetier X-Patchwork-Id: 548697 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 50F0E1402CD for ; Thu, 26 Nov 2015 05:08:36 +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=tkxCEuhR; dkim-atps=neutral Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id F410E28C1A9; Wed, 25 Nov 2015 18:58:29 +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 A26FD28BDA0 for ; Wed, 25 Nov 2015 18:55:43 +0100 (CET) X-policyd-weight: using cached result; rate: -8.5 Received: from mail-wm0-f50.google.com (mail-wm0-f50.google.com [74.125.82.50]) by arrakis.dune.hu (Postfix) with ESMTPS for ; Wed, 25 Nov 2015 18:55:13 +0100 (CET) Received: by wmww144 with SMTP id w144so190310107wmw.1 for ; Wed, 25 Nov 2015 09:55:13 -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=tkxCEuhR1OiBHzKGLyiUaHCpJaT84h/Q+rocPU+xDRiJtqoYeaMhdCVVPvzsFD274l r/baH/dsJOrIIyodmlWNXcDzcCBJwDPJZvrAg+MzHPYln2zP5e6DbegWxj9Wz5kDvWE2 99pIAtMKyikHvutPDKTSjYymTO3PI5VT2K1sI0C9+N9urRkex71y615023noOizEhBTe TBSA6/ZTjiXmk/iMYiC9MnZyoybIoOa2Uz5+W1vr8YTCNj78MEn0gE9FzKxfjvJmX54j qr1CO4kiA4wrv24XJO2DYMQ8qjAc6gVHi+QwupHlzqR3yUNtAmLfcxIRFWgLQwRzWj5c d+Tg== X-Received: by 10.28.222.138 with SMTP id v132mr6299620wmg.23.1448474113201; Wed, 25 Nov 2015 09:55:13 -0800 (PST) Received: from ubuntu1404.lxcnattst (ns623510.ovh.net. [5.135.134.9]) by smtp.gmail.com with ESMTPSA id cv3sm24180221wjc.20.2015.11.25.09.55.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 25 Nov 2015 09:55:12 -0800 (PST) From: Etienne CHAMPETIER To: OpenWrt Development List Date: Wed, 25 Nov 2015 17:54:49 +0000 Message-Id: <1448474090-30280-17-git-send-email-champetier.etienne@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1448474090-30280-1-git-send-email-champetier.etienne@gmail.com> References: <1448474090-30280-1-git-send-email-champetier.etienne@gmail.com> Subject: [OpenWrt-Devel] [PATCH procd v2 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;