Compare commits

...

2 Commits

Author SHA1 Message Date
Matéo Duparc e6e4c201db
Fix typo in README 2022-06-26 13:57:44 +02:00
Matéo Duparc 7afeb9f3a4
Adapt to the new API 2022-06-23 17:01:11 +02:00
5 changed files with 17 additions and 12 deletions

View File

@ -1,4 +1,4 @@
libgocryptfs is a re-desing of the original [gocryptfs](https://github.com/rfjakob/gocryptfs) code to work as a library. Volumes are not mounted with [FUSE](https://www.kernel.org/doc/html/latest/filesystems/fuse.html) but rather opened in memory and accessed through API calls. What the purpose ? libgocryptfs is a re-design of the original [gocryptfs](https://github.com/rfjakob/gocryptfs) code to work as a library. Volumes are not mounted with [FUSE](https://www.kernel.org/doc/html/latest/filesystems/fuse.html) but rather opened in memory and accessed through API calls. What the purpose ?
- Allow the use of gocryptfs in embedded devices where FUSE is not available (such as Android) - Allow the use of gocryptfs in embedded devices where FUSE is not available (such as Android)
- Reduce attack surface by restricting volumes access to only one process rather than one user - Reduce attack surface by restricting volumes access to only one process rather than one user

View File

@ -10,27 +10,27 @@ import (
) )
//export gcf_get_attrs //export gcf_get_attrs
func gcf_get_attrs(sessionID int, relPath string) (uint64, int64, bool) { func gcf_get_attrs(sessionID int, relPath string) (uint32, uint64, uint64, bool) {
value, ok := OpenedVolumes.Load(sessionID) value, ok := OpenedVolumes.Load(sessionID)
if !ok { if !ok {
return 0, 0, false return 0, 0, 0, false
} }
volume := value.(*Volume) volume := value.(*Volume)
dirfd, cName, err := volume.prepareAtSyscall(relPath) dirfd, cName, err := volume.prepareAtSyscall(relPath)
if err != nil { if err != nil {
return 0, 0, false return 0, 0, 0, false
} }
defer syscall.Close(dirfd) defer syscall.Close(dirfd)
st, err := syscallcompat.Fstatat2(dirfd, cName, unix.AT_SYMLINK_NOFOLLOW) st, err := syscallcompat.Fstatat2(dirfd, cName, unix.AT_SYMLINK_NOFOLLOW)
if err != nil { if err != nil {
return 0, 0, false return 0, 0, 0, false
} }
// Translate ciphertext size to plaintext size // Translate ciphertext size to plaintext size
size := volume.translateSize(dirfd, cName, st) size := volume.translateSize(dirfd, cName, st)
return size, int64(st.Mtim.Sec), true return st.Mode, size, uint64(st.Mtim.Sec), true
} }
// libgocryptfs: using Renameat instead of Renameat2 to support older kernels // libgocryptfs: using Renameat instead of Renameat2 to support older kernels

View File

@ -77,7 +77,7 @@ func gcf_list_dir(sessionID int, dirName string) (*C.char, *C.int, C.int) {
// Filter and decrypt filenames // Filter and decrypt filenames
for i := range cipherEntries { for i := range cipherEntries {
cName := cipherEntries[i].Name cName := cipherEntries[i].Name
if dirName == "" && cName == configfile.ConfDefaultName { if dirName == "/" && cName == configfile.ConfDefaultName {
// silently ignore "gocryptfs.conf" in the top level dir // silently ignore "gocryptfs.conf" in the top level dir
continue continue
} }

11
file.go
View File

@ -328,7 +328,7 @@ func (volume *Volume) truncate(handleID int, newSize uint64) bool {
} }
// We need the old file size to determine if we are growing or shrinking // We need the old file size to determine if we are growing or shrinking
// the file // the file
oldSize, _, success := gcf_get_attrs(volume.volumeID, f.path) _, oldSize, _, success := gcf_get_attrs(volume.volumeID, f.path)
if !success { if !success {
return false return false
} }
@ -426,13 +426,18 @@ func gcf_open_write_mode(sessionID int, path string, mode uint32) int {
} }
//export gcf_truncate //export gcf_truncate
func gcf_truncate(sessionID int, handleID int, offset uint64) bool { func gcf_truncate(sessionID int, path string, offset uint64) bool {
value, ok := OpenedVolumes.Load(sessionID) value, ok := OpenedVolumes.Load(sessionID)
if !ok { if !ok {
return false return false
} }
volume := value.(*Volume) volume := value.(*Volume)
return volume.truncate(handleID, offset) for handleID, file := range volume.fileHandles {
if file.path == path {
return volume.truncate(handleID, offset)
}
}
return false
} }
//export gcf_read_file //export gcf_read_file

View File

@ -33,7 +33,7 @@ func (volume *Volume) isFiltered(path string) bool {
} }
func (volume *Volume) prepareAtSyscall(path string) (dirfd int, cName string, err error) { func (volume *Volume) prepareAtSyscall(path string) (dirfd int, cName string, err error) {
if path == "" { if path == "/" {
return volume.prepareAtSyscallMyself(path) return volume.prepareAtSyscallMyself(path)
} }
@ -111,7 +111,7 @@ func (volume *Volume) prepareAtSyscallMyself(path string) (dirfd int, cName stri
dirfd = -1 dirfd = -1
// Handle root node // Handle root node
if path == "" { if path == "/" {
var err error var err error
// Open cipherdir (following symlinks) // Open cipherdir (following symlinks)
dirfd, err = syscallcompat.Open(volume.rootCipherDir, syscall.O_DIRECTORY|syscallcompat.O_PATH, 0) dirfd, err = syscallcompat.Open(volume.rootCipherDir, syscall.O_DIRECTORY|syscallcompat.O_PATH, 0)