Skip to content

Commit

Permalink
nametransform: move permission constants to perms.go
Browse files Browse the repository at this point in the history
Prep for #539
  • Loading branch information
rfjakob committed Jan 10, 2021
1 parent de108d3 commit f3394ae
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
8 changes: 0 additions & 8 deletions internal/nametransform/diriv.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,6 @@ func fdReadDirIV(fd *os.File) (iv []byte, err error) {
// This function is exported because it is used from fusefrontend, main,
// and also the automated tests.
func WriteDirIVAt(dirfd int) error {
// It makes sense to have the diriv files group-readable so the FS can
// be mounted from several users from a network drive (see
// https://github.com/rfjakob/gocryptfs/issues/387 ).
//
// Note that gocryptfs.conf is still created with 0400 permissions so the
// owner must explicitly chmod it to permit access.
const dirivPerms = 0440

iv := cryptocore.RandBytes(DirIVLen)
// 0400 permissions: gocryptfs.diriv should never be modified after creation.
// Don't use "ioutil.WriteFile", it causes trouble on NFS:
Expand Down
2 changes: 1 addition & 1 deletion internal/nametransform/longnames.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (n *NameTransform) WriteLongNameAt(dirfd int, hashName string, plainName st

// Write the encrypted name into hashName.name
fdRaw, err := syscallcompat.Openat(dirfd, hashName+LongNameSuffix,
syscall.O_WRONLY|syscall.O_CREAT|syscall.O_EXCL, 0400)
syscall.O_WRONLY|syscall.O_CREAT|syscall.O_EXCL, namePerms)
if err != nil {
// Don't warn if the file already exists - this is allowed for renames
// and should be handled by the caller.
Expand Down
16 changes: 16 additions & 0 deletions internal/nametransform/perms.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package nametransform

const (
// Permissions for gocryptfs.diriv files
//
// It makes sense to have the diriv files group-readable so the FS can
// be mounted from several users from a network drive (see
// https://github.com/rfjakob/gocryptfs/issues/387 ).
//
// Note that gocryptfs.conf is still created with 0400 permissions so the
// owner must explicitly chmod it to permit access.
dirivPerms = 0440

// Permissions for gocryptfs.longname.[sha256].name files
namePerms = 0400
)

0 comments on commit f3394ae

Please sign in to comment.