Add missing PlaintextNames checks in OpenDir, Mkdir, Rmdir, initDir
Plaintextnames support has bitrotted during the DirIV additions, this needs test cases. Will be added in a future patch. Fixes issue #9.
This commit is contained in:
parent
14deea6c20
commit
ccf6d00728
12
main.go
12
main.go
@ -61,11 +61,13 @@ func initDir(args *argContainer) {
|
|||||||
os.Exit(ERREXIT_INIT)
|
os.Exit(ERREXIT_INIT)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create gocryptfs.diriv in the root dir
|
if args.diriv && !args.plaintextnames {
|
||||||
err = cryptfs.WriteDirIV(args.cipherdir)
|
// Create gocryptfs.diriv in the root dir
|
||||||
if err != nil {
|
err = cryptfs.WriteDirIV(args.cipherdir)
|
||||||
fmt.Println(err)
|
if err != nil {
|
||||||
os.Exit(ERREXIT_INIT)
|
fmt.Println(err)
|
||||||
|
os.Exit(ERREXIT_INIT)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cryptfs.Info.Printf("The filesystem is now ready for mounting.\n")
|
cryptfs.Info.Printf("The filesystem is now ready for mounting.\n")
|
||||||
|
@ -90,7 +90,7 @@ func (fs *FS) OpenDir(dirName string, context *fuse.Context) ([]fuse.DirEntry, f
|
|||||||
return nil, fuse.ToStatus(err)
|
return nil, fuse.ToStatus(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Decrypt filenames
|
// Filter and decrypt filenames
|
||||||
var plain []fuse.DirEntry
|
var plain []fuse.DirEntry
|
||||||
for i := range cipherEntries {
|
for i := range cipherEntries {
|
||||||
cName := cipherEntries[i].Name
|
cName := cipherEntries[i].Name
|
||||||
@ -102,11 +102,13 @@ func (fs *FS) OpenDir(dirName string, context *fuse.Context) ([]fuse.DirEntry, f
|
|||||||
// silently ignore "gocryptfs.diriv" everywhere if dirIV is enabled
|
// silently ignore "gocryptfs.diriv" everywhere if dirIV is enabled
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
var name string
|
var name string = cName
|
||||||
name, err = fs.CryptFS.DecryptName(cName, cachedIV, fs.args.EMENames)
|
if !fs.args.PlaintextNames {
|
||||||
if err != nil {
|
name, err = fs.CryptFS.DecryptName(cName, cachedIV, fs.args.EMENames)
|
||||||
cryptfs.Warn.Printf("Invalid name \"%s\" in dir \"%s\": %s\n", cName, dirName, err)
|
if err != nil {
|
||||||
continue
|
cryptfs.Warn.Printf("Invalid name \"%s\" in dir \"%s\": %s\n", cName, dirName, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
cipherEntries[i].Name = name
|
cipherEntries[i].Name = name
|
||||||
plain = append(plain, cipherEntries[i])
|
plain = append(plain, cipherEntries[i])
|
||||||
@ -251,6 +253,10 @@ func (fs *FS) Mkdir(relPath string, mode uint32, context *fuse.Context) (code fu
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fuse.ToStatus(err)
|
return fuse.ToStatus(err)
|
||||||
}
|
}
|
||||||
|
if !fs.args.DirIV {
|
||||||
|
return fuse.ToStatus(os.Mkdir(encPath, os.FileMode(mode)))
|
||||||
|
}
|
||||||
|
|
||||||
// The new directory may take the place of an older one that is still in the cache
|
// The new directory may take the place of an older one that is still in the cache
|
||||||
fs.CryptFS.DirIVCacheEnc.Clear()
|
fs.CryptFS.DirIVCacheEnc.Clear()
|
||||||
// Create directory
|
// Create directory
|
||||||
@ -290,6 +296,9 @@ func (fs *FS) Rmdir(name string, context *fuse.Context) (code fuse.Status) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fuse.ToStatus(err)
|
return fuse.ToStatus(err)
|
||||||
}
|
}
|
||||||
|
if !fs.args.DirIV {
|
||||||
|
return fuse.ToStatus(syscall.Rmdir(encPath))
|
||||||
|
}
|
||||||
|
|
||||||
// If the directory is not empty besides gocryptfs.diriv, do not even
|
// If the directory is not empty besides gocryptfs.diriv, do not even
|
||||||
// attempt the dance around gocryptfs.diriv.
|
// attempt the dance around gocryptfs.diriv.
|
||||||
|
Loading…
Reference in New Issue
Block a user