| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
|
| 3 |
#include "alloc-util.h" |
| 4 |
#include "capability-list.h" |
| 5 |
#include "capability-util.h" |
| 6 |
#include "format-util.h" |
| 7 |
#include "glyph-util.h" |
| 8 |
#include "hashmap.h" |
| 9 |
#include "hexdecoct.h" |
| 10 |
#include "path-util.h" |
| 11 |
#include "percent-util.h" |
| 12 |
#include "pretty-print.h" |
| 13 |
#include "process-util.h" |
| 14 |
#include "rlimit-util.h" |
| 15 |
#include "sha256.h" |
| 16 |
#include "string-util.h" |
| 17 |
#include "strv.h" |
| 18 |
#include "time-util.h" |
| 19 |
#include "user-record.h" |
| 20 |
#include "group-record.h" |
| 21 |
#include "user-record-show.h" |
| 22 |
#include "user-util.h" |
| 23 |
#include "userdb.h" |
| 24 |
|
| 25 |
const char* user_record_state_color(const char *state) { |
| 26 |
if (STR_IN_SET(state, "unfixated", "absent")) |
| 27 |
return ansi_grey(); |
| 28 |
else if (streq(state, "active")) |
| 29 |
return ansi_highlight_green(); |
| 30 |
else if (STR_IN_SET(state, "locked", "dirty")) |
| 31 |
return ansi_highlight_yellow(); |
| 32 |
|
| 33 |
return NULL; |
| 34 |
} |
| 35 |
|
| 36 |
static void show_self_modifiable( |
| 37 |
const char *heading, |
| 38 |
char **field, |
| 39 |
const char **value) { |
| 40 |
|
| 41 |
assert(heading); |
| 42 |
|
| 43 |
/* Helper function for printing the various self_modifiable_* fields from the user record */ |
| 44 |
|
| 45 |
if (!value) |
| 46 |
/* Case 1: no value is set and no default either */ |
| 47 |
printf("%13s %snone%s\n", heading, ansi_highlight(), ansi_normal()); |
| 48 |
else if (strv_isempty((char**) value)) |
| 49 |
/* Case 2: the array is explicitly set to empty by the administrator */ |
| 50 |
printf("%13s %sdisabled by administrator%s\n", heading, ansi_highlight_red(), ansi_normal()); |
| 51 |
else if (!field) |
| 52 |
/* Case 3: we have values, but the field is NULL. This means that we're using the defaults. |
| 53 |
* We list them anyways, because they're security-sensitive to the administrator */ |
| 54 |
STRV_FOREACH(i, value) |
| 55 |
printf("%13s %s%s%s\n", i == value ? heading : "", ansi_grey(), *i, ansi_normal()); |
| 56 |
else |
| 57 |
/* Case 4: we have a list provided by the administrator */ |
| 58 |
STRV_FOREACH(i, value) |
| 59 |
printf("%13s %s\n", i == value ? heading : "", *i); |
| 60 |
} |
| 61 |
|
| 62 |
static void show_tmpfs_limit(const char *tmpfs, const TmpfsLimit *limit, uint32_t scale) { |
| 63 |
assert(tmpfs); |
| 64 |
assert(limit); |
| 65 |
|
| 66 |
if (!limit->is_set) |
| 67 |
return; |
| 68 |
|
| 69 |
printf(" %s Limit:", tmpfs); |
| 70 |
|
| 71 |
if (limit->limit != UINT64_MAX) |
| 72 |
printf(" %s", FORMAT_BYTES(limit->limit)); |
| 73 |
if (limit->limit == UINT64_MAX || limit->limit_scale != UINT32_MAX) { |
| 74 |
if (limit->limit != UINT64_MAX) |
| 75 |
printf(" or"); |
| 76 |
|
| 77 |
printf(" %i%%", UINT32_SCALE_TO_PERCENT(scale)); |
| 78 |
} |
| 79 |
printf("\n"); |
| 80 |
} |
| 81 |
|
| 82 |
void user_record_show(UserRecord *hr, bool show_full_group_info) { |
| 83 |
_cleanup_strv_free_ char **langs = NULL; |
| 84 |
const char *hd, *ip, *shell; |
| 85 |
UserStorage storage; |
| 86 |
usec_t t; |
| 87 |
size_t k; |
| 88 |
int r, b; |
| 89 |
|
| 90 |
printf(" User name: %s\n", |
| 91 |
user_record_user_name_and_realm(hr)); |
| 92 |
|
| 93 |
if (!strv_isempty(hr->aliases)) { |
| 94 |
STRV_FOREACH(i, hr->aliases) |
| 95 |
printf(i == hr->aliases ? |
| 96 |
" Alias: %s" : ", %s", *i); |
| 97 |
putchar('\n'); |
| 98 |
} |
| 99 |
|
| 100 |
if (hr->state) { |
| 101 |
const char *color; |
| 102 |
|
| 103 |
color = user_record_state_color(hr->state); |
| 104 |
|
| 105 |
printf(" State: %s%s%s\n", |
| 106 |
strempty(color), hr->state, color ? ansi_normal() : ""); |
| 107 |
} |
| 108 |
|
| 109 |
printf(" Disposition: %s\n", user_disposition_to_string(user_record_disposition(hr))); |
| 110 |
|
| 111 |
if (hr->last_change_usec != USEC_INFINITY) { |
| 112 |
printf(" Last Change: %s\n", FORMAT_TIMESTAMP(hr->last_change_usec)); |
| 113 |
|
| 114 |
if (hr->last_change_usec > now(CLOCK_REALTIME)) |
| 115 |
printf(" %sModification time lies in the future, system clock wrong?%s\n", |
| 116 |
ansi_highlight_yellow(), ansi_normal()); |
| 117 |
} |
| 118 |
|
| 119 |
if (hr->last_password_change_usec != USEC_INFINITY && |
| 120 |
hr->last_password_change_usec != hr->last_change_usec) |
| 121 |
printf(" Last Passw.: %s\n", FORMAT_TIMESTAMP(hr->last_password_change_usec)); |
| 122 |
|
| 123 |
r = user_record_test_blocked(hr); |
| 124 |
switch (r) { |
| 125 |
|
| 126 |
case -ENOLCK: |
| 127 |
printf(" Login OK: %sno%s (record is locked)\n", ansi_highlight_red(), ansi_normal()); |
| 128 |
break; |
| 129 |
|
| 130 |
case -EL2HLT: |
| 131 |
printf(" Login OK: %sno%s (record not valid yet))\n", ansi_highlight_red(), ansi_normal()); |
| 132 |
break; |
| 133 |
|
| 134 |
case -EL3HLT: |
| 135 |
printf(" Login OK: %sno%s (record not valid anymore))\n", ansi_highlight_red(), ansi_normal()); |
| 136 |
break; |
| 137 |
|
| 138 |
case -ESTALE: |
| 139 |
default: { |
| 140 |
usec_t y; |
| 141 |
|
| 142 |
if (r < 0 && r != -ESTALE) { |
| 143 |
errno = -r; |
| 144 |
printf(" Login OK: %sno%s (%m)\n", ansi_highlight_red(), ansi_normal()); |
| 145 |
break; |
| 146 |
} |
| 147 |
|
| 148 |
if (is_nologin_shell(user_record_shell(hr))) { |
| 149 |
printf(" Login OK: %sno%s (nologin shell)\n", ansi_highlight_red(), ansi_normal()); |
| 150 |
break; |
| 151 |
} |
| 152 |
|
| 153 |
y = user_record_ratelimit_next_try(hr); |
| 154 |
if (y != USEC_INFINITY && y > now(CLOCK_REALTIME)) { |
| 155 |
printf(" Login OK: %sno%s (ratelimit)\n", ansi_highlight_red(), ansi_normal()); |
| 156 |
break; |
| 157 |
} |
| 158 |
|
| 159 |
printf(" Login OK: %syes%s\n", ansi_highlight_green(), ansi_normal()); |
| 160 |
}} |
| 161 |
|
| 162 |
r = user_record_test_password_change_required(hr); |
| 163 |
switch (r) { |
| 164 |
|
| 165 |
case -EKEYREVOKED: |
| 166 |
printf(" Password OK: %schange now%s\n", ansi_highlight_yellow(), ansi_normal()); |
| 167 |
break; |
| 168 |
|
| 169 |
case -EOWNERDEAD: |
| 170 |
printf(" Password OK: %sexpired%s (change now!)\n", ansi_highlight_yellow(), ansi_normal()); |
| 171 |
break; |
| 172 |
|
| 173 |
case -EKEYREJECTED: |
| 174 |
printf(" Password OK: %sexpired%s (for good)\n", ansi_highlight_red(), ansi_normal()); |
| 175 |
break; |
| 176 |
|
| 177 |
case -EKEYEXPIRED: |
| 178 |
printf(" Password OK: %sexpires soon%s\n", ansi_highlight_yellow(), ansi_normal()); |
| 179 |
break; |
| 180 |
|
| 181 |
case -ENETDOWN: |
| 182 |
printf(" Password OK: %sno timestamp%s\n", ansi_highlight_red(), ansi_normal()); |
| 183 |
break; |
| 184 |
|
| 185 |
case -EROFS: |
| 186 |
printf(" Password OK: %schange not permitted%s\n", ansi_highlight_yellow(), ansi_normal()); |
| 187 |
break; |
| 188 |
|
| 189 |
case -ESTALE: |
| 190 |
printf(" Password OK: %slast password change in future%s\n", ansi_highlight_yellow(), ansi_normal()); |
| 191 |
break; |
| 192 |
|
| 193 |
default: |
| 194 |
if (r < 0) { |
| 195 |
errno = -r; |
| 196 |
printf(" Password OK: %sno%s (%m)\n", ansi_highlight_yellow(), ansi_normal()); |
| 197 |
break; |
| 198 |
} |
| 199 |
|
| 200 |
if (strv_isempty(hr->hashed_password)) { |
| 201 |
if (hr->incomplete) /* Record might be incomplete, due to privs */ |
| 202 |
break; |
| 203 |
printf(" Password OK: %sno%s (none set)\n", ansi_highlight(), ansi_normal()); |
| 204 |
break; |
| 205 |
} |
| 206 |
if (strv_contains(hr->hashed_password, "")) { |
| 207 |
printf(" Password OK: %sno%s (empty set)\n", ansi_highlight_red(), ansi_normal()); |
| 208 |
break; |
| 209 |
} |
| 210 |
bool has_valid_passwords = false; |
| 211 |
STRV_FOREACH(p, hr->hashed_password) |
| 212 |
if (!hashed_password_is_locked_or_invalid(*p)) { |
| 213 |
has_valid_passwords = true; |
| 214 |
break; |
| 215 |
} |
| 216 |
if (has_valid_passwords) |
| 217 |
printf(" Password OK: %syes%s\n", ansi_highlight_green(), ansi_normal()); |
| 218 |
else |
| 219 |
printf(" Password OK: %sno%s (locked)\n", ansi_highlight(), ansi_normal()); |
| 220 |
} |
| 221 |
if (uid_is_valid(hr->uid)) |
| 222 |
printf(" UID: " UID_FMT "\n", hr->uid); |
| 223 |
if (gid_is_valid(user_record_gid(hr))) { |
| 224 |
if (show_full_group_info) { |
| 225 |
_cleanup_(group_record_unrefp) GroupRecord *gr = NULL; |
| 226 |
|
| 227 |
r = groupdb_by_gid(user_record_gid(hr), /* match= */ NULL, /* flags= */ 0, &gr); |
| 228 |
if (r < 0) { |
| 229 |
errno = -r; |
| 230 |
printf(" GID: " GID_FMT " (unresolvable: %m)\n", user_record_gid(hr)); |
| 231 |
} else |
| 232 |
printf(" GID: " GID_FMT " (%s)\n", user_record_gid(hr), gr->group_name); |
| 233 |
} else |
| 234 |
printf(" GID: " GID_FMT "\n", user_record_gid(hr)); |
| 235 |
} else if (uid_is_valid(hr->uid)) /* Show UID as GID if not separately configured */ |
| 236 |
printf(" GID: " GID_FMT "\n", (gid_t) hr->uid); |
| 237 |
|
| 238 |
if (show_full_group_info) { |
| 239 |
_cleanup_(userdb_iterator_freep) UserDBIterator *iterator = NULL; |
| 240 |
|
| 241 |
r = membershipdb_by_user(hr->user_name, 0, &iterator); |
| 242 |
if (r < 0) { |
| 243 |
errno = -r; |
| 244 |
printf(" Aux. Groups: (can't acquire: %m)\n"); |
| 245 |
} else { |
| 246 |
const char *prefix = " Aux. Groups:"; |
| 247 |
|
| 248 |
for (;;) { |
| 249 |
_cleanup_free_ char *group = NULL; |
| 250 |
|
| 251 |
r = membershipdb_iterator_get(iterator, NULL, &group); |
| 252 |
if (r == -ESRCH) |
| 253 |
break; |
| 254 |
if (r < 0) { |
| 255 |
errno = -r; |
| 256 |
printf("%s (can't iterate: %m)\n", prefix); |
| 257 |
break; |
| 258 |
} |
| 259 |
|
| 260 |
printf("%s %s\n", prefix, group); |
| 261 |
prefix = " "; |
| 262 |
} |
| 263 |
} |
| 264 |
} |
| 265 |
|
| 266 |
if (!sd_id128_is_null(hr->uuid)) |
| 267 |
printf(" UUID: " SD_ID128_UUID_FORMAT_STR "\n", SD_ID128_FORMAT_VAL(hr->uuid)); |
| 268 |
|
| 269 |
if (hr->real_name && !streq(hr->real_name, hr->user_name)) |
| 270 |
printf(" Real Name: %s\n", hr->real_name); |
| 271 |
|
| 272 |
hd = user_record_home_directory(hr); |
| 273 |
if (hd) { |
| 274 |
printf(" Directory: %s", hd); |
| 275 |
|
| 276 |
if (hr->fallback_home_directory && hr->use_fallback) |
| 277 |
printf(" %s(fallback)%s", ansi_highlight_yellow(), ansi_normal()); |
| 278 |
|
| 279 |
printf("\n"); |
| 280 |
} |
| 281 |
|
| 282 |
if (hr->default_area) |
| 283 |
printf("Default Area: %s\n", hr->default_area); |
| 284 |
|
| 285 |
if (hr->blob_directory) { |
| 286 |
_cleanup_free_ char **filenames = NULL; |
| 287 |
size_t n_filenames = 0; |
| 288 |
|
| 289 |
r = hashmap_dump_keys_sorted(hr->blob_manifest, (void***) &filenames, &n_filenames); |
| 290 |
if (r < 0) { |
| 291 |
errno = -r; |
| 292 |
printf(" Blob Dir.: %s (can't iterate: %m)\n", hr->blob_directory); |
| 293 |
} else |
| 294 |
printf(" Blob Dir.: %s\n", hr->blob_directory); |
| 295 |
|
| 296 |
for (size_t i = 0; i < n_filenames; i++) { |
| 297 |
_cleanup_free_ char *path = NULL, *link = NULL, *hash = NULL; |
| 298 |
const char *filename = filenames[i]; |
| 299 |
const uint8_t *hash_bytes = hashmap_get(hr->blob_manifest, filename); |
| 300 |
bool last = i == n_filenames - 1; |
| 301 |
|
| 302 |
path = path_join(hr->blob_directory, filename); |
| 303 |
if (path) |
| 304 |
(void) terminal_urlify_path(path, filename, &link); |
| 305 |
hash = hexmem(hash_bytes, SHA256_DIGEST_SIZE); |
| 306 |
|
| 307 |
printf(" %s %s %s(%s)%s\n", |
| 308 |
glyph(last ? GLYPH_TREE_RIGHT : GLYPH_TREE_BRANCH), |
| 309 |
link ?: filename, |
| 310 |
ansi_grey(), |
| 311 |
hash ?: "can't display hash", |
| 312 |
ansi_normal()); |
| 313 |
} |
| 314 |
} |
| 315 |
|
| 316 |
storage = user_record_storage(hr); |
| 317 |
if (storage >= 0) /* Let's be political, and clarify which storage we like, and which we don't. About CIFS we don't complain. */ |
| 318 |
printf(" Storage: %s%s\n", user_storage_to_string(storage), |
| 319 |
storage == USER_LUKS ? " (strong encryption)" : |
| 320 |
storage == USER_FSCRYPT ? " (weak encryption)" : |
| 321 |
IN_SET(storage, USER_DIRECTORY, USER_SUBVOLUME) ? " (no encryption)" : ""); |
| 322 |
|
| 323 |
ip = user_record_image_path(hr); |
| 324 |
if (ip && !streq_ptr(ip, hd)) |
| 325 |
printf(" Image Path: %s\n", ip); |
| 326 |
|
| 327 |
b = user_record_removable(hr); |
| 328 |
if (b >= 0) |
| 329 |
printf(" Removable: %s\n", yes_no(b)); |
| 330 |
|
| 331 |
shell = user_record_shell(hr); |
| 332 |
if (shell) { |
| 333 |
printf(" Shell: %s", shell); |
| 334 |
|
| 335 |
if (hr->fallback_shell && hr->use_fallback) |
| 336 |
printf(" %s(fallback)%s", ansi_highlight_yellow(), ansi_normal()); |
| 337 |
|
| 338 |
printf("\n"); |
| 339 |
} |
| 340 |
|
| 341 |
if (hr->email_address) |
| 342 |
printf(" Email: %s\n", hr->email_address); |
| 343 |
if (hr->location) |
| 344 |
printf(" Location: %s\n", hr->location); |
| 345 |
if (BIRTH_DATE_IS_SET(hr->birth_date)) |
| 346 |
printf(" Birth Date: %04d-%02d-%02d\n", hr->birth_date.tm_year + 1900, hr->birth_date.tm_mon + 1, hr->birth_date.tm_mday); |
| 347 |
if (hr->password_hint) |
| 348 |
printf(" Passw. Hint: %s\n", hr->password_hint); |
| 349 |
if (hr->icon_name) |
| 350 |
printf(" Icon Name: %s\n", hr->icon_name); |
| 351 |
|
| 352 |
if (hr->time_zone) |
| 353 |
printf(" Time Zone: %s\n", hr->time_zone); |
| 354 |
|
| 355 |
r = user_record_languages(hr, &langs); |
| 356 |
if (r < 0) { |
| 357 |
errno = -r; |
| 358 |
printf(" Languages: (can't acquire: %m)\n"); |
| 359 |
} else if (!strv_isempty(langs)) { |
| 360 |
STRV_FOREACH(i, langs) |
| 361 |
printf(i == langs ? " Languages: %s" : ", %s", *i); |
| 362 |
printf("\n"); |
| 363 |
} |
| 364 |
|
| 365 |
if (hr->locked >= 0) |
| 366 |
printf(" Locked: %s\n", yes_no(hr->locked)); |
| 367 |
|
| 368 |
if (hr->not_before_usec != UINT64_MAX) |
| 369 |
printf(" Not Before: %s\n", FORMAT_TIMESTAMP(hr->not_before_usec)); |
| 370 |
|
| 371 |
if (hr->not_after_usec != UINT64_MAX) |
| 372 |
printf(" Not After: %s\n", FORMAT_TIMESTAMP(hr->not_after_usec)); |
| 373 |
|
| 374 |
if (hr->umask != MODE_INVALID) |
| 375 |
printf(" UMask: 0%03o\n", hr->umask); |
| 376 |
|
| 377 |
if (nice_is_valid(hr->nice_level)) |
| 378 |
printf(" Nice: %i\n", hr->nice_level); |
| 379 |
|
| 380 |
for (int j = 0; j < _RLIMIT_MAX; j++) { |
| 381 |
if (hr->rlimits[j]) |
| 382 |
printf(" Limit: RLIMIT_%s=%" PRIu64 ":%" PRIu64 "\n", |
| 383 |
rlimit_to_string(j), (uint64_t) hr->rlimits[j]->rlim_cur, (uint64_t) hr->rlimits[j]->rlim_max); |
| 384 |
} |
| 385 |
|
| 386 |
if (hr->tasks_max != UINT64_MAX) |
| 387 |
printf(" Tasks Max: %" PRIu64 "\n", hr->tasks_max); |
| 388 |
|
| 389 |
if (hr->memory_high != UINT64_MAX) |
| 390 |
printf(" Memory High: %s\n", FORMAT_BYTES(hr->memory_high)); |
| 391 |
|
| 392 |
if (hr->memory_max != UINT64_MAX) |
| 393 |
printf(" Memory Max: %s\n", FORMAT_BYTES(hr->memory_max)); |
| 394 |
|
| 395 |
if (hr->cpu_weight == CGROUP_WEIGHT_IDLE) |
| 396 |
printf(" CPU Weight: %s\n", "idle"); |
| 397 |
else if (hr->cpu_weight != UINT64_MAX) |
| 398 |
printf(" CPU Weight: %" PRIu64 "\n", hr->cpu_weight); |
| 399 |
|
| 400 |
if (hr->io_weight != UINT64_MAX) |
| 401 |
printf(" IO Weight: %" PRIu64 "\n", hr->io_weight); |
| 402 |
|
| 403 |
show_tmpfs_limit("TMP", &hr->tmp_limit, user_record_tmp_limit_scale(hr)); |
| 404 |
show_tmpfs_limit("SHM", &hr->dev_shm_limit, user_record_dev_shm_limit_scale(hr)); |
| 405 |
|
| 406 |
if (hr->access_mode != MODE_INVALID) |
| 407 |
printf(" Access Mode: 0%03o\n", user_record_access_mode(hr)); |
| 408 |
|
| 409 |
uint64_t caps = user_record_capability_bounding_set(hr); |
| 410 |
if (caps != CAP_MASK_UNSET) { |
| 411 |
_cleanup_free_ char *scaps = NULL; |
| 412 |
|
| 413 |
(void) capability_set_to_string_negative(caps, &scaps); |
| 414 |
printf(" Bound. Caps: %s\n", strna(scaps)); |
| 415 |
} |
| 416 |
|
| 417 |
caps = user_record_capability_ambient_set(hr); |
| 418 |
if (caps != CAP_MASK_UNSET) { |
| 419 |
_cleanup_free_ char *scaps = NULL; |
| 420 |
|
| 421 |
(void) capability_set_to_string(caps, &scaps); |
| 422 |
printf("Ambient Caps: %s\n", strna(scaps)); |
| 423 |
} |
| 424 |
|
| 425 |
if (storage == USER_LUKS) { |
| 426 |
printf("LUKS Discard: online=%s offline=%s\n", yes_no(user_record_luks_discard(hr)), yes_no(user_record_luks_offline_discard(hr))); |
| 427 |
|
| 428 |
if (!sd_id128_is_null(hr->luks_uuid)) |
| 429 |
printf(" LUKS UUID: " SD_ID128_UUID_FORMAT_STR "\n", SD_ID128_FORMAT_VAL(hr->luks_uuid)); |
| 430 |
if (!sd_id128_is_null(hr->partition_uuid)) |
| 431 |
printf(" Part UUID: " SD_ID128_UUID_FORMAT_STR "\n", SD_ID128_FORMAT_VAL(hr->partition_uuid)); |
| 432 |
if (!sd_id128_is_null(hr->file_system_uuid)) |
| 433 |
printf(" FS UUID: " SD_ID128_UUID_FORMAT_STR "\n", SD_ID128_FORMAT_VAL(hr->file_system_uuid)); |
| 434 |
|
| 435 |
if (hr->file_system_type) |
| 436 |
printf(" File System: %s\n", user_record_file_system_type(hr)); |
| 437 |
|
| 438 |
if (hr->luks_extra_mount_options) |
| 439 |
printf("LUKS MntOpts: %s\n", hr->luks_extra_mount_options); |
| 440 |
|
| 441 |
if (hr->luks_cipher) |
| 442 |
printf(" LUKS Cipher: %s\n", hr->luks_cipher); |
| 443 |
if (hr->luks_cipher_mode) |
| 444 |
printf(" Cipher Mode: %s\n", hr->luks_cipher_mode); |
| 445 |
if (hr->luks_volume_key_size != UINT64_MAX) |
| 446 |
printf(" Volume Key: %" PRIu64 "bit\n", hr->luks_volume_key_size * 8); |
| 447 |
|
| 448 |
if (hr->luks_pbkdf_type) |
| 449 |
printf(" PBKDF Type: %s\n", hr->luks_pbkdf_type); |
| 450 |
if (hr->luks_pbkdf_hash_algorithm) |
| 451 |
printf(" PBKDF Hash: %s\n", hr->luks_pbkdf_hash_algorithm); |
| 452 |
if (hr->luks_pbkdf_force_iterations != UINT64_MAX) |
| 453 |
printf(" PBKDF Iters: %" PRIu64 "\n", hr->luks_pbkdf_force_iterations); |
| 454 |
if (hr->luks_pbkdf_time_cost_usec != UINT64_MAX) |
| 455 |
printf(" PBKDF Time: %s\n", FORMAT_TIMESPAN(hr->luks_pbkdf_time_cost_usec, 0)); |
| 456 |
if (hr->luks_pbkdf_memory_cost != UINT64_MAX) |
| 457 |
printf(" PBKDF Bytes: %s\n", FORMAT_BYTES(hr->luks_pbkdf_memory_cost)); |
| 458 |
|
| 459 |
if (hr->luks_pbkdf_parallel_threads != UINT64_MAX) |
| 460 |
printf("PBKDF Thread: %" PRIu64 "\n", hr->luks_pbkdf_parallel_threads); |
| 461 |
if (hr->luks_sector_size != UINT64_MAX) |
| 462 |
printf(" Sector Size: %" PRIu64 "\n", hr->luks_sector_size); |
| 463 |
|
| 464 |
} else if (storage == USER_CIFS) { |
| 465 |
|
| 466 |
if (hr->cifs_service) |
| 467 |
printf("CIFS Service: %s\n", hr->cifs_service); |
| 468 |
|
| 469 |
if (hr->cifs_extra_mount_options) |
| 470 |
printf("CIFS MntOpts: %s\n", hr->cifs_extra_mount_options); |
| 471 |
} |
| 472 |
|
| 473 |
if (hr->cifs_user_name) |
| 474 |
printf(" CIFS User: %s\n", user_record_cifs_user_name(hr)); |
| 475 |
if (hr->cifs_domain) |
| 476 |
printf(" CIFS Domain: %s\n", hr->cifs_domain); |
| 477 |
|
| 478 |
if (storage != USER_CLASSIC) |
| 479 |
printf(" Mount Flags: %s %s %s\n", |
| 480 |
hr->nosuid ? "nosuid" : "suid", |
| 481 |
hr->nodev ? "nodev" : "dev", |
| 482 |
hr->noexec ? "noexec" : "exec"); |
| 483 |
|
| 484 |
if (hr->skeleton_directory) |
| 485 |
printf(" Skel. Dir.: %s\n", user_record_skeleton_directory(hr)); |
| 486 |
|
| 487 |
if (hr->disk_size != UINT64_MAX) |
| 488 |
printf(" Disk Size: %s\n", FORMAT_BYTES(hr->disk_size)); |
| 489 |
|
| 490 |
if (hr->disk_usage != UINT64_MAX) { |
| 491 |
if (hr->disk_size != UINT64_MAX) { |
| 492 |
unsigned permille; |
| 493 |
|
| 494 |
permille = (unsigned) DIV_ROUND_UP(hr->disk_usage * 1000U, hr->disk_size); /* Round up! */ |
| 495 |
printf(" Disk Usage: %s (= %u.%01u%%)\n", |
| 496 |
FORMAT_BYTES(hr->disk_usage), |
| 497 |
permille / 10, permille % 10); |
| 498 |
} else |
| 499 |
printf(" Disk Usage: %s\n", FORMAT_BYTES(hr->disk_usage)); |
| 500 |
} |
| 501 |
|
| 502 |
if (hr->disk_free != UINT64_MAX) { |
| 503 |
if (hr->disk_size != UINT64_MAX) { |
| 504 |
const char *color_on, *color_off; |
| 505 |
unsigned permille; |
| 506 |
|
| 507 |
permille = (unsigned) ((hr->disk_free * 1000U) / hr->disk_size); /* Round down! */ |
| 508 |
|
| 509 |
/* Color the output red or yellow if we are below 10% resp. 25% free. Because 10% and |
| 510 |
* 25% can be a lot of space still, let's additionally make some absolute |
| 511 |
* restrictions: 1G and 2G */ |
| 512 |
if (permille <= 100U && |
| 513 |
hr->disk_free < 1024U*1024U*1024U /* 1G */) { |
| 514 |
color_on = ansi_highlight_red(); |
| 515 |
color_off = ansi_normal(); |
| 516 |
} else if (permille <= 250U && |
| 517 |
hr->disk_free < 2U*1024U*1024U*1024U /* 2G */) { |
| 518 |
color_on = ansi_highlight_yellow(); |
| 519 |
color_off = ansi_normal(); |
| 520 |
} else |
| 521 |
color_on = color_off = ""; |
| 522 |
|
| 523 |
printf(" Disk Free: %s%s (= %u.%01u%%)%s\n", |
| 524 |
color_on, |
| 525 |
FORMAT_BYTES(hr->disk_free), |
| 526 |
permille / 10, permille % 10, |
| 527 |
color_off); |
| 528 |
} else |
| 529 |
printf(" Disk Free: %s\n", FORMAT_BYTES(hr->disk_free)); |
| 530 |
} |
| 531 |
|
| 532 |
if (hr->disk_floor != UINT64_MAX) |
| 533 |
printf(" Disk Floor: %s\n", FORMAT_BYTES(hr->disk_floor)); |
| 534 |
|
| 535 |
if (hr->disk_ceiling != UINT64_MAX) |
| 536 |
printf("Disk Ceiling: %s\n", FORMAT_BYTES(hr->disk_ceiling)); |
| 537 |
|
| 538 |
if (hr->good_authentication_counter != UINT64_MAX) |
| 539 |
printf(" Good Auth.: %" PRIu64 "\n", hr->good_authentication_counter); |
| 540 |
|
| 541 |
if (hr->last_good_authentication_usec != UINT64_MAX) |
| 542 |
printf(" Last Good: %s\n", FORMAT_TIMESTAMP(hr->last_good_authentication_usec)); |
| 543 |
|
| 544 |
if (hr->bad_authentication_counter != UINT64_MAX) |
| 545 |
printf(" Bad Auth.: %" PRIu64 "\n", hr->bad_authentication_counter); |
| 546 |
|
| 547 |
if (hr->last_bad_authentication_usec != UINT64_MAX) |
| 548 |
printf(" Last Bad: %s\n", FORMAT_TIMESTAMP(hr->last_bad_authentication_usec)); |
| 549 |
|
| 550 |
t = user_record_ratelimit_next_try(hr); |
| 551 |
if (t != USEC_INFINITY) { |
| 552 |
usec_t n = now(CLOCK_REALTIME); |
| 553 |
|
| 554 |
if (t <= n) |
| 555 |
printf(" Next Try: anytime\n"); |
| 556 |
else |
| 557 |
printf(" Next Try: %sin %s%s\n", |
| 558 |
ansi_highlight_red(), |
| 559 |
FORMAT_TIMESPAN(t - n, USEC_PER_SEC), |
| 560 |
ansi_normal()); |
| 561 |
} |
| 562 |
|
| 563 |
if (storage != USER_CLASSIC) |
| 564 |
printf(" Auth. Limit: %" PRIu64 " attempts per %s\n", user_record_ratelimit_burst(hr), |
| 565 |
FORMAT_TIMESPAN(user_record_ratelimit_interval_usec(hr), 0)); |
| 566 |
|
| 567 |
if (hr->enforce_password_policy >= 0) |
| 568 |
printf(" Passwd Pol.: %s\n", yes_no(hr->enforce_password_policy)); |
| 569 |
|
| 570 |
if (hr->password_change_min_usec != UINT64_MAX || |
| 571 |
hr->password_change_max_usec != UINT64_MAX || |
| 572 |
hr->password_change_warn_usec != UINT64_MAX || |
| 573 |
hr->password_change_inactive_usec != UINT64_MAX) { |
| 574 |
|
| 575 |
printf(" Passwd Chg.:"); |
| 576 |
|
| 577 |
if (hr->password_change_min_usec != UINT64_MAX) { |
| 578 |
printf(" min %s", FORMAT_TIMESPAN(hr->password_change_min_usec, 0)); |
| 579 |
|
| 580 |
if (hr->password_change_max_usec != UINT64_MAX) |
| 581 |
printf(" …"); |
| 582 |
} |
| 583 |
|
| 584 |
if (hr->password_change_max_usec != UINT64_MAX) |
| 585 |
printf(" max %s", FORMAT_TIMESPAN(hr->password_change_max_usec, 0)); |
| 586 |
|
| 587 |
if (hr->password_change_warn_usec != UINT64_MAX) |
| 588 |
printf("/warn %s", FORMAT_TIMESPAN(hr->password_change_warn_usec, 0)); |
| 589 |
|
| 590 |
if (hr->password_change_inactive_usec != UINT64_MAX) |
| 591 |
printf("/inactive %s", FORMAT_TIMESPAN(hr->password_change_inactive_usec, 0)); |
| 592 |
|
| 593 |
printf("\n"); |
| 594 |
} |
| 595 |
|
| 596 |
if (hr->password_change_now >= 0) |
| 597 |
printf("Pas. Ch. Now: %s\n", yes_no(hr->password_change_now)); |
| 598 |
|
| 599 |
if (hr->drop_caches >= 0 || user_record_drop_caches(hr)) |
| 600 |
printf(" Drop Caches: %s\n", yes_no(user_record_drop_caches(hr))); |
| 601 |
|
| 602 |
if (hr->auto_resize_mode >= 0) |
| 603 |
printf(" Auto Resize: %s\n", auto_resize_mode_to_string(user_record_auto_resize_mode(hr))); |
| 604 |
|
| 605 |
if (hr->rebalance_weight != REBALANCE_WEIGHT_UNSET) { |
| 606 |
uint64_t rb; |
| 607 |
|
| 608 |
rb = user_record_rebalance_weight(hr); |
| 609 |
if (rb == REBALANCE_WEIGHT_OFF) |
| 610 |
printf(" Rebalance: off\n"); |
| 611 |
else |
| 612 |
printf(" Rebalance: weight %" PRIu64 "\n", rb); |
| 613 |
} |
| 614 |
|
| 615 |
if (!strv_isempty(hr->ssh_authorized_keys)) |
| 616 |
printf("SSH Pub. Key: %zu\n", strv_length(hr->ssh_authorized_keys)); |
| 617 |
|
| 618 |
if (!strv_isempty(hr->pkcs11_token_uri)) |
| 619 |
STRV_FOREACH(i, hr->pkcs11_token_uri) |
| 620 |
printf(i == hr->pkcs11_token_uri ? |
| 621 |
"PKCS11 Token: %s\n" : |
| 622 |
" %s\n", *i); |
| 623 |
|
| 624 |
if (hr->n_fido2_hmac_credential > 0) |
| 625 |
printf(" FIDO2 Token: %zu\n", hr->n_fido2_hmac_credential); |
| 626 |
|
| 627 |
if (!strv_isempty(hr->recovery_key_type)) |
| 628 |
printf("Recovery Key: %zu\n", strv_length(hr->recovery_key_type)); |
| 629 |
|
| 630 |
k = strv_length(hr->hashed_password); |
| 631 |
if (k == 0) |
| 632 |
printf(" Passwords: %snone%s\n", |
| 633 |
user_record_disposition(hr) == USER_REGULAR ? ansi_highlight_yellow() : ansi_normal(), ansi_normal()); |
| 634 |
else |
| 635 |
printf(" Passwords: %zu\n", k); |
| 636 |
|
| 637 |
if (hr->signed_locally >= 0) |
| 638 |
printf(" Local Sig.: %s\n", yes_no(hr->signed_locally)); |
| 639 |
|
| 640 |
if (hr->stop_delay_usec != UINT64_MAX) |
| 641 |
printf(" Stop Delay: %s\n", FORMAT_TIMESPAN(hr->stop_delay_usec, 0)); |
| 642 |
|
| 643 |
if (hr->auto_login >= 0) |
| 644 |
printf("Autom. Login: %s\n", yes_no(hr->auto_login)); |
| 645 |
|
| 646 |
if (hr->preferred_session_launcher) |
| 647 |
printf("Sess. Launch: %s\n", hr->preferred_session_launcher); |
| 648 |
if (hr->preferred_session_type) |
| 649 |
printf("Session Type: %s\n", hr->preferred_session_type); |
| 650 |
|
| 651 |
if (hr->kill_processes >= 0) |
| 652 |
printf(" Kill Proc.: %s\n", yes_no(hr->kill_processes)); |
| 653 |
|
| 654 |
if (hr->service) |
| 655 |
printf(" Service: %s\n", hr->service); |
| 656 |
|
| 657 |
show_self_modifiable("Self Modify:", |
| 658 |
hr->self_modifiable_fields, |
| 659 |
user_record_self_modifiable_fields(hr)); |
| 660 |
show_self_modifiable("(Blobs)", |
| 661 |
hr->self_modifiable_blobs, |
| 662 |
user_record_self_modifiable_blobs(hr)); |
| 663 |
show_self_modifiable("(Privileged)", |
| 664 |
hr->self_modifiable_privileged, |
| 665 |
user_record_self_modifiable_privileged(hr)); |
| 666 |
} |
| 667 |
|
| 668 |
void group_record_show(GroupRecord *gr, bool show_full_user_info) { |
| 669 |
int r; |
| 670 |
|
| 671 |
printf(" Group name: %s\n", |
| 672 |
group_record_group_name_and_realm(gr)); |
| 673 |
|
| 674 |
printf(" Disposition: %s\n", user_disposition_to_string(group_record_disposition(gr))); |
| 675 |
|
| 676 |
if (gr->last_change_usec != USEC_INFINITY) |
| 677 |
printf(" Last Change: %s\n", FORMAT_TIMESTAMP(gr->last_change_usec)); |
| 678 |
|
| 679 |
if (gid_is_valid(gr->gid)) |
| 680 |
printf(" GID: " GID_FMT "\n", gr->gid); |
| 681 |
|
| 682 |
if (!sd_id128_is_null(gr->uuid)) |
| 683 |
printf(" UUID: " SD_ID128_UUID_FORMAT_STR "\n", SD_ID128_FORMAT_VAL(gr->uuid)); |
| 684 |
|
| 685 |
if (show_full_user_info) { |
| 686 |
_cleanup_(userdb_iterator_freep) UserDBIterator *iterator = NULL; |
| 687 |
|
| 688 |
r = membershipdb_by_group(gr->group_name, 0, &iterator); |
| 689 |
if (r < 0) { |
| 690 |
errno = -r; |
| 691 |
printf(" Members: (can't acquire: %m)"); |
| 692 |
} else { |
| 693 |
const char *prefix = " Members:"; |
| 694 |
|
| 695 |
for (;;) { |
| 696 |
_cleanup_free_ char *user = NULL; |
| 697 |
|
| 698 |
r = membershipdb_iterator_get(iterator, &user, NULL); |
| 699 |
if (r == -ESRCH) |
| 700 |
break; |
| 701 |
if (r < 0) { |
| 702 |
errno = -r; |
| 703 |
printf("%s (can't iterate: %m\n", prefix); |
| 704 |
break; |
| 705 |
} |
| 706 |
|
| 707 |
printf("%s %s\n", prefix, user); |
| 708 |
prefix = " "; |
| 709 |
} |
| 710 |
} |
| 711 |
} else { |
| 712 |
const char *prefix = " Members:"; |
| 713 |
|
| 714 |
STRV_FOREACH(i, gr->members) { |
| 715 |
printf("%s %s\n", prefix, *i); |
| 716 |
prefix = " "; |
| 717 |
} |
| 718 |
} |
| 719 |
|
| 720 |
if (!strv_isempty(gr->administrators)) { |
| 721 |
const char *prefix = " Admins:"; |
| 722 |
|
| 723 |
STRV_FOREACH(i, gr->administrators) { |
| 724 |
printf("%s %s\n", prefix, *i); |
| 725 |
prefix = " "; |
| 726 |
} |
| 727 |
} |
| 728 |
|
| 729 |
if (gr->description && !streq(gr->description, gr->group_name)) |
| 730 |
printf(" Description: %s\n", gr->description); |
| 731 |
|
| 732 |
if (!strv_isempty(gr->hashed_password)) |
| 733 |
printf(" Passwords: %zu\n", strv_length(gr->hashed_password)); |
| 734 |
|
| 735 |
if (gr->service) |
| 736 |
printf(" Service: %s\n", gr->service); |
| 737 |
} |