From: Pranav Lawate Date: Tue, 29 Oct 2024 09:57:51 +0000 (+0530) Subject: Added option -a for listing active users only, optimized using if aflg,return X-Git-Tag: 4.17.0~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=205c23bff28f1af3da10d8a5f6bed1fd9724ddb7;p=thirdparty%2Fshadow.git Added option -a for listing active users only, optimized using if aflg,return Signed-off-by: Pranav Lawate --- diff --git a/src/lastlog.c b/src/lastlog.c index 3bd5c62fa..d622ba84e 100644 --- a/src/lastlog.c +++ b/src/lastlog.c @@ -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;