Skip to content

Commit

Permalink
WIP: use DialContextWithHostname()
Browse files Browse the repository at this point in the history
  • Loading branch information
arashpayan committed Nov 22, 2023
1 parent 4557339 commit 80ffcb7
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 11 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
8 changes: 3 additions & 5 deletions pkg/samba/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}

Expand All @@ -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 {
Expand Down Expand Up @@ -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(),
Expand Down
3 changes: 2 additions & 1 deletion pkg/samba/mount.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package samba

import (
"context"
"net"

"github.com/cloudsoda/go-smb2"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 80ffcb7

Please sign in to comment.