Re: Too powerful rmdir

2009-08-11 Thread Bob Proulx
zhoulai...@melix wrote:
> I suppose this is a designing issue or a bug:

Thanks for the report.  But the behavior you describe is not a bug but
simply a misunderstanding.

> You can remove an empty directory as you like, even if you don't have the
> right to read, write nor execute:

The permissions of the parent directory control whether you can remove
a file from within it.  The permissions of the file being removed are
not the controlling factor.  (And a directory is just a special file
and follows the same rules.)

> f...@ubuntu:~/Unix_Tutorial_8/5$ mkdir test
> f...@ubuntu:~/Unix_Tutorial_8/5$ ls -l
> total 4
> drwxr-xr-x 2 fu fu 4096 2009-08-12 06:39 test

You made the directory in '.' and so therefore we know that '.' allows
you to modify (create or destroy) contents in it.

> f...@ubuntu:~/Unix_Tutorial_8/5$ chmod ugo-rwx test/
> f...@ubuntu:~/Unix_Tutorial_8/5$ ls -l
> total 4
> d- 2 fu fu 4096 2009-08-12 06:39 test

The permissions on that target file are not a controlling factor in
whether you can remove it from its parent directory.  The permissions
on the parent directory control whether you can create or remove files
from the parent directory.

> f...@ubuntu:~/Unix_Tutorial_8/5$ rmdir test
> f...@ubuntu:~/Unix_Tutorial_8/5$ ls -l
> total 0
> f...@ubuntu:~/Unix_Tutorial_8/5$

All correct.  And I am compelled to note that this is all as per
traditional unix filesystem behavior for 40 years.

If you want to prevent a file from being removed (or created) then you
must remove write permission from the directory containing it.

