From pckizer@nostrum.com Wed Jul 28 23:14:57 1999
Return-Path: <pckizer@nostrum.com>
Received: from hermit.bcs.nostrum.com (hermit.bcs.nostrum.com [206.28.8.2])
	by hub.freebsd.org (Postfix) with ESMTP id ED38215570
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 28 Jul 1999 23:14:49 -0700 (PDT)
	(envelope-from pckizer@nostrum.com)
Received: (from pckizer@localhost)
	by hermit.bcs.nostrum.com (8.9.3/8.9.3) id BAA05429;
	Thu, 29 Jul 1999 01:14:10 -0500 (CDT)
Message-Id: <199907290614.BAA05429@hermit.bcs.nostrum.com>
Date: Thu, 29 Jul 1999 01:14:10 -0500 (CDT)
From: pckizer@nostrum.com
Reply-To: pckizer@nostrum.com
To: FreeBSD-gnats-submit@freebsd.org
Subject: [PATCH] RFE for /bin/ls to add a -n option for showing uid/gid numerically
X-Send-Pr-Version: 3.2

>Number:         12866
>Category:       bin
>Synopsis:       [PATCH] RFE for /bin/ls to add a -n option for showing uid/gid numerically
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    sheldonh
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Wed Jul 28 23:20:00 PDT 1999
>Closed-Date:    Tue Aug 8 05:10:21 PDT 2000
>Last-Modified:  Tue Aug 08 05:12:25 PDT 2000
>Originator:     Philip Kizer
>Release:        FreeBSD 3.2-STABLE i386
>Organization:
Texas A&M University
>Environment:

        FreeBSD hermit.bcs.nostrum.com 3.2-STABLE FreeBSD 3.2-STABLE #0: Wed Jul 28 15:40:30 CDT 1999     root@hermit.bcs.nostrum.com:/opt/src/system/src/sys/compile/Hermit  i386

>Description:

I am familiar with having a '-n' option to /bin/ls on other platforms (i.e.
Solaris/Linux/IRIX/etc) to print uid/gid information numerically in long
(-l) listings rather than performing username/groupname lookups.  I was
unable to find any similar option to /bin/ls or similar programs.  (Unless
I just completely overlooked it).

>How-To-Repeat:

No similar option found on FreeBSD, other OSs output similar to:
% ls -ldn
drwxr-x--x    9 1179     100         4096 Jul 29 00:53 .

>Fix:

Determine if my patch is acceptable, as given, or in concept; and apply in
/usr/src/bin/ls:

--- ls.c-old	Wed Jul 28 15:16:56 1999
+++ ls.c	Wed Jul 28 16:11:55 1999
@@ -100,6 +100,7 @@
 int f_timesort;			/* sort by time vice name */
 int f_type;			/* add type character for non-regular files */
 int f_whiteout;			/* show whiteout entries */
+int f_numbers;			/* show uid/gid numbers rather than names */
 
 int rval;
 
@@ -137,7 +138,7 @@
 		f_listdot = 1;
 
 	fts_options = FTS_PHYSICAL;
-	while ((ch = getopt(argc, argv, "1ABCFHLPRTWabcdfgikloqrstu")) != -1) {
+	while ((ch = getopt(argc, argv, "1ABCFHLPRTWabcdfgiklnoqrstu")) != -1) {
 		switch (ch) {
 		/*
 		 * The -1, -C and -l options all override each other so shell
@@ -209,6 +210,9 @@
 		case 'k':
 			f_kblocks = 1;
 			break;
+		case 'n':
+			f_numbers = 1;
+			break;
 		case 'o':
 			f_flags = 1;
 			break;
@@ -401,6 +405,7 @@
 	char *initmax;
 	int entries, needstats;
 	char *user, *group, *flags, buf[20];	/* 32 bits == 10 digits */
+	char user_num[8], group_num[8];
 
 	/*
 	 * If list is NULL there are two possibilities: that the parent
@@ -512,10 +517,19 @@
 
 			btotal += sp->st_blocks;
 			if (f_longform) {
-				user = user_from_uid(sp->st_uid, 0);
+				if (f_numbers) {
+					snprintf(user_num, sizeof(user_num),
+					    "%d", sp->st_uid);
+					user = user_num;
+					snprintf(group_num, sizeof(group_num),
+					    "%d", sp->st_gid);
+					group = user_num;
+				} else {
+					user = user_from_uid(sp->st_uid, 0);
+					group = group_from_gid(sp->st_gid, 0);
+				}
 				if ((ulen = strlen(user)) > maxuser)
 					maxuser = ulen;
-				group = group_from_gid(sp->st_gid, 0);
 				if ((glen = strlen(group)) > maxgroup)
 					maxgroup = glen;
 				if (f_flags) {


>Release-Note:
>Audit-Trail:

From: Nick Hibma <nick.hibma@jrc.it>
To: pckizer@nostrum.com
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: bin/12866: [PATCH] RFE for /bin/ls to add a -n option for showing uid/gid numerically
Date: Thu, 29 Jul 1999 09:34:00 +0200 (MET DST)

 A good reason for implementing this:  Try to do an ls -l on a local disk
 when the NIS server is down. 
 
 
 
Responsible-Changed-From-To: freebsd-bugs->sheldonh 
Responsible-Changed-By: sheldonh 
Responsible-Changed-When: Thu Jul 29 10:14:30 PDT 1999 
Responsible-Changed-Why:  
I'll take this one. There are a couple of nits, so I'll post back 
a revised patch for your enjoyment. 

From: Doug <Doug@gorean.org>
To: pckizer@nostrum.com
Cc: FreeBSD-gnats-submit@freebsd.org
Subject: Re: bin/12866: [PATCH] RFE for /bin/ls to add a -n option for showing 
 uid/gid numerically
Date: Thu, 29 Jul 1999 14:31:26 -0700

 pckizer@nostrum.com wrote:
 
 > I am familiar with having a '-n' option to /bin/ls on other platforms 
 
 	I'm very much in favor of adding this option, thank you for taking the
 time to code it. My one suggestion would be that you optimize the code
 slightly for the most likely case, namely that the -n option has not been
 specified. 
 
 
 > +                          if (!f_numbers) {
 > +                                  user = user_from_uid(sp->st_uid, 0);
 > +                                  group = group_from_gid(sp->st_gid, 0);
 > +                           } else {
 > +                                   snprintf(user_num, sizeof(user_num),
 > +                                       "%d", sp->st_uid);
 > +                                   user = user_num;
 > +                                   snprintf(group_num, sizeof(group_num),
 > +                                       "%d", sp->st_gid);
 > +                                   group = user_num;
 > +                           }
 
 Hope this helps,
 
 Doug
 

From: Sheldon Hearn <sheldonh@uunet.co.za>
To: Mike Pritchard <mpp@mpp.pro-ns.net>
Cc: freebsd-gnats-submit@freebsd.org
Subject: Re: bin/12866: [PATCH] RFE for /bin/ls to add a -n option for showing uid/gid numerically 
Date: Fri, 30 Jul 1999 02:36:43 +0200

 On Thu, 29 Jul 1999 18:05:49 EST, Mike Pritchard wrote:
 
 > If NetBSD or OpenBSD implement the -n option, we should probably just
 > incorporate their program and man page changes instead of cooking up
 > our own.
 
 Both platforms support -n, both in different ways. I'll use their
 variable names, no problem. In OpenBSD, -n implies -l, which is stupid.
 NetBSD is more sensible.
 
 I only want -n to have an effect when -l is specified, so that I can do
 
 alias ls='ls -n'
 
 When I do ``ls -l'' I'll get long listings with numeric user and group
 columns. Otherwise, I'll get short listings as normal.
 
 I'll copy NetBSD. Thanks for the tip.
 
 Ciao,
 Sheldon.
 
State-Changed-From-To: open->suspended 
State-Changed-By: sheldonh 
State-Changed-When: Mon Aug 2 07:58:42 PDT 1999 
State-Changed-Why:  
Committed to HEAD, MFC should probably be held off until Bruce's 
concerns are addressed. 

From: Bruce Evans <bde@zeta.org.au>
To: sheldonh@uunet.co.za
Cc:  
Subject: Re: bin/12866: [PATCH] RFE for /bin/ls to add a -n option for showing uid/gid numerically
Date: Fri, 30 Jul 1999 10:45:54 +1000

 >Alright, here's a patch for your perusal. It differs from yours in that:
 >
 >	* Variables have been renamed.
  	...
 
 I see a few more problems.
 
 >RCS file: /home/ncvs/src/bin/ls/ls.c,v
 >retrieving revision 1.24
 >diff -u -d -r1.24 ls.c
 >--- ls.c	1999/05/08 10:20:30	1.24
 >+++ ls.c	1999/07/29 17:32:51
 >@@ -100,6 +100,7 @@
 > int f_timesort;			/* sort by time vice name */
 > int f_type;			/* add type character for non-regular files */
 > int f_whiteout;			/* show whiteout entries */
 >+int f_numnames;			/* show numeric uid and gid in long listing */
 
 Disorder.
 
 >@@ -401,6 +405,7 @@
 > 	char *initmax;
 > 	int entries, needstats;
 > 	char *user, *group, *flags, buf[20];	/* 32 bits == 10 digits */
 >+	char uid[10], gid[10];
 
 Disorder.  char variables not grouped together.  At least the arrays should
 be.  The comment for buf[] applies more directly to the new arrays.  You
 shouldn't assume that uid_t is 32 bits.
 
 >@@ -512,10 +517,19 @@
 > 
 > 			btotal += sp->st_blocks;
 > 			if (f_longform) {
 >-				user = user_from_uid(sp->st_uid, 0);
 >+				if (f_numnames) {
 >+					snprintf(uid, sizeof(uid), "%u",
 >+					    sp->st_uid);
 >+					user = uid;
 >+					snprintf(gid, sizeof(gid), "%u",
 >+					    sp->st_gid);
 >+					group = gid;
 
 snprintf() returns a value which is always ignored.  It is explicitly
 (void)ed elsewhere.  This is not the way to use snprintf.  Either ensure
 that the buffer is large enough, and don't use snprintf, or size the
 buffer sloppily and check that it was large enough using snprintf and
 handle the error somehow.
 
 Bruce
 
 
State-Changed-From-To: suspended->analyzed 
State-Changed-By: sheldonh 
State-Changed-When: Thu Aug 19 05:27:24 PDT 1999 
State-Changed-Why:  
The style issues have been addressed. This one's an MFC candidate, once 
it's had a little time in CURRENT. 

From: Sheldon Hearn <sheldonh@uunet.co.za>
To: freebsd-gnats-submit@freebsd.org
Cc:  
Subject: Re: bin/12866: /bin/ls -n and -l
Date: Fri, 24 Dec 1999 12:56:14 +0200

 Just some feedback.  I've filed a defect report with the OpenGroup
 people in which I propose that -n, -g and -o should not imply -l.  When
 we get feedback from them, we'll go with the standard, whatever they
 decide.
 
 Ciao,
 Sheldon.
 
State-Changed-From-To: analyzed->closed 
State-Changed-By: sheldonh 
State-Changed-When: Tue Aug 8 05:10:21 PDT 2000 
State-Changed-Why:  
My Open Group report went nowhere.  Since ls(1) is not recommended 
as a source for reliable input in portable shell scripts, and 
since our ls(1) already deviates from the standards, I'm closing 
this PR and leaving the behaviour as is. 

The documentation aspect of this issue will be addressed when my 
standards documentation project gets off the ground, probably 
after BSDcon. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=12866 
>Unformatted:
