import "github.com/hirochachacha/go-smb2"
Package smb2 implements the SMB2/3 client in [MS-SMB2].
https://msdn.microsoft.com/en-us/library/cc246482.aspx
This package doesn't support CAP_UNIX extension. Symlink is supported by FSCTL_SET_REPARSE_POINT and FSCTL_GET_REPARSE_POINT. The symlink-following algorithm is explained in 2.2.2.2.1 and 2.2.2.2.1.1.
https://msdn.microsoft.com/en-us/library/cc246542.aspx
Supported features and protocol versions are declared in feature.go.
Code:
conn, err := net.Dial("tcp", "localhost:445")
if err != nil {
panic(err)
}
defer conn.Close()
d := &smb2.Dialer{
Initiator: &smb2.NTLMInitiator{
User: "Guest",
Password: "",
Domain: "MicrosoftAccount",
},
}
c, err := d.Dial(conn)
if err != nil {
panic(err)
}
defer c.Logoff()
fs, err := c.Mount(`\\localhost\share`)
if err != nil {
panic(err)
}
defer fs.Umount()
f, err := fs.Create("hello.txt")
if err != nil {
panic(err)
}
defer fs.Remove("hello.txt")
defer f.Close()
_, err = f.Write([]byte("Hello world!"))
if err != nil {
panic(err)
}
_, err = f.Seek(0, io.SeekStart)
if err != nil {
panic(err)
}
bs, err := ioutil.ReadAll(f)
if err != nil {
panic(err)
}
fmt.Println(string(bs))
// Hello world!
alias.go all.go client.go conn.go credit.go errors.go feature.go initiator.go kdf.go path.go session.go smb2.go spnego.go transport.go tree_conn.go
const MaxReadSizeLimit = 0x100000
MaxReadSizeLimit limits maxReadSize from negotiate data
const PathSeparator = '\\'
ContextError wraps a context error to support os.IsTimeout function.
func (err *ContextError) Error() string
func (err *ContextError) Timeout() bool
type Dialer struct { MaxCreditBalance uint16 // if it's zero, clientMaxCreditBalance is used. (See feature.go for more details) Negotiator Negotiator Initiator Initiator }
Dialer contains options for func (*Dialer) Dial.
Dial performs negotiation and authentication. It returns a session. It doesn't support NetBIOS transport. This implementation doesn't support multi-session on the same TCP connection. If you want to use another session, you need to prepare another TCP connection at first.
DialContext performs negotiation and authentication using the provided context. Note that returned session doesn't inherit context. If you want to use the same context, call Session.WithContext manually. This implementation doesn't support multi-session on the same TCP connection. If you want to use another session, you need to prepare another TCP connection at first.
type File struct {
// contains filtered or unexported fields
}
ReadAt implements io.ReaderAt.
ReadFrom implements io.ReadFrom. If r is *File on the same *Share as f, it invokes server-side copy.
Seek implements io.Seeker.
func (f *File) Statfs() (FileFsInfo, error)
WriteAt implements io.WriterAt.
WriteTo implements io.WriteTo. If w is *File on the same *Share as f, it invokes server-side copy.
type FileFsInfo interface { BlockSize() uint64 FragmentSize() uint64 TotalBlockCount() uint64 FreeBlockCount() uint64 AvailableBlockCount() uint64 }
type FileStat struct { CreationTime time.Time LastAccessTime time.Time LastWriteTime time.Time ChangeTime time.Time EndOfFile int64 AllocationSize int64 FileAttributes uint32 FileName string }
type Initiator interface {
// contains filtered or unexported methods
}
InternalError represents internal error.
func (err *InternalError) Error() string
InvalidResponseError represents a data sent by the server is corrupted or unexpected.
func (err *InvalidResponseError) Error() string
type NTLMInitiator struct { User string Password string Hash []byte Domain string Workstation string TargetSPN string // contains filtered or unexported fields }
NTLMInitiator implements session-setup through NTLMv2. It doesn't support NTLMv1. You can use Hash instead of Password.
type Negotiator struct { RequireMessageSigning bool // enforce signing? ClientGuid [16]byte // if it's zero, generated by crypto/rand. SpecifiedDialect uint16 // if it's zero, clientDialects is used. (See feature.go for more details) }
Negotiator contains options for func (*Dialer) Dial.
ResponseError represents a error with a nt status code sent by the server. The NTSTATUS is defined in [MS-ERREF]. https://msdn.microsoft.com/en-au/library/cc704588.aspx
func (err *ResponseError) Error() string
type Session struct {
// contains filtered or unexported fields
}
Session represents a SMB session.
Logoff invalidates the current SMB session.
Mount mounts the SMB share. sharename must follow format like `<share>` or `\\<server>\<share>`. Note that the mounted share doesn't inherit session's context. If you want to use the same context, call Share.WithContext manually.
type Share struct {
// contains filtered or unexported fields
}
Share represents a SMB tree connection with VFS interface.
MkdirAll mimics os.MkdirAll
RemoveAll removes path and any children it contains. It removes everything it can but returns the first error it encounters. If the path does not exist, RemoveAll returns nil (no error).
func (fs *Share) Statfs(name string) (FileFsInfo, error)
Symlink mimics os.Symlink. This API should work on latest Windows and latest MacOS. However it may not work on Linux because Samba doesn't support reparse point well. Also there is a restriction on target pathname. Generally, a pathname begins with leading backslash (e.g `\dir\name`) can be interpreted as two ways. On windows, it is evaluated as a relative path, on other systems, it is evaluated as an absolute path. This implementation always assumes that format is absolute path. So, if you know the target server is Windows, you should avoid that format. If you want to use an absolute target path on windows, you can use // `C:\dir\name` format instead.
Umount disconects the current SMB tree.
TransportError represents a error come from net.Conn layer.
func (err *TransportError) Error() string
Path | Synopsis |
---|---|
internal/crypto/ccm | |
internal/crypto/cmac | |
internal/erref | |
internal/msrpc | |
internal/ntlm | |
internal/smb2 | |
internal/spnego | |
internal/utf16le |
Package smb2 imports 34 packages (graph) and is imported by 1 packages. Updated 2020-10-30. Refresh now. Tools for package owners.