1
0
mirror of https://github.com/gilbertchen/duplicacy synced 2025-12-06 00:03:38 +00:00

Merge remote-tracking branch 'remotes/the_fork/master' into tbp/google_rate_limit_exceeded

* remotes/the_fork/master:
  Use math.MaxInt32 to avoid a build error on 32-bit platforms
  Don't verify SSH host if the preference path is not set
  The info command should not overwrite the default password if reset-passwords is on
  Storage name can't be 'ssh' otherwise the ssh password of the default storage nad the storage password of the 'ssh' storage will share the same keychain entry
  When resetPassword is true, the entered password should be the same as that in environment or preference
This commit is contained in:
TheBestPessimist
2017-10-01 12:00:20 +03:00
5 changed files with 40 additions and 12 deletions

View File

@@ -223,6 +223,11 @@ func configRepository(context *cli.Context, init bool) {
storageName = context.Args()[0]
snapshotID = context.Args()[1]
storageURL = context.Args()[2]
if strings.ToLower(storageName) == "ssh" {
duplicacy.LOG_ERROR("PREFERENCE_INVALID", "'%s' is an invalid storage name", storageName)
return
}
}
var repository string
@@ -1117,6 +1122,7 @@ func infoStorage(context *cli.Context) {
duplicacy.SetKeyringFile(path.Join(preferencePath, "keyring"))
}
resetPasswords := context.Bool("reset-passwords")
isEncrypted := context.Bool("e")
preference := duplicacy.Preference{
Name: "default",
@@ -1126,12 +1132,18 @@ func infoStorage(context *cli.Context) {
DoNotSavePassword: true,
}
password := ""
if isEncrypted {
password = duplicacy.GetPassword(preference, "password", "Enter the storage password:", false, false)
if resetPasswords {
// We don't want password entered for the info command to overwrite the saved password for the default storage,
// so we simply assign an empty name.
preference.Name = ""
}
storage := duplicacy.CreateStorage(preference, context.Bool("reset-passwords"), 1)
password := ""
if isEncrypted {
password = duplicacy.GetPassword(preference, "password", "Enter the storage password:", false, resetPasswords)
}
storage := duplicacy.CreateStorage(preference, resetPasswords, 1)
config, isStorageEncrypted, err := duplicacy.DownloadConfig(storage, password)
if isStorageEncrypted {

View File

@@ -74,6 +74,13 @@ func LoadPreferences(repository string) bool {
return false
}
for _, preference := range Preferences {
if strings.ToLower(preference.Name) == "ssh" {
LOG_ERROR("PREFERENCE_INVALID", "'%s' is an invalid storage name", preference.Name)
return false
}
}
return true
}

View File

@@ -968,7 +968,7 @@ func (manager *SnapshotManager) ShowStatisticsTabular(snapshotMap map[string][]*
for _, snapshot := range snapshotList {
for _, chunkID := range manager.GetSnapshotChunks(snapshot) {
if earliestSeenChunks[chunkID] == 0 {
earliestSeenChunks[chunkID] = math.MaxInt64
earliestSeenChunks[chunkID] = math.MaxInt32
}
earliestSeenChunks[chunkID] = MinInt(earliestSeenChunks[chunkID], snapshot.Revision)
}

View File

@@ -77,7 +77,9 @@ func (storage *RateLimitedStorage) SetRateLimits(downloadRateLimit int, uploadRa
func checkHostKey(hostname string, remote net.Addr, key ssh.PublicKey) error {
preferencePath := GetDuplicacyPreferencePath()
if preferencePath == "" {
return fmt.Errorf("Can't verify SSH host since the preference path is not set")
}
hostFile := path.Join(preferencePath, "known_hosts")
file, err := os.OpenFile(hostFile, os.O_RDWR|os.O_CREATE, 0600)
if err != nil {

View File

@@ -182,12 +182,12 @@ func GetPasswordFromPreference(preference Preference, passwordType string) strin
// (i.e., preference.Name) in the key, so the key name should really be passwordType rather
// than passwordID; we're using passwordID here only for backward compatibility
if len(preference.Keys) > 0 && len(preference.Keys[passwordID]) > 0 {
LOG_DEBUG("PASSWORD_KEYCHAIN", "Reading %s from preferences", passwordID)
LOG_DEBUG("PASSWORD_PREFERENCE", "Reading %s from preferences", passwordID)
return preference.Keys[passwordID]
}
if len(preference.Keys) > 0 && len(preference.Keys[passwordType]) > 0 {
LOG_DEBUG("PASSWORD_KEYCHAIN", "Reading %s from preferences", passwordType)
LOG_DEBUG("PASSWORD_PREFERENCE", "Reading %s from preferences", passwordType)
return preference.Keys[passwordType]
}
@@ -198,9 +198,10 @@ func GetPasswordFromPreference(preference Preference, passwordType string) strin
func GetPassword(preference Preference, passwordType string, prompt string,
showPassword bool, resetPassword bool) string {
passwordID := passwordType
password := GetPasswordFromPreference(preference, passwordType)
if password != "" {
return password
preferencePassword := GetPasswordFromPreference(preference, passwordType)
if preferencePassword != "" && !resetPassword {
return preferencePassword
}
if preference.Name != "default" {
@@ -212,6 +213,7 @@ func GetPassword(preference Preference, passwordType string, prompt string,
} else {
password := keyringGet(passwordID)
if password != "" {
LOG_DEBUG("PASSWORD_KEYCHAIN", "Reading %s from keychain/keyring", passwordType)
return password
}
@@ -222,7 +224,7 @@ func GetPassword(preference Preference, passwordType string, prompt string,
}
password = ""
password := ""
fmt.Printf("%s", prompt)
if showPassword {
scanner := bufio.NewScanner(os.Stdin)
@@ -237,6 +239,11 @@ func GetPassword(preference Preference, passwordType string, prompt string,
password = string(passwordInBytes)
}
if resetPassword && preferencePassword != "" && preferencePassword != password {
LOG_ERROR("PASSWORD_MISMATCH", "The password entered is different from what is in the environment or preference")
return ""
}
return password
}