Skip to content

Commit

Permalink
snapd/osutil: Fix adding new user to sudo group in AddExtraSudoUser
Browse files Browse the repository at this point in the history
This is not how adduser works.
  • Loading branch information
mwhudson committed Aug 9, 2016
1 parent 2d1ee2f commit 762bdb6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 5 additions & 1 deletion osutil/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,16 @@ func AddExtraSudoUser(name string, sshKeys []string, gecos string) error {
"--gecos", gecos,
"--extrausers",
"--disabled-password",
"--add_extra_groups", "sudo",
name)
if output, err := cmd.CombinedOutput(); err != nil {
return fmt.Errorf("adduser failed with %s: %s", err, output)
}

cmd = exec.Command("adduser", name, "sudo")
if output, err := cmd.CombinedOutput(); err != nil {
return fmt.Errorf("adding user to sudo group failed with %s: %s", err, output)
}

u, err := userLookup(name)
if err != nil {
return fmt.Errorf("cannot find user %q: %s", name, err)
Expand Down
3 changes: 2 additions & 1 deletion osutil/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ func (s *createUserSuite) TestAddExtraSudoUser(c *check.C) {
err := osutil.AddExtraSudoUser("karl", []string{"ssh-key1", "ssh-key2"}, "my gecos")
c.Assert(err, check.IsNil)
c.Check(mc.Calls(), check.DeepEquals, [][]string{
{"adduser", "--force-badname", "--gecos", "my gecos", "--extrausers", "--disabled-password", "--add_extra_groups", "sudo", "karl"},
{"adduser", "--force-badname", "--gecos", "my gecos", "--extrausers", "--disabled-password", "karl"},
{"adduser", "karl", "sudo"},
})
sshKeys, err := ioutil.ReadFile(filepath.Join(mockHome, ".ssh", "authorized_keys"))
c.Assert(err, check.IsNil)
Expand Down

0 comments on commit 762bdb6

Please sign in to comment.