Ejemplo n.º 1
0
// The first argument is the Label for the collection, and the second is an (optional) alias.
func (s Service) CreateCollection(label, alias string) (Collection, error) {
	// spec: CreateCollection(IN Dict<String,Variant> properties, IN String alias, OUT ObjectPath collection, OUT ObjectPath prompt);
	var collectionPath, promptPath dbus.ObjectPath
	conn, err := dbus.SessionBus()
	if err != nil {
		return Collection{}, err
	}
	properties := map[string]dbus.Variant{
		_CollectionLabel: dbus.MakeVariant(label),
	}
	call := s.Call(_ServiceCreateCollection, 0, properties, alias)
	if call.Err != nil {
		return Collection{}, call.Err
	}
	err = call.Store(&collectionPath, &promptPath)
	if err != nil {
		return Collection{}, err
	}
	if dbus.ObjectPath("/") != collectionPath {
		return Collection{conn.Object(ServiceName, collectionPath)}, nil
	}
	v, err := checkPrompt(promptPath)
	if err != nil {
		return Collection{}, err
	}
	return Collection{conn.Object(ServiceName, dbus.ObjectPath(v.Value().(string)))},
		fmt.Errorf("unable to create collection")
}
Ejemplo n.º 2
0
func DialCollection(path string) (Collection, error) {
	conn, err := dbus.SessionBus()
	if err != nil {
		return Collection{}, err
	}
	obj := conn.Object(ServiceName, dbus.ObjectPath(path))
	return Collection{obj}, nil
}
Ejemplo n.º 3
0
// Unsure how the .Prompt call surfaces, it hasn't come up.
func (s *ssProvider) unlock(p dbus.ObjectPath) error {
	var unlocked []dbus.ObjectPath
	var prompt dbus.ObjectPath
	method := fmt.Sprint(ssServiceIface, "Unlock")
	err := s.srv.Call(method, 0, []dbus.ObjectPath{p}).Store(&unlocked, &prompt)
	if err != nil {
		return fmt.Errorf("keyring/dbus: Unlock error: %s", err)
	}
	if prompt != dbus.ObjectPath("/") {
		method = fmt.Sprint(ssPromptIface, "Prompt")
		call := s.Object(ssServiceName, prompt).Call(method, 0, "unlock")
		return call.Err
	}
	return nil
}
Ejemplo n.º 4
0
// +build linux

package ss

import dbus "github.com/guelfey/go.dbus"

var (
	noPrompt = dbus.ObjectPath("/")
)

func checkPrompt(promptPath dbus.ObjectPath) (dbus.Variant, error) {
	// if we don't need to prompt, just return.
	empty := dbus.Variant{}
	if promptPath == noPrompt {
		return empty, nil
	}
	conn, err := dbus.SessionBus()
	if err != nil {
		return empty, err
	}
	pr := Prompt{conn.Object(ServiceName, promptPath)}
	return pr.Prompt("secretservice.go")
}

func simpleCall(path dbus.ObjectPath, method string, args ...interface{}) error {
	var call *dbus.Call
	var promptPath dbus.ObjectPath
	conn, err := dbus.SessionBus()
	if err != nil {
		return err
	}