[dev] [sbase] S_ISVTX patches

2013-10-20 Thread Markus Wichmann
Hi all,

as previously threatened, here are some git patches. Hope that helps.

Ciao,
Markus
From dfe485c4298aa8572f7534e19336b682239d0879 Mon Sep 17 00:00:00 2001
From: Markus Wichmann nullp...@gmx.net
Date: Sun, 20 Oct 2013 10:49:59 +0200
Subject: [PATCH 1/4] Make mkdir read mode argument as octal.

---
 mkdir.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mkdir.c b/mkdir.c
index 8080797..781654a 100644
--- a/mkdir.c
+++ b/mkdir.c
@@ -30,7 +30,7 @@ main(int argc, char *argv[])
 		break;
 	case 'm':
 		mflag = true;
-		mode = estrtol(EARGF(usage()), 10);
+		mode = estrtol(EARGF(usage()), 8);
 		break;
 	default:
 		usage();
-- 
1.8.4.rc3

From 40cf23698c688972e072f5352af7def861caa327 Mon Sep 17 00:00:00 2001
From: Markus Wichmann nullp...@gmx.net
Date: Sun, 20 Oct 2013 10:50:58 +0200
Subject: [PATCH 2/4] Make chmod honor S_ISVTX.

---
 chmod.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/chmod.c b/chmod.c
index 6d0f8a7..1af3f45 100644
--- a/chmod.c
+++ b/chmod.c
@@ -95,6 +95,7 @@ parsemode(const char *str)
 	if(*end == '\0') {
 		if(octal  04000) mode |= S_ISUID;
 		if(octal  02000) mode |= S_ISGID;
+if(octal  01000) mode |= S_ISVTX;
 		if(octal  00400) mode |= S_IRUSR;
 		if(octal  00200) mode |= S_IWUSR;
 		if(octal  00100) mode |= S_IXUSR;
@@ -140,6 +141,9 @@ parsemode(const char *str)
 		case 's':
 			mode |= S_ISUID|S_ISGID;
 			break;
+case 't':
+mode |= S_ISVTX;
+break;
 		/* error */
 		default:
 			eprintf(%s: invalid mode\n, str);
-- 
1.8.4.rc3

From cd2c8a254aa18b020fa499c509d981a49401ee65 Mon Sep 17 00:00:00 2001
From: Markus Wichmann nullp...@gmx.net
Date: Sun, 20 Oct 2013 10:53:43 +0200
Subject: [PATCH 3/4] Make chmod and ls recognize sticky bit (S_ISVTX).

---
 chmod.c | 4 ++--
 ls.c| 1 +
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/chmod.c b/chmod.c
index 1af3f45..74c8700 100644
--- a/chmod.c
+++ b/chmod.c
@@ -31,9 +31,9 @@ main(int argc, char *argv[])
 			case 'R':
 rflag = true;
 break;
-			case 'r': case 'w': case 'x': case 's':
+case 'r': case 'w': case 'x': case 's': case 't':
 /*
- * -[rwxs] are valid modes so do not interpret
+ * -[rwxst] are valid modes so do not interpret
  * them as options - in any case we are done if
  * we hit this case
  */
diff --git a/ls.c b/ls.c
index af1336d..c5eae89 100644
--- a/ls.c
+++ b/ls.c
@@ -228,6 +228,7 @@ output(Entry *ent)
 
 	if(ent-mode  S_ISUID) mode[3] = (mode[3] == 'x') ? 's' : 'S';
 	if(ent-mode  S_ISGID) mode[6] = (mode[6] == 'x') ? 's' : 'S';
+if(ent-mode  S_ISVTX) mode[9] = (mode[9] == 'x') ? 't' : 'T';
 
 	errno = 0;
 	pw = getpwuid(ent-uid);
-- 
1.8.4.rc3

From a0749cdc82e5fc55e7feba70c081ad3a42684beb Mon Sep 17 00:00:00 2001
From: Markus Wichmann nullp...@gmx.net
Date: Sun, 20 Oct 2013 10:56:49 +0200
Subject: [PATCH 4/4] Add sticky bit to documentation.

---
 chmod.1 | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/chmod.1 b/chmod.1
index 579aa68..4deb792 100644
--- a/chmod.1
+++ b/chmod.1
@@ -9,7 +9,7 @@ chmod \- change file mode
 .P
 .B chmod
 .RB [ \-r ]
-.RB [ ugoa ]*[ +-= ][ rwxs ]*
+.RB [ ugoa ]*[ +-= ][ rwxst ]*
 .RI [ file ...]
 .SH DESCRIPTION
 .B chmod
@@ -18,7 +18,7 @@ changes the file mode for the given files.
 If the mode is an
 .I octal
 number, the modes are set according to that number's comprising bits. The first
-digit defines the setuid (4) and setgid (2) attributes.  The second digit
+digit defines the setuid (4), setgid (2), and sticky (1) attributes.  The second digit
 defines the owner's permissions: read (4), write (2), and execute (1); the third
 defines permissions for others in the file's group; and the fourth for all other
 users. Leading zeroes may be omitted.
@@ -62,6 +62,9 @@ execute permissions.
 .TP
 .B s
 setuid and setgid attributes.
+.TP
+.B t
+sticky attribute.
 .PD
 .SH OPTIONS
 .TP
-- 
1.8.4.rc3



Re: [dev] [sbase] S_ISVTX patches

2013-10-20 Thread sin
On Sun, Oct 20, 2013 at 11:11:21AM +0200, Markus Wichmann wrote:
 Hi all,
 
 as previously threatened, here are some git patches. Hope that helps.

Applied, thanks.

In the future please use tabs instead of spaces (I've manually fixed
your patches for now).

Thanks,
sin



Re: [dev] [sbase] S_ISVTX?

2013-10-19 Thread sin
On Fri, Oct 18, 2013 at 11:49:07PM +0200, Markus Wichmann wrote:
 Hi all,
 
 Now my question: Does someone here have a personal vendetta against
 S_ISVTX?

Not me, unless anyone objects, feel free to send in some patches.

Thanks,
sin



[dev] [sbase] S_ISVTX?

2013-10-18 Thread Markus Wichmann
Hi all,

on an unrelated note: mkdir's mode argument is read in as a decimal
number and applied directly to chmod. Are you sure we want that?
Especially with chmod's and ls' use of the symbolic constants?

Also on an unrelated note: Are there really systems out there that don't
define those symbolic mode bits to the usual definitions?

Now my question: Does someone here have a personal vendetta against
S_ISVTX? I ask, because chmod will silently drop tries to set it via
number and will error on trying to set it via symbol. The commit history
for chmod shows that one commit after the initial one removed that flag,
but not why that was done, and the mailing list archive from around that
time for that author are not helpful, either.

Also ls refuses to display the sticky bit even if it is set.

Really, code to handle that is not that big (it's three lines for chmod
and one line for ls) and as it stands, it's a security risk for me
(because I certainly don't expect /tmp to have mode 0777 after I typed
in 'chmod 1777 /tmp'.  Yes, I know /tmp sucks balls through a straw, but
the fact is that programs are using /tmp and I don't want to repair
every single one I come across.) Also, it takes three preprocessor
directives to make the change transparent to systems that don't offer
the S_ISVTX bit.

So, is there a reason for this particular omission?

Ciao,
Markus