SetConfigPassword will set the configKey to the hash of the password. If the length of the password is zero after trimming+normalization, an error is returned.
(password string)
| 270 | // the password. If the length of the password is |
| 271 | // zero after trimming+normalization, an error is returned. |
| 272 | func SetConfigPassword(password string) error { |
| 273 | password, err := checkPassword(password) |
| 274 | if err != nil { |
| 275 | return err |
| 276 | } |
| 277 | // Create SHA256 has of the password |
| 278 | sha := sha256.New() |
| 279 | _, err = sha.Write([]byte("[" + password + "][rclone-config]")) |
| 280 | if err != nil { |
| 281 | return err |
| 282 | } |
| 283 | configKey = sha.Sum(nil) |
| 284 | if PassConfigKeyForDaemonization { |
| 285 | tempFile, err := os.CreateTemp("", "rclone") |
| 286 | if err != nil { |
| 287 | return fmt.Errorf("cannot create temp file to store configKey: %w", err) |
| 288 | } |
| 289 | _, err = tempFile.WriteString(obscure.MustObscure(string(configKey))) |
| 290 | if err != nil { |
| 291 | errRemove := os.Remove(tempFile.Name()) |
| 292 | if errRemove != nil { |
| 293 | return fmt.Errorf("error writing configKey to temp file and also error deleting it: %w", err) |
| 294 | } |
| 295 | return fmt.Errorf("error writing configKey to temp file: %w", err) |
| 296 | } |
| 297 | err = tempFile.Close() |
| 298 | if err != nil { |
| 299 | errRemove := os.Remove(tempFile.Name()) |
| 300 | if errRemove != nil { |
| 301 | return fmt.Errorf("error closing temp file with configKey and also error deleting it: %w", err) |
| 302 | } |
| 303 | return fmt.Errorf("error closing temp file with configKey: %w", err) |
| 304 | } |
| 305 | fs.Debugf(nil, "saving configKey to temp file") |
| 306 | err = os.Setenv("_RCLONE_CONFIG_KEY_FILE", tempFile.Name()) |
| 307 | if err != nil { |
| 308 | errRemove := os.Remove(tempFile.Name()) |
| 309 | if errRemove != nil { |
| 310 | return fmt.Errorf("unable to set environment variable _RCLONE_CONFIG_KEY_FILE and unable to delete the temp file: %w", err) |
| 311 | } |
| 312 | return fmt.Errorf("unable to set environment variable _RCLONE_CONFIG_KEY_FILE: %w", err) |
| 313 | } |
| 314 | } |
| 315 | return nil |
| 316 | } |
| 317 | |
| 318 | // ClearConfigPassword sets the current the password to empty |
| 319 | func ClearConfigPassword() { |
searching dependent graphs…