MCPcopy
hub / github.com/containers/toolbox / configureUsers

Function configureUsers

src/cmd/initContainer.go:791–857  ·  view source on GitHub ↗
(targetUserUid int, targetUser, targetUserHome, targetUserShell string, homeLink bool)

Source from the content-addressed store, hash-verified

789}
790
791func configureUsers(targetUserUid int, targetUser, targetUserHome, targetUserShell string, homeLink bool) error {
792 if homeLink {
793 if err := redirectPath("/home", "/var/home", true); err != nil {
794 return err
795 }
796 }
797
798 sudoGroup, err := utils.GetGroupForSudo()
799 if err != nil {
800 return fmt.Errorf("failed to get group for sudo: %w", err)
801 }
802
803 if _, err := user.Lookup(targetUser); err != nil {
804 logrus.Debugf("Adding user %s with UID %d:", targetUser, targetUserUid)
805
806 useraddArgs := []string{
807 "--groups", sudoGroup,
808 "--home-dir", targetUserHome,
809 "--no-create-home",
810 "--password", "",
811 "--shell", targetUserShell,
812 "--uid", fmt.Sprint(targetUserUid),
813 targetUser,
814 }
815
816 logrus.Debug("useradd")
817 for _, arg := range useraddArgs {
818 logrus.Debugf("%s", arg)
819 }
820
821 if err := shell.Run("useradd", nil, nil, nil, useraddArgs...); err != nil {
822 return fmt.Errorf("failed to add user %s with UID %d: %w", targetUser, targetUserUid, err)
823 }
824 } else {
825 logrus.Debugf("Modifying user %s with UID %d:", targetUser, targetUserUid)
826
827 usermodArgs := []string{
828 "--append",
829 "--groups", sudoGroup,
830 "--home", targetUserHome,
831 "--password", "",
832 "--shell", targetUserShell,
833 "--uid", fmt.Sprint(targetUserUid),
834 targetUser,
835 }
836
837 logrus.Debug("usermod")
838 for _, arg := range usermodArgs {
839 logrus.Debugf("%s", arg)
840 }
841
842 if err := shell.Run("usermod", nil, nil, nil, usermodArgs...); err != nil {
843 return fmt.Errorf("failed to modify user %s with UID %d: %w", targetUser, targetUserUid, err)
844 }
845 }
846
847 logrus.Debug("Removing password for user root")
848

Callers 1

initContainerFunction · 0.85

Calls 1

redirectPathFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…