Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SMB2_0_INFO_SECURITY request support #65

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 133 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,40 @@ func (fs *Share) Statfs(name string) (FileFsInfo, error) {
return fi, nil
}

func (fs *Share) Security(name string) (*FileSecurityInfo, error) {
name = normPath(name)

if err := validatePath("security", name, false); err != nil {
return nil, err
}

create := &CreateRequest{
SecurityFlags: 0,
RequestedOplockLevel: SMB2_OPLOCK_LEVEL_NONE,
ImpersonationLevel: Impersonation,
SmbCreateFlags: 0,
DesiredAccess: READ_CONTROL,
FileAttributes: 0,
ShareAccess: FILE_SHARE_READ,
CreateDisposition: FILE_OPEN,
CreateOptions: 0,
}

f, err := fs.createFile(name, create, true)
if err != nil {
return nil, &os.PathError{Op: "security", Path: name, Err: err}
}

fi, err := f.security()
if e := f.close(); err == nil {
err = e
}
if err != nil {
return nil, &os.PathError{Op: "security", Path: name, Err: err}
}
return fi, nil
}

func (fs *Share) createFile(name string, req *CreateRequest, followSymlinks bool) (f *File, err error) {
if followSymlinks {
return fs.createFileRec(name, req)
Expand Down Expand Up @@ -1419,6 +1453,105 @@ func (f *File) Statfs() (FileFsInfo, error) {
return fi, nil
}

type FileSecurityInfo struct {
Owner string
Group string
Flags uint16
Sacl []ACE
Dacl []ACE
}

type ACE struct {
AceType uint8
AceFlags uint8
Mask uint32
Sid string

ApplicationData []byte
AttributeData []byte
Flags uint32
InheritedObjectType []byte
ObjectType []byte
}

func (f *File) Security() (*FileSecurityInfo, error) {
fi, err := f.security()
if err != nil {
return nil, &os.PathError{Op: "security", Path: f.name, Err: err}
}
return fi, nil
}

func (f *File) security() (*FileSecurityInfo, error) {
req := &QueryInfoRequest{
InfoType: SMB2_0_INFO_SECURITY,
FileInfoClass: 0,
AdditionalInformation: OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION,
Flags: 0,
OutputBufferLength: uint32(f.maxTransactSize()),
}

infoBytes, err := f.queryInfo(req)
if err != nil {
return nil, err
}

info := SecurityDescriptorDecoder(infoBytes)
if info.IsInvalid() {
return nil, &InvalidResponseError{"broken query info response format"}
}

var owner string
if info.OffsetOwner() != 0 {
owner = info.OwnerSid().Decode().String()
}
var group string
if info.OffsetGroup() != 0 {
group = info.GroupSid().Decode().String()
}

var sacl []ACE
var dacl []ACE
if dec := info.Sacl(); dec != nil {
for _, d := range dec.ACEs() {
sacl = append(sacl, ACE{
AceType: d.AceType(),
AceFlags: d.AceFlags(),
Mask: d.Mask(),
Sid: d.Sid().Decode().String(),
ApplicationData: d.ApplicationData(),
AttributeData: d.AttributeData(),
Flags: d.Flags(),
InheritedObjectType: d.InheritedObjType(),
ObjectType: d.ObjectType(),
})
}
}
if dec := info.Dacl(); dec != nil {
for _, d := range dec.ACEs() {
dacl = append(dacl, ACE{
AceType: d.AceType(),
AceFlags: d.AceFlags(),
Mask: d.Mask(),
Sid: d.Sid().Decode().String(),
ApplicationData: d.ApplicationData(),
AttributeData: d.AttributeData(),
Flags: d.Flags(),
InheritedObjectType: d.InheritedObjType(),
ObjectType: d.ObjectType(),
})
}
}

return &FileSecurityInfo{
Owner: owner,
Group: group,
Flags: info.Control(),
Sacl: sacl,
Dacl: dacl,
}, nil
}

type FileFsInfo interface {
BlockSize() uint64
FragmentSize() uint64
Expand Down
29 changes: 7 additions & 22 deletions internal/smb2/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -649,14 +649,14 @@ const (
// AdditionalInformation
const (
OWNER_SECURITY_INFORMATION = 1 << iota
GROUP_SECUIRTY_INFORMATION
DACL_SECUIRTY_INFORMATION
SACL_SECUIRTY_INFORMATION
LABEL_SECUIRTY_INFORMATION
ATTRIBUTE_SECUIRTY_INFORMATION
SCOPE_SECUIRTY_INFORMATION
GROUP_SECURITY_INFORMATION
DACL_SECURITY_INFORMATION
SACL_SECURITY_INFORMATION
LABEL_SECURITY_INFORMATION
ATTRIBUTE_SECURITY_INFORMATION
SCOPE_SECURITY_INFORMATION

BACKUP_SECUIRTY_INFORMATION = 0x10000
BACKUP_SECURITY_INFORMATION = 0x10000
)

// Flags
Expand Down Expand Up @@ -698,18 +698,3 @@ const (
// FileFsControlInformation
// FileFsObjectIdInformation
)

// AdditionalInformation
const (
// OWNER_SECURITY_INFORMATION = 1 << iota
// GROUP_SECUIRTY_INFORMATION
// DACL_SECUIRTY_INFORMATION
// SACL_SECUIRTY_INFORMATION
// LABEL_SECUIRTY_INFORMATION
// ATTRIBUTE_SECUIRTY_INFORMATION
// SCOPE_SECUIRTY_INFORMATION

// BACKUP_SECUIRTY_INFORMATION = 0x10000
)

//
Loading