From bdce0a39e8eef6bea23485f26bcd8d90615b9e3a Mon Sep 17 00:00:00 2001 From: Yonatan Romero Date: Mon, 19 Sep 2022 18:04:47 +0200 Subject: [PATCH] Issue #672: Change the grep pattern This pattern ensures the user "cloudflared" more precisely --- cmd/cloudflared/linux_service.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/cloudflared/linux_service.go b/cmd/cloudflared/linux_service.go index 6117011a..9147e209 100644 --- a/cmd/cloudflared/linux_service.go +++ b/cmd/cloudflared/linux_service.go @@ -273,7 +273,7 @@ func installSystemd(templateArgs *ServiceTemplateArgs, log *zerolog.Logger) erro } } // 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 { log.Err(err).Msgf("useradd %s error", cloudflaredUser) return err @@ -350,7 +350,7 @@ func uninstallSystemd(log *zerolog.Logger) error { return err } // 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 { log.Err(err).Msgf("userdel %s error", cloudflaredUser) return err