bug-sysutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-sysutils] quick patch to fix --gecos processing for lsuser


From: Barry deFreese
Subject: [Bug-sysutils] quick patch to fix --gecos processing for lsuser
Date: Sun, 06 Jun 2004 07:18:47 -0700
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040413 Debian/1.6-5

Hello,

Last night while testing some of the programs I noticed that lsuser wasn't handling --gecos options. Here is a quick and dirty patch to fix that. I have tested it and it works though as usualy I can't say it is the cleanest implementation.

Thanks,

--
Barry deFreese
Debian 3.0r1 "Woody"
GNU/Hurd
Registered Linux "Newbie" #302256 - Hurd H4XX0r wannabe

"Programming today is a race between software engineers striving
to build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots. So far, the Universe is
winning." Rich Cook.



Index: src/lsuser.c
===================================================================
RCS file: /cvsroot/sysutils/sysutils/src/lsuser.c,v
retrieving revision 1.5
diff -u -p -r1.5 lsuser.c
--- src/lsuser.c        5 Jun 2004 14:39:39 -0000       1.5
+++ src/lsuser.c        6 Jun 2004 15:01:18 -0000
@@ -283,6 +283,58 @@ int main(int argc, char *argv[])
                }
        }
 
+       if (args.gecos) {
+               char **attrarray = NULL;
+
+               if (!(attrarray = strsplit(args.gecos, ",", 0))) {
+                       fprintf(stderr,
+                               _("%s: '%s' failed: %s\n"),
+                               progname, "strsplit", strerror(errno));
+                       status = errno;
+                       goto EXIT;
+               }
+
+               for (i = 0; attrarray[i]; i++) {
+                       if (!strcmp(attrarray[i], GS_FNAME)) {
+                               gattr |= G_FNAME;
+                       } else if (!strcmp(attrarray[i], GS_FULLNAME)) {
+                               gattr |= G_FNAME;
+                       } else if (!strcmp(attrarray[i], GS_ROOM)) {
+                               gattr |= G_ROOM;
+                       } else if (!strcmp(attrarray[i], GS_WPHONE)) {
+                               gattr |= G_WPHONE;
+                       } else if (!strcmp(attrarray[i], GS_HPHONE)) {
+                               gattr |= G_HPHONE;
+                       } else if (!strcmp(attrarray[i], GS_OTHER)) {
+                               gattr |= G_OTHER;
+                       } else {
+                               fprintf(stderr,
+                                       _("%s: invalid attributes "
+                                         "for '--gecos'\n"
+                                         "Valid attributes are:\n"
+                                         "- '%s' | '%s'\n"
+                                         "- '%s'\n"
+                                         "- '%s'\n"
+                                         "- '%s'\n"
+                                         "- '%s'\n"
+                                         "Try '%s --help' for more "
+                                         "information.\n"),
+                                       progname,
+                                       GS_FNAME, GS_FULLNAME,
+                                       GS_HPHONE,
+                                       GS_OTHER,
+                                       GS_ROOM,
+                                       GS_WPHONE,
+                                       progname);
+
+                               status = EINVAL;
+                               strfreev(attrarray);
+                               goto EXIT;
+                       }
+               }
+               strfreev(attrarray);
+       }                               
+
        /* There are two alternatives here, neither of which are really
         * pretty; either to read the entire passwd file once to get
         * all usernames, then use them for the ALL list, or to

reply via email to

[Prev in Thread] Current Thread [Next in Thread]