canSudo checks whether we can sudo -u the configured executable as the configured user by attempting to call the executable with the '-h' flag to print help.
()
| 419 | // configured user by attempting to call the executable with the '-h' flag to |
| 420 | // print help. |
| 421 | func (s *userServer) canSudo() bool { |
| 422 | ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second) |
| 423 | defer cancel() |
| 424 | if err := exec.CommandContext(ctx, "sudo", "-n", "-u", s.username, s.executable, "-h").Run(); err != nil { |
| 425 | return false |
| 426 | } |
| 427 | return true |
| 428 | } |
| 429 | |
| 430 | // canSU checks whether the current process can run su with the right username. |
| 431 | // If su can be run, this returns the path to the su command. |