From 793ceda177a40e16933b74542c3f8d13ff27d56e Mon Sep 17 00:00:00 2001 From: Adrian Vovk Date: Sun, 4 Feb 2024 19:21:29 -0500 Subject: [PATCH] user-record: Add preferredSession{Type,Launcher} These will be used by display managers to pre-select the user's preferred desktop environment and display server type. On homed, the display manager will also be able to set these fields to cache the user's last selection. --- docs/USER_RECORD.md | 13 +++++++++++-- man/homectl.xml | 22 ++++++++++++++++++++++ shell-completion/bash/homectl | 10 +++++++++- src/home/homectl.c | 13 ++++++++++++- src/shared/user-record-show.c | 5 +++++ src/shared/user-record.c | 7 +++++++ src/shared/user-record.h | 3 +++ 7 files changed, 69 insertions(+), 4 deletions(-) diff --git a/docs/USER_RECORD.md b/docs/USER_RECORD.md index a92711f2759..78b29f078ae 100644 --- a/docs/USER_RECORD.md +++ b/docs/USER_RECORD.md @@ -568,6 +568,15 @@ it is bypassed. auto-login. Systems are supposed to automatically log in a user marked this way during boot, if there's exactly one user on it defined this way. +`preferredSessionType` → A string that indicates the user's preferred session type +(i.e. `x11`, `wayland`, or other values valid for `$XDG_SESSION_TYPE`). This should +be used by the display manager to pre-select the correct environment to log into. + +`preferredSessionLauncher` → A string that indicates the user's preferred session launcher +desktop entry file (i.e. `gnome`, `gnome-classic`, `plasma`, `kodi`, or others that appear +in `/usr/share/xsessions/` or `/usr/share/wayland-sessions/`). This should be used by the +display manager to pre-select the correct environment to launch when the user logs in. + `stopDelayUSec` → An unsigned 64-bit integer, indicating the time in µs the per-user service manager is kept around after the user fully logged out. This value is honored by @@ -780,8 +789,8 @@ that may be used in this section are identical to the equally named ones in the `luksPbkdfType`, `luksPbkdfForceIterations`, `luksPbkdfTimeCostUSec`, `luksPbkdfMemoryCost`, `luksPbkdfParallelThreads`, `luksSectorSize`, `autoResizeMode`, `rebalanceWeight`, `rateLimitIntervalUSec`, `rateLimitBurst`, `enforcePasswordPolicy`, -`autoLogin`, `stopDelayUSec`, `killProcesses`, `passwordChangeMinUSec`, -`passwordChangeMaxUSec`, `passwordChangeWarnUSec`, +`autoLogin`, `preferredSessionType`, `preferredSessionLauncher`, `stopDelayUSec`, `killProcesses`, +`passwordChangeMinUSec`, `passwordChangeMaxUSec`, `passwordChangeWarnUSec`, `passwordChangeInactiveUSec`, `passwordChangeNow`, `pkcs11TokenUri`, `fido2HmacCredential`. diff --git a/man/homectl.xml b/man/homectl.xml index 521d3412488..1a0535cd4a6 100644 --- a/man/homectl.xml +++ b/man/homectl.xml @@ -963,6 +963,28 @@ + + + LAUNCHER + + Takes a string argument. Configures the user's preferred session launcher + .desktop entry file (i.e. gnome, plasma, or other names that + appear in /usr/share/xesssions/ or /usr/share/wayland-sessions). + This is read by the display manager to pick the default session that is launched when the user logs in. + + + + + + TYPE + + Takes a string argument. Configures the user's preferred session type + (i.e. x11, wayland, and other values accepted by + $XDG_SESSION_TYPE). This is read by the display manage to pick the + default session type the user is logged into. + + + diff --git a/shell-completion/bash/homectl b/shell-completion/bash/homectl index 527dd81c458..5e2235bc3b0 100644 --- a/shell-completion/bash/homectl +++ b/shell-completion/bash/homectl @@ -110,7 +110,9 @@ _homectl() { --auto-login -b --blob --avatar - --login-background' + --login-background + --session-launcher + --session-type' ) if __contains_word "$prev" ${OPTS[ARG]}; then @@ -153,6 +155,12 @@ _homectl() { --language) comps=$(localectl list-locales 2>/dev/null) ;; + --session-launcher) + comps=$(find /usr/share/{x,wayland-}sessions/ -type f -name '*.desktop' -exec basename {} .desktop \; 2>/dev/null | sort -u) + ;; + --session-type) + comps='wayland x11 tty' + ;; esac COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) return 0 diff --git a/src/home/homectl.c b/src/home/homectl.c index 4afdff74c03..11a138070b1 100644 --- a/src/home/homectl.c +++ b/src/home/homectl.c @@ -2701,6 +2701,9 @@ static int help(int argc, char *argv[], void *userdata) { " --kill-processes=BOOL Whether to kill user processes when sessions\n" " terminate\n" " --auto-login=BOOL Try to log this user in automatically\n" + " --session-launcher=LAUNCHER\n" + " Preferred session launcher file\n" + " --session-type=TYPE Preferred session type\n" "\nSee the %6$s for details.\n", program_invocation_short_name, ansi_highlight(), @@ -2777,6 +2780,8 @@ static int parse_argv(int argc, char *argv[]) { ARG_PASSWORD_CHANGE_INACTIVE, ARG_EXPORT_FORMAT, ARG_AUTO_LOGIN, + ARG_SESSION_LAUNCHER, + ARG_SESSION_TYPE, ARG_PKCS11_TOKEN_URI, ARG_FIDO2_DEVICE, ARG_FIDO2_WITH_PIN, @@ -2870,6 +2875,8 @@ static int parse_argv(int argc, char *argv[]) { { "password-change-warn", required_argument, NULL, ARG_PASSWORD_CHANGE_WARN }, { "password-change-inactive", required_argument, NULL, ARG_PASSWORD_CHANGE_INACTIVE }, { "auto-login", required_argument, NULL, ARG_AUTO_LOGIN }, + { "session-launcher", required_argument, NULL, ARG_SESSION_LAUNCHER, }, + { "session-type", required_argument, NULL, ARG_SESSION_TYPE, }, { "json", required_argument, NULL, ARG_JSON }, { "export-format", required_argument, NULL, ARG_EXPORT_FORMAT }, { "pkcs11-token-uri", required_argument, NULL, ARG_PKCS11_TOKEN_URI }, @@ -3009,7 +3016,9 @@ static int parse_argv(int argc, char *argv[]) { case ARG_CIFS_USER_NAME: case ARG_CIFS_DOMAIN: case ARG_CIFS_EXTRA_MOUNT_OPTIONS: - case ARG_LUKS_EXTRA_MOUNT_OPTIONS: { + case ARG_LUKS_EXTRA_MOUNT_OPTIONS: + case ARG_SESSION_LAUNCHER: + case ARG_SESSION_TYPE: { const char *field = c == ARG_EMAIL_ADDRESS ? "emailAddress" : @@ -3019,6 +3028,8 @@ static int parse_argv(int argc, char *argv[]) { c == ARG_CIFS_DOMAIN ? "cifsDomain" : c == ARG_CIFS_EXTRA_MOUNT_OPTIONS ? "cifsExtraMountOptions" : c == ARG_LUKS_EXTRA_MOUNT_OPTIONS ? "luksExtraMountOptions" : + c == ARG_SESSION_LAUNCHER ? "preferredSessionLauncher" : + c == ARG_SESSION_TYPE ? "preferredSessionType" : NULL; assert(field); diff --git a/src/shared/user-record-show.c b/src/shared/user-record-show.c index 086d344c011..23a41534ba5 100644 --- a/src/shared/user-record-show.c +++ b/src/shared/user-record-show.c @@ -575,6 +575,11 @@ void user_record_show(UserRecord *hr, bool show_full_group_info) { if (hr->auto_login >= 0) printf("Autom. Login: %s\n", yes_no(hr->auto_login)); + if (hr->preferred_session_launcher) + printf("Sess. Launch: %s\n", hr->preferred_session_launcher); + if (hr->preferred_session_type) + printf("Session Type: %s\n", hr->preferred_session_type); + if (hr->kill_processes >= 0) printf(" Kill Proc.: %s\n", yes_no(hr->kill_processes)); diff --git a/src/shared/user-record.c b/src/shared/user-record.c index fc39194ac55..fe102b004a1 100644 --- a/src/shared/user-record.c +++ b/src/shared/user-record.c @@ -189,6 +189,9 @@ static UserRecord* user_record_free(UserRecord *h) { free(h->state); free(h->service); + free(h->preferred_session_type); + free(h->preferred_session_launcher); + strv_free(h->pkcs11_token_uri); for (size_t i = 0; i < h->n_pkcs11_encrypted_key; i++) pkcs11_encrypted_key_done(h->pkcs11_encrypted_key + i); @@ -1340,6 +1343,8 @@ static int dispatch_per_machine(const char *name, JsonVariant *variant, JsonDisp { "rateLimitBurst", _JSON_VARIANT_TYPE_INVALID, json_dispatch_uint64, offsetof(UserRecord, ratelimit_burst), 0 }, { "enforcePasswordPolicy", JSON_VARIANT_BOOLEAN, json_dispatch_tristate, offsetof(UserRecord, enforce_password_policy), 0 }, { "autoLogin", JSON_VARIANT_BOOLEAN, json_dispatch_tristate, offsetof(UserRecord, auto_login), 0 }, + { "preferredSessionType", JSON_VARIANT_STRING, json_dispatch_string, offsetof(UserRecord, preferred_session_type), JSON_SAFE }, + { "preferredSessionLauncher", JSON_VARIANT_STRING, json_dispatch_string, offsetof(UserRecord, preferred_session_launcher), JSON_SAFE }, { "stopDelayUSec", _JSON_VARIANT_TYPE_INVALID, json_dispatch_uint64, offsetof(UserRecord, stop_delay_usec), 0 }, { "killProcesses", JSON_VARIANT_BOOLEAN, json_dispatch_tristate, offsetof(UserRecord, kill_processes), 0 }, { "passwordChangeMinUSec", _JSON_VARIANT_TYPE_INVALID, json_dispatch_uint64, offsetof(UserRecord, password_change_min_usec), 0 }, @@ -1683,6 +1688,8 @@ int user_record_load(UserRecord *h, JsonVariant *v, UserRecordLoadFlags load_fla { "rateLimitBurst", _JSON_VARIANT_TYPE_INVALID, json_dispatch_uint64, offsetof(UserRecord, ratelimit_burst), 0 }, { "enforcePasswordPolicy", JSON_VARIANT_BOOLEAN, json_dispatch_tristate, offsetof(UserRecord, enforce_password_policy), 0 }, { "autoLogin", JSON_VARIANT_BOOLEAN, json_dispatch_tristate, offsetof(UserRecord, auto_login), 0 }, + { "preferredSessionType", JSON_VARIANT_STRING, json_dispatch_string, offsetof(UserRecord, preferred_session_type), JSON_SAFE }, + { "preferredSessionLauncher", JSON_VARIANT_STRING, json_dispatch_string, offsetof(UserRecord, preferred_session_launcher), JSON_SAFE }, { "stopDelayUSec", _JSON_VARIANT_TYPE_INVALID, json_dispatch_uint64, offsetof(UserRecord, stop_delay_usec), 0 }, { "killProcesses", JSON_VARIANT_BOOLEAN, json_dispatch_tristate, offsetof(UserRecord, kill_processes), 0 }, { "passwordChangeMinUSec", _JSON_VARIANT_TYPE_INVALID, json_dispatch_uint64, offsetof(UserRecord, password_change_min_usec), 0 }, diff --git a/src/shared/user-record.h b/src/shared/user-record.h index 1819f55489c..cca112f5feb 100644 --- a/src/shared/user-record.h +++ b/src/shared/user-record.h @@ -351,6 +351,9 @@ typedef struct UserRecord { int auto_login; int drop_caches; + char *preferred_session_type; + char *preferred_session_launcher; + uint64_t stop_delay_usec; /* How long to leave systemd --user around on log-out */ int kill_processes; /* Whether to kill user processes forcibly on log-out */ -- 2.39.2