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
;
65 static int arg_fido2_cred_alg
= COSE_ES256
;
67 static int arg_fido2_cred_alg
= 0;
69 static bool arg_recovery_key
= false;
70 static JsonFormatFlags arg_json_format_flags
= JSON_FORMAT_OFF
;
71 static bool arg_and_resize
= false;
72 static bool arg_and_change_password
= false;
74 EXPORT_FORMAT_FULL
, /* export the full record */
75 EXPORT_FORMAT_STRIPPED
, /* strip "state" + "binding", but leave signature in place */
76 EXPORT_FORMAT_MINIMAL
, /* also strip signature */
77 } arg_export_format
= EXPORT_FORMAT_FULL
;
79 STATIC_DESTRUCTOR_REGISTER(arg_identity_extra
, json_variant_unrefp
);
80 STATIC_DESTRUCTOR_REGISTER(arg_identity_extra_this_machine
, json_variant_unrefp
);
81 STATIC_DESTRUCTOR_REGISTER(arg_identity_extra_privileged
, json_variant_unrefp
);
82 STATIC_DESTRUCTOR_REGISTER(arg_identity_extra_rlimits
, json_variant_unrefp
);
83 STATIC_DESTRUCTOR_REGISTER(arg_identity_filter
, strv_freep
);
84 STATIC_DESTRUCTOR_REGISTER(arg_identity_filter_rlimits
, strv_freep
);
85 STATIC_DESTRUCTOR_REGISTER(arg_pkcs11_token_uri
, strv_freep
);
86 STATIC_DESTRUCTOR_REGISTER(arg_fido2_device
, strv_freep
);
88 static const BusLocator
*bus_mgr
;
90 static bool identity_properties_specified(void) {
93 !json_variant_is_blank_object(arg_identity_extra
) ||
94 !json_variant_is_blank_object(arg_identity_extra_privileged
) ||
95 !json_variant_is_blank_object(arg_identity_extra_this_machine
) ||
96 !json_variant_is_blank_object(arg_identity_extra_rlimits
) ||
97 !strv_isempty(arg_identity_filter
) ||
98 !strv_isempty(arg_identity_filter_rlimits
) ||
99 !strv_isempty(arg_pkcs11_token_uri
) ||
100 !strv_isempty(arg_fido2_device
);
103 static int acquire_bus(sd_bus
**bus
) {
111 r
= bus_connect_transport(arg_transport
, arg_host
, false, bus
);
113 return bus_log_connect_error(r
, arg_transport
);
115 (void) sd_bus_set_allow_interactive_authorization(*bus
, arg_ask_password
);
120 static int list_homes(int argc
, char *argv
[], void *userdata
) {
121 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
122 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
123 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
124 _cleanup_(table_unrefp
) Table
*table
= NULL
;
127 r
= acquire_bus(&bus
);
131 r
= bus_call_method(bus
, bus_mgr
, "ListHomes", &error
, &reply
, NULL
);
133 return log_error_errno(r
, "Failed to list homes: %s", bus_error_message(&error
, r
));
135 table
= table_new("name", "uid", "gid", "state", "realname", "home", "shell");
139 r
= sd_bus_message_enter_container(reply
, 'a', "(susussso)");
141 return bus_log_parse_error(r
);
144 const char *name
, *state
, *realname
, *home
, *shell
, *color
;
148 r
= sd_bus_message_read(reply
, "(susussso)", &name
, &uid
, &state
, &gid
, &realname
, &home
, &shell
, NULL
);
150 return bus_log_parse_error(r
);
154 r
= table_add_many(table
,
159 return table_log_add_error(r
);
162 r
= table_add_cell(table
, &cell
, TABLE_STRING
, state
);
164 return table_log_add_error(r
);
166 color
= user_record_state_color(state
);
168 (void) table_set_color(table
, cell
, color
);
170 r
= table_add_many(table
,
171 TABLE_STRING
, strna(empty_to_null(realname
)),
173 TABLE_STRING
, strna(empty_to_null(shell
)));
175 return table_log_add_error(r
);
178 r
= sd_bus_message_exit_container(reply
);
180 return bus_log_parse_error(r
);
182 if (table_get_rows(table
) > 1 || !FLAGS_SET(arg_json_format_flags
, JSON_FORMAT_OFF
)) {
183 r
= table_set_sort(table
, (size_t) 0);
185 return table_log_sort_error(r
);
187 r
= table_print_with_pager(table
, arg_json_format_flags
, arg_pager_flags
, arg_legend
);
192 if (arg_legend
&& (arg_json_format_flags
& JSON_FORMAT_OFF
)) {
193 if (table_get_rows(table
) > 1)
194 printf("\n%zu home areas listed.\n", table_get_rows(table
) - 1);
196 printf("No home areas.\n");
202 static int acquire_existing_password(
203 const char *user_name
,
205 bool emphasize_current
,
206 AskPasswordFlags flags
) {
208 _cleanup_(strv_free_erasep
) char **password
= NULL
;
209 _cleanup_(erase_and_freep
) char *envpw
= NULL
;
210 _cleanup_free_
char *question
= NULL
;
216 r
= getenv_steal_erase("PASSWORD", &envpw
);
218 return log_error_errno(r
, "Failed to acquire password from environment: %m");
220 /* People really shouldn't use environment variables for passing passwords. We support this
221 * only for testing purposes, and do not document the behaviour, so that people won't
222 * actually use this outside of testing. */
224 r
= user_record_set_password(hr
, STRV_MAKE(envpw
), true);
226 return log_error_errno(r
, "Failed to store password: %m");
231 /* If this is not our own user, then don't use the password cache */
232 if (is_this_me(user_name
) <= 0)
233 SET_FLAG(flags
, ASK_PASSWORD_ACCEPT_CACHED
|ASK_PASSWORD_PUSH_CACHE
, false);
235 if (asprintf(&question
, emphasize_current
?
236 "Please enter current password for user %s:" :
237 "Please enter password for user %s:",
241 r
= ask_password_auto(question
,
242 /* icon= */ "user-home",
244 /* key_name= */ "home-password",
245 /* credential_name= */ "home.password",
249 if (r
== -EUNATCH
) { /* EUNATCH is returned if no password was found and asking interactively was
250 * disabled via the flags. Not an error for us. */
251 log_debug_errno(r
, "No passwords acquired.");
255 return log_error_errno(r
, "Failed to acquire password: %m");
257 r
= user_record_set_password(hr
, password
, true);
259 return log_error_errno(r
, "Failed to store password: %m");
264 static int acquire_recovery_key(
265 const char *user_name
,
267 AskPasswordFlags flags
) {
269 _cleanup_(strv_free_erasep
) char **recovery_key
= NULL
;
270 _cleanup_(erase_and_freep
) char *envpw
= NULL
;
271 _cleanup_free_
char *question
= NULL
;
277 r
= getenv_steal_erase("PASSWORD", &envpw
);
279 return log_error_errno(r
, "Failed to acquire password from environment: %m");
281 /* People really shouldn't use environment variables for passing secrets. We support this
282 * only for testing purposes, and do not document the behaviour, so that people won't
283 * actually use this outside of testing. */
285 r
= user_record_set_password(hr
, STRV_MAKE(envpw
), true); /* recovery keys are stored in the record exactly like regular passwords! */
287 return log_error_errno(r
, "Failed to store recovery key: %m");
292 /* If this is not our own user, then don't use the password cache */
293 if (is_this_me(user_name
) <= 0)
294 SET_FLAG(flags
, ASK_PASSWORD_ACCEPT_CACHED
|ASK_PASSWORD_PUSH_CACHE
, false);
296 if (asprintf(&question
, "Please enter recovery key for user %s:", user_name
) < 0)
299 r
= ask_password_auto(question
,
300 /* icon= */ "user-home",
302 /* key_name= */ "home-recovery-key",
303 /* credential_name= */ "home.recovery-key",
307 if (r
== -EUNATCH
) { /* EUNATCH is returned if no recovery key was found and asking interactively was
308 * disabled via the flags. Not an error for us. */
309 log_debug_errno(r
, "No recovery keys acquired.");
313 return log_error_errno(r
, "Failed to acquire recovery keys: %m");
315 r
= user_record_set_password(hr
, recovery_key
, true);
317 return log_error_errno(r
, "Failed to store recovery keys: %m");
322 static int acquire_token_pin(
323 const char *user_name
,
325 AskPasswordFlags flags
) {
327 _cleanup_(strv_free_erasep
) char **pin
= NULL
;
328 _cleanup_(erase_and_freep
) char *envpin
= NULL
;
329 _cleanup_free_
char *question
= NULL
;
335 r
= getenv_steal_erase("PIN", &envpin
);
337 return log_error_errno(r
, "Failed to acquire PIN from environment: %m");
339 r
= user_record_set_token_pin(hr
, STRV_MAKE(envpin
), false);
341 return log_error_errno(r
, "Failed to store token PIN: %m");
346 /* If this is not our own user, then don't use the password cache */
347 if (is_this_me(user_name
) <= 0)
348 SET_FLAG(flags
, ASK_PASSWORD_ACCEPT_CACHED
|ASK_PASSWORD_PUSH_CACHE
, false);
350 if (asprintf(&question
, "Please enter security token PIN for user %s:", user_name
) < 0)
353 r
= ask_password_auto(
355 /* icon= */ "user-home",
357 /* key_name= */ "token-pin",
358 /* credential_name= */ "home.token-pin",
362 if (r
== -EUNATCH
) { /* EUNATCH is returned if no PIN was found and asking interactively was disabled
363 * via the flags. Not an error for us. */
364 log_debug_errno(r
, "No security token PINs acquired.");
368 return log_error_errno(r
, "Failed to acquire security token PIN: %m");
370 r
= user_record_set_token_pin(hr
, pin
, false);
372 return log_error_errno(r
, "Failed to store security token PIN: %m");
377 static int handle_generic_user_record_error(
378 const char *user_name
,
380 const sd_bus_error
*error
,
382 bool emphasize_current_password
) {
388 if (sd_bus_error_has_name(error
, BUS_ERROR_HOME_ABSENT
))
389 return log_error_errno(SYNTHETIC_ERRNO(EREMOTE
),
390 "Home of user %s is currently absent, please plug in the necessary storage device or backing file system.", user_name
);
392 else if (sd_bus_error_has_name(error
, BUS_ERROR_AUTHENTICATION_LIMIT_HIT
))
393 return log_error_errno(SYNTHETIC_ERRNO(ETOOMANYREFS
),
394 "Too frequent login attempts for user %s, try again later.", user_name
);
396 else if (sd_bus_error_has_name(error
, BUS_ERROR_BAD_PASSWORD
)) {
398 if (!strv_isempty(hr
->password
))
399 log_notice("Password incorrect or not sufficient, please try again.");
401 /* Don't consume cache entries or credentials here, we already tried that unsuccessfully. But
402 * let's push what we acquire here into the cache */
403 r
= acquire_existing_password(
406 emphasize_current_password
,
407 ASK_PASSWORD_PUSH_CACHE
| ASK_PASSWORD_NO_CREDENTIAL
);
411 } else if (sd_bus_error_has_name(error
, BUS_ERROR_BAD_RECOVERY_KEY
)) {
413 if (!strv_isempty(hr
->password
))
414 log_notice("Recovery key incorrect or not sufficient, please try again.");
416 /* Don't consume cache entries or credentials here, we already tried that unsuccessfully. But
417 * let's push what we acquire here into the cache */
418 r
= acquire_recovery_key(
421 ASK_PASSWORD_PUSH_CACHE
| ASK_PASSWORD_NO_CREDENTIAL
);
425 } else if (sd_bus_error_has_name(error
, BUS_ERROR_BAD_PASSWORD_AND_NO_TOKEN
)) {
427 if (strv_isempty(hr
->password
))
428 log_notice("Security token not inserted, please enter password.");
430 log_notice("Password incorrect or not sufficient, and configured security token not inserted, please try again.");
432 r
= acquire_existing_password(
435 emphasize_current_password
,
436 ASK_PASSWORD_PUSH_CACHE
| ASK_PASSWORD_NO_CREDENTIAL
);
440 } else if (sd_bus_error_has_name(error
, BUS_ERROR_TOKEN_PIN_NEEDED
)) {
442 /* First time the PIN is requested, let's accept cached data, and allow using credential store */
443 r
= acquire_token_pin(
446 ASK_PASSWORD_ACCEPT_CACHED
| ASK_PASSWORD_PUSH_CACHE
);
450 } else if (sd_bus_error_has_name(error
, BUS_ERROR_TOKEN_PROTECTED_AUTHENTICATION_PATH_NEEDED
)) {
452 log_notice("%s%sPlease authenticate physically on security token.",
453 emoji_enabled() ? special_glyph(SPECIAL_GLYPH_TOUCH
) : "",
454 emoji_enabled() ? " " : "");
456 r
= user_record_set_pkcs11_protected_authentication_path_permitted(hr
, true);
458 return log_error_errno(r
, "Failed to set PKCS#11 protected authentication path permitted flag: %m");
460 } else if (sd_bus_error_has_name(error
, BUS_ERROR_TOKEN_USER_PRESENCE_NEEDED
)) {
462 log_notice("%s%sPlease confirm presence on security token.",
463 emoji_enabled() ? special_glyph(SPECIAL_GLYPH_TOUCH
) : "",
464 emoji_enabled() ? " " : "");
466 r
= user_record_set_fido2_user_presence_permitted(hr
, true);
468 return log_error_errno(r
, "Failed to set FIDO2 user presence permitted flag: %m");
470 } else if (sd_bus_error_has_name(error
, BUS_ERROR_TOKEN_USER_VERIFICATION_NEEDED
)) {
472 log_notice("%s%sPlease verify user on security token.",
473 emoji_enabled() ? special_glyph(SPECIAL_GLYPH_TOUCH
) : "",
474 emoji_enabled() ? " " : "");
476 r
= user_record_set_fido2_user_verification_permitted(hr
, true);
478 return log_error_errno(r
, "Failed to set FIDO2 user verification permitted flag: %m");
480 } else if (sd_bus_error_has_name(error
, BUS_ERROR_TOKEN_PIN_LOCKED
))
481 return log_error_errno(SYNTHETIC_ERRNO(EPERM
), "Security token PIN is locked, please unlock it first. (Hint: Removal and re-insertion might suffice.)");
483 else if (sd_bus_error_has_name(error
, BUS_ERROR_TOKEN_BAD_PIN
)) {
485 log_notice("Security token PIN incorrect, please try again.");
487 /* If the previous PIN was wrong don't accept cached info anymore, but add to cache. Also, don't use the credential data */
488 r
= acquire_token_pin(
491 ASK_PASSWORD_PUSH_CACHE
| ASK_PASSWORD_NO_CREDENTIAL
);
495 } else if (sd_bus_error_has_name(error
, BUS_ERROR_TOKEN_BAD_PIN_FEW_TRIES_LEFT
)) {
497 log_notice("Security token PIN incorrect, please try again (only a few tries left!).");
499 r
= acquire_token_pin(
502 ASK_PASSWORD_PUSH_CACHE
| ASK_PASSWORD_NO_CREDENTIAL
);
506 } else if (sd_bus_error_has_name(error
, BUS_ERROR_TOKEN_BAD_PIN_ONE_TRY_LEFT
)) {
508 log_notice("Security token PIN incorrect, please try again (only one try left!).");
510 r
= acquire_token_pin(
513 ASK_PASSWORD_PUSH_CACHE
| ASK_PASSWORD_NO_CREDENTIAL
);
517 return log_error_errno(ret
, "Operation on home %s failed: %s", user_name
, bus_error_message(error
, ret
));
522 static int acquire_passed_secrets(const char *user_name
, UserRecord
**ret
) {
523 _cleanup_(user_record_unrefp
) UserRecord
*secret
= NULL
;
528 /* Generates an initial secret objects that contains passwords supplied via $PASSWORD, the password
529 * cache or the credentials subsystem, but excluding any interactive stuff. If nothing is passed,
530 * returns an empty secret object. */
532 secret
= user_record_new();
536 r
= acquire_existing_password(
539 /* emphasize_current_password = */ false,
540 ASK_PASSWORD_ACCEPT_CACHED
| ASK_PASSWORD_NO_TTY
| ASK_PASSWORD_NO_AGENT
);
544 r
= acquire_token_pin(
547 ASK_PASSWORD_ACCEPT_CACHED
| ASK_PASSWORD_NO_TTY
| ASK_PASSWORD_NO_AGENT
);
551 r
= acquire_recovery_key(
554 ASK_PASSWORD_ACCEPT_CACHED
| ASK_PASSWORD_NO_TTY
| ASK_PASSWORD_NO_AGENT
);
558 *ret
= TAKE_PTR(secret
);
562 static int activate_home(int argc
, char *argv
[], void *userdata
) {
563 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
566 r
= acquire_bus(&bus
);
570 STRV_FOREACH(i
, strv_skip(argv
, 1)) {
571 _cleanup_(user_record_unrefp
) UserRecord
*secret
= NULL
;
573 r
= acquire_passed_secrets(*i
, &secret
);
578 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
579 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
581 r
= bus_message_new_method_call(bus
, &m
, bus_mgr
, "ActivateHome");
583 return bus_log_create_error(r
);
585 r
= sd_bus_message_append(m
, "s", *i
);
587 return bus_log_create_error(r
);
589 r
= bus_message_append_secret(m
, secret
);
591 return bus_log_create_error(r
);
593 r
= sd_bus_call(bus
, m
, HOME_SLOW_BUS_CALL_TIMEOUT_USEC
, &error
, NULL
);
595 r
= handle_generic_user_record_error(*i
, secret
, &error
, r
, /* emphasize_current_password= */ false);
610 static int deactivate_home(int argc
, char *argv
[], void *userdata
) {
611 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
614 r
= acquire_bus(&bus
);
618 STRV_FOREACH(i
, strv_skip(argv
, 1)) {
619 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
620 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
622 r
= bus_message_new_method_call(bus
, &m
, bus_mgr
, "DeactivateHome");
624 return bus_log_create_error(r
);
626 r
= sd_bus_message_append(m
, "s", *i
);
628 return bus_log_create_error(r
);
630 r
= sd_bus_call(bus
, m
, HOME_SLOW_BUS_CALL_TIMEOUT_USEC
, &error
, NULL
);
632 log_error_errno(r
, "Failed to deactivate user home: %s", bus_error_message(&error
, r
));
641 static void dump_home_record(UserRecord
*hr
) {
646 if (hr
->incomplete
) {
648 log_warning("Warning: lacking rights to acquire privileged fields of user record of '%s', output incomplete.", hr
->user_name
);
651 if (arg_json_format_flags
& JSON_FORMAT_OFF
)
652 user_record_show(hr
, true);
654 _cleanup_(user_record_unrefp
) UserRecord
*stripped
= NULL
;
656 if (arg_export_format
== EXPORT_FORMAT_STRIPPED
)
657 r
= user_record_clone(hr
, USER_RECORD_EXTRACT_EMBEDDED
|USER_RECORD_PERMISSIVE
, &stripped
);
658 else if (arg_export_format
== EXPORT_FORMAT_MINIMAL
)
659 r
= user_record_clone(hr
, USER_RECORD_EXTRACT_SIGNABLE
|USER_RECORD_PERMISSIVE
, &stripped
);
663 log_warning_errno(r
, "Failed to strip user record, ignoring: %m");
667 json_variant_dump(hr
->json
, arg_json_format_flags
, stdout
, NULL
);
671 static char **mangle_user_list(char **list
, char ***ret_allocated
) {
672 _cleanup_free_
char *myself
= NULL
;
675 if (!strv_isempty(list
)) {
676 *ret_allocated
= NULL
;
680 myself
= getusername_malloc();
688 l
[0] = TAKE_PTR(myself
);
695 static int inspect_home(int argc
, char *argv
[], void *userdata
) {
696 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
697 _cleanup_(strv_freep
) char **mangled_list
= NULL
;
701 pager_open(arg_pager_flags
);
703 r
= acquire_bus(&bus
);
707 items
= mangle_user_list(strv_skip(argv
, 1), &mangled_list
);
711 STRV_FOREACH(i
, items
) {
712 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
713 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
714 _cleanup_(json_variant_unrefp
) JsonVariant
*v
= NULL
;
715 _cleanup_(user_record_unrefp
) UserRecord
*hr
= NULL
;
720 r
= parse_uid(*i
, &uid
);
722 if (!valid_user_group_name(*i
, 0)) {
723 log_error("Invalid user name '%s'.", *i
);
730 r
= bus_call_method(bus
, bus_mgr
, "GetUserRecordByName", &error
, &reply
, "s", *i
);
732 r
= bus_call_method(bus
, bus_mgr
, "GetUserRecordByUID", &error
, &reply
, "u", (uint32_t) uid
);
735 log_error_errno(r
, "Failed to inspect home: %s", bus_error_message(&error
, r
));
742 r
= sd_bus_message_read(reply
, "sbo", &json
, &incomplete
, NULL
);
744 bus_log_parse_error(r
);
751 r
= json_parse(json
, JSON_PARSE_SENSITIVE
, &v
, NULL
, NULL
);
753 log_error_errno(r
, "Failed to parse JSON identity: %m");
760 hr
= user_record_new();
764 r
= user_record_load(hr
, v
, USER_RECORD_LOAD_REFUSE_SECRET
|USER_RECORD_LOG
|USER_RECORD_PERMISSIVE
);
772 hr
->incomplete
= incomplete
;
773 dump_home_record(hr
);
779 static int authenticate_home(int argc
, char *argv
[], void *userdata
) {
780 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
781 _cleanup_(strv_freep
) char **mangled_list
= NULL
;
785 items
= mangle_user_list(strv_skip(argv
, 1), &mangled_list
);
789 r
= acquire_bus(&bus
);
793 (void) polkit_agent_open_if_enabled(arg_transport
, arg_ask_password
);
795 STRV_FOREACH(i
, items
) {
796 _cleanup_(user_record_unrefp
) UserRecord
*secret
= NULL
;
798 r
= acquire_passed_secrets(*i
, &secret
);
803 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
804 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
806 r
= bus_message_new_method_call(bus
, &m
, bus_mgr
, "AuthenticateHome");
808 return bus_log_create_error(r
);
810 r
= sd_bus_message_append(m
, "s", *i
);
812 return bus_log_create_error(r
);
814 r
= bus_message_append_secret(m
, secret
);
816 return bus_log_create_error(r
);
818 r
= sd_bus_call(bus
, m
, HOME_SLOW_BUS_CALL_TIMEOUT_USEC
, &error
, NULL
);
820 r
= handle_generic_user_record_error(*i
, secret
, &error
, r
, false);
835 static int update_last_change(JsonVariant
**v
, bool with_password
, bool override
) {
842 n
= now(CLOCK_REALTIME
);
844 c
= json_variant_by_key(*v
, "lastChangeUSec");
849 goto update_password
;
851 if (!json_variant_is_unsigned(c
))
852 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "lastChangeUSec field is not an unsigned integer, refusing.");
854 u
= json_variant_unsigned(c
);
856 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "lastChangeUSec is from the future, can't update.");
859 r
= json_variant_set_field_unsigned(v
, "lastChangeUSec", n
);
861 return log_error_errno(r
, "Failed to update lastChangeUSec: %m");
867 c
= json_variant_by_key(*v
, "lastPasswordChangeUSec");
874 if (!json_variant_is_unsigned(c
))
875 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "lastPasswordChangeUSec field is not an unsigned integer, refusing.");
877 u
= json_variant_unsigned(c
);
879 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "lastPasswordChangeUSec is from the future, can't update.");
882 r
= json_variant_set_field_unsigned(v
, "lastPasswordChangeUSec", n
);
884 return log_error_errno(r
, "Failed to update lastPasswordChangeUSec: %m");
889 static int apply_identity_changes(JsonVariant
**_v
) {
890 _cleanup_(json_variant_unrefp
) JsonVariant
*v
= NULL
;
895 v
= json_variant_ref(*_v
);
897 r
= json_variant_filter(&v
, arg_identity_filter
);
899 return log_error_errno(r
, "Failed to filter identity: %m");
901 r
= json_variant_merge(&v
, arg_identity_extra
);
903 return log_error_errno(r
, "Failed to merge identities: %m");
905 if (arg_identity_extra_this_machine
|| !strv_isempty(arg_identity_filter
)) {
906 _cleanup_(json_variant_unrefp
) JsonVariant
*per_machine
= NULL
, *mmid
= NULL
;
909 r
= sd_id128_get_machine(&mid
);
911 return log_error_errno(r
, "Failed to acquire machine ID: %m");
913 r
= json_variant_new_string(&mmid
, SD_ID128_TO_STRING(mid
));
915 return log_error_errno(r
, "Failed to allocate matchMachineId object: %m");
917 per_machine
= json_variant_ref(json_variant_by_key(v
, "perMachine"));
919 _cleanup_(json_variant_unrefp
) JsonVariant
*npm
= NULL
, *add
= NULL
;
920 _cleanup_free_ JsonVariant
**array
= NULL
;
924 if (!json_variant_is_array(per_machine
))
925 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "perMachine field is not an array, refusing.");
927 array
= new(JsonVariant
*, json_variant_elements(per_machine
) + 1);
931 JSON_VARIANT_ARRAY_FOREACH(z
, per_machine
) {
934 if (!json_variant_is_object(z
))
935 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "perMachine entry is not an object, refusing.");
939 u
= json_variant_by_key(z
, "matchMachineId");
943 if (!json_variant_equal(u
, mmid
))
946 r
= json_variant_merge(&add
, z
);
948 return log_error_errno(r
, "Failed to merge perMachine entry: %m");
953 r
= json_variant_filter(&add
, arg_identity_filter
);
955 return log_error_errno(r
, "Failed to filter perMachine: %m");
957 r
= json_variant_merge(&add
, arg_identity_extra_this_machine
);
959 return log_error_errno(r
, "Failed to merge in perMachine fields: %m");
961 if (arg_identity_filter_rlimits
|| arg_identity_extra_rlimits
) {
962 _cleanup_(json_variant_unrefp
) JsonVariant
*rlv
= NULL
;
964 rlv
= json_variant_ref(json_variant_by_key(add
, "resourceLimits"));
966 r
= json_variant_filter(&rlv
, arg_identity_filter_rlimits
);
968 return log_error_errno(r
, "Failed to filter resource limits: %m");
970 r
= json_variant_merge(&rlv
, arg_identity_extra_rlimits
);
972 return log_error_errno(r
, "Failed to set resource limits: %m");
974 if (json_variant_is_blank_object(rlv
)) {
975 r
= json_variant_filter(&add
, STRV_MAKE("resourceLimits"));
977 return log_error_errno(r
, "Failed to drop resource limits field from identity: %m");
979 r
= json_variant_set_field(&add
, "resourceLimits", rlv
);
981 return log_error_errno(r
, "Failed to update resource limits of identity: %m");
985 if (!json_variant_is_blank_object(add
)) {
986 r
= json_variant_set_field(&add
, "matchMachineId", mmid
);
988 return log_error_errno(r
, "Failed to set matchMachineId field: %m");
993 r
= json_variant_new_array(&npm
, array
, i
);
995 return log_error_errno(r
, "Failed to allocate new perMachine array: %m");
997 json_variant_unref(per_machine
);
998 per_machine
= TAKE_PTR(npm
);
1000 _cleanup_(json_variant_unrefp
) JsonVariant
*item
= json_variant_ref(arg_identity_extra_this_machine
);
1002 if (arg_identity_extra_rlimits
) {
1003 r
= json_variant_set_field(&item
, "resourceLimits", arg_identity_extra_rlimits
);
1005 return log_error_errno(r
, "Failed to update resource limits of identity: %m");
1008 r
= json_variant_set_field(&item
, "matchMachineId", mmid
);
1010 return log_error_errno(r
, "Failed to set matchMachineId field: %m");
1012 r
= json_variant_append_array(&per_machine
, item
);
1014 return log_error_errno(r
, "Failed to append to perMachine array: %m");
1017 r
= json_variant_set_field(&v
, "perMachine", per_machine
);
1019 return log_error_errno(r
, "Failed to update per machine record: %m");
1022 if (arg_identity_extra_privileged
|| arg_identity_filter
) {
1023 _cleanup_(json_variant_unrefp
) JsonVariant
*privileged
= NULL
;
1025 privileged
= json_variant_ref(json_variant_by_key(v
, "privileged"));
1027 r
= json_variant_filter(&privileged
, arg_identity_filter
);
1029 return log_error_errno(r
, "Failed to filter identity (privileged part): %m");
1031 r
= json_variant_merge(&privileged
, arg_identity_extra_privileged
);
1033 return log_error_errno(r
, "Failed to merge identities (privileged part): %m");
1035 if (json_variant_is_blank_object(privileged
)) {
1036 r
= json_variant_filter(&v
, STRV_MAKE("privileged"));
1038 return log_error_errno(r
, "Failed to drop privileged part from identity: %m");
1040 r
= json_variant_set_field(&v
, "privileged", privileged
);
1042 return log_error_errno(r
, "Failed to update privileged part of identity: %m");
1046 if (arg_identity_filter_rlimits
) {
1047 _cleanup_(json_variant_unrefp
) JsonVariant
*rlv
= NULL
;
1049 rlv
= json_variant_ref(json_variant_by_key(v
, "resourceLimits"));
1051 r
= json_variant_filter(&rlv
, arg_identity_filter_rlimits
);
1053 return log_error_errno(r
, "Failed to filter resource limits: %m");
1055 /* Note that we only filter resource limits here, but don't apply them. We do that in the perMachine section */
1057 if (json_variant_is_blank_object(rlv
)) {
1058 r
= json_variant_filter(&v
, STRV_MAKE("resourceLimits"));
1060 return log_error_errno(r
, "Failed to drop resource limits field from identity: %m");
1062 r
= json_variant_set_field(&v
, "resourceLimits", rlv
);
1064 return log_error_errno(r
, "Failed to update resource limits of identity: %m");
1068 json_variant_unref(*_v
);
1074 static int add_disposition(JsonVariant
**v
) {
1079 if (json_variant_by_key(*v
, "disposition"))
1082 /* Set the disposition to regular, if not configured explicitly */
1083 r
= json_variant_set_field_string(v
, "disposition", "regular");
1085 return log_error_errno(r
, "Failed to set disposition field: %m");
1090 static int acquire_new_home_record(UserRecord
**ret
) {
1091 _cleanup_(json_variant_unrefp
) JsonVariant
*v
= NULL
;
1092 _cleanup_(user_record_unrefp
) UserRecord
*hr
= NULL
;
1098 unsigned line
, column
;
1100 r
= json_parse_file(
1101 streq(arg_identity
, "-") ? stdin
: NULL
,
1102 streq(arg_identity
, "-") ? "<stdin>" : arg_identity
, JSON_PARSE_SENSITIVE
, &v
, &line
, &column
);
1104 return log_error_errno(r
, "Failed to parse identity at %u:%u: %m", line
, column
);
1107 r
= apply_identity_changes(&v
);
1111 r
= add_disposition(&v
);
1115 STRV_FOREACH(i
, arg_pkcs11_token_uri
) {
1116 r
= identity_add_pkcs11_key_data(&v
, *i
);
1121 STRV_FOREACH(i
, arg_fido2_device
) {
1122 r
= identity_add_fido2_parameters(&v
, *i
, arg_fido2_lock_with
, arg_fido2_cred_alg
);
1127 if (arg_recovery_key
) {
1128 r
= identity_add_recovery_key(&v
);
1133 r
= update_last_change(&v
, true, false);
1138 json_variant_dump(v
, JSON_FORMAT_PRETTY
, NULL
, NULL
);
1140 hr
= user_record_new();
1144 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
);
1148 *ret
= TAKE_PTR(hr
);
1152 static int acquire_new_password(
1153 const char *user_name
,
1158 _cleanup_(erase_and_freep
) char *envpw
= NULL
;
1165 r
= getenv_steal_erase("NEWPASSWORD", &envpw
);
1167 return log_error_errno(r
, "Failed to acquire password from environment: %m");
1169 /* As above, this is not for use, just for testing */
1171 r
= user_record_set_password(hr
, STRV_MAKE(envpw
), /* prepend = */ true);
1173 return log_error_errno(r
, "Failed to store password: %m");
1176 *ret
= TAKE_PTR(envpw
);
1182 (void) suggest_passwords();
1185 _cleanup_(strv_free_erasep
) char **first
= NULL
, **second
= NULL
;
1186 _cleanup_free_
char *question
= NULL
;
1189 return log_error_errno(SYNTHETIC_ERRNO(ENOKEY
), "Too many attempts, giving up:");
1191 if (asprintf(&question
, "Please enter new password for user %s:", user_name
) < 0)
1194 r
= ask_password_auto(
1196 /* icon= */ "user-home",
1198 /* key_name= */ "home-password",
1199 /* credential_name= */ "home.new-password",
1201 0, /* no caching, we want to collect a new password here after all */
1204 return log_error_errno(r
, "Failed to acquire password: %m");
1206 question
= mfree(question
);
1207 if (asprintf(&question
, "Please enter new password for user %s (repeat):", user_name
) < 0)
1210 r
= ask_password_auto(
1212 /* icon= */ "user-home",
1214 /* key_name= */ "home-password",
1215 /* credential_name= */ "home.new-password",
1220 return log_error_errno(r
, "Failed to acquire password: %m");
1222 if (strv_equal(first
, second
)) {
1223 _cleanup_(erase_and_freep
) char *copy
= NULL
;
1226 copy
= strdup(first
[0]);
1231 r
= user_record_set_password(hr
, first
, /* prepend = */ true);
1233 return log_error_errno(r
, "Failed to store password: %m");
1236 *ret
= TAKE_PTR(copy
);
1241 log_error("Password didn't match, try again.");
1245 static int create_home(int argc
, char *argv
[], void *userdata
) {
1246 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
1247 _cleanup_(user_record_unrefp
) UserRecord
*hr
= NULL
;
1250 r
= acquire_bus(&bus
);
1254 (void) polkit_agent_open_if_enabled(arg_transport
, arg_ask_password
);
1257 /* If a username was specified, use it */
1259 if (valid_user_group_name(argv
[1], 0))
1260 r
= json_variant_set_field_string(&arg_identity_extra
, "userName", argv
[1]);
1262 _cleanup_free_
char *un
= NULL
, *rr
= NULL
;
1264 /* Before we consider the user name invalid, let's check if we can split it? */
1265 r
= split_user_name_realm(argv
[1], &un
, &rr
);
1267 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "User name '%s' is not valid: %m", argv
[1]);
1270 r
= json_variant_set_field_string(&arg_identity_extra
, "realm", rr
);
1272 return log_error_errno(r
, "Failed to set realm field: %m");
1275 r
= json_variant_set_field_string(&arg_identity_extra
, "userName", un
);
1278 return log_error_errno(r
, "Failed to set userName field: %m");
1280 /* If neither a username nor an identity have been specified we cannot operate. */
1282 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "User name required.");
1285 r
= acquire_new_home_record(&hr
);
1289 /* If the JSON record carries no plain text password (besides the recovery key), then let's query it
1291 if (strv_length(hr
->password
) <= arg_recovery_key
) {
1293 if (strv_isempty(hr
->hashed_password
)) {
1294 _cleanup_(erase_and_freep
) char *new_password
= NULL
;
1296 /* No regular (i.e. non-PKCS#11) hashed passwords set in the record, let's fix that. */
1297 r
= acquire_new_password(hr
->user_name
, hr
, /* suggest = */ true, &new_password
);
1301 r
= user_record_make_hashed_password(hr
, STRV_MAKE(new_password
), /* extend = */ false);
1303 return log_error_errno(r
, "Failed to hash password: %m");
1305 /* There's a hash password set in the record, acquire the unhashed version of it. */
1306 r
= acquire_existing_password(
1309 /* emphasize_current= */ false,
1310 ASK_PASSWORD_ACCEPT_CACHED
| ASK_PASSWORD_PUSH_CACHE
);
1316 if (hr
->enforce_password_policy
== 0) {
1317 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1319 /* If password quality enforcement is disabled, let's at least warn client side */
1321 r
= user_record_quality_check_password(hr
, hr
, &error
);
1323 log_warning_errno(r
, "Specified password does not pass quality checks (%s), proceeding anyway.", bus_error_message(&error
, r
));
1327 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1328 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
1329 _cleanup_(erase_and_freep
) char *formatted
= NULL
;
1331 r
= json_variant_format(hr
->json
, 0, &formatted
);
1333 return log_error_errno(r
, "Failed to format user record: %m");
1335 r
= bus_message_new_method_call(bus
, &m
, bus_mgr
, "CreateHome");
1337 return bus_log_create_error(r
);
1339 (void) sd_bus_message_sensitive(m
);
1341 r
= sd_bus_message_append(m
, "s", formatted
);
1343 return bus_log_create_error(r
);
1345 r
= sd_bus_call(bus
, m
, HOME_SLOW_BUS_CALL_TIMEOUT_USEC
, &error
, NULL
);
1347 if (sd_bus_error_has_name(&error
, BUS_ERROR_LOW_PASSWORD_QUALITY
)) {
1348 _cleanup_(erase_and_freep
) char *new_password
= NULL
;
1350 log_error_errno(r
, "%s", bus_error_message(&error
, r
));
1351 log_info("(Use --enforce-password-policy=no to turn off password quality checks for this account.)");
1353 r
= acquire_new_password(hr
->user_name
, hr
, /* suggest = */ false, &new_password
);
1357 r
= user_record_make_hashed_password(hr
, STRV_MAKE(new_password
), /* extend = */ false);
1359 return log_error_errno(r
, "Failed to hash passwords: %m");
1361 r
= handle_generic_user_record_error(hr
->user_name
, hr
, &error
, r
, false);
1372 static int remove_home(int argc
, char *argv
[], void *userdata
) {
1373 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
1376 r
= acquire_bus(&bus
);
1380 (void) polkit_agent_open_if_enabled(arg_transport
, arg_ask_password
);
1382 STRV_FOREACH(i
, strv_skip(argv
, 1)) {
1383 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1384 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
1386 r
= bus_message_new_method_call(bus
, &m
, bus_mgr
, "RemoveHome");
1388 return bus_log_create_error(r
);
1390 r
= sd_bus_message_append(m
, "s", *i
);
1392 return bus_log_create_error(r
);
1394 r
= sd_bus_call(bus
, m
, HOME_SLOW_BUS_CALL_TIMEOUT_USEC
, &error
, NULL
);
1396 log_error_errno(r
, "Failed to remove home: %s", bus_error_message(&error
, r
));
1405 static int acquire_updated_home_record(
1407 const char *username
,
1410 _cleanup_(json_variant_unrefp
) JsonVariant
*json
= NULL
;
1411 _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
, arg_fido2_cred_alg
);
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
),
1692 "To change the PKCS#11 security token use 'homectl update --pkcs11-token-uri=%s'.",
1693 special_glyph(SPECIAL_GLYPH_ELLIPSIS
));
1694 if (arg_fido2_device
)
1695 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
1696 "To change the FIDO2 security token use 'homectl update --fido2-device=%s'.",
1697 special_glyph(SPECIAL_GLYPH_ELLIPSIS
));
1698 if (identity_properties_specified())
1699 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "The 'passwd' verb does not permit changing other record properties at the same time.");
1704 buffer
= getusername_malloc();
1711 r
= acquire_bus(&bus
);
1715 (void) polkit_agent_open_if_enabled(arg_transport
, arg_ask_password
);
1717 r
= acquire_passed_secrets(username
, &old_secret
);
1721 new_secret
= user_record_new();
1725 r
= acquire_new_password(username
, new_secret
, /* suggest = */ true, NULL
);
1730 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1731 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
1733 r
= bus_message_new_method_call(bus
, &m
, bus_mgr
, "ChangePasswordHome");
1735 return bus_log_create_error(r
);
1737 r
= sd_bus_message_append(m
, "s", username
);
1739 return bus_log_create_error(r
);
1741 r
= bus_message_append_secret(m
, new_secret
);
1743 return bus_log_create_error(r
);
1745 r
= bus_message_append_secret(m
, old_secret
);
1747 return bus_log_create_error(r
);
1749 r
= sd_bus_call(bus
, m
, HOME_SLOW_BUS_CALL_TIMEOUT_USEC
, &error
, NULL
);
1751 if (sd_bus_error_has_name(&error
, BUS_ERROR_LOW_PASSWORD_QUALITY
)) {
1753 log_error_errno(r
, "%s", bus_error_message(&error
, r
));
1755 r
= acquire_new_password(username
, new_secret
, /* suggest = */ false, NULL
);
1757 } else if (sd_bus_error_has_name(&error
, BUS_ERROR_BAD_PASSWORD_AND_NO_TOKEN
))
1759 /* In the generic handler we'd ask for a password in this case, but when
1760 * changing passwords that's not sufficeint, as we need to acquire all keys
1762 return log_error_errno(r
, "Security token not inserted, refusing.");
1764 r
= handle_generic_user_record_error(username
, old_secret
, &error
, r
, true);
1774 static int parse_disk_size(const char *t
, uint64_t *ret
) {
1780 if (streq(t
, "min"))
1782 else if (streq(t
, "max"))
1783 *ret
= UINT64_MAX
-1; /* Largest size that isn't UINT64_MAX special marker */
1787 r
= parse_size(t
, 1024, &ds
);
1789 return log_error_errno(r
, "Failed to parse disk size parameter: %s", t
);
1791 if (ds
>= UINT64_MAX
) /* UINT64_MAX has special meaning for us ("dont change"), refuse */
1792 return log_error_errno(SYNTHETIC_ERRNO(ERANGE
), "Disk size out of range: %s", t
);
1800 static int parse_sector_size(const char *t
, uint64_t *ret
) {
1808 r
= safe_atou64(t
, &ss
);
1810 return log_error_errno(r
, "Failed to parse sector size parameter %s", t
);
1811 if (ss
< 512 || ss
> 4096) /* Allow up to 4K due to dm-crypt support and 4K alignment by the homed LUKS backend */
1812 return log_error_errno(SYNTHETIC_ERRNO(ERANGE
), "Sector size not between 512 and 4096: %s", t
);
1813 if (!ISPOWEROF2(ss
))
1814 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Sector size not power of 2: %s", t
);
1820 static int resize_home(int argc
, char *argv
[], void *userdata
) {
1821 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
1822 _cleanup_(user_record_unrefp
) UserRecord
*secret
= NULL
;
1823 uint64_t ds
= UINT64_MAX
;
1826 r
= acquire_bus(&bus
);
1830 (void) polkit_agent_open_if_enabled(arg_transport
, arg_ask_password
);
1832 if (arg_disk_size_relative
!= UINT64_MAX
||
1833 (argc
> 2 && parse_permyriad(argv
[2]) >= 0))
1834 return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP
),
1835 "Relative disk size specification currently not supported when resizing.");
1838 r
= parse_disk_size(argv
[2], &ds
);
1843 if (arg_disk_size
!= UINT64_MAX
) {
1844 if (ds
!= UINT64_MAX
&& ds
!= arg_disk_size
)
1845 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Disk size specified twice and doesn't match, refusing.");
1850 r
= acquire_passed_secrets(argv
[1], &secret
);
1855 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1856 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
1858 r
= bus_message_new_method_call(bus
, &m
, bus_mgr
, "ResizeHome");
1860 return bus_log_create_error(r
);
1862 r
= sd_bus_message_append(m
, "st", argv
[1], ds
);
1864 return bus_log_create_error(r
);
1866 r
= bus_message_append_secret(m
, secret
);
1868 return bus_log_create_error(r
);
1870 r
= sd_bus_call(bus
, m
, HOME_SLOW_BUS_CALL_TIMEOUT_USEC
, &error
, NULL
);
1872 r
= handle_generic_user_record_error(argv
[1], secret
, &error
, r
, false);
1882 static int lock_home(int argc
, char *argv
[], void *userdata
) {
1883 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
1886 r
= acquire_bus(&bus
);
1890 STRV_FOREACH(i
, strv_skip(argv
, 1)) {
1891 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1892 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
1894 r
= bus_message_new_method_call(bus
, &m
, bus_mgr
, "LockHome");
1896 return bus_log_create_error(r
);
1898 r
= sd_bus_message_append(m
, "s", *i
);
1900 return bus_log_create_error(r
);
1902 r
= sd_bus_call(bus
, m
, HOME_SLOW_BUS_CALL_TIMEOUT_USEC
, &error
, NULL
);
1904 log_error_errno(r
, "Failed to lock home: %s", bus_error_message(&error
, r
));
1913 static int unlock_home(int argc
, char *argv
[], void *userdata
) {
1914 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
1917 r
= acquire_bus(&bus
);
1921 STRV_FOREACH(i
, strv_skip(argv
, 1)) {
1922 _cleanup_(user_record_unrefp
) UserRecord
*secret
= NULL
;
1924 r
= acquire_passed_secrets(*i
, &secret
);
1929 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1930 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
1932 r
= bus_message_new_method_call(bus
, &m
, bus_mgr
, "UnlockHome");
1934 return bus_log_create_error(r
);
1936 r
= sd_bus_message_append(m
, "s", *i
);
1938 return bus_log_create_error(r
);
1940 r
= bus_message_append_secret(m
, secret
);
1942 return bus_log_create_error(r
);
1944 r
= sd_bus_call(bus
, m
, HOME_SLOW_BUS_CALL_TIMEOUT_USEC
, &error
, NULL
);
1946 r
= handle_generic_user_record_error(argv
[1], secret
, &error
, r
, false);
1961 static int with_home(int argc
, char *argv
[], void *userdata
) {
1962 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1963 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
, *reply
= NULL
;
1964 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
1965 _cleanup_(user_record_unrefp
) UserRecord
*secret
= NULL
;
1966 _cleanup_close_
int acquired_fd
= -1;
1967 _cleanup_strv_free_
char **cmdline
= NULL
;
1972 r
= acquire_bus(&bus
);
1977 _cleanup_free_
char *shell
= NULL
;
1979 /* If no command is specified, spawn a shell */
1980 r
= get_shell(&shell
);
1982 return log_error_errno(r
, "Failed to acquire shell: %m");
1984 cmdline
= strv_new(shell
);
1986 cmdline
= strv_copy(argv
+ 2);
1990 r
= acquire_passed_secrets(argv
[1], &secret
);
1995 r
= bus_message_new_method_call(bus
, &m
, bus_mgr
, "AcquireHome");
1997 return bus_log_create_error(r
);
1999 r
= sd_bus_message_append(m
, "s", argv
[1]);
2001 return bus_log_create_error(r
);
2003 r
= bus_message_append_secret(m
, secret
);
2005 return bus_log_create_error(r
);
2007 r
= sd_bus_message_append(m
, "b", /* please_suspend = */ getenv_bool("SYSTEMD_PLEASE_SUSPEND_HOME") > 0);
2009 return bus_log_create_error(r
);
2011 r
= sd_bus_call(bus
, m
, HOME_SLOW_BUS_CALL_TIMEOUT_USEC
, &error
, &reply
);
2012 m
= sd_bus_message_unref(m
);
2014 r
= handle_generic_user_record_error(argv
[1], secret
, &error
, r
, false);
2018 sd_bus_error_free(&error
);
2022 r
= sd_bus_message_read(reply
, "h", &fd
);
2024 return bus_log_parse_error(r
);
2026 acquired_fd
= fcntl(fd
, F_DUPFD_CLOEXEC
, 3);
2027 if (acquired_fd
< 0)
2028 return log_error_errno(errno
, "Failed to duplicate acquired fd: %m");
2030 reply
= sd_bus_message_unref(reply
);
2035 r
= bus_call_method(bus
, bus_mgr
, "GetHomeByName", &error
, &reply
, "s", argv
[1]);
2037 return log_error_errno(r
, "Failed to inspect home: %s", bus_error_message(&error
, r
));
2039 r
= sd_bus_message_read(reply
, "usussso", NULL
, NULL
, NULL
, NULL
, &home
, NULL
, NULL
);
2041 return bus_log_parse_error(r
);
2043 r
= safe_fork("(with)", FORK_RESET_SIGNALS
|FORK_CLOSE_ALL_FDS
|FORK_DEATHSIG
|FORK_LOG
|FORK_RLIMIT_NOFILE_SAFE
|FORK_REOPEN_LOG
, &pid
);
2047 if (chdir(home
) < 0) {
2048 log_error_errno(errno
, "Failed to change to directory %s: %m", home
);
2052 execvp(cmdline
[0], cmdline
);
2053 log_error_errno(errno
, "Failed to execute %s: %m", cmdline
[0]);
2057 ret
= wait_for_terminate_and_check(cmdline
[0], pid
, WAIT_LOG_ABNORMAL
);
2059 /* Close the fd that pings the home now. */
2060 acquired_fd
= safe_close(acquired_fd
);
2062 r
= bus_message_new_method_call(bus
, &m
, bus_mgr
, "ReleaseHome");
2064 return bus_log_create_error(r
);
2066 r
= sd_bus_message_append(m
, "s", argv
[1]);
2068 return bus_log_create_error(r
);
2070 r
= sd_bus_call(bus
, m
, HOME_SLOW_BUS_CALL_TIMEOUT_USEC
, &error
, NULL
);
2072 if (sd_bus_error_has_name(&error
, BUS_ERROR_HOME_BUSY
))
2073 log_notice("Not deactivating home directory of %s, as it is still used.", argv
[1]);
2075 return log_error_errno(r
, "Failed to release user home: %s", bus_error_message(&error
, r
));
2081 static int lock_all_homes(int argc
, char *argv
[], void *userdata
) {
2082 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
2083 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
2084 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
2087 r
= acquire_bus(&bus
);
2091 r
= bus_message_new_method_call(bus
, &m
, bus_mgr
, "LockAllHomes");
2093 return bus_log_create_error(r
);
2095 r
= sd_bus_call(bus
, m
, HOME_SLOW_BUS_CALL_TIMEOUT_USEC
, &error
, NULL
);
2097 return log_error_errno(r
, "Failed to lock all homes: %s", bus_error_message(&error
, r
));
2102 static int deactivate_all_homes(int argc
, char *argv
[], void *userdata
) {
2103 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
2104 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
2105 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
2108 r
= acquire_bus(&bus
);
2112 r
= bus_message_new_method_call(bus
, &m
, bus_mgr
, "DeactivateAllHomes");
2114 return bus_log_create_error(r
);
2116 r
= sd_bus_call(bus
, m
, HOME_SLOW_BUS_CALL_TIMEOUT_USEC
, &error
, NULL
);
2118 return log_error_errno(r
, "Failed to deactivate all homes: %s", bus_error_message(&error
, r
));
2123 static int rebalance(int argc
, char *argv
[], void *userdata
) {
2124 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
2125 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
2126 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
2129 r
= acquire_bus(&bus
);
2133 r
= bus_message_new_method_call(bus
, &m
, bus_mgr
, "Rebalance");
2135 return bus_log_create_error(r
);
2137 r
= sd_bus_call(bus
, m
, HOME_SLOW_BUS_CALL_TIMEOUT_USEC
, &error
, NULL
);
2139 if (sd_bus_error_has_name(&error
, BUS_ERROR_REBALANCE_NOT_NEEDED
))
2140 log_info("No homes needed rebalancing.");
2142 return log_error_errno(r
, "Failed to rebalance: %s", bus_error_message(&error
, r
));
2144 log_info("Completed rebalancing.");
2149 static int drop_from_identity(const char *field
) {
2154 /* If we are called to update an identity record and drop some field, let's keep track of what to
2155 * remove from the old record */
2156 r
= strv_extend(&arg_identity_filter
, field
);
2160 /* Let's also drop the field if it was previously set to a new value on the same command line */
2161 r
= json_variant_filter(&arg_identity_extra
, STRV_MAKE(field
));
2163 return log_error_errno(r
, "Failed to filter JSON identity data: %m");
2165 r
= json_variant_filter(&arg_identity_extra_this_machine
, STRV_MAKE(field
));
2167 return log_error_errno(r
, "Failed to filter JSON identity data: %m");
2169 r
= json_variant_filter(&arg_identity_extra_privileged
, STRV_MAKE(field
));
2171 return log_error_errno(r
, "Failed to filter JSON identity data: %m");
2176 static int help(int argc
, char *argv
[], void *userdata
) {
2177 _cleanup_free_
char *link
= NULL
;
2180 pager_open(arg_pager_flags
);
2182 r
= terminal_urlify_man("homectl", "1", &link
);
2186 printf("%1$s [OPTIONS...] COMMAND ...\n\n"
2187 "%2$sCreate, manipulate or inspect home directories.%3$s\n"
2188 "\n%4$sCommands:%5$s\n"
2189 " list List home areas\n"
2190 " activate USER… Activate a home area\n"
2191 " deactivate USER… Deactivate a home area\n"
2192 " inspect USER… Inspect a home area\n"
2193 " authenticate USER… Authenticate a home area\n"
2194 " create USER Create a home area\n"
2195 " remove USER… Remove a home area\n"
2196 " update USER Update a home area\n"
2197 " passwd USER Change password of a home area\n"
2198 " resize USER SIZE Resize a home area\n"
2199 " lock USER… Temporarily lock an active home area\n"
2200 " unlock USER… Unlock a temporarily locked home area\n"
2201 " lock-all Lock all suitable home areas\n"
2202 " deactivate-all Deactivate all active home areas\n"
2203 " rebalance Rebalance free space between home areas\n"
2204 " with USER [COMMAND…] Run shell or command with access to a home area\n"
2205 "\n%4$sOptions:%5$s\n"
2206 " -h --help Show this help\n"
2207 " --version Show package version\n"
2208 " --no-pager Do not pipe output into a pager\n"
2209 " --no-legend Do not show the headers and footers\n"
2210 " --no-ask-password Do not ask for system passwords\n"
2211 " -H --host=[USER@]HOST Operate on remote host\n"
2212 " -M --machine=CONTAINER Operate on local container\n"
2213 " --identity=PATH Read JSON identity from file\n"
2214 " --json=FORMAT Output inspection data in JSON (takes one of\n"
2215 " pretty, short, off)\n"
2216 " -j Equivalent to --json=pretty (on TTY) or\n"
2217 " --json=short (otherwise)\n"
2218 " --export-format= Strip JSON inspection data (full, stripped,\n"
2220 " -E When specified once equals -j --export-format=\n"
2221 " stripped, when specified twice equals\n"
2222 " -j --export-format=minimal\n"
2223 "\n%4$sGeneral User Record Properties:%5$s\n"
2224 " -c --real-name=REALNAME Real name for user\n"
2225 " --realm=REALM Realm to create user in\n"
2226 " --email-address=EMAIL Email address for user\n"
2227 " --location=LOCATION Set location of user on earth\n"
2228 " --icon-name=NAME Icon name for user\n"
2229 " -d --home-dir=PATH Home directory\n"
2230 " -u --uid=UID Numeric UID for user\n"
2231 " -G --member-of=GROUP Add user to group\n"
2232 " --skel=PATH Skeleton directory to use\n"
2233 " --shell=PATH Shell for account\n"
2234 " --setenv=VARIABLE[=VALUE] Set an environment variable at log-in\n"
2235 " --timezone=TIMEZONE Set a time-zone\n"
2236 " --language=LOCALE Set preferred language\n"
2237 " --ssh-authorized-keys=KEYS\n"
2238 " Specify SSH public keys\n"
2239 " --pkcs11-token-uri=URI URI to PKCS#11 security token containing\n"
2240 " private key and matching X.509 certificate\n"
2241 " --fido2-device=PATH Path to FIDO2 hidraw device with hmac-secret\n"
2243 " --fido2-with-client-pin=BOOL\n"
2244 " Whether to require entering a PIN to unlock the\n"
2246 " --fido2-with-user-presence=BOOL\n"
2247 " Whether to require user presence to unlock the\n"
2249 " --fido2-with-user-verification=BOOL\n"
2250 " Whether to require user verification to unlock\n"
2252 " --recovery-key=BOOL Add a recovery key\n"
2253 "\n%4$sAccount Management User Record Properties:%5$s\n"
2254 " --locked=BOOL Set locked account state\n"
2255 " --not-before=TIMESTAMP Do not allow logins before\n"
2256 " --not-after=TIMESTAMP Do not allow logins after\n"
2257 " --rate-limit-interval=SECS\n"
2258 " Login rate-limit interval in seconds\n"
2259 " --rate-limit-burst=NUMBER\n"
2260 " Login rate-limit attempts per interval\n"
2261 "\n%4$sPassword Policy User Record Properties:%5$s\n"
2262 " --password-hint=HINT Set Password hint\n"
2263 " --enforce-password-policy=BOOL\n"
2264 " Control whether to enforce system's password\n"
2265 " policy for this user\n"
2266 " -P Same as --enforce-password-password=no\n"
2267 " --password-change-now=BOOL\n"
2268 " Require the password to be changed on next login\n"
2269 " --password-change-min=TIME\n"
2270 " Require minimum time between password changes\n"
2271 " --password-change-max=TIME\n"
2272 " Require maximum time between password changes\n"
2273 " --password-change-warn=TIME\n"
2274 " How much time to warn before password expiry\n"
2275 " --password-change-inactive=TIME\n"
2276 " How much time to block password after expiry\n"
2277 "\n%4$sResource Management User Record Properties:%5$s\n"
2278 " --disk-size=BYTES Size to assign the user on disk\n"
2279 " --access-mode=MODE User home directory access mode\n"
2280 " --umask=MODE Umask for user when logging in\n"
2281 " --nice=NICE Nice level for user\n"
2282 " --rlimit=LIMIT=VALUE[:VALUE]\n"
2283 " Set resource limits\n"
2284 " --tasks-max=MAX Set maximum number of per-user tasks\n"
2285 " --memory-high=BYTES Set high memory threshold in bytes\n"
2286 " --memory-max=BYTES Set maximum memory limit\n"
2287 " --cpu-weight=WEIGHT Set CPU weight\n"
2288 " --io-weight=WEIGHT Set IO weight\n"
2289 "\n%4$sStorage User Record Properties:%5$s\n"
2290 " --storage=STORAGE Storage type to use (luks, fscrypt, directory,\n"
2291 " subvolume, cifs)\n"
2292 " --image-path=PATH Path to image file/directory\n"
2293 " --drop-caches=BOOL Whether to automatically drop caches on logout\n"
2294 "\n%4$sLUKS Storage User Record Properties:%5$s\n"
2295 " --fs-type=TYPE File system type to use in case of luks\n"
2296 " storage (btrfs, ext4, xfs)\n"
2297 " --luks-discard=BOOL Whether to use 'discard' feature of file system\n"
2298 " when activated (mounted)\n"
2299 " --luks-offline-discard=BOOL\n"
2300 " Whether to trim file on logout\n"
2301 " --luks-cipher=CIPHER Cipher to use for LUKS encryption\n"
2302 " --luks-cipher-mode=MODE Cipher mode to use for LUKS encryption\n"
2303 " --luks-volume-key-size=BITS\n"
2304 " Volume key size to use for LUKS encryption\n"
2305 " --luks-pbkdf-type=TYPE Password-based Key Derivation Function to use\n"
2306 " --luks-pbkdf-hash-algorithm=ALGORITHM\n"
2307 " PBKDF hash algorithm to use\n"
2308 " --luks-pbkdf-time-cost=SECS\n"
2309 " Time cost for PBKDF in seconds\n"
2310 " --luks-pbkdf-memory-cost=BYTES\n"
2311 " Memory cost for PBKDF in bytes\n"
2312 " --luks-pbkdf-parallel-threads=NUMBER\n"
2313 " Number of parallel threads for PKBDF\n"
2314 " --luks-sector-size=BYTES\n"
2315 " Sector size for LUKS encryption in bytes\n"
2316 " --luks-extra-mount-options=OPTIONS\n"
2317 " LUKS extra mount options\n"
2318 " --auto-resize-mode=MODE Automatically grow/shrink home on login/logout\n"
2319 " --rebalance-weight=WEIGHT Weight while rebalancing\n"
2320 "\n%4$sMounting User Record Properties:%5$s\n"
2321 " --nosuid=BOOL Control the 'nosuid' flag of the home mount\n"
2322 " --nodev=BOOL Control the 'nodev' flag of the home mount\n"
2323 " --noexec=BOOL Control the 'noexec' flag of the home mount\n"
2324 "\n%4$sCIFS User Record Properties:%5$s\n"
2325 " --cifs-domain=DOMAIN CIFS (Windows) domain\n"
2326 " --cifs-user-name=USER CIFS (Windows) user name\n"
2327 " --cifs-service=SERVICE CIFS (Windows) service to mount as home area\n"
2328 " --cifs-extra-mount-options=OPTIONS\n"
2329 " CIFS (Windows) extra mount options\n"
2330 "\n%4$sLogin Behaviour User Record Properties:%5$s\n"
2331 " --stop-delay=SECS How long to leave user services running after\n"
2333 " --kill-processes=BOOL Whether to kill user processes when sessions\n"
2335 " --auto-login=BOOL Try to log this user in automatically\n"
2336 "\nSee the %6$s for details.\n",
2337 program_invocation_short_name
,
2347 static int parse_argv(int argc
, char *argv
[]) {
2350 ARG_VERSION
= 0x100,
2353 ARG_NO_ASK_PASSWORD
,
2363 ARG_LUKS_OFFLINE_DISCARD
,
2369 ARG_SSH_AUTHORIZED_KEYS
,
2378 ARG_LUKS_CIPHER_MODE
,
2379 ARG_LUKS_VOLUME_KEY_SIZE
,
2386 ARG_CIFS_EXTRA_MOUNT_OPTIONS
,
2392 ARG_LUKS_PBKDF_TYPE
,
2393 ARG_LUKS_PBKDF_HASH_ALGORITHM
,
2394 ARG_LUKS_PBKDF_TIME_COST
,
2395 ARG_LUKS_PBKDF_MEMORY_COST
,
2396 ARG_LUKS_PBKDF_PARALLEL_THREADS
,
2397 ARG_LUKS_SECTOR_SIZE
,
2398 ARG_RATE_LIMIT_INTERVAL
,
2399 ARG_RATE_LIMIT_BURST
,
2402 ARG_ENFORCE_PASSWORD_POLICY
,
2403 ARG_PASSWORD_CHANGE_NOW
,
2404 ARG_PASSWORD_CHANGE_MIN
,
2405 ARG_PASSWORD_CHANGE_MAX
,
2406 ARG_PASSWORD_CHANGE_WARN
,
2407 ARG_PASSWORD_CHANGE_INACTIVE
,
2410 ARG_PKCS11_TOKEN_URI
,
2417 ARG_AND_CHANGE_PASSWORD
,
2419 ARG_LUKS_EXTRA_MOUNT_OPTIONS
,
2420 ARG_AUTO_RESIZE_MODE
,
2421 ARG_REBALANCE_WEIGHT
,
2425 static const struct option options
[] = {
2426 { "help", no_argument
, NULL
, 'h' },
2427 { "version", no_argument
, NULL
, ARG_VERSION
},
2428 { "no-pager", no_argument
, NULL
, ARG_NO_PAGER
},
2429 { "no-legend", no_argument
, NULL
, ARG_NO_LEGEND
},
2430 { "no-ask-password", no_argument
, NULL
, ARG_NO_ASK_PASSWORD
},
2431 { "host", required_argument
, NULL
, 'H' },
2432 { "machine", required_argument
, NULL
, 'M' },
2433 { "identity", required_argument
, NULL
, 'I' },
2434 { "real-name", required_argument
, NULL
, 'c' },
2435 { "comment", required_argument
, NULL
, 'c' }, /* Compat alias to keep thing in sync with useradd(8) */
2436 { "realm", required_argument
, NULL
, ARG_REALM
},
2437 { "email-address", required_argument
, NULL
, ARG_EMAIL_ADDRESS
},
2438 { "location", required_argument
, NULL
, ARG_LOCATION
},
2439 { "password-hint", required_argument
, NULL
, ARG_PASSWORD_HINT
},
2440 { "icon-name", required_argument
, NULL
, ARG_ICON_NAME
},
2441 { "home-dir", required_argument
, NULL
, 'd' }, /* Compatible with useradd(8) */
2442 { "uid", required_argument
, NULL
, 'u' }, /* Compatible with useradd(8) */
2443 { "member-of", required_argument
, NULL
, 'G' },
2444 { "groups", required_argument
, NULL
, 'G' }, /* Compat alias to keep thing in sync with useradd(8) */
2445 { "skel", required_argument
, NULL
, 'k' }, /* Compatible with useradd(8) */
2446 { "shell", required_argument
, NULL
, 's' }, /* Compatible with useradd(8) */
2447 { "setenv", required_argument
, NULL
, ARG_SETENV
},
2448 { "timezone", required_argument
, NULL
, ARG_TIMEZONE
},
2449 { "language", required_argument
, NULL
, ARG_LANGUAGE
},
2450 { "locked", required_argument
, NULL
, ARG_LOCKED
},
2451 { "not-before", required_argument
, NULL
, ARG_NOT_BEFORE
},
2452 { "not-after", required_argument
, NULL
, ARG_NOT_AFTER
},
2453 { "expiredate", required_argument
, NULL
, 'e' }, /* Compat alias to keep thing in sync with useradd(8) */
2454 { "ssh-authorized-keys", required_argument
, NULL
, ARG_SSH_AUTHORIZED_KEYS
},
2455 { "disk-size", required_argument
, NULL
, ARG_DISK_SIZE
},
2456 { "access-mode", required_argument
, NULL
, ARG_ACCESS_MODE
},
2457 { "umask", required_argument
, NULL
, ARG_UMASK
},
2458 { "nice", required_argument
, NULL
, ARG_NICE
},
2459 { "rlimit", required_argument
, NULL
, ARG_RLIMIT
},
2460 { "tasks-max", required_argument
, NULL
, ARG_TASKS_MAX
},
2461 { "memory-high", required_argument
, NULL
, ARG_MEMORY_HIGH
},
2462 { "memory-max", required_argument
, NULL
, ARG_MEMORY_MAX
},
2463 { "cpu-weight", required_argument
, NULL
, ARG_CPU_WEIGHT
},
2464 { "io-weight", required_argument
, NULL
, ARG_IO_WEIGHT
},
2465 { "storage", required_argument
, NULL
, ARG_STORAGE
},
2466 { "image-path", required_argument
, NULL
, ARG_IMAGE_PATH
},
2467 { "fs-type", required_argument
, NULL
, ARG_FS_TYPE
},
2468 { "luks-discard", required_argument
, NULL
, ARG_LUKS_DISCARD
},
2469 { "luks-offline-discard", required_argument
, NULL
, ARG_LUKS_OFFLINE_DISCARD
},
2470 { "luks-cipher", required_argument
, NULL
, ARG_LUKS_CIPHER
},
2471 { "luks-cipher-mode", required_argument
, NULL
, ARG_LUKS_CIPHER_MODE
},
2472 { "luks-volume-key-size", required_argument
, NULL
, ARG_LUKS_VOLUME_KEY_SIZE
},
2473 { "luks-pbkdf-type", required_argument
, NULL
, ARG_LUKS_PBKDF_TYPE
},
2474 { "luks-pbkdf-hash-algorithm", required_argument
, NULL
, ARG_LUKS_PBKDF_HASH_ALGORITHM
},
2475 { "luks-pbkdf-time-cost", required_argument
, NULL
, ARG_LUKS_PBKDF_TIME_COST
},
2476 { "luks-pbkdf-memory-cost", required_argument
, NULL
, ARG_LUKS_PBKDF_MEMORY_COST
},
2477 { "luks-pbkdf-parallel-threads", required_argument
, NULL
, ARG_LUKS_PBKDF_PARALLEL_THREADS
},
2478 { "luks-sector-size", required_argument
, NULL
, ARG_LUKS_SECTOR_SIZE
},
2479 { "nosuid", required_argument
, NULL
, ARG_NOSUID
},
2480 { "nodev", required_argument
, NULL
, ARG_NODEV
},
2481 { "noexec", required_argument
, NULL
, ARG_NOEXEC
},
2482 { "cifs-user-name", required_argument
, NULL
, ARG_CIFS_USER_NAME
},
2483 { "cifs-domain", required_argument
, NULL
, ARG_CIFS_DOMAIN
},
2484 { "cifs-service", required_argument
, NULL
, ARG_CIFS_SERVICE
},
2485 { "cifs-extra-mount-options", required_argument
, NULL
, ARG_CIFS_EXTRA_MOUNT_OPTIONS
},
2486 { "rate-limit-interval", required_argument
, NULL
, ARG_RATE_LIMIT_INTERVAL
},
2487 { "rate-limit-burst", required_argument
, NULL
, ARG_RATE_LIMIT_BURST
},
2488 { "stop-delay", required_argument
, NULL
, ARG_STOP_DELAY
},
2489 { "kill-processes", required_argument
, NULL
, ARG_KILL_PROCESSES
},
2490 { "enforce-password-policy", required_argument
, NULL
, ARG_ENFORCE_PASSWORD_POLICY
},
2491 { "password-change-now", required_argument
, NULL
, ARG_PASSWORD_CHANGE_NOW
},
2492 { "password-change-min", required_argument
, NULL
, ARG_PASSWORD_CHANGE_MIN
},
2493 { "password-change-max", required_argument
, NULL
, ARG_PASSWORD_CHANGE_MAX
},
2494 { "password-change-warn", required_argument
, NULL
, ARG_PASSWORD_CHANGE_WARN
},
2495 { "password-change-inactive", required_argument
, NULL
, ARG_PASSWORD_CHANGE_INACTIVE
},
2496 { "auto-login", required_argument
, NULL
, ARG_AUTO_LOGIN
},
2497 { "json", required_argument
, NULL
, ARG_JSON
},
2498 { "export-format", required_argument
, NULL
, ARG_EXPORT_FORMAT
},
2499 { "pkcs11-token-uri", required_argument
, NULL
, ARG_PKCS11_TOKEN_URI
},
2500 { "fido2-credential-algorithm", required_argument
, NULL
, ARG_FIDO2_CRED_ALG
},
2501 { "fido2-device", required_argument
, NULL
, ARG_FIDO2_DEVICE
},
2502 { "fido2-with-client-pin", required_argument
, NULL
, ARG_FIDO2_WITH_PIN
},
2503 { "fido2-with-user-presence", required_argument
, NULL
, ARG_FIDO2_WITH_UP
},
2504 { "fido2-with-user-verification",required_argument
, NULL
, ARG_FIDO2_WITH_UV
},
2505 { "recovery-key", required_argument
, NULL
, ARG_RECOVERY_KEY
},
2506 { "and-resize", required_argument
, NULL
, ARG_AND_RESIZE
},
2507 { "and-change-password", required_argument
, NULL
, ARG_AND_CHANGE_PASSWORD
},
2508 { "drop-caches", required_argument
, NULL
, ARG_DROP_CACHES
},
2509 { "luks-extra-mount-options", required_argument
, NULL
, ARG_LUKS_EXTRA_MOUNT_OPTIONS
},
2510 { "auto-resize-mode", required_argument
, NULL
, ARG_AUTO_RESIZE_MODE
},
2511 { "rebalance-weight", required_argument
, NULL
, ARG_REBALANCE_WEIGHT
},
2523 c
= getopt_long(argc
, argv
, "hH:M:I:c:d:u:k:s:e:G:jPE", options
, NULL
);
2530 return help(0, NULL
, NULL
);
2536 arg_pager_flags
|= PAGER_DISABLE
;
2543 case ARG_NO_ASK_PASSWORD
:
2544 arg_ask_password
= false;
2548 arg_transport
= BUS_TRANSPORT_REMOTE
;
2553 arg_transport
= BUS_TRANSPORT_MACHINE
;
2558 arg_identity
= optarg
;
2562 if (isempty(optarg
)) {
2563 r
= drop_from_identity("realName");
2570 if (!valid_gecos(optarg
))
2571 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Real name '%s' not a valid GECOS field.", optarg
);
2573 r
= json_variant_set_field_string(&arg_identity_extra
, "realName", optarg
);
2575 return log_error_errno(r
, "Failed to set realName field: %m");
2580 _cleanup_free_
char *hd
= NULL
;
2582 if (isempty(optarg
)) {
2583 r
= drop_from_identity("homeDirectory");
2590 r
= parse_path_argument(optarg
, false, &hd
);
2594 if (!valid_home(hd
))
2595 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Home directory '%s' not valid.", hd
);
2597 r
= json_variant_set_field_string(&arg_identity_extra
, "homeDirectory", hd
);
2599 return log_error_errno(r
, "Failed to set homeDirectory field: %m");
2605 if (isempty(optarg
)) {
2606 r
= drop_from_identity("realm");
2613 r
= dns_name_is_valid(optarg
);
2615 return log_error_errno(r
, "Failed to determine whether realm '%s' is a valid DNS domain: %m", optarg
);
2617 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Realm '%s' is not a valid DNS domain: %m", optarg
);
2619 r
= json_variant_set_field_string(&arg_identity_extra
, "realm", optarg
);
2621 return log_error_errno(r
, "Failed to set realm field: %m");
2624 case ARG_EMAIL_ADDRESS
:
2627 case ARG_CIFS_USER_NAME
:
2628 case ARG_CIFS_DOMAIN
:
2629 case ARG_CIFS_EXTRA_MOUNT_OPTIONS
:
2630 case ARG_LUKS_EXTRA_MOUNT_OPTIONS
: {
2633 c
== ARG_EMAIL_ADDRESS
? "emailAddress" :
2634 c
== ARG_LOCATION
? "location" :
2635 c
== ARG_ICON_NAME
? "iconName" :
2636 c
== ARG_CIFS_USER_NAME
? "cifsUserName" :
2637 c
== ARG_CIFS_DOMAIN
? "cifsDomain" :
2638 c
== ARG_CIFS_EXTRA_MOUNT_OPTIONS
? "cifsExtraMountOptions" :
2639 c
== ARG_LUKS_EXTRA_MOUNT_OPTIONS
? "luksExtraMountOptions" :
2644 if (isempty(optarg
)) {
2645 r
= drop_from_identity(field
);
2652 r
= json_variant_set_field_string(&arg_identity_extra
, field
, optarg
);
2654 return log_error_errno(r
, "Failed to set %s field: %m", field
);
2659 case ARG_CIFS_SERVICE
:
2660 if (isempty(optarg
)) {
2661 r
= drop_from_identity("cifsService");
2668 r
= parse_cifs_service(optarg
, NULL
, NULL
, NULL
);
2670 return log_error_errno(r
, "Failed to validate CIFS service name: %s", optarg
);
2672 r
= json_variant_set_field_string(&arg_identity_extra
, "cifsService", optarg
);
2674 return log_error_errno(r
, "Failed to set cifsService field: %m");
2678 case ARG_PASSWORD_HINT
:
2679 if (isempty(optarg
)) {
2680 r
= drop_from_identity("passwordHint");
2687 r
= json_variant_set_field_string(&arg_identity_extra_privileged
, "passwordHint", optarg
);
2689 return log_error_errno(r
, "Failed to set passwordHint field: %m");
2691 string_erase(optarg
);
2697 if (isempty(optarg
)) {
2698 r
= drop_from_identity("niceLevel");
2704 r
= parse_nice(optarg
, &nc
);
2706 return log_error_errno(r
, "Failed to parse nice level: %s", optarg
);
2708 r
= json_variant_set_field_integer(&arg_identity_extra
, "niceLevel", nc
);
2710 return log_error_errno(r
, "Failed to set niceLevel field: %m");
2716 _cleanup_(json_variant_unrefp
) JsonVariant
*v
= NULL
, *jcur
= NULL
, *jmax
= NULL
;
2717 _cleanup_free_
char *field
= NULL
, *t
= NULL
;
2722 if (isempty(optarg
)) {
2723 /* Remove all resource limits */
2725 r
= drop_from_identity("resourceLimits");
2729 arg_identity_filter_rlimits
= strv_free(arg_identity_filter_rlimits
);
2730 arg_identity_extra_rlimits
= json_variant_unref(arg_identity_extra_rlimits
);
2734 eq
= strchr(optarg
, '=');
2736 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Can't parse resource limit assignment: %s", optarg
);
2738 field
= strndup(optarg
, eq
- optarg
);
2742 l
= rlimit_from_string_harder(field
);
2744 return log_error_errno(l
, "Unknown resource limit type: %s", field
);
2746 if (isempty(eq
+ 1)) {
2747 /* Remove only the specific rlimit */
2749 r
= strv_extend(&arg_identity_filter_rlimits
, rlimit_to_string(l
));
2753 r
= json_variant_filter(&arg_identity_extra_rlimits
, STRV_MAKE(field
));
2755 return log_error_errno(r
, "Failed to filter JSON identity data: %m");
2760 r
= rlimit_parse(l
, eq
+ 1, &rl
);
2762 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Failed to parse resource limit value: %s", eq
+ 1);
2764 r
= rl
.rlim_cur
== RLIM_INFINITY
? json_variant_new_null(&jcur
) : json_variant_new_unsigned(&jcur
, rl
.rlim_cur
);
2766 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Failed to allocate current integer: %m");
2768 r
= rl
.rlim_max
== RLIM_INFINITY
? json_variant_new_null(&jmax
) : json_variant_new_unsigned(&jmax
, rl
.rlim_max
);
2770 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Failed to allocate maximum integer: %m");
2774 JSON_BUILD_PAIR("cur", JSON_BUILD_VARIANT(jcur
)),
2775 JSON_BUILD_PAIR("max", JSON_BUILD_VARIANT(jmax
))));
2777 return log_error_errno(r
, "Failed to build resource limit: %m");
2779 t
= strjoin("RLIMIT_", rlimit_to_string(l
));
2783 r
= json_variant_set_field(&arg_identity_extra_rlimits
, t
, v
);
2785 return log_error_errno(r
, "Failed to set %s field: %m", rlimit_to_string(l
));
2793 if (isempty(optarg
)) {
2794 r
= drop_from_identity("uid");
2801 r
= parse_uid(optarg
, &uid
);
2803 return log_error_errno(r
, "Failed to parse UID '%s'.", optarg
);
2805 if (uid_is_system(uid
))
2806 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "UID " UID_FMT
" is in system range, refusing.", uid
);
2807 if (uid_is_dynamic(uid
))
2808 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "UID " UID_FMT
" is in dynamic range, refusing.", uid
);
2809 if (uid
== UID_NOBODY
)
2810 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "UID " UID_FMT
" is nobody UID, refusing.", uid
);
2812 r
= json_variant_set_field_unsigned(&arg_identity_extra
, "uid", uid
);
2814 return log_error_errno(r
, "Failed to set realm field: %m");
2820 case ARG_IMAGE_PATH
: {
2821 const char *field
= c
== 'k' ? "skeletonDirectory" : "imagePath";
2822 _cleanup_free_
char *v
= NULL
;
2824 if (isempty(optarg
)) {
2825 r
= drop_from_identity(field
);
2832 r
= parse_path_argument(optarg
, false, &v
);
2836 r
= json_variant_set_field_string(&arg_identity_extra_this_machine
, field
, v
);
2838 return log_error_errno(r
, "Failed to set %s field: %m", v
);
2844 if (isempty(optarg
)) {
2845 r
= drop_from_identity("shell");
2852 if (!valid_shell(optarg
))
2853 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Shell '%s' not valid.", optarg
);
2855 r
= json_variant_set_field_string(&arg_identity_extra
, "shell", optarg
);
2857 return log_error_errno(r
, "Failed to set shell field: %m");
2862 _cleanup_free_
char **l
= NULL
;
2863 _cleanup_(json_variant_unrefp
) JsonVariant
*ne
= NULL
;
2866 if (isempty(optarg
)) {
2867 r
= drop_from_identity("environment");
2874 e
= json_variant_by_key(arg_identity_extra
, "environment");
2876 r
= json_variant_strv(e
, &l
);
2878 return log_error_errno(r
, "Failed to parse JSON environment field: %m");
2881 r
= strv_env_replace_strdup_passthrough(&l
, optarg
);
2883 return log_error_errno(r
, "Cannot assign environment variable %s: %m", optarg
);
2887 r
= json_variant_new_array_strv(&ne
, l
);
2889 return log_error_errno(r
, "Failed to allocate environment list JSON: %m");
2891 r
= json_variant_set_field(&arg_identity_extra
, "environment", ne
);
2893 return log_error_errno(r
, "Failed to set environment list: %m");
2900 if (isempty(optarg
)) {
2901 r
= drop_from_identity("timeZone");
2908 if (!timezone_is_valid(optarg
, LOG_DEBUG
))
2909 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Timezone '%s' is not valid.", optarg
);
2911 r
= json_variant_set_field_string(&arg_identity_extra
, "timeZone", optarg
);
2913 return log_error_errno(r
, "Failed to set timezone field: %m");
2918 if (isempty(optarg
)) {
2919 r
= drop_from_identity("language");
2926 if (!locale_is_valid(optarg
))
2927 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Locale '%s' is not valid.", optarg
);
2929 if (locale_is_installed(optarg
) <= 0)
2930 log_warning("Locale '%s' is not installed, accepting anyway.", optarg
);
2932 r
= json_variant_set_field_string(&arg_identity_extra
, "preferredLanguage", optarg
);
2934 return log_error_errno(r
, "Failed to set preferredLanguage field: %m");
2942 case ARG_KILL_PROCESSES
:
2943 case ARG_ENFORCE_PASSWORD_POLICY
:
2944 case ARG_AUTO_LOGIN
:
2945 case ARG_PASSWORD_CHANGE_NOW
: {
2947 c
== ARG_LOCKED
? "locked" :
2948 c
== ARG_NOSUID
? "mountNoSuid" :
2949 c
== ARG_NODEV
? "mountNoDevices" :
2950 c
== ARG_NOEXEC
? "mountNoExecute" :
2951 c
== ARG_KILL_PROCESSES
? "killProcesses" :
2952 c
== ARG_ENFORCE_PASSWORD_POLICY
? "enforcePasswordPolicy" :
2953 c
== ARG_AUTO_LOGIN
? "autoLogin" :
2954 c
== ARG_PASSWORD_CHANGE_NOW
? "passwordChangeNow" :
2959 if (isempty(optarg
)) {
2960 r
= drop_from_identity(field
);
2967 r
= parse_boolean(optarg
);
2969 return log_error_errno(r
, "Failed to parse %s boolean: %m", field
);
2971 r
= json_variant_set_field_boolean(&arg_identity_extra
, field
, r
> 0);
2973 return log_error_errno(r
, "Failed to set %s field: %m", field
);
2979 r
= json_variant_set_field_boolean(&arg_identity_extra
, "enforcePasswordPolicy", false);
2981 return log_error_errno(r
, "Failed to set enforcePasswordPolicy field: %m");
2986 if (isempty(optarg
)) {
2987 FOREACH_STRING(prop
, "diskSize", "diskSizeRelative", "rebalanceWeight") {
2988 r
= drop_from_identity(prop
);
2993 arg_disk_size
= arg_disk_size_relative
= UINT64_MAX
;
2997 r
= parse_permyriad(optarg
);
2999 r
= parse_disk_size(optarg
, &arg_disk_size
);
3003 r
= drop_from_identity("diskSizeRelative");
3007 r
= json_variant_set_field_unsigned(&arg_identity_extra_this_machine
, "diskSize", arg_disk_size
);
3009 return log_error_errno(r
, "Failed to set diskSize field: %m");
3011 arg_disk_size_relative
= UINT64_MAX
;
3013 /* Normalize to UINT32_MAX == 100% */
3014 arg_disk_size_relative
= UINT32_SCALE_FROM_PERMYRIAD(r
);
3016 r
= drop_from_identity("diskSize");
3020 r
= json_variant_set_field_unsigned(&arg_identity_extra_this_machine
, "diskSizeRelative", arg_disk_size_relative
);
3022 return log_error_errno(r
, "Failed to set diskSizeRelative field: %m");
3024 arg_disk_size
= UINT64_MAX
;
3027 /* Automatically turn off the rebalance logic if user configured a size explicitly */
3028 r
= json_variant_set_field_unsigned(&arg_identity_extra_this_machine
, "rebalanceWeight", REBALANCE_WEIGHT_OFF
);
3030 return log_error_errno(r
, "Failed to set rebalanceWeight field: %m");
3034 case ARG_ACCESS_MODE
: {
3037 if (isempty(optarg
)) {
3038 r
= drop_from_identity("accessMode");
3045 r
= parse_mode(optarg
, &mode
);
3047 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Access mode '%s' not valid.", optarg
);
3049 r
= json_variant_set_field_unsigned(&arg_identity_extra
, "accessMode", mode
);
3051 return log_error_errno(r
, "Failed to set access mode field: %m");
3056 case ARG_LUKS_DISCARD
:
3057 if (isempty(optarg
)) {
3058 r
= drop_from_identity("luksDiscard");
3065 r
= parse_boolean(optarg
);
3067 return log_error_errno(r
, "Failed to parse --luks-discard= parameter: %s", optarg
);
3069 r
= json_variant_set_field_boolean(&arg_identity_extra
, "luksDiscard", r
);
3071 return log_error_errno(r
, "Failed to set discard field: %m");
3075 case ARG_LUKS_OFFLINE_DISCARD
:
3076 if (isempty(optarg
)) {
3077 r
= drop_from_identity("luksOfflineDiscard");
3084 r
= parse_boolean(optarg
);
3086 return log_error_errno(r
, "Failed to parse --luks-offline-discard= parameter: %s", optarg
);
3088 r
= json_variant_set_field_boolean(&arg_identity_extra
, "luksOfflineDiscard", r
);
3090 return log_error_errno(r
, "Failed to set offline discard field: %m");
3094 case ARG_LUKS_VOLUME_KEY_SIZE
:
3095 case ARG_LUKS_PBKDF_PARALLEL_THREADS
:
3096 case ARG_RATE_LIMIT_BURST
: {
3098 c
== ARG_LUKS_VOLUME_KEY_SIZE
? "luksVolumeKeySize" :
3099 c
== ARG_LUKS_PBKDF_PARALLEL_THREADS
? "luksPbkdfParallelThreads" :
3100 c
== ARG_RATE_LIMIT_BURST
? "rateLimitBurst" : NULL
;
3105 if (isempty(optarg
)) {
3106 r
= drop_from_identity(field
);
3111 r
= safe_atou(optarg
, &n
);
3113 return log_error_errno(r
, "Failed to parse %s parameter: %s", field
, optarg
);
3115 r
= json_variant_set_field_unsigned(&arg_identity_extra
, field
, n
);
3117 return log_error_errno(r
, "Failed to set %s field: %m", field
);
3122 case ARG_LUKS_SECTOR_SIZE
: {
3125 if (isempty(optarg
)) {
3126 r
= drop_from_identity("luksSectorSize");
3133 r
= parse_sector_size(optarg
, &ss
);
3137 r
= json_variant_set_field_unsigned(&arg_identity_extra
, "luksSectorSize", ss
);
3139 return log_error_errno(r
, "Failed to set sector size field: %m");
3147 if (isempty(optarg
)) {
3148 r
= drop_from_identity("umask");
3155 r
= parse_mode(optarg
, &m
);
3157 return log_error_errno(r
, "Failed to parse umask: %m");
3159 r
= json_variant_set_field_integer(&arg_identity_extra
, "umask", m
);
3161 return log_error_errno(r
, "Failed to set umask field: %m");
3166 case ARG_SSH_AUTHORIZED_KEYS
: {
3167 _cleanup_(json_variant_unrefp
) JsonVariant
*v
= NULL
;
3168 _cleanup_(strv_freep
) char **l
= NULL
, **add
= NULL
;
3170 if (isempty(optarg
)) {
3171 r
= drop_from_identity("sshAuthorizedKeys");
3178 if (optarg
[0] == '@') {
3179 _cleanup_fclose_
FILE *f
= NULL
;
3181 /* If prefixed with '@' read from a file */
3183 f
= fopen(optarg
+1, "re");
3185 return log_error_errno(errno
, "Failed to open '%s': %m", optarg
+1);
3188 _cleanup_free_
char *line
= NULL
;
3190 r
= read_line(f
, LONG_LINE_MAX
, &line
);
3192 return log_error_errno(r
, "Failed to read from '%s': %m", optarg
+1);
3202 r
= strv_consume(&add
, TAKE_PTR(line
));
3207 /* Otherwise, assume it's a literal key. Let's do some superficial checks
3208 * before accept it though. */
3210 if (string_has_cc(optarg
, NULL
))
3211 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Authorized key contains control characters, refusing.");
3212 if (optarg
[0] == '#')
3213 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Specified key is a comment?");
3215 add
= strv_new(optarg
);
3220 v
= json_variant_ref(json_variant_by_key(arg_identity_extra_privileged
, "sshAuthorizedKeys"));
3222 r
= json_variant_strv(v
, &l
);
3224 return log_error_errno(r
, "Failed to parse SSH authorized keys list: %m");
3227 r
= strv_extend_strv(&l
, add
, true);
3231 v
= json_variant_unref(v
);
3233 r
= json_variant_new_array_strv(&v
, l
);
3237 r
= json_variant_set_field(&arg_identity_extra_privileged
, "sshAuthorizedKeys", v
);
3239 return log_error_errno(r
, "Failed to set authorized keys: %m");
3244 case ARG_NOT_BEFORE
:
3250 field
= c
== ARG_NOT_BEFORE
? "notBeforeUSec" :
3251 IN_SET(c
, ARG_NOT_AFTER
, 'e') ? "notAfterUSec" : NULL
;
3255 if (isempty(optarg
)) {
3256 r
= drop_from_identity(field
);
3263 /* Note the minor discrepancy regarding -e parsing here: we support that for compat
3264 * reasons, and in the original useradd(8) implementation it accepts dates in the
3265 * format YYYY-MM-DD. Coincidentally, we accept dates formatted like that too, but
3266 * with greater precision. */
3267 r
= parse_timestamp(optarg
, &n
);
3269 return log_error_errno(r
, "Failed to parse %s parameter: %m", field
);
3271 r
= json_variant_set_field_unsigned(&arg_identity_extra
, field
, n
);
3273 return log_error_errno(r
, "Failed to set %s field: %m", field
);
3277 case ARG_PASSWORD_CHANGE_MIN
:
3278 case ARG_PASSWORD_CHANGE_MAX
:
3279 case ARG_PASSWORD_CHANGE_WARN
:
3280 case ARG_PASSWORD_CHANGE_INACTIVE
: {
3284 field
= c
== ARG_PASSWORD_CHANGE_MIN
? "passwordChangeMinUSec" :
3285 c
== ARG_PASSWORD_CHANGE_MAX
? "passwordChangeMaxUSec" :
3286 c
== ARG_PASSWORD_CHANGE_WARN
? "passwordChangeWarnUSec" :
3287 c
== ARG_PASSWORD_CHANGE_INACTIVE
? "passwordChangeInactiveUSec" :
3292 if (isempty(optarg
)) {
3293 r
= drop_from_identity(field
);
3300 r
= parse_sec(optarg
, &n
);
3302 return log_error_errno(r
, "Failed to parse %s parameter: %m", field
);
3304 r
= json_variant_set_field_unsigned(&arg_identity_extra
, field
, n
);
3306 return log_error_errno(r
, "Failed to set %s field: %m", field
);
3312 case ARG_LUKS_CIPHER
:
3313 case ARG_LUKS_CIPHER_MODE
:
3314 case ARG_LUKS_PBKDF_TYPE
:
3315 case ARG_LUKS_PBKDF_HASH_ALGORITHM
: {
3318 c
== ARG_STORAGE
? "storage" :
3319 c
== ARG_FS_TYPE
? "fileSystemType" :
3320 c
== ARG_LUKS_CIPHER
? "luksCipher" :
3321 c
== ARG_LUKS_CIPHER_MODE
? "luksCipherMode" :
3322 c
== ARG_LUKS_PBKDF_TYPE
? "luksPbkdfType" :
3323 c
== ARG_LUKS_PBKDF_HASH_ALGORITHM
? "luksPbkdfHashAlgorithm" : NULL
;
3327 if (isempty(optarg
)) {
3328 r
= drop_from_identity(field
);
3335 if (!string_is_safe(optarg
))
3336 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Parameter for %s field not valid: %s", field
, optarg
);
3338 r
= json_variant_set_field_string(
3339 IN_SET(c
, ARG_STORAGE
, ARG_FS_TYPE
) ?
3340 &arg_identity_extra_this_machine
:
3341 &arg_identity_extra
, field
, optarg
);
3343 return log_error_errno(r
, "Failed to set %s field: %m", field
);
3348 case ARG_LUKS_PBKDF_TIME_COST
:
3349 case ARG_RATE_LIMIT_INTERVAL
:
3350 case ARG_STOP_DELAY
: {
3352 c
== ARG_LUKS_PBKDF_TIME_COST
? "luksPbkdfTimeCostUSec" :
3353 c
== ARG_RATE_LIMIT_INTERVAL
? "rateLimitIntervalUSec" :
3354 c
== ARG_STOP_DELAY
? "stopDelayUSec" :
3360 if (isempty(optarg
)) {
3361 r
= drop_from_identity(field
);
3368 r
= parse_sec(optarg
, &t
);
3370 return log_error_errno(r
, "Failed to parse %s field: %s", field
, optarg
);
3372 r
= json_variant_set_field_unsigned(&arg_identity_extra
, field
, t
);
3374 return log_error_errno(r
, "Failed to set %s field: %m", field
);
3380 const char *p
= optarg
;
3383 r
= drop_from_identity("memberOf");
3391 _cleanup_(json_variant_unrefp
) JsonVariant
*mo
= NULL
;
3392 _cleanup_strv_free_
char **list
= NULL
;
3393 _cleanup_free_
char *word
= NULL
;
3395 r
= extract_first_word(&p
, &word
, ",", 0);
3397 return log_error_errno(r
, "Failed to parse group list: %m");
3401 if (!valid_user_group_name(word
, 0))
3402 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Invalid group name %s.", word
);
3404 mo
= json_variant_ref(json_variant_by_key(arg_identity_extra
, "memberOf"));
3406 r
= json_variant_strv(mo
, &list
);
3408 return log_error_errno(r
, "Failed to parse group list: %m");
3410 r
= strv_extend(&list
, word
);
3417 mo
= json_variant_unref(mo
);
3418 r
= json_variant_new_array_strv(&mo
, list
);
3420 return log_error_errno(r
, "Failed to create group list JSON: %m");
3422 r
= json_variant_set_field(&arg_identity_extra
, "memberOf", mo
);
3424 return log_error_errno(r
, "Failed to update group list: %m");
3430 case ARG_TASKS_MAX
: {
3433 if (isempty(optarg
)) {
3434 r
= drop_from_identity("tasksMax");
3440 r
= safe_atou64(optarg
, &u
);
3442 return log_error_errno(r
, "Failed to parse --tasks-max= parameter: %s", optarg
);
3444 r
= json_variant_set_field_unsigned(&arg_identity_extra
, "tasksMax", u
);
3446 return log_error_errno(r
, "Failed to set tasksMax field: %m");
3451 case ARG_MEMORY_MAX
:
3452 case ARG_MEMORY_HIGH
:
3453 case ARG_LUKS_PBKDF_MEMORY_COST
: {
3455 c
== ARG_MEMORY_MAX
? "memoryMax" :
3456 c
== ARG_MEMORY_HIGH
? "memoryHigh" :
3457 c
== ARG_LUKS_PBKDF_MEMORY_COST
? "luksPbkdfMemoryCost" : NULL
;
3463 if (isempty(optarg
)) {
3464 r
= drop_from_identity(field
);
3470 r
= parse_size(optarg
, 1024, &u
);
3472 return log_error_errno(r
, "Failed to parse %s parameter: %s", field
, optarg
);
3474 r
= json_variant_set_field_unsigned(&arg_identity_extra_this_machine
, field
, u
);
3476 return log_error_errno(r
, "Failed to set %s field: %m", field
);
3481 case ARG_CPU_WEIGHT
:
3482 case ARG_IO_WEIGHT
: {
3483 const char *field
= c
== ARG_CPU_WEIGHT
? "cpuWeight" :
3484 c
== ARG_IO_WEIGHT
? "ioWeight" : NULL
;
3489 if (isempty(optarg
)) {
3490 r
= drop_from_identity(field
);
3496 r
= safe_atou64(optarg
, &u
);
3498 return log_error_errno(r
, "Failed to parse --cpu-weight=/--io-weight= parameter: %s", optarg
);
3500 if (!CGROUP_WEIGHT_IS_OK(u
))
3501 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Weight %" PRIu64
" is out of valid weight range.", u
);
3503 r
= json_variant_set_field_unsigned(&arg_identity_extra
, field
, u
);
3505 return log_error_errno(r
, "Failed to set %s field: %m", field
);
3510 case ARG_PKCS11_TOKEN_URI
:
3511 if (streq(optarg
, "list"))
3512 return pkcs11_list_tokens();
3514 /* If --pkcs11-token-uri= is specified we always drop everything old */
3515 FOREACH_STRING(p
, "pkcs11TokenUri", "pkcs11EncryptedKey") {
3516 r
= drop_from_identity(p
);
3521 if (isempty(optarg
)) {
3522 arg_pkcs11_token_uri
= strv_free(arg_pkcs11_token_uri
);
3526 if (streq(optarg
, "auto")) {
3527 _cleanup_free_
char *found
= NULL
;
3529 r
= pkcs11_find_token_auto(&found
);
3532 r
= strv_consume(&arg_pkcs11_token_uri
, TAKE_PTR(found
));
3534 if (!pkcs11_uri_valid(optarg
))
3535 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Not a valid PKCS#11 URI: %s", optarg
);
3537 r
= strv_extend(&arg_pkcs11_token_uri
, optarg
);
3542 strv_uniq(arg_pkcs11_token_uri
);
3545 case ARG_FIDO2_CRED_ALG
:
3546 r
= parse_fido2_algorithm(optarg
, &arg_fido2_cred_alg
);
3548 return log_error_errno(r
, "Failed to parse COSE algorithm: %s", optarg
);
3551 case ARG_FIDO2_DEVICE
:
3552 if (streq(optarg
, "list"))
3553 return fido2_list_devices();
3555 FOREACH_STRING(p
, "fido2HmacCredential", "fido2HmacSalt") {
3556 r
= drop_from_identity(p
);
3561 if (isempty(optarg
)) {
3562 arg_fido2_device
= strv_free(arg_fido2_device
);
3566 if (streq(optarg
, "auto")) {
3567 _cleanup_free_
char *found
= NULL
;
3569 r
= fido2_find_device_auto(&found
);
3573 r
= strv_consume(&arg_fido2_device
, TAKE_PTR(found
));
3575 r
= strv_extend(&arg_fido2_device
, optarg
);
3579 strv_uniq(arg_fido2_device
);
3582 case ARG_FIDO2_WITH_PIN
: {
3585 r
= parse_boolean_argument("--fido2-with-client-pin=", optarg
, &lock_with_pin
);
3589 SET_FLAG(arg_fido2_lock_with
, FIDO2ENROLL_PIN
, lock_with_pin
);
3593 case ARG_FIDO2_WITH_UP
: {
3596 r
= parse_boolean_argument("--fido2-with-user-presence=", optarg
, &lock_with_up
);
3600 SET_FLAG(arg_fido2_lock_with
, FIDO2ENROLL_UP
, lock_with_up
);
3604 case ARG_FIDO2_WITH_UV
: {
3607 r
= parse_boolean_argument("--fido2-with-user-verification=", optarg
, &lock_with_uv
);
3611 SET_FLAG(arg_fido2_lock_with
, FIDO2ENROLL_UV
, lock_with_uv
);
3615 case ARG_RECOVERY_KEY
:
3616 r
= parse_boolean(optarg
);
3618 return log_error_errno(r
, "Failed to parse --recovery-key= argument: %s", optarg
);
3620 arg_recovery_key
= r
;
3622 FOREACH_STRING(p
, "recoveryKey", "recoveryKeyType") {
3623 r
= drop_from_identity(p
);
3630 case ARG_AUTO_RESIZE_MODE
:
3631 if (isempty(optarg
)) {
3632 r
= drop_from_identity("autoResizeMode");
3639 r
= auto_resize_mode_from_string(optarg
);
3641 return log_error_errno(r
, "Failed to parse --auto-resize-mode= argument: %s", optarg
);
3643 r
= json_variant_set_field_string(&arg_identity_extra
, "autoResizeMode", auto_resize_mode_to_string(r
));
3645 return log_error_errno(r
, "Failed to set autoResizeMode field: %m");
3649 case ARG_REBALANCE_WEIGHT
: {
3652 if (isempty(optarg
)) {
3653 r
= drop_from_identity("rebalanceWeight");
3658 if (streq(optarg
, "off"))
3659 u
= REBALANCE_WEIGHT_OFF
;
3661 r
= safe_atou64(optarg
, &u
);
3663 return log_error_errno(r
, "Failed to parse --rebalance-weight= argument: %s", optarg
);
3665 if (u
< REBALANCE_WEIGHT_MIN
|| u
> REBALANCE_WEIGHT_MAX
)
3666 return log_error_errno(SYNTHETIC_ERRNO(ERANGE
), "Rebalancing weight out of valid range %" PRIu64
"%s%" PRIu64
": %s",
3667 REBALANCE_WEIGHT_MIN
, special_glyph(SPECIAL_GLYPH_ELLIPSIS
), REBALANCE_WEIGHT_MAX
, optarg
);
3670 /* Drop from per machine stuff and everywhere */
3671 r
= drop_from_identity("rebalanceWeight");
3675 /* Add to main identity */
3676 r
= json_variant_set_field_unsigned(&arg_identity_extra
, "rebalanceWeight", u
);
3678 return log_error_errno(r
, "Failed to set rebalanceWeight field: %m");
3684 arg_json_format_flags
= JSON_FORMAT_PRETTY_AUTO
|JSON_FORMAT_COLOR_AUTO
;
3688 r
= parse_json_argument(optarg
, &arg_json_format_flags
);
3695 if (arg_export_format
== EXPORT_FORMAT_FULL
)
3696 arg_export_format
= EXPORT_FORMAT_STRIPPED
;
3697 else if (arg_export_format
== EXPORT_FORMAT_STRIPPED
)
3698 arg_export_format
= EXPORT_FORMAT_MINIMAL
;
3700 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Specifying -E more than twice is not supported.");
3702 arg_json_format_flags
&= ~JSON_FORMAT_OFF
;
3703 if (arg_json_format_flags
== 0)
3704 arg_json_format_flags
= JSON_FORMAT_PRETTY_AUTO
|JSON_FORMAT_COLOR_AUTO
;
3707 case ARG_EXPORT_FORMAT
:
3708 if (streq(optarg
, "full"))
3709 arg_export_format
= EXPORT_FORMAT_FULL
;
3710 else if (streq(optarg
, "stripped"))
3711 arg_export_format
= EXPORT_FORMAT_STRIPPED
;
3712 else if (streq(optarg
, "minimal"))
3713 arg_export_format
= EXPORT_FORMAT_MINIMAL
;
3714 else if (streq(optarg
, "help")) {
3723 case ARG_AND_RESIZE
:
3724 arg_and_resize
= true;
3727 case ARG_AND_CHANGE_PASSWORD
:
3728 arg_and_change_password
= true;
3731 case ARG_DROP_CACHES
: {
3734 if (isempty(optarg
)) {
3735 r
= drop_from_identity("dropCaches");
3740 r
= parse_boolean_argument("--drop-caches=", optarg
, &drop_caches
);
3744 r
= json_variant_set_field_boolean(&arg_identity_extra
, "dropCaches", r
);
3746 return log_error_errno(r
, "Failed to set drop caches field: %m");
3755 assert_not_reached();
3759 if (!strv_isempty(arg_pkcs11_token_uri
) || !strv_isempty(arg_fido2_device
))
3760 arg_and_change_password
= true;
3762 if (arg_disk_size
!= UINT64_MAX
|| arg_disk_size_relative
!= UINT64_MAX
)
3763 arg_and_resize
= true;
3768 static int redirect_bus_mgr(void) {
3771 /* Talk to a different service if that's requested. (The same env var is also understood by homed, so
3772 * that it is relatively easily possible to invoke a second instance of homed for debug purposes and
3773 * have homectl talk to it, without colliding with the host version. This is handy when operating
3774 * from a homed-managed account.) */
3776 suffix
= getenv("SYSTEMD_HOME_DEBUG_SUFFIX");
3778 static BusLocator locator
= {
3779 .path
= "/org/freedesktop/home1",
3780 .interface
= "org.freedesktop.home1.Manager",
3783 /* Yes, we leak this memory, but there's little point to collect this, given that we only do
3784 * this in a debug environment, do it only once, and the string shall live for out entire
3785 * process runtime. */
3787 locator
.destination
= strjoin("org.freedesktop.home1.", suffix
);
3788 if (!locator
.destination
)
3793 bus_mgr
= bus_home_mgr
;
3798 static int run(int argc
, char *argv
[]) {
3799 static const Verb verbs
[] = {
3800 { "help", VERB_ANY
, VERB_ANY
, 0, help
},
3801 { "list", VERB_ANY
, 1, VERB_DEFAULT
, list_homes
},
3802 { "activate", 2, VERB_ANY
, 0, activate_home
},
3803 { "deactivate", 2, VERB_ANY
, 0, deactivate_home
},
3804 { "inspect", VERB_ANY
, VERB_ANY
, 0, inspect_home
},
3805 { "authenticate", VERB_ANY
, VERB_ANY
, 0, authenticate_home
},
3806 { "create", VERB_ANY
, 2, 0, create_home
},
3807 { "remove", 2, VERB_ANY
, 0, remove_home
},
3808 { "update", VERB_ANY
, 2, 0, update_home
},
3809 { "passwd", VERB_ANY
, 2, 0, passwd_home
},
3810 { "resize", 2, 3, 0, resize_home
},
3811 { "lock", 2, VERB_ANY
, 0, lock_home
},
3812 { "unlock", 2, VERB_ANY
, 0, unlock_home
},
3813 { "with", 2, VERB_ANY
, 0, with_home
},
3814 { "lock-all", VERB_ANY
, 1, 0, lock_all_homes
},
3815 { "deactivate-all", VERB_ANY
, 1, 0, deactivate_all_homes
},
3816 { "rebalance", VERB_ANY
, 1, 0, rebalance
},
3824 r
= redirect_bus_mgr();
3828 r
= parse_argv(argc
, argv
);
3832 return dispatch_verb(argc
, argv
, verbs
, NULL
);
3835 DEFINE_MAIN_FUNCTION_WITH_POSITIVE_FAILURE(run
);