From 83871f0501084b0cf0dcbf3288ce06bdd1ddf5b5 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Mon, 3 May 2021 09:57:17 -0700 Subject: [PATCH] cmd/tailscale: make 'file cp' have better error messages on bad targets Say when target isn't owned by current user, and when target doesn't exist in netmap. Signed-off-by: Brad Fitzpatrick --- cmd/tailscale/cli/file.go | 30 ++++++++++++++++++++++++++++-- cmd/tailscale/depaware.txt | 2 +- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/cmd/tailscale/cli/file.go b/cmd/tailscale/cli/file.go index 70aaac4eb..7b6e45600 100644 --- a/cmd/tailscale/cli/file.go +++ b/cmd/tailscale/cli/file.go @@ -29,6 +29,7 @@ "tailscale.com/client/tailscale" "tailscale.com/client/tailscale/apitype" "tailscale.com/ipn" + "tailscale.com/net/tsaddr" "tailscale.com/version" ) @@ -98,7 +99,7 @@ func runCp(ctx context.Context, args []string) error { peerAPIBase, lastSeen, isOffline, err := discoverPeerAPIBase(ctx, ip) if err != nil { - return err + return fmt.Errorf("can't send to %s: %v", target, err) } if isOffline { fmt.Fprintf(os.Stderr, "# warning: %s is offline\n", target) @@ -203,7 +204,32 @@ func discoverPeerAPIBase(ctx context.Context, ipStr string) (base string, lastSe return ft.PeerAPIURL, lastSeen, isOffline, nil } } - return "", time.Time{}, false, errors.New("target seems to be running an old Tailscale version") + return "", time.Time{}, false, fileTargetErrorDetail(ctx, ip) +} + +// fileTargetErrorDetail returns a non-nil error saying why ip is an +// invalid file sharing target. +func fileTargetErrorDetail(ctx context.Context, ip netaddr.IP) error { + found := false + if st, err := tailscale.Status(ctx); err == nil && st.Self != nil { + for _, peer := range st.Peer { + for _, pip := range peer.TailscaleIPs { + if pip == ip { + found = true + if peer.UserID != st.Self.UserID { + return errors.New("owned by different user; can only send files to your own devices") + } + } + } + } + } + if found { + return errors.New("target seems to be running an old Tailscale version") + } + if !tsaddr.IsTailscaleIP(ip) { + return fmt.Errorf("unknown target; %v is not a Tailscale IP address", ip) + } + return errors.New("unknown target; not in your Tailnet") } const maxSniff = 4 << 20 diff --git a/cmd/tailscale/depaware.txt b/cmd/tailscale/depaware.txt index 1f97abce9..89f722e8b 100644 --- a/cmd/tailscale/depaware.txt +++ b/cmd/tailscale/depaware.txt @@ -33,7 +33,7 @@ tailscale.com/cmd/tailscale dependencies: (generated by github.com/tailscale/dep tailscale.com/net/portmapper from tailscale.com/net/netcheck+ tailscale.com/net/stun from tailscale.com/net/netcheck tailscale.com/net/tlsdial from tailscale.com/derp/derphttp - tailscale.com/net/tsaddr from tailscale.com/net/interfaces + tailscale.com/net/tsaddr from tailscale.com/net/interfaces+ 💣 tailscale.com/net/tshttpproxy from tailscale.com/derp/derphttp+ tailscale.com/paths from tailscale.com/cmd/tailscale/cli+ tailscale.com/safesocket from tailscale.com/cmd/tailscale/cli+