Skip to content

Commit

Permalink
Escape password in cifs command line
Browse files Browse the repository at this point in the history
  • Loading branch information
netixx committed Nov 26, 2017
1 parent 9092db7 commit 23d5996
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions netshare/drivers/cifs.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,10 @@ func (c CifsDriver) mountVolume(name, source, dest string, creds *CifsCreds) err
}

if user != "" {
opts.WriteString(fmt.Sprintf("username=%s,", user))
// escape single quotes in password character as it will be quoted in command line
opts.WriteString(fmt.Sprintf("username='%s',", strings.Replace(user, "'", "\\'", -1)))
if pass != "" {
opts.WriteString(fmt.Sprintf("password=%s,", pass))
opts.WriteString(fmt.Sprintf("password='%s',", strings.Replace(pass, "'", "\\'", -1)))
}
} else {
opts.WriteString("guest,")
Expand All @@ -245,7 +246,7 @@ func (c CifsDriver) mountVolume(name, source, dest string, creds *CifsCreds) err

opts.WriteString(fmt.Sprintf("%s %s", source, dest))
cmd := fmt.Sprintf("mount -t cifs -o %s", opts.String())
log.Debugf("Executing: %s\n", strings.Replace(cmd, "password="+pass, "password=****", 1))
log.Debugf("Executing: %s\n", strings.Replace(cmd, "password='"+pass+"'", "password='****'", 1))
return run(cmd)
}

Expand Down

0 comments on commit 23d5996

Please sign in to comment.