Example #1
0
func (self *serverLocal) Wait() (result int, err error) {
	if self.server.running {
		result = <-self.server.status
		self.server.channel.Disconnect()
	} else {
		err = errors.New("server not running")
	}
	return
}
Example #2
0
func (self *cmd_stop) Run(line []string) (err error) {
	var reply bool
	err = self.server.Stop(0, &reply)
	if err != nil {
		return
	}
	if !reply {
		err = errors.New("The server refused to stop")
	} else {
		err = io.EOF
	}
	return
}
Example #3
0
func (self generator_mix) extend_pass(in io.Reader, pass string) (result string, err error) {
	data := make([]byte, 0, 3)
	n, err := in.Read(data)
	if err != nil {
		return "", errors.Decorated(err)
	}
	if n < 3 {
		return "", errors.New("not enough data")
	}
	b1 := data[0]
	b2 := data[1]
	b := byte(int((b1&0x7f)<<8+b2) % len(self.ingredient))
	i := int(data[2]) % (len(pass) + 1)
	result = string(append(append(append(make([]byte, 0, len(pass)+1), pass[:i]...), b), pass[i:]...))
	return
}
Example #4
0
func openVault(srv server.Server, config core.Config) (err error) {
	xdg, err := config.Xdg()
	if err != nil {
		return
	}

	data_home, err := xdg.DataHome()
	if err != nil {
		return
	}
	vault_path := fmt.Sprintf("%s/vault", data_home)
	vault_info, err := os.Stat(vault_path)
	if err != nil {
		return errors.Decorated(err)
	}

	mmi, err := ui.Ui(srv, config)
	if err != nil {
		return
	}

	var master string
	if vault_info == nil {
		master, err = readNewMaster(mmi, "This is a new vault")
		if err != nil {
			return
		}
	} else {
		master, err = mmi.ReadPassword("Please enter your encryption phrase\nto open the password vault.")
		if err != nil {
			return
		}
	}

	var isopen bool
	err = srv.Open(master, &isopen)
	if err != nil {
		return
	}
	if !isopen {
		return errors.New("Could not open vault")
	}

	return
}
Example #5
0
func (self *cmd_add) Run(line []string) (err error) {
	var arg server.SetArgs
	switch len(line) {
	case 2:
		arg, err = self.generateArgs(line[1], "")
	case 3:
		action := line[2]
		switch action {
		case "generate":
			arg, err = self.generateArgs(line[1], "")
		case "prompt":
			arg, err = self.promptArgs(line[1])
		default:
			err = errors.Newf("Unrecognized argument: '%s'", action)
		}
	case 4:
		recipe := line[3]
		action := line[2]
		switch action {
		case "generate":
			arg, err = self.generateArgs(line[1], recipe)
		default:
			err = errors.Newf("Unrecognized argument: '%s'", action)
		}
	default:
		err = errors.New("Invalid arguments")
	}
	if err != nil {
		return
	}

	var pass string
	err = self.server.Set(arg, &pass)
	if err != nil {
		return
	}

	err = self.mmi.Xclip(pass)
	return
}