Пример #1
0
func (fs *readonlyFileSystem) Open(name string, flags uint32, context *fuse.Context) (file nodefs.File, code fuse.Status) {
	if flags&fuse.O_ANYWRITE != 0 {
		return nil, fuse.EPERM
	}
	file, code = fs.FileSystem.Open(name, flags, context)
	return nodefs.NewReadOnlyFile(file), code
}
Пример #2
0
// Open is a FUSE function where an in-memory open file struct is constructed.
func (f *fs) Open(name string, flags uint32, context *fuse.Context) (nodefs.File, fuse.Status) {
	var file nodefs.File
	switch {
	case name == "":
		return nil, EISDIR
	case name == "secret":
		return nil, EISDIR
	default:
		s, err := f.client.Logical().Read(name)
		if err != nil {
			return nil, fuse.ENOENT
		}

		if s == nil || s.Data == nil {
			return nil, fuse.ENOENT
		}

		file = nodefs.NewDataFile([]byte(s.Data["value"].(string)))
	}

	if file != nil {
		file = nodefs.NewReadOnlyFile(file)
		return file, fuse.OK
	}
	return nil, fuse.ENOENT
}
Пример #3
0
// Open is a FUSE function where an in-memory open file struct is constructed.
func (f *fs) Open(name string, flags uint32, context *fuse.Context) (nodefs.File, fuse.Status) {
	log.Printf("Open '%s'\n", name)
	var file nodefs.File
	switch {
	case name == "":
		return nil, EISDIR
	case name == "secret" || name == "sys":
		return nil, EISDIR
	case strings.HasPrefix(name, "secret/"):
		fmt.Println("got here")
		s, err := f.client.Logical().Read(name)
		if err != nil {
			log.Println(err)
			return nil, fuse.ENOENT
		}

		if s == nil || s.Data == nil {
			return nil, fuse.ENOENT
		}

		file = nodefs.NewDataFile([]byte(s.Data["value"].(string) + "\n"))
	}

	if file != nil {
		file = nodefs.NewReadOnlyFile(file)
		return file, fuse.OK
	}
	return nil, fuse.ENOENT
}
Пример #4
0
// NewAdbFile returns a File that reads and writes to name on the device.
// perms should be set from the existing file if it exists, or to the desired new permissions if new.
func NewAdbFile(opts AdbFileOpenOptions) nodefs.File {
	logEntry := StartFileOperation("New", opts.FileBuffer.Path, fmt.Sprint(opts))
	defer logEntry.FinishOperation()

	adbFile := &AdbFile{
		// Log all the operations we don't implement.
		File:               newLoggingFile(nodefs.NewDefaultFile(), opts.FileBuffer.Path),
		AdbFileOpenOptions: opts,
	}

	return nodefs.NewReadOnlyFile(adbFile)
}
Пример #5
0
// Open is a FUSE function where an in-memory open file struct is constructed.
func (kwfs KeywhizFs) Open(name string, flags uint32, context *fuse.Context) (nodefs.File, fuse.Status) {
	kwfs.Debugf("Open called with '%v'", name)

	var file nodefs.File
	switch {
	case name == "", name == ".json", name == ".json/secret":
		return nil, EISDIR
	case name == ".version":
		file = nodefs.NewDataFile([]byte(VERSION))
	case name == ".clear_cache":
		file = nodefs.NewDevNullFile()
	case name == ".running":
		file = nodefs.NewDataFile(running())
	case name == ".json/secrets":
		data, ok := kwfs.Client.RawSecretList()
		if ok {
			file = nodefs.NewDataFile(data)
		}
	case strings.HasPrefix(name, ".json/secret/"):
		name = name[len(".json/secret/"):]
		data, ok := kwfs.Client.RawSecret(name)
		if ok {
			file = nodefs.NewDataFile(data)
			kwfs.Infof("Access to %s by uid %d, with gid %d", name, context.Uid, context.Gid)
		}
	default:
		secret, ok := kwfs.Cache.Secret(name)
		if ok {
			file = nodefs.NewDataFile(secret.Content)
			kwfs.Infof("Access to %s by uid %d, with gid %d", name, context.Uid, context.Gid)
		}
	}

	if file != nil {
		file = nodefs.NewReadOnlyFile(file)
		return file, fuse.OK
	}
	return nil, fuse.ENOENT
}