From patchwork Fri Apr 8 16:05:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Zaman X-Patchwork-Id: 8784431 Return-Path: X-Original-To: patchwork-selinux@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 86844C0554 for ; Fri, 8 Apr 2016 16:13:32 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C719D2011D for ; Fri, 8 Apr 2016 16:13:31 +0000 (UTC) Received: from emvm-gh1-uea09.nsa.gov (smtp.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 D7373202E9 for ; Fri, 8 Apr 2016 16:13:30 +0000 (UTC) X-TM-IMSS-Message-ID: <659904a7000a10e4@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 659904a7000a10e4 ; Fri, 8 Apr 2016 12:10:02 -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 u38GB3mr022517; Fri, 8 Apr 2016 12:11:03 -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 u38G6hE9083036 for ; Fri, 8 Apr 2016 12:06:43 -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 u38G6Zm4021132 for ; Fri, 8 Apr 2016 12:06:43 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A1AyCgBH1gdXd0LcVdFaAoMMgXu4NoJsgSSGDQKBfwEBAQEBARMBCgsUIXAMAYN0AQEBAxIVGQEBNwEPORg0AQUBHDuIBQGhG4ExPjGKT4UoAQSNPgEBAQEBAQQCARcGCoQOi1sLgXULQIJDjVNziUOODmSIRYVijWgvgQ6CWQ0ZgVdfAYEfhmWBNAEBAQ X-IPAS-Result: A1AyCgBH1gdXd0LcVdFaAoMMgXu4NoJsgSSGDQKBfwEBAQEBARMBCgsUIXAMAYN0AQEBAxIVGQEBNwEPORg0AQUBHDuIBQGhG4ExPjGKT4UoAQSNPgEBAQEBAQQCARcGCoQOi1sLgXULQIJDjVNziUOODmSIRYVijWgvgQ6CWQ0ZgVdfAYEfhmWBNAEBAQ X-IronPort-AV: E=Sophos;i="5.24,454,1454994000"; d="scan'208";a="5363092" Received: from emvm-gh1-uea09.nsa.gov ([10.208.42.194]) by goalie.tycho.ncsc.mil with ESMTP; 08 Apr 2016 12:06:42 -0400 X-TM-IMSS-Message-ID: <6594ffe6000a0eba@nsa.gov> Received: from mail-pa0-f66.google.com (mail-pa0-f66.google.com [209.85.220.66]) by nsa.gov ([10.208.42.194]) with ESMTP (TREND IMSS SMTP Service 7.1; TLSv1/SSLv3 AES128-SHA (128/128)) id 6594ffe6000a0eba ; Fri, 8 Apr 2016 12:05:39 -0400 Received: by mail-pa0-f66.google.com with SMTP id hb4so9371070pac.1 for ; Fri, 08 Apr 2016 09:06:40 -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=GWKBTiq8x6cwHfaQph0htpHFlHFke+LGoBgroxugkZE=; b=zsvhsOCNpxKhfN46Zana420TKXbHzWgau7JTOgfVtLczcJkFoTWK2EUHxfPH7DOtR3 udM86luOPciWmTbJvXgwvFP9G+dfCfjfJHb769lfTov/YaBMK5gKjKJrhazYIowjwf4W BsRKgyAo+ujviXbedMOtQMEXB6ra5ey3lnwAYOoiOiYmdCdI8U3mp1MEi7qLO+v0RwCv iAXzI6czscO+2f/Wh1ZGSoL+AYggU0fmu8VHQjp8Wv8EZ/ubVLLeL1rpcjDnJPTEFp1e EIGLw+wr4586XaaQaLLL1Bxd/US8O6hBN/n+1QQtea4UjOySc9KgRiWynPS3Bvua1h4m gvcw== 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=GWKBTiq8x6cwHfaQph0htpHFlHFke+LGoBgroxugkZE=; b=XB5tO1TGhsqXI3qw0OeNj3jIt7knUwa4v14mcIPguGlEI4wfDOyJs1yJgJbc7v9dFA LOa2B8S0B4VLGuZN0kHW1kpWBs83cX0BWLyMbnCxNDtvls8xQg8gkRrxMINPDI5Go3Ig AmnGJapYUmcq1qPYnbudxAwMVEuWo3AMkHywkyQybcDMa1DLgtxERrrMlXVe9zYicxus Y7v5f5LIkE65iHmG8Pcj4RscFLzRhWj5I2am87XdcKBuQhwxllDmyKj3A3Un5He7x3bb 54lViyJLUjPpWT6Wt9a5Z5xI0w8CCFqnGADAzKaxHUAJHtJUae5RiAUBd/C8Je+TI+hK jgfg== X-Gm-Message-State: AD7BkJL8pLBEWUzDgBtFzUuIwWWhOnn5b2pDC8mNJrFAguFl7i5m9QJxXJmplhnTvVHWRg== X-Received: by 10.66.157.69 with SMTP id wk5mr13457622pab.40.1460131599664; Fri, 08 Apr 2016 09:06:39 -0700 (PDT) Received: from localhost ([2404:e800:e600:38b:5121:e6bd:6ddf:d757]) by smtp.gmail.com with ESMTPSA id m84sm19679059pfi.75.2016.04.08.09.06.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 Apr 2016 09:06:39 -0700 (PDT) From: Jason Zaman To: selinux@tycho.nsa.gov Subject: [PATCH 7/7] genhomedircon: write contexts for username and userid Date: Sat, 9 Apr 2016 00:05:35 +0800 Message-Id: <1460131535-15688-8-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 | 51 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/libsemanage/src/genhomedircon.c b/libsemanage/src/genhomedircon.c index 60c9d27..66ab307 100644 --- a/libsemanage/src/genhomedircon.c +++ b/libsemanage/src/genhomedircon.c @@ -625,6 +625,34 @@ static int write_home_root_context(genhomedircon_settings_t * s, FILE * out, return write_replacements(s, out, tpl, repl); } +static int write_username_context(genhomedircon_settings_t * s, FILE * out, + semanage_list_t * tpl, + const genhomedircon_user_entry_t *user) +{ + replacement_pair_t repl[] = { + {.search_for = TEMPLATE_USERNAME,.replace_with = user->name}, + {.search_for = TEMPLATE_ROLE,.replace_with = user->prefix}, + {.search_for = TEMPLATE_SEUSER,.replace_with = user->sename}, + {NULL, NULL} + }; + + return write_replacements(s, out, tpl, repl); +} + +static int write_userid_context(genhomedircon_settings_t * s, FILE * out, + semanage_list_t * tpl, + const genhomedircon_user_entry_t *user) +{ + replacement_pair_t repl[] = { + {.search_for = TEMPLATE_USERID,.replace_with = user->uid}, + {.search_for = TEMPLATE_ROLE,.replace_with = user->prefix}, + {.search_for = TEMPLATE_SEUSER,.replace_with = user->sename}, + {NULL, NULL} + }; + + return write_replacements(s, out, tpl, repl); +} + static int write_user_context(genhomedircon_settings_t * s, FILE * out, semanage_list_t * tpl, const genhomedircon_user_entry_t *user) { @@ -926,6 +954,8 @@ static genhomedircon_user_entry_t *get_users(genhomedircon_settings_t * s, } static int write_gen_home_dir_context(genhomedircon_settings_t * s, FILE * out, + semanage_list_t * username_context_tpl, + semanage_list_t * userid_context_tpl, semanage_list_t * user_context_tpl, semanage_list_t * homedir_context_tpl) { @@ -940,6 +970,10 @@ static int write_gen_home_dir_context(genhomedircon_settings_t * s, FILE * out, for (; users; pop_user_entry(&users)) { if (write_home_dir_context(s, out, homedir_context_tpl, users)) goto err; + if (write_username_context(s, out, username_context_tpl, users)) + goto err; + if (write_userid_context(s, out, userid_context_tpl, users)) + goto err; if (write_user_context(s, out, user_context_tpl, users)) goto err; } @@ -1033,14 +1067,27 @@ static int write_context_file(genhomedircon_settings_t * s, FILE * out) s->fallback->home = NULL; } } - if (user_context_tpl) { + if (user_context_tpl || userid_context_tpl || username_context_tpl) { + if (write_username_context(s, out, username_context_tpl, + s->fallback) != STATUS_SUCCESS) { + retval = STATUS_ERR; + goto done; + } + + if (write_userid_context(s, out, userid_context_tpl, + s->fallback) != STATUS_SUCCESS) { + retval = STATUS_ERR; + goto done; + } + if (write_user_context(s, out, user_context_tpl, s->fallback) != STATUS_SUCCESS) { retval = STATUS_ERR; goto done; } - if (write_gen_home_dir_context(s, out, user_context_tpl, + if (write_gen_home_dir_context(s, out, username_context_tpl, + userid_context_tpl, user_context_tpl, homedir_context_tpl) != STATUS_SUCCESS) { retval = STATUS_ERR; }