]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared: merge {user,group}-record-show.[ch]
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 28 Aug 2020 15:11:46 +0000 (17:11 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 1 Sep 2020 08:48:03 +0000 (10:48 +0200)
It is natural to include both, and in total they declared three
functions. Let's merge them for simplicity.

src/shared/group-record-show.c [deleted file]
src/shared/group-record-show.h [deleted file]
src/shared/meson.build
src/shared/user-record-show.c
src/shared/user-record-show.h
src/userdb/userdbctl.c

diff --git a/src/shared/group-record-show.c b/src/shared/group-record-show.c
deleted file mode 100644 (file)
index 8b59f91..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-/* SPDX-License-Identifier: LGPL-2.1+ */
-
-#include "format-util.h"
-#include "group-record-show.h"
-#include "strv.h"
-#include "user-util.h"
-#include "userdb.h"
-
-void group_record_show(GroupRecord *gr, bool show_full_user_info) {
-        int r;
-
-        printf("  Group name: %s\n",
-               group_record_group_name_and_realm(gr));
-
-        printf(" Disposition: %s\n", user_disposition_to_string(group_record_disposition(gr)));
-
-        if (gr->last_change_usec != USEC_INFINITY) {
-                char buf[FORMAT_TIMESTAMP_MAX];
-                printf(" Last Change: %s\n", format_timestamp(buf, sizeof(buf), gr->last_change_usec));
-        }
-
-        if (gid_is_valid(gr->gid))
-                printf("         GID: " GID_FMT "\n", gr->gid);
-
-        if (show_full_user_info) {
-                _cleanup_(userdb_iterator_freep) UserDBIterator *iterator = NULL;
-
-                r = membershipdb_by_group(gr->group_name, 0, &iterator);
-                if (r < 0) {
-                        errno = -r;
-                        printf("     Members: (can't acquire: %m)");
-                } else {
-                        const char *prefix = "     Members:";
-
-                        for (;;) {
-                                _cleanup_free_ char *user = NULL;
-
-                                r = membershipdb_iterator_get(iterator, &user, NULL);
-                                if (r == -ESRCH)
-                                        break;
-                                if (r < 0) {
-                                        errno = -r;
-                                        printf("%s (can't iterate: %m\n", prefix);
-                                        break;
-                                }
-
-                                printf("%s %s\n", prefix, user);
-                                prefix = "             ";
-                        }
-                }
-        } else {
-                const char *prefix = "     Members:";
-                char **i;
-
-                STRV_FOREACH(i, gr->members) {
-                        printf("%s %s\n", prefix, *i);
-                        prefix = "             ";
-                }
-        }
-
-        if (!strv_isempty(gr->administrators)) {
-                const char *prefix = "      Admins:";
-                char **i;
-
-                STRV_FOREACH(i, gr->administrators) {
-                        printf("%s %s\n", prefix, *i);
-                        prefix = "             ";
-                }
-        }
-
-        if (gr->description && !streq(gr->description, gr->group_name))
-                printf(" Description: %s\n", gr->description);
-
-        if (!strv_isempty(gr->hashed_password))
-                printf("   Passwords: %zu\n", strv_length(gr->hashed_password));
-
-        if (gr->service)
-                printf("     Service: %s\n", gr->service);
-}
diff --git a/src/shared/group-record-show.h b/src/shared/group-record-show.h
deleted file mode 100644 (file)
index 12bdbd1..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-/* SPDX-License-Identifier: LGPL-2.1+ */
-#pragma once
-
-#include "group-record.h"
-
-void group_record_show(GroupRecord *gr, bool show_full_user_info);
index 38762f020ee3c7d8ddd1cc01dd0a35ab4d48c817..c149ff4cd8047cca37f7855159de9fa34a751f46 100644 (file)
@@ -115,8 +115,6 @@ shared_sources = files('''
         gpt.h
         group-record-nss.c
         group-record-nss.h
-        group-record-show.c
-        group-record-show.h
         group-record.c
         group-record.h
         id128-print.c
index 551df720ba840e794d8ec9214f84f92b1a9c80ac..33787c083f571f0d1448733008d1ad2fe73d08b4 100644 (file)
@@ -2,7 +2,6 @@
 
 #include "format-util.h"
 #include "fs-util.h"
-#include "group-record.h"
 #include "process-util.h"
 #include "rlimit-util.h"
 #include "strv.h"
@@ -506,3 +505,75 @@ void user_record_show(UserRecord *hr, bool show_full_group_info) {
         if (hr->service)
                 printf("     Service: %s\n", hr->service);
 }
+
+void group_record_show(GroupRecord *gr, bool show_full_user_info) {
+        int r;
+
+        printf("  Group name: %s\n",
+               group_record_group_name_and_realm(gr));
+
+        printf(" Disposition: %s\n", user_disposition_to_string(group_record_disposition(gr)));
+
+        if (gr->last_change_usec != USEC_INFINITY) {
+                char buf[FORMAT_TIMESTAMP_MAX];
+                printf(" Last Change: %s\n", format_timestamp(buf, sizeof(buf), gr->last_change_usec));
+        }
+
+        if (gid_is_valid(gr->gid))
+                printf("         GID: " GID_FMT "\n", gr->gid);
+
+        if (show_full_user_info) {
+                _cleanup_(userdb_iterator_freep) UserDBIterator *iterator = NULL;
+
+                r = membershipdb_by_group(gr->group_name, 0, &iterator);
+                if (r < 0) {
+                        errno = -r;
+                        printf("     Members: (can't acquire: %m)");
+                } else {
+                        const char *prefix = "     Members:";
+
+                        for (;;) {
+                                _cleanup_free_ char *user = NULL;
+
+                                r = membershipdb_iterator_get(iterator, &user, NULL);
+                                if (r == -ESRCH)
+                                        break;
+                                if (r < 0) {
+                                        errno = -r;
+                                        printf("%s (can't iterate: %m\n", prefix);
+                                        break;
+                                }
+
+                                printf("%s %s\n", prefix, user);
+                                prefix = "             ";
+                        }
+                }
+        } else {
+                const char *prefix = "     Members:";
+                char **i;
+
+                STRV_FOREACH(i, gr->members) {
+                        printf("%s %s\n", prefix, *i);
+                        prefix = "             ";
+                }
+        }
+
+        if (!strv_isempty(gr->administrators)) {
+                const char *prefix = "      Admins:";
+                char **i;
+
+                STRV_FOREACH(i, gr->administrators) {
+                        printf("%s %s\n", prefix, *i);
+                        prefix = "             ";
+                }
+        }
+
+        if (gr->description && !streq(gr->description, gr->group_name))
+                printf(" Description: %s\n", gr->description);
+
+        if (!strv_isempty(gr->hashed_password))
+                printf("   Passwords: %zu\n", strv_length(gr->hashed_password));
+
+        if (gr->service)
+                printf("     Service: %s\n", gr->service);
+}
index bd22be2ae04ad6b284896e8b166ba0d4f93d2f86..4dcee180a2d42158b14a8e3c10058eaecc95fc46 100644 (file)
@@ -2,7 +2,9 @@
 #pragma once
 
 #include "user-record.h"
+#include "group-record.h"
 
 const char *user_record_state_color(const char *state);
 
 void user_record_show(UserRecord *hr, bool show_full_group_info);
+void group_record_show(GroupRecord *gr, bool show_full_user_info);
index 12c6943ebd7f2d9be1bfa6c8d3c9c98ed2908417..0e3204f932af650f314b53fa4e362682cd6741ca 100644 (file)
@@ -8,7 +8,6 @@
 #include "fd-util.h"
 #include "format-table.h"
 #include "format-util.h"
-#include "group-record-show.h"
 #include "main-func.h"
 #include "pager.h"
 #include "parse-util.h"