Issue #672: Change the grep pattern
This pattern ensures the user "cloudflared" more precisely
This commit is contained in:
parent
c219cc24a4
commit
bdce0a39e8
|
@ -273,7 +273,7 @@ func installSystemd(templateArgs *ServiceTemplateArgs, log *zerolog.Logger) erro
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Create the cloudflared user if it does not exist
|
// Create the cloudflared user if it does not exist
|
||||||
if err := runCommand("grep", "-qw", fmt.Sprintf("^%s", cloudflaredUser), "/etc/passwd"); err != nil {
|
if err := runCommand("grep", "-q", fmt.Sprintf("^%s:", cloudflaredUser), "/etc/passwd"); err != nil {
|
||||||
if err := runCommand("useradd", "--system", "--no-create-home", "--home-dir=/nonexistent", "--shell=/usr/sbin/nologin", cloudflaredUser); err != nil {
|
if err := runCommand("useradd", "--system", "--no-create-home", "--home-dir=/nonexistent", "--shell=/usr/sbin/nologin", cloudflaredUser); err != nil {
|
||||||
log.Err(err).Msgf("useradd %s error", cloudflaredUser)
|
log.Err(err).Msgf("useradd %s error", cloudflaredUser)
|
||||||
return err
|
return err
|
||||||
|
@ -350,7 +350,7 @@ func uninstallSystemd(log *zerolog.Logger) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// Delete the cloudflared user if it exists
|
// Delete the cloudflared user if it exists
|
||||||
if err := runCommand("grep", "-qw", fmt.Sprintf("^%s", cloudflaredUser), "/etc/passwd"); err == nil {
|
if err := runCommand("grep", "-q", fmt.Sprintf("^%s:", cloudflaredUser), "/etc/passwd"); err == nil {
|
||||||
if err := runCommand("userdel", cloudflaredUser); err != nil {
|
if err := runCommand("userdel", cloudflaredUser); err != nil {
|
||||||
log.Err(err).Msgf("userdel %s error", cloudflaredUser)
|
log.Err(err).Msgf("userdel %s error", cloudflaredUser)
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in New Issue