Skip to contentSkip to conversation

libsemanage patch

PATCH Daniel J Walsh 3 participants 9 messages Jul 15, 2009 – Sep 16, 2009 SELinux security module

lore
Share & tools
lore
#0 lore raw

If you have a homedir that ends in '/', genhomedircon gets confused.

# useradd -h /home2/dwalsh/ dwalsh
# genhomedircon

Check out the labeling. genhomedircon thinks dwalsh is a toplevel home root.

We should just get rid of this command... :^)

Patch removes all trailing '/' from homedir.

src/genhomedircon.c +4 -0
diff --exclude-from=exclude -N -u -r nsalibsemanage/src/genhomedircon.c libsemanage-2.0.33/src/genhomedircon.c
@@ -304,6 +304,10 @@
 			continue;
 		if (!semanage_list_find(shells, pwbuf->pw_shell))
 			continue;
+		int len = strlen(pwbuf->pw_dir) -1;
+		for(; len > 0 && pwbuf->pw_dir[len]=='/'; len--) {
+			pwbuf->pw_dir[len]=0;
+		}
 		if (strcmp(pwbuf->pw_dir, "/") == 0)
 			continue;
 		if (semanage_str_count(pwbuf->pw_dir, '/') <= 1)
Acked-by
#1 lore raw
Quoted 10 lines · Daniel J Walsh

If you have a homedir that ends in '/', genhomedircon gets confused.

# useradd -h /home2/dwalsh/ dwalsh
# genhomedircon

Check out the labeling. genhomedircon thinks dwalsh is a toplevel home root.

We should just get rid of this command... :^)

Patch removes all trailing '/' from homedir.

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#2 lore raw
In reply to Daniel J Walsh
Quoted 15 lines · Daniel J Walsh

If you have a homedir that ends in '/', genhomedircon gets confused.

# useradd -h /home2/dwalsh/ dwalsh
# genhomedircon

Check out the labeling. genhomedircon thinks dwalsh is a toplevel home root.

We should just get rid of this command... :^)

Patch removes all trailing '/' from homedir.

diff --exclude-from=exclude -N -u -r nsalibsemanage/src/genhomedircon.c libsemanage-2.0.33/src/genhomedircon.c

src/genhomedircon.c line 313

Quoted 10 lines
src/genhomedircon.c +4 -0
@@ -304,6 +304,10 @@
 			continue;
 		if (!semanage_list_find(shells, pwbuf->pw_shell))
 			continue;
+		int len = strlen(pwbuf->pw_dir) -1;
+		for(; len > 0 && pwbuf->pw_dir[len]=='/'; len--) {
+			pwbuf->pw_dir[len]=0;
+		}
 		if (strcmp(pwbuf->pw_dir, "/") == 0)
 			continue;
 		if (semanage_str_count(pwbuf->pw_dir, '/') <= 1)

Why aren't you just doing:

len = strlen(pwbuf->pwdir);
if (pwbuf->pwdir[len] == '/')

	pwbuf->pwdir[len] = '\0';

?

Also, won't this fail if the homedir is set to '/' ? This check should probably go below the strcmp(pwbuf->pw_dir, "/") that is currently below it.

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#3 lore raw
Quoted 33 lines · Joshua Brindle
Quoted 19 lines · Daniel J Walsh

If you have a homedir that ends in '/', genhomedircon gets confused.

# useradd -h /home2/dwalsh/ dwalsh
# genhomedircon

Check out the labeling. genhomedircon thinks dwalsh is a toplevel home root.

We should just get rid of this command... :^)

Patch removes all trailing '/' from homedir.

diff --exclude-from=exclude -N -u -r nsalibsemanage/src/genhomedircon.c libsemanage-2.0.33/src/genhomedircon.c
--- nsalibsemanage/src/genhomedircon.c 2008-08-28
09:34:24.000000000 -0400
+++ libsemanage-2.0.33/src/genhomedircon.c 2009-07-15
10:32:20.000000000 -0400

src/genhomedircon.c line 313

Quoted 10 lines
src/genhomedircon.c +4 -0
@@ -304,6 +304,10 @@
             continue;
         if (!semanage_list_find(shells, pwbuf->pw_shell))
             continue;
+        int len = strlen(pwbuf->pw_dir) -1;
+        for(; len > 0 && pwbuf->pw_dir[len]=='/'; len--) {
+            pwbuf->pw_dir[len]=0;
+        }
         if (strcmp(pwbuf->pw_dir, "/") == 0)
             continue;
         if (semanage_str_count(pwbuf->pw_dir, '/') <= 1)

Why aren't you just doing:

Quoted 6 lines

len = strlen(pwbuf->pwdir);
if (pwbuf->pwdir[len] == '/')

    pwbuf->pwdir[len] = '\0';

?

What about /home/dwalsh//////
Which I believe is legal

Quoted 3 lines

Also, won't this fail if the homedir is set to '/' ? This check should probably go below the strcmp(pwbuf->pw_dir, "/") that is currently below it.

Yes good point.

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#4 lore raw
Quoted 38 lines · Daniel J Walsh
Quoted 37 lines · Joshua Brindle
Quoted 19 lines · Daniel J Walsh

If you have a homedir that ends in '/', genhomedircon gets confused.

# useradd -h /home2/dwalsh/ dwalsh
# genhomedircon

Check out the labeling. genhomedircon thinks dwalsh is a toplevel home root.

We should just get rid of this command... :^)

Patch removes all trailing '/' from homedir.

diff --exclude-from=exclude -N -u -r nsalibsemanage/src/genhomedircon.c libsemanage-2.0.33/src/genhomedircon.c
--- nsalibsemanage/src/genhomedircon.c 2008-08-28
09:34:24.000000000 -0400
+++ libsemanage-2.0.33/src/genhomedircon.c 2009-07-15
10:32:20.000000000 -0400

src/genhomedircon.c line 313

Quoted 10 lines
src/genhomedircon.c +4 -0
@@ -304,6 +304,10 @@
             continue;
         if (!semanage_list_find(shells, pwbuf->pw_shell))
             continue;
+        int len = strlen(pwbuf->pw_dir) -1;
+        for(; len > 0 && pwbuf->pw_dir[len]=='/'; len--) {
+            pwbuf->pw_dir[len]=0;
+        }
         if (strcmp(pwbuf->pw_dir, "/") == 0)
             continue;
         if (semanage_str_count(pwbuf->pw_dir, '/') <= 1)

Why aren't you just doing:

len = strlen(pwbuf->pwdir);
if (pwbuf->pwdir[len] == '/')

    pwbuf->pwdir[len] = '\0';
Quoted 9 lines
Quoted 2 lines

?

What about /home/dwalsh//////
Which I believe is legal

Quoted 3 lines

Also, won't this fail if the homedir is set to '/' ? This check should probably go below the strcmp(pwbuf->pw_dir, "/") that is currently below it.

Yes good point.

I thought it worked fine with '/'. Since the loop condition is len > 0 (where len is the index of the last character, not the length of the string, which is a bit confusing and should probably be changed), it would never reset the first character. And don't you want this before the strcmp(pwbuf->pw_dir, "/") in case the path is ///// (which would of course be silly, but I believe is legal anyway)?

Chad

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#5 lore raw
Quoted 56 lines · Chad Sellers
Quoted 43 lines · Daniel J Walsh
Quoted 34 lines · Joshua Brindle
Quoted 20 lines · Daniel J Walsh

If you have a homedir that ends in '/', genhomedircon gets confused.

# useradd -h /home2/dwalsh/ dwalsh
# genhomedircon

Check out the labeling. genhomedircon thinks dwalsh is a toplevel home root.

We should just get rid of this command... :^)

Patch removes all trailing '/' from homedir.

diff --exclude-from=exclude -N -u -r nsalibsemanage/src/genhomedircon.c libsemanage-2.0.33/src/genhomedircon.c
--- nsalibsemanage/src/genhomedircon.c 2008-08-28
09:34:24.000000000 -0400
+++ libsemanage-2.0.33/src/genhomedircon.c 2009-07-15
10:32:20.000000000 -0400

src/genhomedircon.c line 313

Quoted 10 lines
src/genhomedircon.c +4 -0
@@ -304,6 +304,10 @@
              continue;
          if (!semanage_list_find(shells, pwbuf->pw_shell))
              continue;
+        int len = strlen(pwbuf->pw_dir) -1;
+        for(; len>  0&&  pwbuf->pw_dir[len]=='/'; len--) {
+            pwbuf->pw_dir[len]=0;
+        }
          if (strcmp(pwbuf->pw_dir, "/") == 0)
              continue;
          if (semanage_str_count(pwbuf->pw_dir, '/')<= 1)

Why aren't you just doing:

Quoted 7 lines

len = strlen(pwbuf->pwdir);
if (pwbuf->pwdir[len] == '/')

     pwbuf->pwdir[len] = '\0';

?

Quoted 10 lines

What about /home/dwalsh//////
Which I believe is legal

Quoted 4 lines

Also, won't this fail if the homedir is set to '/' ? This check should probably go below the strcmp(pwbuf->pw_dir, "/") that is currently below it.

Yes good point.

Quoted 10 lines

I thought it worked fine with '/'. Since the loop condition is len> 0 (where len is the index of the last character, not the length of the string, which is a bit confusing and should probably be changed), it would never reset the first character. And don't you want this before the strcmp(pwbuf->pw_dir, "/") in case the path is ///// (which would of course be silly, but I believe is legal anyway)?

Chad

Yep, got it.

#6 lore raw
Quoted 66 lines · Joshua Brindle
Quoted 63 lines · Chad Sellers
Quoted 43 lines · Daniel J Walsh
Quoted 34 lines · Joshua Brindle
Quoted 20 lines · Daniel J Walsh

If you have a homedir that ends in '/', genhomedircon gets confused.

# useradd -h /home2/dwalsh/ dwalsh
# genhomedircon

Check out the labeling. genhomedircon thinks dwalsh is a toplevel home root.

We should just get rid of this command... :^)

Patch removes all trailing '/' from homedir.

diff --exclude-from=exclude -N -u -r nsalibsemanage/src/genhomedircon.c libsemanage-2.0.33/src/genhomedircon.c
--- nsalibsemanage/src/genhomedircon.c 2008-08-28
09:34:24.000000000 -0400
+++ libsemanage-2.0.33/src/genhomedircon.c 2009-07-15
10:32:20.000000000 -0400

src/genhomedircon.c line 313

Quoted 10 lines
src/genhomedircon.c +4 -0
@@ -304,6 +304,10 @@
              continue;
          if (!semanage_list_find(shells, pwbuf->pw_shell))
              continue;
+        int len = strlen(pwbuf->pw_dir) -1;
+        for(; len>  0&&  pwbuf->pw_dir[len]=='/'; len--) {
+            pwbuf->pw_dir[len]=0;
+        }
          if (strcmp(pwbuf->pw_dir, "/") == 0)
              continue;
          if (semanage_str_count(pwbuf->pw_dir, '/')<= 1)

Why aren't you just doing:

Quoted 7 lines

len = strlen(pwbuf->pwdir);
if (pwbuf->pwdir[len] == '/')

     pwbuf->pwdir[len] = '\0';

?

Quoted 10 lines

What about /home/dwalsh//////
Which I believe is legal

Quoted 4 lines

Also, won't this fail if the homedir is set to '/' ? This check should probably go below the strcmp(pwbuf->pw_dir, "/") that is currently below it.

Yes good point.

I thought it worked fine with '/'. Since the loop condition is len> 0 (where len is the index of the last character, not the length of the string, which is a bit confusing and should probably be changed), it would never reset the first character. And don't you want this before the strcmp(pwbuf->pw_dir, "/") in case the path is ///// (which would of course be silly, but I believe is legal anyway)?

Quoted 7 lines
Quoted 3 lines

Chad

Yep, got it.

Sorry, premature ack.

I'm not seeing the expected results here. I added a user with a homedir of /home/method///// and the file_contexts.homedirs still has:

/home/method//////.+ staff_u:object_r:user_home_t:s0

Also, you should probably use '\0' rather than 0 when truncating the path. And does this get rid of the need of:

                semanage_rtrim(path, '/');

a few lines below your patch?

#7 lore raw
In reply to Joshua Brindle

Updated patch. Need check in two places.

src/genhomedircon.c +9 -0
@@ -304,6 +304,10 @@
 			continue;
 		if (!semanage_list_find(shells, pwbuf->pw_shell))
 			continue;
+		int len = strlen(pwbuf->pw_dir) -1;
+		for(; len > 0 && pwbuf->pw_dir[len] == '/'; len--) {
+			pwbuf->pw_dir[len] = '\0';
+		}
 		if (strcmp(pwbuf->pw_dir, "/") == 0)
 			continue;
 		if (semanage_str_count(pwbuf->pw_dir, '/') <= 1)
@@ -788,6 +792,11 @@
 			continue;
 		}
 
+		int len = strlen(pwent->pw_dir) -1;
+		for(; len > 0 && pwent->pw_dir[len] == '/'; len--) {
+			pwent->pw_dir[len] = '\0';
+		}
+
 		if (strcmp(pwent->pw_dir, "/") == 0) {
 			/* don't relabel / genhomdircon checked to see if root
 			 * was the user and if so, set his home directory to
#8 lore raw
Quoted 1 line · Daniel J Walsh

Updated patch. Need check in two places.

merged in libsemanage 2.0.38

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.