From 80ffcb73ff7fb0a7422177464b742bbffc572b11 Mon Sep 17 00:00:00 2001 From: Arash Payan Date: Tue, 21 Nov 2023 17:48:51 -0800 Subject: [PATCH] WIP: use DialContextWithHostname() --- README.md | 4 ++-- go.mod | 4 +++- go.sum | 2 -- pkg/samba/address.go | 8 +++----- pkg/samba/mount.go | 3 ++- 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 8fa33e2..15be020 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,6 @@ $ carnival -u user shares smb://address Password: ``` -If the username is set through the `-u/--username` flag, the password will be prompted +If the `-u/--username` flag is set, you will be prompted for the password. -If no username is set, an anonymous session will be attempted +If no username is provided, carnival will attempt to authenticate anonymously. diff --git a/go.mod b/go.mod index f756fc1..9f71222 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.21.4 require ( github.com/charmbracelet/bubbles v0.15.0 github.com/charmbracelet/lipgloss v0.6.0 - github.com/cloudsoda/go-smb2 v0.0.0-20231106205947-b0758ecc4c67 + github.com/cloudsoda/go-smb2 v0.0.0 github.com/rs/zerolog v1.29.0 github.com/stretchr/testify v1.8.3 github.com/urfave/cli/v2 v2.25.0 @@ -39,3 +39,5 @@ require ( golang.org/x/text v0.14.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) + +replace github.com/cloudsoda/go-smb2 => ../go-smb2 diff --git a/go.sum b/go.sum index fcba579..bb27c94 100644 --- a/go.sum +++ b/go.sum @@ -11,8 +11,6 @@ github.com/charmbracelet/bubbletea v0.23.2/go.mod h1:FaP3WUivcTM0xOKNmhciz60M6I+ github.com/charmbracelet/harmonica v0.2.0/go.mod h1:KSri/1RMQOZLbw7AHqgcBycp8pgJnQMYYT8QZRqZ1Ao= github.com/charmbracelet/lipgloss v0.6.0 h1:1StyZB9vBSOyuZxQUcUwGr17JmojPNm87inij9N3wJY= github.com/charmbracelet/lipgloss v0.6.0/go.mod h1:tHh2wr34xcHjC2HCXIlGSG1jaDF0S0atAUvBMP6Ppuk= -github.com/cloudsoda/go-smb2 v0.0.0-20231106205947-b0758ecc4c67 h1:KzZU0EMkUm4vX/jPp5d/VttocDpocL/8QP0zyiI9Xiw= -github.com/cloudsoda/go-smb2 v0.0.0-20231106205947-b0758ecc4c67/go.mod h1:xFxVVe3plxwhM+6BgTTPByEgG8hggo8+gtRUkbc5W8Q= github.com/containerd/console v1.0.3 h1:lIr7SlA5PxZyMV30bDW0MGbiOPXwc63yRuCP0ARubLw= github.com/containerd/console v1.0.3/go.mod h1:7LqA/THxQ86k76b8c/EMSiaJ3h1eZkMkXar0TQ1gf3U= github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= diff --git a/pkg/samba/address.go b/pkg/samba/address.go index 5f68aca..d485384 100644 --- a/pkg/samba/address.go +++ b/pkg/samba/address.go @@ -24,8 +24,8 @@ type URL struct { Credentials *Credentials } -// credentialsFromContext gets username from cli context and if set, it prompts the password from the terminal. -// If the flag is not set, then empty credentials will be returned (for anonymous session). +// credentialsFromContext gets username from ctx and if set, prompts the user for a password. +// If the username is not set, nil Credentials will be returned. func credentialsFromContext(ctx *cli.Context) (*Credentials, error) { creds := &Credentials{} @@ -42,7 +42,7 @@ func credentialsFromContext(ctx *cli.Context) (*Credentials, error) { return creds, nil } -// promptForPassword prompts password from terminal without echoing it +// promptForPassword prompts for a password via the terminal func promptForPassword() (string, error) { _, err := fmt.Fprint(os.Stderr, "Password:") if err != nil { @@ -89,11 +89,9 @@ func newURL(str string, creds *Credentials) (URL, error) { if u.Port() == "" { u2.Address = u.Hostname() + ":445" } - if creds != nil { u2.Credentials = creds } - if u.User != nil { u2.Credentials = &Credentials{ Username: u.User.Username(), diff --git a/pkg/samba/mount.go b/pkg/samba/mount.go index 96c7a2d..6a289ac 100644 --- a/pkg/samba/mount.go +++ b/pkg/samba/mount.go @@ -1,6 +1,7 @@ package samba import ( + "context" "net" "github.com/cloudsoda/go-smb2" @@ -35,7 +36,7 @@ func connect(u URL, domain string) (*smb2.Session, error) { d.Initiator = &smb2.NTLMInitiator{} } - srvr, err := d.Dial(conn) + srvr, err := d.DialContextWithHostname(context.Background(), conn, u.Address) if err != nil { conn.Close() return nil, err