]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lslogins: add -y,--shell
authorKarel Zak <kzak@redhat.com>
Mon, 14 Feb 2022 12:58:30 +0000 (13:58 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 14 Feb 2022 12:58:30 +0000 (13:58 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
login-utils/lslogins.1.adoc
login-utils/lslogins.c

index dd9033668febb6713c7f87cf223098d35a6e4f7f..5d3111252a6f6ae50eb2dd6c311f00e2ffb7b25f 100644 (file)
@@ -38,7 +38,7 @@ Alternate path for btmp.
 Separate info about each user with a colon instead of a newline.
 
 *-e*, *--export*::
-Output data in the format of NAME=VALUE.
+Output data in the format of NAME=VALUE. See also option *--shell*.
 
 *-f*, *--failed*::
 Display data about the users' last failed login attempts.
@@ -95,6 +95,9 @@ Alternate path for wtmp.
 *--lastlog* _path_::
 Alternate path for *lastlog*(8).
 
+*y-*, *--shell*::
+The column name will be modified to contain only characters allowed for shell variable identifiers. This is usable, for example, with *--export*. Note that this feature has been automatically enabled for *--export* in version 2.37, but due to compatibility issues, now it's necessary to request this behavior by *--shell*.
+
 *-Z*, *--context*::
 Display the users' security context.
 
index 132046cbf405e477ffd76d76ad9d3b11794d477e..4a1c62fe9d553b1afd0ab87168bacce62f5b3857 100644 (file)
@@ -281,6 +281,7 @@ struct lslogins_control {
        unsigned int selinux_enabled : 1,
                     fail_on_unknown : 1,               /* fail if user does not exist */
                     ulist_on : 1,
+                    shellvar : 1,
                     noheadings : 1,
                     notrunc : 1;
 };
@@ -1072,6 +1073,8 @@ static struct libscols_table *setup_table(struct lslogins_control *ctl)
                err(EXIT_FAILURE, _("failed to allocate output table"));
        if (ctl->noheadings)
                scols_table_enable_noheadings(table, 1);
+       if (ctl->shellvar)
+               scols_table_enable_shellvar(table, 1);
 
        switch(outmode) {
        case OUT_COLON:
@@ -1420,6 +1423,7 @@ static void __attribute__((__noreturn__)) usage(void)
        fputs(_(" -s, --system-accs        display system accounts\n"), out);
        fputs(_("     --time-format=<type> display dates in short, full or iso format\n"), out);
        fputs(_(" -u, --user-accs          display user accounts\n"), out);
+       fputs(_(" -y, --shell              use column names to be usable as shell variable identifiers\n"), out);
        fputs(_(" -Z, --context            display SELinux contexts\n"), out);
        fputs(_(" -z, --print0             delimit user entries with a nul character\n"), out);
        fputs(_("     --wtmp-file <path>   set an alternate path for wtmp\n"), out);
@@ -1460,6 +1464,7 @@ int main(int argc, char *argv[])
                { "acc-expiration", no_argument,        0, 'a' },
                { "colon-separate", no_argument,        0, 'c' },
                { "export",         no_argument,        0, 'e' },
+               { "shell",          no_argument,        0, 'y' },
                { "failed",         no_argument,        0, 'f' },
                { "groups",         required_argument,  0, 'g' },
                { "help",           no_argument,        0, 'h' },
@@ -1509,7 +1514,7 @@ int main(int argc, char *argv[])
        add_column(columns, ncolumns++, COL_UID);
        add_column(columns, ncolumns++, COL_USER);
 
-       while ((c = getopt_long(argc, argv, "acefGg:hLl:no:prsuVzZ",
+       while ((c = getopt_long(argc, argv, "acefGg:hLl:no:prsuVyzZ",
                                longopts, NULL)) != -1) {
 
                err_exclusive_options(c, longopts, excl, excl_st);
@@ -1585,6 +1590,9 @@ int main(int argc, char *argv[])
                        add_column(columns, ncolumns++, COL_HUSH_STATUS);
                        add_column(columns, ncolumns++, COL_PWDMETHOD);
                        break;
+               case 'y':
+                       ctl->shellvar = 1;
+                       break;
                case 'z':
                        outmode = OUT_NUL;
                        break;