Date: Wed, 9 May 2001 17:20:58 +0100 From: Jamie Heckford <heckfordj@psi-domain.co.uk> To: Peter Pentchev <roam@orbitel.bg> Cc: freebsd-hackers@freebsd.org Subject: Re: bin/27205: Listing all users in the passwd file Message-ID: <20010509172058.E5971@storm.psi-domain.co.uk> In-Reply-To: <20010509173744.F645@ringworld.oblivion.bg>; from roam@orbitel.bg on Wed, May 09, 2001 at 15:37:44 %2B0100 References: <20010508153202.9C4B5402EC6@rafiu.psi-domain.co.uk> <5.1.0.14.2.20010509171743.03e700c0@mail.gothic.net.au> <20010509105612.A4112@storm.psi-domain.co.uk> <20010509173744.F645@ringworld.oblivion.bg>
next in thread | previous in thread | raw e-mail | index | archive | help
Yup, thats the sort of thing I meant. Worthy of a review by any of the commiters? I can remember a big thing going around about modifications to existing programs a couple of weeks ago, this was not intended to upset / annoy / start a flame war anyone! :) Jamie On 2001.05.09 15:37 Peter Pentchev wrote: > I'd think id(1) would be a more proper place, as it already knows how to > format various passwd(5) and group(5) information. > > How about the attached patch? (and I'm probably starting another of > those > bikesheds as to whether new options should be added to existing > utilities..) > > G'luck, > Peter > > -- > This sentence contains exactly threee erors. > > On Wed, May 09, 2001 at 10:56:12AM +0100, Jamie Heckford wrote: > > Good points, glad to see the usual FreeBSD approach of allowing > > only the best into the code ;) > > > > Some sort of wrapper makes perfect sense for the sendmail option - > > I did think of this, but your right, it is best to assume the > > "user-friendly" approach > > and not give users tweaking to do out of the box. > > > > Could be a possibilty of adding it as a switch / option to pw(8), with > > NIS capabilities? (Rewritten in C of course) Would this be deemed > useful > > and anyone happy to review a patch? > [snip] > > > > > > > >I discovered the following awk script that prints out all users on > the > > > system > > > >(from /etc/passwd). (Courtesy of sendmail.org) > > > > > > > >awk -F: '$3 > 100 { print $1 }' /etc/passwd > > > > > > > >Which will print out a list of all users in the passwd file wuth a > UID > > > greater > > > >than 100. > > > > > > > >Could this be turned into a command such as "userlist", and/or would > it > > > be > > > >deemed usefull? > > > > > > Not particularly, as it doesn't work with NIS, and won't work with > > > nsswitch.conf. > > > > > > A small perl script or C program using getpwent() in a loop is more > > > effective, as it takes into account both NIS and nsswitch.conf > > Index: src/usr.bin/id/id.1 > =================================================================== > RCS file: /home/ncvs/src/usr.bin/id/id.1,v > retrieving revision 1.9 > diff -u -r1.9 id.1 > --- src/usr.bin/id/id.1 2000/11/20 19:20:48 1.9 > +++ src/usr.bin/id/id.1 2001/05/09 14:33:53 > @@ -43,21 +43,28 @@ > .Nd return user identity > .Sh SYNOPSIS > .Nm > +.Op Fl a > .Op Ar user > .Nm > -.Fl G Op Fl n > +.Fl G Op Fl an > .Op Ar user > .Nm > .Fl P > +.Op Fl a > .Op Ar user > .Nm > -.Fl g Op Fl nr > +.Fl g > +.Op Fl a | Fl r > +.Op Fl n > .Op Ar user > .Nm > .Fl p > +.Op Fl a > .Op Ar user > .Nm > -.Fl u Op Fl nr > +.Fl u > +.Op Fl a | Fl r > +.Op Fl n > .Op Ar user > .Sh DESCRIPTION > The > @@ -80,6 +87,10 @@ > as white-space separated numbers, in no particular order. > .It Fl P > Display the id as a password file entry. > +.It Fl a > +Display information about all system users, not just about the calling > process. > +This flag cannot be used together with > +.Fl r . > .It Fl g > Display the effective group ID as a number. > .It Fl n > @@ -118,6 +129,8 @@ > and > .Fl u > options instead of the effective ID. > +This flag cannot be used together with > +.Fl a . > .It Fl u > Display the effective user ID as a number. > .El > Index: src/usr.bin/id/id.c > =================================================================== > RCS file: /home/ncvs/src/usr.bin/id/id.c,v > retrieving revision 1.12 > diff -u -r1.12 id.c > --- src/usr.bin/id/id.c 1999/09/06 20:07:12 1.12 > +++ src/usr.bin/id/id.c 2001/05/09 14:33:53 > @@ -55,6 +55,9 @@ > #include <string.h> > #include <unistd.h> > > +int Gflag, Pflag, aflag, gflag, id, nflag, pflag, rflag, uflag; > + > +int id_doit __P((struct passwd *)); > void current __P((void)); > void pline __P((struct passwd *)); > void pretty __P((struct passwd *)); > @@ -69,12 +72,10 @@ > int argc; > char *argv[]; > { > - struct group *gr; > struct passwd *pw; > - int Gflag, Pflag, ch, gflag, id, nflag, pflag, rflag, uflag; > + int ch; > > - Gflag = Pflag = gflag = nflag = pflag = rflag = uflag = 0; > - while ((ch = getopt(argc, argv, "PGgnpru")) != -1) > + while ((ch = getopt(argc, argv, "PGagnpru")) != -1) > switch(ch) { > case 'G': > Gflag = 1; > @@ -82,6 +83,9 @@ > case 'P': > Pflag = 1; > break; > + case 'a': > + aflag = 1; > + break; > case 'g': > gflag = 1; > break; > @@ -104,6 +108,9 @@ > argc -= optind; > argv += optind; > > + if (aflag && (rflag || (argc != 0))) > + usage(); > + > switch(Gflag + Pflag + gflag + pflag + uflag) { > case 1: > break; > @@ -115,7 +122,20 @@ > usage(); > } > > - pw = *argv ? who(*argv) : NULL; > + if (!aflag) { > + pw = *argv ? who(*argv) : NULL; > + id_doit(pw); > + } else { > + while ((pw = getpwent()) != NULL) > + id_doit(pw); > + } > +} > + > +int > +id_doit(pw) > + struct passwd *pw; > +{ > + struct group *gr; > > if (gflag) { > id = pw ? pw->pw_gid : rflag ? getgid() : getegid(); > @@ -123,7 +143,7 @@ > (void)printf("%s\n", gr->gr_name); > else > (void)printf("%u\n", id); > - exit(0); > + return (0); > } > > if (uflag) { > @@ -132,29 +152,29 @@ > (void)printf("%s\n", pw->pw_name); > else > (void)printf("%u\n", id); > - exit(0); > + return (0); > } > > if (Gflag) { > group(pw, nflag); > - exit(0); > + return (0); > } > > if (Pflag) { > pline(pw); > - exit(0); > + return (0); > } > > if (pflag) { > pretty(pw); > - exit(0); > + return (0); > } > > if (pw) > user(pw); > - else > + else if (!aflag) > current(); > - exit(0); > + return (0); > } > > void > > To Unsubscribe: send mail to majordomo@FreeBSD.org > with "unsubscribe freebsd-hackers" in the body of the message > > -- Jamie Heckford Network Operations Manager Psi-Domain - Innovative Linux Solutions. Ask Us How. FreeBSD - The power to serve Join our mailing list and stay informed by emailing majordomo@psi-domain.co.uk with the line: subscribe collective ===================================== email: heckfordj@psi-domain.co.uk web: http://www.psi-domain.co.uk/ tel: +44 (0)1737 789 246 fax: +44 (0)1737 789 245 mobile: +44 (0)7866 724 224 ===================================== To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010509172058.E5971>