1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
6 #include "cgroup-util.h"
7 #include "dns-domain.h"
10 #include "glyph-util.h"
11 #include "hexdecoct.h"
12 #include "hostname-util.h"
13 #include "memory-util.h"
14 #include "path-util.h"
15 #include "pkcs11-util.h"
16 #include "rlimit-util.h"
17 #include "string-table.h"
19 #include "uid-alloc-range.h"
20 #include "user-record.h"
21 #include "user-util.h"
23 #define DEFAULT_RATELIMIT_BURST 30
24 #define DEFAULT_RATELIMIT_INTERVAL_USEC (1*USEC_PER_MINUTE)
26 UserRecord
* user_record_new(void) {
29 h
= new(UserRecord
, 1);
35 .disposition
= _USER_DISPOSITION_INVALID
,
36 .last_change_usec
= UINT64_MAX
,
37 .last_password_change_usec
= UINT64_MAX
,
38 .umask
= MODE_INVALID
,
39 .nice_level
= INT_MAX
,
40 .not_before_usec
= UINT64_MAX
,
41 .not_after_usec
= UINT64_MAX
,
43 .storage
= _USER_STORAGE_INVALID
,
44 .access_mode
= MODE_INVALID
,
45 .disk_size
= UINT64_MAX
,
46 .disk_size_relative
= UINT64_MAX
,
47 .tasks_max
= UINT64_MAX
,
48 .memory_high
= UINT64_MAX
,
49 .memory_max
= UINT64_MAX
,
50 .cpu_weight
= UINT64_MAX
,
51 .io_weight
= UINT64_MAX
,
57 .luks_offline_discard
= -1,
58 .luks_volume_key_size
= UINT64_MAX
,
59 .luks_pbkdf_force_iterations
= UINT64_MAX
,
60 .luks_pbkdf_time_cost_usec
= UINT64_MAX
,
61 .luks_pbkdf_memory_cost
= UINT64_MAX
,
62 .luks_pbkdf_parallel_threads
= UINT64_MAX
,
63 .luks_sector_size
= UINT64_MAX
,
64 .disk_usage
= UINT64_MAX
,
65 .disk_free
= UINT64_MAX
,
66 .disk_ceiling
= UINT64_MAX
,
67 .disk_floor
= UINT64_MAX
,
69 .good_authentication_counter
= UINT64_MAX
,
70 .bad_authentication_counter
= UINT64_MAX
,
71 .last_good_authentication_usec
= UINT64_MAX
,
72 .last_bad_authentication_usec
= UINT64_MAX
,
73 .ratelimit_begin_usec
= UINT64_MAX
,
74 .ratelimit_count
= UINT64_MAX
,
75 .ratelimit_interval_usec
= UINT64_MAX
,
76 .ratelimit_burst
= UINT64_MAX
,
78 .enforce_password_policy
= -1,
80 .stop_delay_usec
= UINT64_MAX
,
82 .password_change_min_usec
= UINT64_MAX
,
83 .password_change_max_usec
= UINT64_MAX
,
84 .password_change_warn_usec
= UINT64_MAX
,
85 .password_change_inactive_usec
= UINT64_MAX
,
86 .password_change_now
= -1,
87 .pkcs11_protected_authentication_path_permitted
= -1,
88 .fido2_user_presence_permitted
= -1,
89 .fido2_user_verification_permitted
= -1,
91 .auto_resize_mode
= _AUTO_RESIZE_MODE_INVALID
,
92 .rebalance_weight
= REBALANCE_WEIGHT_UNSET
,
98 static void pkcs11_encrypted_key_done(Pkcs11EncryptedKey
*k
) {
103 erase_and_free(k
->data
);
104 erase_and_free(k
->hashed_password
);
107 static void fido2_hmac_credential_done(Fido2HmacCredential
*c
) {
114 static void fido2_hmac_salt_done(Fido2HmacSalt
*s
) {
118 fido2_hmac_credential_done(&s
->credential
);
119 erase_and_free(s
->salt
);
120 erase_and_free(s
->hashed_password
);
123 static void recovery_key_done(RecoveryKey
*k
) {
128 erase_and_free(k
->hashed_password
);
131 static UserRecord
* user_record_free(UserRecord
*h
) {
137 free(h
->user_name_and_realm_auto
);
139 free(h
->email_address
);
140 erase_and_free(h
->password_hint
);
146 strv_free(h
->environment
);
148 free(h
->preferred_language
);
149 rlimit_free_all(h
->rlimits
);
151 free(h
->skeleton_directory
);
153 strv_free_erase(h
->hashed_password
);
154 strv_free_erase(h
->ssh_authorized_keys
);
155 strv_free_erase(h
->password
);
156 strv_free_erase(h
->token_pin
);
158 free(h
->cifs_service
);
159 free(h
->cifs_user_name
);
160 free(h
->cifs_domain
);
161 free(h
->cifs_extra_mount_options
);
164 free(h
->image_path_auto
);
165 free(h
->home_directory
);
166 free(h
->home_directory_auto
);
168 strv_free(h
->member_of
);
169 strv_free(h
->capability_bounding_set
);
170 strv_free(h
->capability_ambient_set
);
172 free(h
->file_system_type
);
173 free(h
->luks_cipher
);
174 free(h
->luks_cipher_mode
);
175 free(h
->luks_pbkdf_hash_algorithm
);
176 free(h
->luks_pbkdf_type
);
177 free(h
->luks_extra_mount_options
);
182 strv_free(h
->pkcs11_token_uri
);
183 for (size_t i
= 0; i
< h
->n_pkcs11_encrypted_key
; i
++)
184 pkcs11_encrypted_key_done(h
->pkcs11_encrypted_key
+ i
);
185 free(h
->pkcs11_encrypted_key
);
187 for (size_t i
= 0; i
< h
->n_fido2_hmac_credential
; i
++)
188 fido2_hmac_credential_done(h
->fido2_hmac_credential
+ i
);
189 for (size_t i
= 0; i
< h
->n_fido2_hmac_salt
; i
++)
190 fido2_hmac_salt_done(h
->fido2_hmac_salt
+ i
);
192 strv_free(h
->recovery_key_type
);
193 for (size_t i
= 0; i
< h
->n_recovery_key
; i
++)
194 recovery_key_done(h
->recovery_key
+ i
);
196 json_variant_unref(h
->json
);
201 DEFINE_TRIVIAL_REF_UNREF_FUNC(UserRecord
, user_record
, user_record_free
);
203 int json_dispatch_realm(const char *name
, JsonVariant
*variant
, JsonDispatchFlags flags
, void *userdata
) {
208 if (json_variant_is_null(variant
)) {
213 if (!json_variant_is_string(variant
))
214 return json_log(variant
, flags
, SYNTHETIC_ERRNO(EINVAL
), "JSON field '%s' is not a string.", strna(name
));
216 n
= json_variant_string(variant
);
217 r
= dns_name_is_valid(n
);
219 return json_log(variant
, flags
, r
, "Failed to check if JSON field '%s' is a valid DNS domain.", strna(name
));
221 return json_log(variant
, flags
, SYNTHETIC_ERRNO(EINVAL
), "JSON field '%s' is not a valid DNS domain.", strna(name
));
223 r
= free_and_strdup(s
, n
);
225 return json_log(variant
, flags
, r
, "Failed to allocate string: %m");
230 int json_dispatch_gecos(const char *name
, JsonVariant
*variant
, JsonDispatchFlags flags
, void *userdata
) {
234 if (json_variant_is_null(variant
)) {
239 if (!json_variant_is_string(variant
))
240 return json_log(variant
, flags
, SYNTHETIC_ERRNO(EINVAL
), "JSON field '%s' is not a string.", strna(name
));
242 n
= json_variant_string(variant
);
243 if (valid_gecos(n
)) {
244 if (free_and_strdup(s
, n
) < 0)
245 return json_log_oom(variant
, flags
);
247 _cleanup_free_
char *m
= NULL
;
249 json_log(variant
, flags
|JSON_DEBUG
, SYNTHETIC_ERRNO(EINVAL
), "JSON field '%s' is not a valid GECOS compatible string, mangling.", strna(name
));
253 return json_log_oom(variant
, flags
);
255 free_and_replace(*s
, m
);
261 static int json_dispatch_nice(const char *name
, JsonVariant
*variant
, JsonDispatchFlags flags
, void *userdata
) {
265 if (json_variant_is_null(variant
)) {
270 if (!json_variant_is_integer(variant
))
271 return json_log(variant
, flags
, SYNTHETIC_ERRNO(EINVAL
), "JSON field '%s' is not a string.", strna(name
));
273 m
= json_variant_integer(variant
);
274 if (m
< PRIO_MIN
|| m
>= PRIO_MAX
)
275 return json_log(variant
, flags
, SYNTHETIC_ERRNO(ERANGE
), "JSON field '%s' is not a valid nice level.", strna(name
));
281 static int json_dispatch_rlimit_value(const char *name
, JsonVariant
*variant
, JsonDispatchFlags flags
, void *userdata
) {
282 rlim_t
*ret
= userdata
;
284 if (json_variant_is_null(variant
))
285 *ret
= RLIM_INFINITY
;
286 else if (json_variant_is_unsigned(variant
)) {
289 w
= json_variant_unsigned(variant
);
290 if (w
== RLIM_INFINITY
|| (uint64_t) w
!= json_variant_unsigned(variant
))
291 return json_log(variant
, flags
, SYNTHETIC_ERRNO(ERANGE
), "Resource limit value '%s' is out of range.", name
);
295 return json_log(variant
, flags
, SYNTHETIC_ERRNO(EINVAL
), "Resource limit value '%s' is not an unsigned integer.", name
);
300 static int json_dispatch_rlimits(const char *name
, JsonVariant
*variant
, JsonDispatchFlags flags
, void *userdata
) {
301 struct rlimit
** limits
= userdata
;
308 if (json_variant_is_null(variant
)) {
309 rlimit_free_all(limits
);
313 if (!json_variant_is_object(variant
))
314 return json_log(variant
, flags
, SYNTHETIC_ERRNO(EINVAL
), "JSON field '%s' is not an object.", strna(name
));
316 JSON_VARIANT_OBJECT_FOREACH(key
, value
, variant
) {
317 JsonVariant
*jcur
, *jmax
;
322 p
= startswith(key
, "RLIMIT_");
324 l
= -SYNTHETIC_ERRNO(EINVAL
);
326 l
= rlimit_from_string(p
);
328 return json_log(variant
, flags
, l
, "Resource limit '%s' not known.", key
);
330 if (!json_variant_is_object(value
))
331 return json_log(value
, flags
, SYNTHETIC_ERRNO(EINVAL
), "Resource limit '%s' has invalid value.", key
);
333 if (json_variant_elements(value
) != 4)
334 return json_log(value
, flags
, SYNTHETIC_ERRNO(EINVAL
), "Resource limit '%s' value is does not have two fields as expected.", key
);
336 jcur
= json_variant_by_key(value
, "cur");
338 return json_log(value
, flags
, SYNTHETIC_ERRNO(EINVAL
), "Resource limit '%s' lacks 'cur' field.", key
);
339 r
= json_dispatch_rlimit_value("cur", jcur
, flags
, &rl
.rlim_cur
);
343 jmax
= json_variant_by_key(value
, "max");
345 return json_log(value
, flags
, SYNTHETIC_ERRNO(EINVAL
), "Resource limit '%s' lacks 'max' field.", key
);
346 r
= json_dispatch_rlimit_value("max", jmax
, flags
, &rl
.rlim_max
);
353 limits
[l
] = newdup(struct rlimit
, &rl
, 1);
362 static int json_dispatch_filename_or_path(const char *name
, JsonVariant
*variant
, JsonDispatchFlags flags
, void *userdata
) {
363 char **s
= ASSERT_PTR(userdata
);
367 if (json_variant_is_null(variant
)) {
372 if (!json_variant_is_string(variant
))
373 return json_log(variant
, flags
, SYNTHETIC_ERRNO(EINVAL
), "JSON field '%s' is not a string.", strna(name
));
375 n
= json_variant_string(variant
);
376 if (!filename_is_valid(n
) && !path_is_normalized(n
))
377 return json_log(variant
, flags
, SYNTHETIC_ERRNO(EINVAL
), "JSON field '%s' is not a valid file name or normalized path.", strna(name
));
379 r
= free_and_strdup(s
, n
);
381 return json_log(variant
, flags
, r
, "Failed to allocate string: %m");
386 static int json_dispatch_path(const char *name
, JsonVariant
*variant
, JsonDispatchFlags flags
, void *userdata
) {
391 if (json_variant_is_null(variant
)) {
396 if (!json_variant_is_string(variant
))
397 return json_log(variant
, flags
, SYNTHETIC_ERRNO(EINVAL
), "JSON field '%s' is not a string.", strna(name
));
399 n
= json_variant_string(variant
);
400 if (!path_is_normalized(n
))
401 return json_log(variant
, flags
, SYNTHETIC_ERRNO(EINVAL
), "JSON field '%s' is not a normalized file system path.", strna(name
));
402 if (!path_is_absolute(n
))
403 return json_log(variant
, flags
, SYNTHETIC_ERRNO(EINVAL
), "JSON field '%s' is not an absolute file system path.", strna(name
));
405 r
= free_and_strdup(s
, n
);
407 return json_log(variant
, flags
, r
, "Failed to allocate string: %m");
412 static int json_dispatch_home_directory(const char *name
, JsonVariant
*variant
, JsonDispatchFlags flags
, void *userdata
) {
417 if (json_variant_is_null(variant
)) {
422 if (!json_variant_is_string(variant
))
423 return json_log(variant
, flags
, SYNTHETIC_ERRNO(EINVAL
), "JSON field '%s' is not a string.", strna(name
));
425 n
= json_variant_string(variant
);
427 return json_log(variant
, flags
, SYNTHETIC_ERRNO(EINVAL
), "JSON field '%s' is not a valid home directory path.", strna(name
));
429 r
= free_and_strdup(s
, n
);
431 return json_log(variant
, flags
, r
, "Failed to allocate string: %m");
436 static int json_dispatch_image_path(const char *name
, JsonVariant
*variant
, JsonDispatchFlags flags
, void *userdata
) {
441 if (json_variant_is_null(variant
)) {
446 if (!json_variant_is_string(variant
))
447 return json_log(variant
, flags
, SYNTHETIC_ERRNO(EINVAL
), "JSON field '%s' is not a string.", strna(name
));
449 n
= json_variant_string(variant
);
450 if (empty_or_root(n
) || !path_is_valid(n
) || !path_is_absolute(n
))
451 return json_log(variant
, flags
, SYNTHETIC_ERRNO(EINVAL
), "JSON field '%s' is not a valid image path.", strna(name
));
453 r
= free_and_strdup(s
, n
);
455 return json_log(variant
, flags
, r
, "Failed to allocate string: %m");
460 static int json_dispatch_umask(const char *name
, JsonVariant
*variant
, JsonDispatchFlags flags
, void *userdata
) {
461 mode_t
*m
= userdata
;
464 if (json_variant_is_null(variant
)) {
469 if (!json_variant_is_unsigned(variant
))
470 return json_log(variant
, flags
, SYNTHETIC_ERRNO(EINVAL
), "JSON field '%s' is not a number.", strna(name
));
472 k
= json_variant_unsigned(variant
);
474 return json_log(variant
, flags
, SYNTHETIC_ERRNO(EINVAL
),
475 "JSON field '%s' outside of valid range 0%s0777.",
476 strna(name
), special_glyph(SPECIAL_GLYPH_ELLIPSIS
));
482 static int json_dispatch_access_mode(const char *name
, JsonVariant
*variant
, JsonDispatchFlags flags
, void *userdata
) {
483 mode_t
*m
= userdata
;
486 if (json_variant_is_null(variant
)) {
491 if (!json_variant_is_unsigned(variant
))
492 return json_log(variant
, flags
, SYNTHETIC_ERRNO(EINVAL
), "JSON field '%s' is not a number.", strna(name
));
494 k
= json_variant_unsigned(variant
);
496 return json_log(variant
, flags
, SYNTHETIC_ERRNO(EINVAL
),
497 "JSON field '%s' outside of valid range 0%s07777.",
498 strna(name
), special_glyph(SPECIAL_GLYPH_ELLIPSIS
));
504 static int json_dispatch_environment(const char *name
, JsonVariant
*variant
, JsonDispatchFlags flags
, void *userdata
) {
505 _cleanup_strv_free_
char **n
= NULL
;
506 char ***l
= userdata
;
509 if (json_variant_is_null(variant
)) {
514 if (!json_variant_is_array(variant
))
515 return json_log(variant
, flags
, SYNTHETIC_ERRNO(EINVAL
), "JSON field '%s' is not an array.", strna(name
));
517 for (size_t i
= 0; i
< json_variant_elements(variant
); i
++) {
521 e
= json_variant_by_index(variant
, i
);
522 if (!json_variant_is_string(e
))
523 return json_log(variant
, flags
, SYNTHETIC_ERRNO(EINVAL
), "JSON field '%s' is not an array of strings.", strna(name
));
525 assert_se(a
= json_variant_string(e
));
527 if (!env_assignment_is_valid(a
))
528 return json_log(variant
, flags
, SYNTHETIC_ERRNO(EINVAL
), "JSON field '%s' is not an array of environment variables.", strna(name
));
530 r
= strv_env_replace_strdup(&n
, a
);
532 return json_log_oom(variant
, flags
);
535 return strv_free_and_replace(*l
, n
);
538 int json_dispatch_user_disposition(const char *name
, JsonVariant
*variant
, JsonDispatchFlags flags
, void *userdata
) {
539 UserDisposition
*disposition
= userdata
, k
;
541 if (json_variant_is_null(variant
)) {
542 *disposition
= _USER_DISPOSITION_INVALID
;
546 if (!json_variant_is_string(variant
))
547 return json_log(variant
, flags
, SYNTHETIC_ERRNO(EINVAL
), "JSON field '%s' is not a string.", strna(name
));
549 k
= user_disposition_from_string(json_variant_string(variant
));
551 return json_log(variant
, flags
, k
, "Disposition type '%s' not known.", json_variant_string(variant
));
557 static int json_dispatch_storage(const char *name
, JsonVariant
*variant
, JsonDispatchFlags flags
, void *userdata
) {
558 UserStorage
*storage
= userdata
, k
;
560 if (json_variant_is_null(variant
)) {
561 *storage
= _USER_STORAGE_INVALID
;
565 if (!json_variant_is_string(variant
))
566 return json_log(variant
, flags
, SYNTHETIC_ERRNO(EINVAL
), "JSON field '%s' is not a string.", strna(name
));
568 k
= user_storage_from_string(json_variant_string(variant
));
570 return json_log(variant
, flags
, k
, "Storage type '%s' not known.", json_variant_string(variant
));
576 static int json_dispatch_tasks_or_memory_max(const char *name
, JsonVariant
*variant
, JsonDispatchFlags flags
, void *userdata
) {
577 uint64_t *limit
= userdata
, k
;
579 if (json_variant_is_null(variant
)) {
584 if (!json_variant_is_unsigned(variant
))
585 return json_log(variant
, flags
, SYNTHETIC_ERRNO(EINVAL
), "JSON field '%s' is not an integer.", strna(name
));
587 k
= json_variant_unsigned(variant
);
588 if (k
<= 0 || k
>= UINT64_MAX
)
589 return json_log(variant
, flags
, SYNTHETIC_ERRNO(ERANGE
),
590 "JSON field '%s' is not in valid range %" PRIu64
"%s%" PRIu64
".",
591 strna(name
), (uint64_t) 1, special_glyph(SPECIAL_GLYPH_ELLIPSIS
), UINT64_MAX
-1);
597 static int json_dispatch_weight(const char *name
, JsonVariant
*variant
, JsonDispatchFlags flags
, void *userdata
) {
598 uint64_t *weight
= userdata
, k
;
600 if (json_variant_is_null(variant
)) {
601 *weight
= UINT64_MAX
;
605 if (!json_variant_is_unsigned(variant
))
606 return json_log(variant
, flags
, SYNTHETIC_ERRNO(EINVAL
), "JSON field '%s' is not an integer.", strna(name
));
608 k
= json_variant_unsigned(variant
);
609 if (k
<= CGROUP_WEIGHT_MIN
|| k
>= CGROUP_WEIGHT_MAX
)
610 return json_log(variant
, flags
, SYNTHETIC_ERRNO(ERANGE
),
611 "JSON field '%s' is not in valid range %" PRIu64
"%s%" PRIu64
".",
612 strna(name
), (uint64_t) CGROUP_WEIGHT_MIN
,
613 special_glyph(SPECIAL_GLYPH_ELLIPSIS
), (uint64_t) CGROUP_WEIGHT_MAX
);
619 int json_dispatch_user_group_list(const char *name
, JsonVariant
*variant
, JsonDispatchFlags flags
, void *userdata
) {
620 _cleanup_strv_free_
char **l
= NULL
;
621 char ***list
= userdata
;
625 if (!json_variant_is_array(variant
))
626 return json_log(variant
, flags
, SYNTHETIC_ERRNO(EINVAL
), "JSON field '%s' is not an array of strings.", strna(name
));
628 JSON_VARIANT_ARRAY_FOREACH(e
, variant
) {
630 if (!json_variant_is_string(e
))
631 return json_log(e
, flags
, SYNTHETIC_ERRNO(EINVAL
), "JSON array element is not a string.");
633 if (!valid_user_group_name(json_variant_string(e
), FLAGS_SET(flags
, JSON_RELAX
) ? VALID_USER_RELAX
: 0))
634 return json_log(e
, flags
, SYNTHETIC_ERRNO(EINVAL
), "JSON array element is not a valid user/group name: %s", json_variant_string(e
));
636 r
= strv_extend(&l
, json_variant_string(e
));
638 return json_log(e
, flags
, r
, "Failed to append array element: %m");
641 r
= strv_extend_strv(list
, l
, true);
643 return json_log(variant
, flags
, r
, "Failed to merge user/group arrays: %m");
648 static int dispatch_secret(const char *name
, JsonVariant
*variant
, JsonDispatchFlags flags
, void *userdata
) {
650 static const JsonDispatch secret_dispatch_table
[] = {
651 { "password", _JSON_VARIANT_TYPE_INVALID
, json_dispatch_strv
, offsetof(UserRecord
, password
), 0 },
652 { "tokenPin", _JSON_VARIANT_TYPE_INVALID
, json_dispatch_strv
, offsetof(UserRecord
, token_pin
), 0 },
653 { "pkcs11Pin", /* legacy alias */ _JSON_VARIANT_TYPE_INVALID
, json_dispatch_strv
, offsetof(UserRecord
, token_pin
), 0 },
654 { "pkcs11ProtectedAuthenticationPathPermitted", JSON_VARIANT_BOOLEAN
, json_dispatch_tristate
, offsetof(UserRecord
, pkcs11_protected_authentication_path_permitted
), 0 },
655 { "fido2UserPresencePermitted", JSON_VARIANT_BOOLEAN
, json_dispatch_tristate
, offsetof(UserRecord
, fido2_user_presence_permitted
), 0 },
656 { "fido2UserVerificationPermitted", JSON_VARIANT_BOOLEAN
, json_dispatch_tristate
, offsetof(UserRecord
, fido2_user_verification_permitted
), 0 },
660 return json_dispatch(variant
, secret_dispatch_table
, flags
, userdata
);
663 static int dispatch_pkcs11_uri(const char *name
, JsonVariant
*variant
, JsonDispatchFlags flags
, void *userdata
) {
668 if (json_variant_is_null(variant
)) {
673 if (!json_variant_is_string(variant
))
674 return json_log(variant
, flags
, SYNTHETIC_ERRNO(EINVAL
), "JSON field '%s' is not a string.", strna(name
));
676 n
= json_variant_string(variant
);
677 if (!pkcs11_uri_valid(n
))
678 return json_log(variant
, flags
, SYNTHETIC_ERRNO(EINVAL
), "JSON field '%s' is not a valid RFC7512 PKCS#11 URI.", strna(name
));
680 r
= free_and_strdup(s
, n
);
682 return json_log(variant
, flags
, r
, "Failed to allocate string: %m");
687 static int dispatch_pkcs11_uri_array(const char *name
, JsonVariant
*variant
, JsonDispatchFlags flags
, void *userdata
) {
688 _cleanup_strv_free_
char **z
= NULL
;
689 char ***l
= userdata
;
693 if (json_variant_is_null(variant
)) {
698 if (json_variant_is_string(variant
)) {
701 n
= json_variant_string(variant
);
702 if (!pkcs11_uri_valid(n
))
703 return json_log(variant
, flags
, SYNTHETIC_ERRNO(EINVAL
), "JSON field '%s' is not a valid RFC7512 PKCS#11 URI.", strna(name
));
711 if (!json_variant_is_array(variant
))
712 return json_log(variant
, flags
, SYNTHETIC_ERRNO(EINVAL
), "JSON field '%s' is not a string or array of strings.", strna(name
));
714 JSON_VARIANT_ARRAY_FOREACH(e
, variant
) {
717 if (!json_variant_is_string(e
))
718 return json_log(e
, flags
, SYNTHETIC_ERRNO(EINVAL
), "JSON array element is not a string.");
720 n
= json_variant_string(e
);
721 if (!pkcs11_uri_valid(n
))
722 return json_log(variant
, flags
, SYNTHETIC_ERRNO(EINVAL
), "JSON array element in '%s' is not a valid RFC7512 PKCS#11 URI: %s", strna(name
), n
);
724 r
= strv_extend(&z
, n
);
730 strv_free_and_replace(*l
, z
);
734 static int dispatch_pkcs11_key_data(const char *name
, JsonVariant
*variant
, JsonDispatchFlags flags
, void *userdata
) {
735 Pkcs11EncryptedKey
*k
= userdata
;
740 if (json_variant_is_null(variant
)) {
741 k
->data
= erase_and_free(k
->data
);
746 if (!json_variant_is_string(variant
))
747 return json_log(variant
, flags
, SYNTHETIC_ERRNO(EINVAL
), "JSON field '%s' is not a string.", strna(name
));
749 r
= unbase64mem(json_variant_string(variant
), SIZE_MAX
, &b
, &l
);
751 return json_log(variant
, flags
, r
, "Failed to decode encrypted PKCS#11 key: %m");
753 erase_and_free(k
->data
);
760 static int dispatch_pkcs11_key(const char *name
, JsonVariant
*variant
, JsonDispatchFlags flags
, void *userdata
) {
761 UserRecord
*h
= userdata
;
765 if (!json_variant_is_array(variant
))
766 return json_log(variant
, flags
, SYNTHETIC_ERRNO(EINVAL
), "JSON field '%s' is not an array of objects.", strna(name
));
768 JSON_VARIANT_ARRAY_FOREACH(e
, variant
) {
769 Pkcs11EncryptedKey
*array
, *k
;
771 static const JsonDispatch pkcs11_key_dispatch_table
[] = {
772 { "uri", JSON_VARIANT_STRING
, dispatch_pkcs11_uri
, offsetof(Pkcs11EncryptedKey
, uri
), JSON_MANDATORY
},
773 { "data", JSON_VARIANT_STRING
, dispatch_pkcs11_key_data
, 0, JSON_MANDATORY
},
774 { "hashedPassword", JSON_VARIANT_STRING
, json_dispatch_string
, offsetof(Pkcs11EncryptedKey
, hashed_password
), JSON_MANDATORY
},
778 if (!json_variant_is_object(e
))
779 return json_log(e
, flags
, SYNTHETIC_ERRNO(EINVAL
), "JSON array element is not an object.");
781 array
= reallocarray(h
->pkcs11_encrypted_key
, h
->n_pkcs11_encrypted_key
+ 1, sizeof(Pkcs11EncryptedKey
));
785 h
->pkcs11_encrypted_key
= array
;
786 k
= h
->pkcs11_encrypted_key
+ h
->n_pkcs11_encrypted_key
;
787 *k
= (Pkcs11EncryptedKey
) {};
789 r
= json_dispatch(e
, pkcs11_key_dispatch_table
, flags
, k
);
791 pkcs11_encrypted_key_done(k
);
795 h
->n_pkcs11_encrypted_key
++;
801 static int dispatch_fido2_hmac_credential(const char *name
, JsonVariant
*variant
, JsonDispatchFlags flags
, void *userdata
) {
802 Fido2HmacCredential
*k
= userdata
;
807 if (json_variant_is_null(variant
)) {
808 k
->id
= mfree(k
->id
);
813 if (!json_variant_is_string(variant
))
814 return json_log(variant
, flags
, SYNTHETIC_ERRNO(EINVAL
), "JSON field '%s' is not a string.", strna(name
));
816 r
= unbase64mem(json_variant_string(variant
), SIZE_MAX
, &b
, &l
);
818 return json_log(variant
, flags
, r
, "Failed to decode FIDO2 credential ID: %m");
820 free_and_replace(k
->id
, b
);
826 static int dispatch_fido2_hmac_credential_array(const char *name
, JsonVariant
*variant
, JsonDispatchFlags flags
, void *userdata
) {
827 UserRecord
*h
= userdata
;
831 if (!json_variant_is_array(variant
))
832 return json_log(variant
, flags
, SYNTHETIC_ERRNO(EINVAL
), "JSON field '%s' is not an array of strings.", strna(name
));
834 JSON_VARIANT_ARRAY_FOREACH(e
, variant
) {
835 Fido2HmacCredential
*array
;
839 if (!json_variant_is_string(e
))
840 return json_log(e
, flags
, SYNTHETIC_ERRNO(EINVAL
), "JSON array element is not a string.");
842 array
= reallocarray(h
->fido2_hmac_credential
, h
->n_fido2_hmac_credential
+ 1, sizeof(Fido2HmacCredential
));
846 r
= unbase64mem(json_variant_string(e
), SIZE_MAX
, &b
, &l
);
848 return json_log(variant
, flags
, r
, "Failed to decode FIDO2 credential ID: %m");
850 h
->fido2_hmac_credential
= array
;
852 h
->fido2_hmac_credential
[h
->n_fido2_hmac_credential
++] = (Fido2HmacCredential
) {
861 static int dispatch_fido2_hmac_salt_value(const char *name
, JsonVariant
*variant
, JsonDispatchFlags flags
, void *userdata
) {
862 Fido2HmacSalt
*k
= userdata
;
867 if (json_variant_is_null(variant
)) {
868 k
->salt
= erase_and_free(k
->salt
);
873 if (!json_variant_is_string(variant
))
874 return json_log(variant
, flags
, SYNTHETIC_ERRNO(EINVAL
), "JSON field '%s' is not a string.", strna(name
));
876 r
= unbase64mem(json_variant_string(variant
), SIZE_MAX
, &b
, &l
);
878 return json_log(variant
, flags
, r
, "Failed to decode FIDO2 salt: %m");
880 erase_and_free(k
->salt
);
887 static int dispatch_fido2_hmac_salt(const char *name
, JsonVariant
*variant
, JsonDispatchFlags flags
, void *userdata
) {
888 UserRecord
*h
= userdata
;
892 if (!json_variant_is_array(variant
))
893 return json_log(variant
, flags
, SYNTHETIC_ERRNO(EINVAL
), "JSON field '%s' is not an array of objects.", strna(name
));
895 JSON_VARIANT_ARRAY_FOREACH(e
, variant
) {
896 Fido2HmacSalt
*array
, *k
;
898 static const JsonDispatch fido2_hmac_salt_dispatch_table
[] = {
899 { "credential", JSON_VARIANT_STRING
, dispatch_fido2_hmac_credential
, offsetof(Fido2HmacSalt
, credential
), JSON_MANDATORY
},
900 { "salt", JSON_VARIANT_STRING
, dispatch_fido2_hmac_salt_value
, 0, JSON_MANDATORY
},
901 { "hashedPassword", JSON_VARIANT_STRING
, json_dispatch_string
, offsetof(Fido2HmacSalt
, hashed_password
), JSON_MANDATORY
},
902 { "up", JSON_VARIANT_BOOLEAN
, json_dispatch_tristate
, offsetof(Fido2HmacSalt
, up
), 0 },
903 { "uv", JSON_VARIANT_BOOLEAN
, json_dispatch_tristate
, offsetof(Fido2HmacSalt
, uv
), 0 },
904 { "clientPin", JSON_VARIANT_BOOLEAN
, json_dispatch_tristate
, offsetof(Fido2HmacSalt
, client_pin
), 0 },
908 if (!json_variant_is_object(e
))
909 return json_log(e
, flags
, SYNTHETIC_ERRNO(EINVAL
), "JSON array element is not an object.");
911 array
= reallocarray(h
->fido2_hmac_salt
, h
->n_fido2_hmac_salt
+ 1, sizeof(Fido2HmacSalt
));
915 h
->fido2_hmac_salt
= array
;
916 k
= h
->fido2_hmac_salt
+ h
->n_fido2_hmac_salt
;
917 *k
= (Fido2HmacSalt
) {
923 r
= json_dispatch(e
, fido2_hmac_salt_dispatch_table
, flags
, k
);
925 fido2_hmac_salt_done(k
);
929 h
->n_fido2_hmac_salt
++;
935 static int dispatch_recovery_key(const char *name
, JsonVariant
*variant
, JsonDispatchFlags flags
, void *userdata
) {
936 UserRecord
*h
= userdata
;
940 if (!json_variant_is_array(variant
))
941 return json_log(variant
, flags
, SYNTHETIC_ERRNO(EINVAL
), "JSON field '%s' is not an array of objects.", strna(name
));
943 JSON_VARIANT_ARRAY_FOREACH(e
, variant
) {
944 RecoveryKey
*array
, *k
;
946 static const JsonDispatch recovery_key_dispatch_table
[] = {
947 { "type", JSON_VARIANT_STRING
, json_dispatch_string
, 0, JSON_MANDATORY
},
948 { "hashedPassword", JSON_VARIANT_STRING
, json_dispatch_string
, offsetof(RecoveryKey
, hashed_password
), JSON_MANDATORY
},
952 if (!json_variant_is_object(e
))
953 return json_log(e
, flags
, SYNTHETIC_ERRNO(EINVAL
), "JSON array element is not an object.");
955 array
= reallocarray(h
->recovery_key
, h
->n_recovery_key
+ 1, sizeof(RecoveryKey
));
959 h
->recovery_key
= array
;
960 k
= h
->recovery_key
+ h
->n_recovery_key
;
961 *k
= (RecoveryKey
) {};
963 r
= json_dispatch(e
, recovery_key_dispatch_table
, flags
, k
);
965 recovery_key_done(k
);
975 static int dispatch_auto_resize_mode(const char *name
, JsonVariant
*variant
, JsonDispatchFlags flags
, void *userdata
) {
976 AutoResizeMode
*mode
= userdata
, m
;
980 if (json_variant_is_null(variant
)) {
981 *mode
= _AUTO_RESIZE_MODE_INVALID
;
985 if (json_variant_is_boolean(variant
)) {
986 *mode
= json_variant_boolean(variant
) ? AUTO_RESIZE_SHRINK_AND_GROW
: AUTO_RESIZE_OFF
;
990 if (!json_variant_is_string(variant
))
991 return json_log(variant
, flags
, SYNTHETIC_ERRNO(EINVAL
), "JSON field '%s' is not a string, boolean or null.", strna(name
));
993 m
= auto_resize_mode_from_string(json_variant_string(variant
));
995 return json_log(variant
, flags
, SYNTHETIC_ERRNO(EINVAL
), "JSON field '%s' is not a valid automatic resize mode.", strna(name
));
1001 static int dispatch_rebalance_weight(const char *name
, JsonVariant
*variant
, JsonDispatchFlags flags
, void *userdata
) {
1002 uint64_t *rebalance_weight
= userdata
;
1005 assert_se(rebalance_weight
);
1007 if (json_variant_is_null(variant
)) {
1008 *rebalance_weight
= REBALANCE_WEIGHT_UNSET
;
1012 if (json_variant_is_boolean(variant
)) {
1013 *rebalance_weight
= json_variant_boolean(variant
) ? REBALANCE_WEIGHT_DEFAULT
: REBALANCE_WEIGHT_OFF
;
1017 if (!json_variant_is_unsigned(variant
))
1018 return json_log(variant
, flags
, SYNTHETIC_ERRNO(EINVAL
), "JSON field '%s' is not an unsigned integer, boolean or null.", strna(name
));
1020 u
= json_variant_unsigned(variant
);
1021 if (u
>= REBALANCE_WEIGHT_MIN
&& u
<= REBALANCE_WEIGHT_MAX
)
1022 *rebalance_weight
= (uint64_t) u
;
1024 *rebalance_weight
= REBALANCE_WEIGHT_OFF
;
1026 return json_log(variant
, flags
, SYNTHETIC_ERRNO(ERANGE
),
1027 "Rebalance weight is out of valid range %" PRIu64
"%s%" PRIu64
".",
1028 REBALANCE_WEIGHT_MIN
, special_glyph(SPECIAL_GLYPH_ELLIPSIS
), REBALANCE_WEIGHT_MAX
);
1033 static int dispatch_privileged(const char *name
, JsonVariant
*variant
, JsonDispatchFlags flags
, void *userdata
) {
1035 static const JsonDispatch privileged_dispatch_table
[] = {
1036 { "passwordHint", JSON_VARIANT_STRING
, json_dispatch_string
, offsetof(UserRecord
, password_hint
), 0 },
1037 { "hashedPassword", _JSON_VARIANT_TYPE_INVALID
, json_dispatch_strv
, offsetof(UserRecord
, hashed_password
), JSON_SAFE
},
1038 { "sshAuthorizedKeys", _JSON_VARIANT_TYPE_INVALID
, json_dispatch_strv
, offsetof(UserRecord
, ssh_authorized_keys
), 0 },
1039 { "pkcs11EncryptedKey", JSON_VARIANT_ARRAY
, dispatch_pkcs11_key
, 0, 0 },
1040 { "fido2HmacSalt", JSON_VARIANT_ARRAY
, dispatch_fido2_hmac_salt
, 0, 0 },
1041 { "recoveryKey", JSON_VARIANT_ARRAY
, dispatch_recovery_key
, 0, 0 },
1045 return json_dispatch(variant
, privileged_dispatch_table
, flags
, userdata
);
1048 static int dispatch_binding(const char *name
, JsonVariant
*variant
, JsonDispatchFlags flags
, void *userdata
) {
1050 static const JsonDispatch binding_dispatch_table
[] = {
1051 { "imagePath", JSON_VARIANT_STRING
, json_dispatch_image_path
, offsetof(UserRecord
, image_path
), 0 },
1052 { "homeDirectory", JSON_VARIANT_STRING
, json_dispatch_home_directory
, offsetof(UserRecord
, home_directory
), 0 },
1053 { "partitionUuid", JSON_VARIANT_STRING
, json_dispatch_id128
, offsetof(UserRecord
, partition_uuid
), 0 },
1054 { "luksUuid", JSON_VARIANT_STRING
, json_dispatch_id128
, offsetof(UserRecord
, luks_uuid
), 0 },
1055 { "fileSystemUuid", JSON_VARIANT_STRING
, json_dispatch_id128
, offsetof(UserRecord
, file_system_uuid
), 0 },
1056 { "uid", JSON_VARIANT_UNSIGNED
, json_dispatch_uid_gid
, offsetof(UserRecord
, uid
), 0 },
1057 { "gid", JSON_VARIANT_UNSIGNED
, json_dispatch_uid_gid
, offsetof(UserRecord
, gid
), 0 },
1058 { "storage", JSON_VARIANT_STRING
, json_dispatch_storage
, offsetof(UserRecord
, storage
), 0 },
1059 { "fileSystemType", JSON_VARIANT_STRING
, json_dispatch_string
, offsetof(UserRecord
, file_system_type
), JSON_SAFE
},
1060 { "luksCipher", JSON_VARIANT_STRING
, json_dispatch_string
, offsetof(UserRecord
, luks_cipher
), JSON_SAFE
},
1061 { "luksCipherMode", JSON_VARIANT_STRING
, json_dispatch_string
, offsetof(UserRecord
, luks_cipher_mode
), JSON_SAFE
},
1062 { "luksVolumeKeySize", JSON_VARIANT_UNSIGNED
, json_dispatch_uint64
, offsetof(UserRecord
, luks_volume_key_size
), 0 },
1073 if (!json_variant_is_object(variant
))
1074 return json_log(variant
, flags
, SYNTHETIC_ERRNO(EINVAL
), "JSON field '%s' is not an object.", strna(name
));
1076 r
= sd_id128_get_machine(&mid
);
1078 return json_log(variant
, flags
, r
, "Failed to determine machine ID: %m");
1080 m
= json_variant_by_key(variant
, SD_ID128_TO_STRING(mid
));
1084 return json_dispatch(m
, binding_dispatch_table
, flags
, userdata
);
1087 int per_machine_id_match(JsonVariant
*ids
, JsonDispatchFlags flags
) {
1091 r
= sd_id128_get_machine(&mid
);
1093 return json_log(ids
, flags
, r
, "Failed to acquire machine ID: %m");
1095 if (json_variant_is_string(ids
)) {
1098 r
= sd_id128_from_string(json_variant_string(ids
), &k
);
1100 json_log(ids
, flags
, r
, "%s is not a valid machine ID, ignoring: %m", json_variant_string(ids
));
1104 return sd_id128_equal(mid
, k
);
1107 if (json_variant_is_array(ids
)) {
1110 JSON_VARIANT_ARRAY_FOREACH(e
, ids
) {
1113 if (!json_variant_is_string(e
)) {
1114 json_log(e
, flags
, 0, "Machine ID is not a string, ignoring: %m");
1118 r
= sd_id128_from_string(json_variant_string(e
), &k
);
1120 json_log(e
, flags
, r
, "%s is not a valid machine ID, ignoring: %m", json_variant_string(e
));
1124 if (sd_id128_equal(mid
, k
))
1131 json_log(ids
, flags
, 0, "Machine ID is not a string or array of strings, ignoring: %m");
1135 int per_machine_hostname_match(JsonVariant
*hns
, JsonDispatchFlags flags
) {
1136 _cleanup_free_
char *hn
= NULL
;
1139 r
= gethostname_strict(&hn
);
1141 json_log(hns
, flags
, r
, "No hostname set, not matching perMachine hostname record: %m");
1145 return json_log(hns
, flags
, r
, "Failed to acquire hostname: %m");
1147 if (json_variant_is_string(hns
))
1148 return streq(json_variant_string(hns
), hn
);
1150 if (json_variant_is_array(hns
)) {
1153 JSON_VARIANT_ARRAY_FOREACH(e
, hns
) {
1155 if (!json_variant_is_string(e
)) {
1156 json_log(e
, flags
, 0, "Hostname is not a string, ignoring: %m");
1160 if (streq(json_variant_string(hns
), hn
))
1167 json_log(hns
, flags
, 0, "Hostname is not a string or array of strings, ignoring: %m");
1171 static int dispatch_per_machine(const char *name
, JsonVariant
*variant
, JsonDispatchFlags flags
, void *userdata
) {
1173 static const JsonDispatch per_machine_dispatch_table
[] = {
1174 { "matchMachineId", _JSON_VARIANT_TYPE_INVALID
, NULL
, 0, 0 },
1175 { "matchHostname", _JSON_VARIANT_TYPE_INVALID
, NULL
, 0, 0 },
1176 { "iconName", JSON_VARIANT_STRING
, json_dispatch_string
, offsetof(UserRecord
, icon_name
), JSON_SAFE
},
1177 { "location", JSON_VARIANT_STRING
, json_dispatch_string
, offsetof(UserRecord
, location
), 0 },
1178 { "shell", JSON_VARIANT_STRING
, json_dispatch_filename_or_path
, offsetof(UserRecord
, shell
), 0 },
1179 { "umask", JSON_VARIANT_UNSIGNED
, json_dispatch_umask
, offsetof(UserRecord
, umask
), 0 },
1180 { "environment", JSON_VARIANT_ARRAY
, json_dispatch_environment
, offsetof(UserRecord
, environment
), 0 },
1181 { "timeZone", JSON_VARIANT_STRING
, json_dispatch_string
, offsetof(UserRecord
, time_zone
), JSON_SAFE
},
1182 { "preferredLanguage", JSON_VARIANT_STRING
, json_dispatch_string
, offsetof(UserRecord
, preferred_language
), JSON_SAFE
},
1183 { "niceLevel", _JSON_VARIANT_TYPE_INVALID
, json_dispatch_nice
, offsetof(UserRecord
, nice_level
), 0 },
1184 { "resourceLimits", _JSON_VARIANT_TYPE_INVALID
, json_dispatch_rlimits
, offsetof(UserRecord
, rlimits
), 0 },
1185 { "locked", JSON_VARIANT_BOOLEAN
, json_dispatch_tristate
, offsetof(UserRecord
, locked
), 0 },
1186 { "notBeforeUSec", JSON_VARIANT_UNSIGNED
, json_dispatch_uint64
, offsetof(UserRecord
, not_before_usec
), 0 },
1187 { "notAfterUSec", JSON_VARIANT_UNSIGNED
, json_dispatch_uint64
, offsetof(UserRecord
, not_after_usec
), 0 },
1188 { "storage", JSON_VARIANT_STRING
, json_dispatch_storage
, offsetof(UserRecord
, storage
), 0 },
1189 { "diskSize", JSON_VARIANT_UNSIGNED
, json_dispatch_uint64
, offsetof(UserRecord
, disk_size
), 0 },
1190 { "diskSizeRelative", JSON_VARIANT_UNSIGNED
, json_dispatch_uint64
, offsetof(UserRecord
, disk_size_relative
), 0 },
1191 { "skeletonDirectory", JSON_VARIANT_STRING
, json_dispatch_path
, offsetof(UserRecord
, skeleton_directory
), 0 },
1192 { "accessMode", JSON_VARIANT_UNSIGNED
, json_dispatch_access_mode
, offsetof(UserRecord
, access_mode
), 0 },
1193 { "tasksMax", JSON_VARIANT_UNSIGNED
, json_dispatch_tasks_or_memory_max
, offsetof(UserRecord
, tasks_max
), 0 },
1194 { "memoryHigh", JSON_VARIANT_UNSIGNED
, json_dispatch_tasks_or_memory_max
, offsetof(UserRecord
, memory_high
), 0 },
1195 { "memoryMax", JSON_VARIANT_UNSIGNED
, json_dispatch_tasks_or_memory_max
, offsetof(UserRecord
, memory_max
), 0 },
1196 { "cpuWeight", JSON_VARIANT_UNSIGNED
, json_dispatch_weight
, offsetof(UserRecord
, cpu_weight
), 0 },
1197 { "ioWeight", JSON_VARIANT_UNSIGNED
, json_dispatch_weight
, offsetof(UserRecord
, io_weight
), 0 },
1198 { "mountNoDevices", JSON_VARIANT_BOOLEAN
, json_dispatch_boolean
, offsetof(UserRecord
, nodev
), 0 },
1199 { "mountNoSuid", JSON_VARIANT_BOOLEAN
, json_dispatch_boolean
, offsetof(UserRecord
, nosuid
), 0 },
1200 { "mountNoExecute", JSON_VARIANT_BOOLEAN
, json_dispatch_boolean
, offsetof(UserRecord
, noexec
), 0 },
1201 { "cifsDomain", JSON_VARIANT_STRING
, json_dispatch_string
, offsetof(UserRecord
, cifs_domain
), JSON_SAFE
},
1202 { "cifsUserName", JSON_VARIANT_STRING
, json_dispatch_string
, offsetof(UserRecord
, cifs_user_name
), JSON_SAFE
},
1203 { "cifsService", JSON_VARIANT_STRING
, json_dispatch_string
, offsetof(UserRecord
, cifs_service
), JSON_SAFE
},
1204 { "cifsExtraMountOptions", JSON_VARIANT_STRING
, json_dispatch_string
, offsetof(UserRecord
, cifs_extra_mount_options
), 0 },
1205 { "imagePath", JSON_VARIANT_STRING
, json_dispatch_path
, offsetof(UserRecord
, image_path
), 0 },
1206 { "uid", JSON_VARIANT_UNSIGNED
, json_dispatch_uid_gid
, offsetof(UserRecord
, uid
), 0 },
1207 { "gid", JSON_VARIANT_UNSIGNED
, json_dispatch_uid_gid
, offsetof(UserRecord
, gid
), 0 },
1208 { "memberOf", JSON_VARIANT_ARRAY
, json_dispatch_user_group_list
, offsetof(UserRecord
, member_of
), JSON_RELAX
},
1209 { "capabilityBoundingSet", JSON_VARIANT_ARRAY
, json_dispatch_strv
, offsetof(UserRecord
, capability_bounding_set
), JSON_SAFE
},
1210 { "capabilityAmbientSet", JSON_VARIANT_ARRAY
, json_dispatch_strv
, offsetof(UserRecord
, capability_ambient_set
), JSON_SAFE
},
1211 { "fileSystemType", JSON_VARIANT_STRING
, json_dispatch_string
, offsetof(UserRecord
, file_system_type
), JSON_SAFE
},
1212 { "partitionUuid", JSON_VARIANT_STRING
, json_dispatch_id128
, offsetof(UserRecord
, partition_uuid
), 0 },
1213 { "luksUuid", JSON_VARIANT_STRING
, json_dispatch_id128
, offsetof(UserRecord
, luks_uuid
), 0 },
1214 { "fileSystemUuid", JSON_VARIANT_STRING
, json_dispatch_id128
, offsetof(UserRecord
, file_system_uuid
), 0 },
1215 { "luksDiscard", _JSON_VARIANT_TYPE_INVALID
, json_dispatch_tristate
, offsetof(UserRecord
, luks_discard
), 0, },
1216 { "luksOfflineDiscard", _JSON_VARIANT_TYPE_INVALID
, json_dispatch_tristate
, offsetof(UserRecord
, luks_offline_discard
), 0, },
1217 { "luksCipher", JSON_VARIANT_STRING
, json_dispatch_string
, offsetof(UserRecord
, luks_cipher
), JSON_SAFE
},
1218 { "luksCipherMode", JSON_VARIANT_STRING
, json_dispatch_string
, offsetof(UserRecord
, luks_cipher_mode
), JSON_SAFE
},
1219 { "luksVolumeKeySize", JSON_VARIANT_UNSIGNED
, json_dispatch_uint64
, offsetof(UserRecord
, luks_volume_key_size
), 0 },
1220 { "luksPbkdfHashAlgorithm", JSON_VARIANT_STRING
, json_dispatch_string
, offsetof(UserRecord
, luks_pbkdf_hash_algorithm
), JSON_SAFE
},
1221 { "luksPbkdfType", JSON_VARIANT_STRING
, json_dispatch_string
, offsetof(UserRecord
, luks_pbkdf_type
), JSON_SAFE
},
1222 { "luksPbkdfForceIterations", JSON_VARIANT_UNSIGNED
, json_dispatch_uint64
, offsetof(UserRecord
, luks_pbkdf_force_iterations
), 0 },
1223 { "luksPbkdfTimeCostUSec", JSON_VARIANT_UNSIGNED
, json_dispatch_uint64
, offsetof(UserRecord
, luks_pbkdf_time_cost_usec
), 0 },
1224 { "luksPbkdfMemoryCost", JSON_VARIANT_UNSIGNED
, json_dispatch_uint64
, offsetof(UserRecord
, luks_pbkdf_memory_cost
), 0 },
1225 { "luksPbkdfParallelThreads", JSON_VARIANT_UNSIGNED
, json_dispatch_uint64
, offsetof(UserRecord
, luks_pbkdf_parallel_threads
), 0 },
1226 { "luksSectorSize", JSON_VARIANT_UNSIGNED
, json_dispatch_uint64
, offsetof(UserRecord
, luks_sector_size
), 0 },
1227 { "luksExtraMountOptions", JSON_VARIANT_STRING
, json_dispatch_string
, offsetof(UserRecord
, luks_extra_mount_options
), 0 },
1228 { "dropCaches", JSON_VARIANT_BOOLEAN
, json_dispatch_tristate
, offsetof(UserRecord
, drop_caches
), 0 },
1229 { "autoResizeMode", _JSON_VARIANT_TYPE_INVALID
, dispatch_auto_resize_mode
, offsetof(UserRecord
, auto_resize_mode
), 0 },
1230 { "rebalanceWeight", _JSON_VARIANT_TYPE_INVALID
, dispatch_rebalance_weight
, offsetof(UserRecord
, rebalance_weight
), 0 },
1231 { "rateLimitIntervalUSec", JSON_VARIANT_UNSIGNED
, json_dispatch_uint64
, offsetof(UserRecord
, ratelimit_interval_usec
), 0 },
1232 { "rateLimitBurst", JSON_VARIANT_UNSIGNED
, json_dispatch_uint64
, offsetof(UserRecord
, ratelimit_burst
), 0 },
1233 { "enforcePasswordPolicy", JSON_VARIANT_BOOLEAN
, json_dispatch_tristate
, offsetof(UserRecord
, enforce_password_policy
), 0 },
1234 { "autoLogin", JSON_VARIANT_BOOLEAN
, json_dispatch_tristate
, offsetof(UserRecord
, auto_login
), 0 },
1235 { "stopDelayUSec", JSON_VARIANT_UNSIGNED
, json_dispatch_uint64
, offsetof(UserRecord
, stop_delay_usec
), 0 },
1236 { "killProcesses", JSON_VARIANT_BOOLEAN
, json_dispatch_tristate
, offsetof(UserRecord
, kill_processes
), 0 },
1237 { "passwordChangeMinUSec", JSON_VARIANT_UNSIGNED
, json_dispatch_uint64
, offsetof(UserRecord
, password_change_min_usec
), 0 },
1238 { "passwordChangeMaxUSec", JSON_VARIANT_UNSIGNED
, json_dispatch_uint64
, offsetof(UserRecord
, password_change_max_usec
), 0 },
1239 { "passwordChangeWarnUSec", JSON_VARIANT_UNSIGNED
, json_dispatch_uint64
, offsetof(UserRecord
, password_change_warn_usec
), 0 },
1240 { "passwordChangeInactiveUSec", JSON_VARIANT_UNSIGNED
, json_dispatch_uint64
, offsetof(UserRecord
, password_change_inactive_usec
), 0 },
1241 { "passwordChangeNow", JSON_VARIANT_BOOLEAN
, json_dispatch_tristate
, offsetof(UserRecord
, password_change_now
), 0 },
1242 { "pkcs11TokenUri", JSON_VARIANT_ARRAY
, dispatch_pkcs11_uri_array
, offsetof(UserRecord
, pkcs11_token_uri
), 0 },
1243 { "fido2HmacCredential", JSON_VARIANT_ARRAY
, dispatch_fido2_hmac_credential_array
, 0, 0 },
1253 if (!json_variant_is_array(variant
))
1254 return json_log(variant
, flags
, SYNTHETIC_ERRNO(EINVAL
), "JSON field '%s' is not an array.", strna(name
));
1256 JSON_VARIANT_ARRAY_FOREACH(e
, variant
) {
1257 bool matching
= false;
1260 if (!json_variant_is_object(e
))
1261 return json_log(variant
, flags
, SYNTHETIC_ERRNO(EINVAL
), "JSON field '%s' is not an array of objects.", strna(name
));
1263 m
= json_variant_by_key(e
, "matchMachineId");
1265 r
= per_machine_id_match(m
, flags
);
1273 m
= json_variant_by_key(e
, "matchHostname");
1275 r
= per_machine_hostname_match(m
, flags
);
1286 r
= json_dispatch(e
, per_machine_dispatch_table
, flags
, userdata
);
1294 static int dispatch_status(const char *name
, JsonVariant
*variant
, JsonDispatchFlags flags
, void *userdata
) {
1296 static const JsonDispatch status_dispatch_table
[] = {
1297 { "diskUsage", JSON_VARIANT_UNSIGNED
, json_dispatch_uint64
, offsetof(UserRecord
, disk_usage
), 0 },
1298 { "diskFree", JSON_VARIANT_UNSIGNED
, json_dispatch_uint64
, offsetof(UserRecord
, disk_free
), 0 },
1299 { "diskSize", JSON_VARIANT_UNSIGNED
, json_dispatch_uint64
, offsetof(UserRecord
, disk_size
), 0 },
1300 { "diskCeiling", JSON_VARIANT_UNSIGNED
, json_dispatch_uint64
, offsetof(UserRecord
, disk_ceiling
), 0 },
1301 { "diskFloor", JSON_VARIANT_UNSIGNED
, json_dispatch_uint64
, offsetof(UserRecord
, disk_floor
), 0 },
1302 { "state", JSON_VARIANT_STRING
, json_dispatch_string
, offsetof(UserRecord
, state
), JSON_SAFE
},
1303 { "service", JSON_VARIANT_STRING
, json_dispatch_string
, offsetof(UserRecord
, service
), JSON_SAFE
},
1304 { "signedLocally", _JSON_VARIANT_TYPE_INVALID
, json_dispatch_tristate
, offsetof(UserRecord
, signed_locally
), 0 },
1305 { "goodAuthenticationCounter", JSON_VARIANT_UNSIGNED
, json_dispatch_uint64
, offsetof(UserRecord
, good_authentication_counter
), 0 },
1306 { "badAuthenticationCounter", JSON_VARIANT_UNSIGNED
, json_dispatch_uint64
, offsetof(UserRecord
, bad_authentication_counter
), 0 },
1307 { "lastGoodAuthenticationUSec", JSON_VARIANT_UNSIGNED
, json_dispatch_uint64
, offsetof(UserRecord
, last_good_authentication_usec
), 0 },
1308 { "lastBadAuthenticationUSec", JSON_VARIANT_UNSIGNED
, json_dispatch_uint64
, offsetof(UserRecord
, last_bad_authentication_usec
), 0 },
1309 { "rateLimitBeginUSec", JSON_VARIANT_UNSIGNED
, json_dispatch_uint64
, offsetof(UserRecord
, ratelimit_begin_usec
), 0 },
1310 { "rateLimitCount", JSON_VARIANT_UNSIGNED
, json_dispatch_uint64
, offsetof(UserRecord
, ratelimit_count
), 0 },
1311 { "removable", JSON_VARIANT_BOOLEAN
, json_dispatch_boolean
, offsetof(UserRecord
, removable
), 0 },
1312 { "accessMode", JSON_VARIANT_UNSIGNED
, json_dispatch_access_mode
, offsetof(UserRecord
, access_mode
), 0 },
1313 { "fileSystemType", JSON_VARIANT_STRING
, json_dispatch_string
, offsetof(UserRecord
, file_system_type
), JSON_SAFE
},
1324 if (!json_variant_is_object(variant
))
1325 return json_log(variant
, flags
, SYNTHETIC_ERRNO(EINVAL
), "JSON field '%s' is not an object.", strna(name
));
1327 r
= sd_id128_get_machine(&mid
);
1329 return json_log(variant
, flags
, r
, "Failed to determine machine ID: %m");
1331 m
= json_variant_by_key(variant
, SD_ID128_TO_STRING(mid
));
1335 return json_dispatch(m
, status_dispatch_table
, flags
, userdata
);
1338 int user_record_build_image_path(UserStorage storage
, const char *user_name_and_realm
, char **ret
) {
1342 assert(storage
>= 0);
1343 assert(user_name_and_realm
);
1346 if (storage
== USER_LUKS
)
1348 else if (IN_SET(storage
, USER_DIRECTORY
, USER_SUBVOLUME
, USER_FSCRYPT
))
1349 suffix
= ".homedir";
1355 z
= strjoin(get_home_root(), "/", user_name_and_realm
, suffix
);
1359 *ret
= path_simplify(z
);
1363 static int user_record_augment(UserRecord
*h
, JsonDispatchFlags json_flags
) {
1368 if (!FLAGS_SET(h
->mask
, USER_RECORD_REGULAR
))
1371 assert(h
->user_name
);
1373 if (!h
->user_name_and_realm_auto
&& h
->realm
) {
1374 h
->user_name_and_realm_auto
= strjoin(h
->user_name
, "@", h
->realm
);
1375 if (!h
->user_name_and_realm_auto
)
1376 return json_log_oom(h
->json
, json_flags
);
1379 /* Let's add in the following automatisms only for regular users, they don't make sense for any others */
1380 if (user_record_disposition(h
) != USER_REGULAR
)
1383 if (!h
->home_directory
&& !h
->home_directory_auto
) {
1384 h
->home_directory_auto
= path_join(get_home_root(), h
->user_name
);
1385 if (!h
->home_directory_auto
)
1386 return json_log_oom(h
->json
, json_flags
);
1389 if (!h
->image_path
&& !h
->image_path_auto
) {
1390 r
= user_record_build_image_path(user_record_storage(h
), user_record_user_name_and_realm(h
), &h
->image_path_auto
);
1392 return json_log(h
->json
, json_flags
, r
, "Failed to determine default image path: %m");
1398 int user_group_record_mangle(
1400 UserRecordLoadFlags load_flags
,
1401 JsonVariant
**ret_variant
,
1402 UserRecordMask
*ret_mask
) {
1404 static const struct {
1405 UserRecordMask mask
;
1408 { USER_RECORD_PRIVILEGED
, "privileged" },
1409 { USER_RECORD_SECRET
, "secret" },
1410 { USER_RECORD_BINDING
, "binding" },
1411 { USER_RECORD_PER_MACHINE
, "perMachine" },
1412 { USER_RECORD_STATUS
, "status" },
1413 { USER_RECORD_SIGNATURE
, "signature" },
1416 JsonDispatchFlags json_flags
= USER_RECORD_LOAD_FLAGS_TO_JSON_DISPATCH_FLAGS(load_flags
);
1417 _cleanup_(json_variant_unrefp
) JsonVariant
*w
= NULL
;
1418 JsonVariant
*array
[ELEMENTSOF(mask_field
) * 2];
1419 size_t n_retain
= 0;
1420 UserRecordMask m
= 0;
1423 assert((load_flags
& _USER_RECORD_MASK_MAX
) == 0); /* detect mistakes when accidentally passing
1424 * UserRecordMask bit masks as UserRecordLoadFlags
1428 assert(ret_variant
);
1431 /* Note that this function is shared with the group record parser, hence we try to be generic in our
1432 * log message wording here, to cover both cases. */
1434 if (!json_variant_is_object(v
))
1435 return json_log(v
, json_flags
, SYNTHETIC_ERRNO(EBADMSG
), "Record is not a JSON object, refusing.");
1437 if (USER_RECORD_ALLOW_MASK(load_flags
) == 0) /* allow nothing? */
1438 return json_log(v
, json_flags
, SYNTHETIC_ERRNO(EINVAL
), "Nothing allowed in record, refusing.");
1440 if (USER_RECORD_STRIP_MASK(load_flags
) == _USER_RECORD_MASK_MAX
) /* strip everything? */
1441 return json_log(v
, json_flags
, SYNTHETIC_ERRNO(EINVAL
), "Stripping everything from record, refusing.");
1443 /* Check if we have the special sections and if they match our flags set */
1444 for (size_t i
= 0; i
< ELEMENTSOF(mask_field
); i
++) {
1447 if (FLAGS_SET(USER_RECORD_STRIP_MASK(load_flags
), mask_field
[i
].mask
)) {
1449 w
= json_variant_ref(v
);
1451 r
= json_variant_filter(&w
, STRV_MAKE(mask_field
[i
].name
));
1453 return json_log(w
, json_flags
, r
, "Failed to remove field from variant: %m");
1458 e
= json_variant_by_key_full(v
, mask_field
[i
].name
, &k
);
1460 if (!FLAGS_SET(USER_RECORD_ALLOW_MASK(load_flags
), mask_field
[i
].mask
))
1461 return json_log(e
, json_flags
, SYNTHETIC_ERRNO(EBADMSG
), "Record contains '%s' field, which is not allowed.", mask_field
[i
].name
);
1463 if (FLAGS_SET(load_flags
, USER_RECORD_STRIP_REGULAR
)) {
1464 array
[n_retain
++] = k
;
1465 array
[n_retain
++] = e
;
1468 m
|= mask_field
[i
].mask
;
1470 if (FLAGS_SET(USER_RECORD_REQUIRE_MASK(load_flags
), mask_field
[i
].mask
))
1471 return json_log(v
, json_flags
, SYNTHETIC_ERRNO(EBADMSG
), "Record lacks '%s' field, which is required.", mask_field
[i
].name
);
1475 if (FLAGS_SET(load_flags
, USER_RECORD_STRIP_REGULAR
)) {
1476 /* If we are supposed to strip regular items, then let's instead just allocate a new object
1477 * with just the stuff we need. */
1479 w
= json_variant_unref(w
);
1480 r
= json_variant_new_object(&w
, array
, n_retain
);
1482 return json_log(v
, json_flags
, r
, "Failed to allocate new object: %m");
1484 /* And now check if there's anything else in the record */
1485 for (size_t i
= 0; i
< json_variant_elements(v
); i
+= 2) {
1487 bool special
= false;
1489 assert_se(f
= json_variant_string(json_variant_by_index(v
, i
)));
1491 for (size_t j
= 0; j
< ELEMENTSOF(mask_field
); j
++)
1492 if (streq(f
, mask_field
[j
].name
)) { /* already covered in the loop above */
1498 if ((load_flags
& (USER_RECORD_ALLOW_REGULAR
|USER_RECORD_REQUIRE_REGULAR
)) == 0)
1499 return json_log(v
, json_flags
, SYNTHETIC_ERRNO(EBADMSG
), "Record contains '%s' field, which is not allowed.", f
);
1501 m
|= USER_RECORD_REGULAR
;
1506 if (FLAGS_SET(load_flags
, USER_RECORD_REQUIRE_REGULAR
) && !FLAGS_SET(m
, USER_RECORD_REGULAR
))
1507 return json_log(v
, json_flags
, SYNTHETIC_ERRNO(EBADMSG
), "Record lacks basic identity fields, which are required.");
1509 if (!FLAGS_SET(load_flags
, USER_RECORD_EMPTY_OK
) && m
== 0)
1510 return json_log(v
, json_flags
, SYNTHETIC_ERRNO(EBADMSG
), "Record is empty.");
1513 *ret_variant
= TAKE_PTR(w
);
1515 *ret_variant
= json_variant_ref(v
);
1521 int user_record_load(UserRecord
*h
, JsonVariant
*v
, UserRecordLoadFlags load_flags
) {
1523 static const JsonDispatch user_dispatch_table
[] = {
1524 { "userName", JSON_VARIANT_STRING
, json_dispatch_user_group_name
, offsetof(UserRecord
, user_name
), JSON_RELAX
},
1525 { "realm", JSON_VARIANT_STRING
, json_dispatch_realm
, offsetof(UserRecord
, realm
), 0 },
1526 { "realName", JSON_VARIANT_STRING
, json_dispatch_gecos
, offsetof(UserRecord
, real_name
), 0 },
1527 { "emailAddress", JSON_VARIANT_STRING
, json_dispatch_string
, offsetof(UserRecord
, email_address
), JSON_SAFE
},
1528 { "iconName", JSON_VARIANT_STRING
, json_dispatch_string
, offsetof(UserRecord
, icon_name
), JSON_SAFE
},
1529 { "location", JSON_VARIANT_STRING
, json_dispatch_string
, offsetof(UserRecord
, location
), 0 },
1530 { "disposition", JSON_VARIANT_STRING
, json_dispatch_user_disposition
, offsetof(UserRecord
, disposition
), 0 },
1531 { "lastChangeUSec", JSON_VARIANT_UNSIGNED
, json_dispatch_uint64
, offsetof(UserRecord
, last_change_usec
), 0 },
1532 { "lastPasswordChangeUSec", JSON_VARIANT_UNSIGNED
, json_dispatch_uint64
, offsetof(UserRecord
, last_password_change_usec
), 0 },
1533 { "shell", JSON_VARIANT_STRING
, json_dispatch_filename_or_path
, offsetof(UserRecord
, shell
), 0 },
1534 { "umask", JSON_VARIANT_UNSIGNED
, json_dispatch_umask
, offsetof(UserRecord
, umask
), 0 },
1535 { "environment", JSON_VARIANT_ARRAY
, json_dispatch_environment
, offsetof(UserRecord
, environment
), 0 },
1536 { "timeZone", JSON_VARIANT_STRING
, json_dispatch_string
, offsetof(UserRecord
, time_zone
), JSON_SAFE
},
1537 { "preferredLanguage", JSON_VARIANT_STRING
, json_dispatch_string
, offsetof(UserRecord
, preferred_language
), JSON_SAFE
},
1538 { "niceLevel", _JSON_VARIANT_TYPE_INVALID
, json_dispatch_nice
, offsetof(UserRecord
, nice_level
), 0 },
1539 { "resourceLimits", _JSON_VARIANT_TYPE_INVALID
, json_dispatch_rlimits
, offsetof(UserRecord
, rlimits
), 0 },
1540 { "locked", JSON_VARIANT_BOOLEAN
, json_dispatch_tristate
, offsetof(UserRecord
, locked
), 0 },
1541 { "notBeforeUSec", JSON_VARIANT_UNSIGNED
, json_dispatch_uint64
, offsetof(UserRecord
, not_before_usec
), 0 },
1542 { "notAfterUSec", JSON_VARIANT_UNSIGNED
, json_dispatch_uint64
, offsetof(UserRecord
, not_after_usec
), 0 },
1543 { "storage", JSON_VARIANT_STRING
, json_dispatch_storage
, offsetof(UserRecord
, storage
), 0 },
1544 { "diskSize", JSON_VARIANT_UNSIGNED
, json_dispatch_uint64
, offsetof(UserRecord
, disk_size
), 0 },
1545 { "diskSizeRelative", JSON_VARIANT_UNSIGNED
, json_dispatch_uint64
, offsetof(UserRecord
, disk_size_relative
), 0 },
1546 { "skeletonDirectory", JSON_VARIANT_STRING
, json_dispatch_path
, offsetof(UserRecord
, skeleton_directory
), 0 },
1547 { "accessMode", JSON_VARIANT_UNSIGNED
, json_dispatch_access_mode
, offsetof(UserRecord
, access_mode
), 0 },
1548 { "tasksMax", JSON_VARIANT_UNSIGNED
, json_dispatch_tasks_or_memory_max
, offsetof(UserRecord
, tasks_max
), 0 },
1549 { "memoryHigh", JSON_VARIANT_UNSIGNED
, json_dispatch_tasks_or_memory_max
, offsetof(UserRecord
, memory_high
), 0 },
1550 { "memoryMax", JSON_VARIANT_UNSIGNED
, json_dispatch_tasks_or_memory_max
, offsetof(UserRecord
, memory_max
), 0 },
1551 { "cpuWeight", JSON_VARIANT_UNSIGNED
, json_dispatch_weight
, offsetof(UserRecord
, cpu_weight
), 0 },
1552 { "ioWeight", JSON_VARIANT_UNSIGNED
, json_dispatch_weight
, offsetof(UserRecord
, io_weight
), 0 },
1553 { "mountNoDevices", JSON_VARIANT_BOOLEAN
, json_dispatch_boolean
, offsetof(UserRecord
, nodev
), 0 },
1554 { "mountNoSuid", JSON_VARIANT_BOOLEAN
, json_dispatch_boolean
, offsetof(UserRecord
, nosuid
), 0 },
1555 { "mountNoExecute", JSON_VARIANT_BOOLEAN
, json_dispatch_boolean
, offsetof(UserRecord
, noexec
), 0 },
1556 { "cifsDomain", JSON_VARIANT_STRING
, json_dispatch_string
, offsetof(UserRecord
, cifs_domain
), JSON_SAFE
},
1557 { "cifsUserName", JSON_VARIANT_STRING
, json_dispatch_string
, offsetof(UserRecord
, cifs_user_name
), JSON_SAFE
},
1558 { "cifsService", JSON_VARIANT_STRING
, json_dispatch_string
, offsetof(UserRecord
, cifs_service
), JSON_SAFE
},
1559 { "cifsExtraMountOptions", JSON_VARIANT_STRING
, json_dispatch_string
, offsetof(UserRecord
, cifs_extra_mount_options
), 0 },
1560 { "imagePath", JSON_VARIANT_STRING
, json_dispatch_path
, offsetof(UserRecord
, image_path
), 0 },
1561 { "homeDirectory", JSON_VARIANT_STRING
, json_dispatch_home_directory
, offsetof(UserRecord
, home_directory
), 0 },
1562 { "uid", JSON_VARIANT_UNSIGNED
, json_dispatch_uid_gid
, offsetof(UserRecord
, uid
), 0 },
1563 { "gid", JSON_VARIANT_UNSIGNED
, json_dispatch_uid_gid
, offsetof(UserRecord
, gid
), 0 },
1564 { "memberOf", JSON_VARIANT_ARRAY
, json_dispatch_user_group_list
, offsetof(UserRecord
, member_of
), JSON_RELAX
},
1565 { "capabilityBoundingSet", JSON_VARIANT_ARRAY
, json_dispatch_strv
, offsetof(UserRecord
, capability_bounding_set
), JSON_SAFE
},
1566 { "capabilityAmbientSet", JSON_VARIANT_ARRAY
, json_dispatch_strv
, offsetof(UserRecord
, capability_ambient_set
), JSON_SAFE
},
1567 { "fileSystemType", JSON_VARIANT_STRING
, json_dispatch_string
, offsetof(UserRecord
, file_system_type
), JSON_SAFE
},
1568 { "partitionUuid", JSON_VARIANT_STRING
, json_dispatch_id128
, offsetof(UserRecord
, partition_uuid
), 0 },
1569 { "luksUuid", JSON_VARIANT_STRING
, json_dispatch_id128
, offsetof(UserRecord
, luks_uuid
), 0 },
1570 { "fileSystemUuid", JSON_VARIANT_STRING
, json_dispatch_id128
, offsetof(UserRecord
, file_system_uuid
), 0 },
1571 { "luksDiscard", _JSON_VARIANT_TYPE_INVALID
, json_dispatch_tristate
, offsetof(UserRecord
, luks_discard
), 0 },
1572 { "luksOfflineDiscard", _JSON_VARIANT_TYPE_INVALID
, json_dispatch_tristate
, offsetof(UserRecord
, luks_offline_discard
), 0 },
1573 { "luksCipher", JSON_VARIANT_STRING
, json_dispatch_string
, offsetof(UserRecord
, luks_cipher
), JSON_SAFE
},
1574 { "luksCipherMode", JSON_VARIANT_STRING
, json_dispatch_string
, offsetof(UserRecord
, luks_cipher_mode
), JSON_SAFE
},
1575 { "luksVolumeKeySize", JSON_VARIANT_UNSIGNED
, json_dispatch_uint64
, offsetof(UserRecord
, luks_volume_key_size
), 0 },
1576 { "luksPbkdfHashAlgorithm", JSON_VARIANT_STRING
, json_dispatch_string
, offsetof(UserRecord
, luks_pbkdf_hash_algorithm
), JSON_SAFE
},
1577 { "luksPbkdfType", JSON_VARIANT_STRING
, json_dispatch_string
, offsetof(UserRecord
, luks_pbkdf_type
), JSON_SAFE
},
1578 { "luksPbkdfForceIterations", JSON_VARIANT_UNSIGNED
, json_dispatch_uint64
, offsetof(UserRecord
, luks_pbkdf_force_iterations
), 0 },
1579 { "luksPbkdfTimeCostUSec", JSON_VARIANT_UNSIGNED
, json_dispatch_uint64
, offsetof(UserRecord
, luks_pbkdf_time_cost_usec
), 0 },
1580 { "luksPbkdfMemoryCost", JSON_VARIANT_UNSIGNED
, json_dispatch_uint64
, offsetof(UserRecord
, luks_pbkdf_memory_cost
), 0 },
1581 { "luksPbkdfParallelThreads", JSON_VARIANT_UNSIGNED
, json_dispatch_uint64
, offsetof(UserRecord
, luks_pbkdf_parallel_threads
), 0 },
1582 { "luksSectorSize", JSON_VARIANT_UNSIGNED
, json_dispatch_uint64
, offsetof(UserRecord
, luks_sector_size
), 0 },
1583 { "luksExtraMountOptions", JSON_VARIANT_STRING
, json_dispatch_string
, offsetof(UserRecord
, luks_extra_mount_options
), 0 },
1584 { "dropCaches", JSON_VARIANT_BOOLEAN
, json_dispatch_tristate
, offsetof(UserRecord
, drop_caches
), 0 },
1585 { "autoResizeMode", _JSON_VARIANT_TYPE_INVALID
, dispatch_auto_resize_mode
, offsetof(UserRecord
, auto_resize_mode
), 0 },
1586 { "rebalanceWeight", _JSON_VARIANT_TYPE_INVALID
, dispatch_rebalance_weight
, offsetof(UserRecord
, rebalance_weight
), 0 },
1587 { "service", JSON_VARIANT_STRING
, json_dispatch_string
, offsetof(UserRecord
, service
), JSON_SAFE
},
1588 { "rateLimitIntervalUSec", JSON_VARIANT_UNSIGNED
, json_dispatch_uint64
, offsetof(UserRecord
, ratelimit_interval_usec
), 0 },
1589 { "rateLimitBurst", JSON_VARIANT_UNSIGNED
, json_dispatch_uint64
, offsetof(UserRecord
, ratelimit_burst
), 0 },
1590 { "enforcePasswordPolicy", JSON_VARIANT_BOOLEAN
, json_dispatch_tristate
, offsetof(UserRecord
, enforce_password_policy
), 0 },
1591 { "autoLogin", JSON_VARIANT_BOOLEAN
, json_dispatch_tristate
, offsetof(UserRecord
, auto_login
), 0 },
1592 { "stopDelayUSec", JSON_VARIANT_UNSIGNED
, json_dispatch_uint64
, offsetof(UserRecord
, stop_delay_usec
), 0 },
1593 { "killProcesses", JSON_VARIANT_BOOLEAN
, json_dispatch_tristate
, offsetof(UserRecord
, kill_processes
), 0 },
1594 { "passwordChangeMinUSec", JSON_VARIANT_UNSIGNED
, json_dispatch_uint64
, offsetof(UserRecord
, password_change_min_usec
), 0 },
1595 { "passwordChangeMaxUSec", JSON_VARIANT_UNSIGNED
, json_dispatch_uint64
, offsetof(UserRecord
, password_change_max_usec
), 0 },
1596 { "passwordChangeWarnUSec", JSON_VARIANT_UNSIGNED
, json_dispatch_uint64
, offsetof(UserRecord
, password_change_warn_usec
), 0 },
1597 { "passwordChangeInactiveUSec", JSON_VARIANT_UNSIGNED
, json_dispatch_uint64
, offsetof(UserRecord
, password_change_inactive_usec
), 0 },
1598 { "passwordChangeNow", JSON_VARIANT_BOOLEAN
, json_dispatch_tristate
, offsetof(UserRecord
, password_change_now
), 0 },
1599 { "pkcs11TokenUri", JSON_VARIANT_ARRAY
, dispatch_pkcs11_uri_array
, offsetof(UserRecord
, pkcs11_token_uri
), 0 },
1600 { "fido2HmacCredential", JSON_VARIANT_ARRAY
, dispatch_fido2_hmac_credential_array
, 0, 0 },
1601 { "recoveryKeyType", JSON_VARIANT_ARRAY
, json_dispatch_strv
, offsetof(UserRecord
, recovery_key_type
), 0 },
1603 { "secret", JSON_VARIANT_OBJECT
, dispatch_secret
, 0, 0 },
1604 { "privileged", JSON_VARIANT_OBJECT
, dispatch_privileged
, 0, 0 },
1606 /* Ignore the perMachine, binding, status stuff here, and process it later, so that it overrides whatever is set above */
1607 { "perMachine", JSON_VARIANT_ARRAY
, NULL
, 0, 0 },
1608 { "binding", JSON_VARIANT_OBJECT
, NULL
, 0, 0 },
1609 { "status", JSON_VARIANT_OBJECT
, NULL
, 0, 0 },
1611 /* Ignore 'signature', we check it with explicit accessors instead */
1612 { "signature", JSON_VARIANT_ARRAY
, NULL
, 0, 0 },
1616 JsonDispatchFlags json_flags
= USER_RECORD_LOAD_FLAGS_TO_JSON_DISPATCH_FLAGS(load_flags
);
1622 /* Note that this call will leave a half-initialized record around on failure! */
1624 r
= user_group_record_mangle(v
, load_flags
, &h
->json
, &h
->mask
);
1628 r
= json_dispatch(h
->json
, user_dispatch_table
, json_flags
, h
);
1632 /* During the parsing operation above we ignored the 'perMachine', 'binding' and 'status' fields,
1633 * since we want them to override the global options. Let's process them now. */
1635 r
= dispatch_per_machine("perMachine", json_variant_by_key(h
->json
, "perMachine"), json_flags
, h
);
1639 r
= dispatch_binding("binding", json_variant_by_key(h
->json
, "binding"), json_flags
, h
);
1643 r
= dispatch_status("status", json_variant_by_key(h
->json
, "status"), json_flags
, h
);
1647 if (FLAGS_SET(h
->mask
, USER_RECORD_REGULAR
) && !h
->user_name
)
1648 return json_log(h
->json
, json_flags
, SYNTHETIC_ERRNO(EINVAL
), "User name field missing, refusing.");
1650 r
= user_record_augment(h
, json_flags
);
1657 int user_record_build(UserRecord
**ret
, ...) {
1658 _cleanup_(json_variant_unrefp
) JsonVariant
*v
= NULL
;
1659 _cleanup_(user_record_unrefp
) UserRecord
*u
= NULL
;
1666 r
= json_buildv(&v
, ap
);
1672 u
= user_record_new();
1676 r
= user_record_load(u
, v
, USER_RECORD_LOAD_FULL
);
1684 const char *user_record_user_name_and_realm(UserRecord
*h
) {
1687 /* Return the pre-initialized joined string if it is defined */
1688 if (h
->user_name_and_realm_auto
)
1689 return h
->user_name_and_realm_auto
;
1691 /* If it's not defined then we cannot have a realm */
1693 return h
->user_name
;
1696 UserStorage
user_record_storage(UserRecord
*h
) {
1699 if (h
->storage
>= 0)
1702 return USER_CLASSIC
;
1705 const char *user_record_file_system_type(UserRecord
*h
) {
1708 return h
->file_system_type
?: "btrfs";
1711 const char *user_record_skeleton_directory(UserRecord
*h
) {
1714 return h
->skeleton_directory
?: "/etc/skel";
1717 mode_t
user_record_access_mode(UserRecord
*h
) {
1720 return h
->access_mode
!= MODE_INVALID
? h
->access_mode
: 0700;
1723 const char* user_record_home_directory(UserRecord
*h
) {
1726 if (h
->home_directory
)
1727 return h
->home_directory
;
1728 if (h
->home_directory_auto
)
1729 return h
->home_directory_auto
;
1731 /* The root user is special, hence be special about it */
1732 if (streq_ptr(h
->user_name
, "root"))
1738 const char *user_record_image_path(UserRecord
*h
) {
1742 return h
->image_path
;
1743 if (h
->image_path_auto
)
1744 return h
->image_path_auto
;
1746 return IN_SET(user_record_storage(h
), USER_CLASSIC
, USER_DIRECTORY
, USER_SUBVOLUME
, USER_FSCRYPT
) ? user_record_home_directory(h
) : NULL
;
1749 const char *user_record_cifs_user_name(UserRecord
*h
) {
1752 return h
->cifs_user_name
?: h
->user_name
;
1755 unsigned long user_record_mount_flags(UserRecord
*h
) {
1758 return (h
->nosuid
? MS_NOSUID
: 0) |
1759 (h
->noexec
? MS_NOEXEC
: 0) |
1760 (h
->nodev
? MS_NODEV
: 0);
1763 const char *user_record_shell(UserRecord
*h
) {
1769 if (streq_ptr(h
->user_name
, "root"))
1772 if (user_record_disposition(h
) == USER_REGULAR
)
1773 return DEFAULT_USER_SHELL
;
1778 const char *user_record_real_name(UserRecord
*h
) {
1781 return h
->real_name
?: h
->user_name
;
1784 bool user_record_luks_discard(UserRecord
*h
) {
1789 if (h
->luks_discard
>= 0)
1790 return h
->luks_discard
;
1792 ip
= user_record_image_path(h
);
1796 /* Use discard by default if we are referring to a real block device, but not when operating on a
1797 * loopback device. We want to optimize for SSD and flash storage after all, but we should be careful
1798 * when storing stuff on top of regular file systems in loopback files as doing discard then would
1799 * mean thin provisioning and we should not do that willy-nilly since it means we'll risk EIO later
1800 * on should the disk space to back our file systems not be available. */
1802 return path_startswith(ip
, "/dev/");
1805 bool user_record_luks_offline_discard(UserRecord
*h
) {
1810 if (h
->luks_offline_discard
>= 0)
1811 return h
->luks_offline_discard
;
1813 /* Discard while we are logged out should generally be a good idea, except when operating directly on
1814 * physical media, where we should just bind it to the online discard mode. */
1816 ip
= user_record_image_path(h
);
1820 if (path_startswith(ip
, "/dev/"))
1821 return user_record_luks_discard(h
);
1826 const char *user_record_luks_cipher(UserRecord
*h
) {
1829 return h
->luks_cipher
?: "aes";
1832 const char *user_record_luks_cipher_mode(UserRecord
*h
) {
1835 return h
->luks_cipher_mode
?: "xts-plain64";
1838 uint64_t user_record_luks_volume_key_size(UserRecord
*h
) {
1841 /* We return a value here that can be cast without loss into size_t which is what libcrypsetup expects */
1843 if (h
->luks_volume_key_size
== UINT64_MAX
)
1846 return MIN(h
->luks_volume_key_size
, SIZE_MAX
);
1849 const char* user_record_luks_pbkdf_type(UserRecord
*h
) {
1852 return h
->luks_pbkdf_type
?: "argon2id";
1855 uint64_t user_record_luks_pbkdf_force_iterations(UserRecord
*h
) {
1858 /* propagate default "benchmark" mode as itself */
1859 if (h
->luks_pbkdf_force_iterations
== UINT64_MAX
)
1862 /* clamp everything else to actually accepted number of iterations of libcryptsetup */
1863 return CLAMP(h
->luks_pbkdf_force_iterations
, 1U, UINT32_MAX
);
1866 uint64_t user_record_luks_pbkdf_time_cost_usec(UserRecord
*h
) {
1869 /* Returns a value with ms granularity, since that's what libcryptsetup expects */
1871 if (h
->luks_pbkdf_time_cost_usec
== UINT64_MAX
)
1872 return 500 * USEC_PER_MSEC
; /* We default to 500ms, in contrast to libcryptsetup's 2s, which is just awfully slow on every login */
1874 return MIN(DIV_ROUND_UP(h
->luks_pbkdf_time_cost_usec
, USEC_PER_MSEC
), UINT32_MAX
) * USEC_PER_MSEC
;
1877 uint64_t user_record_luks_pbkdf_memory_cost(UserRecord
*h
) {
1880 /* Returns a value with kb granularity, since that's what libcryptsetup expects */
1881 if (h
->luks_pbkdf_memory_cost
== UINT64_MAX
)
1882 return streq(user_record_luks_pbkdf_type(h
), "pbkdf2") ? 0 : /* doesn't apply for simple pbkdf2 */
1883 64*1024*1024; /* We default to 64M, since this should work on smaller systems too */
1885 return MIN(DIV_ROUND_UP(h
->luks_pbkdf_memory_cost
, 1024), UINT32_MAX
) * 1024;
1888 uint64_t user_record_luks_pbkdf_parallel_threads(UserRecord
*h
) {
1891 if (h
->luks_pbkdf_parallel_threads
== UINT64_MAX
)
1892 return streq(user_record_luks_pbkdf_type(h
), "pbkdf2") ? 0 : /* doesn't apply for simple pbkdf2 */
1893 1; /* We default to 1, since this should work on smaller systems too */
1895 return MIN(h
->luks_pbkdf_parallel_threads
, UINT32_MAX
);
1898 uint64_t user_record_luks_sector_size(UserRecord
*h
) {
1901 if (h
->luks_sector_size
== UINT64_MAX
)
1904 /* Allow up to 4K due to dm-crypt support and 4K alignment by the homed LUKS backend */
1905 return CLAMP(UINT64_C(1) << (63 - __builtin_clzl(h
->luks_sector_size
)), 512U, 4096U);
1908 const char *user_record_luks_pbkdf_hash_algorithm(UserRecord
*h
) {
1911 return h
->luks_pbkdf_hash_algorithm
?: "sha512";
1914 gid_t
user_record_gid(UserRecord
*h
) {
1917 if (gid_is_valid(h
->gid
))
1920 return (gid_t
) h
->uid
;
1923 UserDisposition
user_record_disposition(UserRecord
*h
) {
1926 if (h
->disposition
>= 0)
1927 return h
->disposition
;
1929 /* If not declared, derive from UID */
1931 if (!uid_is_valid(h
->uid
))
1932 return _USER_DISPOSITION_INVALID
;
1934 if (h
->uid
== 0 || h
->uid
== UID_NOBODY
)
1935 return USER_INTRINSIC
;
1937 if (uid_is_system(h
->uid
))
1940 if (uid_is_dynamic(h
->uid
))
1941 return USER_DYNAMIC
;
1943 if (uid_is_container(h
->uid
))
1944 return USER_CONTAINER
;
1946 if (h
->uid
> INT32_MAX
)
1947 return USER_RESERVED
;
1949 return USER_REGULAR
;
1952 int user_record_removable(UserRecord
*h
) {
1953 UserStorage storage
;
1956 if (h
->removable
>= 0)
1957 return h
->removable
;
1959 /* Refuse to decide for classic records */
1960 storage
= user_record_storage(h
);
1961 if (h
->storage
< 0 || h
->storage
== USER_CLASSIC
)
1964 /* For now consider only LUKS home directories with a reference by path as removable */
1965 return storage
== USER_LUKS
&& path_startswith(user_record_image_path(h
), "/dev/");
1968 uint64_t user_record_ratelimit_interval_usec(UserRecord
*h
) {
1971 if (h
->ratelimit_interval_usec
== UINT64_MAX
)
1972 return DEFAULT_RATELIMIT_INTERVAL_USEC
;
1974 return h
->ratelimit_interval_usec
;
1977 uint64_t user_record_ratelimit_burst(UserRecord
*h
) {
1980 if (h
->ratelimit_burst
== UINT64_MAX
)
1981 return DEFAULT_RATELIMIT_BURST
;
1983 return h
->ratelimit_burst
;
1986 bool user_record_can_authenticate(UserRecord
*h
) {
1989 /* Returns true if there's some form of property configured that the user can authenticate against */
1991 if (h
->n_pkcs11_encrypted_key
> 0)
1994 if (h
->n_fido2_hmac_salt
> 0)
1997 return !strv_isempty(h
->hashed_password
);
2000 bool user_record_drop_caches(UserRecord
*h
) {
2003 if (h
->drop_caches
>= 0)
2004 return h
->drop_caches
;
2006 /* By default drop caches on fscrypt, not otherwise. */
2007 return user_record_storage(h
) == USER_FSCRYPT
;
2010 AutoResizeMode
user_record_auto_resize_mode(UserRecord
*h
) {
2013 if (h
->auto_resize_mode
>= 0)
2014 return h
->auto_resize_mode
;
2016 return user_record_storage(h
) == USER_LUKS
? AUTO_RESIZE_SHRINK_AND_GROW
: AUTO_RESIZE_OFF
;
2019 uint64_t user_record_rebalance_weight(UserRecord
*h
) {
2022 if (h
->rebalance_weight
== REBALANCE_WEIGHT_UNSET
)
2023 return REBALANCE_WEIGHT_DEFAULT
;
2025 return h
->rebalance_weight
;
2028 static uint64_t parse_caps_strv(char **l
) {
2032 STRV_FOREACH(i
, l
) {
2033 r
= capability_from_name(*i
);
2035 log_debug_errno(r
, "Don't know capability '%s', ignoring: %m", *i
);
2037 c
|= UINT64_C(1) << r
;
2043 uint64_t user_record_capability_bounding_set(UserRecord
*h
) {
2046 /* Returns UINT64_MAX if no bounding set is configured (!) */
2048 if (!h
->capability_bounding_set
)
2051 return parse_caps_strv(h
->capability_bounding_set
);
2054 uint64_t user_record_capability_ambient_set(UserRecord
*h
) {
2057 /* Returns UINT64_MAX if no ambient set is configured (!) */
2059 if (!h
->capability_ambient_set
)
2062 return parse_caps_strv(h
->capability_ambient_set
) & user_record_capability_bounding_set(h
);
2065 uint64_t user_record_ratelimit_next_try(UserRecord
*h
) {
2068 /* Calculates when the it's possible to login next. Returns:
2070 * UINT64_MAX → Nothing known
2072 * Any other → Next time in CLOCK_REALTIME in usec (which could be in the past)
2075 if (h
->ratelimit_begin_usec
== UINT64_MAX
||
2076 h
->ratelimit_count
== UINT64_MAX
)
2079 if (h
->ratelimit_begin_usec
> now(CLOCK_REALTIME
)) /* If the ratelimit time is in the future, then
2080 * the local clock is probably incorrect. Let's
2081 * not refuse login then. */
2084 if (h
->ratelimit_count
< user_record_ratelimit_burst(h
))
2087 return usec_add(h
->ratelimit_begin_usec
, user_record_ratelimit_interval_usec(h
));
2090 bool user_record_equal(UserRecord
*a
, UserRecord
*b
) {
2094 /* We assume that when a record is modified its JSON data is updated at the same time, hence it's
2095 * sufficient to compare the JSON data. */
2097 return json_variant_equal(a
->json
, b
->json
);
2100 bool user_record_compatible(UserRecord
*a
, UserRecord
*b
) {
2104 /* If either lacks the regular section, we can't really decide, let's hence say they are
2106 if (!(a
->mask
& b
->mask
& USER_RECORD_REGULAR
))
2109 return streq_ptr(a
->user_name
, b
->user_name
) &&
2110 streq_ptr(a
->realm
, b
->realm
);
2113 int user_record_compare_last_change(UserRecord
*a
, UserRecord
*b
) {
2117 if (a
->last_change_usec
== b
->last_change_usec
)
2120 /* Always consider a record with a timestamp newer than one without */
2121 if (a
->last_change_usec
== UINT64_MAX
)
2123 if (b
->last_change_usec
== UINT64_MAX
)
2126 return CMP(a
->last_change_usec
, b
->last_change_usec
);
2129 int user_record_clone(UserRecord
*h
, UserRecordLoadFlags flags
, UserRecord
**ret
) {
2130 _cleanup_(user_record_unrefp
) UserRecord
*c
= NULL
;
2136 c
= user_record_new();
2140 r
= user_record_load(c
, h
->json
, flags
);
2148 int user_record_masked_equal(UserRecord
*a
, UserRecord
*b
, UserRecordMask mask
) {
2149 _cleanup_(user_record_unrefp
) UserRecord
*x
= NULL
, *y
= NULL
;
2155 /* Compares the two records, but ignores anything not listed in the specified mask */
2157 if ((a
->mask
& ~mask
) != 0) {
2158 r
= user_record_clone(a
, USER_RECORD_ALLOW(mask
) | USER_RECORD_STRIP(~mask
& _USER_RECORD_MASK_MAX
) | USER_RECORD_PERMISSIVE
, &x
);
2165 if ((b
->mask
& ~mask
) != 0) {
2166 r
= user_record_clone(b
, USER_RECORD_ALLOW(mask
) | USER_RECORD_STRIP(~mask
& _USER_RECORD_MASK_MAX
) | USER_RECORD_PERMISSIVE
, &y
);
2173 return user_record_equal(a
, b
);
2176 int user_record_test_blocked(UserRecord
*h
) {
2179 /* Checks whether access to the specified user shall be allowed at the moment. Returns:
2181 * -ESTALE: Record is from the future
2182 * -ENOLCK: Record is blocked
2183 * -EL2HLT: Record is not valid yet
2184 * -EL3HLT: Record is not valid anymore
2193 n
= now(CLOCK_REALTIME
);
2195 if (h
->not_before_usec
!= UINT64_MAX
&& n
< h
->not_before_usec
)
2197 if (h
->not_after_usec
!= UINT64_MAX
&& n
> h
->not_after_usec
)
2200 if (h
->last_change_usec
!= UINT64_MAX
&&
2201 h
->last_change_usec
> n
) /* Complain during log-ins when the record is from the future */
2207 int user_record_test_password_change_required(UserRecord
*h
) {
2208 bool change_permitted
;
2213 /* Checks whether the user must change the password when logging in
2215 -EKEYREVOKED: Change password now because admin said so
2216 -EOWNERDEAD: Change password now because it expired
2217 -EKEYREJECTED: Password is expired, no changing is allowed
2218 -EKEYEXPIRED: Password is about to expire, warn user
2219 -ENETDOWN: Record has expiration info but no password change timestamp
2220 -EROFS: No password change required nor permitted
2221 -ESTALE: RTC likely incorrect, last password change is in the future
2222 0: No password change required, but permitted
2225 /* If a password change request has been set explicitly, it overrides everything */
2226 if (h
->password_change_now
> 0)
2227 return -EKEYREVOKED
;
2229 n
= now(CLOCK_REALTIME
);
2231 /* Password change in the future? Then our RTC is likely incorrect */
2232 if (h
->last_password_change_usec
!= UINT64_MAX
&&
2233 h
->last_password_change_usec
> n
&&
2234 (h
->password_change_min_usec
!= UINT64_MAX
||
2235 h
->password_change_max_usec
!= UINT64_MAX
||
2236 h
->password_change_inactive_usec
!= UINT64_MAX
))
2239 /* Then, let's check if password changing is currently allowed at all */
2240 if (h
->password_change_min_usec
!= UINT64_MAX
) {
2242 /* Expiry configured but no password change timestamp known? */
2243 if (h
->last_password_change_usec
== UINT64_MAX
)
2246 if (h
->password_change_min_usec
>= UINT64_MAX
- h
->last_password_change_usec
)
2247 change_permitted
= false;
2249 change_permitted
= n
>= h
->last_password_change_usec
+ h
->password_change_min_usec
;
2252 change_permitted
= true;
2254 /* Let's check whether the password has expired. */
2255 if (!(h
->password_change_max_usec
== UINT64_MAX
||
2256 h
->password_change_max_usec
>= UINT64_MAX
- h
->last_password_change_usec
)) {
2258 uint64_t change_before
;
2260 /* Expiry configured but no password change timestamp known? */
2261 if (h
->last_password_change_usec
== UINT64_MAX
)
2264 /* Password is in inactive phase? */
2265 if (h
->password_change_inactive_usec
!= UINT64_MAX
&&
2266 h
->password_change_inactive_usec
< UINT64_MAX
- h
->password_change_max_usec
) {
2269 added
= h
->password_change_inactive_usec
+ h
->password_change_max_usec
;
2270 if (added
< UINT64_MAX
- h
->last_password_change_usec
&&
2271 n
>= h
->last_password_change_usec
+ added
)
2272 return -EKEYREJECTED
;
2275 /* Password needs to be changed now? */
2276 change_before
= h
->last_password_change_usec
+ h
->password_change_max_usec
;
2277 if (n
>= change_before
)
2278 return change_permitted
? -EOWNERDEAD
: -EKEYREJECTED
;
2281 if (h
->password_change_warn_usec
!= UINT64_MAX
&&
2282 (change_before
< h
->password_change_warn_usec
||
2283 n
>= change_before
- h
->password_change_warn_usec
))
2284 return change_permitted
? -EKEYEXPIRED
: -EROFS
;
2287 /* No password changing necessary */
2288 return change_permitted
? 0 : -EROFS
;
2291 static const char* const user_storage_table
[_USER_STORAGE_MAX
] = {
2292 [USER_CLASSIC
] = "classic",
2293 [USER_LUKS
] = "luks",
2294 [USER_DIRECTORY
] = "directory",
2295 [USER_SUBVOLUME
] = "subvolume",
2296 [USER_FSCRYPT
] = "fscrypt",
2297 [USER_CIFS
] = "cifs",
2300 DEFINE_STRING_TABLE_LOOKUP(user_storage
, UserStorage
);
2302 static const char* const user_disposition_table
[_USER_DISPOSITION_MAX
] = {
2303 [USER_INTRINSIC
] = "intrinsic",
2304 [USER_SYSTEM
] = "system",
2305 [USER_DYNAMIC
] = "dynamic",
2306 [USER_REGULAR
] = "regular",
2307 [USER_CONTAINER
] = "container",
2308 [USER_RESERVED
] = "reserved",
2311 DEFINE_STRING_TABLE_LOOKUP(user_disposition
, UserDisposition
);
2313 static const char* const auto_resize_mode_table
[_AUTO_RESIZE_MODE_MAX
] = {
2314 [AUTO_RESIZE_OFF
] = "off",
2315 [AUTO_RESIZE_GROW
] = "grow",
2316 [AUTO_RESIZE_SHRINK_AND_GROW
] = "shrink-and-grow",
2319 DEFINE_STRING_TABLE_LOOKUP(auto_resize_mode
, AutoResizeMode
);