Skip to contentSkip to conversation

libsemanage/genhomedircon: check usepasswd in add_user

PATCH In review Vit Mojzis 2 participants 9 messages Oct 27, 2020 – Nov 10, 2020 SELinux security module

lore
Share & tools
lore

Vit Mojzis

author
#0 lore raw

PATCH 1/1 libsemanage/genhomedircon: check usepasswd in add_user

Only add user homedir context entry when usepasswd = True

Resolves:
\#cat /etc/selinux/semanage.conf | grep usepasswd
usepasswd=False
\#useradd -Z unconfined_u -d /tmp test
\#matchpathcon /tmp
/tmp unconfined_u:object_r:user_home_dir_t:s0

---
 libsemanage/src/genhomedircon.c | 3 +++
 1 file changed, 3 insertions(+)
libsemanage/src/genhomedircon.c +3 -0
index d08c88de..19dfb7b0 100644
@@ -966,6 +966,9 @@ static int add_user(genhomedircon_settings_t * s,
 		}
 	}
 
+	if (!(s->usepasswd))
+		return STATUS_SUCCESS;
+
 	int retval = STATUS_ERR;
 
 	char *rbuf = NULL;
Signature · 1 line
2.25.4
#1 lore raw
Quoted 8 lines · Vit Mojzis

Only add user homedir context entry when usepasswd = True

Resolves:
\#cat /etc/selinux/semanage.conf | grep usepasswd
usepasswd=False
\#useradd -Z unconfined_u -d /tmp test
\#matchpathcon /tmp
/tmp unconfined_u:object_r:user_home_dir_t:s0

It should be enough to indent lines with few spaces, e.g.

Resolves:

    # grep usepasswd /etc/selinux/semanage.conf
    usepasswd=False
    # useradd -Z unconfined_u -d /tmp test
    # matchpathcon /tmp
    /tmp	unconfined_u:object_r:user_home_dir_t:s0

Also please provide Signed-off-by: see
https://github.com/SELinuxProject/selinux/blob/master/CONTRIBUTING.md

Quoted 21 lines
---
 libsemanage/src/genhomedircon.c | 3 +++
 1 file changed, 3 insertions(+)
libsemanage/src/genhomedircon.c +3 -0
index d08c88de..19dfb7b0 100644
@@ -966,6 +966,9 @@ static int add_user(genhomedircon_settings_t * s,
 		}
 	}
 
+	if (!(s->usepasswd))
+		return STATUS_SUCCESS;
+
 	int retval = STATUS_ERR;
 
 	char *rbuf = NULL;
Signature · 1 line
2.25.4
author
#2 lore raw

PATCH 1/1 libsemanage/genhomedircon: check usepasswd in add_user

Only add user homedir context entry when usepasswd = True

Resolves:
#cat /etc/selinux/semanage.conf | grep usepasswd usepasswd=False
#useradd -Z unconfined_u -d /tmp test #matchpathcon /tmp
/tmp unconfined_u:object_r:user_home_dir_t:s0

---
 libsemanage/src/genhomedircon.c | 3 +++
 1 file changed, 3 insertions(+)
libsemanage/src/genhomedircon.c +3 -0
index d08c88de..19dfb7b0 100644
@@ -966,6 +966,9 @@ static int add_user(genhomedircon_settings_t * s,
 		}
 	}
 
+	if (!(s->usepasswd))
+		return STATUS_SUCCESS;
+
 	int retval = STATUS_ERR;
 
 	char *rbuf = NULL;
Signature · 1 line
2.25.4
#3 lore raw
Quoted 31 lines · Vit Mojzis

Only add user homedir context entry when usepasswd = True

Resolves:
#cat /etc/selinux/semanage.conf | grep usepasswd usepasswd=False
#useradd -Z unconfined_u -d /tmp test #matchpathcon /tmp
/tmp unconfined_u:object_r:user_home_dir_t:s0

---
 libsemanage/src/genhomedircon.c | 3 +++
 1 file changed, 3 insertions(+)
libsemanage/src/genhomedircon.c +3 -0
index d08c88de..19dfb7b0 100644
@@ -966,6 +966,9 @@ static int add_user(genhomedircon_settings_t * s,
 		}
 	}
 
+	if (!(s->usepasswd))
+		return STATUS_SUCCESS;
+
 	int retval = STATUS_ERR;
 
 	char *rbuf = NULL;
Signature · 1 line
2.25.4

add_user() seems to be too deep. Would it make sense to (s->usepasswd) in write_context_file() as part of a condition on line 1338:

	if (user_context_tpl || username_context_tpl) {

?

author
#4 lore raw

PATCH 1/1 libsemanage/genhomedircon: check usepasswd

Only add user homedir contexts when usepasswd = True

Resolves:
\#cat /etc/selinux/semanage.conf | grep usepasswd
usepasswd=False
\#useradd -Z unconfined_u -d /tmp test
\#matchpathcon /tmp
/tmp unconfined_u:object_r:user_home_dir_t:s0

---
 libsemanage/src/genhomedircon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libsemanage/src/genhomedircon.c +1 -1
index d08c88de..fc75fa8c 100644
@@ -1332,7 +1332,7 @@ static int write_context_file(genhomedircon_settings_t * s, FILE * out)
 			s->fallback->home = NULL;
 		}
 	}
