All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jason Zaman <jason@perfinion.com>
To: selinux@tycho.nsa.gov
Subject: [PATCH v2 6/8] genhomedircon: make USERID, USERNAME context lists
Date: Sat, 23 Apr 2016 14:04:57 +0800	[thread overview]
Message-ID: <1461391499-20593-7-git-send-email-jason@perfinion.com> (raw)
In-Reply-To: <1461391499-20593-1-git-send-email-jason@perfinion.com>

Signed-off-by: Jason Zaman <jason@perfinion.com>
---
 libsemanage/src/genhomedircon.c | 28 ++++++++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)

diff --git a/libsemanage/src/genhomedircon.c b/libsemanage/src/genhomedircon.c
index 56c58e0..e69b311 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,21 @@ 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) ||
+		(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))
+		return 0;
+
 	return (int)(strstr(string, TEMPLATE_USER) != NULL);
 }
 
@@ -944,16 +962,21 @@ 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 *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);
 	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
+	 && !username_context_tpl
+	 && !user_context_tpl)
 		goto done;
 
 	if (write_file_context_header(out) != STATUS_SUCCESS) {
@@ -1022,6 +1045,7 @@ 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(&user_context_tpl);
 	semanage_list_destroy(&homedir_context_tpl);
 	semanage_list_destroy(&homeroot_context_tpl);
-- 
2.7.3

  parent reply	other threads:[~2016-04-23  6:05 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-01  9:36 genhomedircon uid template Jason Zaman
2016-02-01 19:30 ` Stephen Smalley
2016-02-02  6:26   ` Jason Zaman
2016-02-02 13:57     ` Christopher J. PeBenito
2016-02-02 15:03     ` Stephen Smalley
2016-02-02 20:39       ` Nicolas Iooss
2016-04-08 16:05 ` genhomedircon USERID and USERNAME patches Jason Zaman
2016-04-08 16:05   ` [PATCH 1/7] genhomedircon: factor out common replacement code Jason Zaman
2016-04-08 16:05   ` [PATCH 2/7] genhomedircon: move fallback user to genhomedircon_user_entry_t Jason Zaman
2016-04-08 16:05   ` [PATCH 3/7] genhomedircon: rename FALLBACK #defines consistent with struct Jason Zaman
2016-04-08 16:05   ` [PATCH 4/7] genhomedircon: make all write context funcs take user_entry struct Jason Zaman
2016-04-08 16:05   ` [PATCH 5/7] genhomedircon: Add uid and gid to struct user_entry Jason Zaman
2016-04-08 16:05   ` [PATCH 6/7] genhomedircon: make USERID, USERNAME context lists Jason Zaman
2016-04-08 16:05   ` [PATCH 7/7] genhomedircon: write contexts for username and userid Jason Zaman
2016-04-11 21:44   ` genhomedircon USERID and USERNAME patches Nicolas Iooss
2016-04-12  7:56     ` Dominick Grift
2016-04-12 11:51     ` Jason Zaman
2016-04-12 12:57     ` Stephen Smalley
2016-04-12 14:35       ` Christopher J. PeBenito
2016-04-13 16:34         ` Dominick Grift
2016-04-13 17:00           ` Stephen Smalley
2016-04-13 17:10             ` Dominick Grift
2016-04-13 17:18               ` Dominick Grift
2016-04-13 18:25                 ` Dominick Grift
2016-04-17 10:12                   ` Dominick Grift
2016-04-17 12:03                     ` Dominick Grift
2016-04-17 19:19                       ` Dominick Grift
2016-04-18  6:23                         ` Dominick Grift
2016-04-23  6:04   ` genhomedircon USERID and USERNAME patches v2 Jason Zaman
2016-04-23  6:04     ` [PATCH v2 1/8] genhomedircon: factor out common replacement code Jason Zaman
2016-04-23  6:04     ` [PATCH v2 2/8] genhomedircon: move fallback user to genhomedircon_user_entry_t Jason Zaman
2016-04-29 16:54       ` Stephen Smalley
2016-04-29 19:23         ` Jason Zaman
2016-04-29 20:29           ` Stephen Smalley
2016-04-23  6:04     ` [PATCH v2 3/8] genhomedircon: rename FALLBACK #defines consistent with struct Jason Zaman
2016-04-23  6:04     ` [PATCH v2 4/8] genhomedircon: make all write context funcs take user_entry struct Jason Zaman
2016-04-23  6:04     ` [PATCH v2 5/8] genhomedircon: Add uid and gid to struct user_entry Jason Zaman
2016-04-27 17:04       ` Stephen Smalley
2016-04-28 17:53         ` Jason Zaman
2016-04-28 18:13           ` Stephen Smalley
2016-04-29 12:01             ` Jason Zaman
2016-04-23  6:04     ` Jason Zaman [this message]
2016-04-23  6:04     ` [PATCH v2 7/8] genhomedircon: write contexts for username and userid Jason Zaman
2016-04-23  6:04     ` [PATCH v2 8/8] genhomedircon: fix FALLBACK_NAME regex Jason Zaman
2016-04-26 22:03     ` genhomedircon USERID and USERNAME patches v2 Nicolas Iooss
2016-04-29 12:04   ` [PATCH v3 5/8] genhomedircon: Add uid and gid to struct user_entry Jason Zaman
2016-04-29 20:28     ` Stephen Smalley

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1461391499-20593-7-git-send-email-jason@perfinion.com \
    --to=jason@perfinion.com \
    --cc=selinux@tycho.nsa.gov \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.