Beispiel #1
0
func initDir(args *argContainer) {
	err := checkDirEmpty(args.cipherdir)
	if err != nil {
		fmt.Printf("Invalid cipherdir: %v\n", err)
		os.Exit(ERREXIT_INIT)
	}

	// Create gocryptfs.conf
	cryptfs.Info.Printf("Choose a password for protecting your files.\n")
	password := readPasswordTwice(args.extpass)
	err = cryptfs.CreateConfFile(args.config, password, args.plaintextnames, args.scryptn)
	if err != nil {
		fmt.Println(err)
		os.Exit(ERREXIT_INIT)
	}

	if args.diriv && !args.plaintextnames {
		// Create gocryptfs.diriv in the root dir
		err = cryptfs.WriteDirIV(args.cipherdir)
		if err != nil {
			fmt.Println(err)
			os.Exit(ERREXIT_INIT)
		}
	}

	cryptfs.Info.Printf(colorGreen + "The filesystem has been created successfully.\n" + colorReset)
	cryptfs.Info.Printf(colorGrey+"You can now mount it using: %s %s MOUNTPOINT\n"+colorReset,
		PROGRAM_NAME, args.cipherdir)
	os.Exit(0)
}
Beispiel #2
0
// resetTmpDir - delete old tmp dir, create new one, write gocryptfs.diriv
func resetTmpDir() {
	fu := exec.Command("fusermount", "-z", "-u", defaultPlainDir)
	fu.Run()

	err := os.RemoveAll(tmpDir)
	if err != nil {
		fmt.Println("resetTmpDir: RemoveAll:" + err.Error())
		os.Exit(1)
	}

	err = os.MkdirAll(defaultPlainDir, 0777)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	err = os.MkdirAll(defaultCipherDir, 0777)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	err = cryptfs.WriteDirIV(defaultCipherDir)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
}
Beispiel #3
0
func (fs *FS) Mkdir(relPath string, mode uint32, context *fuse.Context) (code fuse.Status) {
	if fs.isFiltered(relPath) {
		return fuse.EPERM
	}
	encPath, err := fs.getBackingPath(relPath)
	if err != nil {
		return fuse.ToStatus(err)
	}
	if !fs.args.DirIV {
		return fuse.ToStatus(os.Mkdir(encPath, os.FileMode(mode)))
	}

	// We need write and execute permissions to create gocryptfs.diriv
	origMode := mode
	mode = mode | 0300

	// The new directory may take the place of an older one that is still in the cache
	fs.CryptFS.DirIVCacheEnc.Clear()
	// Create directory
	fs.dirIVLock.Lock()
	defer fs.dirIVLock.Unlock()
	err = os.Mkdir(encPath, os.FileMode(mode))
	if err != nil {
		return fuse.ToStatus(err)
	}
	// Create gocryptfs.diriv inside
	err = cryptfs.WriteDirIV(encPath)
	if err != nil {
		// This should not happen
		cryptfs.Warn.Printf("Mkdir: WriteDirIV failed: %v", err)
		err2 := syscall.Rmdir(encPath)
		if err2 != nil {
			cryptfs.Warn.Printf("Mkdir: Rmdir rollback failed: %v", err2)
		}
		return fuse.ToStatus(err)
	}

	// Set permissions back to what the user wanted
	if origMode != mode {
		err = os.Chmod(encPath, os.FileMode(origMode))
		if err != nil {
			cryptfs.Warn.Printf("Mkdir: Chmod failed: %v", err)
		}
	}

	return fuse.OK
}