Skip to content

Commit

Permalink
Merge pull request #501 from PawelWMS/pawelwi/user_password_fix_merge
Browse files Browse the repository at this point in the history
* Regression fix to setting the user password for generated images.
  • Loading branch information
PawelWMS authored Dec 29, 2020
2 parents 153dedb + 0abb891 commit 9142048
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions toolkit/tools/imagegen/installutils/installutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -862,8 +862,9 @@ func addUsers(installChroot *safechroot.Chroot, users []configuration.User) (err
if !rootUserAdded {
logger.Log.Debugf("No root user entry found in config file. Setting root password to never expire.")

// Ignore updating if there is no shadow file to update
if exists, ferr := file.PathExists(shadowFile); ferr != nil {
// Ignore updating if there is no shadow file to update in the target image
installChrootShadowFile := filepath.Join(installChroot.RootDir(), shadowFile)
if exists, ferr := file.PathExists(installChrootShadowFile); ferr != nil {
logger.Log.Error("Error accessing shadow file.")
return ferr
} else if !exists {
Expand All @@ -887,10 +888,11 @@ func createUserWithPassword(installChroot *safechroot.Chroot, user configuration
)

var (
hashedPassword string
stdout string
stderr string
salt string
hashedPassword string
stdout string
stderr string
salt string
installChrootShadowFile = filepath.Join(installChroot.RootDir(), shadowFile)
)

// Get the hashed password for the user
Expand Down Expand Up @@ -926,7 +928,7 @@ func createUserWithPassword(installChroot *safechroot.Chroot, user configuration
logger.Log.Warnf("Ignoring UID for (%s) user, using default", rootUser)
}

if exists, ferr := file.PathExists(shadowFile); ferr != nil {
if exists, ferr := file.PathExists(installChrootShadowFile); ferr != nil {
logger.Log.Error("Error accessing shadow file.")
err = ferr
return
Expand Down Expand Up @@ -961,7 +963,7 @@ func createUserWithPassword(installChroot *safechroot.Chroot, user configuration
// Update password expiration
if user.PasswordExpiresDays != 0 {
// Ignore updating if there is no shadow file to update
if exists, ferr := file.PathExists(shadowFile); ferr != nil {
if exists, ferr := file.PathExists(installChrootShadowFile); ferr != nil {
logger.Log.Error("Error accessing shadow file.")
err = ferr
return
Expand Down

0 comments on commit 9142048

Please sign in to comment.