1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
7 #include "ask-password-api.h"
9 #include "bus-common-errors.h"
10 #include "bus-error.h"
11 #include "bus-locator.h"
12 #include "cgroup-util.h"
13 #include "dns-domain.h"
17 #include "format-table.h"
19 #include "glyph-util.h"
20 #include "home-util.h"
21 #include "homectl-fido2.h"
22 #include "homectl-pkcs11.h"
23 #include "homectl-recovery-key.h"
24 #include "libfido2-util.h"
25 #include "locale-util.h"
26 #include "main-func.h"
27 #include "memory-util.h"
29 #include "parse-argument.h"
30 #include "parse-util.h"
31 #include "path-util.h"
32 #include "percent-util.h"
33 #include "pkcs11-util.h"
34 #include "pretty-print.h"
35 #include "process-util.h"
36 #include "pwquality-util.h"
37 #include "rlimit-util.h"
38 #include "spawn-polkit-agent.h"
39 #include "terminal-util.h"
40 #include "uid-alloc-range.h"
41 #include "user-record-pwquality.h"
42 #include "user-record-show.h"
43 #include "user-record-util.h"
44 #include "user-record.h"
45 #include "user-util.h"
48 static PagerFlags arg_pager_flags
= 0;
49 static bool arg_legend
= true;
50 static bool arg_ask_password
= true;
51 static BusTransport arg_transport
= BUS_TRANSPORT_LOCAL
;
52 static const char *arg_host
= NULL
;
53 static const char *arg_identity
= NULL
;
54 static JsonVariant
*arg_identity_extra
= NULL
;
55 static JsonVariant
*arg_identity_extra_privileged
= NULL
;
56 static JsonVariant
*arg_identity_extra_this_machine
= NULL
;
57 static JsonVariant
*arg_identity_extra_rlimits
= NULL
;
58 static char **arg_identity_filter
= NULL
; /* this one is also applied to 'privileged' and 'thisMachine' subobjects */
59 static char **arg_identity_filter_rlimits
= NULL
;
60 static uint64_t arg_disk_size
= UINT64_MAX
;
61 static uint64_t arg_disk_size_relative
= UINT64_MAX
;
62 static char **arg_pkcs11_token_uri
= NULL
;
63 static char **arg_fido2_device
= NULL
;
64 static Fido2EnrollFlags arg_fido2_lock_with
= FIDO2ENROLL_PIN
| FIDO2ENROLL_UP
;
66 static int arg_fido2_cred_alg
= COSE_ES256
;
68 static int arg_fido2_cred_alg
= 0;
70 static bool arg_recovery_key
= false;
71 static JsonFormatFlags arg_json_format_flags
= JSON_FORMAT_OFF
;
72 static bool arg_and_resize
= false;
73 static bool arg_and_change_password
= false;
75 EXPORT_FORMAT_FULL
, /* export the full record */
76 EXPORT_FORMAT_STRIPPED
, /* strip "state" + "binding", but leave signature in place */
77 EXPORT_FORMAT_MINIMAL
, /* also strip signature */
78 } arg_export_format
= EXPORT_FORMAT_FULL
;
80 STATIC_DESTRUCTOR_REGISTER(arg_identity_extra
, json_variant_unrefp
);
81 STATIC_DESTRUCTOR_REGISTER(arg_identity_extra_this_machine
, json_variant_unrefp
);
82 STATIC_DESTRUCTOR_REGISTER(arg_identity_extra_privileged
, json_variant_unrefp
);
83 STATIC_DESTRUCTOR_REGISTER(arg_identity_extra_rlimits
, json_variant_unrefp
);
84 STATIC_DESTRUCTOR_REGISTER(arg_identity_filter
, strv_freep
);
85 STATIC_DESTRUCTOR_REGISTER(arg_identity_filter_rlimits
, strv_freep
);
86 STATIC_DESTRUCTOR_REGISTER(arg_pkcs11_token_uri
, strv_freep
);
87 STATIC_DESTRUCTOR_REGISTER(arg_fido2_device
, strv_freep
);
89 static const BusLocator
*bus_mgr
;
91 static bool identity_properties_specified(void) {
94 !json_variant_is_blank_object(arg_identity_extra
) ||
95 !json_variant_is_blank_object(arg_identity_extra_privileged
) ||
96 !json_variant_is_blank_object(arg_identity_extra_this_machine
) ||
97 !json_variant_is_blank_object(arg_identity_extra_rlimits
) ||
98 !strv_isempty(arg_identity_filter
) ||
99 !strv_isempty(arg_identity_filter_rlimits
) ||
100 !strv_isempty(arg_pkcs11_token_uri
) ||
101 !strv_isempty(arg_fido2_device
);
104 static int acquire_bus(sd_bus
**bus
) {
112 r
= bus_connect_transport(arg_transport
, arg_host
, false, bus
);
114 return bus_log_connect_error(r
, arg_transport
);
116 (void) sd_bus_set_allow_interactive_authorization(*bus
, arg_ask_password
);
121 static int list_homes(int argc
, char *argv
[], void *userdata
) {
122 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
123 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
124 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
125 _cleanup_(table_unrefp
) Table
*table
= NULL
;
128 r
= acquire_bus(&bus
);
132 r
= bus_call_method(bus
, bus_mgr
, "ListHomes", &error
, &reply
, NULL
);
134 return log_error_errno(r
, "Failed to list homes: %s", bus_error_message(&error
, r
));
136 table
= table_new("name", "uid", "gid", "state", "realname", "home", "shell");
140 r
= sd_bus_message_enter_container(reply
, 'a', "(susussso)");
142 return bus_log_parse_error(r
);
145 const char *name
, *state
, *realname
, *home
, *shell
, *color
;
149 r
= sd_bus_message_read(reply
, "(susussso)", &name
, &uid
, &state
, &gid
, &realname
, &home
, &shell
, NULL
);
151 return bus_log_parse_error(r
);
155 r
= table_add_many(table
,
160 return table_log_add_error(r
);
163 r
= table_add_cell(table
, &cell
, TABLE_STRING
, state
);
165 return table_log_add_error(r
);
167 color
= user_record_state_color(state
);
169 (void) table_set_color(table
, cell
, color
);
171 r
= table_add_many(table
,
172 TABLE_STRING
, strna(empty_to_null(realname
)),
174 TABLE_STRING
, strna(empty_to_null(shell
)));
176 return table_log_add_error(r
);
179 r
= sd_bus_message_exit_container(reply
);
181 return bus_log_parse_error(r
);
183 if (table_get_rows(table
) > 1 || !FLAGS_SET(arg_json_format_flags
, JSON_FORMAT_OFF
)) {
184 r
= table_set_sort(table
, (size_t) 0);
186 return table_log_sort_error(r
);
188 r
= table_print_with_pager(table
, arg_json_format_flags
, arg_pager_flags
, arg_legend
);
193 if (arg_legend
&& (arg_json_format_flags
& JSON_FORMAT_OFF
)) {
194 if (table_get_rows(table
) > 1)
195 printf("\n%zu home areas listed.\n", table_get_rows(table
) - 1);
197 printf("No home areas.\n");
203 static int acquire_existing_password(
204 const char *user_name
,
206 bool emphasize_current
,
207 AskPasswordFlags flags
) {
209 _cleanup_(strv_free_erasep
) char **password
= NULL
;
210 _cleanup_(erase_and_freep
) char *envpw
= NULL
;
211 _cleanup_free_
char *question
= NULL
;
217 r
= getenv_steal_erase("PASSWORD", &envpw
);
219 return log_error_errno(r
, "Failed to acquire password from environment: %m");
221 /* People really shouldn't use environment variables for passing passwords. We support this
222 * only for testing purposes, and do not document the behaviour, so that people won't
223 * actually use this outside of testing. */
225 r
= user_record_set_password(hr
, STRV_MAKE(envpw
), true);
227 return log_error_errno(r
, "Failed to store password: %m");
232 /* If this is not our own user, then don't use the password cache */
233 if (is_this_me(user_name
) <= 0)
234 SET_FLAG(flags
, ASK_PASSWORD_ACCEPT_CACHED
|ASK_PASSWORD_PUSH_CACHE
, false);
236 if (asprintf(&question
, emphasize_current
?
237 "Please enter current password for user %s:" :
238 "Please enter password for user %s:",
242 r
= ask_password_auto(question
,
243 /* icon= */ "user-home",
245 /* key_name= */ "home-password",
246 /* credential_name= */ "home.password",
250 if (r
== -EUNATCH
) { /* EUNATCH is returned if no password was found and asking interactively was
251 * disabled via the flags. Not an error for us. */
252 log_debug_errno(r
, "No passwords acquired.");
256 return log_error_errno(r
, "Failed to acquire password: %m");
258 r
= user_record_set_password(hr
, password
, true);
260 return log_error_errno(r
, "Failed to store password: %m");
265 static int acquire_recovery_key(
266 const char *user_name
,
268 AskPasswordFlags flags
) {
270 _cleanup_(strv_free_erasep
) char **recovery_key
= NULL
;
271 _cleanup_(erase_and_freep
) char *envpw
= NULL
;
272 _cleanup_free_
char *question
= NULL
;
278 r
= getenv_steal_erase("PASSWORD", &envpw
);
280 return log_error_errno(r
, "Failed to acquire password from environment: %m");
282 /* People really shouldn't use environment variables for passing secrets. We support this
283 * only for testing purposes, and do not document the behaviour, so that people won't
284 * actually use this outside of testing. */
286 r
= user_record_set_password(hr
, STRV_MAKE(envpw
), true); /* recovery keys are stored in the record exactly like regular passwords! */
288 return log_error_errno(r
, "Failed to store recovery key: %m");
293 /* If this is not our own user, then don't use the password cache */
294 if (is_this_me(user_name
) <= 0)
295 SET_FLAG(flags
, ASK_PASSWORD_ACCEPT_CACHED
|ASK_PASSWORD_PUSH_CACHE
, false);
297 if (asprintf(&question
, "Please enter recovery key for user %s:", user_name
) < 0)
300 r
= ask_password_auto(question
,
301 /* icon= */ "user-home",
303 /* key_name= */ "home-recovery-key",
304 /* credential_name= */ "home.recovery-key",
308 if (r
== -EUNATCH
) { /* EUNATCH is returned if no recovery key was found and asking interactively was
309 * disabled via the flags. Not an error for us. */
310 log_debug_errno(r
, "No recovery keys acquired.");
314 return log_error_errno(r
, "Failed to acquire recovery keys: %m");
316 r
= user_record_set_password(hr
, recovery_key
, true);
318 return log_error_errno(r
, "Failed to store recovery keys: %m");
323 static int acquire_token_pin(
324 const char *user_name
,
326 AskPasswordFlags flags
) {
328 _cleanup_(strv_free_erasep
) char **pin
= NULL
;
329 _cleanup_(erase_and_freep
) char *envpin
= NULL
;
330 _cleanup_free_
char *question
= NULL
;
336 r
= getenv_steal_erase("PIN", &envpin
);
338 return log_error_errno(r
, "Failed to acquire PIN from environment: %m");
340 r
= user_record_set_token_pin(hr
, STRV_MAKE(envpin
), false);
342 return log_error_errno(r
, "Failed to store token PIN: %m");
347 /* If this is not our own user, then don't use the password cache */
348 if (is_this_me(user_name
) <= 0)
349 SET_FLAG(flags
, ASK_PASSWORD_ACCEPT_CACHED
|ASK_PASSWORD_PUSH_CACHE
, false);
351 if (asprintf(&question
, "Please enter security token PIN for user %s:", user_name
) < 0)
354 r
= ask_password_auto(
356 /* icon= */ "user-home",
358 /* key_name= */ "token-pin",
359 /* credential_name= */ "home.token-pin",
363 if (r
== -EUNATCH
) { /* EUNATCH is returned if no PIN was found and asking interactively was disabled
364 * via the flags. Not an error for us. */
365 log_debug_errno(r
, "No security token PINs acquired.");
369 return log_error_errno(r
, "Failed to acquire security token PIN: %m");
371 r
= user_record_set_token_pin(hr
, pin
, false);
373 return log_error_errno(r
, "Failed to store security token PIN: %m");
378 static int handle_generic_user_record_error(
379 const char *user_name
,
381 const sd_bus_error
*error
,
383 bool emphasize_current_password
) {
389 if (sd_bus_error_has_name(error
, BUS_ERROR_HOME_ABSENT
))
390 return log_error_errno(SYNTHETIC_ERRNO(EREMOTE
),
391 "Home of user %s is currently absent, please plug in the necessary storage device or backing file system.", user_name
);
393 else if (sd_bus_error_has_name(error
, BUS_ERROR_AUTHENTICATION_LIMIT_HIT
))
394 return log_error_errno(SYNTHETIC_ERRNO(ETOOMANYREFS
),
395 "Too frequent login attempts for user %s, try again later.", user_name
);
397 else if (sd_bus_error_has_name(error
, BUS_ERROR_BAD_PASSWORD
)) {
399 if (!strv_isempty(hr
->password
))
400 log_notice("Password incorrect or not sufficient, please try again.");
402 /* Don't consume cache entries or credentials here, we already tried that unsuccessfully. But
403 * let's push what we acquire here into the cache */
404 r
= acquire_existing_password(
407 emphasize_current_password
,
408 ASK_PASSWORD_PUSH_CACHE
| ASK_PASSWORD_NO_CREDENTIAL
);
412 } else if (sd_bus_error_has_name(error
, BUS_ERROR_BAD_RECOVERY_KEY
)) {
414 if (!strv_isempty(hr
->password
))
415 log_notice("Recovery key incorrect or not sufficient, please try again.");
417 /* Don't consume cache entries or credentials here, we already tried that unsuccessfully. But
418 * let's push what we acquire here into the cache */
419 r
= acquire_recovery_key(
422 ASK_PASSWORD_PUSH_CACHE
| ASK_PASSWORD_NO_CREDENTIAL
);
426 } else if (sd_bus_error_has_name(error
, BUS_ERROR_BAD_PASSWORD_AND_NO_TOKEN
)) {
428 if (strv_isempty(hr
->password
))
429 log_notice("Security token not inserted, please enter password.");
431 log_notice("Password incorrect or not sufficient, and configured security token not inserted, please try again.");
433 r
= acquire_existing_password(
436 emphasize_current_password
,
437 ASK_PASSWORD_PUSH_CACHE
| ASK_PASSWORD_NO_CREDENTIAL
);
441 } else if (sd_bus_error_has_name(error
, BUS_ERROR_TOKEN_PIN_NEEDED
)) {
443 /* First time the PIN is requested, let's accept cached data, and allow using credential store */
444 r
= acquire_token_pin(
447 ASK_PASSWORD_ACCEPT_CACHED
| ASK_PASSWORD_PUSH_CACHE
);
451 } else if (sd_bus_error_has_name(error
, BUS_ERROR_TOKEN_PROTECTED_AUTHENTICATION_PATH_NEEDED
)) {
453 log_notice("%s%sPlease authenticate physically on security token.",
454 emoji_enabled() ? special_glyph(SPECIAL_GLYPH_TOUCH
) : "",
455 emoji_enabled() ? " " : "");
457 r
= user_record_set_pkcs11_protected_authentication_path_permitted(hr
, true);
459 return log_error_errno(r
, "Failed to set PKCS#11 protected authentication path permitted flag: %m");
461 } else if (sd_bus_error_has_name(error
, BUS_ERROR_TOKEN_USER_PRESENCE_NEEDED
)) {
463 log_notice("%s%sPlease confirm presence on security token.",
464 emoji_enabled() ? special_glyph(SPECIAL_GLYPH_TOUCH
) : "",
465 emoji_enabled() ? " " : "");
467 r
= user_record_set_fido2_user_presence_permitted(hr
, true);
469 return log_error_errno(r
, "Failed to set FIDO2 user presence permitted flag: %m");
471 } else if (sd_bus_error_has_name(error
, BUS_ERROR_TOKEN_USER_VERIFICATION_NEEDED
)) {
473 log_notice("%s%sPlease verify user on security token.",
474 emoji_enabled() ? special_glyph(SPECIAL_GLYPH_TOUCH
) : "",
475 emoji_enabled() ? " " : "");
477 r
= user_record_set_fido2_user_verification_permitted(hr
, true);
479 return log_error_errno(r
, "Failed to set FIDO2 user verification permitted flag: %m");
481 } else if (sd_bus_error_has_name(error
, BUS_ERROR_TOKEN_PIN_LOCKED
))
482 return log_error_errno(SYNTHETIC_ERRNO(EPERM
), "Security token PIN is locked, please unlock it first. (Hint: Removal and re-insertion might suffice.)");
484 else if (sd_bus_error_has_name(error
, BUS_ERROR_TOKEN_BAD_PIN
)) {
486 log_notice("Security token PIN incorrect, please try again.");
488 /* If the previous PIN was wrong don't accept cached info anymore, but add to cache. Also, don't use the credential data */
489 r
= acquire_token_pin(
492 ASK_PASSWORD_PUSH_CACHE
| ASK_PASSWORD_NO_CREDENTIAL
);
496 } else if (sd_bus_error_has_name(error
, BUS_ERROR_TOKEN_BAD_PIN_FEW_TRIES_LEFT
)) {
498 log_notice("Security token PIN incorrect, please try again (only a few tries left!).");
500 r
= acquire_token_pin(
503 ASK_PASSWORD_PUSH_CACHE
| ASK_PASSWORD_NO_CREDENTIAL
);
507 } else if (sd_bus_error_has_name(error
, BUS_ERROR_TOKEN_BAD_PIN_ONE_TRY_LEFT
)) {
509 log_notice("Security token PIN incorrect, please try again (only one try left!).");
511 r
= acquire_token_pin(
514 ASK_PASSWORD_PUSH_CACHE
| ASK_PASSWORD_NO_CREDENTIAL
);
518 return log_error_errno(ret
, "Operation on home %s failed: %s", user_name
, bus_error_message(error
, ret
));
523 static int acquire_passed_secrets(const char *user_name
, UserRecord
**ret
) {
524 _cleanup_(user_record_unrefp
) UserRecord
*secret
= NULL
;
529 /* Generates an initial secret objects that contains passwords supplied via $PASSWORD, the password
530 * cache or the credentials subsystem, but excluding any interactive stuff. If nothing is passed,
531 * returns an empty secret object. */
533 secret
= user_record_new();
537 r
= acquire_existing_password(
540 /* emphasize_current_password = */ false,
541 ASK_PASSWORD_ACCEPT_CACHED
| ASK_PASSWORD_NO_TTY
| ASK_PASSWORD_NO_AGENT
);
545 r
= acquire_token_pin(
548 ASK_PASSWORD_ACCEPT_CACHED
| ASK_PASSWORD_NO_TTY
| ASK_PASSWORD_NO_AGENT
);
552 r
= acquire_recovery_key(
555 ASK_PASSWORD_ACCEPT_CACHED
| ASK_PASSWORD_NO_TTY
| ASK_PASSWORD_NO_AGENT
);
559 *ret
= TAKE_PTR(secret
);
563 static int activate_home(int argc
, char *argv
[], void *userdata
) {
564 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
567 r
= acquire_bus(&bus
);
571 STRV_FOREACH(i
, strv_skip(argv
, 1)) {
572 _cleanup_(user_record_unrefp
) UserRecord
*secret
= NULL
;
574 r
= acquire_passed_secrets(*i
, &secret
);
579 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
580 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
582 r
= bus_message_new_method_call(bus
, &m
, bus_mgr
, "ActivateHome");
584 return bus_log_create_error(r
);
586 r
= sd_bus_message_append(m
, "s", *i
);
588 return bus_log_create_error(r
);
590 r
= bus_message_append_secret(m
, secret
);
592 return bus_log_create_error(r
);
594 r
= sd_bus_call(bus
, m
, HOME_SLOW_BUS_CALL_TIMEOUT_USEC
, &error
, NULL
);
596 r
= handle_generic_user_record_error(*i
, secret
, &error
, r
, /* emphasize_current_password= */ false);
611 static int deactivate_home(int argc
, char *argv
[], void *userdata
) {
612 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
615 r
= acquire_bus(&bus
);
619 STRV_FOREACH(i
, strv_skip(argv
, 1)) {
620 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
621 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
623 r
= bus_message_new_method_call(bus
, &m
, bus_mgr
, "DeactivateHome");
625 return bus_log_create_error(r
);
627 r
= sd_bus_message_append(m
, "s", *i
);
629 return bus_log_create_error(r
);
631 r
= sd_bus_call(bus
, m
, HOME_SLOW_BUS_CALL_TIMEOUT_USEC
, &error
, NULL
);
633 log_error_errno(r
, "Failed to deactivate user home: %s", bus_error_message(&error
, r
));
642 static void dump_home_record(UserRecord
*hr
) {
647 if (hr
->incomplete
) {
649 log_warning("Warning: lacking rights to acquire privileged fields of user record of '%s', output incomplete.", hr
->user_name
);
652 if (arg_json_format_flags
& JSON_FORMAT_OFF
)
653 user_record_show(hr
, true);
655 _cleanup_(user_record_unrefp
) UserRecord
*stripped
= NULL
;
657 if (arg_export_format
== EXPORT_FORMAT_STRIPPED
)
658 r
= user_record_clone(hr
, USER_RECORD_EXTRACT_EMBEDDED
|USER_RECORD_PERMISSIVE
, &stripped
);
659 else if (arg_export_format
== EXPORT_FORMAT_MINIMAL
)
660 r
= user_record_clone(hr
, USER_RECORD_EXTRACT_SIGNABLE
|USER_RECORD_PERMISSIVE
, &stripped
);
664 log_warning_errno(r
, "Failed to strip user record, ignoring: %m");
668 json_variant_dump(hr
->json
, arg_json_format_flags
, stdout
, NULL
);
672 static char **mangle_user_list(char **list
, char ***ret_allocated
) {
673 _cleanup_free_
char *myself
= NULL
;
676 if (!strv_isempty(list
)) {
677 *ret_allocated
= NULL
;
681 myself
= getusername_malloc();
689 l
[0] = TAKE_PTR(myself
);
696 static int inspect_home(int argc
, char *argv
[], void *userdata
) {
697 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
698 _cleanup_(strv_freep
) char **mangled_list
= NULL
;
702 pager_open(arg_pager_flags
);
704 r
= acquire_bus(&bus
);
708 items
= mangle_user_list(strv_skip(argv
, 1), &mangled_list
);
712 STRV_FOREACH(i
, items
) {
713 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
714 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
715 _cleanup_(json_variant_unrefp
) JsonVariant
*v
= NULL
;
716 _cleanup_(user_record_unrefp
) UserRecord
*hr
= NULL
;
721 r
= parse_uid(*i
, &uid
);
723 if (!valid_user_group_name(*i
, 0)) {
724 log_error("Invalid user name '%s'.", *i
);
731 r
= bus_call_method(bus
, bus_mgr
, "GetUserRecordByName", &error
, &reply
, "s", *i
);
733 r
= bus_call_method(bus
, bus_mgr
, "GetUserRecordByUID", &error
, &reply
, "u", (uint32_t) uid
);
736 log_error_errno(r
, "Failed to inspect home: %s", bus_error_message(&error
, r
));
743 r
= sd_bus_message_read(reply
, "sbo", &json
, &incomplete
, NULL
);
745 bus_log_parse_error(r
);
752 r
= json_parse(json
, JSON_PARSE_SENSITIVE
, &v
, NULL
, NULL
);
754 log_error_errno(r
, "Failed to parse JSON identity: %m");
761 hr
= user_record_new();
765 r
= user_record_load(hr
, v
, USER_RECORD_LOAD_REFUSE_SECRET
|USER_RECORD_LOG
|USER_RECORD_PERMISSIVE
);
773 hr
->incomplete
= incomplete
;
774 dump_home_record(hr
);
780 static int authenticate_home(int argc
, char *argv
[], void *userdata
) {
781 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
782 _cleanup_(strv_freep
) char **mangled_list
= NULL
;
786 items
= mangle_user_list(strv_skip(argv
, 1), &mangled_list
);
790 r
= acquire_bus(&bus
);
794 (void) polkit_agent_open_if_enabled(arg_transport
, arg_ask_password
);
796 STRV_FOREACH(i
, items
) {
797 _cleanup_(user_record_unrefp
) UserRecord
*secret
= NULL
;
799 r
= acquire_passed_secrets(*i
, &secret
);
804 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
805 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
807 r
= bus_message_new_method_call(bus
, &m
, bus_mgr
, "AuthenticateHome");
809 return bus_log_create_error(r
);
811 r
= sd_bus_message_append(m
, "s", *i
);
813 return bus_log_create_error(r
);
815 r
= bus_message_append_secret(m
, secret
);
817 return bus_log_create_error(r
);
819 r
= sd_bus_call(bus
, m
, HOME_SLOW_BUS_CALL_TIMEOUT_USEC
, &error
, NULL
);
821 r
= handle_generic_user_record_error(*i
, secret
, &error
, r
, false);
836 static int update_last_change(JsonVariant
**v
, bool with_password
, bool override
) {
843 n
= now(CLOCK_REALTIME
);
845 c
= json_variant_by_key(*v
, "lastChangeUSec");
850 goto update_password
;
852 if (!json_variant_is_unsigned(c
))
853 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "lastChangeUSec field is not an unsigned integer, refusing.");
855 u
= json_variant_unsigned(c
);
857 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "lastChangeUSec is from the future, can't update.");
860 r
= json_variant_set_field_unsigned(v
, "lastChangeUSec", n
);
862 return log_error_errno(r
, "Failed to update lastChangeUSec: %m");
868 c
= json_variant_by_key(*v
, "lastPasswordChangeUSec");
875 if (!json_variant_is_unsigned(c
))
876 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "lastPasswordChangeUSec field is not an unsigned integer, refusing.");
878 u
= json_variant_unsigned(c
);
880 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "lastPasswordChangeUSec is from the future, can't update.");
883 r
= json_variant_set_field_unsigned(v
, "lastPasswordChangeUSec", n
);
885 return log_error_errno(r
, "Failed to update lastPasswordChangeUSec: %m");
890 static int apply_identity_changes(JsonVariant
**_v
) {
891 _cleanup_(json_variant_unrefp
) JsonVariant
*v
= NULL
;
896 v
= json_variant_ref(*_v
);
898 r
= json_variant_filter(&v
, arg_identity_filter
);
900 return log_error_errno(r
, "Failed to filter identity: %m");
902 r
= json_variant_merge(&v
, arg_identity_extra
);
904 return log_error_errno(r
, "Failed to merge identities: %m");
906 if (arg_identity_extra_this_machine
|| !strv_isempty(arg_identity_filter
)) {
907 _cleanup_(json_variant_unrefp
) JsonVariant
*per_machine
= NULL
, *mmid
= NULL
;
910 r
= sd_id128_get_machine(&mid
);
912 return log_error_errno(r
, "Failed to acquire machine ID: %m");
914 r
= json_variant_new_string(&mmid
, SD_ID128_TO_STRING(mid
));
916 return log_error_errno(r
, "Failed to allocate matchMachineId object: %m");
918 per_machine
= json_variant_ref(json_variant_by_key(v
, "perMachine"));
920 _cleanup_(json_variant_unrefp
) JsonVariant
*npm
= NULL
, *add
= NULL
;
921 _cleanup_free_ JsonVariant
**array
= NULL
;
925 if (!json_variant_is_array(per_machine
))
926 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "perMachine field is not an array, refusing.");
928 array
= new(JsonVariant
*, json_variant_elements(per_machine
) + 1);
932 JSON_VARIANT_ARRAY_FOREACH(z
, per_machine
) {
935 if (!json_variant_is_object(z
))
936 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "perMachine entry is not an object, refusing.");
940 u
= json_variant_by_key(z
, "matchMachineId");
944 if (!json_variant_equal(u
, mmid
))
947 r
= json_variant_merge(&add
, z
);
949 return log_error_errno(r
, "Failed to merge perMachine entry: %m");
954 r
= json_variant_filter(&add
, arg_identity_filter
);
956 return log_error_errno(r
, "Failed to filter perMachine: %m");
958 r
= json_variant_merge(&add
, arg_identity_extra_this_machine
);
960 return log_error_errno(r
, "Failed to merge in perMachine fields: %m");
962 if (arg_identity_filter_rlimits
|| arg_identity_extra_rlimits
) {
963 _cleanup_(json_variant_unrefp
) JsonVariant
*rlv
= NULL
;
965 rlv
= json_variant_ref(json_variant_by_key(add
, "resourceLimits"));
967 r
= json_variant_filter(&rlv
, arg_identity_filter_rlimits
);
969 return log_error_errno(r
, "Failed to filter resource limits: %m");
971 r
= json_variant_merge(&rlv
, arg_identity_extra_rlimits
);
973 return log_error_errno(r
, "Failed to set resource limits: %m");
975 if (json_variant_is_blank_object(rlv
)) {
976 r
= json_variant_filter(&add
, STRV_MAKE("resourceLimits"));
978 return log_error_errno(r
, "Failed to drop resource limits field from identity: %m");
980 r
= json_variant_set_field(&add
, "resourceLimits", rlv
);
982 return log_error_errno(r
, "Failed to update resource limits of identity: %m");
986 if (!json_variant_is_blank_object(add
)) {
987 r
= json_variant_set_field(&add
, "matchMachineId", mmid
);
989 return log_error_errno(r
, "Failed to set matchMachineId field: %m");
994 r
= json_variant_new_array(&npm
, array
, i
);
996 return log_error_errno(r
, "Failed to allocate new perMachine array: %m");
998 json_variant_unref(per_machine
);
999 per_machine
= TAKE_PTR(npm
);
1001 _cleanup_(json_variant_unrefp
) JsonVariant
*item
= json_variant_ref(arg_identity_extra_this_machine
);
1003 if (arg_identity_extra_rlimits
) {
1004 r
= json_variant_set_field(&item
, "resourceLimits", arg_identity_extra_rlimits
);
1006 return log_error_errno(r
, "Failed to update resource limits of identity: %m");
1009 r
= json_variant_set_field(&item
, "matchMachineId", mmid
);
1011 return log_error_errno(r
, "Failed to set matchMachineId field: %m");
1013 r
= json_variant_append_array(&per_machine
, item
);
1015 return log_error_errno(r
, "Failed to append to perMachine array: %m");
1018 r
= json_variant_set_field(&v
, "perMachine", per_machine
);
1020 return log_error_errno(r
, "Failed to update per machine record: %m");
1023 if (arg_identity_extra_privileged
|| arg_identity_filter
) {
1024 _cleanup_(json_variant_unrefp
) JsonVariant
*privileged
= NULL
;
1026 privileged
= json_variant_ref(json_variant_by_key(v
, "privileged"));
1028 r
= json_variant_filter(&privileged
, arg_identity_filter
);
1030 return log_error_errno(r
, "Failed to filter identity (privileged part): %m");
1032 r
= json_variant_merge(&privileged
, arg_identity_extra_privileged
);
1034 return log_error_errno(r
, "Failed to merge identities (privileged part): %m");
1036 if (json_variant_is_blank_object(privileged
)) {
1037 r
= json_variant_filter(&v
, STRV_MAKE("privileged"));
1039 return log_error_errno(r
, "Failed to drop privileged part from identity: %m");
1041 r
= json_variant_set_field(&v
, "privileged", privileged
);
1043 return log_error_errno(r
, "Failed to update privileged part of identity: %m");
1047 if (arg_identity_filter_rlimits
) {
1048 _cleanup_(json_variant_unrefp
) JsonVariant
*rlv
= NULL
;
1050 rlv
= json_variant_ref(json_variant_by_key(v
, "resourceLimits"));
1052 r
= json_variant_filter(&rlv
, arg_identity_filter_rlimits
);
1054 return log_error_errno(r
, "Failed to filter resource limits: %m");
1056 /* Note that we only filter resource limits here, but don't apply them. We do that in the perMachine section */
1058 if (json_variant_is_blank_object(rlv
)) {
1059 r
= json_variant_filter(&v
, STRV_MAKE("resourceLimits"));
1061 return log_error_errno(r
, "Failed to drop resource limits field from identity: %m");
1063 r
= json_variant_set_field(&v
, "resourceLimits", rlv
);
1065 return log_error_errno(r
, "Failed to update resource limits of identity: %m");
1069 json_variant_unref(*_v
);
1075 static int add_disposition(JsonVariant
**v
) {
1080 if (json_variant_by_key(*v
, "disposition"))
1083 /* Set the disposition to regular, if not configured explicitly */
1084 r
= json_variant_set_field_string(v
, "disposition", "regular");
1086 return log_error_errno(r
, "Failed to set disposition field: %m");
1091 static int acquire_new_home_record(UserRecord
**ret
) {
1092 _cleanup_(json_variant_unrefp
) JsonVariant
*v
= NULL
;
1093 _cleanup_(user_record_unrefp
) UserRecord
*hr
= NULL
;
1099 unsigned line
, column
;
1101 r
= json_parse_file(
1102 streq(arg_identity
, "-") ? stdin
: NULL
,
1103 streq(arg_identity
, "-") ? "<stdin>" : arg_identity
, JSON_PARSE_SENSITIVE
, &v
, &line
, &column
);
1105 return log_error_errno(r
, "Failed to parse identity at %u:%u: %m", line
, column
);
1108 r
= apply_identity_changes(&v
);
1112 r
= add_disposition(&v
);
1116 STRV_FOREACH(i
, arg_pkcs11_token_uri
) {
1117 r
= identity_add_pkcs11_key_data(&v
, *i
);
1122 STRV_FOREACH(i
, arg_fido2_device
) {
1123 r
= identity_add_fido2_parameters(&v
, *i
, arg_fido2_lock_with
, arg_fido2_cred_alg
);
1128 if (arg_recovery_key
) {
1129 r
= identity_add_recovery_key(&v
);
1134 r
= update_last_change(&v
, true, false);
1139 json_variant_dump(v
, JSON_FORMAT_PRETTY
, NULL
, NULL
);
1141 hr
= user_record_new();
1145 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
);
1149 *ret
= TAKE_PTR(hr
);
1153 static int acquire_new_password(
1154 const char *user_name
,
1159 _cleanup_(erase_and_freep
) char *envpw
= NULL
;
1166 r
= getenv_steal_erase("NEWPASSWORD", &envpw
);
1168 return log_error_errno(r
, "Failed to acquire password from environment: %m");
1170 /* As above, this is not for use, just for testing */
1172 r
= user_record_set_password(hr
, STRV_MAKE(envpw
), /* prepend = */ true);
1174 return log_error_errno(r
, "Failed to store password: %m");
1177 *ret
= TAKE_PTR(envpw
);
1183 (void) suggest_passwords();
1186 _cleanup_(strv_free_erasep
) char **first
= NULL
, **second
= NULL
;
1187 _cleanup_free_
char *question
= NULL
;
1190 return log_error_errno(SYNTHETIC_ERRNO(ENOKEY
), "Too many attempts, giving up:");
1192 if (asprintf(&question
, "Please enter new password for user %s:", user_name
) < 0)
1195 r
= ask_password_auto(
1197 /* icon= */ "user-home",
1199 /* key_name= */ "home-password",
1200 /* credential_name= */ "home.new-password",
1202 0, /* no caching, we want to collect a new password here after all */
1205 return log_error_errno(r
, "Failed to acquire password: %m");
1207 question
= mfree(question
);
1208 if (asprintf(&question
, "Please enter new password for user %s (repeat):", user_name
) < 0)
1211 r
= ask_password_auto(
1213 /* icon= */ "user-home",
1215 /* key_name= */ "home-password",
1216 /* credential_name= */ "home.new-password",
1221 return log_error_errno(r
, "Failed to acquire password: %m");
1223 if (strv_equal(first
, second
)) {
1224 _cleanup_(erase_and_freep
) char *copy
= NULL
;
1227 copy
= strdup(first
[0]);
1232 r
= user_record_set_password(hr
, first
, /* prepend = */ true);
1234 return log_error_errno(r
, "Failed to store password: %m");
1237 *ret
= TAKE_PTR(copy
);
1242 log_error("Password didn't match, try again.");
1246 static int create_home(int argc
, char *argv
[], void *userdata
) {
1247 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
1248 _cleanup_(user_record_unrefp
) UserRecord
*hr
= NULL
;
1251 r
= acquire_bus(&bus
);
1255 (void) polkit_agent_open_if_enabled(arg_transport
, arg_ask_password
);
1258 /* If a username was specified, use it */
1260 if (valid_user_group_name(argv
[1], 0))
1261 r
= json_variant_set_field_string(&arg_identity_extra
, "userName", argv
[1]);
1263 _cleanup_free_
char *un
= NULL
, *rr
= NULL
;
1265 /* Before we consider the user name invalid, let's check if we can split it? */
1266 r
= split_user_name_realm(argv
[1], &un
, &rr
);
1268 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "User name '%s' is not valid: %m", argv
[1]);
1271 r
= json_variant_set_field_string(&arg_identity_extra
, "realm", rr
);
1273 return log_error_errno(r
, "Failed to set realm field: %m");
1276 r
= json_variant_set_field_string(&arg_identity_extra
, "userName", un
);
1279 return log_error_errno(r
, "Failed to set userName field: %m");
1281 /* If neither a username nor an identity have been specified we cannot operate. */
1283 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "User name required.");
1286 r
= acquire_new_home_record(&hr
);
1290 /* If the JSON record carries no plain text password (besides the recovery key), then let's query it
1292 if (strv_length(hr
->password
) <= arg_recovery_key
) {
1294 if (strv_isempty(hr
->hashed_password
)) {
1295 _cleanup_(erase_and_freep
) char *new_password
= NULL
;
1297 /* No regular (i.e. non-PKCS#11) hashed passwords set in the record, let's fix that. */
1298 r
= acquire_new_password(hr
->user_name
, hr
, /* suggest = */ true, &new_password
);
1302 r
= user_record_make_hashed_password(hr
, STRV_MAKE(new_password
), /* extend = */ false);
1304 return log_error_errno(r
, "Failed to hash password: %m");
1306 /* There's a hash password set in the record, acquire the unhashed version of it. */
1307 r
= acquire_existing_password(
1310 /* emphasize_current= */ false,
1311 ASK_PASSWORD_ACCEPT_CACHED
| ASK_PASSWORD_PUSH_CACHE
);
1317 if (hr
->enforce_password_policy
== 0) {
1318 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1320 /* If password quality enforcement is disabled, let's at least warn client side */
1322 r
= user_record_quality_check_password(hr
, hr
, &error
);
1324 log_warning_errno(r
, "Specified password does not pass quality checks (%s), proceeding anyway.", bus_error_message(&error
, r
));
1328 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1329 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
1330 _cleanup_(erase_and_freep
) char *formatted
= NULL
;
1332 r
= json_variant_format(hr
->json
, 0, &formatted
);
1334 return log_error_errno(r
, "Failed to format user record: %m");
1336 r
= bus_message_new_method_call(bus
, &m
, bus_mgr
, "CreateHome");
1338 return bus_log_create_error(r
);
1340 (void) sd_bus_message_sensitive(m
);
1342 r
= sd_bus_message_append(m
, "s", formatted
);
1344 return bus_log_create_error(r
);
1346 r
= sd_bus_call(bus
, m
, HOME_SLOW_BUS_CALL_TIMEOUT_USEC
, &error
, NULL
);
1348 if (sd_bus_error_has_name(&error
, BUS_ERROR_LOW_PASSWORD_QUALITY
)) {
1349 _cleanup_(erase_and_freep
) char *new_password
= NULL
;
1351 log_error_errno(r
, "%s", bus_error_message(&error
, r
));
1352 log_info("(Use --enforce-password-policy=no to turn off password quality checks for this account.)");
1354 r
= acquire_new_password(hr
->user_name
, hr
, /* suggest = */ false, &new_password
);
1358 r
= user_record_make_hashed_password(hr
, STRV_MAKE(new_password
), /* extend = */ false);
1360 return log_error_errno(r
, "Failed to hash passwords: %m");
1362 r
= handle_generic_user_record_error(hr
->user_name
, hr
, &error
, r
, false);
1373 static int remove_home(int argc
, char *argv
[], void *userdata
) {
1374 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
1377 r
= acquire_bus(&bus
);
1381 (void) polkit_agent_open_if_enabled(arg_transport
, arg_ask_password
);
1383 STRV_FOREACH(i
, strv_skip(argv
, 1)) {
1384 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1385 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
1387 r
= bus_message_new_method_call(bus
, &m
, bus_mgr
, "RemoveHome");
1389 return bus_log_create_error(r
);
1391 r
= sd_bus_message_append(m
, "s", *i
);
1393 return bus_log_create_error(r
);
1395 r
= sd_bus_call(bus
, m
, HOME_SLOW_BUS_CALL_TIMEOUT_USEC
, &error
, NULL
);
1397 log_error_errno(r
, "Failed to remove home: %s", bus_error_message(&error
, r
));
1406 static int acquire_updated_home_record(
1408 const char *username
,
1411 _cleanup_(json_variant_unrefp
) JsonVariant
*json
= NULL
;
1412 _cleanup_(user_record_unrefp
) UserRecord
*hr
= NULL
;
1418 unsigned line
, column
;
1421 r
= json_parse_file(
1422 streq(arg_identity
, "-") ? stdin
: NULL
,
1423 streq(arg_identity
, "-") ? "<stdin>" : arg_identity
, JSON_PARSE_SENSITIVE
, &json
, &line
, &column
);
1425 return log_error_errno(r
, "Failed to parse identity at %u:%u: %m", line
, column
);
1427 un
= json_variant_by_key(json
, "userName");
1429 if (!json_variant_is_string(un
) || (username
&& !streq(json_variant_string(un
), username
)))
1430 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "User name specified on command line and in JSON record do not match.");
1433 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "No username specified.");
1435 r
= json_variant_set_field_string(&arg_identity_extra
, "userName", username
);
1437 return log_error_errno(r
, "Failed to set userName field: %m");
1441 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1442 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
1446 if (!identity_properties_specified())
1447 return log_error_errno(SYNTHETIC_ERRNO(EALREADY
), "No field to change specified.");
1449 r
= bus_call_method(bus
, bus_mgr
, "GetUserRecordByName", &error
, &reply
, "s", username
);
1451 return log_error_errno(r
, "Failed to acquire user home record: %s", bus_error_message(&error
, r
));
1453 r
= sd_bus_message_read(reply
, "sbo", &text
, &incomplete
, NULL
);
1455 return bus_log_parse_error(r
);
1458 return log_error_errno(SYNTHETIC_ERRNO(EACCES
), "Lacking rights to acquire user record including privileged metadata, can't update record.");
1460 r
= json_parse(text
, JSON_PARSE_SENSITIVE
, &json
, NULL
, NULL
);
1462 return log_error_errno(r
, "Failed to parse JSON identity: %m");
1464 reply
= sd_bus_message_unref(reply
);
1466 r
= json_variant_filter(&json
, STRV_MAKE("binding", "status", "signature"));
1468 return log_error_errno(r
, "Failed to strip binding and status from record to update: %m");
1471 r
= apply_identity_changes(&json
);
1475 STRV_FOREACH(i
, arg_pkcs11_token_uri
) {
1476 r
= identity_add_pkcs11_key_data(&json
, *i
);
1481 STRV_FOREACH(i
, arg_fido2_device
) {
1482 r
= identity_add_fido2_parameters(&json
, *i
, arg_fido2_lock_with
, arg_fido2_cred_alg
);
1487 /* If the user supplied a full record, then add in lastChange, but do not override. Otherwise always
1489 r
= update_last_change(&json
, arg_pkcs11_token_uri
|| arg_fido2_device
, !arg_identity
);
1494 json_variant_dump(json
, JSON_FORMAT_PRETTY
, NULL
, NULL
);
1496 hr
= user_record_new();
1500 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
);
1504 *ret
= TAKE_PTR(hr
);
1508 static int home_record_reset_human_interaction_permission(UserRecord
*hr
) {
1513 /* When we execute multiple operations one after the other, let's reset the permission to ask the
1514 * user each time, so that if interaction is necessary we will be told so again and thus can print a
1515 * nice message to the user, telling the user so. */
1517 r
= user_record_set_pkcs11_protected_authentication_path_permitted(hr
, -1);
1519 return log_error_errno(r
, "Failed to reset PKCS#11 protected authentication path permission flag: %m");
1521 r
= user_record_set_fido2_user_presence_permitted(hr
, -1);
1523 return log_error_errno(r
, "Failed to reset FIDO2 user presence permission flag: %m");
1525 r
= user_record_set_fido2_user_verification_permitted(hr
, -1);
1527 return log_error_errno(r
, "Failed to reset FIDO2 user verification permission flag: %m");
1532 static int update_home(int argc
, char *argv
[], void *userdata
) {
1533 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
1534 _cleanup_(user_record_unrefp
) UserRecord
*hr
= NULL
, *secret
= NULL
;
1535 _cleanup_free_
char *buffer
= NULL
;
1536 const char *username
;
1541 else if (!arg_identity
) {
1542 buffer
= getusername_malloc();
1550 r
= acquire_bus(&bus
);
1554 (void) polkit_agent_open_if_enabled(arg_transport
, arg_ask_password
);
1556 r
= acquire_updated_home_record(bus
, username
, &hr
);
1560 /* Add in all secrets we can acquire cheaply */
1561 r
= acquire_passed_secrets(username
, &secret
);
1565 r
= user_record_merge_secret(hr
, secret
);
1569 /* If we do multiple operations, let's output things more verbosely, since otherwise the repeated
1570 * authentication might be confusing. */
1572 if (arg_and_resize
|| arg_and_change_password
)
1573 log_info("Updating home directory.");
1576 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1577 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
1578 _cleanup_free_
char *formatted
= NULL
;
1580 r
= bus_message_new_method_call(bus
, &m
, bus_mgr
, "UpdateHome");
1582 return bus_log_create_error(r
);
1584 r
= json_variant_format(hr
->json
, 0, &formatted
);
1586 return log_error_errno(r
, "Failed to format user record: %m");
1588 (void) sd_bus_message_sensitive(m
);
1590 r
= sd_bus_message_append(m
, "s", formatted
);
1592 return bus_log_create_error(r
);
1594 r
= sd_bus_call(bus
, m
, HOME_SLOW_BUS_CALL_TIMEOUT_USEC
, &error
, NULL
);
1596 if (arg_and_change_password
&&
1597 sd_bus_error_has_name(&error
, BUS_ERROR_BAD_PASSWORD_AND_NO_TOKEN
))
1598 /* In the generic handler we'd ask for a password in this case, but when
1599 * changing passwords that's not sufficient, as we need to acquire all keys
1601 return log_error_errno(r
, "Security token not inserted, refusing.");
1603 r
= handle_generic_user_record_error(hr
->user_name
, hr
, &error
, r
, false);
1611 log_info("Resizing home.");
1613 (void) home_record_reset_human_interaction_permission(hr
);
1615 /* Also sync down disk size to underlying LUKS/fscrypt/quota */
1616 while (arg_and_resize
) {
1617 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1618 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
1620 r
= bus_message_new_method_call(bus
, &m
, bus_mgr
, "ResizeHome");
1622 return bus_log_create_error(r
);
1624 /* Specify UINT64_MAX as size, in which case the underlying disk size will just be synced */
1625 r
= sd_bus_message_append(m
, "st", hr
->user_name
, UINT64_MAX
);
1627 return bus_log_create_error(r
);
1629 r
= bus_message_append_secret(m
, hr
);
1631 return bus_log_create_error(r
);
1633 r
= sd_bus_call(bus
, m
, HOME_SLOW_BUS_CALL_TIMEOUT_USEC
, &error
, NULL
);
1635 if (arg_and_change_password
&&
1636 sd_bus_error_has_name(&error
, BUS_ERROR_BAD_PASSWORD_AND_NO_TOKEN
))
1637 return log_error_errno(r
, "Security token not inserted, refusing.");
1639 r
= handle_generic_user_record_error(hr
->user_name
, hr
, &error
, r
, false);
1646 if (arg_and_change_password
)
1647 log_info("Synchronizing passwords and encryption keys.");
1649 (void) home_record_reset_human_interaction_permission(hr
);
1651 /* Also sync down passwords to underlying LUKS/fscrypt */
1652 while (arg_and_change_password
) {
1653 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1654 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
1656 r
= bus_message_new_method_call(bus
, &m
, bus_mgr
, "ChangePasswordHome");
1658 return bus_log_create_error(r
);
1660 /* Specify an empty new secret, in which case the underlying LUKS/fscrypt password will just be synced */
1661 r
= sd_bus_message_append(m
, "ss", hr
->user_name
, "{}");
1663 return bus_log_create_error(r
);
1665 r
= bus_message_append_secret(m
, hr
);
1667 return bus_log_create_error(r
);
1669 r
= sd_bus_call(bus
, m
, HOME_SLOW_BUS_CALL_TIMEOUT_USEC
, &error
, NULL
);
1671 if (sd_bus_error_has_name(&error
, BUS_ERROR_BAD_PASSWORD_AND_NO_TOKEN
))
1672 return log_error_errno(r
, "Security token not inserted, refusing.");
1674 r
= handle_generic_user_record_error(hr
->user_name
, hr
, &error
, r
, false);
1684 static int passwd_home(int argc
, char *argv
[], void *userdata
) {
1685 _cleanup_(user_record_unrefp
) UserRecord
*old_secret
= NULL
, *new_secret
= NULL
;
1686 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
1687 _cleanup_free_
char *buffer
= NULL
;
1688 const char *username
;
1691 if (arg_pkcs11_token_uri
)
1692 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
1693 "To change the PKCS#11 security token use 'homectl update --pkcs11-token-uri=%s'.",
1694 special_glyph(SPECIAL_GLYPH_ELLIPSIS
));
1695 if (arg_fido2_device
)
1696 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
1697 "To change the FIDO2 security token use 'homectl update --fido2-device=%s'.",
1698 special_glyph(SPECIAL_GLYPH_ELLIPSIS
));
1699 if (identity_properties_specified())
1700 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "The 'passwd' verb does not permit changing other record properties at the same time.");
1705 buffer
= getusername_malloc();
1712 r
= acquire_bus(&bus
);
1716 (void) polkit_agent_open_if_enabled(arg_transport
, arg_ask_password
);
1718 r
= acquire_passed_secrets(username
, &old_secret
);
1722 new_secret
= user_record_new();
1726 r
= acquire_new_password(username
, new_secret
, /* suggest = */ true, NULL
);
1731 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1732 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
1734 r
= bus_message_new_method_call(bus
, &m
, bus_mgr
, "ChangePasswordHome");
1736 return bus_log_create_error(r
);
1738 r
= sd_bus_message_append(m
, "s", username
);
1740 return bus_log_create_error(r
);
1742 r
= bus_message_append_secret(m
, new_secret
);
1744 return bus_log_create_error(r
);
1746 r
= bus_message_append_secret(m
, old_secret
);
1748 return bus_log_create_error(r
);
1750 r
= sd_bus_call(bus
, m
, HOME_SLOW_BUS_CALL_TIMEOUT_USEC
, &error
, NULL
);
1752 if (sd_bus_error_has_name(&error
, BUS_ERROR_LOW_PASSWORD_QUALITY
)) {
1754 log_error_errno(r
, "%s", bus_error_message(&error
, r
));
1756 r
= acquire_new_password(username
, new_secret
, /* suggest = */ false, NULL
);
1758 } else if (sd_bus_error_has_name(&error
, BUS_ERROR_BAD_PASSWORD_AND_NO_TOKEN
))
1760 /* In the generic handler we'd ask for a password in this case, but when
1761 * changing passwords that's not sufficeint, as we need to acquire all keys
1763 return log_error_errno(r
, "Security token not inserted, refusing.");
1765 r
= handle_generic_user_record_error(username
, old_secret
, &error
, r
, true);
1775 static int parse_disk_size(const char *t
, uint64_t *ret
) {
1781 if (streq(t
, "min"))
1783 else if (streq(t
, "max"))
1784 *ret
= UINT64_MAX
-1; /* Largest size that isn't UINT64_MAX special marker */
1788 r
= parse_size(t
, 1024, &ds
);
1790 return log_error_errno(r
, "Failed to parse disk size parameter: %s", t
);
1792 if (ds
>= UINT64_MAX
) /* UINT64_MAX has special meaning for us ("dont change"), refuse */
1793 return log_error_errno(SYNTHETIC_ERRNO(ERANGE
), "Disk size out of range: %s", t
);
1801 static int resize_home(int argc
, char *argv
[], void *userdata
) {
1802 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
1803 _cleanup_(user_record_unrefp
) UserRecord
*secret
= NULL
;
1804 uint64_t ds
= UINT64_MAX
;
1807 r
= acquire_bus(&bus
);
1811 (void) polkit_agent_open_if_enabled(arg_transport
, arg_ask_password
);
1813 if (arg_disk_size_relative
!= UINT64_MAX
||
1814 (argc
> 2 && parse_permyriad(argv
[2]) >= 0))
1815 return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP
),
1816 "Relative disk size specification currently not supported when resizing.");
1819 r
= parse_disk_size(argv
[2], &ds
);
1824 if (arg_disk_size
!= UINT64_MAX
) {
1825 if (ds
!= UINT64_MAX
&& ds
!= arg_disk_size
)
1826 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Disk size specified twice and doesn't match, refusing.");
1831 r
= acquire_passed_secrets(argv
[1], &secret
);
1836 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1837 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
1839 r
= bus_message_new_method_call(bus
, &m
, bus_mgr
, "ResizeHome");
1841 return bus_log_create_error(r
);
1843 r
= sd_bus_message_append(m
, "st", argv
[1], ds
);
1845 return bus_log_create_error(r
);
1847 r
= bus_message_append_secret(m
, secret
);
1849 return bus_log_create_error(r
);
1851 r
= sd_bus_call(bus
, m
, HOME_SLOW_BUS_CALL_TIMEOUT_USEC
, &error
, NULL
);
1853 r
= handle_generic_user_record_error(argv
[1], secret
, &error
, r
, false);
1863 static int lock_home(int argc
, char *argv
[], void *userdata
) {
1864 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
1867 r
= acquire_bus(&bus
);
1871 STRV_FOREACH(i
, strv_skip(argv
, 1)) {
1872 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1873 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
1875 r
= bus_message_new_method_call(bus
, &m
, bus_mgr
, "LockHome");
1877 return bus_log_create_error(r
);
1879 r
= sd_bus_message_append(m
, "s", *i
);
1881 return bus_log_create_error(r
);
1883 r
= sd_bus_call(bus
, m
, HOME_SLOW_BUS_CALL_TIMEOUT_USEC
, &error
, NULL
);
1885 log_error_errno(r
, "Failed to lock home: %s", bus_error_message(&error
, r
));
1894 static int unlock_home(int argc
, char *argv
[], void *userdata
) {
1895 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
1898 r
= acquire_bus(&bus
);
1902 STRV_FOREACH(i
, strv_skip(argv
, 1)) {
1903 _cleanup_(user_record_unrefp
) UserRecord
*secret
= NULL
;
1905 r
= acquire_passed_secrets(*i
, &secret
);
1910 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1911 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
1913 r
= bus_message_new_method_call(bus
, &m
, bus_mgr
, "UnlockHome");
1915 return bus_log_create_error(r
);
1917 r
= sd_bus_message_append(m
, "s", *i
);
1919 return bus_log_create_error(r
);
1921 r
= bus_message_append_secret(m
, secret
);
1923 return bus_log_create_error(r
);
1925 r
= sd_bus_call(bus
, m
, HOME_SLOW_BUS_CALL_TIMEOUT_USEC
, &error
, NULL
);
1927 r
= handle_generic_user_record_error(argv
[1], secret
, &error
, r
, false);
1942 static int with_home(int argc
, char *argv
[], void *userdata
) {
1943 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1944 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
, *reply
= NULL
;
1945 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
1946 _cleanup_(user_record_unrefp
) UserRecord
*secret
= NULL
;
1947 _cleanup_close_
int acquired_fd
= -EBADF
;
1948 _cleanup_strv_free_
char **cmdline
= NULL
;
1953 r
= acquire_bus(&bus
);
1958 _cleanup_free_
char *shell
= NULL
;
1960 /* If no command is specified, spawn a shell */
1961 r
= get_shell(&shell
);
1963 return log_error_errno(r
, "Failed to acquire shell: %m");
1965 cmdline
= strv_new(shell
);
1967 cmdline
= strv_copy(argv
+ 2);
1971 r
= acquire_passed_secrets(argv
[1], &secret
);
1976 r
= bus_message_new_method_call(bus
, &m
, bus_mgr
, "AcquireHome");
1978 return bus_log_create_error(r
);
1980 r
= sd_bus_message_append(m
, "s", argv
[1]);
1982 return bus_log_create_error(r
);
1984 r
= bus_message_append_secret(m
, secret
);
1986 return bus_log_create_error(r
);
1988 r
= sd_bus_message_append(m
, "b", /* please_suspend = */ getenv_bool("SYSTEMD_PLEASE_SUSPEND_HOME") > 0);
1990 return bus_log_create_error(r
);
1992 r
= sd_bus_call(bus
, m
, HOME_SLOW_BUS_CALL_TIMEOUT_USEC
, &error
, &reply
);
1993 m
= sd_bus_message_unref(m
);
1995 r
= handle_generic_user_record_error(argv
[1], secret
, &error
, r
, false);
1999 sd_bus_error_free(&error
);
2003 r
= sd_bus_message_read(reply
, "h", &fd
);
2005 return bus_log_parse_error(r
);
2007 acquired_fd
= fcntl(fd
, F_DUPFD_CLOEXEC
, 3);
2008 if (acquired_fd
< 0)
2009 return log_error_errno(errno
, "Failed to duplicate acquired fd: %m");
2011 reply
= sd_bus_message_unref(reply
);
2016 r
= bus_call_method(bus
, bus_mgr
, "GetHomeByName", &error
, &reply
, "s", argv
[1]);
2018 return log_error_errno(r
, "Failed to inspect home: %s", bus_error_message(&error
, r
));
2020 r
= sd_bus_message_read(reply
, "usussso", NULL
, NULL
, NULL
, NULL
, &home
, NULL
, NULL
);
2022 return bus_log_parse_error(r
);
2024 r
= safe_fork("(with)", FORK_RESET_SIGNALS
|FORK_CLOSE_ALL_FDS
|FORK_DEATHSIG
|FORK_LOG
|FORK_RLIMIT_NOFILE_SAFE
|FORK_REOPEN_LOG
, &pid
);
2028 if (chdir(home
) < 0) {
2029 log_error_errno(errno
, "Failed to change to directory %s: %m", home
);
2033 execvp(cmdline
[0], cmdline
);
2034 log_error_errno(errno
, "Failed to execute %s: %m", cmdline
[0]);
2038 ret
= wait_for_terminate_and_check(cmdline
[0], pid
, WAIT_LOG_ABNORMAL
);
2040 /* Close the fd that pings the home now. */
2041 acquired_fd
= safe_close(acquired_fd
);
2043 r
= bus_message_new_method_call(bus
, &m
, bus_mgr
, "ReleaseHome");
2045 return bus_log_create_error(r
);
2047 r
= sd_bus_message_append(m
, "s", argv
[1]);
2049 return bus_log_create_error(r
);
2051 r
= sd_bus_call(bus
, m
, HOME_SLOW_BUS_CALL_TIMEOUT_USEC
, &error
, NULL
);
2053 if (sd_bus_error_has_name(&error
, BUS_ERROR_HOME_BUSY
))
2054 log_notice("Not deactivating home directory of %s, as it is still used.", argv
[1]);
2056 return log_error_errno(r
, "Failed to release user home: %s", bus_error_message(&error
, r
));
2062 static int lock_all_homes(int argc
, char *argv
[], void *userdata
) {
2063 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
2064 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
2065 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
2068 r
= acquire_bus(&bus
);
2072 r
= bus_message_new_method_call(bus
, &m
, bus_mgr
, "LockAllHomes");
2074 return bus_log_create_error(r
);
2076 r
= sd_bus_call(bus
, m
, HOME_SLOW_BUS_CALL_TIMEOUT_USEC
, &error
, NULL
);
2078 return log_error_errno(r
, "Failed to lock all homes: %s", bus_error_message(&error
, r
));
2083 static int deactivate_all_homes(int argc
, char *argv
[], void *userdata
) {
2084 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
2085 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
2086 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
2089 r
= acquire_bus(&bus
);
2093 r
= bus_message_new_method_call(bus
, &m
, bus_mgr
, "DeactivateAllHomes");
2095 return bus_log_create_error(r
);
2097 r
= sd_bus_call(bus
, m
, HOME_SLOW_BUS_CALL_TIMEOUT_USEC
, &error
, NULL
);
2099 return log_error_errno(r
, "Failed to deactivate all homes: %s", bus_error_message(&error
, r
));
2104 static int rebalance(int argc
, char *argv
[], void *userdata
) {
2105 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
2106 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
2107 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
2110 r
= acquire_bus(&bus
);
2114 r
= bus_message_new_method_call(bus
, &m
, bus_mgr
, "Rebalance");
2116 return bus_log_create_error(r
);
2118 r
= sd_bus_call(bus
, m
, HOME_SLOW_BUS_CALL_TIMEOUT_USEC
, &error
, NULL
);
2120 if (sd_bus_error_has_name(&error
, BUS_ERROR_REBALANCE_NOT_NEEDED
))
2121 log_info("No homes needed rebalancing.");
2123 return log_error_errno(r
, "Failed to rebalance: %s", bus_error_message(&error
, r
));
2125 log_info("Completed rebalancing.");
2130 static int drop_from_identity(const char *field
) {
2135 /* If we are called to update an identity record and drop some field, let's keep track of what to
2136 * remove from the old record */
2137 r
= strv_extend(&arg_identity_filter
, field
);
2141 /* Let's also drop the field if it was previously set to a new value on the same command line */
2142 r
= json_variant_filter(&arg_identity_extra
, STRV_MAKE(field
));
2144 return log_error_errno(r
, "Failed to filter JSON identity data: %m");
2146 r
= json_variant_filter(&arg_identity_extra_this_machine
, STRV_MAKE(field
));
2148 return log_error_errno(r
, "Failed to filter JSON identity data: %m");
2150 r
= json_variant_filter(&arg_identity_extra_privileged
, STRV_MAKE(field
));
2152 return log_error_errno(r
, "Failed to filter JSON identity data: %m");
2157 static int help(int argc
, char *argv
[], void *userdata
) {
2158 _cleanup_free_
char *link
= NULL
;
2161 pager_open(arg_pager_flags
);
2163 r
= terminal_urlify_man("homectl", "1", &link
);
2167 printf("%1$s [OPTIONS...] COMMAND ...\n\n"
2168 "%2$sCreate, manipulate or inspect home directories.%3$s\n"
2169 "\n%4$sCommands:%5$s\n"
2170 " list List home areas\n"
2171 " activate USER… Activate a home area\n"
2172 " deactivate USER… Deactivate a home area\n"
2173 " inspect USER… Inspect a home area\n"
2174 " authenticate USER… Authenticate a home area\n"
2175 " create USER Create a home area\n"
2176 " remove USER… Remove a home area\n"
2177 " update USER Update a home area\n"
2178 " passwd USER Change password of a home area\n"
2179 " resize USER SIZE Resize a home area\n"
2180 " lock USER… Temporarily lock an active home area\n"
2181 " unlock USER… Unlock a temporarily locked home area\n"
2182 " lock-all Lock all suitable home areas\n"
2183 " deactivate-all Deactivate all active home areas\n"
2184 " rebalance Rebalance free space between home areas\n"
2185 " with USER [COMMAND…] Run shell or command with access to a home area\n"
2186 "\n%4$sOptions:%5$s\n"
2187 " -h --help Show this help\n"
2188 " --version Show package version\n"
2189 " --no-pager Do not pipe output into a pager\n"
2190 " --no-legend Do not show the headers and footers\n"
2191 " --no-ask-password Do not ask for system passwords\n"
2192 " -H --host=[USER@]HOST Operate on remote host\n"
2193 " -M --machine=CONTAINER Operate on local container\n"
2194 " --identity=PATH Read JSON identity from file\n"
2195 " --json=FORMAT Output inspection data in JSON (takes one of\n"
2196 " pretty, short, off)\n"
2197 " -j Equivalent to --json=pretty (on TTY) or\n"
2198 " --json=short (otherwise)\n"
2199 " --export-format= Strip JSON inspection data (full, stripped,\n"
2201 " -E When specified once equals -j --export-format=\n"
2202 " stripped, when specified twice equals\n"
2203 " -j --export-format=minimal\n"
2204 "\n%4$sGeneral User Record Properties:%5$s\n"
2205 " -c --real-name=REALNAME Real name for user\n"
2206 " --realm=REALM Realm to create user in\n"
2207 " --email-address=EMAIL Email address for user\n"
2208 " --location=LOCATION Set location of user on earth\n"
2209 " --icon-name=NAME Icon name for user\n"
2210 " -d --home-dir=PATH Home directory\n"
2211 " -u --uid=UID Numeric UID for user\n"
2212 " -G --member-of=GROUP Add user to group\n"
2213 " --skel=PATH Skeleton directory to use\n"
2214 " --shell=PATH Shell for account\n"
2215 " --setenv=VARIABLE[=VALUE] Set an environment variable at log-in\n"
2216 " --timezone=TIMEZONE Set a time-zone\n"
2217 " --language=LOCALE Set preferred language\n"
2218 " --ssh-authorized-keys=KEYS\n"
2219 " Specify SSH public keys\n"
2220 " --pkcs11-token-uri=URI URI to PKCS#11 security token containing\n"
2221 " private key and matching X.509 certificate\n"
2222 " --fido2-device=PATH Path to FIDO2 hidraw device with hmac-secret\n"
2224 " --fido2-with-client-pin=BOOL\n"
2225 " Whether to require entering a PIN to unlock the\n"
2227 " --fido2-with-user-presence=BOOL\n"
2228 " Whether to require user presence to unlock the\n"
2230 " --fido2-with-user-verification=BOOL\n"
2231 " Whether to require user verification to unlock\n"
2233 " --recovery-key=BOOL Add a recovery key\n"
2234 "\n%4$sAccount Management User Record Properties:%5$s\n"
2235 " --locked=BOOL Set locked account state\n"
2236 " --not-before=TIMESTAMP Do not allow logins before\n"
2237 " --not-after=TIMESTAMP Do not allow logins after\n"
2238 " --rate-limit-interval=SECS\n"
2239 " Login rate-limit interval in seconds\n"
2240 " --rate-limit-burst=NUMBER\n"
2241 " Login rate-limit attempts per interval\n"
2242 "\n%4$sPassword Policy User Record Properties:%5$s\n"
2243 " --password-hint=HINT Set Password hint\n"
2244 " --enforce-password-policy=BOOL\n"
2245 " Control whether to enforce system's password\n"
2246 " policy for this user\n"
2247 " -P Same as --enforce-password-password=no\n"
2248 " --password-change-now=BOOL\n"
2249 " Require the password to be changed on next login\n"
2250 " --password-change-min=TIME\n"
2251 " Require minimum time between password changes\n"
2252 " --password-change-max=TIME\n"
2253 " Require maximum time between password changes\n"
2254 " --password-change-warn=TIME\n"
2255 " How much time to warn before password expiry\n"
2256 " --password-change-inactive=TIME\n"
2257 " How much time to block password after expiry\n"
2258 "\n%4$sResource Management User Record Properties:%5$s\n"
2259 " --disk-size=BYTES Size to assign the user on disk\n"
2260 " --access-mode=MODE User home directory access mode\n"
2261 " --umask=MODE Umask for user when logging in\n"
2262 " --nice=NICE Nice level for user\n"
2263 " --rlimit=LIMIT=VALUE[:VALUE]\n"
2264 " Set resource limits\n"
2265 " --tasks-max=MAX Set maximum number of per-user tasks\n"
2266 " --memory-high=BYTES Set high memory threshold in bytes\n"
2267 " --memory-max=BYTES Set maximum memory limit\n"
2268 " --cpu-weight=WEIGHT Set CPU weight\n"
2269 " --io-weight=WEIGHT Set IO weight\n"
2270 "\n%4$sStorage User Record Properties:%5$s\n"
2271 " --storage=STORAGE Storage type to use (luks, fscrypt, directory,\n"
2272 " subvolume, cifs)\n"
2273 " --image-path=PATH Path to image file/directory\n"
2274 " --drop-caches=BOOL Whether to automatically drop caches on logout\n"
2275 "\n%4$sLUKS Storage User Record Properties:%5$s\n"
2276 " --fs-type=TYPE File system type to use in case of luks\n"
2277 " storage (btrfs, ext4, xfs)\n"
2278 " --luks-discard=BOOL Whether to use 'discard' feature of file system\n"
2279 " when activated (mounted)\n"
2280 " --luks-offline-discard=BOOL\n"
2281 " Whether to trim file on logout\n"
2282 " --luks-cipher=CIPHER Cipher to use for LUKS encryption\n"
2283 " --luks-cipher-mode=MODE Cipher mode to use for LUKS encryption\n"
2284 " --luks-volume-key-size=BITS\n"
2285 " Volume key size to use for LUKS encryption\n"
2286 " --luks-pbkdf-type=TYPE Password-based Key Derivation Function to use\n"
2287 " --luks-pbkdf-hash-algorithm=ALGORITHM\n"
2288 " PBKDF hash algorithm to use\n"
2289 " --luks-pbkdf-time-cost=SECS\n"
2290 " Time cost for PBKDF in seconds\n"
2291 " --luks-pbkdf-memory-cost=BYTES\n"
2292 " Memory cost for PBKDF in bytes\n"
2293 " --luks-pbkdf-parallel-threads=NUMBER\n"
2294 " Number of parallel threads for PKBDF\n"
2295 " --luks-sector-size=BYTES\n"
2296 " Sector size for LUKS encryption in bytes\n"
2297 " --luks-extra-mount-options=OPTIONS\n"
2298 " LUKS extra mount options\n"
2299 " --auto-resize-mode=MODE Automatically grow/shrink home on login/logout\n"
2300 " --rebalance-weight=WEIGHT Weight while rebalancing\n"
2301 "\n%4$sMounting User Record Properties:%5$s\n"
2302 " --nosuid=BOOL Control the 'nosuid' flag of the home mount\n"
2303 " --nodev=BOOL Control the 'nodev' flag of the home mount\n"
2304 " --noexec=BOOL Control the 'noexec' flag of the home mount\n"
2305 "\n%4$sCIFS User Record Properties:%5$s\n"
2306 " --cifs-domain=DOMAIN CIFS (Windows) domain\n"
2307 " --cifs-user-name=USER CIFS (Windows) user name\n"
2308 " --cifs-service=SERVICE CIFS (Windows) service to mount as home area\n"
2309 " --cifs-extra-mount-options=OPTIONS\n"
2310 " CIFS (Windows) extra mount options\n"
2311 "\n%4$sLogin Behaviour User Record Properties:%5$s\n"
2312 " --stop-delay=SECS How long to leave user services running after\n"
2314 " --kill-processes=BOOL Whether to kill user processes when sessions\n"
2316 " --auto-login=BOOL Try to log this user in automatically\n"
2317 "\nSee the %6$s for details.\n",
2318 program_invocation_short_name
,
2328 static int parse_argv(int argc
, char *argv
[]) {
2331 ARG_VERSION
= 0x100,
2334 ARG_NO_ASK_PASSWORD
,
2344 ARG_LUKS_OFFLINE_DISCARD
,
2350 ARG_SSH_AUTHORIZED_KEYS
,
2359 ARG_LUKS_CIPHER_MODE
,
2360 ARG_LUKS_VOLUME_KEY_SIZE
,
2367 ARG_CIFS_EXTRA_MOUNT_OPTIONS
,
2373 ARG_LUKS_PBKDF_TYPE
,
2374 ARG_LUKS_PBKDF_HASH_ALGORITHM
,
2375 ARG_LUKS_PBKDF_FORCE_ITERATIONS
,
2376 ARG_LUKS_PBKDF_TIME_COST
,
2377 ARG_LUKS_PBKDF_MEMORY_COST
,
2378 ARG_LUKS_PBKDF_PARALLEL_THREADS
,
2379 ARG_LUKS_SECTOR_SIZE
,
2380 ARG_RATE_LIMIT_INTERVAL
,
2381 ARG_RATE_LIMIT_BURST
,
2384 ARG_ENFORCE_PASSWORD_POLICY
,
2385 ARG_PASSWORD_CHANGE_NOW
,
2386 ARG_PASSWORD_CHANGE_MIN
,
2387 ARG_PASSWORD_CHANGE_MAX
,
2388 ARG_PASSWORD_CHANGE_WARN
,
2389 ARG_PASSWORD_CHANGE_INACTIVE
,
2392 ARG_PKCS11_TOKEN_URI
,
2399 ARG_AND_CHANGE_PASSWORD
,
2401 ARG_LUKS_EXTRA_MOUNT_OPTIONS
,
2402 ARG_AUTO_RESIZE_MODE
,
2403 ARG_REBALANCE_WEIGHT
,
2407 static const struct option options
[] = {
2408 { "help", no_argument
, NULL
, 'h' },
2409 { "version", no_argument
, NULL
, ARG_VERSION
},
2410 { "no-pager", no_argument
, NULL
, ARG_NO_PAGER
},
2411 { "no-legend", no_argument
, NULL
, ARG_NO_LEGEND
},
2412 { "no-ask-password", no_argument
, NULL
, ARG_NO_ASK_PASSWORD
},
2413 { "host", required_argument
, NULL
, 'H' },
2414 { "machine", required_argument
, NULL
, 'M' },
2415 { "identity", required_argument
, NULL
, 'I' },
2416 { "real-name", required_argument
, NULL
, 'c' },
2417 { "comment", required_argument
, NULL
, 'c' }, /* Compat alias to keep thing in sync with useradd(8) */
2418 { "realm", required_argument
, NULL
, ARG_REALM
},
2419 { "email-address", required_argument
, NULL
, ARG_EMAIL_ADDRESS
},
2420 { "location", required_argument
, NULL
, ARG_LOCATION
},
2421 { "password-hint", required_argument
, NULL
, ARG_PASSWORD_HINT
},
2422 { "icon-name", required_argument
, NULL
, ARG_ICON_NAME
},
2423 { "home-dir", required_argument
, NULL
, 'd' }, /* Compatible with useradd(8) */
2424 { "uid", required_argument
, NULL
, 'u' }, /* Compatible with useradd(8) */
2425 { "member-of", required_argument
, NULL
, 'G' },
2426 { "groups", required_argument
, NULL
, 'G' }, /* Compat alias to keep thing in sync with useradd(8) */
2427 { "skel", required_argument
, NULL
, 'k' }, /* Compatible with useradd(8) */
2428 { "shell", required_argument
, NULL
, 's' }, /* Compatible with useradd(8) */
2429 { "setenv", required_argument
, NULL
, ARG_SETENV
},
2430 { "timezone", required_argument
, NULL
, ARG_TIMEZONE
},
2431 { "language", required_argument
, NULL
, ARG_LANGUAGE
},
2432 { "locked", required_argument
, NULL
, ARG_LOCKED
},
2433 { "not-before", required_argument
, NULL
, ARG_NOT_BEFORE
},
2434 { "not-after", required_argument
, NULL
, ARG_NOT_AFTER
},
2435 { "expiredate", required_argument
, NULL
, 'e' }, /* Compat alias to keep thing in sync with useradd(8) */
2436 { "ssh-authorized-keys", required_argument
, NULL
, ARG_SSH_AUTHORIZED_KEYS
},
2437 { "disk-size", required_argument
, NULL
, ARG_DISK_SIZE
},
2438 { "access-mode", required_argument
, NULL
, ARG_ACCESS_MODE
},
2439 { "umask", required_argument
, NULL
, ARG_UMASK
},
2440 { "nice", required_argument
, NULL
, ARG_NICE
},
2441 { "rlimit", required_argument
, NULL
, ARG_RLIMIT
},
2442 { "tasks-max", required_argument
, NULL
, ARG_TASKS_MAX
},
2443 { "memory-high", required_argument
, NULL
, ARG_MEMORY_HIGH
},
2444 { "memory-max", required_argument
, NULL
, ARG_MEMORY_MAX
},
2445 { "cpu-weight", required_argument
, NULL
, ARG_CPU_WEIGHT
},
2446 { "io-weight", required_argument
, NULL
, ARG_IO_WEIGHT
},
2447 { "storage", required_argument
, NULL
, ARG_STORAGE
},
2448 { "image-path", required_argument
, NULL
, ARG_IMAGE_PATH
},
2449 { "fs-type", required_argument
, NULL
, ARG_FS_TYPE
},
2450 { "luks-discard", required_argument
, NULL
, ARG_LUKS_DISCARD
},
2451 { "luks-offline-discard", required_argument
, NULL
, ARG_LUKS_OFFLINE_DISCARD
},
2452 { "luks-cipher", required_argument
, NULL
, ARG_LUKS_CIPHER
},
2453 { "luks-cipher-mode", required_argument
, NULL
, ARG_LUKS_CIPHER_MODE
},
2454 { "luks-volume-key-size", required_argument
, NULL
, ARG_LUKS_VOLUME_KEY_SIZE
},
2455 { "luks-pbkdf-type", required_argument
, NULL
, ARG_LUKS_PBKDF_TYPE
},
2456 { "luks-pbkdf-hash-algorithm", required_argument
, NULL
, ARG_LUKS_PBKDF_HASH_ALGORITHM
},
2457 { "luks-pbkdf-force-iterations", required_argument
, NULL
, ARG_LUKS_PBKDF_FORCE_ITERATIONS
},
2458 { "luks-pbkdf-time-cost", required_argument
, NULL
, ARG_LUKS_PBKDF_TIME_COST
},
2459 { "luks-pbkdf-memory-cost", required_argument
, NULL
, ARG_LUKS_PBKDF_MEMORY_COST
},
2460 { "luks-pbkdf-parallel-threads", required_argument
, NULL
, ARG_LUKS_PBKDF_PARALLEL_THREADS
},
2461 { "luks-sector-size", required_argument
, NULL
, ARG_LUKS_SECTOR_SIZE
},
2462 { "nosuid", required_argument
, NULL
, ARG_NOSUID
},
2463 { "nodev", required_argument
, NULL
, ARG_NODEV
},
2464 { "noexec", required_argument
, NULL
, ARG_NOEXEC
},
2465 { "cifs-user-name", required_argument
, NULL
, ARG_CIFS_USER_NAME
},
2466 { "cifs-domain", required_argument
, NULL
, ARG_CIFS_DOMAIN
},
2467 { "cifs-service", required_argument
, NULL
, ARG_CIFS_SERVICE
},
2468 { "cifs-extra-mount-options", required_argument
, NULL
, ARG_CIFS_EXTRA_MOUNT_OPTIONS
},
2469 { "rate-limit-interval", required_argument
, NULL
, ARG_RATE_LIMIT_INTERVAL
},
2470 { "rate-limit-burst", required_argument
, NULL
, ARG_RATE_LIMIT_BURST
},
2471 { "stop-delay", required_argument
, NULL
, ARG_STOP_DELAY
},
2472 { "kill-processes", required_argument
, NULL
, ARG_KILL_PROCESSES
},
2473 { "enforce-password-policy", required_argument
, NULL
, ARG_ENFORCE_PASSWORD_POLICY
},
2474 { "password-change-now", required_argument
, NULL
, ARG_PASSWORD_CHANGE_NOW
},
2475 { "password-change-min", required_argument
, NULL
, ARG_PASSWORD_CHANGE_MIN
},
2476 { "password-change-max", required_argument
, NULL
, ARG_PASSWORD_CHANGE_MAX
},
2477 { "password-change-warn", required_argument
, NULL
, ARG_PASSWORD_CHANGE_WARN
},
2478 { "password-change-inactive", required_argument
, NULL
, ARG_PASSWORD_CHANGE_INACTIVE
},
2479 { "auto-login", required_argument
, NULL
, ARG_AUTO_LOGIN
},
2480 { "json", required_argument
, NULL
, ARG_JSON
},
2481 { "export-format", required_argument
, NULL
, ARG_EXPORT_FORMAT
},
2482 { "pkcs11-token-uri", required_argument
, NULL
, ARG_PKCS11_TOKEN_URI
},
2483 { "fido2-credential-algorithm", required_argument
, NULL
, ARG_FIDO2_CRED_ALG
},
2484 { "fido2-device", required_argument
, NULL
, ARG_FIDO2_DEVICE
},
2485 { "fido2-with-client-pin", required_argument
, NULL
, ARG_FIDO2_WITH_PIN
},
2486 { "fido2-with-user-presence", required_argument
, NULL
, ARG_FIDO2_WITH_UP
},
2487 { "fido2-with-user-verification",required_argument
, NULL
, ARG_FIDO2_WITH_UV
},
2488 { "recovery-key", required_argument
, NULL
, ARG_RECOVERY_KEY
},
2489 { "and-resize", required_argument
, NULL
, ARG_AND_RESIZE
},
2490 { "and-change-password", required_argument
, NULL
, ARG_AND_CHANGE_PASSWORD
},
2491 { "drop-caches", required_argument
, NULL
, ARG_DROP_CACHES
},
2492 { "luks-extra-mount-options", required_argument
, NULL
, ARG_LUKS_EXTRA_MOUNT_OPTIONS
},
2493 { "auto-resize-mode", required_argument
, NULL
, ARG_AUTO_RESIZE_MODE
},
2494 { "rebalance-weight", required_argument
, NULL
, ARG_REBALANCE_WEIGHT
},
2506 c
= getopt_long(argc
, argv
, "hH:M:I:c:d:u:k:s:e:G:jPE", options
, NULL
);
2513 return help(0, NULL
, NULL
);
2519 arg_pager_flags
|= PAGER_DISABLE
;
2526 case ARG_NO_ASK_PASSWORD
:
2527 arg_ask_password
= false;
2531 arg_transport
= BUS_TRANSPORT_REMOTE
;
2536 arg_transport
= BUS_TRANSPORT_MACHINE
;
2541 arg_identity
= optarg
;
2545 if (isempty(optarg
)) {
2546 r
= drop_from_identity("realName");
2553 if (!valid_gecos(optarg
))
2554 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Real name '%s' not a valid GECOS field.", optarg
);
2556 r
= json_variant_set_field_string(&arg_identity_extra
, "realName", optarg
);
2558 return log_error_errno(r
, "Failed to set realName field: %m");
2563 _cleanup_free_
char *hd
= NULL
;
2565 if (isempty(optarg
)) {
2566 r
= drop_from_identity("homeDirectory");
2573 r
= parse_path_argument(optarg
, false, &hd
);
2577 if (!valid_home(hd
))
2578 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Home directory '%s' not valid.", hd
);
2580 r
= json_variant_set_field_string(&arg_identity_extra
, "homeDirectory", hd
);
2582 return log_error_errno(r
, "Failed to set homeDirectory field: %m");
2588 if (isempty(optarg
)) {
2589 r
= drop_from_identity("realm");
2596 r
= dns_name_is_valid(optarg
);
2598 return log_error_errno(r
, "Failed to determine whether realm '%s' is a valid DNS domain: %m", optarg
);
2600 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Realm '%s' is not a valid DNS domain: %m", optarg
);
2602 r
= json_variant_set_field_string(&arg_identity_extra
, "realm", optarg
);
2604 return log_error_errno(r
, "Failed to set realm field: %m");
2607 case ARG_EMAIL_ADDRESS
:
2610 case ARG_CIFS_USER_NAME
:
2611 case ARG_CIFS_DOMAIN
:
2612 case ARG_CIFS_EXTRA_MOUNT_OPTIONS
:
2613 case ARG_LUKS_EXTRA_MOUNT_OPTIONS
: {
2616 c
== ARG_EMAIL_ADDRESS
? "emailAddress" :
2617 c
== ARG_LOCATION
? "location" :
2618 c
== ARG_ICON_NAME
? "iconName" :
2619 c
== ARG_CIFS_USER_NAME
? "cifsUserName" :
2620 c
== ARG_CIFS_DOMAIN
? "cifsDomain" :
2621 c
== ARG_CIFS_EXTRA_MOUNT_OPTIONS
? "cifsExtraMountOptions" :
2622 c
== ARG_LUKS_EXTRA_MOUNT_OPTIONS
? "luksExtraMountOptions" :
2627 if (isempty(optarg
)) {
2628 r
= drop_from_identity(field
);
2635 r
= json_variant_set_field_string(&arg_identity_extra
, field
, optarg
);
2637 return log_error_errno(r
, "Failed to set %s field: %m", field
);
2642 case ARG_CIFS_SERVICE
:
2643 if (isempty(optarg
)) {
2644 r
= drop_from_identity("cifsService");
2651 r
= parse_cifs_service(optarg
, NULL
, NULL
, NULL
);
2653 return log_error_errno(r
, "Failed to validate CIFS service name: %s", optarg
);
2655 r
= json_variant_set_field_string(&arg_identity_extra
, "cifsService", optarg
);
2657 return log_error_errno(r
, "Failed to set cifsService field: %m");
2661 case ARG_PASSWORD_HINT
:
2662 if (isempty(optarg
)) {
2663 r
= drop_from_identity("passwordHint");
2670 r
= json_variant_set_field_string(&arg_identity_extra_privileged
, "passwordHint", optarg
);
2672 return log_error_errno(r
, "Failed to set passwordHint field: %m");
2674 string_erase(optarg
);
2680 if (isempty(optarg
)) {
2681 r
= drop_from_identity("niceLevel");
2687 r
= parse_nice(optarg
, &nc
);
2689 return log_error_errno(r
, "Failed to parse nice level: %s", optarg
);
2691 r
= json_variant_set_field_integer(&arg_identity_extra
, "niceLevel", nc
);
2693 return log_error_errno(r
, "Failed to set niceLevel field: %m");
2699 _cleanup_(json_variant_unrefp
) JsonVariant
*v
= NULL
, *jcur
= NULL
, *jmax
= NULL
;
2700 _cleanup_free_
char *field
= NULL
, *t
= NULL
;
2705 if (isempty(optarg
)) {
2706 /* Remove all resource limits */
2708 r
= drop_from_identity("resourceLimits");
2712 arg_identity_filter_rlimits
= strv_free(arg_identity_filter_rlimits
);
2713 arg_identity_extra_rlimits
= json_variant_unref(arg_identity_extra_rlimits
);
2717 eq
= strchr(optarg
, '=');
2719 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Can't parse resource limit assignment: %s", optarg
);
2721 field
= strndup(optarg
, eq
- optarg
);
2725 l
= rlimit_from_string_harder(field
);
2727 return log_error_errno(l
, "Unknown resource limit type: %s", field
);
2729 if (isempty(eq
+ 1)) {
2730 /* Remove only the specific rlimit */
2732 r
= strv_extend(&arg_identity_filter_rlimits
, rlimit_to_string(l
));
2736 r
= json_variant_filter(&arg_identity_extra_rlimits
, STRV_MAKE(field
));
2738 return log_error_errno(r
, "Failed to filter JSON identity data: %m");
2743 r
= rlimit_parse(l
, eq
+ 1, &rl
);
2745 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Failed to parse resource limit value: %s", eq
+ 1);
2747 r
= rl
.rlim_cur
== RLIM_INFINITY
? json_variant_new_null(&jcur
) : json_variant_new_unsigned(&jcur
, rl
.rlim_cur
);
2749 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Failed to allocate current integer: %m");
2751 r
= rl
.rlim_max
== RLIM_INFINITY
? json_variant_new_null(&jmax
) : json_variant_new_unsigned(&jmax
, rl
.rlim_max
);
2753 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Failed to allocate maximum integer: %m");
2757 JSON_BUILD_PAIR("cur", JSON_BUILD_VARIANT(jcur
)),
2758 JSON_BUILD_PAIR("max", JSON_BUILD_VARIANT(jmax
))));
2760 return log_error_errno(r
, "Failed to build resource limit: %m");
2762 t
= strjoin("RLIMIT_", rlimit_to_string(l
));
2766 r
= json_variant_set_field(&arg_identity_extra_rlimits
, t
, v
);
2768 return log_error_errno(r
, "Failed to set %s field: %m", rlimit_to_string(l
));
2776 if (isempty(optarg
)) {
2777 r
= drop_from_identity("uid");
2784 r
= parse_uid(optarg
, &uid
);
2786 return log_error_errno(r
, "Failed to parse UID '%s'.", optarg
);
2788 if (uid_is_system(uid
))
2789 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "UID " UID_FMT
" is in system range, refusing.", uid
);
2790 if (uid_is_dynamic(uid
))
2791 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "UID " UID_FMT
" is in dynamic range, refusing.", uid
);
2792 if (uid
== UID_NOBODY
)
2793 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "UID " UID_FMT
" is nobody UID, refusing.", uid
);
2795 r
= json_variant_set_field_unsigned(&arg_identity_extra
, "uid", uid
);
2797 return log_error_errno(r
, "Failed to set realm field: %m");
2803 case ARG_IMAGE_PATH
: {
2804 const char *field
= c
== 'k' ? "skeletonDirectory" : "imagePath";
2805 _cleanup_free_
char *v
= NULL
;
2807 if (isempty(optarg
)) {
2808 r
= drop_from_identity(field
);
2815 r
= parse_path_argument(optarg
, false, &v
);
2819 r
= json_variant_set_field_string(&arg_identity_extra_this_machine
, field
, v
);
2821 return log_error_errno(r
, "Failed to set %s field: %m", v
);
2827 if (isempty(optarg
)) {
2828 r
= drop_from_identity("shell");
2835 if (!valid_shell(optarg
))
2836 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Shell '%s' not valid.", optarg
);
2838 r
= json_variant_set_field_string(&arg_identity_extra
, "shell", optarg
);
2840 return log_error_errno(r
, "Failed to set shell field: %m");
2845 _cleanup_free_
char **l
= NULL
;
2846 _cleanup_(json_variant_unrefp
) JsonVariant
*ne
= NULL
;
2849 if (isempty(optarg
)) {
2850 r
= drop_from_identity("environment");
2857 e
= json_variant_by_key(arg_identity_extra
, "environment");
2859 r
= json_variant_strv(e
, &l
);
2861 return log_error_errno(r
, "Failed to parse JSON environment field: %m");
2864 r
= strv_env_replace_strdup_passthrough(&l
, optarg
);
2866 return log_error_errno(r
, "Cannot assign environment variable %s: %m", optarg
);
2870 r
= json_variant_new_array_strv(&ne
, l
);
2872 return log_error_errno(r
, "Failed to allocate environment list JSON: %m");
2874 r
= json_variant_set_field(&arg_identity_extra
, "environment", ne
);
2876 return log_error_errno(r
, "Failed to set environment list: %m");
2883 if (isempty(optarg
)) {
2884 r
= drop_from_identity("timeZone");
2891 if (!timezone_is_valid(optarg
, LOG_DEBUG
))
2892 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Timezone '%s' is not valid.", optarg
);
2894 r
= json_variant_set_field_string(&arg_identity_extra
, "timeZone", optarg
);
2896 return log_error_errno(r
, "Failed to set timezone field: %m");
2901 if (isempty(optarg
)) {
2902 r
= drop_from_identity("language");
2909 if (!locale_is_valid(optarg
))
2910 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Locale '%s' is not valid.", optarg
);
2912 if (locale_is_installed(optarg
) <= 0)
2913 log_warning("Locale '%s' is not installed, accepting anyway.", optarg
);
2915 r
= json_variant_set_field_string(&arg_identity_extra
, "preferredLanguage", optarg
);
2917 return log_error_errno(r
, "Failed to set preferredLanguage field: %m");
2925 case ARG_KILL_PROCESSES
:
2926 case ARG_ENFORCE_PASSWORD_POLICY
:
2927 case ARG_AUTO_LOGIN
:
2928 case ARG_PASSWORD_CHANGE_NOW
: {
2930 c
== ARG_LOCKED
? "locked" :
2931 c
== ARG_NOSUID
? "mountNoSuid" :
2932 c
== ARG_NODEV
? "mountNoDevices" :
2933 c
== ARG_NOEXEC
? "mountNoExecute" :
2934 c
== ARG_KILL_PROCESSES
? "killProcesses" :
2935 c
== ARG_ENFORCE_PASSWORD_POLICY
? "enforcePasswordPolicy" :
2936 c
== ARG_AUTO_LOGIN
? "autoLogin" :
2937 c
== ARG_PASSWORD_CHANGE_NOW
? "passwordChangeNow" :
2942 if (isempty(optarg
)) {
2943 r
= drop_from_identity(field
);
2950 r
= parse_boolean(optarg
);
2952 return log_error_errno(r
, "Failed to parse %s boolean: %m", field
);
2954 r
= json_variant_set_field_boolean(&arg_identity_extra
, field
, r
> 0);
2956 return log_error_errno(r
, "Failed to set %s field: %m", field
);
2962 r
= json_variant_set_field_boolean(&arg_identity_extra
, "enforcePasswordPolicy", false);
2964 return log_error_errno(r
, "Failed to set enforcePasswordPolicy field: %m");
2969 if (isempty(optarg
)) {
2970 FOREACH_STRING(prop
, "diskSize", "diskSizeRelative", "rebalanceWeight") {
2971 r
= drop_from_identity(prop
);
2976 arg_disk_size
= arg_disk_size_relative
= UINT64_MAX
;
2980 r
= parse_permyriad(optarg
);
2982 r
= parse_disk_size(optarg
, &arg_disk_size
);
2986 r
= drop_from_identity("diskSizeRelative");
2990 r
= json_variant_set_field_unsigned(&arg_identity_extra_this_machine
, "diskSize", arg_disk_size
);
2992 return log_error_errno(r
, "Failed to set diskSize field: %m");
2994 arg_disk_size_relative
= UINT64_MAX
;
2996 /* Normalize to UINT32_MAX == 100% */
2997 arg_disk_size_relative
= UINT32_SCALE_FROM_PERMYRIAD(r
);
2999 r
= drop_from_identity("diskSize");
3003 r
= json_variant_set_field_unsigned(&arg_identity_extra_this_machine
, "diskSizeRelative", arg_disk_size_relative
);
3005 return log_error_errno(r
, "Failed to set diskSizeRelative field: %m");
3007 arg_disk_size
= UINT64_MAX
;
3010 /* Automatically turn off the rebalance logic if user configured a size explicitly */
3011 r
= json_variant_set_field_unsigned(&arg_identity_extra_this_machine
, "rebalanceWeight", REBALANCE_WEIGHT_OFF
);
3013 return log_error_errno(r
, "Failed to set rebalanceWeight field: %m");
3017 case ARG_ACCESS_MODE
: {
3020 if (isempty(optarg
)) {
3021 r
= drop_from_identity("accessMode");
3028 r
= parse_mode(optarg
, &mode
);
3030 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Access mode '%s' not valid.", optarg
);
3032 r
= json_variant_set_field_unsigned(&arg_identity_extra
, "accessMode", mode
);
3034 return log_error_errno(r
, "Failed to set access mode field: %m");
3039 case ARG_LUKS_DISCARD
:
3040 if (isempty(optarg
)) {
3041 r
= drop_from_identity("luksDiscard");
3048 r
= parse_boolean(optarg
);
3050 return log_error_errno(r
, "Failed to parse --luks-discard= parameter: %s", optarg
);
3052 r
= json_variant_set_field_boolean(&arg_identity_extra
, "luksDiscard", r
);
3054 return log_error_errno(r
, "Failed to set discard field: %m");
3058 case ARG_LUKS_OFFLINE_DISCARD
:
3059 if (isempty(optarg
)) {
3060 r
= drop_from_identity("luksOfflineDiscard");
3067 r
= parse_boolean(optarg
);
3069 return log_error_errno(r
, "Failed to parse --luks-offline-discard= parameter: %s", optarg
);
3071 r
= json_variant_set_field_boolean(&arg_identity_extra
, "luksOfflineDiscard", r
);
3073 return log_error_errno(r
, "Failed to set offline discard field: %m");
3077 case ARG_LUKS_VOLUME_KEY_SIZE
:
3078 case ARG_LUKS_PBKDF_FORCE_ITERATIONS
:
3079 case ARG_LUKS_PBKDF_PARALLEL_THREADS
:
3080 case ARG_RATE_LIMIT_BURST
: {
3082 c
== ARG_LUKS_VOLUME_KEY_SIZE
? "luksVolumeKeySize" :
3083 c
== ARG_LUKS_PBKDF_FORCE_ITERATIONS
? "luksPbkdfForceIterations" :
3084 c
== ARG_LUKS_PBKDF_PARALLEL_THREADS
? "luksPbkdfParallelThreads" :
3085 c
== ARG_RATE_LIMIT_BURST
? "rateLimitBurst" : NULL
;
3090 if (isempty(optarg
)) {
3091 r
= drop_from_identity(field
);
3096 r
= safe_atou(optarg
, &n
);
3098 return log_error_errno(r
, "Failed to parse %s parameter: %s", field
, optarg
);
3100 r
= json_variant_set_field_unsigned(&arg_identity_extra
, field
, n
);
3102 return log_error_errno(r
, "Failed to set %s field: %m", field
);
3107 case ARG_LUKS_SECTOR_SIZE
: {
3110 if (isempty(optarg
)) {
3111 r
= drop_from_identity("luksSectorSize");
3118 r
= parse_sector_size(optarg
, &ss
);
3122 r
= json_variant_set_field_unsigned(&arg_identity_extra
, "luksSectorSize", ss
);
3124 return log_error_errno(r
, "Failed to set sector size field: %m");
3132 if (isempty(optarg
)) {
3133 r
= drop_from_identity("umask");
3140 r
= parse_mode(optarg
, &m
);
3142 return log_error_errno(r
, "Failed to parse umask: %m");
3144 r
= json_variant_set_field_integer(&arg_identity_extra
, "umask", m
);
3146 return log_error_errno(r
, "Failed to set umask field: %m");
3151 case ARG_SSH_AUTHORIZED_KEYS
: {
3152 _cleanup_(json_variant_unrefp
) JsonVariant
*v
= NULL
;
3153 _cleanup_(strv_freep
) char **l
= NULL
, **add
= NULL
;
3155 if (isempty(optarg
)) {
3156 r
= drop_from_identity("sshAuthorizedKeys");
3163 if (optarg
[0] == '@') {
3164 _cleanup_fclose_
FILE *f
= NULL
;
3166 /* If prefixed with '@' read from a file */
3168 f
= fopen(optarg
+1, "re");
3170 return log_error_errno(errno
, "Failed to open '%s': %m", optarg
+1);
3173 _cleanup_free_
char *line
= NULL
;
3175 r
= read_line(f
, LONG_LINE_MAX
, &line
);
3177 return log_error_errno(r
, "Failed to read from '%s': %m", optarg
+1);
3187 r
= strv_consume(&add
, TAKE_PTR(line
));
3192 /* Otherwise, assume it's a literal key. Let's do some superficial checks
3193 * before accept it though. */
3195 if (string_has_cc(optarg
, NULL
))
3196 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Authorized key contains control characters, refusing.");
3197 if (optarg
[0] == '#')
3198 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Specified key is a comment?");
3200 add
= strv_new(optarg
);
3205 v
= json_variant_ref(json_variant_by_key(arg_identity_extra_privileged
, "sshAuthorizedKeys"));
3207 r
= json_variant_strv(v
, &l
);
3209 return log_error_errno(r
, "Failed to parse SSH authorized keys list: %m");
3212 r
= strv_extend_strv(&l
, add
, true);
3216 v
= json_variant_unref(v
);
3218 r
= json_variant_new_array_strv(&v
, l
);
3222 r
= json_variant_set_field(&arg_identity_extra_privileged
, "sshAuthorizedKeys", v
);
3224 return log_error_errno(r
, "Failed to set authorized keys: %m");
3229 case ARG_NOT_BEFORE
:
3235 field
= c
== ARG_NOT_BEFORE
? "notBeforeUSec" :
3236 IN_SET(c
, ARG_NOT_AFTER
, 'e') ? "notAfterUSec" : NULL
;
3240 if (isempty(optarg
)) {
3241 r
= drop_from_identity(field
);
3248 /* Note the minor discrepancy regarding -e parsing here: we support that for compat
3249 * reasons, and in the original useradd(8) implementation it accepts dates in the
3250 * format YYYY-MM-DD. Coincidentally, we accept dates formatted like that too, but
3251 * with greater precision. */
3252 r
= parse_timestamp(optarg
, &n
);
3254 return log_error_errno(r
, "Failed to parse %s parameter: %m", field
);
3256 r
= json_variant_set_field_unsigned(&arg_identity_extra
, field
, n
);
3258 return log_error_errno(r
, "Failed to set %s field: %m", field
);
3262 case ARG_PASSWORD_CHANGE_MIN
:
3263 case ARG_PASSWORD_CHANGE_MAX
:
3264 case ARG_PASSWORD_CHANGE_WARN
:
3265 case ARG_PASSWORD_CHANGE_INACTIVE
: {
3269 field
= c
== ARG_PASSWORD_CHANGE_MIN
? "passwordChangeMinUSec" :
3270 c
== ARG_PASSWORD_CHANGE_MAX
? "passwordChangeMaxUSec" :
3271 c
== ARG_PASSWORD_CHANGE_WARN
? "passwordChangeWarnUSec" :
3272 c
== ARG_PASSWORD_CHANGE_INACTIVE
? "passwordChangeInactiveUSec" :
3277 if (isempty(optarg
)) {
3278 r
= drop_from_identity(field
);
3285 r
= parse_sec(optarg
, &n
);
3287 return log_error_errno(r
, "Failed to parse %s parameter: %m", field
);
3289 r
= json_variant_set_field_unsigned(&arg_identity_extra
, field
, n
);
3291 return log_error_errno(r
, "Failed to set %s field: %m", field
);
3297 case ARG_LUKS_CIPHER
:
3298 case ARG_LUKS_CIPHER_MODE
:
3299 case ARG_LUKS_PBKDF_TYPE
:
3300 case ARG_LUKS_PBKDF_HASH_ALGORITHM
: {
3303 c
== ARG_STORAGE
? "storage" :
3304 c
== ARG_FS_TYPE
? "fileSystemType" :
3305 c
== ARG_LUKS_CIPHER
? "luksCipher" :
3306 c
== ARG_LUKS_CIPHER_MODE
? "luksCipherMode" :
3307 c
== ARG_LUKS_PBKDF_TYPE
? "luksPbkdfType" :
3308 c
== ARG_LUKS_PBKDF_HASH_ALGORITHM
? "luksPbkdfHashAlgorithm" : NULL
;
3312 if (isempty(optarg
)) {
3313 r
= drop_from_identity(field
);
3320 if (!string_is_safe(optarg
))
3321 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Parameter for %s field not valid: %s", field
, optarg
);
3323 r
= json_variant_set_field_string(
3324 IN_SET(c
, ARG_STORAGE
, ARG_FS_TYPE
) ?
3325 &arg_identity_extra_this_machine
:
3326 &arg_identity_extra
, field
, optarg
);
3328 return log_error_errno(r
, "Failed to set %s field: %m", field
);
3333 case ARG_LUKS_PBKDF_TIME_COST
:
3334 case ARG_RATE_LIMIT_INTERVAL
:
3335 case ARG_STOP_DELAY
: {
3337 c
== ARG_LUKS_PBKDF_TIME_COST
? "luksPbkdfTimeCostUSec" :
3338 c
== ARG_RATE_LIMIT_INTERVAL
? "rateLimitIntervalUSec" :
3339 c
== ARG_STOP_DELAY
? "stopDelayUSec" :
3345 if (isempty(optarg
)) {
3346 r
= drop_from_identity(field
);
3353 r
= parse_sec(optarg
, &t
);
3355 return log_error_errno(r
, "Failed to parse %s field: %s", field
, optarg
);
3357 r
= json_variant_set_field_unsigned(&arg_identity_extra
, field
, t
);
3359 return log_error_errno(r
, "Failed to set %s field: %m", field
);
3365 const char *p
= optarg
;
3368 r
= drop_from_identity("memberOf");
3376 _cleanup_(json_variant_unrefp
) JsonVariant
*mo
= NULL
;
3377 _cleanup_strv_free_
char **list
= NULL
;
3378 _cleanup_free_
char *word
= NULL
;
3380 r
= extract_first_word(&p
, &word
, ",", 0);
3382 return log_error_errno(r
, "Failed to parse group list: %m");
3386 if (!valid_user_group_name(word
, 0))
3387 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Invalid group name %s.", word
);
3389 mo
= json_variant_ref(json_variant_by_key(arg_identity_extra
, "memberOf"));
3391 r
= json_variant_strv(mo
, &list
);
3393 return log_error_errno(r
, "Failed to parse group list: %m");
3395 r
= strv_extend(&list
, word
);
3402 mo
= json_variant_unref(mo
);
3403 r
= json_variant_new_array_strv(&mo
, list
);
3405 return log_error_errno(r
, "Failed to create group list JSON: %m");
3407 r
= json_variant_set_field(&arg_identity_extra
, "memberOf", mo
);
3409 return log_error_errno(r
, "Failed to update group list: %m");
3415 case ARG_TASKS_MAX
: {
3418 if (isempty(optarg
)) {
3419 r
= drop_from_identity("tasksMax");
3425 r
= safe_atou64(optarg
, &u
);
3427 return log_error_errno(r
, "Failed to parse --tasks-max= parameter: %s", optarg
);
3429 r
= json_variant_set_field_unsigned(&arg_identity_extra
, "tasksMax", u
);
3431 return log_error_errno(r
, "Failed to set tasksMax field: %m");
3436 case ARG_MEMORY_MAX
:
3437 case ARG_MEMORY_HIGH
:
3438 case ARG_LUKS_PBKDF_MEMORY_COST
: {
3440 c
== ARG_MEMORY_MAX
? "memoryMax" :
3441 c
== ARG_MEMORY_HIGH
? "memoryHigh" :
3442 c
== ARG_LUKS_PBKDF_MEMORY_COST
? "luksPbkdfMemoryCost" : NULL
;
3448 if (isempty(optarg
)) {
3449 r
= drop_from_identity(field
);
3455 r
= parse_size(optarg
, 1024, &u
);
3457 return log_error_errno(r
, "Failed to parse %s parameter: %s", field
, optarg
);
3459 r
= json_variant_set_field_unsigned(&arg_identity_extra_this_machine
, field
, u
);
3461 return log_error_errno(r
, "Failed to set %s field: %m", field
);
3466 case ARG_CPU_WEIGHT
:
3467 case ARG_IO_WEIGHT
: {
3468 const char *field
= c
== ARG_CPU_WEIGHT
? "cpuWeight" :
3469 c
== ARG_IO_WEIGHT
? "ioWeight" : NULL
;
3474 if (isempty(optarg
)) {
3475 r
= drop_from_identity(field
);
3481 r
= safe_atou64(optarg
, &u
);
3483 return log_error_errno(r
, "Failed to parse --cpu-weight=/--io-weight= parameter: %s", optarg
);
3485 if (!CGROUP_WEIGHT_IS_OK(u
))
3486 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Weight %" PRIu64
" is out of valid weight range.", u
);
3488 r
= json_variant_set_field_unsigned(&arg_identity_extra
, field
, u
);
3490 return log_error_errno(r
, "Failed to set %s field: %m", field
);
3495 case ARG_PKCS11_TOKEN_URI
:
3496 if (streq(optarg
, "list"))
3497 return pkcs11_list_tokens();
3499 /* If --pkcs11-token-uri= is specified we always drop everything old */
3500 FOREACH_STRING(p
, "pkcs11TokenUri", "pkcs11EncryptedKey") {
3501 r
= drop_from_identity(p
);
3506 if (isempty(optarg
)) {
3507 arg_pkcs11_token_uri
= strv_free(arg_pkcs11_token_uri
);
3511 if (streq(optarg
, "auto")) {
3512 _cleanup_free_
char *found
= NULL
;
3514 r
= pkcs11_find_token_auto(&found
);
3517 r
= strv_consume(&arg_pkcs11_token_uri
, TAKE_PTR(found
));
3519 if (!pkcs11_uri_valid(optarg
))
3520 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Not a valid PKCS#11 URI: %s", optarg
);
3522 r
= strv_extend(&arg_pkcs11_token_uri
, optarg
);
3527 strv_uniq(arg_pkcs11_token_uri
);
3530 case ARG_FIDO2_CRED_ALG
:
3531 r
= parse_fido2_algorithm(optarg
, &arg_fido2_cred_alg
);
3533 return log_error_errno(r
, "Failed to parse COSE algorithm: %s", optarg
);
3536 case ARG_FIDO2_DEVICE
:
3537 if (streq(optarg
, "list"))
3538 return fido2_list_devices();
3540 FOREACH_STRING(p
, "fido2HmacCredential", "fido2HmacSalt") {
3541 r
= drop_from_identity(p
);
3546 if (isempty(optarg
)) {
3547 arg_fido2_device
= strv_free(arg_fido2_device
);
3551 if (streq(optarg
, "auto")) {
3552 _cleanup_free_
char *found
= NULL
;
3554 r
= fido2_find_device_auto(&found
);
3558 r
= strv_consume(&arg_fido2_device
, TAKE_PTR(found
));
3560 r
= strv_extend(&arg_fido2_device
, optarg
);
3564 strv_uniq(arg_fido2_device
);
3567 case ARG_FIDO2_WITH_PIN
: {
3570 r
= parse_boolean_argument("--fido2-with-client-pin=", optarg
, &lock_with_pin
);
3574 SET_FLAG(arg_fido2_lock_with
, FIDO2ENROLL_PIN
, lock_with_pin
);
3578 case ARG_FIDO2_WITH_UP
: {
3581 r
= parse_boolean_argument("--fido2-with-user-presence=", optarg
, &lock_with_up
);
3585 SET_FLAG(arg_fido2_lock_with
, FIDO2ENROLL_UP
, lock_with_up
);
3589 case ARG_FIDO2_WITH_UV
: {
3592 r
= parse_boolean_argument("--fido2-with-user-verification=", optarg
, &lock_with_uv
);
3596 SET_FLAG(arg_fido2_lock_with
, FIDO2ENROLL_UV
, lock_with_uv
);
3600 case ARG_RECOVERY_KEY
:
3601 r
= parse_boolean(optarg
);
3603 return log_error_errno(r
, "Failed to parse --recovery-key= argument: %s", optarg
);
3605 arg_recovery_key
= r
;
3607 FOREACH_STRING(p
, "recoveryKey", "recoveryKeyType") {
3608 r
= drop_from_identity(p
);
3615 case ARG_AUTO_RESIZE_MODE
:
3616 if (isempty(optarg
)) {
3617 r
= drop_from_identity("autoResizeMode");
3624 r
= auto_resize_mode_from_string(optarg
);
3626 return log_error_errno(r
, "Failed to parse --auto-resize-mode= argument: %s", optarg
);
3628 r
= json_variant_set_field_string(&arg_identity_extra
, "autoResizeMode", auto_resize_mode_to_string(r
));
3630 return log_error_errno(r
, "Failed to set autoResizeMode field: %m");
3634 case ARG_REBALANCE_WEIGHT
: {
3637 if (isempty(optarg
)) {
3638 r
= drop_from_identity("rebalanceWeight");
3643 if (streq(optarg
, "off"))
3644 u
= REBALANCE_WEIGHT_OFF
;
3646 r
= safe_atou64(optarg
, &u
);
3648 return log_error_errno(r
, "Failed to parse --rebalance-weight= argument: %s", optarg
);
3650 if (u
< REBALANCE_WEIGHT_MIN
|| u
> REBALANCE_WEIGHT_MAX
)
3651 return log_error_errno(SYNTHETIC_ERRNO(ERANGE
), "Rebalancing weight out of valid range %" PRIu64
"%s%" PRIu64
": %s",
3652 REBALANCE_WEIGHT_MIN
, special_glyph(SPECIAL_GLYPH_ELLIPSIS
), REBALANCE_WEIGHT_MAX
, optarg
);
3655 /* Drop from per machine stuff and everywhere */
3656 r
= drop_from_identity("rebalanceWeight");
3660 /* Add to main identity */
3661 r
= json_variant_set_field_unsigned(&arg_identity_extra
, "rebalanceWeight", u
);
3663 return log_error_errno(r
, "Failed to set rebalanceWeight field: %m");
3669 arg_json_format_flags
= JSON_FORMAT_PRETTY_AUTO
|JSON_FORMAT_COLOR_AUTO
;
3673 r
= parse_json_argument(optarg
, &arg_json_format_flags
);
3680 if (arg_export_format
== EXPORT_FORMAT_FULL
)
3681 arg_export_format
= EXPORT_FORMAT_STRIPPED
;
3682 else if (arg_export_format
== EXPORT_FORMAT_STRIPPED
)
3683 arg_export_format
= EXPORT_FORMAT_MINIMAL
;
3685 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Specifying -E more than twice is not supported.");
3687 arg_json_format_flags
&= ~JSON_FORMAT_OFF
;
3688 if (arg_json_format_flags
== 0)
3689 arg_json_format_flags
= JSON_FORMAT_PRETTY_AUTO
|JSON_FORMAT_COLOR_AUTO
;
3692 case ARG_EXPORT_FORMAT
:
3693 if (streq(optarg
, "full"))
3694 arg_export_format
= EXPORT_FORMAT_FULL
;
3695 else if (streq(optarg
, "stripped"))
3696 arg_export_format
= EXPORT_FORMAT_STRIPPED
;
3697 else if (streq(optarg
, "minimal"))
3698 arg_export_format
= EXPORT_FORMAT_MINIMAL
;
3699 else if (streq(optarg
, "help")) {
3708 case ARG_AND_RESIZE
:
3709 arg_and_resize
= true;
3712 case ARG_AND_CHANGE_PASSWORD
:
3713 arg_and_change_password
= true;
3716 case ARG_DROP_CACHES
: {
3719 if (isempty(optarg
)) {
3720 r
= drop_from_identity("dropCaches");
3725 r
= parse_boolean_argument("--drop-caches=", optarg
, &drop_caches
);
3729 r
= json_variant_set_field_boolean(&arg_identity_extra
, "dropCaches", r
);
3731 return log_error_errno(r
, "Failed to set drop caches field: %m");
3740 assert_not_reached();
3744 if (!strv_isempty(arg_pkcs11_token_uri
) || !strv_isempty(arg_fido2_device
))
3745 arg_and_change_password
= true;
3747 if (arg_disk_size
!= UINT64_MAX
|| arg_disk_size_relative
!= UINT64_MAX
)
3748 arg_and_resize
= true;
3753 static int redirect_bus_mgr(void) {
3756 /* Talk to a different service if that's requested. (The same env var is also understood by homed, so
3757 * that it is relatively easily possible to invoke a second instance of homed for debug purposes and
3758 * have homectl talk to it, without colliding with the host version. This is handy when operating
3759 * from a homed-managed account.) */
3761 suffix
= getenv("SYSTEMD_HOME_DEBUG_SUFFIX");
3763 static BusLocator locator
= {
3764 .path
= "/org/freedesktop/home1",
3765 .interface
= "org.freedesktop.home1.Manager",
3768 /* Yes, we leak this memory, but there's little point to collect this, given that we only do
3769 * this in a debug environment, do it only once, and the string shall live for out entire
3770 * process runtime. */
3772 locator
.destination
= strjoin("org.freedesktop.home1.", suffix
);
3773 if (!locator
.destination
)
3778 bus_mgr
= bus_home_mgr
;
3783 static int run(int argc
, char *argv
[]) {
3784 static const Verb verbs
[] = {
3785 { "help", VERB_ANY
, VERB_ANY
, 0, help
},
3786 { "list", VERB_ANY
, 1, VERB_DEFAULT
, list_homes
},
3787 { "activate", 2, VERB_ANY
, 0, activate_home
},
3788 { "deactivate", 2, VERB_ANY
, 0, deactivate_home
},
3789 { "inspect", VERB_ANY
, VERB_ANY
, 0, inspect_home
},
3790 { "authenticate", VERB_ANY
, VERB_ANY
, 0, authenticate_home
},
3791 { "create", VERB_ANY
, 2, 0, create_home
},
3792 { "remove", 2, VERB_ANY
, 0, remove_home
},
3793 { "update", VERB_ANY
, 2, 0, update_home
},
3794 { "passwd", VERB_ANY
, 2, 0, passwd_home
},
3795 { "resize", 2, 3, 0, resize_home
},
3796 { "lock", 2, VERB_ANY
, 0, lock_home
},
3797 { "unlock", 2, VERB_ANY
, 0, unlock_home
},
3798 { "with", 2, VERB_ANY
, 0, with_home
},
3799 { "lock-all", VERB_ANY
, 1, 0, lock_all_homes
},
3800 { "deactivate-all", VERB_ANY
, 1, 0, deactivate_all_homes
},
3801 { "rebalance", VERB_ANY
, 1, 0, rebalance
},
3809 r
= redirect_bus_mgr();
3813 r
= parse_argv(argc
, argv
);
3817 return dispatch_verb(argc
, argv
, verbs
, NULL
);
3820 DEFINE_MAIN_FUNCTION_WITH_POSITIVE_FAILURE(run
);