diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2020-09-08 14:52:13 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2020-09-15 09:30:56 +0200 |
commit | 0e98d17e77a024a16fc15589b2b21bb6196d4567 (patch) | |
tree | dcd69b9b40f5b0001ee8251461e3df82d592c12c /src/firstboot/firstboot.c | |
parent | 6743a1caf4037f03dc51a1277855018e4ab61957 (diff) | |
download | systemd-0e98d17e77a024a16fc15589b2b21bb6196d4567.tar.gz |
Add a helper function that does make_salt+crypt_r
No functional change.
Diffstat (limited to 'src/firstboot/firstboot.c')
-rw-r--r-- | src/firstboot/firstboot.c | 17 |
1 files changed, 5 insertions, 12 deletions
diff --git a/src/firstboot/firstboot.c b/src/firstboot/firstboot.c index f8499a6ffd..3109f9cdfc 100644 --- a/src/firstboot/firstboot.c +++ b/src/firstboot/firstboot.c @@ -802,7 +802,7 @@ static int write_root_shadow(const char *shadow_path, const char *hashed_passwor static int process_root_args(void) { _cleanup_close_ int lock = -1; - struct crypt_data cd = {}; + _cleanup_(erase_and_freep) char *_hashed_password = NULL; const char *password, *hashed_password; const char *etc_passwd, *etc_shadow; int r; @@ -866,20 +866,13 @@ static int process_root_args(void) { password = "x"; hashed_password = arg_root_password; } else if (arg_root_password) { - _cleanup_free_ char *salt = NULL; - /* hashed_password points inside cd after crypt_r returns so cd has function scope. */ + r = hash_password(arg_root_password, &_hashed_password); + if (r < 0) + return log_error_errno(r, "Failed to hash password: %m"); password = "x"; + hashed_password = _hashed_password; - r = make_salt(&salt); - if (r < 0) - return log_error_errno(r, "Failed to get salt: %m"); - - errno = 0; - hashed_password = crypt_r(arg_root_password, salt, &cd); - if (!hashed_password) - return log_error_errno(errno == 0 ? SYNTHETIC_ERRNO(EINVAL) : errno, - "Failed to encrypt password: %m"); } else if (arg_delete_root_password) password = hashed_password = ""; else |