MCPcopy Create free account
hub / github.com/tailscale/tailscale / canSU

Method canSU

drive/driveimpl/remote_impl.go:433–452  ·  view source on GitHub ↗

canSU checks whether the current process can run su with the right username. If su can be run, this returns the path to the su command. If not, this returns the empty string "".

()

Source from the content-addressed store, hash-verified

431// If su can be run, this returns the path to the su command.
432// If not, this returns the empty string "".
433func (s *userServer) canSU() string {
434 su, err := exec.LookPath("su")
435 if err != nil {
436 s.logf("can't find su command: %v", err)
437 return ""
438 }
439
440 // First try to execute su <user> -c true to make sure we can su.
441 err = exec.Command(
442 su,
443 s.username,
444 "-c", "true",
445 ).Run()
446 if err != nil {
447 s.logf("su check failed: %s", err)
448 return ""
449 }
450
451 return su
452}
453
454// assertNotRoot returns an error if the current user has UID 0 or if we cannot
455// determine the current user.

Callers 1

runMethod · 0.95

Calls 2

RunMethod · 0.65
logfMethod · 0.45

Tested by

no test coverage detected