libsmbclient

package module
v0.0.0-...-b69795f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 7, 2022 License: MIT Imports: 5 Imported by: 0

README

Go Bindings for libsmbclient

PkgGoDev Tests report Go Report Card License

Bindings (read-only for now) for the libsmbclient library from samba. To compile on debian/ubuntu install the "libsmbclient-dev" package.

Build it with:

$ go build ./cmd/smb
$ ./smb -show-dir smb://localhost

Check main.go for a code example.

Limitation:

The C libsmbclient from samba is not thread safe, so all go smbclient.Client/smbclient.File operations are serialized (i.e. there can only be one operation at a time for each Client/File). As a workaround you should create one smbclient.Client per goroutine.

Example usage:

import (
       "fmt"

       "github.com/mvo5/libsmbclient-go"
)

client := smbclient.New()
dh, err := client.Opendir("smb://localhost")
if err != nil {
    return err
}
defer dh.Closedir()
for {
    dirent, err := dh.Readdir()
    if err != nil {
       break
    }
    fmt.Println(dirent)
}

Documentation

Index

Examples

Constants

View Source
const (
	// SmbcWorkgroup is a workgroup entity.
	SmbcWorkgroup SmbcType = C.SMBC_WORKGROUP
	// SmbcFileShare is a file share.
	SmbcFileShare = C.SMBC_FILE_SHARE
	// SmbcPrinterShare is a printer share.
	SmbcPrinterShare = C.SMBC_PRINTER_SHARE
	// SmbcCommsShare is a communication share.
	SmbcCommsShare = C.SMBC_COMMS_SHARE
	// SmbcIPCShare is an ipc share entity.
	SmbcIPCShare = C.SMBC_IPC_SHARE
	// SmbcDir is a directory.
	SmbcDir = C.SMBC_DIR
	// SmbcFile is a file.
	SmbcFile = C.SMBC_FILE
	// SmbcLink is a symlink.
	SmbcLink = C.SMBC_LINK
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthCallback

type AuthCallback = func(serverName, shareName string) (domain, username, password string)

AuthCallback is the authentication function that will be called during connection with samba.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a samba client instance, handling its own context and lock.

func New

func New() *Client

New creates a new samba client.

Example
client := libsmbclient.New()
dh, err := client.Opendir("smb://localhost")
if err != nil {
	log.Fatal(err)
}
defer dh.Closedir()
for {
	dirent, err := dh.Readdir()
	if err != nil {
		break
	}
	fmt.Println(dirent)
}
Output:

func (*Client) Close

func (c *Client) Close() error

Close closes the current samba client and release context.

func (*Client) Destroy

func (c *Client) Destroy() error

Destroy closes the current samba client.

func (*Client) GetDebug

func (c *Client) GetDebug() int

GetDebug returns the debug level.

func (*Client) GetUser

func (c *Client) GetUser() string

GetUser returns the authenticated user.

func (*Client) GetWorkgroup

func (c *Client) GetWorkgroup() string

GetWorkgroup returns the name of the current workgroup.

func (*Client) Open

func (c *Client) Open(furl string, flags, mode int) (File, error)

Open opens a file and returns a handle on success. FIXME: mode is actually "mode_t mode"

func (*Client) Opendir

func (c *Client) Opendir(durl string) (File, error)

Opendir opens a directory and returns a handle on success.

func (*Client) SetAuthCallback

func (c *Client) SetAuthCallback(f AuthCallback)

SetAuthCallback assigns the authentication function that will be called during connection with samba.

func (*Client) SetDebug

func (c *Client) SetDebug(level int)

SetDebug sets the degug level.

func (*Client) SetUseKerberos

func (c *Client) SetUseKerberos()

SetUseKerberos enable krb5 integration for authentication.

func (*Client) SetUser

func (c *Client) SetUser(user string)

SetUser sets the user to use for the session.

func (*Client) SetWorkgroup

func (c *Client) SetWorkgroup(wg string)

SetWorkgroup sets the work group to use for the session.

type Dirent

type Dirent struct {
	Type    SmbcType
	Comment string
	Name    string
}

Dirent represents a samba directory entry.

type File

type File struct {
	// contains filtered or unexported fields
}

File reprends a samba file.

func (*File) Close

func (e *File) Close()

Close closes current file and and releases its ressources.

func (*File) Closedir

func (e *File) Closedir() error

Closedir closes current directory.

func (*File) Lseek

func (e *File) Lseek(offset, whence int) (int, error)

Lseek repositions the file offset of the open file to the argument offset according to the directive whence.

func (*File) Read

func (e *File) Read(buf []byte) (int, error)

Read reads up to len(b) bytes from the File. It returns the number of bytes read and any error encountered. At end of file, Read returns 0, io.EOF.

func (*File) Readdir

func (e *File) Readdir() (*Dirent, error)

Readdir reads the directory named pointed by File and returned its Dirent.

type SmbcType

type SmbcType int

SmbcType is the different type of entity returned by samba.

Directories

Path Synopsis
cmd
smb

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL