write_passphrase_to_secrets_file

Function write_passphrase_to_secrets_file 

Source
pub fn write_passphrase_to_secrets_file(
    secret_handling: NonAdministrativeSecretHandling,
    system_user: &User,
    backend_user: &str,
    passphrase: &Passphrase,
) -> Result<(), Error>
Expand description

Writes a Passphrase to a secret file location of a system user.

The secret file location is established based on the chosen secret_handling, system_user and backend_user.

§Note

This function must be run as root, as the secrets file is created for a specific system_user and the ownership of the resulting secrets file is adjusted in such a way that the system_user has access.

§Errors

Returns an error if

  • the effective user ID of the calling user is not that of root
  • the secret is a plaintext file, but reading it as a string fails
  • the secret needs to be encrypted using systemd-creds(1), but
    • systemd-creds(1) cannot be found or the systemd-creds(1) command
    • cannot be spawned in the background
    • cannot be attached to on stdin in the background
    • cannot be written to on its stdin
    • fails to execute
    • returned with a non-zero exit code
  • the file at path cannot be created
  • the file at path cannot be written to
  • the ownership of file at path cannot be changed to that of systemd-creds(1)
  • the file permissions of the file at path cannot be adjusted