-	if (user_context_tpl || username_context_tpl) {
+	if (!(s->usepasswd) && (user_context_tpl || username_context_tpl)) {
 		if (write_username_context(s, out, username_context_tpl,
 					   s->fallback) != STATUS_SUCCESS) {
 			retval = STATUS_ERR;
Signature · 1 line
2.26.2
author
#5 lore raw

PATCH 1/1 libsemanage/genhomedircon: check usepasswd

In reply to Petr Lautrbach

Only add user homedir contexts when usepasswd = True

Resolves:
#cat /etc/selinux/semanage.conf | grep usepasswd usepasswd=False
#useradd -Z unconfined_u -d /tmp test #matchpathcon /tmp
/tmp unconfined_u:object_r:user_home_dir_t:s0

---
 libsemanage/src/genhomedircon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libsemanage/src/genhomedircon.c +1 -1
index d08c88de..fc75fa8c 100644
@@ -1332,7 +1332,7 @@ static int write_context_file(genhomedircon_settings_t * s, FILE * out)
 			s->fallback->home = NULL;
 		}
 	}
-	if (user_context_tpl || username_context_tpl) {
+	if (!(s->usepasswd) && (user_context_tpl || username_context_tpl)) {
 		if (write_username_context(s, out, username_context_tpl,
 					   s->fallback) != STATUS_SUCCESS) {
 			retval = STATUS_ERR;
Signature · 1 line
2.26.2
#6 lore raw

Re: [PATCH] libsemanage/genhomedircon: check usepasswd

Quoted 19 lines · Vit Mojzis

Only add user homedir contexts when usepasswd = True

Resolves:
#cat /etc/selinux/semanage.conf | grep usepasswd usepasswd=False
#useradd -Z unconfined_u -d /tmp test #matchpathcon /tmp
/tmp unconfined_u:object_r:user_home_dir_t:s0

---
 libsemanage/src/genhomedircon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libsemanage/src/genhomedircon.c +0 -0
index d08c88de..fc75fa8c 100644

libsemanage/src/genhomedircon.c static int write_context_file(genhomedircon_settings_t * s, FILE * out) · line 1335

Quoted 5 lines
libsemanage/src/genhomedircon.c +1 -1
@@ -1332,7 +1332,7 @@ static int write_context_file(genhomedircon_settings_t * s, FILE * out)
 			s->fallback->home = NULL;
 		}
 	}
-	if (user_context_tpl || username_context_tpl) {
+	if (!(s->usepasswd) && (user_context_tpl || username_context_tpl)) {

I guess this condition is reversed - we want to write user contexts when usepasswd is True

Quoted 6 lines
libsemanage/src/genhomedircon.c +0 -0
 		if (write_username_context(s, out, username_context_tpl,
 					   s->fallback) != STATUS_SUCCESS) {
 			retval = STATUS_ERR;
Signature · 1 line
2.26.2
author
#7 lore raw

PATCH v2 1/1 libsemanage/genhomedircon: check usepasswd

Only add user homedir contexts when usepasswd = True

Resolves:
#cat /etc/selinux/semanage.conf | grep usepasswd usepasswd=False
#useradd -Z unconfined_u -d /tmp test #matchpathcon /tmp
/tmp unconfined_u:object_r:user_home_dir_t:s0

---
v2 - invert condition as suggested by plautrba

 libsemanage/src/genhomedircon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libsemanage/src/genhomedircon.c +1 -1
index d08c88de..18d3d99a 100644
@@ -1332,7 +1332,7 @@ static int write_context_file(genhomedircon_settings_t * s, FILE * out)
 			s->fallback->home = NULL;
 		}
 	}
-	if (user_context_tpl || username_context_tpl) {
+	if ((s->usepasswd) && (user_context_tpl || username_context_tpl)) {
 		if (write_username_context(s, out, username_context_tpl,
 					   s->fallback) != STATUS_SUCCESS) {
 			retval = STATUS_ERR;
Signature · 1 line
2.26.2
Acked-by on v2 1/1
#8 lore raw

Re: [PATCH v2] libsemanage/genhomedircon: check usepasswd

Quoted 10 lines · Vit Mojzis

Only add user homedir contexts when usepasswd = True

Resolves:
#cat /etc/selinux/semanage.conf | grep usepasswd usepasswd=False
#useradd -Z unconfined_u -d /tmp test #matchpathcon /tmp
/tmp unconfined_u:object_r:user_home_dir_t:s0

Merged with slightly changed commit message, thanks!

Quoted 22 lines

---
v2 - invert condition as suggested by plautrba

 libsemanage/src/genhomedircon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libsemanage/src/genhomedircon.c +1 -1
index d08c88de..18d3d99a 100644
@@ -1332,7 +1332,7 @@ static int write_context_file(genhomedircon_settings_t * s, FILE * out)
 			s->fallback->home = NULL;
 		}
 	}
-	if (user_context_tpl || username_context_tpl) {
+	if ((s->usepasswd) && (user_context_tpl || username_context_tpl)) {
 		if (write_username_context(s, out, username_context_tpl,
 					   s->fallback) != STATUS_SUCCESS) {
 			retval = STATUS_ERR;
Signature · 1 line
2.26.2