From patchwork Fri Apr 8 16:05:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Zaman X-Patchwork-Id: 8784441 Return-Path: X-Original-To: patchwork-selinux@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 12A709F659 for ; Fri, 8 Apr 2016 16:13:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 55D392011D for ; Fri, 8 Apr 2016 16:13:33 +0000 (UTC) Received: from emvm-gh1-uea09.nsa.gov (emvm-gh1-uea09.nsa.gov [8.44.101.9]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 61152202DD for ; Fri, 8 Apr 2016 16:13:32 +0000 (UTC) X-TM-IMSS-Message-ID: <65990063000a10e1@nsa.gov> Received: from tarius.tycho.ncsc.mil ([144.51.242.1]) by nsa.gov ([10.208.42.194]) with ESMTP (TREND IMSS SMTP Service 7.1) id 65990063000a10e1 ; Fri, 8 Apr 2016 12:10:01 -0400 Received: from prometheus.infosec.tycho.ncsc.mil (prometheus [192.168.25.40]) by tarius.tycho.ncsc.mil (8.14.4/8.14.4) with ESMTP id u38GB1uZ022449; Fri, 8 Apr 2016 12:11:01 -0400 Received: from tarius.tycho.ncsc.mil (tarius.infosec.tycho.ncsc.mil [144.51.242.1]) by prometheus.infosec.tycho.ncsc.mil (8.15.2/8.15.2) with ESMTP id u38G6dUm083033 for ; Fri, 8 Apr 2016 12:06:39 -0400 Received: from goalie.tycho.ncsc.mil (goalie [144.51.242.250]) by tarius.tycho.ncsc.mil (8.14.4/8.14.4) with ESMTP id u38G6Zm3021132 for ; Fri, 8 Apr 2016 12:06:39 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A1AyCgBH1gdXd0PcVdFaAoMMgXu4NoJsgSSGDQKBfwEBAQEBARMBCgsUIXAMAYN0AQEBAxIuAQE3AQ85GDQBBQEcO4gFAaEbgTE+MYpPhSgBBI0+AQEBAQEBBAIBFwYKhA6LWwQHgXULQIJDjkaJQ44OZIhFhWKNaC+BDoJZgX1fAYEfhmWBNAEBAQ X-IPAS-Result: A1AyCgBH1gdXd0PcVdFaAoMMgXu4NoJsgSSGDQKBfwEBAQEBARMBCgsUIXAMAYN0AQEBAxIuAQE3AQ85GDQBBQEcO4gFAaEbgTE+MYpPhSgBBI0+AQEBAQEBBAIBFwYKhA6LWwQHgXULQIJDjkaJQ44OZIhFhWKNaC+BDoJZgX1fAYEfhmWBNAEBAQ X-IronPort-AV: E=Sophos;i="5.24,454,1454994000"; d="scan'208";a="5363088" Received: from emvm-gh1-uea09.nsa.gov ([10.208.42.194]) by goalie.tycho.ncsc.mil with ESMTP; 08 Apr 2016 12:06:38 -0400 X-TM-IMSS-Message-ID: <6594f01e000a0eb1@nsa.gov> Received: from mail-pa0-f67.google.com (mail-pa0-f67.google.com [209.85.220.67]) by nsa.gov ([10.208.42.194]) with ESMTP (TREND IMSS SMTP Service 7.1; TLSv1/SSLv3 AES128-SHA (128/128)) id 6594f01e000a0eb1 ; Fri, 8 Apr 2016 12:05:35 -0400 Received: by mail-pa0-f67.google.com with SMTP id hb4so9370959pac.1 for ; Fri, 08 Apr 2016 09:06:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=perfinion-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=pWHAmd4n94lhOLkDfA4lEnEVqxAqxHmNRbMePKV+S4M=; b=skljtLJcXGFqAv1MMprorvyI+Qpr4vQeBhE9vv2PBnC5YqLtbPnQO5AHuxE0JBb5aS Gu4aBhf8u2qRbcjbtCztnrrFMcxQ5iaIxVOV3Q7Tm6QbpfOtyqVyefzLYyrsstH/EdQb exBXCE6/bVkmLeYv7wuj2YpzjUV2TKUhvyr56THB7oCYEDM5cgb83FnaOxGMX7vSMgBE mgjPJA+d/Aox8t/mqVaLbYeCd84lw1ujuFjlZYoAkCepoVSeXQCxhhUhMPerKircVAFK P1IDei9NgKzJ+Unrc2sm1z+DHH86zxOhfyvbT4pKP1N/0SpiCp3ILnKSB8e5rwT0D/rQ 1GyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=pWHAmd4n94lhOLkDfA4lEnEVqxAqxHmNRbMePKV+S4M=; b=NEsOzxb4DXO2HV7O2FI1vNfKwI2n01WwbDNuzXU4dab4Ug5HiR8cqukCy/EyXNQYk5 AECM4mB9jgd4ZcjywDE4kB4NDgTpnkUCgy5HiwTPGgiw9WL9LojkM9e2+GV3g+YPETgg gYNX8z74CdRESQHvjpOV7BkRzMg3UkZds/5Ra2RRDltAIeY0VFQUiDNsStEOn544QIhq 3A+Iii2am/iEFdrC3B9hyQv4jPokcU3fedTiZneSdC0x9Lzj5nYNmeehn2WJcWQhvFPV urvNlEbW64uTX6WJSYuSHqpvV391BezDIySrqy0RKI28tVWBI2KrM62NSGc1FUoXPnQO lswg== X-Gm-Message-State: AD7BkJJlEwLni48Vv+gbDS8KOPo2f4fNE3NIpSGOpf8SfL/xepdZE071rhsFEOGD9AVHYA== X-Received: by 10.66.159.232 with SMTP id xf8mr13721091pab.71.1460131595824; Fri, 08 Apr 2016 09:06:35 -0700 (PDT) Received: from localhost ([2404:e800:e600:38b:5121:e6bd:6ddf:d757]) by smtp.gmail.com with ESMTPSA id 62sm19675250pfk.83.2016.04.08.09.06.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 Apr 2016 09:06:35 -0700 (PDT) From: Jason Zaman To: selinux@tycho.nsa.gov Subject: [PATCH 6/7] genhomedircon: make USERID, USERNAME context lists Date: Sat, 9 Apr 2016 00:05:34 +0800 Message-Id: <1460131535-15688-7-git-send-email-jason@perfinion.com> X-Mailer: git-send-email 2.7.3 In-Reply-To: <1460131535-15688-1-git-send-email-jason@perfinion.com> References: <20160201093633.GB21978@meriadoc.perfinion.com> <1460131535-15688-1-git-send-email-jason@perfinion.com> X-TM-AS-MML: disable X-BeenThere: selinux@tycho.nsa.gov X-Mailman-Version: 2.1.20 Precedence: list List-Id: "Security-Enhanced Linux \(SELinux\) mailing list" List-Post: List-Help: MIME-Version: 1.0 Errors-To: selinux-bounces@tycho.nsa.gov Sender: "Selinux" X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP --- libsemanage/src/genhomedircon.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/libsemanage/src/genhomedircon.c b/libsemanage/src/genhomedircon.c index ae4a261..60c9d27 100644 --- a/libsemanage/src/genhomedircon.c +++ b/libsemanage/src/genhomedircon.c @@ -73,8 +73,13 @@ which are searched for and replaced */ #define TEMPLATE_HOME_ROOT "HOME_ROOT" #define TEMPLATE_HOME_DIR "HOME_DIR" +/* these are legacy */ #define TEMPLATE_USER "USER" #define TEMPLATE_ROLE "ROLE" +/* new names */ +#define TEMPLATE_USERNAME "%{USERNAME}" +#define TEMPLATE_USERID "%{USERID}" + #define TEMPLATE_SEUSER "system_u" #define TEMPLATE_LEVEL "s0" @@ -463,8 +468,23 @@ static int HOME_DIR_PRED(const char *string) return semanage_is_prefix(string, TEMPLATE_HOME_DIR); } +/* new names */ +static int USERNAME_CONTEXT_PRED(const char *string) +{ + return (int)(strstr(string, TEMPLATE_USERNAME) != NULL); +} + +static int USERID_CONTEXT_PRED(const char *string) +{ + return (int)(strstr(string, TEMPLATE_USERID) != NULL); +} + +/* This will never match USER if USERNAME or USERID are found. */ static int USER_CONTEXT_PRED(const char *string) { + if (USERNAME_CONTEXT_PRED(string) || USERID_CONTEXT_PRED(string)) + return 0; + return (int)(strstr(string, TEMPLATE_USER) != NULL); } @@ -943,16 +963,24 @@ static int write_context_file(genhomedircon_settings_t * s, FILE * out) { semanage_list_t *homedirs = NULL; semanage_list_t *h = NULL; - semanage_list_t *user_context_tpl = NULL; semanage_list_t *homedir_context_tpl = NULL; semanage_list_t *homeroot_context_tpl = NULL; + semanage_list_t *username_context_tpl = NULL; + semanage_list_t *userid_context_tpl = NULL; + semanage_list_t *user_context_tpl = NULL; int retval = STATUS_SUCCESS; homedir_context_tpl = make_template(s, &HOME_DIR_PRED); homeroot_context_tpl = make_template(s, &HOME_ROOT_PRED); + username_context_tpl = make_template(s, &USERNAME_CONTEXT_PRED); + userid_context_tpl = make_template(s, &USERID_CONTEXT_PRED); user_context_tpl = make_template(s, &USER_CONTEXT_PRED); - if (!homedir_context_tpl && !homeroot_context_tpl && !user_context_tpl) + if (!homedir_context_tpl + && !homeroot_context_tpl + && !userid_context_tpl + && !username_context_tpl + && !user_context_tpl) goto done; if (write_file_context_header(out) != STATUS_SUCCESS) { @@ -1021,6 +1049,8 @@ static int write_context_file(genhomedircon_settings_t * s, FILE * out) done: /* Cleanup */ semanage_list_destroy(&homedirs); + semanage_list_destroy(&username_context_tpl); + semanage_list_destroy(&userid_context_tpl); semanage_list_destroy(&user_context_tpl); semanage_list_destroy(&homedir_context_tpl); semanage_list_destroy(&homeroot_context_tpl);