HALF ECHO LEARN / REFERENCE COLLECTION
v262.2src/home/homectl.c
Git blob: 0fcf210f9340db07221cb542aaf5fc1759a817bb
Lines 4001–5000 of 5,181
if (!pkcs11_uri_valid(arg))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Not a valid PKCS#11 URI: %s", arg);
r = strv_extend(&arg_pkcs11_token_uri, arg);
}
if (r < 0)
return r;
strv_uniq(arg_pkcs11_token_uri);
return 1;
}
static int parse_fido2_device_field(const char *arg) {
int r;
assert(arg);
if (streq(arg, "list"))
return fido2_list_devices();
r = drop_from_identity("fido2HmacCredential", "fido2HmacSalt");
if (r < 0)
return r;
if (isempty(arg)) {
arg_fido2_device = strv_free(arg_fido2_device);
return 1;
}
if (streq(arg, "auto")) {
char *found;
r = fido2_find_device_auto(&found);
if (r < 0)
return r;
r = strv_consume(&arg_fido2_device, found);
} else
r = strv_extend(&arg_fido2_device, arg);
if (r < 0)
return r;
strv_uniq(arg_fido2_device);
return 1;
}
VERB_COMMON_HELP_AUTO_HIDDEN();
static int parse_argv(int argc, char *argv[], char ***remaining_args) {
_cleanup_strv_free_ char **arg_languages = NULL;
int r;
/* This points to one of arg_identity_extra, arg_identity_extra_this_machine,
* arg_identity_extra_other_machines, in order to redirect changes on the next property being set to
* this part of the identity, instead of the default. */
sd_json_variant **match_identity = NULL;
assert(argc >= 0);
assert(argv);
assert(remaining_args);
/* Eventually we should probably turn this into a proper --dry-run option, but as long as it is not
* hooked up everywhere let's make it an environment variable only. */
r = getenv_bool("SYSTEMD_HOME_DRY_RUN");
if (r >= 0)
arg_dry_run = r;
else if (r != -ENXIO)
log_debug_errno(r, "Unable to parse $SYSTEMD_HOME_DRY_RUN, ignoring: %m");
OptionParser opts = { argc, argv };
FOREACH_OPTION_OR_RETURN(c, &opts)
switch (c) {
OPTION_COMMON_HELP:
return command_print_help();
OPTION_COMMON_VERSION:
return version();
OPTION_LONG("offline", NULL, "Don't update record embedded in home directory"):
arg_offline = true;
break;
OPTION_COMMON_HOST:
arg_transport = BUS_TRANSPORT_REMOTE;
arg_host = opts.arg;
break;
OPTION_COMMON_MACHINE:
r = parse_machine_argument(opts.arg, &arg_host, &arg_transport);
if (r < 0)
return r;
break;
OPTION('I', "identity", "PATH", "Read JSON identity from file"):
arg_identity = opts.arg;
break;
OPTION_COMMON_JSON:
r = parse_json_argument(opts.arg, &arg_json_format_flags);
if (r <= 0)
return r;
break;
OPTION_COMMON_LOWERCASE_J:
arg_json_format_flags = SD_JSON_FORMAT_PRETTY_AUTO|SD_JSON_FORMAT_COLOR_AUTO;
break;
OPTION_LONG("export-format", "FORMAT",
"Strip JSON inspection data (full, stripped, minimal)"):
if (streq(opts.arg, "help"))
return DUMP_STRING_TABLE(export_format, ExportFormat, _EXPORT_FORMAT_MAX);
arg_export_format = export_format_from_string(opts.arg);
if (arg_export_format < 0)
return log_error_errno(arg_export_format, "Invalid export format: %s", opts.arg);
break;
OPTION_SHORT('E', NULL, "Same as -j --export-format=stripped"): {}
OPTION_HELP_VERBATIM("-EE", "Same as -j --export-format=minimal"):
if (arg_export_format == EXPORT_FORMAT_FULL)
arg_export_format = EXPORT_FORMAT_STRIPPED;
else if (arg_export_format == EXPORT_FORMAT_STRIPPED)
arg_export_format = EXPORT_FORMAT_MINIMAL;
else
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Specifying -E more than twice is not supported.");
arg_json_format_flags &= ~SD_JSON_FORMAT_OFF;
if (arg_json_format_flags == 0)
arg_json_format_flags = SD_JSON_FORMAT_PRETTY_AUTO|SD_JSON_FORMAT_COLOR_AUTO;
break;
OPTION_LONG("key-name", "NAME", "Key name when adding a signing key"):
if (!isempty(opts.arg) && !filename_is_valid(opts.arg))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Parameter for --key-name= not a valid filename: %s", opts.arg);
r = free_and_strdup_warn(&arg_key_name, empty_to_null(opts.arg));
if (r < 0)
return r;
break;
OPTION_LONG("seize", "BOOL",
"Whether to strip existing signatures of user record when creating"):
r = parse_boolean_argument("--seize=", opts.arg, &arg_seize);
if (r < 0)
return r;
break;
OPTION_LONG("prompt-new-user", NULL,
"firstboot: Query user interactively for user to create"):
arg_prompt_new_user = true;
break;
OPTION_LONG("prompt-groups", "BOOL",
"In first-boot mode, don't prompt for auxiliary group memberships"):
r = parse_boolean_argument("--prompt-groups=", opts.arg, &arg_prompt_groups);
if (r < 0)
return r;
break;
OPTION_LONG("prompt-shell", "BOOL",
"In first-boot mode, don't prompt for shells"):
r = parse_boolean_argument("--prompt-shell=", opts.arg, &arg_prompt_shell);
if (r < 0)
return r;
break;
OPTION_LONG("chrome", "BOOL",
"In first-boot mode, don't show colour bar at top and bottom of terminal"):
r = parse_boolean_argument("--chrome=", opts.arg, &arg_chrome);
if (r < 0)
return r;
break;
OPTION_LONG("mute-console", "BOOL",
"In first-boot mode, tell kernel/PID 1 to not write to the console while running"):
r = parse_boolean_argument("--mute-console=", opts.arg, &arg_mute_console);
if (r < 0)
return r;
break;
OPTION_COMMON_NO_PAGER:
arg_pager_flags |= PAGER_DISABLE;
break;
OPTION_COMMON_NO_LEGEND:
arg_legend = false;
break;
OPTION_COMMON_NO_ASK_PASSWORD:
arg_ask_password = false;
break;
OPTION_GROUP("General User Record Properties"): {}
OPTION('c', "real-name", "REALNAME", "Real name for user"): {}
OPTION_LONG("comment", "REALNAME", /* help= */ NULL): /* Compat alias to keep things in sync with useradd(8) */
if (!isempty(opts.arg) && !valid_gecos(opts.arg))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Invalid GECOS field '%s'.", opts.arg);
r = parse_string_field(match_identity ?: &arg_identity_extra, "realName", opts.arg);
if (r < 0)
return r;
break;
OPTION_LONG("realm", "REALM", "Realm to create user in"):
r = parse_realm_field(&arg_identity_extra, "realm", opts.arg);
if (r < 0)
return r;
break;
OPTION_LONG("alias", "ALIAS", "Define alias usernames for this account"):
r = parse_group_field(&arg_identity_extra, "aliases", opts.arg);
if (r < 0)
return r;
break;
OPTION_LONG("email-address", "EMAIL", "Email address for user"):
r = parse_string_field(match_identity ?: &arg_identity_extra, "emailAddress", opts.arg);
if (r < 0)
return r;
break;
OPTION_LONG("location", "LOCATION", "Set location of user on earth"):
r = parse_string_field(match_identity ?: &arg_identity_extra, "location", opts.arg);
if (r < 0)
return r;
break;
OPTION_LONG_FLAGS(OPTION_OPTIONAL_ARG, "birth-date", "DATE",
"Set user birth date (YYYY-MM-DD)"):
if (isempty(opts.arg)) {
r = drop_from_identity("birthDate");
if (r < 0)
return r;
} else {
r = parse_birth_date(opts.arg, /* ret= */ NULL);
if (r < 0)
return log_error_errno(r, "Invalid birth date (expected YYYY-MM-DD): %s", opts.arg);
r = parse_string_field(&arg_identity_extra, "birthDate", opts.arg);
if (r < 0)
return r;
}
break;
OPTION_LONG("icon-name", "NAME", "Icon name for user"):
r = parse_string_field(match_identity ?: &arg_identity_extra, "iconName", opts.arg);
if (r < 0)
return r;
break;
OPTION('d', "home-dir", "PATH", "Home directory"): /* Compatible with useradd(8) */
r = parse_home_directory_field(&arg_identity_extra, "homeDirectory", opts.arg);
if (r < 0)
return r;
break;
OPTION('u', "uid", "UID", "Numeric UID for user"): /* Compatible with useradd(8) */
r = parse_uid_field(&arg_identity_extra, "uid", opts.arg);
if (r < 0)
return r;
break;
OPTION('G', "member-of", "GROUP", "Add user to group"): {}
OPTION_LONG("groups", "GROUP", /* help= */ NULL): /* Compat alias to keep things in sync with useradd(8) */
r = parse_group_field(match_identity ?: &arg_identity_extra, "memberOf", opts.arg);
if (r < 0)
return r;
break;
OPTION_LONG("capability-bounding-set", "CAPS", "Bounding POSIX capability set"):
r = parse_capability_set_field(match_identity ?: &arg_identity_extra,
&arg_capability_bounding_set,
"capabilityBoundingSet", opts.arg);
if (r < 0)
return r;
break;
OPTION_LONG("capability-ambient-set", "CAPS", "Ambient POSIX capability set"):
r = parse_capability_set_field(match_identity ?: &arg_identity_extra,
&arg_capability_ambient_set,
"capabilityAmbientSet", opts.arg);
if (r < 0)
return r;
break;
OPTION_LONG("access-mode", "MODE", "User home directory access mode"):
r = parse_mode_field(&arg_identity_extra, "accessMode", opts.arg);
if (r < 0)
return r;
break;
OPTION_LONG("umask", "MODE", "Umask for user when logging in"):
r = parse_mode_field(match_identity ?: &arg_identity_extra, "umask", opts.arg);
if (r < 0)
return r;
break;
OPTION('k', "skel", "PATH", "Skeleton directory to use"): /* Compatible with useradd(8) */
r = parse_path_field(match_identity ?: &arg_identity_extra_this_machine, "skeletonDirectory", opts.arg);
if (r < 0)
return r;
break;
OPTION('s', "shell", "PATH", "Shell for account"): /* Compatible with useradd(8) */
if (!isempty(opts.arg) && !valid_shell(opts.arg))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Shell '%s' not valid.", opts.arg);
r = parse_string_field(match_identity ?: &arg_identity_extra, "shell", opts.arg);
if (r < 0)
return r;
break;
OPTION_LONG("setenv", "VARIABLE[=VALUE]", "Set an environment variable at log-in"):
r = parse_environment_field(match_identity ?: &arg_identity_extra, "environment", opts.arg);
if (r < 0)
return r;
break;
OPTION_LONG("timezone", "TIMEZONE", "Set a time-zone"):
if (!isempty(opts.arg) && !timezone_is_valid(opts.arg, LOG_DEBUG))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Timezone '%s' is not valid.", opts.arg);
r = parse_string_field(match_identity ?: &arg_identity_extra, "timeZone", opts.arg);
if (r < 0)
return r;
break;
OPTION_LONG("language", "LOCALE", "Set preferred languages"):
r = parse_language_field(&arg_languages, opts.arg);
if (r < 0)
return r;
break;
OPTION_LONG("default-area", "AREA", "Select default area"):
r = parse_filename_field(match_identity ?: &arg_identity_extra, "defaultArea", opts.arg);
if (r < 0)
return r;
break;
OPTION_GROUP("Authentication User Record Properties"): {}
OPTION_LONG("ssh-authorized-keys", "KEYS", "Specify SSH public keys"):
r = parse_ssh_authorized_keys(&arg_identity_extra_privileged, "sshAuthorizedKeys", opts.arg);
if (r < 0)
return r;
break;
OPTION_LONG("pkcs11-token-uri", "URI",
"URI to PKCS#11 security token containing private key and matching X.509 certificate"):
r = parse_pkcs11_token_uri_field(opts.arg);
if (r <= 0)
return r;
break;
OPTION_LONG("fido2-device", "PATH",
"Path to FIDO2 hidraw device with hmac-secret extension"):
r = parse_fido2_device_field(opts.arg);
if (r <= 0)
return r;
break;
OPTION_LONG("fido2-with-client-pin", "BOOL",
"Whether to require entering a PIN to unlock the account"):
r = parse_boolean_argument("--fido2-with-client-pin=", opts.arg, NULL);
if (r < 0)
return r;
SET_FLAG(arg_fido2_lock_with, FIDO2ENROLL_PIN, r);
break;
OPTION_LONG("fido2-with-user-presence", "BOOL",
"Whether to require user presence to unlock the account"):
r = parse_boolean_argument("--fido2-with-user-presence=", opts.arg, NULL);
if (r < 0)
return r;
SET_FLAG(arg_fido2_lock_with, FIDO2ENROLL_UP, r);
break;
OPTION_LONG("fido2-with-user-verification", "BOOL",
"Whether to require user verification to unlock the account"):
r = parse_boolean_argument("--fido2-with-user-verification=", opts.arg, NULL);
if (r < 0)
return r;
SET_FLAG(arg_fido2_lock_with, FIDO2ENROLL_UV, r);
break;
OPTION_LONG("recovery-key", "BOOL", "Add a recovery key"):
r = parse_boolean(opts.arg);
if (r < 0)
return log_error_errno(r, "Failed to parse --recovery-key= argument: %s", opts.arg);
arg_recovery_key = r;
r = drop_from_identity("recoveryKey", "recoveryKeyType");
if (r < 0)
return r;
break;
OPTION_LONG("recovery-key-file", "PATH", "Write the generated recovery key to a file"):
r = parse_path_argument(opts.arg, /* suppress_root= */ false, &arg_recovery_key_file);
if (r < 0)
return r;
break;
OPTION_GROUP("Blob Directory User Record Properties"): {}
OPTION('b', "blob", "[FILENAME=]PATH",
"Path to a replacement blob directory, or replace an individual files in the blob directory"): {}
OPTION_LONG("avatar", "PATH", "Path to user avatar picture"): {}
OPTION_LONG("login-background", "PATH", "Path to user login background picture"): {
_cleanup_close_ int fd = -EBADF;
_cleanup_free_ char *path = NULL, *filename = NULL;
const char *long_code = opts.opt->long_code;
if (streq(long_code, "blob")) {
const char *eq;
if (isempty(opts.arg)) { /* --blob= deletes everything, including existing blob dirs */
hashmap_clear(arg_blob_files);
arg_blob_dir = mfree(arg_blob_dir);
arg_blob_clear = true;
break;
}
eq = strrchr(opts.arg, '=');
if (!eq) { /* --blob=/some/path replaces the blob dir */
r = parse_path_argument(opts.arg, /* suppress_root= */ false, &arg_blob_dir);
if (r < 0)
return r;
break;
}
/* --blob=filename=/some/path replaces the file "filename" with /some/path */
filename = strndup(opts.arg, eq - opts.arg);
if (!filename)
return log_oom();
if (isempty(filename))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Can't parse blob file assignment: %s", opts.arg);
if (!suitable_blob_filename(filename))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Invalid blob filename: %s", filename);
r = parse_path_argument(eq + 1, /* suppress_root= */ false, &path);
if (r < 0)
return r;
} else {
filename = strdup(long_code);
if (!filename)
return log_oom();
r = parse_path_argument(opts.arg, /* suppress_root= */ false, &path);
if (r < 0)
return r;
}
if (path) {
fd = open(path, O_RDONLY|O_CLOEXEC|O_NOCTTY);
if (fd < 0)
return log_error_errno(errno, "Failed to open %s: %m", path);
if (fd_verify_regular(fd) < 0)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Provided blob is not a regular file: %s", path);
} else
fd = -EBADF; /* Delete the file */
r = hashmap_ensure_put(&arg_blob_files, &blob_fd_hash_ops, filename, FD_TO_PTR(fd));
if (r < 0)
return log_error_errno(r, "Failed to map %s to %s in blob directory: %m", path, filename);
TAKE_PTR(filename); /* hashmap takes ownership */
TAKE_FD(fd);
break;
}
OPTION_GROUP("Account Management User Record Properties"): {}
OPTION_LONG("locked", "BOOL", "Set locked account state"):
r = parse_boolean_field(match_identity ?: &arg_identity_extra, "locked", opts.arg);
if (r < 0)
return r;
break;
OPTION_LONG("not-before", "TIMESTAMP", "Do not allow logins before"): {}
OPTION_LONG("not-after", "TIMESTAMP", "Do not allow logins after"): {}
OPTION_LONG("expiredate", "TIMESTAMP", /* help= */ NULL): /* Compat alias for -e to keep things in sync with useradd(8) */ {
const char *field = streq(opts.opt->long_code, "not-before") ? "notBeforeUSec" : "notAfterUSec";
r = parse_timestamp_field(match_identity ?: &arg_identity_extra, field, opts.arg);
if (r < 0)
return r;
break;
}
OPTION_SHORT('e', "TIMESTAMP", /* help= */ NULL): /* -e alias for --expiredate */
r = parse_timestamp_field(match_identity ?: &arg_identity_extra, "notAfterUSec", opts.arg);
if (r < 0)
return r;
break;
OPTION_LONG("rate-limit-interval", "SECS", "Login rate-limit interval in seconds"):
r = parse_time_field(match_identity ?: &arg_identity_extra, "rateLimitIntervalUSec", opts.arg);
if (r < 0)
return r;
break;
OPTION_LONG("rate-limit-burst", "NUMBER", "Login rate-limit attempts per interval"):
r = parse_unsigned_field(match_identity ?: &arg_identity_extra, "rateLimitBurst", opts.arg);
if (r < 0)
return r;
break;
OPTION_GROUP("Password Policy User Record Properties"): {}
OPTION_LONG("password-hint", "HINT", "Set Password hint"):
r = parse_string_field(&arg_identity_extra_privileged, "passwordHint", opts.arg);
if (r < 0)
return r;
string_erase((char *) opts.arg);
break;
OPTION_LONG("enforce-password-policy", "BOOL",
"Control whether to enforce system's password policy for this user"):
r = parse_boolean_field(match_identity ?: &arg_identity_extra, "enforcePasswordPolicy", opts.arg);
if (r < 0)
return r;
break;
OPTION_SHORT('P', NULL, "Same as --enforce-password-policy=no"):
r = sd_json_variant_set_field_boolean(&arg_identity_extra, "enforcePasswordPolicy", false);
if (r < 0)
return log_error_errno(r, "Failed to set %s field: %m", "enforcePasswordPolicy");
break;
OPTION_LONG("password-change-now", "BOOL",
"Require the password to be changed on next login"):
r = parse_boolean_field(match_identity ?: &arg_identity_extra, "passwordChangeNow", opts.arg);
if (r < 0)
return r;
break;
OPTION_LONG("password-change-min", "TIME", "Require minimum time between password changes"): {}
OPTION_LONG("password-change-max", "TIME", "Require maximum time between password changes"): {}
OPTION_LONG("password-change-warn", "TIME", "How much time to warn before password expiry"): {}
OPTION_LONG("password-change-inactive", "TIME", "How much time to block password after expiry"): {
const char *lc = opts.opt->long_code;
const char *field =
streq(lc, "password-change-min") ? "passwordChangeMinUSec" :
streq(lc, "password-change-max") ? "passwordChangeMaxUSec" :
streq(lc, "password-change-warn") ? "passwordChangeWarnUSec" :
streq(lc, "password-change-inactive") ? "passwordChangeInactiveUSec" :
NULL;
assert(field);
r = parse_time_field(match_identity ?: &arg_identity_extra, field, opts.arg);
if (r < 0)
return r;
break;
}
OPTION_GROUP("Resource Management User Record Properties"): {}
OPTION_LONG("disk-size", "BYTES", "Size to assign the user on disk"):
r = parse_disk_size_field(match_identity ?: &arg_identity_extra_this_machine, opts.arg);
if (r < 0)
return r;
break;
OPTION_LONG("nice", "NICE", "Nice level for user"):
r = parse_nice_field(match_identity ?: &arg_identity_extra, "niceLevel", opts.arg);
if (r < 0)
return r;
break;
OPTION_LONG("rlimit", "LIMIT=VALUE[:VALUE]", "Set resource limits"):
r = parse_rlimit_field(&arg_identity_extra_rlimits, "resourceLimits", opts.arg);
if (r < 0)
return r;
break;
OPTION_LONG("tasks-max", "MAX", "Set maximum number of per-user tasks"):
r = parse_u64_field(match_identity ?: &arg_identity_extra, "tasksMax", opts.arg);
if (r < 0)
return r;
break;
OPTION_LONG("memory-high", "BYTES", "Set high memory threshold in bytes"):
r = parse_size_field(match_identity ?: &arg_identity_extra_this_machine, "memoryHigh", opts.arg);
if (r < 0)
return r;
break;
OPTION_LONG("memory-max", "BYTES", "Set maximum memory limit"):
r = parse_size_field(match_identity ?: &arg_identity_extra_this_machine, "memoryMax", opts.arg);
if (r < 0)
return r;
break;
OPTION_LONG("cpu-weight", "WEIGHT", "Set CPU weight"): {}
OPTION_LONG("io-weight", "WEIGHT", "Set IO weight"): {
const char *field = streq(opts.opt->long_code, "cpu-weight") ? "cpuWeight" : "ioWeight";
r = parse_weight_field(match_identity ?: &arg_identity_extra, field, opts.arg);
if (r < 0)
return r;
break;
}
OPTION_LONG("tmp-limit", "BYTES|PERCENT", "Set limit on /tmp/"): {}
OPTION_LONG("dev-shm-limit", "BYTES|PERCENT", "Set limit on /dev/shm/"): {
bool is_tmp = streq(opts.opt->long_code, "tmp-limit");
const char *field = is_tmp ? "tmpLimit" : "devShmLimit";
const char *field_scale = is_tmp ? "tmpLimitScale" : "devShmLimitScale";
r = parse_tmpfs_limit_field(match_identity ?: &arg_identity_extra,
field, field_scale, opts.arg);
if (r < 0)
return r;
break;
}
OPTION_GROUP("Storage User Record Properties"): {}
OPTION_LONG("storage", "STORAGE",
"Storage type to use (luks, fscrypt, directory, subvolume, cifs)"):
if (!string_is_safe(opts.arg, STRING_ALLOW_GLOBS))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Parameter for field %s not valid: %s", "storage", opts.arg);
r = parse_string_field(match_identity ?: &arg_identity_extra_this_machine, "storage", opts.arg);
if (r < 0)
return r;
break;
OPTION_LONG("image-path", "PATH", "Path to image file/directory"):
r = parse_path_field(match_identity ?: &arg_identity_extra_this_machine, "imagePath", opts.arg);
if (r < 0)
return r;
break;
OPTION_LONG("drop-caches", "BOOL", "Whether to automatically drop caches on logout"):
r = parse_boolean_field(match_identity ?: &arg_identity_extra, "dropCaches", opts.arg);
if (r < 0)
return r;
break;
OPTION_GROUP("LUKS Storage User Record Properties"): {}
OPTION_LONG("fs-type", "TYPE",
"File system type to use in case of luks storage (btrfs, ext4, xfs)"):
if (!string_is_safe(opts.arg, STRING_ALLOW_GLOBS))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Parameter for field %s not valid: %s", "fileSystemType", opts.arg);
r = parse_string_field(match_identity ?: &arg_identity_extra_this_machine, "fileSystemType", opts.arg);
if (r < 0)
return r;
break;
OPTION_LONG("luks-discard", "BOOL",
"Whether to use 'discard' feature of file system when activated (mounted)"): {}
OPTION_LONG("luks-offline-discard", "BOOL", "Whether to trim file on logout"): {
const char *field = streq(opts.opt->long_code, "luks-discard") ? "luksDiscard" : "luksOfflineDiscard";
r = parse_boolean_field(match_identity ?: &arg_identity_extra, field, opts.arg);
if (r < 0)
return r;
break;
}
OPTION_LONG("luks-cipher", "CIPHER", "Cipher to use for LUKS encryption"):
if (!string_is_safe(opts.arg, STRING_ALLOW_GLOBS))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Parameter for field %s not valid: %s", "luksCipher", opts.arg);
r = parse_string_field(match_identity ?: &arg_identity_extra, "luksCipher", opts.arg);
if (r < 0)
return r;
break;
OPTION_LONG("luks-cipher-mode", "MODE", "Cipher mode to use for LUKS encryption"):
if (!string_is_safe(opts.arg, STRING_ALLOW_GLOBS))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Parameter for field %s not valid: %s", "luksCipherMode", opts.arg);
r = parse_string_field(match_identity ?: &arg_identity_extra, "luksCipherMode", opts.arg);
if (r < 0)
return r;
break;
OPTION_LONG("luks-volume-key-size", "BITS", "Volume key size to use for LUKS encryption"):
r = parse_unsigned_field(match_identity ?: &arg_identity_extra, "luksVolumeKeySize", opts.arg);
if (r < 0)
return r;
break;
OPTION_LONG("luks-pbkdf-type", "TYPE", "Password-based Key Derivation Function to use"):
if (!string_is_safe(opts.arg, STRING_ALLOW_GLOBS))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Parameter for field %s not valid: %s", "luksPbkdfType", opts.arg);
r = parse_string_field(match_identity ?: &arg_identity_extra, "luksPbkdfType", opts.arg);
if (r < 0)
return r;
break;
OPTION_LONG("luks-pbkdf-hash-algorithm", "ALG", "PBKDF hash algorithm to use"):
if (!string_is_safe(opts.arg, STRING_ALLOW_GLOBS))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Parameter for field %s not valid: %s", "luksPbkdfHashAlgorithm", opts.arg);
r = parse_string_field(match_identity ?: &arg_identity_extra, "luksPbkdfHashAlgorithm", opts.arg);
if (r < 0)
return r;
break;
OPTION_LONG("luks-pbkdf-time-cost", "SECS", "Time cost for PBKDF in seconds"):
r = parse_time_field(match_identity ?: &arg_identity_extra, "luksPbkdfTimeCostUSec", opts.arg);
if (r < 0)
return r;
break;
OPTION_LONG("luks-pbkdf-memory-cost", "BYTES", "Memory cost for PBKDF in bytes"):
r = parse_size_field(match_identity ?: &arg_identity_extra_this_machine, "luksPbkdfMemoryCost", opts.arg);
if (r < 0)
return r;
break;
OPTION_LONG("luks-pbkdf-parallel-threads", "N", "Number of parallel threads for PKBDF"):
r = parse_unsigned_field(match_identity ?: &arg_identity_extra, "luksPbkdfParallelThreads", opts.arg);
if (r < 0)
return r;
break;
OPTION_LONG("luks-sector-size", "BYTES", "Sector size for LUKS encryption in bytes"):
r = parse_sector_size_field(match_identity ?: &arg_identity_extra, "luksSectorSize", opts.arg);
if (r < 0)
return r;
break;
OPTION_LONG("luks-extra-mount-options", "…", "LUKS extra mount options"):
r = parse_string_field(match_identity ?: &arg_identity_extra, "luksExtraMountOptions", opts.arg);
if (r < 0)
return r;
break;
OPTION_LONG("luks-pbkdf-force-iterations", "NUMBER", /* help= */ NULL):
r = parse_unsigned_field(match_identity ?: &arg_identity_extra, "luksPbkdfForceIterations", opts.arg);
if (r < 0)
return r;
break;
OPTION_LONG("auto-resize-mode", "MODE",
"Automatically grow/shrink home on login/logout"):
r = parse_auto_resize_mode_field(match_identity ?: &arg_identity_extra,
"autoResizeMode", opts.arg);
if (r < 0)
return r;
break;
OPTION_LONG("rebalance-weight", "WEIGHT", "Weight while rebalancing"):
r = parse_rebalance_weight(match_identity ?: &arg_identity_extra,
"rebalanceWeight", opts.arg);
if (r < 0)
return r;
break;
OPTION_GROUP("Mounting User Record Properties"): {}
OPTION_LONG("nosuid", "BOOL", "Control the 'nosuid' flag of the home mount"):
r = parse_boolean_field(match_identity ?: &arg_identity_extra, "mountNoSuid", opts.arg);
if (r < 0)
return r;
break;
OPTION_LONG("nodev", "BOOL", "Control the 'nodev' flag of the home mount"):
r = parse_boolean_field(match_identity ?: &arg_identity_extra, "mountNoDevices", opts.arg);
if (r < 0)
return r;
break;
OPTION_LONG("noexec", "BOOL", "Control the 'noexec' flag of the home mount"):
r = parse_boolean_field(match_identity ?: &arg_identity_extra, "mountNoExecute", opts.arg);
if (r < 0)
return r;
break;
OPTION_GROUP("CIFS User Record Properties"): {}
OPTION_LONG("cifs-domain", "DOMAIN", "CIFS (Windows) domain"):
r = parse_string_field(match_identity ?: &arg_identity_extra, "cifsDomain", opts.arg);
if (r < 0)
return r;
break;
OPTION_LONG("cifs-user-name", "USER", "CIFS (Windows) user name"):
r = parse_string_field(match_identity ?: &arg_identity_extra, "cifsUserName", opts.arg);
if (r < 0)
return r;
break;
OPTION_LONG("cifs-service", "SERVICE",
"CIFS (Windows) service to mount as home area"):
if (!isempty(opts.arg)) {
r = parse_cifs_service(opts.arg, /* ret_host= */ NULL, /* ret_service= */ NULL, /* ret_path= */ NULL);
if (r < 0)
return log_error_errno(r, "Failed to validate CIFS service name: %s", opts.arg);
}
r = parse_string_field(match_identity ?: &arg_identity_extra, "cifsService", opts.arg);
if (r < 0)
return r;
break;
OPTION_LONG("cifs-extra-mount-options", "…",
"CIFS (Windows) extra mount options"):
r = parse_string_field(match_identity ?: &arg_identity_extra, "cifsExtraMountOptions", opts.arg);
if (r < 0)
return r;
break;
OPTION_GROUP("Login Behaviour User Record Properties"): {}
OPTION_LONG("stop-delay", "SECS",
"How long to leave user services running after logout"):
r = parse_time_field(match_identity ?: &arg_identity_extra, "stopDelayUSec", opts.arg);
if (r < 0)
return r;
break;
OPTION_LONG("kill-processes", "BOOL",
"Whether to kill user processes when sessions terminate"):
r = parse_boolean_field(match_identity ?: &arg_identity_extra, "killProcesses", opts.arg);
if (r < 0)
return r;
break;
OPTION_LONG("auto-login", "BOOL", "Try to log this user in automatically"):
r = parse_boolean_field(match_identity ?: &arg_identity_extra, "autoLogin", opts.arg);
if (r < 0)
return r;
break;
OPTION_LONG("session-launcher", "LAUNCHER", "Preferred session launcher file"):
r = parse_string_field(match_identity ?: &arg_identity_extra, "preferredSessionLauncher", opts.arg);
if (r < 0)
return r;
break;
OPTION_LONG("session-type", "TYPE", "Preferred session type"):
r = parse_string_field(match_identity ?: &arg_identity_extra, "preferredSessionType", opts.arg);
if (r < 0)
return r;
break;
/* Hidden options below */
OPTION_LONG("fido2-credential-algorithm", "ALG", /* help= */ NULL):
r = parse_fido2_algorithm(opts.arg, &arg_fido2_cred_alg);
if (r < 0)
return log_error_errno(r, "Failed to parse COSE algorithm: %s", opts.arg);
break;
OPTION_LONG("match", "any|this|other|auto", /* help= */ NULL):
if (streq(opts.arg, "any"))
match_identity = &arg_identity_extra;
else if (streq(opts.arg, "this"))
match_identity = &arg_identity_extra_this_machine;
else if (streq(opts.arg, "other"))
match_identity = &arg_identity_extra_other_machines;
else if (streq(opts.arg, "auto"))
match_identity = NULL;
else
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "--machine= argument not understood. Refusing.");
break;
OPTION_SHORT('A', NULL, /* help= */ NULL):
match_identity = &arg_identity_extra;
break;
OPTION_SHORT('T', NULL, /* help= */ NULL):
match_identity = &arg_identity_extra_this_machine;
break;
OPTION_SHORT('N', NULL, /* help= */ NULL):
match_identity = &arg_identity_extra_other_machines;
break;
OPTION_COMMON_INTROSPECT_CLI:
return introspect_cli(arg_json_format_flags);
}
if (!strv_isempty(arg_languages)) {
char **additional;
r = sd_json_variant_set_field_string(&arg_identity_extra, "preferredLanguage", arg_languages[0]);
if (r < 0)
return log_error_errno(r, "Failed to update preferred language: %m");
additional = strv_skip(arg_languages, 1);
if (!strv_isempty(additional)) {
r = sd_json_variant_set_field_strv(&arg_identity_extra, "additionalLanguages", additional);
if (r < 0)
return log_error_errno(r, "Failed to update additional language list: %m");
} else {
r = drop_from_identity("additionalLanguages");
if (r < 0)
return r;
}
}
if (arg_recovery_key_file && !arg_recovery_key)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "--recovery-key-file= requires --recovery-key=yes.");
*remaining_args = option_parser_get_args(&opts);
return 1;
}
static int redirect_bus_mgr(void) {
const char *suffix;
/* Talk to a different service if that's requested. (The same env var is also understood by homed, so
* that it is relatively easily possible to invoke a second instance of homed for debug purposes and
* have homectl talk to it, without colliding with the host version. This is handy when operating
* from a homed-managed account.) */
suffix = getenv("SYSTEMD_HOME_DEBUG_SUFFIX");
if (suffix) {
static BusLocator locator = {
.path = "/org/freedesktop/home1",
.interface = "org.freedesktop.home1.Manager",
};
/* Yes, we leak this memory, but there's little point to collect this, given that we only do
* this in a debug environment, do it only once, and the string shall live for out entire
* process runtime. */
locator.destination = strjoin("org.freedesktop.home1.", suffix);
if (!locator.destination)
return log_oom();
bus_mgr = &locator;
} else
bus_mgr = bus_home_mgr;
return 0;
}
static bool is_fallback_shell(const char *p) {
const char *q;
if (!p)
return false;
if (p[0] == '-') {
/* Skip over login shell dash */
p++;
if (streq(p, "ystemd-home-fallback-shell")) /* maybe the dash was used to override the binary name? */
return true;
}
q = strrchr(p, '/'); /* Skip over path */
if (q)
p = q + 1;
return streq(p, "systemd-home-fallback-shell");
}
static int fallback_shell(int argc, char *argv[]) {
_cleanup_(user_record_unrefp) UserRecord *secret = NULL, *hr = NULL;
_cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
_cleanup_strv_free_ char **l = NULL;
_cleanup_free_ char *argv0 = NULL;
const char *json, *hd, *shell;
int r, incomplete;
/* So here's the deal: if users log into a system via ssh, and their homed-managed home directory
* wasn't activated yet, SSH will permit the access but the home directory isn't actually available
* yet. SSH doesn't allow us to ask authentication questions from the PAM session stack, and doesn't
* run the PAM authentication stack (because it authenticates via its own key management, after
* all). So here's our way to support this: homectl can be invoked as a multi-call binary under the
* name "systemd-home-fallback-shell". If so, it will chainload a login shell, but first try to
* unlock the home directory of the user it is invoked as. systemd-homed will then override the shell
* listed in user records whose home directory is not activated yet with this pseudo-shell. Net
* effect: one SSH auth succeeds this pseudo shell gets invoked, which will unlock the homedir
* (possibly asking for a passphrase) and then chainload the regular shell. Once the login is
* complete the user record will look like any other. */
r = acquire_bus(&bus);
if (r < 0)
return r;