From patchwork Fri Apr 8 16:05:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Zaman X-Patchwork-Id: 8784471 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 A9FADC0553 for ; Fri, 8 Apr 2016 16:13:38 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C87202011D for ; Fri, 8 Apr 2016 16:13:37 +0000 (UTC) Received: from emvm-gh1-uea08.nsa.gov (smtp.nsa.gov [8.44.101.8]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 79871202EB for ; Fri, 8 Apr 2016 16:13:36 +0000 (UTC) X-TM-IMSS-Message-ID: <19ba884a000ae7e6@nsa.gov> Received: from tarius.tycho.ncsc.mil ([144.51.242.1]) by nsa.gov ([10.208.42.193]) with ESMTP (TREND IMSS SMTP Service 7.1) id 19ba884a000ae7e6 ; Fri, 8 Apr 2016 12:10:52 -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 u38GAwbF022296; Fri, 8 Apr 2016 12:10:58 -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 u38G6Ts4083027 for ; Fri, 8 Apr 2016 12:06:29 -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 u38G6LBH021119 for ; Fri, 8 Apr 2016 12:06:29 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A1AyCgBH1gdXd8TAVdFcgwyBe7g2gmyBJIYNAoF/AQEBAQEBEwEKCxQhcAwBg3QBAQEDEhUZAQE3AQ9RNAEFARw7iAUBoRuBMT4xik+FKAEEjT4BAQEBAQUCARcGCoQOjVsLQIJDh3WFXnOJQ44OZIhFhWJFjSMvgQ6CWQ0ZgVdfAYEfiBkBAQE X-IPAS-Result: A1AyCgBH1gdXd8TAVdFcgwyBe7g2gmyBJIYNAoF/AQEBAQEBEwEKCxQhcAwBg3QBAQEDEhUZAQE3AQ9RNAEFARw7iAUBoRuBMT4xik+FKAEEjT4BAQEBAQUCARcGCoQOjVsLQIJDh3WFXnOJQ44OZIhFhWJFjSMvgQ6CWQ0ZgVdfAYEfiBkBAQE X-IronPort-AV: E=Sophos;i="5.24,454,1454994000"; d="scan'208";a="5363086" Received: from emvm-gh1-uea09.nsa.gov ([10.208.42.194]) by goalie.tycho.ncsc.mil with ESMTP; 08 Apr 2016 12:06:28 -0400 X-TM-IMSS-Message-ID: <6594c7d6000a0e98@nsa.gov> Received: from mail-pf0-f196.google.com (mail-pf0-f196.google.com [209.85.192.196]) by nsa.gov ([10.208.42.194]) with ESMTP (TREND IMSS SMTP Service 7.1; TLSv1/SSLv3 AES128-SHA (128/128)) id 6594c7d6000a0e98 ; Fri, 8 Apr 2016 12:05:25 -0400 Received: by mail-pf0-f196.google.com with SMTP id r187so9830593pfr.2 for ; Fri, 08 Apr 2016 09:06:26 -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=AlZV/UT4EHZVWN1z7mx1282EIIEP9WmztiFuVPLJQlQ=; b=LA9NoAC9neNmUcRXZvwAytrNj3DO9pQdbc0OrEe0J81dFpbpKcQkTEgE6z443QP97g xWjauhIIJyUanKVjdUQdnUG1HzHc1ZP3Elf9gS9v8zbnpGVxmgD6fdE9d01syJS4y5Gs 2dwA4N0eAQdhH906lJ72ESnmx7uWZBXHE73aVALpQVBtj8QPd1TMfuOsXiaLdn1p9+xH LdtVKFNmrr8mhTcDrT+gARHvbQkx8ID0rq5gwjsJ1dKMMZhJKXTrc3cmzsq2U8Hb7rY7 HRxL2GAPvks7+8HuWidfF0U5MgxwKSxMmCHR/EX1tfvS2UaSZCJQm0BIkwZwSwdRgh8R omCw== 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=AlZV/UT4EHZVWN1z7mx1282EIIEP9WmztiFuVPLJQlQ=; b=g+iyeuKY8UUuB1qnSlQG8/OA7Wshkr2an09yvlMEGiwO2JU+JlHntXZgGxE2NMHi0M KOTwtCk+H5Ko7yDjy/legppEwsU3zlzyQOgF5SX4Fw2srVsiR8l4oYkcHfu0XtKqvjb5 oUA7IezNo/QtwvWKWg4IY6XSvSMdezdy34YPS/rxtw1kpxRNNX2HBFkMRi9jq1q+KgU0 z/ynGtdc/ZUguVrDAx71oHP4gIB7mFNRV6HgBszbcLrFEUHUKIZM4GmAJ45le7YdSdPe 4FmNNESAWKBmL2vfBs2zfZzpUYxIwQhvhoBdGYFOlgjdW/89+7hwUGr3xlZMZLJjs26l BwaQ== X-Gm-Message-State: AD7BkJIEfYMx3EnC6t4KNP2S0YkFL0+HkPsFygKf3L0Eqnq0eGwx/rrneyUyo0a5OACe3A== X-Received: by 10.98.43.204 with SMTP id r195mr13740258pfr.49.1460131585587; Fri, 08 Apr 2016 09:06:25 -0700 (PDT) Received: from localhost ([2404:e800:e600:38b:5121:e6bd:6ddf:d757]) by smtp.gmail.com with ESMTPSA id bu17sm19739093pac.25.2016.04.08.09.06.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 Apr 2016 09:06:24 -0700 (PDT) From: Jason Zaman To: selinux@tycho.nsa.gov Subject: [PATCH 4/7] genhomedircon: make all write context funcs take user_entry struct Date: Sat, 9 Apr 2016 00:05:32 +0800 Message-Id: <1460131535-15688-5-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 | 86 ++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 56 deletions(-) diff --git a/libsemanage/src/genhomedircon.c b/libsemanage/src/genhomedircon.c index 61f503f..495f084 100644 --- a/libsemanage/src/genhomedircon.c +++ b/libsemanage/src/genhomedircon.c @@ -570,20 +570,23 @@ static int write_replacements(genhomedircon_settings_t * s, FILE * out, } static int write_home_dir_context(genhomedircon_settings_t * s, FILE * out, - semanage_list_t * tpl, const char *user, - const char *seuser, const char *home, - const char *role_prefix, const char *level) + semanage_list_t * tpl, const genhomedircon_user_entry_t *user) { replacement_pair_t repl[] = { - {.search_for = TEMPLATE_SEUSER,.replace_with = seuser}, - {.search_for = TEMPLATE_HOME_DIR,.replace_with = home}, - {.search_for = TEMPLATE_ROLE,.replace_with = role_prefix}, - {.search_for = TEMPLATE_LEVEL,.replace_with = level}, + {.search_for = TEMPLATE_SEUSER,.replace_with = user->sename}, + {.search_for = TEMPLATE_HOME_DIR,.replace_with = user->home}, + {.search_for = TEMPLATE_ROLE,.replace_with = user->prefix}, + {.search_for = TEMPLATE_LEVEL,.replace_with = user->level}, {NULL, NULL} }; - if (fprintf(out, COMMENT_USER_HOME_CONTEXT, user) < 0) - return STATUS_ERR; + if (strcmp(user->name, FALLBACK_NAME) == 0) { + if (fprintf(out, COMMENT_USER_HOME_CONTEXT, FALLBACK_SENAME) < 0) + return STATUS_ERR; + } else { + if (fprintf(out, COMMENT_USER_HOME_CONTEXT, user->name) < 0) + return STATUS_ERR; + } return write_replacements(s, out, tpl, repl); } @@ -600,13 +603,12 @@ static int write_home_root_context(genhomedircon_settings_t * s, FILE * out, } static int write_user_context(genhomedircon_settings_t * s, FILE * out, - semanage_list_t * tpl, const char *user, - const char *seuser, const char *role_prefix) + semanage_list_t * tpl, const genhomedircon_user_entry_t *user) { replacement_pair_t repl[] = { - {.search_for = TEMPLATE_USER,.replace_with = user}, - {.search_for = TEMPLATE_ROLE,.replace_with = role_prefix}, - {.search_for = TEMPLATE_SEUSER,.replace_with = seuser}, + {.search_for = TEMPLATE_USER,.replace_with = user->name}, + {.search_for = TEMPLATE_ROLE,.replace_with = user->prefix}, + {.search_for = TEMPLATE_SEUSER,.replace_with = user->sename}, {NULL, NULL} }; @@ -691,32 +693,6 @@ static void pop_user_entry(genhomedircon_user_entry_t ** list) free(temp); } -static int set_fallback_user(genhomedircon_settings_t *s, const char *user, - const char *prefix, const char *level) -{ - char *fallback_user = strdup(user); - char *fallback_user_prefix = strdup(prefix); - char *fallback_user_level = NULL; - if (level) - fallback_user_level = strdup(level); - - if (fallback_user == NULL || fallback_user_prefix == NULL || - (fallback_user_level == NULL && level != NULL)) { - free(fallback_user); - free(fallback_user_prefix); - free(fallback_user_level); - return STATUS_ERR; - } - - free(s->fallback_user); - free(s->fallback_user_prefix); - free(s->fallback_user_level); - s->fallback_user = fallback_user; - s->fallback_user_prefix = fallback_user_prefix; - s->fallback_user_level = fallback_user_level; - return STATUS_SUCCESS; -} - static int setup_fallback_user(genhomedircon_settings_t * s) { semanage_seuser_t **seuser_list = NULL; @@ -761,7 +737,8 @@ static int setup_fallback_user(genhomedircon_settings_t * s) level = FALLBACK_LEVEL; } - if (set_fallback_user(s, seuname, prefix, level) != 0) + if (push_user_entry(&(s->fallback), FALLBACK_NAME, 0, 0, + seuname, prefix, "", level) != 0) errors = STATUS_ERR; semanage_user_key_free(key); if (u) @@ -822,7 +799,7 @@ static genhomedircon_user_entry_t *get_users(genhomedircon_settings_t * s, seuname = semanage_seuser_get_sename(seuser_list[i]); name = semanage_seuser_get_name(seuser_list[i]); - if (strcmp(name,"root") && strcmp(seuname, s->fallback_user) == 0) + if (strcmp(name,"root") && strcmp(seuname, s->fallback->sename) == 0) continue; if (strcmp(name, DEFAULT_LOGIN) == 0) @@ -915,13 +892,9 @@ 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->name, - users->sename, users->home, - users->prefix, users->level)) + if (write_home_dir_context(s, out, homedir_context_tpl, users)) goto err; - if (write_user_context(s, out, user_context_tpl, users->name, - users->sename, users->prefix)) + if (write_user_context(s, out, user_context_tpl, users)) goto err; } @@ -983,13 +956,13 @@ static int write_context_file(genhomedircon_settings_t * s, FILE * out) goto done; } - if (write_home_dir_context(s, out, - homedir_context_tpl, - s->fallback_user, s->fallback_user, - ustr_cstr(temp), - s->fallback_user_prefix, s->fallback_user_level) != - STATUS_SUCCESS) { + free(s->fallback->home); + s->fallback->home = (char*) ustr_cstr(temp); + + if (write_home_dir_context(s, out, homedir_context_tpl, + s->fallback) != STATUS_SUCCESS) { ustr_sc_free(&temp); + s->fallback->home = NULL; retval = STATUS_ERR; goto done; } @@ -997,17 +970,18 @@ static int write_context_file(genhomedircon_settings_t * s, FILE * out) homeroot_context_tpl, h->data) != STATUS_SUCCESS) { ustr_sc_free(&temp); + s->fallback->home = NULL; retval = STATUS_ERR; goto done; } ustr_sc_free(&temp); + s->fallback->home = NULL; } } if (user_context_tpl) { if (write_user_context(s, out, user_context_tpl, - ".*", s->fallback_user, - s->fallback_user_prefix) != STATUS_SUCCESS) { + s->fallback) != STATUS_SUCCESS) { retval = STATUS_ERR; goto done; }