Try this:

  $ mkdir test
  $ chmod a-w .
  $ rmdir test
  rmdir: failed to remove `test': Permission denied

In any case, even if this wasn't so, it is the kernel that enforces
permissions *not* an individual userspace command.  Otherwise all it
would take to circumvent the permissions would be to use perl.

  perl -e 'rmdir("somedir");unlink("somefile");'

Bob




Re: [PATCH] ls: Use pretty UTF-8 arrow when showing where symlinks point to

2009-08-11 Thread Lennart Poettering
On Tue, 11.08.09 22:27, Pádraig Brady (p...@draigbrady.com) wrote:

> this is equivalent I think:
> 
>static const char *arrow = " -> ";
> #ifdef HAVE_NL_LANGINFO
>if (fancy_chars && STREQ (nl_langinfo (CODESET), "UTF-8"))
>  arrow = " \xe2\x86\x92 ";
> #endif
>DIRED_FPUTS_LITERAL (arrow, stdout);

You evaluate the whole expression on every iteration. The whole point
of making this variable static is to make sure this isn't necessary.

Lennart

-- 
Lennart PoetteringRed Hat, Inc.
lennart [at] poettering [dot] net
http://0pointer.net/lennart/   GnuPG 0x1A015CC4




Too powerful rmdir

2009-08-11 Thread zhoulai...@melix
Hello,

I suppose this is a designing issue or a bug:

You can remove an empty directory as you like, even if you don't have the
right to read, write nor execute:

f...@ubuntu:~/Unix_Tutorial_8/5$ mkdir test
f...@ubuntu:~/Unix_Tutorial_8/5$ ls -l
total 4
drwxr-xr-x 2 fu fu 4096 2009-08-12 06:39 test
f...@ubuntu:~/Unix_Tutorial_8/5$ chmod ugo-rwx test/
f...@ubuntu:~/Unix_Tutorial_8/5$ ls -l
total 4
d- 2 fu fu 4096 2009-08-12 06:39 test
f...@ubuntu:~/Unix_Tutorial_8/5$ rmdir test
f...@ubuntu:~/Unix_Tutorial_8/5$ ls -l
total 0
f...@ubuntu:~/Unix_Tutorial_8/5$



-- 
Zhoulai FU

Ecole Polytechnique (X-2005)
Telecom Paris (2010)


Re: [PATCH] ls: Use pretty UTF-8 arrow when showing where symlinks point to

2009-08-11 Thread Pádraig Brady
Lennart Poettering wrote:
> [Second version of the patch, makes this feature optional with --fancy-chars]

--fancy-chars :)
I'm not sure how serious this patch is.
How about:

alias lsf='ls -l --color | sed "s/ -> / $(tput bold)\u25aa\u25b6$(tput sgr0) /"'

cheers,
Pádraig.

p.s. this chunk is far too verbose

> +#ifdef HAVE_NL_LANGINFO
> +   static const char *arrow = NULL;
> +
> +   if (!arrow)
> + {
> +   arrow = " -> ";
> +
> +   if (fancy_chars)
> + {
> +   const char *cs;
> +   cs = nl_langinfo(CODESET);
> +
> +   if (cs && strcmp(cs, "UTF-8") == 0)
> + arrow = " \xe2\x86\x92 ";
> + }
> + }
> +   DIRED_FPUTS_LITERAL (arrow, stdout);
> +#else
> DIRED_FPUTS_LITERAL (" -> ", stdout);
> +#endif

this is equivalent I think:

   static const char *arrow = " -> ";
#ifdef HAVE_NL_LANGINFO
   if (fancy_chars && STREQ (nl_langinfo (CODESET), "UTF-8"))
 arrow = " \xe2\x86\x92 ";
#endif
   DIRED_FPUTS_LITERAL (arrow, stdout);





[PATCH] ls: Use pretty UTF-8 arrow when showing where symlinks point to

2009-08-11 Thread Lennart Poettering
[Second version of the patch, makes this feature optional with --fancy-chars]

Diego Pettenò complained that "ls -l" doesn't use the UTF-8 arrow
character to show where symlinks point to. This tiny patch fixes that.
With this applied the character is used when the CODESET is UTF-8
otherwise we fall back to the traditional "->" arrow.

This is only enabled if --fancy-chars is passed as argument.

Ah, "ls -l" is so much prettier now!

For verification:

http://pastie.org/573270

---
 src/ls.c |   33 +
 1 files changed, 33 insertions(+), 0 deletions(-)

diff --git a/src/ls.c b/src/ls.c
index 07e9cf1..0d5be7c 100644
--- a/src/ls.c
+++ b/src/ls.c
@@ -496,6 +496,11 @@ static enum indicator_style const indicator_style_types[] =
 };
 ARGMATCH_VERIFY (indicator_style_args, indicator_style_types);
 
+/* Use fancy Unicode characters in output. At this point this simply
+   replaces the -> arrow for symlinks by a real Unicode arrow. */
+
+static bool fancy_chars;
+
 /* True means use colors to mark types.  Also define the different
colors as well as the stuff for the LS_COLORS environment variable.
The LS_COLORS variable is now in a termcap-like format.  */
@@ -758,6 +763,7 @@ enum
   AUTHOR_OPTION = CHAR_MAX + 1,
   BLOCK_SIZE_OPTION,
   COLOR_OPTION,
+  FANCY_CHARS_OPTION,
   DEREFERENCE_COMMAND_LINE_SYMLINK_TO_DIR_OPTION,
   FILE_TYPE_INDICATOR_OPTION,
   FORMAT_OPTION,
@@ -813,6 +819,7 @@ static struct option const long_options[] =
   {"time", required_argument, NULL, TIME_OPTION},
   {"time-style", required_argument, NULL, TIME_STYLE_OPTION},
   {"color", optional_argument, NULL, COLOR_OPTION},
+  {"fancy-chars", no_argument, NULL, FANCY_CHARS_OPTION},
   {"block-size", required_argument, NULL, BLOCK_SIZE_OPTION},
   {"context", no_argument, 0, 'Z'},
   {"author", no_argument, NULL, AUTHOR_OPTION},
@@ -1522,6 +1529,7 @@ decode_switches (int argc, char **argv)
   ignore_patterns = NULL;
   hide_patterns = NULL;
   print_scontext = false;
+  fancy_chars = false;
 
   /* FIXME: put this in a function.  */
   {
@@ -1866,6 +1874,10 @@ decode_switches (int argc, char **argv)
break;
  }
 
+   case FANCY_CHARS_OPTION:
+ fancy_chars = true;
+ break;
+
case INDICATOR_STYLE_OPTION:
  indicator_style = XARGMATCH ("--indicator-style", optarg,
   indicator_style_args,
@@ -3749,7 +3761,26 @@ print_long_format (const struct fileinfo *f)
 {
   if (f->linkname)
{
+#ifdef HAVE_NL_LANGINFO
+ static const char *arrow = NULL;
+
+ if (!arrow)
+   {
+ arrow = " -> ";
+
+ if (fancy_chars)
+   {
+ const char *cs;
+ cs = nl_langinfo(CODESET);
+
+ if (cs && strcmp(cs, "UTF-8") == 0)
+   arrow = " \xe2\x86\x92 ";
+   }
+   }
+ DIRED_FPUTS_LITERAL (arrow, stdout);
+#else
  DIRED_FPUTS_LITERAL (" -> ", stdout);
+#endif
  print_name_with_quoting (f->linkname, f->linkmode, f->linkok - 1,
   f->stat_ok, f->filetype, NULL,
   f->stat.st_nlink, (p - buf) + w + 4);
@@ -4533,6 +4564,8 @@ Mandatory arguments to long options are mandatory for 
short options too.\n\
   -C list entries by columns\n\
   --color[=WHEN] control whether color is used to distinguish 
file\n\
types.  WHEN may be `never', `always', or 
`auto'\n\
+  --fancy-chars  control whether fancy Unicode characters may be\n\
+   used in the output.\n\
   -d, --directorylist directory entries instead of contents,\n\
and do not dereference symbolic links\n\
   -D, --diredgenerate output designed for Emacs' dired mode\n\
-- 
1.6.4



Lennart

-- 
Lennart PoetteringRed Hat, Inc.
lennart [at] poettering [dot] net ICQ# 11060553
http://0pointer.net/lennart/   GnuPG 0x1A015CC4




Re: chmod feature request: setting different modes for files and directories

2009-08-11 Thread Andreas Schwab
Pádraig Brady  writes:

> Tobia Conforto wrote:
>> The same is true when someone
>> extracts some files from an archive or copies them over a removable
>> media, where permissions need to be reset to something sane, like 755/644:
>> 
>
> current:  chmod -R 755 another/path; find another/path -type f -exec chmod 
> 644 {} +

current: find another/path -type f -exec chmod 644 {} + -o type d -exec chmod 
755 {} +

> proposed: chmod -R d:755,f:644 another/path
>
> This case is more valid as it would be faster since you'd be traversing
> the branch only once.

Also only one traverse with find (which is more flexible here as well).

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."




Re: chmod feature request: setting different modes for files and directories

2009-08-11 Thread Pádraig Brady
Tobia Conforto wrote:
> Dear coreutils maintainers,
> 
> I'd like to ask for an often needed feature of chmod: the ability to set
> different modes for files and directories. I will briefly explain the
> need, and then propose a possible syntax.
> 

current:  find some/path -type d -exec chmod g+s {} +
proposed: chmod -R d:g+s some/path

I think the find syntax is more general/known/standardized.
So I don't think this use case warrants the change.

> The same is true when someone
> extracts some files from an archive or copies them over a removable
> media, where permissions need to be reset to something sane, like 755/644:
> 

current:  chmod -R 755 another/path; find another/path -type f -exec chmod 644 
{} +
proposed: chmod -R d:755,f:644 another/path

This case is more valid as it would be faster since you'd be traversing
the branch only once. Though again it's more syntax.
TBH I never use chmod -R (or grep -R etc.) and always use
the more general `find`.

So I'd not be inclined to make this change.

cheers,
Pádraig.