1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
7 #include "ask-password-api.h"
8 #include "bus-common-errors.h"
10 #include "bus-locator.h"
11 #include "cgroup-util.h"
12 #include "dns-domain.h"
16 #include "format-table.h"
18 #include "glyph-util.h"
19 #include "home-util.h"
20 #include "homectl-fido2.h"
21 #include "homectl-pkcs11.h"
22 #include "homectl-recovery-key.h"
23 #include "libfido2-util.h"
24 #include "locale-util.h"
25 #include "main-func.h"
26 #include "memory-util.h"
28 #include "parse-argument.h"
29 #include "parse-util.h"
30 #include "path-util.h"
31 #include "percent-util.h"
32 #include "pkcs11-util.h"
33 #include "pretty-print.h"
34 #include "process-util.h"
35 #include "pwquality-util.h"
36 #include "rlimit-util.h"
37 #include "spawn-polkit-agent.h"
38 #include "terminal-util.h"
39 #include "uid-alloc-range.h"
40 #include "user-record-pwquality.h"
41 #include "user-record-show.h"
42 #include "user-record-util.h"
43 #include "user-record.h"
44 #include "user-util.h"
47 static PagerFlags arg_pager_flags
= 0;
48 static bool arg_legend
= true;
49 static bool arg_ask_password
= true;
50 static BusTransport arg_transport
= BUS_TRANSPORT_LOCAL
;
51 static const char *arg_host
= NULL
;
52 static const char *arg_identity
= NULL
;
53 static JsonVariant
*arg_identity_extra
= NULL
;
54 static JsonVariant
*arg_identity_extra_privileged
= NULL
;
55 static JsonVariant
*arg_identity_extra_this_machine
= NULL
;
56 static JsonVariant
*arg_identity_extra_rlimits
= NULL
;
57 static char **arg_identity_filter
= NULL
; /* this one is also applied to 'privileged' and 'thisMachine' subobjects */
58 static char **arg_identity_filter_rlimits
= NULL
;
59 static uint64_t arg_disk_size
= UINT64_MAX
;
60 static uint64_t arg_disk_size_relative
= UINT64_MAX
;
61 static char **arg_pkcs11_token_uri
= NULL
;
62 static char **arg_fido2_device
= NULL
;
63 static Fido2EnrollFlags arg_fido2_lock_with
= FIDO2ENROLL_PIN
| FIDO2ENROLL_UP
;
64 static bool arg_recovery_key
= false;
65 static JsonFormatFlags arg_json_format_flags
= JSON_FORMAT_OFF
;
66 static bool arg_and_resize
= false;
67 static bool arg_and_change_password
= false;
69 EXPORT_FORMAT_FULL
, /* export the full record */
70 EXPORT_FORMAT_STRIPPED
, /* strip "state" + "binding", but leave signature in place */
71 EXPORT_FORMAT_MINIMAL
, /* also strip signature */
72 } arg_export_format
= EXPORT_FORMAT_FULL
;
74 STATIC_DESTRUCTOR_REGISTER(arg_identity_extra
, json_variant_unrefp
);
75 STATIC_DESTRUCTOR_REGISTER(arg_identity_extra_this_machine
, json_variant_unrefp
);
76 STATIC_DESTRUCTOR_REGISTER(arg_identity_extra_privileged
, json_variant_unrefp
);
77 STATIC_DESTRUCTOR_REGISTER(arg_identity_extra_rlimits
, json_variant_unrefp
);
78 STATIC_DESTRUCTOR_REGISTER(arg_identity_filter
, strv_freep
);
79 STATIC_DESTRUCTOR_REGISTER(arg_identity_filter_rlimits
, strv_freep
);
80 STATIC_DESTRUCTOR_REGISTER(arg_pkcs11_token_uri
, strv_freep
);
81 STATIC_DESTRUCTOR_REGISTER(arg_fido2_device
, strv_freep
);
83 static const BusLocator
*bus_mgr
;
85 static bool identity_properties_specified(void) {
88 !json_variant_is_blank_object(arg_identity_extra
) ||
89 !json_variant_is_blank_object(arg_identity_extra_privileged
) ||
90 !json_variant_is_blank_object(arg_identity_extra_this_machine
) ||
91 !json_variant_is_blank_object(arg_identity_extra_rlimits
) ||
92 !strv_isempty(arg_identity_filter
) ||
93 !strv_isempty(arg_identity_filter_rlimits
) ||
94 !strv_isempty(arg_pkcs11_token_uri
) ||
95 !strv_isempty(arg_fido2_device
);
98 static int acquire_bus(sd_bus
**bus
) {
106 r
= bus_connect_transport(arg_transport
, arg_host
, false, bus
);
108 return bus_log_connect_error(r
, arg_transport
);
110 (void) sd_bus_set_allow_interactive_authorization(*bus
, arg_ask_password
);
115 static int list_homes(int argc
, char *argv
[], void *userdata
) {
116 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
117 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
118 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
119 _cleanup_(table_unrefp
) Table
*table
= NULL
;
122 r
= acquire_bus(&bus
);
126 r
= bus_call_method(bus
, bus_mgr
, "ListHomes", &error
, &reply
, NULL
);
128 return log_error_errno(r
, "Failed to list homes: %s", bus_error_message(&error
, r
));
130 table
= table_new("name", "uid", "gid", "state", "realname", "home", "shell");
134 r
= sd_bus_message_enter_container(reply
, 'a', "(susussso)");
136 return bus_log_parse_error(r
);
139 const char *name
, *state
, *realname
, *home
, *shell
, *color
;
143 r
= sd_bus_message_read(reply
, "(susussso)", &name
, &uid
, &state
, &gid
, &realname
, &home
, &shell
, NULL
);
145 return bus_log_parse_error(r
);
149 r
= table_add_many(table
,
154 return table_log_add_error(r
);
157 r
= table_add_cell(table
, &cell
, TABLE_STRING
, state
);
159 return table_log_add_error(r
);
161 color
= user_record_state_color(state
);
163 (void) table_set_color(table
, cell
, color
);
165 r
= table_add_many(table
,
166 TABLE_STRING
, strna(empty_to_null(realname
)),
168 TABLE_STRING
, strna(empty_to_null(shell
)));
170 return table_log_add_error(r
);
173 r
= sd_bus_message_exit_container(reply
);
175 return bus_log_parse_error(r
);
177 if (table_get_rows(table
) > 1 || !FLAGS_SET(arg_json_format_flags
, JSON_FORMAT_OFF
)) {
178 r
= table_set_sort(table
, (size_t) 0);
180 return table_log_sort_error(r
);
182 r
= table_print_with_pager(table
, arg_json_format_flags
, arg_pager_flags
, arg_legend
);
187 if (arg_legend
&& (arg_json_format_flags
& JSON_FORMAT_OFF
)) {
188 if (table_get_rows(table
) > 1)
189 printf("\n%zu home areas listed.\n", table_get_rows(table
) - 1);
191 printf("No home areas.\n");
197 static int acquire_existing_password(
198 const char *user_name
,
200 bool emphasize_current
,
201 AskPasswordFlags flags
) {
203 _cleanup_(strv_free_erasep
) char **password
= NULL
;
204 _cleanup_(erase_and_freep
) char *envpw
= NULL
;
205 _cleanup_free_
char *question
= NULL
;
211 r
= getenv_steal_erase("PASSWORD", &envpw
);
213 return log_error_errno(r
, "Failed to acquire password from environment: %m");
215 /* People really shouldn't use environment variables for passing passwords. We support this
216 * only for testing purposes, and do not document the behaviour, so that people won't
217 * actually use this outside of testing. */
219 r
= user_record_set_password(hr
, STRV_MAKE(envpw
), true);
221 return log_error_errno(r
, "Failed to store password: %m");
226 /* If this is not our own user, then don't use the password cache */
227 if (is_this_me(user_name
) <= 0)
228 SET_FLAG(flags
, ASK_PASSWORD_ACCEPT_CACHED
|ASK_PASSWORD_PUSH_CACHE
, false);
230 if (asprintf(&question
, emphasize_current
?
231 "Please enter current password for user %s:" :
232 "Please enter password for user %s:",
236 r
= ask_password_auto(question
,
237 /* icon= */ "user-home",
239 /* key_name= */ "home-password",
240 /* credential_name= */ "home.password",
244 if (r
== -EUNATCH
) { /* EUNATCH is returned if no password was found and asking interactively was
245 * disabled via the flags. Not an error for us. */
246 log_debug_errno(r
, "No passwords acquired.");
250 return log_error_errno(r
, "Failed to acquire password: %m");
252 r
= user_record_set_password(hr
, password
, true);
254 return log_error_errno(r
, "Failed to store password: %m");
259 static int acquire_recovery_key(
260 const char *user_name
,
262 AskPasswordFlags flags
) {
264 _cleanup_(strv_free_erasep
) char **recovery_key
= NULL
;
265 _cleanup_(erase_and_freep
) char *envpw
= NULL
;
266 _cleanup_free_
char *question
= NULL
;
272 r
= getenv_steal_erase("PASSWORD", &envpw
);
274 return log_error_errno(r
, "Failed to acquire password from environment: %m");
276 /* People really shouldn't use environment variables for passing secrets. We support this
277 * only for testing purposes, and do not document the behaviour, so that people won't
278 * actually use this outside of testing. */
280 r
= user_record_set_password(hr
, STRV_MAKE(envpw
), true); /* recovery keys are stored in the record exactly like regular passwords! */
282 return log_error_errno(r
, "Failed to store recovery key: %m");
287 /* If this is not our own user, then don't use the password cache */
288 if (is_this_me(user_name
) <= 0)
289 SET_FLAG(flags
, ASK_PASSWORD_ACCEPT_CACHED
|ASK_PASSWORD_PUSH_CACHE
, false);
291 if (asprintf(&question
, "Please enter recovery key for user %s:", user_name
) < 0)
294 r
= ask_password_auto(question
,
295 /* icon= */ "user-home",
297 /* key_name= */ "home-recovery-key",
298 /* credential_name= */ "home.recovery-key",
302 if (r
== -EUNATCH
) { /* EUNATCH is returned if no recovery key was found and asking interactively was
303 * disabled via the flags. Not an error for us. */
304 log_debug_errno(r
, "No recovery keys acquired.");
308 return log_error_errno(r
, "Failed to acquire recovery keys: %m");
310 r
= user_record_set_password(hr
, recovery_key
, true);
312 return log_error_errno(r
, "Failed to store recovery keys: %m");
317 static int acquire_token_pin(
318 const char *user_name
,
320 AskPasswordFlags flags
) {
322 _cleanup_(strv_free_erasep
) char **pin
= NULL
;
323 _cleanup_(erase_and_freep
) char *envpin
= NULL
;
324 _cleanup_free_
char *question
= NULL
;
330 r
= getenv_steal_erase("PIN", &envpin
);
332 return log_error_errno(r
, "Failed to acquire PIN from environment: %m");
334 r
= user_record_set_token_pin(hr
, STRV_MAKE(envpin
), false);
336 return log_error_errno(r
, "Failed to store token PIN: %m");
341 /* If this is not our own user, then don't use the password cache */
342 if (is_this_me(user_name
) <= 0)
343 SET_FLAG(flags
, ASK_PASSWORD_ACCEPT_CACHED
|ASK_PASSWORD_PUSH_CACHE
, false);
345 if (asprintf(&question
, "Please enter security token PIN for user %s:", user_name
) < 0)
348 r
= ask_password_auto(
350 /* icon= */ "user-home",
352 /* key_name= */ "token-pin",
353 /* credential_name= */ "home.token-pin",
357 if (r
== -EUNATCH
) { /* EUNATCH is returned if no PIN was found and asking interactively was disabled
358 * via the flags. Not an error for us. */
359 log_debug_errno(r
, "No security token PINs acquired.");
363 return log_error_errno(r
, "Failed to acquire security token PIN: %m");
365 r
= user_record_set_token_pin(hr
, pin
, false);
367 return log_error_errno(r
, "Failed to store security token PIN: %m");
372 static int handle_generic_user_record_error(
373 const char *user_name
,
375 const sd_bus_error
*error
,
377 bool emphasize_current_password
) {
383 if (sd_bus_error_has_name(error
, BUS_ERROR_HOME_ABSENT
))
384 return log_error_errno(SYNTHETIC_ERRNO(EREMOTE
),
385 "Home of user %s is currently absent, please plug in the necessary storage device or backing file system.", user_name
);
387 else if (sd_bus_error_has_name(error
, BUS_ERROR_AUTHENTICATION_LIMIT_HIT
))
388 return log_error_errno(SYNTHETIC_ERRNO(ETOOMANYREFS
),
389 "Too frequent login attempts for user %s, try again later.", user_name
);
391 else if (sd_bus_error_has_name(error
, BUS_ERROR_BAD_PASSWORD
)) {
393 if (!strv_isempty(hr
->password
))
394 log_notice("Password incorrect or not sufficient, please try again.");
396 /* Don't consume cache entries or credentials here, we already tried that unsuccessfully. But
397 * let's push what we acquire here into the cache */
398 r
= acquire_existing_password(
401 emphasize_current_password
,
402 ASK_PASSWORD_PUSH_CACHE
| ASK_PASSWORD_NO_CREDENTIAL
);
406 } else if (sd_bus_error_has_name(error
, BUS_ERROR_BAD_RECOVERY_KEY
)) {
408 if (!strv_isempty(hr
->password
))
409 log_notice("Recovery key incorrect or not sufficient, please try again.");
411 /* Don't consume cache entries or credentials here, we already tried that unsuccessfully. But
412 * let's push what we acquire here into the cache */
413 r
= acquire_recovery_key(
416 ASK_PASSWORD_PUSH_CACHE
| ASK_PASSWORD_NO_CREDENTIAL
);
420 } else if (sd_bus_error_has_name(error
, BUS_ERROR_BAD_PASSWORD_AND_NO_TOKEN
)) {
422 if (strv_isempty(hr
->password
))
423 log_notice("Security token not inserted, please enter password.");
425 log_notice("Password incorrect or not sufficient, and configured security token not inserted, please try again.");
427 r
= acquire_existing_password(
430 emphasize_current_password
,
431 ASK_PASSWORD_PUSH_CACHE
| ASK_PASSWORD_NO_CREDENTIAL
);
435 } else if (sd_bus_error_has_name(error
, BUS_ERROR_TOKEN_PIN_NEEDED
)) {
437 /* First time the PIN is requested, let's accept cached data, and allow using credential store */
438 r
= acquire_token_pin(
441 ASK_PASSWORD_ACCEPT_CACHED
| ASK_PASSWORD_PUSH_CACHE
);
445 } else if (sd_bus_error_has_name(error
, BUS_ERROR_TOKEN_PROTECTED_AUTHENTICATION_PATH_NEEDED
)) {
447 log_notice("%s%sPlease authenticate physically on security token.",
448 emoji_enabled() ? special_glyph(SPECIAL_GLYPH_TOUCH
) : "",
449 emoji_enabled() ? " " : "");
451 r
= user_record_set_pkcs11_protected_authentication_path_permitted(hr
, true);
453 return log_error_errno(r
, "Failed to set PKCS#11 protected authentication path permitted flag: %m");
455 } else if (sd_bus_error_has_name(error
, BUS_ERROR_TOKEN_USER_PRESENCE_NEEDED
)) {
457 log_notice("%s%sPlease confirm presence on security token.",
458 emoji_enabled() ? special_glyph(SPECIAL_GLYPH_TOUCH
) : "",
459 emoji_enabled() ? " " : "");
461 r
= user_record_set_fido2_user_presence_permitted(hr
, true);
463 return log_error_errno(r
, "Failed to set FIDO2 user presence permitted flag: %m");
465 } else if (sd_bus_error_has_name(error
, BUS_ERROR_TOKEN_USER_VERIFICATION_NEEDED
)) {
467 log_notice("%s%sPlease verify user on security token.",
468 emoji_enabled() ? special_glyph(SPECIAL_GLYPH_TOUCH
) : "",
469 emoji_enabled() ? " " : "");
471 r
= user_record_set_fido2_user_verification_permitted(hr
, true);
473 return log_error_errno(r
, "Failed to set FIDO2 user verification permitted flag: %m");
475 } else if (sd_bus_error_has_name(error
, BUS_ERROR_TOKEN_PIN_LOCKED
))
476 return log_error_errno(SYNTHETIC_ERRNO(EPERM
), "Security token PIN is locked, please unlock it first. (Hint: Removal and re-insertion might suffice.)");
478 else if (sd_bus_error_has_name(error
, BUS_ERROR_TOKEN_BAD_PIN
)) {
480 log_notice("Security token PIN incorrect, please try again.");
482 /* If the previous PIN was wrong don't accept cached info anymore, but add to cache. Also, don't use the credential data */
483 r
= acquire_token_pin(
486 ASK_PASSWORD_PUSH_CACHE
| ASK_PASSWORD_NO_CREDENTIAL
);
490 } else if (sd_bus_error_has_name(error
, BUS_ERROR_TOKEN_BAD_PIN_FEW_TRIES_LEFT
)) {
492 log_notice("Security token PIN incorrect, please try again (only a few tries left!).");
494 r
= acquire_token_pin(
497 ASK_PASSWORD_PUSH_CACHE
| ASK_PASSWORD_NO_CREDENTIAL
);
501 } else if (sd_bus_error_has_name(error
, BUS_ERROR_TOKEN_BAD_PIN_ONE_TRY_LEFT
)) {
503 log_notice("Security token PIN incorrect, please try again (only one try left!).");
505 r
= acquire_token_pin(
508 ASK_PASSWORD_PUSH_CACHE
| ASK_PASSWORD_NO_CREDENTIAL
);
512 return log_error_errno(ret
, "Operation on home %s failed: %s", user_name
, bus_error_message(error
, ret
));
517 static int acquire_passed_secrets(const char *user_name
, UserRecord
**ret
) {
518 _cleanup_(user_record_unrefp
) UserRecord
*secret
= NULL
;
523 /* Generates an initial secret objects that contains passwords supplied via $PASSWORD, the password
524 * cache or the credentials subsystem, but excluding any interactive stuff. If nothing is passed,
525 * returns an empty secret object. */
527 secret
= user_record_new();
531 r
= acquire_existing_password(
534 /* emphasize_current_password = */ false,
535 ASK_PASSWORD_ACCEPT_CACHED
| ASK_PASSWORD_NO_TTY
| ASK_PASSWORD_NO_AGENT
);
539 r
= acquire_token_pin(
542 ASK_PASSWORD_ACCEPT_CACHED
| ASK_PASSWORD_NO_TTY
| ASK_PASSWORD_NO_AGENT
);
546 r
= acquire_recovery_key(
549 ASK_PASSWORD_ACCEPT_CACHED
| ASK_PASSWORD_NO_TTY
| ASK_PASSWORD_NO_AGENT
);
553 *ret
= TAKE_PTR(secret
);
557 static int activate_home(int argc
, char *argv
[], void *userdata
) {
558 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
562 r
= acquire_bus(&bus
);
566 STRV_FOREACH(i
, strv_skip(argv
, 1)) {
567 _cleanup_(user_record_unrefp
) UserRecord
*secret
= NULL
;
569 r
= acquire_passed_secrets(*i
, &secret
);
574 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
575 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
577 r
= bus_message_new_method_call(bus
, &m
, bus_mgr
, "ActivateHome");
579 return bus_log_create_error(r
);
581 r
= sd_bus_message_append(m
, "s", *i
);
583 return bus_log_create_error(r
);
585 r
= bus_message_append_secret(m
, secret
);
587 return bus_log_create_error(r
);
589 r
= sd_bus_call(bus
, m
, HOME_SLOW_BUS_CALL_TIMEOUT_USEC
, &error
, NULL
);
591 r
= handle_generic_user_record_error(*i
, secret
, &error
, r
, /* emphasize_current_password= */ false);
606 static int deactivate_home(int argc
, char *argv
[], void *userdata
) {
607 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
611 r
= acquire_bus(&bus
);
615 STRV_FOREACH(i
, strv_skip(argv
, 1)) {
616 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
617 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
619 r
= bus_message_new_method_call(bus
, &m
, bus_mgr
, "DeactivateHome");
621 return bus_log_create_error(r
);
623 r
= sd_bus_message_append(m
, "s", *i
);
625 return bus_log_create_error(r
);
627 r
= sd_bus_call(bus
, m
, HOME_SLOW_BUS_CALL_TIMEOUT_USEC
, &error
, NULL
);
629 log_error_errno(r
, "Failed to deactivate user home: %s", bus_error_message(&error
, r
));
638 static void dump_home_record(UserRecord
*hr
) {
643 if (hr
->incomplete
) {
645 log_warning("Warning: lacking rights to acquire privileged fields of user record of '%s', output incomplete.", hr
->user_name
);
648 if (arg_json_format_flags
& JSON_FORMAT_OFF
)
649 user_record_show(hr
, true);
651 _cleanup_(user_record_unrefp
) UserRecord
*stripped
= NULL
;
653 if (arg_export_format
== EXPORT_FORMAT_STRIPPED
)
654 r
= user_record_clone(hr
, USER_RECORD_EXTRACT_EMBEDDED
|USER_RECORD_PERMISSIVE
, &stripped
);
655 else if (arg_export_format
== EXPORT_FORMAT_MINIMAL
)
656 r
= user_record_clone(hr
, USER_RECORD_EXTRACT_SIGNABLE
|USER_RECORD_PERMISSIVE
, &stripped
);
660 log_warning_errno(r
, "Failed to strip user record, ignoring: %m");
664 json_variant_dump(hr
->json
, arg_json_format_flags
, stdout
, NULL
);
668 static char **mangle_user_list(char **list
, char ***ret_allocated
) {
669 _cleanup_free_
char *myself
= NULL
;
672 if (!strv_isempty(list
)) {
673 *ret_allocated
= NULL
;
677 myself
= getusername_malloc();
685 l
[0] = TAKE_PTR(myself
);
692 static int inspect_home(int argc
, char *argv
[], void *userdata
) {
693 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
694 _cleanup_(strv_freep
) char **mangled_list
= NULL
;
698 pager_open(arg_pager_flags
);
700 r
= acquire_bus(&bus
);
704 items
= mangle_user_list(strv_skip(argv
, 1), &mangled_list
);
708 STRV_FOREACH(i
, items
) {
709 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
710 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
711 _cleanup_(json_variant_unrefp
) JsonVariant
*v
= NULL
;
712 _cleanup_(user_record_unrefp
) UserRecord
*hr
= NULL
;
717 r
= parse_uid(*i
, &uid
);
719 if (!valid_user_group_name(*i
, 0)) {
720 log_error("Invalid user name '%s'.", *i
);
727 r
= bus_call_method(bus
, bus_mgr
, "GetUserRecordByName", &error
, &reply
, "s", *i
);
729 r
= bus_call_method(bus
, bus_mgr
, "GetUserRecordByUID", &error
, &reply
, "u", (uint32_t) uid
);
732 log_error_errno(r
, "Failed to inspect home: %s", bus_error_message(&error
, r
));
739 r
= sd_bus_message_read(reply
, "sbo", &json
, &incomplete
, NULL
);
741 bus_log_parse_error(r
);
748 r
= json_parse(json
, JSON_PARSE_SENSITIVE
, &v
, NULL
, NULL
);
750 log_error_errno(r
, "Failed to parse JSON identity: %m");
757 hr
= user_record_new();
761 r
= user_record_load(hr
, v
, USER_RECORD_LOAD_REFUSE_SECRET
|USER_RECORD_LOG
|USER_RECORD_PERMISSIVE
);
769 hr
->incomplete
= incomplete
;
770 dump_home_record(hr
);
776 static int authenticate_home(int argc
, char *argv
[], void *userdata
) {
777 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
778 _cleanup_(strv_freep
) char **mangled_list
= NULL
;
782 items
= mangle_user_list(strv_skip(argv
, 1), &mangled_list
);
786 r
= acquire_bus(&bus
);
790 (void) polkit_agent_open_if_enabled(arg_transport
, arg_ask_password
);
792 STRV_FOREACH(i
, items
) {
793 _cleanup_(user_record_unrefp
) UserRecord
*secret
= NULL
;
795 r
= acquire_passed_secrets(*i
, &secret
);
800 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
801 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
803 r
= bus_message_new_method_call(bus
, &m
, bus_mgr
, "AuthenticateHome");
805 return bus_log_create_error(r
);
807 r
= sd_bus_message_append(m
, "s", *i
);
809 return bus_log_create_error(r
);
811 r
= bus_message_append_secret(m
, secret
);
813 return bus_log_create_error(r
);
815 r
= sd_bus_call(bus
, m
, HOME_SLOW_BUS_CALL_TIMEOUT_USEC
, &error
, NULL
);
817 r
= handle_generic_user_record_error(*i
, secret
, &error
, r
, false);
832 static int update_last_change(JsonVariant
**v
, bool with_password
, bool override
) {
839 n
= now(CLOCK_REALTIME
);
841 c
= json_variant_by_key(*v
, "lastChangeUSec");
846 goto update_password
;
848 if (!json_variant_is_unsigned(c
))
849 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "lastChangeUSec field is not an unsigned integer, refusing.");
851 u
= json_variant_unsigned(c
);
853 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "lastChangeUSec is from the future, can't update.");
856 r
= json_variant_set_field_unsigned(v
, "lastChangeUSec", n
);
858 return log_error_errno(r
, "Failed to update lastChangeUSec: %m");
864 c
= json_variant_by_key(*v
, "lastPasswordChangeUSec");
871 if (!json_variant_is_unsigned(c
))
872 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "lastPasswordChangeUSec field is not an unsigned integer, refusing.");
874 u
= json_variant_unsigned(c
);
876 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "lastPasswordChangeUSec is from the future, can't update.");
879 r
= json_variant_set_field_unsigned(v
, "lastPasswordChangeUSec", n
);
881 return log_error_errno(r
, "Failed to update lastPasswordChangeUSec: %m");
886 static int apply_identity_changes(JsonVariant
**_v
) {
887 _cleanup_(json_variant_unrefp
) JsonVariant
*v
= NULL
;
892 v
= json_variant_ref(*_v
);
894 r
= json_variant_filter(&v
, arg_identity_filter
);
896 return log_error_errno(r
, "Failed to filter identity: %m");
898 r
= json_variant_merge(&v
, arg_identity_extra
);
900 return log_error_errno(r
, "Failed to merge identities: %m");
902 if (arg_identity_extra_this_machine
|| !strv_isempty(arg_identity_filter
)) {
903 _cleanup_(json_variant_unrefp
) JsonVariant
*per_machine
= NULL
, *mmid
= NULL
;
906 r
= sd_id128_get_machine(&mid
);
908 return log_error_errno(r
, "Failed to acquire machine ID: %m");
910 r
= json_variant_new_string(&mmid
, SD_ID128_TO_STRING(mid
));
912 return log_error_errno(r
, "Failed to allocate matchMachineId object: %m");
914 per_machine
= json_variant_ref(json_variant_by_key(v
, "perMachine"));
916 _cleanup_(json_variant_unrefp
) JsonVariant
*npm
= NULL
, *add
= NULL
;
917 _cleanup_free_ JsonVariant
**array
= NULL
;
921 if (!json_variant_is_array(per_machine
))
922 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "perMachine field is not an array, refusing.");
924 array
= new(JsonVariant
*, json_variant_elements(per_machine
) + 1);
928 JSON_VARIANT_ARRAY_FOREACH(z
, per_machine
) {
931 if (!json_variant_is_object(z
))
932 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "perMachine entry is not an object, refusing.");
936 u
= json_variant_by_key(z
, "matchMachineId");
940 if (!json_variant_equal(u
, mmid
))
943 r
= json_variant_merge(&add
, z
);
945 return log_error_errno(r
, "Failed to merge perMachine entry: %m");
950 r
= json_variant_filter(&add
, arg_identity_filter
);
952 return log_error_errno(r
, "Failed to filter perMachine: %m");
954 r
= json_variant_merge(&add
, arg_identity_extra_this_machine
);
956 return log_error_errno(r
, "Failed to merge in perMachine fields: %m");
958 if (arg_identity_filter_rlimits
|| arg_identity_extra_rlimits
) {
959 _cleanup_(json_variant_unrefp
) JsonVariant
*rlv
= NULL
;
961 rlv
= json_variant_ref(json_variant_by_key(add
, "resourceLimits"));
963 r
= json_variant_filter(&rlv
, arg_identity_filter_rlimits
);
965 return log_error_errno(r
, "Failed to filter resource limits: %m");
967 r
= json_variant_merge(&rlv
, arg_identity_extra_rlimits
);
969 return log_error_errno(r
, "Failed to set resource limits: %m");
971 if (json_variant_is_blank_object(rlv
)) {
972 r
= json_variant_filter(&add
, STRV_MAKE("resourceLimits"));
974 return log_error_errno(r
, "Failed to drop resource limits field from identity: %m");
976 r
= json_variant_set_field(&add
, "resourceLimits", rlv
);
978 return log_error_errno(r
, "Failed to update resource limits of identity: %m");
982 if (!json_variant_is_blank_object(add
)) {
983 r
= json_variant_set_field(&add
, "matchMachineId", mmid
);
985 return log_error_errno(r
, "Failed to set matchMachineId field: %m");
990 r
= json_variant_new_array(&npm
, array
, i
);
992 return log_error_errno(r
, "Failed to allocate new perMachine array: %m");
994 json_variant_unref(per_machine
);
995 per_machine
= TAKE_PTR(npm
);
997 _cleanup_(json_variant_unrefp
) JsonVariant
*item
= json_variant_ref(arg_identity_extra_this_machine
);
999 if (arg_identity_extra_rlimits
) {
1000 r
= json_variant_set_field(&item
, "resourceLimits", arg_identity_extra_rlimits
);
1002 return log_error_errno(r
, "Failed to update resource limits of identity: %m");
1005 r
= json_variant_set_field(&item
, "matchMachineId", mmid
);
1007 return log_error_errno(r
, "Failed to set matchMachineId field: %m");
1009 r
= json_variant_append_array(&per_machine
, item
);
1011 return log_error_errno(r
, "Failed to append to perMachine array: %m");
1014 r
= json_variant_set_field(&v
, "perMachine", per_machine
);
1016 return log_error_errno(r
, "Failed to update per machine record: %m");
1019 if (arg_identity_extra_privileged
|| arg_identity_filter
) {
1020 _cleanup_(json_variant_unrefp
) JsonVariant
*privileged
= NULL
;
1022 privileged
= json_variant_ref(json_variant_by_key(v
, "privileged"));
1024 r
= json_variant_filter(&privileged
, arg_identity_filter
);
1026 return log_error_errno(r
, "Failed to filter identity (privileged part): %m");
1028 r
= json_variant_merge(&privileged
, arg_identity_extra_privileged
);
1030 return log_error_errno(r
, "Failed to merge identities (privileged part): %m");
1032 if (json_variant_is_blank_object(privileged
)) {
1033 r
= json_variant_filter(&v
, STRV_MAKE("privileged"));
1035 return log_error_errno(r
, "Failed to drop privileged part from identity: %m");
1037 r
= json_variant_set_field(&v
, "privileged", privileged
);
1039 return log_error_errno(r
, "Failed to update privileged part of identity: %m");
1043 if (arg_identity_filter_rlimits
) {
1044 _cleanup_(json_variant_unrefp
) JsonVariant
*rlv
= NULL
;
1046 rlv
= json_variant_ref(json_variant_by_key(v
, "resourceLimits"));
1048 r
= json_variant_filter(&rlv
, arg_identity_filter_rlimits
);
1050 return log_error_errno(r
, "Failed to filter resource limits: %m");
1052 /* Note that we only filter resource limits here, but don't apply them. We do that in the perMachine section */
1054 if (json_variant_is_blank_object(rlv
)) {
1055 r
= json_variant_filter(&v
, STRV_MAKE("resourceLimits"));
1057 return log_error_errno(r
, "Failed to drop resource limits field from identity: %m");
1059 r
= json_variant_set_field(&v
, "resourceLimits", rlv
);
1061 return log_error_errno(r
, "Failed to update resource limits of identity: %m");
1065 json_variant_unref(*_v
);
1071 static int add_disposition(JsonVariant
**v
) {
1076 if (json_variant_by_key(*v
, "disposition"))
1079 /* Set the disposition to regular, if not configured explicitly */
1080 r
= json_variant_set_field_string(v
, "disposition", "regular");
1082 return log_error_errno(r
, "Failed to set disposition field: %m");
1087 static int acquire_new_home_record(UserRecord
**ret
) {
1088 _cleanup_(json_variant_unrefp
) JsonVariant
*v
= NULL
;
1089 _cleanup_(user_record_unrefp
) UserRecord
*hr
= NULL
;
1096 unsigned line
, column
;
1098 r
= json_parse_file(
1099 streq(arg_identity
, "-") ? stdin
: NULL
,
1100 streq(arg_identity
, "-") ? "<stdin>" : arg_identity
, JSON_PARSE_SENSITIVE
, &v
, &line
, &column
);
1102 return log_error_errno(r
, "Failed to parse identity at %u:%u: %m", line
, column
);
1105 r
= apply_identity_changes(&v
);
1109 r
= add_disposition(&v
);
1113 STRV_FOREACH(i
, arg_pkcs11_token_uri
) {
1114 r
= identity_add_pkcs11_key_data(&v
, *i
);
1119 STRV_FOREACH(i
, arg_fido2_device
) {
1120 r
= identity_add_fido2_parameters(&v
, *i
, arg_fido2_lock_with
);
1125 if (arg_recovery_key
) {
1126 r
= identity_add_recovery_key(&v
);
1131 r
= update_last_change(&v
, true, false);
1136 json_variant_dump(v
, JSON_FORMAT_PRETTY
, NULL
, NULL
);
1138 hr
= user_record_new();
1142 r
= user_record_load(hr
, v
, USER_RECORD_REQUIRE_REGULAR
|USER_RECORD_ALLOW_SECRET
|USER_RECORD_ALLOW_PRIVILEGED
|USER_RECORD_ALLOW_PER_MACHINE
|USER_RECORD_ALLOW_SIGNATURE
|USER_RECORD_LOG
|USER_RECORD_PERMISSIVE
);
1146 *ret
= TAKE_PTR(hr
);
1150 static int acquire_new_password(
1151 const char *user_name
,
1156 _cleanup_(erase_and_freep
) char *envpw
= NULL
;
1163 r
= getenv_steal_erase("NEWPASSWORD", &envpw
);
1165 return log_error_errno(r
, "Failed to acquire password from environment: %m");
1167 /* As above, this is not for use, just for testing */
1169 r
= user_record_set_password(hr
, STRV_MAKE(envpw
), /* prepend = */ true);
1171 return log_error_errno(r
, "Failed to store password: %m");
1174 *ret
= TAKE_PTR(envpw
);
1180 (void) suggest_passwords();
1183 _cleanup_(strv_free_erasep
) char **first
= NULL
, **second
= NULL
;
1184 _cleanup_free_
char *question
= NULL
;
1187 return log_error_errno(SYNTHETIC_ERRNO(ENOKEY
), "Too many attempts, giving up:");
1189 if (asprintf(&question
, "Please enter new password for user %s:", user_name
) < 0)
1192 r
= ask_password_auto(
1194 /* icon= */ "user-home",
1196 /* key_name= */ "home-password",
1197 /* credential_name= */ "home.new-password",
1199 0, /* no caching, we want to collect a new password here after all */
1202 return log_error_errno(r
, "Failed to acquire password: %m");
1204 question
= mfree(question
);
1205 if (asprintf(&question
, "Please enter new password for user %s (repeat):", user_name
) < 0)
1208 r
= ask_password_auto(
1210 /* icon= */ "user-home",
1212 /* key_name= */ "home-password",
1213 /* credential_name= */ "home.new-password",
1218 return log_error_errno(r
, "Failed to acquire password: %m");
1220 if (strv_equal(first
, second
)) {
1221 _cleanup_(erase_and_freep
) char *copy
= NULL
;
1224 copy
= strdup(first
[0]);
1229 r
= user_record_set_password(hr
, first
, /* prepend = */ true);
1231 return log_error_errno(r
, "Failed to store password: %m");
1234 *ret
= TAKE_PTR(copy
);
1239 log_error("Password didn't match, try again.");
1243 static int create_home(int argc
, char *argv
[], void *userdata
) {
1244 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
1245 _cleanup_(user_record_unrefp
) UserRecord
*hr
= NULL
;
1248 r
= acquire_bus(&bus
);
1252 (void) polkit_agent_open_if_enabled(arg_transport
, arg_ask_password
);
1255 /* If a username was specified, use it */
1257 if (valid_user_group_name(argv
[1], 0))
1258 r
= json_variant_set_field_string(&arg_identity_extra
, "userName", argv
[1]);
1260 _cleanup_free_
char *un
= NULL
, *rr
= NULL
;
1262 /* Before we consider the user name invalid, let's check if we can split it? */
1263 r
= split_user_name_realm(argv
[1], &un
, &rr
);
1265 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "User name '%s' is not valid: %m", argv
[1]);
1268 r
= json_variant_set_field_string(&arg_identity_extra
, "realm", rr
);
1270 return log_error_errno(r
, "Failed to set realm field: %m");
1273 r
= json_variant_set_field_string(&arg_identity_extra
, "userName", un
);
1276 return log_error_errno(r
, "Failed to set userName field: %m");
1278 /* If neither a username nor an identity have been specified we cannot operate. */
1280 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "User name required.");
1283 r
= acquire_new_home_record(&hr
);
1287 /* If the JSON record carries no plain text password (besides the recovery key), then let's query it
1289 if (strv_length(hr
->password
) <= arg_recovery_key
) {
1291 if (strv_isempty(hr
->hashed_password
)) {
1292 _cleanup_(erase_and_freep
) char *new_password
= NULL
;
1294 /* No regular (i.e. non-PKCS#11) hashed passwords set in the record, let's fix that. */
1295 r
= acquire_new_password(hr
->user_name
, hr
, /* suggest = */ true, &new_password
);
1299 r
= user_record_make_hashed_password(hr
, STRV_MAKE(new_password
), /* extend = */ false);
1301 return log_error_errno(r
, "Failed to hash password: %m");
1303 /* There's a hash password set in the record, acquire the unhashed version of it. */
1304 r
= acquire_existing_password(
1307 /* emphasize_current= */ false,
1308 ASK_PASSWORD_ACCEPT_CACHED
| ASK_PASSWORD_PUSH_CACHE
);
1314 if (hr
->enforce_password_policy
== 0) {
1315 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1317 /* If password quality enforcement is disabled, let's at least warn client side */
1319 r
= user_record_quality_check_password(hr
, hr
, &error
);
1321 log_warning_errno(r
, "Specified password does not pass quality checks (%s), proceeding anyway.", bus_error_message(&error
, r
));
1325 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1326 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
1327 _cleanup_(erase_and_freep
) char *formatted
= NULL
;
1329 r
= json_variant_format(hr
->json
, 0, &formatted
);
1331 return log_error_errno(r
, "Failed to format user record: %m");
1333 r
= bus_message_new_method_call(bus
, &m
, bus_mgr
, "CreateHome");
1335 return bus_log_create_error(r
);
1337 (void) sd_bus_message_sensitive(m
);
1339 r
= sd_bus_message_append(m
, "s", formatted
);
1341 return bus_log_create_error(r
);
1343 r
= sd_bus_call(bus
, m
, HOME_SLOW_BUS_CALL_TIMEOUT_USEC
, &error
, NULL
);
1345 if (sd_bus_error_has_name(&error
, BUS_ERROR_LOW_PASSWORD_QUALITY
)) {
1346 _cleanup_(erase_and_freep
) char *new_password
= NULL
;
1348 log_error_errno(r
, "%s", bus_error_message(&error
, r
));
1349 log_info("(Use --enforce-password-policy=no to turn off password quality checks for this account.)");
1351 r
= acquire_new_password(hr
->user_name
, hr
, /* suggest = */ false, &new_password
);
1355 r
= user_record_make_hashed_password(hr
, STRV_MAKE(new_password
), /* extend = */ false);
1357 return log_error_errno(r
, "Failed to hash passwords: %m");
1359 r
= handle_generic_user_record_error(hr
->user_name
, hr
, &error
, r
, false);
1370 static int remove_home(int argc
, char *argv
[], void *userdata
) {
1371 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
1375 r
= acquire_bus(&bus
);
1379 (void) polkit_agent_open_if_enabled(arg_transport
, arg_ask_password
);
1381 STRV_FOREACH(i
, strv_skip(argv
, 1)) {
1382 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1383 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
1385 r
= bus_message_new_method_call(bus
, &m
, bus_mgr
, "RemoveHome");
1387 return bus_log_create_error(r
);
1389 r
= sd_bus_message_append(m
, "s", *i
);
1391 return bus_log_create_error(r
);
1393 r
= sd_bus_call(bus
, m
, HOME_SLOW_BUS_CALL_TIMEOUT_USEC
, &error
, NULL
);
1395 log_error_errno(r
, "Failed to remove home: %s", bus_error_message(&error
, r
));
1404 static int acquire_updated_home_record(
1406 const char *username
,
1409 _cleanup_(json_variant_unrefp
) JsonVariant
*json
= NULL
;
1410 _cleanup_(user_record_unrefp
) UserRecord
*hr
= NULL
;
1417 unsigned line
, column
;
1420 r
= json_parse_file(
1421 streq(arg_identity
, "-") ? stdin
: NULL
,
1422 streq(arg_identity
, "-") ? "<stdin>" : arg_identity
, JSON_PARSE_SENSITIVE
, &json
, &line
, &column
);
1424 return log_error_errno(r
, "Failed to parse identity at %u:%u: %m", line
, column
);
1426 un
= json_variant_by_key(json
, "userName");
1428 if (!json_variant_is_string(un
) || (username
&& !streq(json_variant_string(un
), username
)))
1429 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "User name specified on command line and in JSON record do not match.");
1432 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "No username specified.");
1434 r
= json_variant_set_field_string(&arg_identity_extra
, "userName", username
);
1436 return log_error_errno(r
, "Failed to set userName field: %m");
1440 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1441 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
1445 if (!identity_properties_specified())
1446 return log_error_errno(SYNTHETIC_ERRNO(EALREADY
), "No field to change specified.");
1448 r
= bus_call_method(bus
, bus_mgr
, "GetUserRecordByName", &error
, &reply
, "s", username
);
1450 return log_error_errno(r
, "Failed to acquire user home record: %s", bus_error_message(&error
, r
));
1452 r
= sd_bus_message_read(reply
, "sbo", &text
, &incomplete
, NULL
);
1454 return bus_log_parse_error(r
);
1457 return log_error_errno(SYNTHETIC_ERRNO(EACCES
), "Lacking rights to acquire user record including privileged metadata, can't update record.");
1459 r
= json_parse(text
, JSON_PARSE_SENSITIVE
, &json
, NULL
, NULL
);
1461 return log_error_errno(r
, "Failed to parse JSON identity: %m");
1463 reply
= sd_bus_message_unref(reply
);
1465 r
= json_variant_filter(&json
, STRV_MAKE("binding", "status", "signature"));
1467 return log_error_errno(r
, "Failed to strip binding and status from record to update: %m");
1470 r
= apply_identity_changes(&json
);
1474 STRV_FOREACH(i
, arg_pkcs11_token_uri
) {
1475 r
= identity_add_pkcs11_key_data(&json
, *i
);
1480 STRV_FOREACH(i
, arg_fido2_device
) {
1481 r
= identity_add_fido2_parameters(&json
, *i
, arg_fido2_lock_with
);
1486 /* If the user supplied a full record, then add in lastChange, but do not override. Otherwise always
1488 r
= update_last_change(&json
, arg_pkcs11_token_uri
|| arg_fido2_device
, !arg_identity
);
1493 json_variant_dump(json
, JSON_FORMAT_PRETTY
, NULL
, NULL
);
1495 hr
= user_record_new();
1499 r
= user_record_load(hr
, json
, USER_RECORD_REQUIRE_REGULAR
|USER_RECORD_ALLOW_PRIVILEGED
|USER_RECORD_ALLOW_PER_MACHINE
|USER_RECORD_ALLOW_SECRET
|USER_RECORD_ALLOW_SIGNATURE
|USER_RECORD_LOG
|USER_RECORD_PERMISSIVE
);
1503 *ret
= TAKE_PTR(hr
);
1507 static int home_record_reset_human_interaction_permission(UserRecord
*hr
) {
1512 /* When we execute multiple operations one after the other, let's reset the permission to ask the
1513 * user each time, so that if interaction is necessary we will be told so again and thus can print a
1514 * nice message to the user, telling the user so. */
1516 r
= user_record_set_pkcs11_protected_authentication_path_permitted(hr
, -1);
1518 return log_error_errno(r
, "Failed to reset PKCS#11 protected authentication path permission flag: %m");
1520 r
= user_record_set_fido2_user_presence_permitted(hr
, -1);
1522 return log_error_errno(r
, "Failed to reset FIDO2 user presence permission flag: %m");
1524 r
= user_record_set_fido2_user_verification_permitted(hr
, -1);
1526 return log_error_errno(r
, "Failed to reset FIDO2 user verification permission flag: %m");
1531 static int update_home(int argc
, char *argv
[], void *userdata
) {
1532 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
1533 _cleanup_(user_record_unrefp
) UserRecord
*hr
= NULL
, *secret
= NULL
;
1534 _cleanup_free_
char *buffer
= NULL
;
1535 const char *username
;
1540 else if (!arg_identity
) {
1541 buffer
= getusername_malloc();
1549 r
= acquire_bus(&bus
);
1553 (void) polkit_agent_open_if_enabled(arg_transport
, arg_ask_password
);
1555 r
= acquire_updated_home_record(bus
, username
, &hr
);
1559 /* Add in all secrets we can acquire cheaply */
1560 r
= acquire_passed_secrets(username
, &secret
);
1564 r
= user_record_merge_secret(hr
, secret
);
1568 /* If we do multiple operations, let's output things more verbosely, since otherwise the repeated
1569 * authentication might be confusing. */
1571 if (arg_and_resize
|| arg_and_change_password
)
1572 log_info("Updating home directory.");
1575 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1576 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
1577 _cleanup_free_
char *formatted
= NULL
;
1579 r
= bus_message_new_method_call(bus
, &m
, bus_mgr
, "UpdateHome");
1581 return bus_log_create_error(r
);
1583 r
= json_variant_format(hr
->json
, 0, &formatted
);
1585 return log_error_errno(r
, "Failed to format user record: %m");
1587 (void) sd_bus_message_sensitive(m
);
1589 r
= sd_bus_message_append(m
, "s", formatted
);
1591 return bus_log_create_error(r
);
1593 r
= sd_bus_call(bus
, m
, HOME_SLOW_BUS_CALL_TIMEOUT_USEC
, &error
, NULL
);
1595 if (arg_and_change_password
&&
1596 sd_bus_error_has_name(&error
, BUS_ERROR_BAD_PASSWORD_AND_NO_TOKEN
))
1597 /* In the generic handler we'd ask for a password in this case, but when
1598 * changing passwords that's not sufficient, as we need to acquire all keys
1600 return log_error_errno(r
, "Security token not inserted, refusing.");
1602 r
= handle_generic_user_record_error(hr
->user_name
, hr
, &error
, r
, false);
1610 log_info("Resizing home.");
1612 (void) home_record_reset_human_interaction_permission(hr
);
1614 /* Also sync down disk size to underlying LUKS/fscrypt/quota */
1615 while (arg_and_resize
) {
1616 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1617 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
1619 r
= bus_message_new_method_call(bus
, &m
, bus_mgr
, "ResizeHome");
1621 return bus_log_create_error(r
);
1623 /* Specify UINT64_MAX as size, in which case the underlying disk size will just be synced */
1624 r
= sd_bus_message_append(m
, "st", hr
->user_name
, UINT64_MAX
);
1626 return bus_log_create_error(r
);
1628 r
= bus_message_append_secret(m
, hr
);
1630 return bus_log_create_error(r
);
1632 r
= sd_bus_call(bus
, m
, HOME_SLOW_BUS_CALL_TIMEOUT_USEC
, &error
, NULL
);
1634 if (arg_and_change_password
&&
1635 sd_bus_error_has_name(&error
, BUS_ERROR_BAD_PASSWORD_AND_NO_TOKEN
))
1636 return log_error_errno(r
, "Security token not inserted, refusing.");
1638 r
= handle_generic_user_record_error(hr
->user_name
, hr
, &error
, r
, false);
1645 if (arg_and_change_password
)
1646 log_info("Synchronizing passwords and encryption keys.");
1648 (void) home_record_reset_human_interaction_permission(hr
);
1650 /* Also sync down passwords to underlying LUKS/fscrypt */
1651 while (arg_and_change_password
) {
1652 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1653 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
1655 r
= bus_message_new_method_call(bus
, &m
, bus_mgr
, "ChangePasswordHome");
1657 return bus_log_create_error(r
);
1659 /* Specify an empty new secret, in which case the underlying LUKS/fscrypt password will just be synced */
1660 r
= sd_bus_message_append(m
, "ss", hr
->user_name
, "{}");
1662 return bus_log_create_error(r
);
1664 r
= bus_message_append_secret(m
, hr
);
1666 return bus_log_create_error(r
);
1668 r
= sd_bus_call(bus
, m
, HOME_SLOW_BUS_CALL_TIMEOUT_USEC
, &error
, NULL
);
1670 if (sd_bus_error_has_name(&error
, BUS_ERROR_BAD_PASSWORD_AND_NO_TOKEN
))
1671 return log_error_errno(r
, "Security token not inserted, refusing.");
1673 r
= handle_generic_user_record_error(hr
->user_name
, hr
, &error
, r
, false);
1683 static int passwd_home(int argc
, char *argv
[], void *userdata
) {
1684 _cleanup_(user_record_unrefp
) UserRecord
*old_secret
= NULL
, *new_secret
= NULL
;
1685 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
1686 _cleanup_free_
char *buffer
= NULL
;
1687 const char *username
;
1690 if (arg_pkcs11_token_uri
)
1691 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "To change the PKCS#11 security token use 'homectl update --pkcs11-token-uri=…'.");
1692 if (arg_fido2_device
)
1693 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "To change the FIDO2 security token use 'homectl update --fido2-device=…'.");
1694 if (identity_properties_specified())
1695 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "The 'passwd' verb does not permit changing other record properties at the same time.");
1700 buffer
= getusername_malloc();
1707 r
= acquire_bus(&bus
);
1711 (void) polkit_agent_open_if_enabled(arg_transport
, arg_ask_password
);
1713 r
= acquire_passed_secrets(username
, &old_secret
);
1717 new_secret
= user_record_new();
1721 r
= acquire_new_password(username
, new_secret
, /* suggest = */ true, NULL
);
1726 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1727 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
1729 r
= bus_message_new_method_call(bus
, &m
, bus_mgr
, "ChangePasswordHome");
1731 return bus_log_create_error(r
);
1733 r
= sd_bus_message_append(m
, "s", username
);
1735 return bus_log_create_error(r
);
1737 r
= bus_message_append_secret(m
, new_secret
);
1739 return bus_log_create_error(r
);
1741 r
= bus_message_append_secret(m
, old_secret
);
1743 return bus_log_create_error(r
);
1745 r
= sd_bus_call(bus
, m
, HOME_SLOW_BUS_CALL_TIMEOUT_USEC
, &error
, NULL
);
1747 if (sd_bus_error_has_name(&error
, BUS_ERROR_LOW_PASSWORD_QUALITY
)) {
1749 log_error_errno(r
, "%s", bus_error_message(&error
, r
));
1751 r
= acquire_new_password(username
, new_secret
, /* suggest = */ false, NULL
);
1753 } else if (sd_bus_error_has_name(&error
, BUS_ERROR_BAD_PASSWORD_AND_NO_TOKEN
))
1755 /* In the generic handler we'd ask for a password in this case, but when
1756 * changing passwords that's not sufficeint, as we need to acquire all keys
1758 return log_error_errno(r
, "Security token not inserted, refusing.");
1760 r
= handle_generic_user_record_error(username
, old_secret
, &error
, r
, true);
1770 static int parse_disk_size(const char *t
, uint64_t *ret
) {
1776 if (streq(t
, "min"))
1778 else if (streq(t
, "max"))
1779 *ret
= UINT64_MAX
-1; /* Largest size that isn't UINT64_MAX special marker */
1783 r
= parse_size(t
, 1024, &ds
);
1785 return log_error_errno(r
, "Failed to parse disk size parameter: %s", t
);
1787 if (ds
>= UINT64_MAX
) /* UINT64_MAX has special meaning for us ("dont change"), refuse */
1788 return log_error_errno(SYNTHETIC_ERRNO(ERANGE
), "Disk size out of range: %s", t
);
1796 static int resize_home(int argc
, char *argv
[], void *userdata
) {
1797 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
1798 _cleanup_(user_record_unrefp
) UserRecord
*secret
= NULL
;
1799 uint64_t ds
= UINT64_MAX
;
1802 r
= acquire_bus(&bus
);
1806 (void) polkit_agent_open_if_enabled(arg_transport
, arg_ask_password
);
1808 if (arg_disk_size_relative
!= UINT64_MAX
||
1809 (argc
> 2 && parse_permyriad(argv
[2]) >= 0))
1810 return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP
),
1811 "Relative disk size specification currently not supported when resizing.");
1814 r
= parse_disk_size(argv
[2], &ds
);
1819 if (arg_disk_size
!= UINT64_MAX
) {
1820 if (ds
!= UINT64_MAX
&& ds
!= arg_disk_size
)
1821 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Disk size specified twice and doesn't match, refusing.");
1826 r
= acquire_passed_secrets(argv
[1], &secret
);
1831 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1832 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
1834 r
= bus_message_new_method_call(bus
, &m
, bus_mgr
, "ResizeHome");
1836 return bus_log_create_error(r
);
1838 r
= sd_bus_message_append(m
, "st", argv
[1], ds
);
1840 return bus_log_create_error(r
);
1842 r
= bus_message_append_secret(m
, secret
);
1844 return bus_log_create_error(r
);
1846 r
= sd_bus_call(bus
, m
, HOME_SLOW_BUS_CALL_TIMEOUT_USEC
, &error
, NULL
);
1848 r
= handle_generic_user_record_error(argv
[1], secret
, &error
, r
, false);
1858 static int lock_home(int argc
, char *argv
[], void *userdata
) {
1859 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
1863 r
= acquire_bus(&bus
);
1867 STRV_FOREACH(i
, strv_skip(argv
, 1)) {
1868 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1869 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
1871 r
= bus_message_new_method_call(bus
, &m
, bus_mgr
, "LockHome");
1873 return bus_log_create_error(r
);
1875 r
= sd_bus_message_append(m
, "s", *i
);
1877 return bus_log_create_error(r
);
1879 r
= sd_bus_call(bus
, m
, HOME_SLOW_BUS_CALL_TIMEOUT_USEC
, &error
, NULL
);
1881 log_error_errno(r
, "Failed to lock home: %s", bus_error_message(&error
, r
));
1890 static int unlock_home(int argc
, char *argv
[], void *userdata
) {
1891 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
1895 r
= acquire_bus(&bus
);
1899 STRV_FOREACH(i
, strv_skip(argv
, 1)) {
1900 _cleanup_(user_record_unrefp
) UserRecord
*secret
= NULL
;
1902 r
= acquire_passed_secrets(*i
, &secret
);
1907 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1908 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
1910 r
= bus_message_new_method_call(bus
, &m
, bus_mgr
, "UnlockHome");
1912 return bus_log_create_error(r
);
1914 r
= sd_bus_message_append(m
, "s", *i
);
1916 return bus_log_create_error(r
);
1918 r
= bus_message_append_secret(m
, secret
);
1920 return bus_log_create_error(r
);
1922 r
= sd_bus_call(bus
, m
, HOME_SLOW_BUS_CALL_TIMEOUT_USEC
, &error
, NULL
);
1924 r
= handle_generic_user_record_error(argv
[1], secret
, &error
, r
, false);
1939 static int with_home(int argc
, char *argv
[], void *userdata
) {
1940 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1941 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
, *reply
= NULL
;
1942 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
1943 _cleanup_(user_record_unrefp
) UserRecord
*secret
= NULL
;
1944 _cleanup_close_
int acquired_fd
= -1;
1945 _cleanup_strv_free_
char **cmdline
= NULL
;
1950 r
= acquire_bus(&bus
);
1955 _cleanup_free_
char *shell
= NULL
;
1957 /* If no command is specified, spawn a shell */
1958 r
= get_shell(&shell
);
1960 return log_error_errno(r
, "Failed to acquire shell: %m");
1962 cmdline
= strv_new(shell
);
1964 cmdline
= strv_copy(argv
+ 2);
1968 r
= acquire_passed_secrets(argv
[1], &secret
);
1973 r
= bus_message_new_method_call(bus
, &m
, bus_mgr
, "AcquireHome");
1975 return bus_log_create_error(r
);
1977 r
= sd_bus_message_append(m
, "s", argv
[1]);
1979 return bus_log_create_error(r
);
1981 r
= bus_message_append_secret(m
, secret
);
1983 return bus_log_create_error(r
);
1985 r
= sd_bus_message_append(m
, "b", /* please_suspend = */ getenv_bool("SYSTEMD_PLEASE_SUSPEND_HOME") > 0);
1987 return bus_log_create_error(r
);
1989 r
= sd_bus_call(bus
, m
, HOME_SLOW_BUS_CALL_TIMEOUT_USEC
, &error
, &reply
);
1990 m
= sd_bus_message_unref(m
);
1992 r
= handle_generic_user_record_error(argv
[1], secret
, &error
, r
, false);
1996 sd_bus_error_free(&error
);
2000 r
= sd_bus_message_read(reply
, "h", &fd
);
2002 return bus_log_parse_error(r
);
2004 acquired_fd
= fcntl(fd
, F_DUPFD_CLOEXEC
, 3);
2005 if (acquired_fd
< 0)
2006 return log_error_errno(errno
, "Failed to duplicate acquired fd: %m");
2008 reply
= sd_bus_message_unref(reply
);
2013 r
= bus_call_method(bus
, bus_mgr
, "GetHomeByName", &error
, &reply
, "s", argv
[1]);
2015 return log_error_errno(r
, "Failed to inspect home: %s", bus_error_message(&error
, r
));
2017 r
= sd_bus_message_read(reply
, "usussso", NULL
, NULL
, NULL
, NULL
, &home
, NULL
, NULL
);
2019 return bus_log_parse_error(r
);
2021 r
= safe_fork("(with)", FORK_RESET_SIGNALS
|FORK_CLOSE_ALL_FDS
|FORK_DEATHSIG
|FORK_LOG
|FORK_RLIMIT_NOFILE_SAFE
|FORK_REOPEN_LOG
, &pid
);
2025 if (chdir(home
) < 0) {
2026 log_error_errno(errno
, "Failed to change to directory %s: %m", home
);
2030 execvp(cmdline
[0], cmdline
);
2031 log_error_errno(errno
, "Failed to execute %s: %m", cmdline
[0]);
2035 ret
= wait_for_terminate_and_check(cmdline
[0], pid
, WAIT_LOG_ABNORMAL
);
2037 /* Close the fd that pings the home now. */
2038 acquired_fd
= safe_close(acquired_fd
);
2040 r
= bus_message_new_method_call(bus
, &m
, bus_mgr
, "ReleaseHome");
2042 return bus_log_create_error(r
);
2044 r
= sd_bus_message_append(m
, "s", argv
[1]);
2046 return bus_log_create_error(r
);
2048 r
= sd_bus_call(bus
, m
, HOME_SLOW_BUS_CALL_TIMEOUT_USEC
, &error
, NULL
);
2050 if (sd_bus_error_has_name(&error
, BUS_ERROR_HOME_BUSY
))
2051 log_notice("Not deactivating home directory of %s, as it is still used.", argv
[1]);
2053 return log_error_errno(r
, "Failed to release user home: %s", bus_error_message(&error
, r
));
2059 static int lock_all_homes(int argc
, char *argv
[], void *userdata
) {
2060 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
2061 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
2062 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
2065 r
= acquire_bus(&bus
);
2069 r
= bus_message_new_method_call(bus
, &m
, bus_mgr
, "LockAllHomes");
2071 return bus_log_create_error(r
);
2073 r
= sd_bus_call(bus
, m
, HOME_SLOW_BUS_CALL_TIMEOUT_USEC
, &error
, NULL
);
2075 return log_error_errno(r
, "Failed to lock all homes: %s", bus_error_message(&error
, r
));
2080 static int deactivate_all_homes(int argc
, char *argv
[], void *userdata
) {
2081 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
2082 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
2083 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
2086 r
= acquire_bus(&bus
);
2090 r
= bus_message_new_method_call(bus
, &m
, bus_mgr
, "DeactivateAllHomes");
2092 return bus_log_create_error(r
);
2094 r
= sd_bus_call(bus
, m
, HOME_SLOW_BUS_CALL_TIMEOUT_USEC
, &error
, NULL
);
2096 return log_error_errno(r
, "Failed to deactivate all homes: %s", bus_error_message(&error
, r
));
2101 static int rebalance(int argc
, char *argv
[], void *userdata
) {
2102 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
2103 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
2104 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
2107 r
= acquire_bus(&bus
);
2111 r
= bus_message_new_method_call(bus
, &m
, bus_mgr
, "Rebalance");
2113 return bus_log_create_error(r
);
2115 r
= sd_bus_call(bus
, m
, HOME_SLOW_BUS_CALL_TIMEOUT_USEC
, &error
, NULL
);
2117 if (sd_bus_error_has_name(&error
, BUS_ERROR_REBALANCE_NOT_NEEDED
))
2118 log_info("No homes needed rebalancing.");
2120 return log_error_errno(r
, "Failed to rebalance: %s", bus_error_message(&error
, r
));
2122 log_info("Completed rebalancing.");
2127 static int drop_from_identity(const char *field
) {
2132 /* If we are called to update an identity record and drop some field, let's keep track of what to
2133 * remove from the old record */
2134 r
= strv_extend(&arg_identity_filter
, field
);
2138 /* Let's also drop the field if it was previously set to a new value on the same command line */
2139 r
= json_variant_filter(&arg_identity_extra
, STRV_MAKE(field
));
2141 return log_error_errno(r
, "Failed to filter JSON identity data: %m");
2143 r
= json_variant_filter(&arg_identity_extra_this_machine
, STRV_MAKE(field
));
2145 return log_error_errno(r
, "Failed to filter JSON identity data: %m");
2147 r
= json_variant_filter(&arg_identity_extra_privileged
, STRV_MAKE(field
));
2149 return log_error_errno(r
, "Failed to filter JSON identity data: %m");
2154 static int help(int argc
, char *argv
[], void *userdata
) {
2155 _cleanup_free_
char *link
= NULL
;
2158 pager_open(arg_pager_flags
);
2160 r
= terminal_urlify_man("homectl", "1", &link
);
2164 printf("%1$s [OPTIONS...] COMMAND ...\n\n"
2165 "%2$sCreate, manipulate or inspect home directories.%3$s\n"
2166 "\n%4$sCommands:%5$s\n"
2167 " list List home areas\n"
2168 " activate USER… Activate a home area\n"
2169 " deactivate USER… Deactivate a home area\n"
2170 " inspect USER… Inspect a home area\n"
2171 " authenticate USER… Authenticate a home area\n"
2172 " create USER Create a home area\n"
2173 " remove USER… Remove a home area\n"
2174 " update USER Update a home area\n"
2175 " passwd USER Change password of a home area\n"
2176 " resize USER SIZE Resize a home area\n"
2177 " lock USER… Temporarily lock an active home area\n"
2178 " unlock USER… Unlock a temporarily locked home area\n"
2179 " lock-all Lock all suitable home areas\n"
2180 " deactivate-all Deactivate all active home areas\n"
2181 " rebalance Rebalance free space between home areas\n"
2182 " with USER [COMMAND…] Run shell or command with access to a home area\n"
2183 "\n%4$sOptions:%5$s\n"
2184 " -h --help Show this help\n"
2185 " --version Show package version\n"
2186 " --no-pager Do not pipe output into a pager\n"
2187 " --no-legend Do not show the headers and footers\n"
2188 " --no-ask-password Do not ask for system passwords\n"
2189 " -H --host=[USER@]HOST Operate on remote host\n"
2190 " -M --machine=CONTAINER Operate on local container\n"
2191 " --identity=PATH Read JSON identity from file\n"
2192 " --json=FORMAT Output inspection data in JSON (takes one of\n"
2193 " pretty, short, off)\n"
2194 " -j Equivalent to --json=pretty (on TTY) or\n"
2195 " --json=short (otherwise)\n"
2196 " --export-format= Strip JSON inspection data (full, stripped,\n"
2198 " -E When specified once equals -j --export-format=\n"
2199 " stripped, when specified twice equals\n"
2200 " -j --export-format=minimal\n"
2201 "\n%4$sGeneral User Record Properties:%5$s\n"
2202 " -c --real-name=REALNAME Real name for user\n"
2203 " --realm=REALM Realm to create user in\n"
2204 " --email-address=EMAIL Email address for user\n"
2205 " --location=LOCATION Set location of user on earth\n"
2206 " --icon-name=NAME Icon name for user\n"
2207 " -d --home-dir=PATH Home directory\n"
2208 " -u --uid=UID Numeric UID for user\n"
2209 " -G --member-of=GROUP Add user to group\n"
2210 " --skel=PATH Skeleton directory to use\n"
2211 " --shell=PATH Shell for account\n"
2212 " --setenv=VARIABLE[=VALUE] Set an environment variable at log-in\n"
2213 " --timezone=TIMEZONE Set a time-zone\n"
2214 " --language=LOCALE Set preferred language\n"
2215 " --ssh-authorized-keys=KEYS\n"
2216 " Specify SSH public keys\n"
2217 " --pkcs11-token-uri=URI URI to PKCS#11 security token containing\n"
2218 " private key and matching X.509 certificate\n"
2219 " --fido2-device=PATH Path to FIDO2 hidraw device with hmac-secret\n"
2221 " --fido2-with-client-pin=BOOL\n"
2222 " Whether to require entering a PIN to unlock the\n"
2224 " --fido2-with-user-presence=BOOL\n"
2225 " Whether to require user presence to unlock the\n"
2227 " --fido2-with-user-verification=BOOL\n"
2228 " Whether to require user verification to unlock\n"
2230 " --recovery-key=BOOL Add a recovery key\n"
2231 "\n%4$sAccount Management User Record Properties:%5$s\n"
2232 " --locked=BOOL Set locked account state\n"
2233 " --not-before=TIMESTAMP Do not allow logins before\n"
2234 " --not-after=TIMESTAMP Do not allow logins after\n"
2235 " --rate-limit-interval=SECS\n"
2236 " Login rate-limit interval in seconds\n"
2237 " --rate-limit-burst=NUMBER\n"
2238 " Login rate-limit attempts per interval\n"
2239 "\n%4$sPassword Policy User Record Properties:%5$s\n"
2240 " --password-hint=HINT Set Password hint\n"
2241 " --enforce-password-policy=BOOL\n"
2242 " Control whether to enforce system's password\n"
2243 " policy for this user\n"
2244 " -P Same as --enforce-password-password=no\n"
2245 " --password-change-now=BOOL\n"
2246 " Require the password to be changed on next login\n"
2247 " --password-change-min=TIME\n"
2248 " Require minimum time between password changes\n"
2249 " --password-change-max=TIME\n"
2250 " Require maximum time between password changes\n"
2251 " --password-change-warn=TIME\n"
2252 " How much time to warn before password expiry\n"
2253 " --password-change-inactive=TIME\n"
2254 " How much time to block password after expiry\n"
2255 "\n%4$sResource Management User Record Properties:%5$s\n"
2256 " --disk-size=BYTES Size to assign the user on disk\n"
2257 " --access-mode=MODE User home directory access mode\n"
2258 " --umask=MODE Umask for user when logging in\n"
2259 " --nice=NICE Nice level for user\n"
2260 " --rlimit=LIMIT=VALUE[:VALUE]\n"
2261 " Set resource limits\n"
2262 " --tasks-max=MAX Set maximum number of per-user tasks\n"
2263 " --memory-high=BYTES Set high memory threshold in bytes\n"
2264 " --memory-max=BYTES Set maximum memory limit\n"
2265 " --cpu-weight=WEIGHT Set CPU weight\n"
2266 " --io-weight=WEIGHT Set IO weight\n"
2267 "\n%4$sStorage User Record Properties:%5$s\n"
2268 " --storage=STORAGE Storage type to use (luks, fscrypt, directory,\n"
2269 " subvolume, cifs)\n"
2270 " --image-path=PATH Path to image file/directory\n"
2271 " --drop-caches=BOOL Whether to automatically drop caches on logout\n"
2272 "\n%4$sLUKS Storage User Record Properties:%5$s\n"
2273 " --fs-type=TYPE File system type to use in case of luks\n"
2274 " storage (btrfs, ext4, xfs)\n"
2275 " --luks-discard=BOOL Whether to use 'discard' feature of file system\n"
2276 " when activated (mounted)\n"
2277 " --luks-offline-discard=BOOL\n"
2278 " Whether to trim file on logout\n"
2279 " --luks-cipher=CIPHER Cipher to use for LUKS encryption\n"
2280 " --luks-cipher-mode=MODE Cipher mode to use for LUKS encryption\n"
2281 " --luks-volume-key-size=BITS\n"
2282 " Volume key size to use for LUKS encryption\n"
2283 " --luks-pbkdf-type=TYPE Password-based Key Derivation Function to use\n"
2284 " --luks-pbkdf-hash-algorithm=ALGORITHM\n"
2285 " PBKDF hash algorithm to use\n"
2286 " --luks-pbkdf-time-cost=SECS\n"
2287 " Time cost for PBKDF in seconds\n"
2288 " --luks-pbkdf-memory-cost=BYTES\n"
2289 " Memory cost for PBKDF in bytes\n"
2290 " --luks-pbkdf-parallel-threads=NUMBER\n"
2291 " Number of parallel threads for PKBDF\n"
2292 " --luks-extra-mount-options=OPTIONS\n"
2293 " LUKS extra mount options\n"
2294 " --auto-resize-mode=MODE Automatically grow/shrink home on login/logout\n"
2295 " --rebalance-weight=WEIGHT Weight while rebalancing\n"
2296 "\n%4$sMounting User Record Properties:%5$s\n"
2297 " --nosuid=BOOL Control the 'nosuid' flag of the home mount\n"
2298 " --nodev=BOOL Control the 'nodev' flag of the home mount\n"
2299 " --noexec=BOOL Control the 'noexec' flag of the home mount\n"
2300 "\n%4$sCIFS User Record Properties:%5$s\n"
2301 " --cifs-domain=DOMAIN CIFS (Windows) domain\n"
2302 " --cifs-user-name=USER CIFS (Windows) user name\n"
2303 " --cifs-service=SERVICE CIFS (Windows) service to mount as home area\n"
2304 " --cifs-extra-mount-options=OPTIONS\n"
2305 " CIFS (Windows) extra mount options\n"
2306 "\n%4$sLogin Behaviour User Record Properties:%5$s\n"
2307 " --stop-delay=SECS How long to leave user services running after\n"
2309 " --kill-processes=BOOL Whether to kill user processes when sessions\n"
2311 " --auto-login=BOOL Try to log this user in automatically\n"
2312 "\nSee the %6$s for details.\n",
2313 program_invocation_short_name
,
2323 static int parse_argv(int argc
, char *argv
[]) {
2326 ARG_VERSION
= 0x100,
2329 ARG_NO_ASK_PASSWORD
,
2339 ARG_LUKS_OFFLINE_DISCARD
,
2345 ARG_SSH_AUTHORIZED_KEYS
,
2354 ARG_LUKS_CIPHER_MODE
,
2355 ARG_LUKS_VOLUME_KEY_SIZE
,
2362 ARG_CIFS_EXTRA_MOUNT_OPTIONS
,
2368 ARG_LUKS_PBKDF_TYPE
,
2369 ARG_LUKS_PBKDF_HASH_ALGORITHM
,
2370 ARG_LUKS_PBKDF_TIME_COST
,
2371 ARG_LUKS_PBKDF_MEMORY_COST
,
2372 ARG_LUKS_PBKDF_PARALLEL_THREADS
,
2373 ARG_RATE_LIMIT_INTERVAL
,
2374 ARG_RATE_LIMIT_BURST
,
2377 ARG_ENFORCE_PASSWORD_POLICY
,
2378 ARG_PASSWORD_CHANGE_NOW
,
2379 ARG_PASSWORD_CHANGE_MIN
,
2380 ARG_PASSWORD_CHANGE_MAX
,
2381 ARG_PASSWORD_CHANGE_WARN
,
2382 ARG_PASSWORD_CHANGE_INACTIVE
,
2385 ARG_PKCS11_TOKEN_URI
,
2392 ARG_AND_CHANGE_PASSWORD
,
2394 ARG_LUKS_EXTRA_MOUNT_OPTIONS
,
2395 ARG_AUTO_RESIZE_MODE
,
2396 ARG_REBALANCE_WEIGHT
,
2399 static const struct option options
[] = {
2400 { "help", no_argument
, NULL
, 'h' },
2401 { "version", no_argument
, NULL
, ARG_VERSION
},
2402 { "no-pager", no_argument
, NULL
, ARG_NO_PAGER
},
2403 { "no-legend", no_argument
, NULL
, ARG_NO_LEGEND
},
2404 { "no-ask-password", no_argument
, NULL
, ARG_NO_ASK_PASSWORD
},
2405 { "host", required_argument
, NULL
, 'H' },
2406 { "machine", required_argument
, NULL
, 'M' },
2407 { "identity", required_argument
, NULL
, 'I' },
2408 { "real-name", required_argument
, NULL
, 'c' },
2409 { "comment", required_argument
, NULL
, 'c' }, /* Compat alias to keep thing in sync with useradd(8) */
2410 { "realm", required_argument
, NULL
, ARG_REALM
},
2411 { "email-address", required_argument
, NULL
, ARG_EMAIL_ADDRESS
},
2412 { "location", required_argument
, NULL
, ARG_LOCATION
},
2413 { "password-hint", required_argument
, NULL
, ARG_PASSWORD_HINT
},
2414 { "icon-name", required_argument
, NULL
, ARG_ICON_NAME
},
2415 { "home-dir", required_argument
, NULL
, 'd' }, /* Compatible with useradd(8) */
2416 { "uid", required_argument
, NULL
, 'u' }, /* Compatible with useradd(8) */
2417 { "member-of", required_argument
, NULL
, 'G' },
2418 { "groups", required_argument
, NULL
, 'G' }, /* Compat alias to keep thing in sync with useradd(8) */
2419 { "skel", required_argument
, NULL
, 'k' }, /* Compatible with useradd(8) */
2420 { "shell", required_argument
, NULL
, 's' }, /* Compatible with useradd(8) */
2421 { "setenv", required_argument
, NULL
, ARG_SETENV
},
2422 { "timezone", required_argument
, NULL
, ARG_TIMEZONE
},
2423 { "language", required_argument
, NULL
, ARG_LANGUAGE
},
2424 { "locked", required_argument
, NULL
, ARG_LOCKED
},
2425 { "not-before", required_argument
, NULL
, ARG_NOT_BEFORE
},
2426 { "not-after", required_argument
, NULL
, ARG_NOT_AFTER
},
2427 { "expiredate", required_argument
, NULL
, 'e' }, /* Compat alias to keep thing in sync with useradd(8) */
2428 { "ssh-authorized-keys", required_argument
, NULL
, ARG_SSH_AUTHORIZED_KEYS
},
2429 { "disk-size", required_argument
, NULL
, ARG_DISK_SIZE
},
2430 { "access-mode", required_argument
, NULL
, ARG_ACCESS_MODE
},
2431 { "umask", required_argument
, NULL
, ARG_UMASK
},
2432 { "nice", required_argument
, NULL
, ARG_NICE
},
2433 { "rlimit", required_argument
, NULL
, ARG_RLIMIT
},
2434 { "tasks-max", required_argument
, NULL
, ARG_TASKS_MAX
},
2435 { "memory-high", required_argument
, NULL
, ARG_MEMORY_HIGH
},
2436 { "memory-max", required_argument
, NULL
, ARG_MEMORY_MAX
},
2437 { "cpu-weight", required_argument
, NULL
, ARG_CPU_WEIGHT
},
2438 { "io-weight", required_argument
, NULL
, ARG_IO_WEIGHT
},
2439 { "storage", required_argument
, NULL
, ARG_STORAGE
},
2440 { "image-path", required_argument
, NULL
, ARG_IMAGE_PATH
},
2441 { "fs-type", required_argument
, NULL
, ARG_FS_TYPE
},
2442 { "luks-discard", required_argument
, NULL
, ARG_LUKS_DISCARD
},
2443 { "luks-offline-discard", required_argument
, NULL
, ARG_LUKS_OFFLINE_DISCARD
},
2444 { "luks-cipher", required_argument
, NULL
, ARG_LUKS_CIPHER
},
2445 { "luks-cipher-mode", required_argument
, NULL
, ARG_LUKS_CIPHER_MODE
},
2446 { "luks-volume-key-size", required_argument
, NULL
, ARG_LUKS_VOLUME_KEY_SIZE
},
2447 { "luks-pbkdf-type", required_argument
, NULL
, ARG_LUKS_PBKDF_TYPE
},
2448 { "luks-pbkdf-hash-algorithm", required_argument
, NULL
, ARG_LUKS_PBKDF_HASH_ALGORITHM
},
2449 { "luks-pbkdf-time-cost", required_argument
, NULL
, ARG_LUKS_PBKDF_TIME_COST
},
2450 { "luks-pbkdf-memory-cost", required_argument
, NULL
, ARG_LUKS_PBKDF_MEMORY_COST
},
2451 { "luks-pbkdf-parallel-threads", required_argument
, NULL
, ARG_LUKS_PBKDF_PARALLEL_THREADS
},
2452 { "nosuid", required_argument
, NULL
, ARG_NOSUID
},
2453 { "nodev", required_argument
, NULL
, ARG_NODEV
},
2454 { "noexec", required_argument
, NULL
, ARG_NOEXEC
},
2455 { "cifs-user-name", required_argument
, NULL
, ARG_CIFS_USER_NAME
},
2456 { "cifs-domain", required_argument
, NULL
, ARG_CIFS_DOMAIN
},
2457 { "cifs-service", required_argument
, NULL
, ARG_CIFS_SERVICE
},
2458 { "cifs-extra-mount-options", required_argument
, NULL
, ARG_CIFS_EXTRA_MOUNT_OPTIONS
},
2459 { "rate-limit-interval", required_argument
, NULL
, ARG_RATE_LIMIT_INTERVAL
},
2460 { "rate-limit-burst", required_argument
, NULL
, ARG_RATE_LIMIT_BURST
},
2461 { "stop-delay", required_argument
, NULL
, ARG_STOP_DELAY
},
2462 { "kill-processes", required_argument
, NULL
, ARG_KILL_PROCESSES
},
2463 { "enforce-password-policy", required_argument
, NULL
, ARG_ENFORCE_PASSWORD_POLICY
},
2464 { "password-change-now", required_argument
, NULL
, ARG_PASSWORD_CHANGE_NOW
},
2465 { "password-change-min", required_argument
, NULL
, ARG_PASSWORD_CHANGE_MIN
},
2466 { "password-change-max", required_argument
, NULL
, ARG_PASSWORD_CHANGE_MAX
},
2467 { "password-change-warn", required_argument
, NULL
, ARG_PASSWORD_CHANGE_WARN
},
2468 { "password-change-inactive", required_argument
, NULL
, ARG_PASSWORD_CHANGE_INACTIVE
},
2469 { "auto-login", required_argument
, NULL
, ARG_AUTO_LOGIN
},
2470 { "json", required_argument
, NULL
, ARG_JSON
},
2471 { "export-format", required_argument
, NULL
, ARG_EXPORT_FORMAT
},
2472 { "pkcs11-token-uri", required_argument
, NULL
, ARG_PKCS11_TOKEN_URI
},
2473 { "fido2-device", required_argument
, NULL
, ARG_FIDO2_DEVICE
},
2474 { "fido2-with-client-pin", required_argument
, NULL
, ARG_FIDO2_WITH_PIN
},
2475 { "fido2-with-user-presence", required_argument
, NULL
, ARG_FIDO2_WITH_UP
},
2476 { "fido2-with-user-verification",required_argument
, NULL
, ARG_FIDO2_WITH_UV
},
2477 { "recovery-key", required_argument
, NULL
, ARG_RECOVERY_KEY
},
2478 { "and-resize", required_argument
, NULL
, ARG_AND_RESIZE
},
2479 { "and-change-password", required_argument
, NULL
, ARG_AND_CHANGE_PASSWORD
},
2480 { "drop-caches", required_argument
, NULL
, ARG_DROP_CACHES
},
2481 { "luks-extra-mount-options", required_argument
, NULL
, ARG_LUKS_EXTRA_MOUNT_OPTIONS
},
2482 { "auto-resize-mode", required_argument
, NULL
, ARG_AUTO_RESIZE_MODE
},
2483 { "rebalance-weight", required_argument
, NULL
, ARG_REBALANCE_WEIGHT
},
2495 c
= getopt_long(argc
, argv
, "hH:M:I:c:d:u:k:s:e:G:jPE", options
, NULL
);
2502 return help(0, NULL
, NULL
);
2508 arg_pager_flags
|= PAGER_DISABLE
;
2515 case ARG_NO_ASK_PASSWORD
:
2516 arg_ask_password
= false;
2520 arg_transport
= BUS_TRANSPORT_REMOTE
;
2525 arg_transport
= BUS_TRANSPORT_MACHINE
;
2530 arg_identity
= optarg
;
2534 if (isempty(optarg
)) {
2535 r
= drop_from_identity("realName");
2542 if (!valid_gecos(optarg
))
2543 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Real name '%s' not a valid GECOS field.", optarg
);
2545 r
= json_variant_set_field_string(&arg_identity_extra
, "realName", optarg
);
2547 return log_error_errno(r
, "Failed to set realName field: %m");
2552 _cleanup_free_
char *hd
= NULL
;
2554 if (isempty(optarg
)) {
2555 r
= drop_from_identity("homeDirectory");
2562 r
= parse_path_argument(optarg
, false, &hd
);
2566 if (!valid_home(hd
))
2567 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Home directory '%s' not valid.", hd
);
2569 r
= json_variant_set_field_string(&arg_identity_extra
, "homeDirectory", hd
);
2571 return log_error_errno(r
, "Failed to set homeDirectory field: %m");
2577 if (isempty(optarg
)) {
2578 r
= drop_from_identity("realm");
2585 r
= dns_name_is_valid(optarg
);
2587 return log_error_errno(r
, "Failed to determine whether realm '%s' is a valid DNS domain: %m", optarg
);
2589 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Realm '%s' is not a valid DNS domain: %m", optarg
);
2591 r
= json_variant_set_field_string(&arg_identity_extra
, "realm", optarg
);
2593 return log_error_errno(r
, "Failed to set realm field: %m");
2596 case ARG_EMAIL_ADDRESS
:
2599 case ARG_CIFS_USER_NAME
:
2600 case ARG_CIFS_DOMAIN
:
2601 case ARG_CIFS_EXTRA_MOUNT_OPTIONS
:
2602 case ARG_LUKS_EXTRA_MOUNT_OPTIONS
: {
2605 c
== ARG_EMAIL_ADDRESS
? "emailAddress" :
2606 c
== ARG_LOCATION
? "location" :
2607 c
== ARG_ICON_NAME
? "iconName" :
2608 c
== ARG_CIFS_USER_NAME
? "cifsUserName" :
2609 c
== ARG_CIFS_DOMAIN
? "cifsDomain" :
2610 c
== ARG_CIFS_EXTRA_MOUNT_OPTIONS
? "cifsExtraMountOptions" :
2611 c
== ARG_LUKS_EXTRA_MOUNT_OPTIONS
? "luksExtraMountOptions" :
2616 if (isempty(optarg
)) {
2617 r
= drop_from_identity(field
);
2624 r
= json_variant_set_field_string(&arg_identity_extra
, field
, optarg
);
2626 return log_error_errno(r
, "Failed to set %s field: %m", field
);
2631 case ARG_CIFS_SERVICE
:
2632 if (isempty(optarg
)) {
2633 r
= drop_from_identity("cifsService");
2640 r
= parse_cifs_service(optarg
, NULL
, NULL
, NULL
);
2642 return log_error_errno(r
, "Failed to validate CIFS service name: %s", optarg
);
2644 r
= json_variant_set_field_string(&arg_identity_extra
, "cifsService", optarg
);
2646 return log_error_errno(r
, "Failed to set cifsService field: %m");
2650 case ARG_PASSWORD_HINT
:
2651 if (isempty(optarg
)) {
2652 r
= drop_from_identity("passwordHint");
2659 r
= json_variant_set_field_string(&arg_identity_extra_privileged
, "passwordHint", optarg
);
2661 return log_error_errno(r
, "Failed to set passwordHint field: %m");
2663 string_erase(optarg
);
2669 if (isempty(optarg
)) {
2670 r
= drop_from_identity("niceLevel");
2676 r
= parse_nice(optarg
, &nc
);
2678 return log_error_errno(r
, "Failed to parse nice level: %s", optarg
);
2680 r
= json_variant_set_field_integer(&arg_identity_extra
, "niceLevel", nc
);
2682 return log_error_errno(r
, "Failed to set niceLevel field: %m");
2688 _cleanup_(json_variant_unrefp
) JsonVariant
*v
= NULL
, *jcur
= NULL
, *jmax
= NULL
;
2689 _cleanup_free_
char *field
= NULL
, *t
= NULL
;
2694 if (isempty(optarg
)) {
2695 /* Remove all resource limits */
2697 r
= drop_from_identity("resourceLimits");
2701 arg_identity_filter_rlimits
= strv_free(arg_identity_filter_rlimits
);
2702 arg_identity_extra_rlimits
= json_variant_unref(arg_identity_extra_rlimits
);
2706 eq
= strchr(optarg
, '=');
2708 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Can't parse resource limit assignment: %s", optarg
);
2710 field
= strndup(optarg
, eq
- optarg
);
2714 l
= rlimit_from_string_harder(field
);
2716 return log_error_errno(l
, "Unknown resource limit type: %s", field
);
2718 if (isempty(eq
+ 1)) {
2719 /* Remove only the specific rlimit */
2721 r
= strv_extend(&arg_identity_filter_rlimits
, rlimit_to_string(l
));
2725 r
= json_variant_filter(&arg_identity_extra_rlimits
, STRV_MAKE(field
));
2727 return log_error_errno(r
, "Failed to filter JSON identity data: %m");
2732 r
= rlimit_parse(l
, eq
+ 1, &rl
);
2734 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Failed to parse resource limit value: %s", eq
+ 1);
2736 r
= rl
.rlim_cur
== RLIM_INFINITY
? json_variant_new_null(&jcur
) : json_variant_new_unsigned(&jcur
, rl
.rlim_cur
);
2738 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Failed to allocate current integer: %m");
2740 r
= rl
.rlim_max
== RLIM_INFINITY
? json_variant_new_null(&jmax
) : json_variant_new_unsigned(&jmax
, rl
.rlim_max
);
2742 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Failed to allocate maximum integer: %m");
2746 JSON_BUILD_PAIR("cur", JSON_BUILD_VARIANT(jcur
)),
2747 JSON_BUILD_PAIR("max", JSON_BUILD_VARIANT(jmax
))));
2749 return log_error_errno(r
, "Failed to build resource limit: %m");
2751 t
= strjoin("RLIMIT_", rlimit_to_string(l
));
2755 r
= json_variant_set_field(&arg_identity_extra_rlimits
, t
, v
);
2757 return log_error_errno(r
, "Failed to set %s field: %m", rlimit_to_string(l
));
2765 if (isempty(optarg
)) {
2766 r
= drop_from_identity("uid");
2773 r
= parse_uid(optarg
, &uid
);
2775 return log_error_errno(r
, "Failed to parse UID '%s'.", optarg
);
2777 if (uid_is_system(uid
))
2778 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "UID " UID_FMT
" is in system range, refusing.", uid
);
2779 if (uid_is_dynamic(uid
))
2780 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "UID " UID_FMT
" is in dynamic range, refusing.", uid
);
2781 if (uid
== UID_NOBODY
)
2782 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "UID " UID_FMT
" is nobody UID, refusing.", uid
);
2784 r
= json_variant_set_field_unsigned(&arg_identity_extra
, "uid", uid
);
2786 return log_error_errno(r
, "Failed to set realm field: %m");
2792 case ARG_IMAGE_PATH
: {
2793 const char *field
= c
== 'k' ? "skeletonDirectory" : "imagePath";
2794 _cleanup_free_
char *v
= NULL
;
2796 if (isempty(optarg
)) {
2797 r
= drop_from_identity(field
);
2804 r
= parse_path_argument(optarg
, false, &v
);
2808 r
= json_variant_set_field_string(&arg_identity_extra_this_machine
, field
, v
);
2810 return log_error_errno(r
, "Failed to set %s field: %m", v
);
2816 if (isempty(optarg
)) {
2817 r
= drop_from_identity("shell");
2824 if (!valid_shell(optarg
))
2825 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Shell '%s' not valid.", optarg
);
2827 r
= json_variant_set_field_string(&arg_identity_extra
, "shell", optarg
);
2829 return log_error_errno(r
, "Failed to set shell field: %m");
2834 _cleanup_free_
char **l
= NULL
;
2835 _cleanup_(json_variant_unrefp
) JsonVariant
*ne
= NULL
;
2838 if (isempty(optarg
)) {
2839 r
= drop_from_identity("environment");
2846 e
= json_variant_by_key(arg_identity_extra
, "environment");
2848 r
= json_variant_strv(e
, &l
);
2850 return log_error_errno(r
, "Failed to parse JSON environment field: %m");
2853 r
= strv_env_replace_strdup_passthrough(&l
, optarg
);
2855 return log_error_errno(r
, "Cannot assign environment variable %s: %m", optarg
);
2859 r
= json_variant_new_array_strv(&ne
, l
);
2861 return log_error_errno(r
, "Failed to allocate environment list JSON: %m");
2863 r
= json_variant_set_field(&arg_identity_extra
, "environment", ne
);
2865 return log_error_errno(r
, "Failed to set environment list: %m");
2872 if (isempty(optarg
)) {
2873 r
= drop_from_identity("timeZone");
2880 if (!timezone_is_valid(optarg
, LOG_DEBUG
))
2881 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Timezone '%s' is not valid.", optarg
);
2883 r
= json_variant_set_field_string(&arg_identity_extra
, "timeZone", optarg
);
2885 return log_error_errno(r
, "Failed to set timezone field: %m");
2890 if (isempty(optarg
)) {
2891 r
= drop_from_identity("language");
2898 if (!locale_is_valid(optarg
))
2899 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Locale '%s' is not valid.", optarg
);
2901 if (locale_is_installed(optarg
) <= 0)
2902 log_warning("Locale '%s' is not installed, accepting anyway.", optarg
);
2904 r
= json_variant_set_field_string(&arg_identity_extra
, "preferredLanguage", optarg
);
2906 return log_error_errno(r
, "Failed to set preferredLanguage field: %m");
2914 case ARG_KILL_PROCESSES
:
2915 case ARG_ENFORCE_PASSWORD_POLICY
:
2916 case ARG_AUTO_LOGIN
:
2917 case ARG_PASSWORD_CHANGE_NOW
: {
2919 c
== ARG_LOCKED
? "locked" :
2920 c
== ARG_NOSUID
? "mountNoSuid" :
2921 c
== ARG_NODEV
? "mountNoDevices" :
2922 c
== ARG_NOEXEC
? "mountNoExecute" :
2923 c
== ARG_KILL_PROCESSES
? "killProcesses" :
2924 c
== ARG_ENFORCE_PASSWORD_POLICY
? "enforcePasswordPolicy" :
2925 c
== ARG_AUTO_LOGIN
? "autoLogin" :
2926 c
== ARG_PASSWORD_CHANGE_NOW
? "passwordChangeNow" :
2931 if (isempty(optarg
)) {
2932 r
= drop_from_identity(field
);
2939 r
= parse_boolean(optarg
);
2941 return log_error_errno(r
, "Failed to parse %s boolean: %m", field
);
2943 r
= json_variant_set_field_boolean(&arg_identity_extra
, field
, r
> 0);
2945 return log_error_errno(r
, "Failed to set %s field: %m", field
);
2951 r
= json_variant_set_field_boolean(&arg_identity_extra
, "enforcePasswordPolicy", false);
2953 return log_error_errno(r
, "Failed to set enforcePasswordPolicy field: %m");
2958 if (isempty(optarg
)) {
2961 FOREACH_STRING(prop
, "diskSize", "diskSizeRelative", "rebalanceWeight") {
2962 r
= drop_from_identity(prop
);
2967 arg_disk_size
= arg_disk_size_relative
= UINT64_MAX
;
2971 r
= parse_permyriad(optarg
);
2973 r
= parse_disk_size(optarg
, &arg_disk_size
);
2977 r
= drop_from_identity("diskSizeRelative");
2981 r
= json_variant_set_field_unsigned(&arg_identity_extra_this_machine
, "diskSize", arg_disk_size
);
2983 return log_error_errno(r
, "Failed to set diskSize field: %m");
2985 arg_disk_size_relative
= UINT64_MAX
;
2987 /* Normalize to UINT32_MAX == 100% */
2988 arg_disk_size_relative
= UINT32_SCALE_FROM_PERMYRIAD(r
);
2990 r
= drop_from_identity("diskSize");
2994 r
= json_variant_set_field_unsigned(&arg_identity_extra_this_machine
, "diskSizeRelative", arg_disk_size_relative
);
2996 return log_error_errno(r
, "Failed to set diskSizeRelative field: %m");
2998 arg_disk_size
= UINT64_MAX
;
3001 /* Automatically turn off the rebalance logic if user configured a size explicitly */
3002 r
= json_variant_set_field_unsigned(&arg_identity_extra_this_machine
, "rebalanceWeight", REBALANCE_WEIGHT_OFF
);
3004 return log_error_errno(r
, "Failed to set rebalanceWeight field: %m");
3008 case ARG_ACCESS_MODE
: {
3011 if (isempty(optarg
)) {
3012 r
= drop_from_identity("accessMode");
3019 r
= parse_mode(optarg
, &mode
);
3021 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Access mode '%s' not valid.", optarg
);
3023 r
= json_variant_set_field_unsigned(&arg_identity_extra
, "accessMode", mode
);
3025 return log_error_errno(r
, "Failed to set access mode field: %m");
3030 case ARG_LUKS_DISCARD
:
3031 if (isempty(optarg
)) {
3032 r
= drop_from_identity("luksDiscard");
3039 r
= parse_boolean(optarg
);
3041 return log_error_errno(r
, "Failed to parse --luks-discard= parameter: %s", optarg
);
3043 r
= json_variant_set_field_boolean(&arg_identity_extra
, "luksDiscard", r
);
3045 return log_error_errno(r
, "Failed to set discard field: %m");
3049 case ARG_LUKS_OFFLINE_DISCARD
:
3050 if (isempty(optarg
)) {
3051 r
= drop_from_identity("luksOfflineDiscard");
3058 r
= parse_boolean(optarg
);
3060 return log_error_errno(r
, "Failed to parse --luks-offline-discard= parameter: %s", optarg
);
3062 r
= json_variant_set_field_boolean(&arg_identity_extra
, "luksOfflineDiscard", r
);
3064 return log_error_errno(r
, "Failed to set offline discard field: %m");
3068 case ARG_LUKS_VOLUME_KEY_SIZE
:
3069 case ARG_LUKS_PBKDF_PARALLEL_THREADS
:
3070 case ARG_RATE_LIMIT_BURST
: {
3072 c
== ARG_LUKS_VOLUME_KEY_SIZE
? "luksVolumeKeySize" :
3073 c
== ARG_LUKS_PBKDF_PARALLEL_THREADS
? "luksPbkdfParallelThreads" :
3074 c
== ARG_RATE_LIMIT_BURST
? "rateLimitBurst" : NULL
;
3079 if (isempty(optarg
)) {
3080 r
= drop_from_identity(field
);
3085 r
= safe_atou(optarg
, &n
);
3087 return log_error_errno(r
, "Failed to parse %s parameter: %s", field
, optarg
);
3089 r
= json_variant_set_field_unsigned(&arg_identity_extra
, field
, n
);
3091 return log_error_errno(r
, "Failed to set %s field: %m", field
);
3099 if (isempty(optarg
)) {
3100 r
= drop_from_identity("umask");
3107 r
= parse_mode(optarg
, &m
);
3109 return log_error_errno(r
, "Failed to parse umask: %m");
3111 r
= json_variant_set_field_integer(&arg_identity_extra
, "umask", m
);
3113 return log_error_errno(r
, "Failed to set umask field: %m");
3118 case ARG_SSH_AUTHORIZED_KEYS
: {
3119 _cleanup_(json_variant_unrefp
) JsonVariant
*v
= NULL
;
3120 _cleanup_(strv_freep
) char **l
= NULL
, **add
= NULL
;
3122 if (isempty(optarg
)) {
3123 r
= drop_from_identity("sshAuthorizedKeys");
3130 if (optarg
[0] == '@') {
3131 _cleanup_fclose_
FILE *f
= NULL
;
3133 /* If prefixed with '@' read from a file */
3135 f
= fopen(optarg
+1, "re");
3137 return log_error_errno(errno
, "Failed to open '%s': %m", optarg
+1);
3140 _cleanup_free_
char *line
= NULL
;
3142 r
= read_line(f
, LONG_LINE_MAX
, &line
);
3144 return log_error_errno(r
, "Failed to read from '%s': %m", optarg
+1);
3154 r
= strv_consume(&add
, TAKE_PTR(line
));
3159 /* Otherwise, assume it's a literal key. Let's do some superficial checks
3160 * before accept it though. */
3162 if (string_has_cc(optarg
, NULL
))
3163 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Authorized key contains control characters, refusing.");
3164 if (optarg
[0] == '#')
3165 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Specified key is a comment?");
3167 add
= strv_new(optarg
);
3172 v
= json_variant_ref(json_variant_by_key(arg_identity_extra_privileged
, "sshAuthorizedKeys"));
3174 r
= json_variant_strv(v
, &l
);
3176 return log_error_errno(r
, "Failed to parse SSH authorized keys list: %m");
3179 r
= strv_extend_strv(&l
, add
, true);
3183 v
= json_variant_unref(v
);
3185 r
= json_variant_new_array_strv(&v
, l
);
3189 r
= json_variant_set_field(&arg_identity_extra_privileged
, "sshAuthorizedKeys", v
);
3191 return log_error_errno(r
, "Failed to set authorized keys: %m");
3196 case ARG_NOT_BEFORE
:
3202 field
= c
== ARG_NOT_BEFORE
? "notBeforeUSec" :
3203 IN_SET(c
, ARG_NOT_AFTER
, 'e') ? "notAfterUSec" : NULL
;
3207 if (isempty(optarg
)) {
3208 r
= drop_from_identity(field
);
3215 /* Note the minor discrepancy regarding -e parsing here: we support that for compat
3216 * reasons, and in the original useradd(8) implementation it accepts dates in the
3217 * format YYYY-MM-DD. Coincidentally, we accept dates formatted like that too, but
3218 * with greater precision. */
3219 r
= parse_timestamp(optarg
, &n
);
3221 return log_error_errno(r
, "Failed to parse %s parameter: %m", field
);
3223 r
= json_variant_set_field_unsigned(&arg_identity_extra
, field
, n
);
3225 return log_error_errno(r
, "Failed to set %s field: %m", field
);
3229 case ARG_PASSWORD_CHANGE_MIN
:
3230 case ARG_PASSWORD_CHANGE_MAX
:
3231 case ARG_PASSWORD_CHANGE_WARN
:
3232 case ARG_PASSWORD_CHANGE_INACTIVE
: {
3236 field
= c
== ARG_PASSWORD_CHANGE_MIN
? "passwordChangeMinUSec" :
3237 c
== ARG_PASSWORD_CHANGE_MAX
? "passwordChangeMaxUSec" :
3238 c
== ARG_PASSWORD_CHANGE_WARN
? "passwordChangeWarnUSec" :
3239 c
== ARG_PASSWORD_CHANGE_INACTIVE
? "passwordChangeInactiveUSec" :
3244 if (isempty(optarg
)) {
3245 r
= drop_from_identity(field
);
3252 r
= parse_sec(optarg
, &n
);
3254 return log_error_errno(r
, "Failed to parse %s parameter: %m", field
);
3256 r
= json_variant_set_field_unsigned(&arg_identity_extra
, field
, n
);
3258 return log_error_errno(r
, "Failed to set %s field: %m", field
);
3264 case ARG_LUKS_CIPHER
:
3265 case ARG_LUKS_CIPHER_MODE
:
3266 case ARG_LUKS_PBKDF_TYPE
:
3267 case ARG_LUKS_PBKDF_HASH_ALGORITHM
: {
3270 c
== ARG_STORAGE
? "storage" :
3271 c
== ARG_FS_TYPE
? "fileSystemType" :
3272 c
== ARG_LUKS_CIPHER
? "luksCipher" :
3273 c
== ARG_LUKS_CIPHER_MODE
? "luksCipherMode" :
3274 c
== ARG_LUKS_PBKDF_TYPE
? "luksPbkdfType" :
3275 c
== ARG_LUKS_PBKDF_HASH_ALGORITHM
? "luksPbkdfHashAlgorithm" : NULL
;
3279 if (isempty(optarg
)) {
3280 r
= drop_from_identity(field
);
3287 if (!string_is_safe(optarg
))
3288 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Parameter for %s field not valid: %s", field
, optarg
);
3290 r
= json_variant_set_field_string(
3291 IN_SET(c
, ARG_STORAGE
, ARG_FS_TYPE
) ?
3292 &arg_identity_extra_this_machine
:
3293 &arg_identity_extra
, field
, optarg
);
3295 return log_error_errno(r
, "Failed to set %s field: %m", field
);
3300 case ARG_LUKS_PBKDF_TIME_COST
:
3301 case ARG_RATE_LIMIT_INTERVAL
:
3302 case ARG_STOP_DELAY
: {
3304 c
== ARG_LUKS_PBKDF_TIME_COST
? "luksPbkdfTimeCostUSec" :
3305 c
== ARG_RATE_LIMIT_INTERVAL
? "rateLimitIntervalUSec" :
3306 c
== ARG_STOP_DELAY
? "stopDelayUSec" :
3312 if (isempty(optarg
)) {
3313 r
= drop_from_identity(field
);
3320 r
= parse_sec(optarg
, &t
);
3322 return log_error_errno(r
, "Failed to parse %s field: %s", field
, optarg
);
3324 r
= json_variant_set_field_unsigned(&arg_identity_extra
, field
, t
);
3326 return log_error_errno(r
, "Failed to set %s field: %m", field
);
3332 const char *p
= optarg
;
3335 r
= drop_from_identity("memberOf");
3343 _cleanup_(json_variant_unrefp
) JsonVariant
*mo
= NULL
;
3344 _cleanup_strv_free_
char **list
= NULL
;
3345 _cleanup_free_
char *word
= NULL
;
3347 r
= extract_first_word(&p
, &word
, ",", 0);
3349 return log_error_errno(r
, "Failed to parse group list: %m");
3353 if (!valid_user_group_name(word
, 0))
3354 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Invalid group name %s.", word
);
3356 mo
= json_variant_ref(json_variant_by_key(arg_identity_extra
, "memberOf"));
3358 r
= json_variant_strv(mo
, &list
);
3360 return log_error_errno(r
, "Failed to parse group list: %m");
3362 r
= strv_extend(&list
, word
);
3369 mo
= json_variant_unref(mo
);
3370 r
= json_variant_new_array_strv(&mo
, list
);
3372 return log_error_errno(r
, "Failed to create group list JSON: %m");
3374 r
= json_variant_set_field(&arg_identity_extra
, "memberOf", mo
);
3376 return log_error_errno(r
, "Failed to update group list: %m");
3382 case ARG_TASKS_MAX
: {
3385 if (isempty(optarg
)) {
3386 r
= drop_from_identity("tasksMax");
3392 r
= safe_atou64(optarg
, &u
);
3394 return log_error_errno(r
, "Failed to parse --tasks-max= parameter: %s", optarg
);
3396 r
= json_variant_set_field_unsigned(&arg_identity_extra
, "tasksMax", u
);
3398 return log_error_errno(r
, "Failed to set tasksMax field: %m");
3403 case ARG_MEMORY_MAX
:
3404 case ARG_MEMORY_HIGH
:
3405 case ARG_LUKS_PBKDF_MEMORY_COST
: {
3407 c
== ARG_MEMORY_MAX
? "memoryMax" :
3408 c
== ARG_MEMORY_HIGH
? "memoryHigh" :
3409 c
== ARG_LUKS_PBKDF_MEMORY_COST
? "luksPbkdfMemoryCost" : NULL
;
3415 if (isempty(optarg
)) {
3416 r
= drop_from_identity(field
);
3422 r
= parse_size(optarg
, 1024, &u
);
3424 return log_error_errno(r
, "Failed to parse %s parameter: %s", field
, optarg
);
3426 r
= json_variant_set_field_unsigned(&arg_identity_extra_this_machine
, field
, u
);
3428 return log_error_errno(r
, "Failed to set %s field: %m", field
);
3433 case ARG_CPU_WEIGHT
:
3434 case ARG_IO_WEIGHT
: {
3435 const char *field
= c
== ARG_CPU_WEIGHT
? "cpuWeight" :
3436 c
== ARG_IO_WEIGHT
? "ioWeight" : NULL
;
3441 if (isempty(optarg
)) {
3442 r
= drop_from_identity(field
);
3448 r
= safe_atou64(optarg
, &u
);
3450 return log_error_errno(r
, "Failed to parse --cpu-weight=/--io-weight= parameter: %s", optarg
);
3452 if (!CGROUP_WEIGHT_IS_OK(u
))
3453 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Weight %" PRIu64
" is out of valid weight range.", u
);
3455 r
= json_variant_set_field_unsigned(&arg_identity_extra
, field
, u
);
3457 return log_error_errno(r
, "Failed to set %s field: %m", field
);
3462 case ARG_PKCS11_TOKEN_URI
: {
3465 if (streq(optarg
, "list"))
3466 return pkcs11_list_tokens();
3468 /* If --pkcs11-token-uri= is specified we always drop everything old */
3469 FOREACH_STRING(p
, "pkcs11TokenUri", "pkcs11EncryptedKey") {
3470 r
= drop_from_identity(p
);
3475 if (isempty(optarg
)) {
3476 arg_pkcs11_token_uri
= strv_free(arg_pkcs11_token_uri
);
3480 if (streq(optarg
, "auto")) {
3481 _cleanup_free_
char *found
= NULL
;
3483 r
= pkcs11_find_token_auto(&found
);
3486 r
= strv_consume(&arg_pkcs11_token_uri
, TAKE_PTR(found
));
3488 if (!pkcs11_uri_valid(optarg
))
3489 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Not a valid PKCS#11 URI: %s", optarg
);
3491 r
= strv_extend(&arg_pkcs11_token_uri
, optarg
);
3496 strv_uniq(arg_pkcs11_token_uri
);
3500 case ARG_FIDO2_DEVICE
: {
3503 if (streq(optarg
, "list"))
3504 return fido2_list_devices();
3506 FOREACH_STRING(p
, "fido2HmacCredential", "fido2HmacSalt") {
3507 r
= drop_from_identity(p
);
3512 if (isempty(optarg
)) {
3513 arg_fido2_device
= strv_free(arg_fido2_device
);
3517 if (streq(optarg
, "auto")) {
3518 _cleanup_free_
char *found
= NULL
;
3520 r
= fido2_find_device_auto(&found
);
3524 r
= strv_consume(&arg_fido2_device
, TAKE_PTR(found
));
3526 r
= strv_extend(&arg_fido2_device
, optarg
);
3530 strv_uniq(arg_fido2_device
);
3534 case ARG_FIDO2_WITH_PIN
: {
3537 r
= parse_boolean_argument("--fido2-with-client-pin=", optarg
, &lock_with_pin
);
3541 SET_FLAG(arg_fido2_lock_with
, FIDO2ENROLL_PIN
, lock_with_pin
);
3545 case ARG_FIDO2_WITH_UP
: {
3548 r
= parse_boolean_argument("--fido2-with-user-presence=", optarg
, &lock_with_up
);
3552 SET_FLAG(arg_fido2_lock_with
, FIDO2ENROLL_UP
, lock_with_up
);
3556 case ARG_FIDO2_WITH_UV
: {
3559 r
= parse_boolean_argument("--fido2-with-user-verification=", optarg
, &lock_with_uv
);
3563 SET_FLAG(arg_fido2_lock_with
, FIDO2ENROLL_UV
, lock_with_uv
);
3567 case ARG_RECOVERY_KEY
: {
3570 r
= parse_boolean(optarg
);
3572 return log_error_errno(r
, "Failed to parse --recovery-key= argument: %s", optarg
);
3574 arg_recovery_key
= r
;
3576 FOREACH_STRING(p
, "recoveryKey", "recoveryKeyType") {
3577 r
= drop_from_identity(p
);
3585 case ARG_AUTO_RESIZE_MODE
:
3586 if (isempty(optarg
)) {
3587 r
= drop_from_identity("autoResizeMode");
3594 r
= auto_resize_mode_from_string(optarg
);
3596 return log_error_errno(r
, "Failed to parse --auto-resize-mode= argument: %s", optarg
);
3598 r
= json_variant_set_field_string(&arg_identity_extra
, "autoResizeMode", auto_resize_mode_to_string(r
));
3600 return log_error_errno(r
, "Failed to set autoResizeMode field: %m");
3604 case ARG_REBALANCE_WEIGHT
: {
3607 if (isempty(optarg
)) {
3608 r
= drop_from_identity("rebalanceWeight");
3613 if (streq(optarg
, "off"))
3614 u
= REBALANCE_WEIGHT_OFF
;
3616 r
= safe_atou64(optarg
, &u
);
3618 return log_error_errno(r
, "Failed to parse --rebalance-weight= argument: %s", optarg
);
3620 if (u
< REBALANCE_WEIGHT_MIN
|| u
> REBALANCE_WEIGHT_MAX
)
3621 return log_error_errno(SYNTHETIC_ERRNO(ERANGE
), "Rebalancing weight out of valid range %" PRIu64
"…%" PRIu64
": %s",
3622 REBALANCE_WEIGHT_MIN
, REBALANCE_WEIGHT_MAX
, optarg
);
3625 /* Drop from per machine stuff and everywhere */
3626 r
= drop_from_identity("rebalanceWeight");
3630 /* Add to main identity */
3631 r
= json_variant_set_field_unsigned(&arg_identity_extra
, "rebalanceWeight", u
);
3633 return log_error_errno(r
, "Failed to set rebalanceWeight field: %m");
3639 arg_json_format_flags
= JSON_FORMAT_PRETTY_AUTO
|JSON_FORMAT_COLOR_AUTO
;
3643 r
= parse_json_argument(optarg
, &arg_json_format_flags
);
3650 if (arg_export_format
== EXPORT_FORMAT_FULL
)
3651 arg_export_format
= EXPORT_FORMAT_STRIPPED
;
3652 else if (arg_export_format
== EXPORT_FORMAT_STRIPPED
)
3653 arg_export_format
= EXPORT_FORMAT_MINIMAL
;
3655 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Specifying -E more than twice is not supported.");
3657 arg_json_format_flags
&= ~JSON_FORMAT_OFF
;
3658 if (arg_json_format_flags
== 0)
3659 arg_json_format_flags
= JSON_FORMAT_PRETTY_AUTO
|JSON_FORMAT_COLOR_AUTO
;
3662 case ARG_EXPORT_FORMAT
:
3663 if (streq(optarg
, "full"))
3664 arg_export_format
= EXPORT_FORMAT_FULL
;
3665 else if (streq(optarg
, "stripped"))
3666 arg_export_format
= EXPORT_FORMAT_STRIPPED
;
3667 else if (streq(optarg
, "minimal"))
3668 arg_export_format
= EXPORT_FORMAT_MINIMAL
;
3669 else if (streq(optarg
, "help")) {
3678 case ARG_AND_RESIZE
:
3679 arg_and_resize
= true;
3682 case ARG_AND_CHANGE_PASSWORD
:
3683 arg_and_change_password
= true;
3686 case ARG_DROP_CACHES
: {
3689 if (isempty(optarg
)) {
3690 r
= drop_from_identity("dropCaches");
3695 r
= parse_boolean_argument("--drop-caches=", optarg
, &drop_caches
);
3699 r
= json_variant_set_field_boolean(&arg_identity_extra
, "dropCaches", r
);
3701 return log_error_errno(r
, "Failed to set drop caches field: %m");
3710 assert_not_reached();
3714 if (!strv_isempty(arg_pkcs11_token_uri
) || !strv_isempty(arg_fido2_device
))
3715 arg_and_change_password
= true;
3717 if (arg_disk_size
!= UINT64_MAX
|| arg_disk_size_relative
!= UINT64_MAX
)
3718 arg_and_resize
= true;
3723 static int redirect_bus_mgr(void) {
3726 /* Talk to a different service if that's requested. (The same env var is also understood by homed, so
3727 * that it is relatively easily possible to invoke a second instance of homed for debug purposes and
3728 * have homectl talk to it, without colliding with the host version. This is handy when operating
3729 * from a homed-managed account.) */
3731 suffix
= getenv("SYSTEMD_HOME_DEBUG_SUFFIX");
3733 static BusLocator locator
= {
3734 .path
= "/org/freedesktop/home1",
3735 .interface
= "org.freedesktop.home1.Manager",
3738 /* Yes, we leak this memory, but there's little point to collect this, given that we only do
3739 * this in a debug environment, do it only once, and the string shall live for out entire
3740 * process runtime. */
3742 locator
.destination
= strjoin("org.freedesktop.home1.", suffix
);
3743 if (!locator
.destination
)
3748 bus_mgr
= bus_home_mgr
;
3753 static int run(int argc
, char *argv
[]) {
3754 static const Verb verbs
[] = {
3755 { "help", VERB_ANY
, VERB_ANY
, 0, help
},
3756 { "list", VERB_ANY
, 1, VERB_DEFAULT
, list_homes
},
3757 { "activate", 2, VERB_ANY
, 0, activate_home
},
3758 { "deactivate", 2, VERB_ANY
, 0, deactivate_home
},
3759 { "inspect", VERB_ANY
, VERB_ANY
, 0, inspect_home
},
3760 { "authenticate", VERB_ANY
, VERB_ANY
, 0, authenticate_home
},
3761 { "create", VERB_ANY
, 2, 0, create_home
},
3762 { "remove", 2, VERB_ANY
, 0, remove_home
},
3763 { "update", VERB_ANY
, 2, 0, update_home
},
3764 { "passwd", VERB_ANY
, 2, 0, passwd_home
},
3765 { "resize", 2, 3, 0, resize_home
},
3766 { "lock", 2, VERB_ANY
, 0, lock_home
},
3767 { "unlock", 2, VERB_ANY
, 0, unlock_home
},
3768 { "with", 2, VERB_ANY
, 0, with_home
},
3769 { "lock-all", VERB_ANY
, 1, 0, lock_all_homes
},
3770 { "deactivate-all", VERB_ANY
, 1, 0, deactivate_all_homes
},
3771 { "rebalance", VERB_ANY
, 1, 0, rebalance
},
3779 r
= redirect_bus_mgr();
3783 r
= parse_argv(argc
, argv
);
3787 return dispatch_verb(argc
, argv
, verbs
, NULL
);
3790 DEFINE_MAIN_FUNCTION_WITH_POSITIVE_FAILURE(run
);