]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
Added option -a for listing active users only, optimized using if aflg,return
authorPranav Lawate <plawate@plawate-thinkpadp1gen4i.pnq.csb>
Tue, 29 Oct 2024 09:57:51 +0000 (15:27 +0530)
committerSerge Hallyn <serge@hallyn.com>
Tue, 10 Dec 2024 03:04:21 +0000 (21:04 -0600)
Signed-off-by: Pranav Lawate <pran.lawate@gmail.com>
src/lastlog.c

index 3bd5c62fafaeddbcc82b7913a6970b4de831d5b2..d622ba84e7453ecf006db43be768a21239ffe805 100644 (file)
@@ -61,6 +61,7 @@ static bool tflg = false;     /* print is restricted to most recent days */
 static bool bflg = false;      /* print excludes most recent days */
 static bool Cflg = false;      /* clear record for user */
 static bool Sflg = false;      /* set record for user */
+static bool aflg = false;      /* print only users that have logged in */
 
 #define        NOW     time(NULL)
 
@@ -81,6 +82,7 @@ usage (int status)
        (void) fputs (_("  -S, --set                     set lastlog record to current time (usable only with -u)\n"), usageout);
        (void) fputs (_("  -t, --time DAYS               print only lastlog records more recent than DAYS\n"), usageout);
        (void) fputs (_("  -u, --user LOGIN              print lastlog record of the specified LOGIN\n"), usageout);
+       (void) fputs (_("  -a, --active                  print lastlog excluding '**Never logged in**' users"), usageout);
        (void) fputs ("\n", usageout);
        exit (status);
 }
@@ -165,6 +167,9 @@ static void print_one (/*@null@*/const struct passwd *pw)
                cp = ptime;
        }
        if (ll.ll_time == (time_t) 0) {
+               /* If aflg is used,i.e aflag=true omit the 'Never logged in' lines */
+               if (aflg)
+                       return;
                cp = _("**Never logged in**\0");
        }
 
@@ -319,10 +324,11 @@ int main (int argc, char **argv)
                        {"set",    no_argument,       NULL, 'S'},
                        {"time",   required_argument, NULL, 't'},
                        {"user",   required_argument, NULL, 'u'},
+                       {"active", no_argument,       NULL, 'a'},
                        {NULL, 0, NULL, '\0'}
                };
 
-               while ((c = getopt_long (argc, argv, "b:ChR:St:u:", longopts,
+               while ((c = getopt_long (argc, argv, "b:ChR:St:u:a", longopts,
                                         NULL)) != -1) {
                        switch (c) {
                        case 'b':
@@ -396,6 +402,11 @@ int main (int argc, char **argv)
                                }
                                break;
                        }
+                       case 'a':
+                       {
+                               aflg = true;
+                               break;
+                       }
                        default:
                                usage (EXIT_FAILURE);
                                /*@notreached@*/break;