]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/group-record-show.c
Merge pull request #16690 from poettering/userdb-group-desc
[thirdparty/systemd.git] / src / shared / group-record-show.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2
3 #include "format-util.h"
4 #include "group-record-show.h"
5 #include "strv.h"
6 #include "user-util.h"
7 #include "userdb.h"
8
9 void group_record_show(GroupRecord *gr, bool show_full_user_info) {
10 int r;
11
12 printf(" Group name: %s\n",
13 group_record_group_name_and_realm(gr));
14
15 printf(" Disposition: %s\n", user_disposition_to_string(group_record_disposition(gr)));
16
17 if (gr->last_change_usec != USEC_INFINITY) {
18 char buf[FORMAT_TIMESTAMP_MAX];
19 printf(" Last Change: %s\n", format_timestamp(buf, sizeof(buf), gr->last_change_usec));
20 }
21
22 if (gid_is_valid(gr->gid))
23 printf(" GID: " GID_FMT "\n", gr->gid);
24
25 if (show_full_user_info) {
26 _cleanup_(userdb_iterator_freep) UserDBIterator *iterator = NULL;
27
28 r = membershipdb_by_group(gr->group_name, 0, &iterator);
29 if (r < 0) {
30 errno = -r;
31 printf(" Members: (can't acquire: %m)");
32 } else {
33 const char *prefix = " Members:";
34
35 for (;;) {
36 _cleanup_free_ char *user = NULL;
37
38 r = membershipdb_iterator_get(iterator, &user, NULL);
39 if (r == -ESRCH)
40 break;
41 if (r < 0) {
42 errno = -r;
43 printf("%s (can't iterate: %m\n", prefix);
44 break;
45 }
46
47 printf("%s %s\n", prefix, user);
48 prefix = " ";
49 }
50 }
51 } else {
52 const char *prefix = " Members:";
53 char **i;
54
55 STRV_FOREACH(i, gr->members) {
56 printf("%s %s\n", prefix, *i);
57 prefix = " ";
58 }
59 }
60
61 if (!strv_isempty(gr->administrators)) {
62 const char *prefix = " Admins:";
63 char **i;
64
65 STRV_FOREACH(i, gr->administrators) {
66 printf("%s %s\n", prefix, *i);
67 prefix = " ";
68 }
69 }
70
71 if (gr->description && !streq(gr->description, gr->group_name))
72 printf(" Description: %s\n", gr->description);
73
74 if (!strv_isempty(gr->hashed_password))
75 printf(" Passwords: %zu\n", strv_length(gr->hashed_password));
76
77 if (gr->service)
78 printf(" Service: %s\n", gr->service);
79 }