summaryrefslogtreecommitdiff
path: root/fs/permissions/permission_linux.go
blob: feae729940c041997a5aa56b8b63fa1719c53510 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package permissions

/*
#include "permission_linux.h"
#cgo LDFLAGS: -L. -lacl
*/
import "C"

import (
	"errors"
	"unsafe"
)

// To check whether user has Linux file system permissions to read a given file.
func ToRead(user, filePath string) (bool, error) {
	cUser := C.CString(user)
	cFilePath := C.CString(filePath)

	defer C.free(unsafe.Pointer(cUser))
	defer C.free(unsafe.Pointer(cFilePath))

	cOk, err := C.permission_to_read(cUser, cFilePath)
	if cOk == 1 {
		return true, nil
	}

	if err != nil {
		// err contains errno message
		return false, err
	}

	return false, errors.New("User without permission to read file")
}