]> granicus.if.org Git - shadow/commitdiff
Merge Debian's patch 412_lastlog_-u_numerical_range
authornekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Wed, 26 Dec 2007 21:54:04 +0000 (21:54 +0000)
committernekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Wed, 26 Dec 2007 21:54:04 +0000 (21:54 +0000)
* NEWS, src/lastlog.c, man/lastlog.8.xml: Accept numerical user, or
  ranges with the -u option.
* TODO: The same change should be done on faillog.

ChangeLog
NEWS
TODO
man/lastlog.8.xml
src/lastlog.c

index 787ebda00d9a2588d495e96bc406c07c84c7dad0..1f12ae14b7805240a1495a094555d4375c2c4eb5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2007-12-26  Nicolas François  <nicolas.francois@centraliens.net>
+
+       Merge Debian's patch 412_lastlog_-u_numerical_range
+       * NEWS, src/lastlog.c, man/lastlog.8.xml: Accept numerical user, or
+       ranges with the -u option.
+
 2007-12-26  Nicolas François  <nicolas.francois@centraliens.net>
 
        Merge Debian's patch 466_fflush-prompt
diff --git a/NEWS b/NEWS
index e6a6870c424d617ec643af672fd5798bd45c0c46..7d9b9b07fb4885348c4d94aeb3a951c4a6c04ed7 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -13,6 +13,9 @@ shadow-4.1.0 -> shadow-4.1.1                                          UNRELEASED
 - su
   * su's arguments are now reordered. If needed, use -- to separate su's
     options from the shell's options.
+- lastlog
+  * Accept users specified as a numerical UID, or ranges of users (-user,
+    user-, user1-user2).
 
 shadow-4.0.18.2 -> shadow-4.1.0                                                09-12-2008
 
diff --git a/TODO b/TODO
index fa65c9ebba9a8b2a21c4dfc72b422a5ae4fc166e..b70031c57377f9dfbe27d57672ae0fa44b8e0754 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,3 +1,6 @@
+faillog
+ - accept numerical user and range of users
+
 Document when/where option appeared, document whether an option is standard
 or not.
 
index 0ab25b9566a6e4f7acd5bd42caebb96cf9191afc..ea6159cde80292ddb21aa0d2fb975df0f222d074 100644 (file)
       <varlistentry>
        <term>
          <option>-u</option>, <option>--user</option>
-         <replaceable>LOGIN</replaceable>
+         <replaceable>LOGIN</replaceable>|<replaceable>RANGE</replaceable>
        </term>
        <listitem>
-         <para>Print the lastlog record for user with specified
-           <emphasis remap='I'>LOGIN</emphasis> only.
+         <para>
+           Print the lastlog record of the specified user(s).
+         </para>
+         <para>
+           The users can be specified by a login name, a numerical user ID,
+           or a <replaceable>RANGE</replaceable> of users. This
+           <replaceable>RANGE</replaceable> of users can be specified with a
+           min and max values (<replaceable>UID_MIN-UID_MAX</replaceable>), a
+           max value (<replaceable>-UID_MAX</replaceable>), or a min value
+           (<replaceable>UID_MIN-</replaceable>).
          </para>
-       </listitem>
-      </varlistentry>
-    </variablelist>
-    <variablelist remap='TP'>
-      <varlistentry>
-       <term>
-         The <option>-t</option> flag overrides the use of <option>-u</option>.
-       </term>
-       <listitem>
-         <para></para>
        </listitem>
       </varlistentry>
     </variablelist>
index 638ce69289386c59045664999165aab0f12aae21..b8e975f788879cb60995b28e105ad1dc1f60b16d 100644 (file)
  * Global variables
  */
 static FILE *lastlogfile;      /* lastlog file stream */
-static off_t user;             /* one single user, specified on command line */
+static long umin;              /* if uflg, only display users with uid >= umin */
+static long umax;              /* if uflg, only display users with uid <= umax */
 static int days;               /* number of days to consider for print command */
 static time_t seconds;         /* that number of days in seconds */
 static int inverse_days;       /* number of days to consider for print command */
 static time_t inverse_seconds; /* that number of days in seconds */
 
 
-static int uflg = 0;           /* set if user is a valid user id */
+static int uflg = 0;           /* print only an user of range of users */
 static int tflg = 0;           /* print is restricted to most recent days */
 static int bflg = 0;           /* print excludes most recent days */
 static struct lastlog lastlog; /* scratch structure to play with ... */
@@ -127,26 +128,14 @@ static void print (void)
 {
        off_t offset;
 
-       if (uflg) {
-               offset = user * sizeof lastlog;
-
-               if (fstat (fileno (lastlogfile), &statbuf)) {
-                       perror (LASTLOG_FILE);
-                       return;
-               }
-               if (offset >= statbuf.st_size)
-                       return;
-
-               fseeko (lastlogfile, offset, SEEK_SET);
-               if (fread ((char *) &lastlog, sizeof lastlog, 1,
-                          lastlogfile) == 1)
-                       print_one (pwent);
-               else
-                       perror (LASTLOG_FILE);
-       } else {
+       {
                setpwent ();
                while ((pwent = getpwent ())) {
                        user = pwent->pw_uid;
+                       if (uflg &&
+                           ((umin != -1 && user < umin) ||
+                            (umax != -1 && user > umax)))
+                               continue;
                        offset = user * sizeof lastlog;
 
                        fseeko (lastlogfile, offset, SEEK_SET);
@@ -199,15 +188,46 @@ int main (int argc, char **argv)
                                bflg++;
                                break;
                        case 'u':
+                               /*
+                                * The user can be:
+                                *  - a login name
+                                *  - numerical
+                                *  - a numerical login ID
+                                *  - a range (-x, x-, x-y)
+                                */
+                               uflg++;
                                pwent = xgetpwnam (optarg);
-                               if (!pwent) {
-                                       fprintf (stderr,
-                                                _("Unknown User: %s\n"),
-                                                optarg);
-                                       exit (1);
+                               if (NULL != pwent) {
+                                       umin = pwent->pw_uid;
+                                       umax = umin;
+                               } else {
+                                       char *endptr = NULL;
+                                       user = strtol(optarg, &endptr, 10);
+                                       if (*optarg != '\0' && *endptr == '\0') {
+                                               if (user < 0) {
+                                                       /* -<userid> */
+                                                       umin = -1;
+                                                       umax = -user;
+                                               } else {
+                                                       /* <userid> */
+                                                       umin = user;
+                                                       umax = user;
+                                               }
+                                       } else if (endptr[0] == '-' && endptr[1] == '\0') {
+                                               /* <userid>- */
+                                               umin = user;
+                                               umax = -1;
+                                       } else if (*endptr == '-') {
+                                               /* <userid>-<userid> */
+                                               umin = user;
+                                               umax = atol(endptr+1);
+                                       } else {
+                                               fprintf (stderr,
+                                                        _("Unknown user or range: %s\n"),
+                                                        optarg);
+                                               exit (1);
+                                       }
                                }
-                               uflg++;
-                               user = pwent->pw_uid;
                                break;
                        default:
                                usage ();