Skip to content

Robin-Van-de-Merghel/libsmbclient-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

83 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Bindings for libsmbclient

PkgGoDev Go Report Card License

Note

Forked from mvo5/libsmbclient-go

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 generate ./... # Generate stringer files 
$ go build ./cmd/smb/main.go
$ ./smb ls smb://localhost

Tip

The code above assumes you have a running samba service. You can start one from the docker-compose file:

$ cd test
$ docker-compose up -d

The default creds are user1/password1, with two usable shares:

  1. public
  2. private

Check main.go for a code example.

Fork note:

The original project was not updated for four years. My goal is to update it, and add some features to use it in another personal project.

Note

It is my first time playing with cgo and doing a "real" library. Feel free to help and correct me!

Roadmap/Features:

In another project called GoExec, I am trying to reproduce netexec. It is my reason for developing this library. Globally the current roadmap is:

  • List shares on a server
  • Read files from a share (note: need to be updated)
  • Kerberos [not tested]
  • Basic auth (username/password)
  • Hash auth
  • Creating files
  • Uploading files
  • Deleting files
  • Bug fixes
  • Get metadata [NEW]
  • ...
  • Feel free to suggest!

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/robin-van-de-merghel/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)
}

You can also get metadata from a share/file by default:

Name (public): Attributes (SMBAttributes(
        acls=[
        ACLAttributes(
                name=175A113BC9F8\nobody,
                type=0,
                flag=0,
                masks=FILE_READ_DATA,FILE_WRITE_DATA,FILE_APPEND_DATA,FILE_READ_EA,FILE_WRITE_EA,FILE_EXECUTE,FILE_DELETE_CHILD,FILE_READ_ATTRIBUTES,FILE_WRITE_ATTRIBUTES,DELETE,READ_CONTRO
L,WRITE_DAC,WRITE_OWNER,SYNCHRONIZE,);
        ACLAttributes(
                name=Unix Group\root,
                type=0,
                flag=0,
                masks=FILE_READ_DATA,FILE_READ_EA,FILE_EXECUTE,FILE_READ_ATTRIBUTES,READ_CONTROL,SYNCHRONIZE,);],
        revisions=[1,],
        owners=[175A113BC9F8\nobody,],
        groups=[Unix Group\root,]
))

About

Go bindings for libsmbclient

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •