Skip to content
Open
Show file tree
Hide file tree
Changes from 8 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
2 changes: 1 addition & 1 deletion Documentation/MANPAGE-render.bash
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

set -eu
cd "$(dirname "$0")"
Expand Down
4 changes: 3 additions & 1 deletion benchmark-reverse.bash
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/bin/bash -eu
#!/usr/bin/env bash

# Benchmark gocryptfs' reverse mode

set -eu

cd "$(dirname "$0")"
MYNAME=$(basename "$0")
source tests/fuse-unmount.bash
Expand Down
4 changes: 3 additions & 1 deletion benchmark.bash
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/bin/bash -eu
#!/usr/bin/env bash

# Run the set of "canonical" benchmarks that are shown on
# https://nuetzlich.net/gocryptfs/comparison/

set -eu

cd "$(dirname "$0")"
MYNAME=$(basename "$0")
source tests/fuse-unmount.bash
Expand Down
4 changes: 3 additions & 1 deletion build-without-openssl.bash
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/bin/bash -eu
#!/usr/bin/env bash

set -eu

cd "$(dirname "$0")"

Expand Down
4 changes: 3 additions & 1 deletion build.bash
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash -eu
#!/usr/bin/env bash
#
# Compile gocryptfs and bake the git version string of itself and the go-fuse
# library into the binary.
Expand All @@ -10,6 +10,8 @@
# SOURCE_DATE_EPOCH=1544192417 ./build.bash
# .

set -eu

cd "$(dirname "$0")"

# $0 does not work because we may have been sourced
Expand Down
2 changes: 1 addition & 1 deletion contrib/gocryptfs-maybe.bash
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
#
# Conditionally try to mount a gocryptfs filesystem. If either
# * CIPHERDIR/gocryptfs.conf does not exist OR
Expand Down
2 changes: 1 addition & 1 deletion contrib/maxlen.bash
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
#
# Find out the maximum supported filename length and print it.
#
Expand Down
6 changes: 5 additions & 1 deletion crossbuild.bash
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
#
# Build on all supported architectures & operating systems

Expand Down Expand Up @@ -31,3 +31,7 @@ time GOOS=darwin GOARCH=amd64 compile_tests

# MacOS on Apple Silicon M1.
GOOS=darwin GOARCH=arm64 build

# FreeBSD
GOOS=freebsd GOARCH=amd64 build

33 changes: 33 additions & 0 deletions internal/fusefrontend/node_xattr_freebsd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package fusefrontend

import (
"golang.org/x/sys/unix"

"github.com/hanwen/go-fuse/v2/fuse"
)

const noSuchAttributeError = unix.ENOATTR

func filterXattrSetFlags(flags int) int {
return flags
}

func (n *Node) getXAttr(cAttr string) (out []byte, errno unix.Errno) {
// TODO
return nil, unix.EOPNOTSUPP
}

func (n *Node) setXAttr(context *fuse.Context, cAttr string, cData []byte, flags uint32) (errno unix.Errno) {
// TODO
return unix.EOPNOTSUPP
}

func (n *Node) removeXAttr(cAttr string) (errno unix.Errno) {
// TODO
return unix.EOPNOTSUPP
}

func (n *Node) listXAttr() (out []string, errno unix.Errno) {
// TODO
return nil, unix.EOPNOTSUPP
}
43 changes: 43 additions & 0 deletions internal/fusefrontend_reverse/node_xattr_freebsd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package fusefrontend_reverse

import (
"fmt"

"golang.org/x/sys/unix"

"github.com/hanwen/go-fuse/v2/fs"

"github.com/rfjakob/gocryptfs/v2/internal/syscallcompat"
)

const noSuchAttributeError = unix.ENOATTR

func (n *Node) getXAttr(cAttr string) (out []byte, errno unix.Errno) {
d, errno := n.prepareAtSyscall("")
if errno != 0 {
return
}
defer unix.Close(d.dirfd)

procPath := fmt.Sprintf("/proc/self/fd/%d/%s", d.dirfd, d.pName)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does not make sense on freebsd. Please fix or just stub it with EOPNOTSUPP.

Same for the other functions in this file.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Functions in this file have been stubbed in the latest commit.

pData, err := syscallcompat.Lgetxattr(procPath, cAttr)
if err != nil {
return nil, fs.ToErrno(err)
}
return pData, 0
}

func (n *Node) listXAttr() (out []string, errno unix.Errno) {
d, errno := n.prepareAtSyscall("")
if errno != 0 {
return
}
defer unix.Close(d.dirfd)

procPath := fmt.Sprintf("/proc/self/fd/%d/%s", d.dirfd, d.pName)
pNames, err := syscallcompat.Llistxattr(procPath)
if err != nil {
return nil, fs.ToErrno(err)
}
return pNames, 0
}
2 changes: 1 addition & 1 deletion internal/siv_aead/benchmark.bash
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

set -eu

Expand Down
2 changes: 1 addition & 1 deletion internal/speed/benchmark.bash
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

set -eu

Expand Down
2 changes: 1 addition & 1 deletion internal/stupidgcm/benchmark.bash
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
#!/usr/bin/env bash

exec ../speed/benchmark.bash
16 changes: 16 additions & 0 deletions internal/syscallcompat/asuser_freebsd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package syscallcompat

import (
"github.com/hanwen/go-fuse/v2/fuse"
)

// asUser runs `f()` under the effective uid, gid, groups specified
// in `context`.
//
// If `context` is nil, `f()` is executed directly without switching user id.
//
// WARNING this function is not complete, and always runs f() as if context is nil.
// FreeBSD does not support changing uid/gid per thread.
func asUser(f func() (int, error), context *fuse.Context) (int, error) {
return f()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this is dangerous. This allows any user to create suid-root binaries.

If not possible to implement, log a warning and return an error.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated so that f() is executed is context is nil, otherwise a warning is logged and unix.EOPNOTSUPP.

}
2 changes: 2 additions & 0 deletions internal/syscallcompat/emulate.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build darwin
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this cause problems on freebsd? Then please use

//go:build !freebsd

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be built on Linux so it can be tested on Linux

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was causing a problem on FreeBSD as the dev parameter to Mknod is uint64 on FreeBSD (instead of int used by Linux and Mac OS).

I've added the suggested build parameter to emulate.go, and created the file internal/syscallcompat/emulate_freebsd.go for FreeBSD with dev cast to uint64.


package syscallcompat

import (
Expand Down
1 change: 1 addition & 0 deletions internal/syscallcompat/emulate_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build darwin
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this cause problems on freebsd? Then please use

//go:build !freebsd

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file will now build on FreeBSD after the above change to emulate.go.

package syscallcompat

import (
Expand Down
22 changes: 22 additions & 0 deletions internal/syscallcompat/quirks_freebsd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package syscallcompat

import (
"golang.org/x/sys/unix"

"github.com/rfjakob/gocryptfs/v2/internal/tlog"
)

// DetectQuirks decides if there are known quirks on the backing filesystem
// that need to be workarounded.
//
// Tested by tests/root_test.TestBtrfsQuirks
func DetectQuirks(cipherdir string) (q uint64) {
var st unix.Statfs_t
err := unix.Statfs(cipherdir, &st)
if err != nil {
tlog.Warn.Printf("DetectQuirks: Statfs on %q failed: %v", cipherdir, err)
return 0
}

return q
}
2 changes: 1 addition & 1 deletion internal/syscallcompat/sys_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func getxattrSmartBuf(fn func(buf []byte) (int, error)) ([]byte, error) {
buf := make([]byte, GETXATTR_BUFSZ_SMALL)
sz, err := fn(buf)
// Non-existing xattr
if err == unix.ENODATA {
if err == ENODATA {
return nil, err
}
// Underlying fs does not support security.capabilities (example: tmpfs)
Expand Down
2 changes: 2 additions & 0 deletions internal/syscallcompat/sys_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ const (
RENAME_NOREPLACE = unix.RENAME_EXCL
RENAME_EXCHANGE = unix.RENAME_SWAP

ENODATA = unix.ENODATA

// Only exists on Linux. Define here to fix build failure, even though
// we will never see this flag.
RENAME_WHITEOUT = 1 << 30
Expand Down
Loading