Merge pull request #24273 from lnussel/refactor_sysuser_creds
Refactor sysuser creds
This commit is contained in:
@@ -83,6 +83,38 @@ int read_credential(const char *name, void **ret, size_t *ret_size) {
|
||||
(char**) ret, ret_size);
|
||||
}
|
||||
|
||||
int get_credential_user_password(const char *username, char **ret_password, bool *ret_is_hashed) {
|
||||
_cleanup_(erase_and_freep) char *creds_password = NULL;
|
||||
_cleanup_free_ char *cn = NULL;
|
||||
int r;
|
||||
|
||||
/* Try to pick up the password for this account via the credentials logic */
|
||||
cn = strjoin("passwd.hashed-password.", username);
|
||||
if (!cn)
|
||||
return -ENOMEM;
|
||||
|
||||
r = read_credential(cn, (void**) &creds_password, NULL);
|
||||
if (r == -ENOENT) {
|
||||
free(cn);
|
||||
cn = strjoin("passwd.plaintext-password.", username);
|
||||
if (!cn)
|
||||
return -ENOMEM;
|
||||
|
||||
r = read_credential(cn, (void**) &creds_password, NULL);
|
||||
if (r < 0)
|
||||
log_debug_errno(r, "Couldn't read credential '%s', ignoring: %m", cn);
|
||||
else
|
||||
*ret_is_hashed = false;
|
||||
} else if (r < 0)
|
||||
log_debug_errno(r, "Couldn't read credential '%s', ignoring: %m", cn);
|
||||
else
|
||||
*ret_is_hashed = true;
|
||||
|
||||
*ret_password = TAKE_PTR(creds_password);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
#if HAVE_OPENSSL
|
||||
|
||||
#define CREDENTIAL_HOST_SECRET_SIZE 4096
|
||||
|
||||
@@ -44,6 +44,8 @@ typedef enum CredentialSecretFlags {
|
||||
|
||||
int get_credential_host_secret(CredentialSecretFlags flags, void **ret, size_t *ret_size);
|
||||
|
||||
int get_credential_user_password(const char *username, char **ret_password, bool *ret_is_hashed);
|
||||
|
||||
/* The four modes we support: keyed only by on-disk key, only by TPM2 HMAC key, and by the combination of
|
||||
* both, as well as one with a fixed zero length key if TPM2 is missing (the latter of course provides no
|
||||
* authenticity or confidentiality, but is still useful for integrity protection, and makes things simpler
|
||||
|
||||
Reference in New Issue
Block a user