bin/86710: Update bin/ls to have option to cancel -A with super
user
Marcus Alves Grando
mnag at FreeBSD.org
Thu Sep 29 11:20:22 PDT 2005
The following reply was made to PR bin/86710; it has been noted by GNATS.
From: Marcus Alves Grando <mnag at FreeBSD.org>
To: bug-followup at FreeBSD.org, keramida at ceid.upatras.gr
Cc:
Subject: Re: bin/86710: Update bin/ls to have option to cancel -A with super
user
Date: Thu, 29 Sep 2005 15:13:23 -0300
This is a multi-part message in MIME format.
--------------000304070007040709010902
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
New patch attached.
--
Marcus Alves Grando
Grupos Internet S/A
marcus(at)corp.grupos.com.br
mnag(at)FreeBSD.org
--------------000304070007040709010902
Content-Type: text/x-patch;
name="ls.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="ls.patch"
Index: ls.1
===================================================================
RCS file: /home/ncvs/src/bin/ls/ls.1,v
retrieving revision 1.91
diff -u -r1.91 ls.1
--- ls.1 6 Sep 2005 20:14:39 -0000 1.91
+++ ls.1 29 Sep 2005 18:07:47 -0000
@@ -40,7 +40,7 @@
.Nd list directory contents
.Sh SYNOPSIS
.Nm
-.Op Fl ABCFGHLPRSTWZabcdfghiklmnopqrstuwx1
+.Op Fl ABCFGHILPRSTWZabcdfghiklmnopqrstuwx1
.Op Ar
.Sh DESCRIPTION
For each operand that names a
@@ -73,6 +73,8 @@
and
.Pa .. .
Always set for the super-user.
+.Fl I
+cancel this option.
.It Fl B
Force printing of non-printable characters (as defined by
.Xr ctype 3
@@ -117,6 +119,12 @@
or
.Fl l
options are specified.
+.It Fl I
+This option cancels the
+.Fl A
+option. Usually used by super user when
+.Fl A
+is not necessary.
.It Fl L
If argument is a symbolic link, list the file or directory the link references
rather than the link itself.
Index: ls.c
===================================================================
RCS file: /home/ncvs/src/bin/ls/ls.c,v
retrieving revision 1.80
diff -u -r1.80 ls.c
--- ls.c 3 Jun 2005 11:05:58 -0000 1.80
+++ ls.c 29 Sep 2005 18:07:47 -0000
@@ -110,6 +110,8 @@
static int f_kblocks; /* print size in kilobytes */
static int f_listdir; /* list actual directory, not contents */
static int f_listdot; /* list files beginning with . */
+static int f_nolistdot; /* don't list files beginning with . */
+static int f_forcelistdot; /* force list files beginning with . */
int f_longform; /* long listing format */
int f_nonprint; /* show unprintables as ? */
static int f_nosort; /* don't sort output */
@@ -175,13 +177,9 @@
termwidth = atoi(p);
}
- /* Root is -A automatically. */
- if (!getuid())
- f_listdot = 1;
-
fts_options = FTS_PHYSICAL;
while ((ch = getopt(argc, argv,
- "1ABCFGHLPRSTWZabcdfghiklmnopqrstuwx")) != -1) {
+ "1ABCFGHILPRSTWZabcdfghiklmnopqrstuwx")) != -1) {
switch (ch) {
/*
* The -1, -C, -x and -l options all override each other so
@@ -243,10 +241,14 @@
break;
case 'a':
fts_options |= FTS_SEEDOT;
- /* FALLTHROUGH */
+ f_forcelistdot = 1;
+ break;
case 'A':
f_listdot = 1;
break;
+ case 'I':
+ f_nolistdot = 1;
+ break;
/* The -d option turns off the -R option. */
case 'd':
f_listdir = 1;
@@ -326,6 +328,10 @@
argc -= optind;
argv += optind;
+ /* Root is -A automatically. */
+ if (getuid() == 0 && f_nolistdot != 1)
+ f_listdot = 1;
+
/* Enabling of colours is conditional on the environment. */
if (getenv("CLICOLOR") &&
(isatty(STDOUT_FILENO) || getenv("CLICOLOR_FORCE")))
@@ -350,7 +356,7 @@
#endif /*COLORLS*/
#ifdef COLORLS
- if (f_color) {
+ if (f_color == 1) {
/*
* We can't put tabs and color sequences together:
* column number will be incremented incorrectly
@@ -368,10 +374,10 @@
* information, unless in color mode in which case we do
* need this to determine which colors to display.
*/
- if (!f_inode && !f_longform && !f_size && !f_timesort &&
- !f_sizesort && !f_type
+ if (f_inode != 1 && f_longform != 1 && f_size != 1
+ && f_timesort != 1 && f_sizesort != 1 && f_type != 1
#ifdef COLORLS
- && !f_color
+ && f_color != 1
#endif
)
fts_options |= FTS_NOSTAT;
@@ -380,20 +386,20 @@
* If not -F, -d or -l options, follow any symbolic links listed on
* the command line.
*/
- if (!f_longform && !f_listdir && !f_type)
+ if (f_longform != 1 && f_listdir != 1 && f_type != 1)
fts_options |= FTS_COMFOLLOW;
/*
* If -W, show whiteout entries
*/
#ifdef FTS_WHITEOUT
- if (f_whiteout)
+ if (f_whiteout == 1)
fts_options |= FTS_WHITEOUT;
#endif
/* If -l or -s, figure out block size. */
- if (f_longform || f_size) {
- if (f_kblocks)
+ if (f_longform == 1 || f_size == 1) {
+ if (f_kblocks == 1)
blocksize = 2;
else {
(void)getbsize(¬used, &blocksize);
@@ -401,36 +407,36 @@
}
}
/* Select a sort function. */
- if (f_reversesort) {
- if (!f_timesort && !f_sizesort)
+ if (f_reversesort == 1) {
+ if (f_timesort != 1 && f_sizesort != 1)
sortfcn = revnamecmp;
- else if (f_accesstime)
+ else if (f_accesstime == 1)
sortfcn = revacccmp;
- else if (f_statustime)
+ else if (f_statustime == 1)
sortfcn = revstatcmp;
- else if (f_sizesort)
+ else if (f_sizesort == 1)
sortfcn = revsizecmp;
else /* Use modification time. */
sortfcn = revmodcmp;
} else {
- if (!f_timesort && !f_sizesort)
+ if (f_timesort != 1 && f_sizesort != 1)
sortfcn = namecmp;
- else if (f_accesstime)
+ else if (f_accesstime == 1)
sortfcn = acccmp;
- else if (f_statustime)
+ else if (f_statustime == 1)
sortfcn = statcmp;
- else if (f_sizesort)
+ else if (f_sizesort == 1)
sortfcn = sizecmp;
else /* Use modification time. */
sortfcn = modcmp;
}
/* Select a print function. */
- if (f_singlecol)
+ if (f_singlecol == 1)
printfcn = printscol;
- else if (f_longform)
+ else if (f_longform == 1)
printfcn = printlong;
- else if (f_stream)
+ else if (f_stream == 1)
printfcn = printstream;
else
printfcn = printcol;
@@ -468,7 +474,7 @@
chp = fts_children(ftsp, 0);
if (chp != NULL)
display(NULL, chp, options);
- if (f_listdir)
+ if (f_listdir == 1)
return;
/*
@@ -490,7 +496,8 @@
break;
case FTS_D:
if (p->fts_level != FTS_ROOTLEVEL &&
- p->fts_name[0] == '.' && !f_listdot)
+ p->fts_name[0] == '.' && ((f_listdot != 1 ||
+ f_nolistdot == 1) && f_forcelistdot != 1))
break;
/*
@@ -510,7 +517,7 @@
chp = fts_children(ftsp, ch_options);
display(p, chp, options);
- if (!f_recursive && chp != NULL)
+ if (f_recursive != 1 && chp != NULL)
(void)fts_set(ftsp, p, FTS_SKIP);
break;
default:
@@ -615,7 +622,7 @@
maxlabelstr = 0;
/* FALLTHROUGH */
#ifdef COLORLS
- if (!f_color)
+ if (f_color != 1)
#endif
f_notabs = 0;
/* FALLTHROUGH */
@@ -644,20 +651,21 @@
*/
if (p == NULL) {
/* Directories will be displayed later. */
- if (cur->fts_info == FTS_D && !f_listdir) {
+ if (cur->fts_info == FTS_D && f_listdir != 1) {
cur->fts_number = NO_PRINT;
continue;
}
} else {
/* Only display dot file if -a/-A set. */
- if (cur->fts_name[0] == '.' && !f_listdot) {
+ if (cur->fts_name[0] == '.' && ((f_listdot != 1 ||
+ f_nolistdot == 1) && f_forcelistdot != 1)) {
cur->fts_number = NO_PRINT;
continue;
}
}
if (cur->fts_namelen > maxlen)
maxlen = cur->fts_namelen;
- if (f_octal || f_octal_escape) {
+ if (f_octal == 1 || f_octal_escape == 1) {
u_long t = len_octal(cur->fts_name, cur->fts_namelen);
if (t > maxlen)
@@ -675,8 +683,8 @@
maxsize = sp->st_size;
btotal += sp->st_blocks;
- if (f_longform) {
- if (f_numericonly) {
+ if (f_longform == 1) {
+ if (f_numericonly == 1) {
(void)snprintf(nuser, sizeof(nuser),
"%u", sp->st_uid);
(void)snprintf(ngroup, sizeof(ngroup),
@@ -691,7 +699,7 @@
maxuser = ulen;
if ((glen = strlen(group)) > maxgroup)
maxgroup = glen;
- if (f_flags) {
+ if (f_flags == 1) {
flags = fflagstostr(sp->st_flags);
if (flags != NULL && *flags == '\0') {
free(flags);
@@ -705,7 +713,7 @@
} else
flen = 0;
labelstr = NULL;
- if (f_label) {
+ if (f_label == 1) {
char name[PATH_MAX + 1];
mac_t label;
int error;
@@ -772,12 +780,12 @@
S_ISBLK(sp->st_mode))
bcfile = 1;
- if (f_flags) {
+ if (f_flags == 1) {
np->flags = &np->data[ulen + glen + 2];
(void)strcpy(np->flags, flags);
free(flags);
}
- if (f_label) {
+ if (f_label == 1) {
np->label = &np->data[ulen + glen + 2
+ (f_flags ? flen + 1 : 0)];
(void)strcpy(np->label, labelstr);
@@ -820,7 +828,7 @@
printfcn(&d);
output = 1;
- if (f_longform)
+ if (f_longform == 1)
for (cur = list; cur; cur = cur->fts_link)
free(cur->fts_pointer);
}
--------------000304070007040709010902--
More information about the freebsd-bugs
mailing list